[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/ -> general-template.php (source)

   1  <?php
   2  /**
   3   * General template tags that can go anywhere in a template.
   4   *
   5   * @package WordPress
   6   * @subpackage Template
   7   */
   8  
   9  /**
  10   * Loads header template.
  11   *
  12   * Includes the header template for a theme or if a name is specified then a
  13   * specialized header will be included.
  14   *
  15   * For the parameter, if the file is called "header-special.php" then specify
  16   * "special".
  17   *
  18   * @since 1.5.0
  19   * @since 5.5.0 A return value was added.
  20   * @since 5.5.0 The `$args` parameter was added.
  21   *
  22   * @param string|null $name The name of the specialized header. Default null.
  23   * @param array       $args Optional. Additional arguments passed to the header template.
  24   *                          Default empty array.
  25   * @return void|false Void on success, false if the template does not exist.
  26   */
  27  function get_header( $name = null, $args = array() ) {
  28      /**
  29       * Fires before the header template file is loaded.
  30       *
  31       * @since 2.1.0
  32       * @since 2.8.0 The `$name` parameter was added.
  33       * @since 5.5.0 The `$args` parameter was added.
  34       *
  35       * @param string|null $name Name of the specific header file to use. Null for the default header.
  36       * @param array       $args Additional arguments passed to the header template.
  37       */
  38      do_action( 'get_header', $name, $args );
  39  
  40      $templates = array();
  41      $name      = (string) $name;
  42      if ( '' !== $name ) {
  43          $templates[] = "header-{$name}.php";
  44      }
  45  
  46      $templates[] = 'header.php';
  47  
  48      if ( ! locate_template( $templates, true, true, $args ) ) {
  49          return false;
  50      }
  51  }
  52  
  53  /**
  54   * Loads footer template.
  55   *
  56   * Includes the footer template for a theme or if a name is specified then a
  57   * specialized footer will be included.
  58   *
  59   * For the parameter, if the file is called "footer-special.php" then specify
  60   * "special".
  61   *
  62   * @since 1.5.0
  63   * @since 5.5.0 A return value was added.
  64   * @since 5.5.0 The `$args` parameter was added.
  65   *
  66   * @param string|null $name The name of the specialized footer. Default null.
  67   * @param array       $args Optional. Additional arguments passed to the footer template.
  68   *                          Default empty array.
  69   * @return void|false Void on success, false if the template does not exist.
  70   */
  71  function get_footer( $name = null, $args = array() ) {
  72      /**
  73       * Fires before the footer template file is loaded.
  74       *
  75       * @since 2.1.0
  76       * @since 2.8.0 The `$name` parameter was added.
  77       * @since 5.5.0 The `$args` parameter was added.
  78       *
  79       * @param string|null $name Name of the specific footer file to use. Null for the default footer.
  80       * @param array       $args Additional arguments passed to the footer template.
  81       */
  82      do_action( 'get_footer', $name, $args );
  83  
  84      $templates = array();
  85      $name      = (string) $name;
  86      if ( '' !== $name ) {
  87          $templates[] = "footer-{$name}.php";
  88      }
  89  
  90      $templates[] = 'footer.php';
  91  
  92      if ( ! locate_template( $templates, true, true, $args ) ) {
  93          return false;
  94      }
  95  }
  96  
  97  /**
  98   * Loads sidebar template.
  99   *
 100   * Includes the sidebar template for a theme or if a name is specified then a
 101   * specialized sidebar will be included.
 102   *
 103   * For the parameter, if the file is called "sidebar-special.php" then specify
 104   * "special".
 105   *
 106   * @since 1.5.0
 107   * @since 5.5.0 A return value was added.
 108   * @since 5.5.0 The `$args` parameter was added.
 109   *
 110   * @param string|null $name The name of the specialized sidebar. Default null.
 111   * @param array       $args Optional. Additional arguments passed to the sidebar template.
 112   *                          Default empty array.
 113   * @return void|false Void on success, false if the template does not exist.
 114   */
 115  function get_sidebar( $name = null, $args = array() ) {
 116      /**
 117       * Fires before the sidebar template file is loaded.
 118       *
 119       * @since 2.2.0
 120       * @since 2.8.0 The `$name` parameter was added.
 121       * @since 5.5.0 The `$args` parameter was added.
 122       *
 123       * @param string|null $name Name of the specific sidebar file to use. Null for the default sidebar.
 124       * @param array       $args Additional arguments passed to the sidebar template.
 125       */
 126      do_action( 'get_sidebar', $name, $args );
 127  
 128      $templates = array();
 129      $name      = (string) $name;
 130      if ( '' !== $name ) {
 131          $templates[] = "sidebar-{$name}.php";
 132      }
 133  
 134      $templates[] = 'sidebar.php';
 135  
 136      if ( ! locate_template( $templates, true, true, $args ) ) {
 137          return false;
 138      }
 139  }
 140  
 141  /**
 142   * Loads a template part into a template.
 143   *
 144   * Provides a simple mechanism for child themes to overload reusable sections of code
 145   * in the theme.
 146   *
 147   * Includes the named template part for a theme or if a name is specified then a
 148   * specialized part will be included. If the theme contains no {slug}.php file
 149   * then no template will be included.
 150   *
 151   * The template is included using require, not require_once, so you may include the
 152   * same template part multiple times.
 153   *
 154   * For the $name parameter, if the file is called "{slug}-special.php" then specify
 155   * "special".
 156   *
 157   * @since 3.0.0
 158   * @since 5.5.0 A return value was added.
 159   * @since 5.5.0 The `$args` parameter was added.
 160   *
 161   * @param string      $slug The slug name for the generic template.
 162   * @param string|null $name Optional. The name of the specialized template. Default null.
 163   * @param array       $args Optional. Additional arguments passed to the template.
 164   *                          Default empty array.
 165   * @return void|false Void on success, false if the template does not exist.
 166   */
 167  function get_template_part( $slug, $name = null, $args = array() ) {
 168      /**
 169       * Fires before the specified template part file is loaded.
 170       *
 171       * The dynamic portion of the hook name, `$slug`, refers to the slug name
 172       * for the generic template part.
 173       *
 174       * @since 3.0.0
 175       * @since 5.5.0 The `$args` parameter was added.
 176       *
 177       * @param string      $slug The slug name for the generic template.
 178       * @param string|null $name The name of the specialized template
 179       *                          or null if there is none.
 180       * @param array       $args Additional arguments passed to the template.
 181       */
 182      do_action( "get_template_part_{$slug}", $slug, $name, $args );
 183  
 184      $templates = array();
 185      $name      = (string) $name;
 186      if ( '' !== $name ) {
 187          $templates[] = "{$slug}-{$name}.php";
 188      }
 189  
 190      $templates[] = "{$slug}.php";
 191  
 192      /**
 193       * Fires before an attempt is made to locate and load a template part.
 194       *
 195       * @since 5.2.0
 196       * @since 5.5.0 The `$args` parameter was added.
 197       *
 198       * @param string   $slug      The slug name for the generic template.
 199       * @param string   $name      The name of the specialized template
 200       *                            or an empty string if there is none.
 201       * @param string[] $templates Array of template files to search for, in order.
 202       * @param array    $args      Additional arguments passed to the template.
 203       */
 204      do_action( 'get_template_part', $slug, $name, $templates, $args );
 205  
 206      if ( ! locate_template( $templates, true, false, $args ) ) {
 207          return false;
 208      }
 209  }
 210  
 211  /**
 212   * Displays search form.
 213   *
 214   * Will first attempt to locate the searchform.php file in either the child or
 215   * the parent, then load it. If it doesn't exist, then the default search form
 216   * will be displayed. The default search form is HTML, which will be displayed.
 217   * There is a filter applied to the search form HTML in order to edit or replace
 218   * it. The filter is {@see 'get_search_form'}.
 219   *
 220   * This function is primarily used by themes which want to hardcode the search
 221   * form into the sidebar and also by the search widget in WordPress.
 222   *
 223   * There is also an action that is called whenever the function is run called,
 224   * {@see 'pre_get_search_form'}. This can be useful for outputting JavaScript that the
 225   * search relies on or various formatting that applies to the beginning of the
 226   * search. To give a few examples of what it can be used for.
 227   *
 228   * @since 2.7.0
 229   * @since 5.2.0 The `$args` array parameter was added in place of an `$echo` boolean flag.
 230   *
 231   * @param array $args {
 232   *     Optional. Array of display arguments.
 233   *
 234   *     @type bool   $echo       Whether to echo or return the form. Default true.
 235   *     @type string $aria_label ARIA label for the search form. Useful to distinguish
 236   *                              multiple search forms on the same page and improve
 237   *                              accessibility. Default empty.
 238   * }
 239   * @return void|string Void if 'echo' argument is true, search form HTML if 'echo' is false.
 240   */
 241  function get_search_form( $args = array() ) {
 242      /**
 243       * Fires before the search form is retrieved, at the start of get_search_form().
 244       *
 245       * @since 2.7.0 as 'get_search_form' action.
 246       * @since 3.6.0
 247       * @since 5.5.0 The `$args` parameter was added.
 248       *
 249       * @link https://core.trac.wordpress.org/ticket/19321
 250       *
 251       * @param array $args The array of arguments for building the search form.
 252       *                    See get_search_form() for information on accepted arguments.
 253       */
 254      do_action( 'pre_get_search_form', $args );
 255  
 256      $echo = true;
 257  
 258      if ( ! is_array( $args ) ) {
 259          /*
 260           * Back compat: to ensure previous uses of get_search_form() continue to
 261           * function as expected, we handle a value for the boolean $echo param removed
 262           * in 5.2.0. Then we deal with the $args array and cast its defaults.
 263           */
 264          $echo = (bool) $args;
 265  
 266          // Set an empty array and allow default arguments to take over.
 267          $args = array();
 268      }
 269  
 270      // Defaults are to echo and to output no custom label on the form.
 271      $defaults = array(
 272          'echo'       => $echo,
 273          'aria_label' => '',
 274      );
 275  
 276      $args = wp_parse_args( $args, $defaults );
 277  
 278      /**
 279       * Filters the array of arguments used when generating the search form.
 280       *
 281       * @since 5.2.0
 282       *
 283       * @param array $args The array of arguments for building the search form.
 284       *                    See get_search_form() for information on accepted arguments.
 285       */
 286      $args = apply_filters( 'search_form_args', $args );
 287  
 288      // Ensure that the filtered arguments contain all required default values.
 289      $args = array_merge( $defaults, $args );
 290  
 291      $format = current_theme_supports( 'html5', 'search-form' ) ? 'html5' : 'xhtml';
 292  
 293      /**
 294       * Filters the HTML format of the search form.
 295       *
 296       * @since 3.6.0
 297       * @since 5.5.0 The `$args` parameter was added.
 298       *
 299       * @param string $format The type of markup to use in the search form.
 300       *                       Accepts 'html5', 'xhtml'.
 301       * @param array  $args   The array of arguments for building the search form.
 302       *                       See get_search_form() for information on accepted arguments.
 303       */
 304      $format = apply_filters( 'search_form_format', $format, $args );
 305  
 306      $search_form_template = locate_template( 'searchform.php' );
 307  
 308      if ( '' !== $search_form_template ) {
 309          ob_start();
 310          require $search_form_template;
 311          $form = ob_get_clean();
 312      } else {
 313          // Build a string containing an aria-label to use for the search form.
 314          if ( $args['aria_label'] ) {
 315              $aria_label = 'aria-label="' . esc_attr( $args['aria_label'] ) . '" ';
 316          } else {
 317              /*
 318               * If there's no custom aria-label, we can set a default here. At the
 319               * moment it's empty as there's uncertainty about what the default should be.
 320               */
 321              $aria_label = '';
 322          }
 323  
 324          if ( 'html5' === $format ) {
 325              $form = '<form role="search" ' . $aria_label . 'method="get" class="search-form" action="' . esc_url( home_url( '/' ) ) . '">
 326                  <label>
 327                      <span class="screen-reader-text">' .
 328                      /* translators: Hidden accessibility text. */
 329                      _x( 'Search for:', 'label' ) .
 330                      '</span>
 331                      <input type="search" class="search-field" placeholder="' . esc_attr_x( 'Search &hellip;', 'placeholder' ) . '" value="' . get_search_query() . '" name="s" />
 332                  </label>
 333                  <input type="submit" class="search-submit" value="' . esc_attr_x( 'Search', 'submit button' ) . '" />
 334              </form>';
 335          } else {
 336              $form = '<form role="search" ' . $aria_label . 'method="get" id="searchform" class="searchform" action="' . esc_url( home_url( '/' ) ) . '">
 337                  <div>
 338                      <label class="screen-reader-text" for="s">' .
 339                      /* translators: Hidden accessibility text. */
 340                      _x( 'Search for:', 'label' ) .
 341                      '</label>
 342                      <input type="text" value="' . get_search_query() . '" name="s" id="s" />
 343                      <input type="submit" id="searchsubmit" value="' . esc_attr_x( 'Search', 'submit button' ) . '" />
 344                  </div>
 345              </form>';
 346          }
 347      }
 348  
 349      /**
 350       * Filters the HTML output of the search form.
 351       *
 352       * @since 2.7.0
 353       * @since 5.5.0 The `$args` parameter was added.
 354       *
 355       * @param string $form The search form HTML output.
 356       * @param array  $args The array of arguments for building the search form.
 357       *                     See get_search_form() for information on accepted arguments.
 358       */
 359      $result = apply_filters( 'get_search_form', $form, $args );
 360  
 361      if ( null === $result ) {
 362          $result = $form;
 363      }
 364  
 365      if ( $args['echo'] ) {
 366          echo $result;
 367      } else {
 368          return $result;
 369      }
 370  }
 371  
 372  
 373  /**
 374   * Retrieves the markup for an accessible tooltip.
 375   *
 376   * Returns a button with an accessible name popover.
 377   *
 378   * @since 7.1.0
 379   *
 380   * @param string $content Plain-text tooltip content. An empty value returns an empty string.
 381   * @param array  $args {
 382   *     Optional. Arguments for building the tooltip.
 383   *
 384   *     @type string $id          Unique ID for the popover element. Default is a
 385   *                               generated unique ID.
 386   *     @type string $label       Not used for tooltips.
 387   *     @type string $close_label Not used for tooltips.
 388   *     @type string $icon        Dashicons icon class for the toggle button.
 389   *                               Default 'dashicons-editor-help'. Should match the control's
 390   *                               visible label.
 391   *     @type string $class       Additional class(es) for the wrapping element.
 392   *                               Default empty.
 393   * }
 394   * @return string Tooltip HTML markup, or an empty string when no content is provided.
 395   */
 396  function wp_get_tooltip( $content, $args = array() ) {
 397      $args['type'] = 'tooltip';
 398      return wp_get_tooltip_helper( $content, $args );
 399  }
 400  
 401  /**
 402   * Retrieves the markup for an accessible tooltip or toggletip.
 403   *
 404   * Returns a button and either a hover/focus triggered tooltip popover or an action
 405   * triggered toggle tip. Enqueue the `wp-tooltip` style and script where it is used.
 406   * Tooltips are used to show the accessible name of a control.
 407   * Toggletips are be used for longer supporting text explaining context.
 408   *
 409   * @since 7.1.0
 410   *
 411   * @param string $content Plain-text tooltip content. An empty value returns an empty string.
 412   * @param array  $args {
 413   *     Optional. Arguments for building the tooltip.
 414   *
 415   *     @type string $id          Unique ID for the popover element. Default is a
 416   *                               generated unique ID.
 417   *     @type string $label       Accessible label for the toggle button.
 418   *                               Default 'Help', matching the default icon.
 419   *                               Ignored for tooltips.
 420   *     @type string $close_label Accessible label for the close button. Default 'Close'.
 421   *     @type string $icon        Dashicons icon class for the toggle button.
 422   *                               Default 'dashicons-editor-help'. Should match the control's
 423   *                               visible label.
 424   *     @type string $class       Additional class(es) for the wrapping element.
 425   *                               Default empty.
 426   * }
 427   * @return string Tooltip HTML markup, or an empty string when no content is provided.
 428   */
 429  function wp_get_toggletip( $content, $args ) {
 430      $args['type'] = 'toggletip';
 431      return wp_get_tooltip_helper( $content, $args );
 432  }
 433  
 434  /**
 435   * Retrieves the markup for an accessible tooltip or toggletip.
 436   *
 437   * Returns a button and either a hover/focus triggered tooltip popover or an action
 438   * triggered toggle tip. Enqueue the `wp-tooltip` style and script where it is used.
 439   * Tooltips are used to show the accessible name of a control.
 440   * Toggletips are used for longer supporting text explaining context.
 441   *
 442   * @since 7.1.0
 443   *
 444   * @param string $content Plain-text tooltip content. An empty value returns an empty string.
 445   * @param array  $args {
 446   *     Optional. Arguments for building the tooltip.
 447   *
 448   *     @type string $id          Unique ID for the popover element. Default is a
 449   *                               generated unique ID.
 450   *     @type string $label       Accessible label for the toggle button.
 451   *                               Default 'Help', matching the default icon.
 452   *                               Ignored for tooltips.
 453   *     @type string $close_label Accessible label for the close button. Default 'Close'.
 454   *     @type string $icon        Dashicons icon class for the toggle button.
 455   *                               Default 'dashicons-editor-help'. Should match the control's
 456   *                               visible label.
 457   *     @type string $class       Additional class(es) for the wrapping element.
 458   *                               Default empty.
 459   *     @type string $type        Type of tooltip: either `tooltip` or `toggletip`.
 460   *                               Default 'tooltip'.
 461   * }
 462   * @return string Tooltip HTML markup, or an empty string when no content is provided.
 463   */
 464  function wp_get_tooltip_helper( $content, $args = array() ) {
 465      $content = trim( (string) $content );
 466  
 467      if ( '' === $content ) {
 468          return '';
 469      }
 470  
 471      $defaults = array(
 472          'id'          => '',
 473          'label'       => __( 'Help' ),
 474          'close_label' => __( 'Close' ),
 475          'icon'        => 'dashicons-editor-help',
 476          'class'       => '',
 477          'type'        => 'tooltip',
 478      );
 479  
 480      $args = wp_parse_args( $args, $defaults );
 481  
 482      $id = '' !== $args['id'] ? $args['id'] : wp_unique_id( 'wp-tooltip-' );
 483  
 484      $classes = ( 'tooltip' === $args['type'] ) ? 'wp-tooltip wp-is-tooltip' : 'wp-tooltip wp-is-toggletip';
 485      if ( '' !== $args['class'] ) {
 486          $classes .= ' ' . $args['class'];
 487      }
 488  
 489      $icon = '' !== $args['icon'] ? ' ' . $args['icon'] : '';
 490  
 491      /*
 492       * The markup only uses phrasing content so it is valid when nested
 493       * in a phrasing context. Sectioning content (e.g. `div`, `dialog`) will
 494       * cause the parser to close an open `p`, creating an empty and breaking
 495       * the layout. See #65660.
 496       */
 497      if ( 'tooltip' === $args['type'] ) {
 498          // Tooltips are only used to visually display labels.
 499          $label  = wp_strip_all_tags( $content, true );
 500          $markup = sprintf(
 501              '<span class="%1$s">' .
 502                  '<button type="button" class="wp-tooltip__toggle" popovertarget="%2$s" aria-label="%3$s">' .
 503                      '<span class="dashicons%4$s" aria-hidden="true"></span>' .
 504                  '</button>' .
 505                  '<span popover="hint" id="%2$s" class="wp-tooltip__bubble" role="tooltip">' .
 506                      '<span id="%2$s-text" class="wp-tooltip__text">%5$s</span>' .
 507                  '</span>' .
 508              '</span>',
 509              esc_attr( $classes ),
 510              esc_attr( $id ),
 511              esc_attr( $label ),
 512              esc_attr( $icon ),
 513              esc_html( $content ),
 514          );
 515      } else {
 516          /*
 517           * A `span` with `role="dialog"` is used instead of a `dialog` element to keep the
 518           * markup as phrasing content. The `aria-label`, `tabindex`, and `autofocus`
 519           * attributes reproduce the accessible name and focus handling of the native element.
 520           */
 521          $markup = sprintf(
 522              '<span class="%1$s">' .
 523                  '<button type="button" class="wp-tooltip__toggle" popovertarget="%2$s" aria-label="%3$s" aria-haspopup="dialog">' .
 524                      '<span class="dashicons%4$s" aria-hidden="true"></span>' .
 525                  '</button>' .
 526                  '<span popover="auto" id="%2$s" class="wp-tooltip__bubble" role="dialog" aria-label="%3$s" tabindex="-1" autofocus>' .
 527                      '<span id="%2$s-text" class="wp-tooltip__text">%5$s</span>' .
 528                      '<button type="button" class="wp-tooltip__close" popovertarget="%2$s" popovertargetaction="hide" aria-label="%6$s">' .
 529                          '<span class="dashicons dashicons-no-alt" aria-hidden="true"></span>' .
 530                      '</button>' .
 531                  '</span>' .
 532              '</span>',
 533              esc_attr( $classes ),
 534              esc_attr( $id ),
 535              esc_attr( $args['label'] ),
 536              esc_attr( $icon ),
 537              esc_html( $content ),
 538              esc_attr( $args['close_label'] ),
 539          );
 540      }
 541  
 542      return $markup;
 543  }
 544  
 545  /**
 546   * Displays the Log In/Out link.
 547   *
 548   * Displays a link, which allows users to navigate to the Log In page to log in
 549   * or log out depending on whether they are currently logged in.
 550   *
 551   * @since 1.5.0
 552   *
 553   * @param string $redirect Optional path to redirect to on login/logout.
 554   * @param bool   $display  Default to echo and not return the link.
 555   * @return void|string Void if `$display` argument is true, log in/out link if `$display` is false.
 556   */
 557  function wp_loginout( $redirect = '', $display = true ) {
 558      if ( ! is_user_logged_in() ) {
 559          $link = '<a href="' . esc_url( wp_login_url( $redirect ) ) . '">' . __( 'Log in' ) . '</a>';
 560      } else {
 561          $link = '<a href="' . esc_url( wp_logout_url( $redirect ) ) . '">' . __( 'Log out' ) . '</a>';
 562      }
 563  
 564      if ( $display ) {
 565          /**
 566           * Filters the HTML output for the Log In/Log Out link.
 567           *
 568           * @since 1.5.0
 569           *
 570           * @param string $link The HTML link content.
 571           */
 572          echo apply_filters( 'loginout', $link );
 573      } else {
 574          /** This filter is documented in wp-includes/general-template.php */
 575          return apply_filters( 'loginout', $link );
 576      }
 577  }
 578  
 579  /**
 580   * Retrieves the logout URL.
 581   *
 582   * Returns the URL that allows the user to log out of the site.
 583   *
 584   * @since 2.7.0
 585   *
 586   * @param string $redirect Path to redirect to on logout.
 587   * @return string The logout URL. Note: HTML-encoded via esc_html() in wp_nonce_url().
 588   */
 589  function wp_logout_url( $redirect = '' ) {
 590      $args = array();
 591      if ( ! empty( $redirect ) ) {
 592          $args['redirect_to'] = urlencode( $redirect );
 593      }
 594  
 595      $logout_url = add_query_arg( $args, site_url( 'wp-login.php?action=logout', 'login' ) );
 596      $logout_url = wp_nonce_url( $logout_url, 'log-out' );
 597  
 598      /**
 599       * Filters the logout URL.
 600       *
 601       * @since 2.8.0
 602       *
 603       * @param string $logout_url The HTML-encoded logout URL.
 604       * @param string $redirect   Path to redirect to on logout.
 605       */
 606      return apply_filters( 'logout_url', $logout_url, $redirect );
 607  }
 608  
 609  /**
 610   * Retrieves the login URL.
 611   *
 612   * @since 2.7.0
 613   *
 614   * @param string $redirect     Path to redirect to on log in.
 615   * @param bool   $force_reauth Whether to force reauthorization, even if a cookie is present.
 616   *                             Default false.
 617   * @return string The login URL. Not HTML-encoded.
 618   */
 619  function wp_login_url( $redirect = '', $force_reauth = false ) {
 620      $login_url = site_url( 'wp-login.php', 'login' );
 621  
 622      if ( ! empty( $redirect ) ) {
 623          $login_url = add_query_arg( 'redirect_to', urlencode( $redirect ), $login_url );
 624      }
 625  
 626      if ( $force_reauth ) {
 627          $login_url = add_query_arg( 'reauth', '1', $login_url );
 628      }
 629  
 630      /**
 631       * Filters the login URL.
 632       *
 633       * @since 2.8.0
 634       * @since 4.2.0 The `$force_reauth` parameter was added.
 635       *
 636       * @param string $login_url    The login URL. Not HTML-encoded.
 637       * @param string $redirect     The path to redirect to on login, if supplied.
 638       * @param bool   $force_reauth Whether to force reauthorization, even if a cookie is present.
 639       */
 640      return apply_filters( 'login_url', $login_url, $redirect, $force_reauth );
 641  }
 642  
 643  /**
 644   * Returns the URL that allows the user to register on the site.
 645   *
 646   * @since 3.6.0
 647   *
 648   * @return string User registration URL.
 649   */
 650  function wp_registration_url() {
 651      /**
 652       * Filters the user registration URL.
 653       *
 654       * @since 3.6.0
 655       *
 656       * @param string $register The user registration URL.
 657       */
 658      return apply_filters( 'register_url', site_url( 'wp-login.php?action=register', 'login' ) );
 659  }
 660  
 661  /**
 662   * Provides a simple login form for use anywhere within WordPress.
 663   *
 664   * The login form HTML is echoed by default. Pass a false value for `$echo` to return it instead.
 665   *
 666   * @since 3.0.0
 667   * @since 6.6.0 Added `required_username` and `required_password` arguments.
 668   *
 669   * @param array $args {
 670   *     Optional. Array of options to control the form output. Default empty array.
 671   *
 672   *     @type bool   $echo              Whether to display the login form or return the form HTML code.
 673   *                                     Default true (echo).
 674   *     @type string $redirect          URL to redirect to. Must be absolute, as in "https://example.com/mypage/".
 675   *                                     Default is to redirect back to the request URI.
 676   *     @type string $form_id           ID attribute value for the form. Default 'loginform'.
 677   *     @type string $label_username    Label for the username or email address field. Default 'Username or Email Address'.
 678   *     @type string $label_password    Label for the password field. Default 'Password'.
 679   *     @type string $label_remember    Label for the remember field. Default 'Remember Me'.
 680   *     @type string $label_log_in      Label for the submit button. Default 'Log In'.
 681   *     @type string $id_username       ID attribute value for the username field. Default 'user_login'.
 682   *     @type string $id_password       ID attribute value for the password field. Default 'user_pass'.
 683   *     @type string $id_remember       ID attribute value for the remember field. Default 'rememberme'.
 684   *     @type string $id_submit         ID attribute value for the submit button. Default 'wp-submit'.
 685   *     @type bool   $remember          Whether to display the "rememberme" checkbox in the form.
 686   *     @type string $value_username    Default value for the username field. Default empty.
 687   *     @type bool   $value_remember    Whether the "Remember Me" checkbox should be checked by default.
 688   *                                     Default false (unchecked).
 689   *     @type bool   $required_username Whether the username field has the 'required' attribute.
 690   *                                     Default false.
 691   *     @type bool   $required_password Whether the password field has the 'required' attribute.
 692   *                                     Default false.
 693   *
 694   * }
 695   * @return void|string Void if 'echo' argument is true, login form HTML if 'echo' is false.
 696   */
 697  function wp_login_form( $args = array() ) {
 698      $defaults = array(
 699          'echo'              => true,
 700          // Default 'redirect' value takes the user back to the request URI.
 701          'redirect'          => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'],
 702          'form_id'           => 'loginform',
 703          'label_username'    => __( 'Username or Email Address' ),
 704          'label_password'    => __( 'Password' ),
 705          'label_remember'    => __( 'Remember Me' ),
 706          'label_log_in'      => __( 'Log In' ),
 707          'id_username'       => 'user_login',
 708          'id_password'       => 'user_pass',
 709          'id_remember'       => 'rememberme',
 710          'id_submit'         => 'wp-submit',
 711          'remember'          => true,
 712          'value_username'    => '',
 713          // Set 'value_remember' to true to default the "Remember me" checkbox to checked.
 714          'value_remember'    => false,
 715          // Set 'required_username' to true to add the required attribute to username field.
 716          'required_username' => false,
 717          // Set 'required_password' to true to add the required attribute to password field.
 718          'required_password' => false,
 719      );
 720  
 721      /**
 722       * Filters the default login form output arguments.
 723       *
 724       * @since 3.0.0
 725       *
 726       * @see wp_login_form()
 727       *
 728       * @param array $defaults An array of default login form arguments.
 729       */
 730      $args = wp_parse_args( $args, apply_filters( 'login_form_defaults', $defaults ) );
 731  
 732      /**
 733       * Filters content to display at the top of the login form.
 734       *
 735       * The filter evaluates just following the opening form tag element.
 736       *
 737       * @since 3.0.0
 738       *
 739       * @param string $content Content to display. Default empty.
 740       * @param array  $args    Array of login form arguments.
 741       */
 742      $login_form_top = apply_filters( 'login_form_top', '', $args );
 743  
 744      /**
 745       * Filters content to display in the middle of the login form.
 746       *
 747       * The filter evaluates just following the location where the 'login-password'
 748       * field is displayed.
 749       *
 750       * @since 3.0.0
 751       *
 752       * @param string $content Content to display. Default empty.
 753       * @param array  $args    Array of login form arguments.
 754       */
 755      $login_form_middle = apply_filters( 'login_form_middle', '', $args );
 756  
 757      /**
 758       * Filters content to display at the bottom of the login form.
 759       *
 760       * The filter evaluates just preceding the closing form tag element.
 761       *
 762       * @since 3.0.0
 763       *
 764       * @param string $content Content to display. Default empty.
 765       * @param array  $args    Array of login form arguments.
 766       */
 767      $login_form_bottom = apply_filters( 'login_form_bottom', '', $args );
 768  
 769      $direction_style = is_rtl() ? ' style="direction: ltr;"' : '';
 770  
 771      $form =
 772          sprintf(
 773              '<form name="%1$s" id="%1$s" action="%2$s" method="post">',
 774              esc_attr( $args['form_id'] ),
 775              esc_url( site_url( 'wp-login.php', 'login_post' ) )
 776          ) .
 777          $login_form_top .
 778          sprintf(
 779              '<p class="login-username">
 780                  <label for="%1$s">%2$s</label>
 781                  <input type="text" name="log" id="%1$s" autocomplete="username" class="input" value="%3$s" size="20"%4$s%5$s />
 782              </p>',
 783              esc_attr( $args['id_username'] ),
 784              esc_html( $args['label_username'] ),
 785              esc_attr( $args['value_username'] ),
 786              ( $args['required_username'] ? ' required="required"' : '' ),
 787              $direction_style
 788          ) .
 789          sprintf(
 790              '<p class="login-password">
 791                  <label for="%1$s">%2$s</label>
 792                  <input type="password" name="pwd" id="%1$s" autocomplete="current-password" spellcheck="false" class="input" value="" size="20"%3$s%4$s />
 793              </p>',
 794              esc_attr( $args['id_password'] ),
 795              esc_html( $args['label_password'] ),
 796              ( $args['required_password'] ? ' required="required"' : '' ),
 797              $direction_style
 798          ) .
 799          $login_form_middle .
 800          ( $args['remember'] ?
 801              sprintf(
 802                  '<p class="login-remember"><label><input name="rememberme" type="checkbox" id="%1$s" value="forever"%2$s /> %3$s</label></p>',
 803                  esc_attr( $args['id_remember'] ),
 804                  ( $args['value_remember'] ? ' checked="checked"' : '' ),
 805                  esc_html( $args['label_remember'] )
 806              ) : ''
 807          ) .
 808          sprintf(
 809              '<p class="login-submit">
 810                  <input type="submit" name="wp-submit" id="%1$s" class="button button-primary" value="%2$s" />
 811                  <input type="hidden" name="redirect_to" value="%3$s" />
 812              </p>',
 813              esc_attr( $args['id_submit'] ),
 814              esc_attr( $args['label_log_in'] ),
 815              esc_url( $args['redirect'] )
 816          ) .
 817          $login_form_bottom .
 818          '</form>';
 819  
 820      if ( $args['echo'] ) {
 821          echo $form;
 822      } else {
 823          return $form;
 824      }
 825  }
 826  
 827  /**
 828   * Returns the URL that allows the user to reset the lost password.
 829   *
 830   * @since 2.8.0
 831   *
 832   * @param string $redirect Path to redirect to on login.
 833   * @return string Lost password URL.
 834   */
 835  function wp_lostpassword_url( $redirect = '' ) {
 836      $args = array(
 837          'action' => 'lostpassword',
 838      );
 839  
 840      if ( ! empty( $redirect ) ) {
 841          $args['redirect_to'] = urlencode( $redirect );
 842      }
 843  
 844      if ( is_multisite() ) {
 845          $blog_details  = get_site();
 846          $wp_login_path = $blog_details->path . 'wp-login.php';
 847      } else {
 848          $wp_login_path = 'wp-login.php';
 849      }
 850  
 851      $lostpassword_url = add_query_arg( $args, network_site_url( $wp_login_path, 'login' ) );
 852  
 853      /**
 854       * Filters the Lost Password URL.
 855       *
 856       * @since 2.8.0
 857       *
 858       * @param string $lostpassword_url The lost password page URL.
 859       * @param string $redirect         The path to redirect to on login.
 860       */
 861      return apply_filters( 'lostpassword_url', $lostpassword_url, $redirect );
 862  }
 863  
 864  /**
 865   * Displays the Registration or Admin link.
 866   *
 867   * Display a link which allows the user to navigate to the registration page if
 868   * not logged in and registration is enabled or to the dashboard if logged in.
 869   *
 870   * @since 1.5.0
 871   *
 872   * @param string $before  Text to output before the link. Default `<li>`.
 873   * @param string $after   Text to output after the link. Default `</li>`.
 874   * @param bool   $display Default to echo and not return the link.
 875   * @return void|string Void if `$display` argument is true, registration or admin link
 876   *                     if `$display` is false.
 877   */
 878  function wp_register( $before = '<li>', $after = '</li>', $display = true ) {
 879      if ( ! is_user_logged_in() ) {
 880          if ( get_option( 'users_can_register' ) ) {
 881              $link = $before . '<a href="' . esc_url( wp_registration_url() ) . '">' . __( 'Register' ) . '</a>' . $after;
 882          } else {
 883              $link = '';
 884          }
 885      } elseif ( current_user_can( 'read' ) ) {
 886          $link = $before . '<a href="' . admin_url() . '">' . __( 'Site Admin' ) . '</a>' . $after;
 887      } else {
 888          $link = '';
 889      }
 890  
 891      /**
 892       * Filters the HTML link to the Registration or Admin page.
 893       *
 894       * Users are sent to the admin page if logged-in, or the registration page
 895       * if enabled and logged-out.
 896       *
 897       * @since 1.5.0
 898       *
 899       * @param string $link The HTML code for the link to the Registration or Admin page.
 900       */
 901      $link = apply_filters( 'register', $link );
 902  
 903      if ( $display ) {
 904          echo $link;
 905      } else {
 906          return $link;
 907      }
 908  }
 909  
 910  /**
 911   * Theme container function for the 'wp_meta' action.
 912   *
 913   * The {@see 'wp_meta'} action can have several purposes, depending on how you use it,
 914   * but one purpose might have been to allow for theme switching.
 915   *
 916   * @since 1.5.0
 917   *
 918   * @link https://core.trac.wordpress.org/ticket/1458 Explanation of 'wp_meta' action.
 919   */
 920  function wp_meta() {
 921      /**
 922       * Fires before displaying echoed content in the sidebar.
 923       *
 924       * @since 1.5.0
 925       */
 926      do_action( 'wp_meta' );
 927  }
 928  
 929  /**
 930   * Displays information about the current site.
 931   *
 932   * @since 0.71
 933   *
 934   * @see get_bloginfo() For possible `$show` values
 935   *
 936   * @param string $show Optional. Site information to display. Default empty.
 937   */
 938  function bloginfo( $show = '' ) {
 939      echo get_bloginfo( $show, 'display' );
 940  }
 941  
 942  /**
 943   * Retrieves information about the current site.
 944   *
 945   * Possible values for `$show` include:
 946   *
 947   * - 'name' - Site title (set in Settings > General)
 948   * - 'description' - Site tagline (set in Settings > General)
 949   * - 'wpurl' - The WordPress address (URL) (set in Settings > General)
 950   * - 'url' - The Site address (URL) (set in Settings > General)
 951   * - 'admin_email' - Admin email (set in Settings > General)
 952   * - 'charset' - The "Encoding for pages and feeds"  (set in Settings > Reading)
 953   * - 'version' - The current WordPress version
 954   * - 'html_type' - The Content-Type (default: "text/html"). Themes and plugins
 955   *   can override the default value using the {@see 'pre_option_html_type'} filter
 956   * - 'text_direction' - The text direction determined by the site's language. is_rtl()
 957   *   should be used instead
 958   * - 'language' - Language code for the current site
 959   * - 'stylesheet_url' - URL to the stylesheet for the active theme. An active child theme
 960   *   will take precedence over this value
 961   * - 'stylesheet_directory' - Directory path for the active theme.  An active child theme
 962   *   will take precedence over this value
 963   * - 'template_url' / 'template_directory' - URL of the active theme's directory. An active
 964   *   child theme will NOT take precedence over this value
 965   * - 'pingback_url' - The pingback XML-RPC file URL (xmlrpc.php)
 966   * - 'atom_url' - The Atom feed URL (/feed/atom)
 967   * - 'rdf_url' - The RDF/RSS 1.0 feed URL (/feed/rdf)
 968   * - 'rss_url' - The RSS 0.92 feed URL (/feed/rss)
 969   * - 'rss2_url' - The RSS 2.0 feed URL (/feed)
 970   * - 'comments_atom_url' - The comments Atom feed URL (/comments/feed)
 971   * - 'comments_rss2_url' - The comments RSS 2.0 feed URL (/comments/feed)
 972   *
 973   * Some `$show` values are deprecated and will be removed in future versions.
 974   * These options will trigger the _deprecated_argument() function.
 975   *
 976   * Deprecated arguments include:
 977   *
 978   * - 'siteurl' - Use 'url' instead
 979   * - 'home' - Use 'url' instead
 980   *
 981   * @since 0.71
 982   *
 983   * @global string $wp_version The WordPress version string.
 984   *
 985   * @param string $show   Optional. Site info to retrieve. Default empty (site name).
 986   * @param string $filter Optional. How to filter what is retrieved. Default 'raw'.
 987   * @return string Mostly string values, might be empty.
 988   */
 989  function get_bloginfo( $show = '', $filter = 'raw' ) {
 990      switch ( $show ) {
 991          case 'home':    // Deprecated.
 992          case 'siteurl': // Deprecated.
 993              _deprecated_argument(
 994                  __FUNCTION__,
 995                  '2.2.0',
 996                  sprintf(
 997                      /* translators: 1: 'siteurl'/'home' argument, 2: bloginfo() function name, 3: 'url' argument. */
 998                      __( 'The %1$s option is deprecated for the family of %2$s functions. Use the %3$s option instead.' ),
 999                      '<code>' . $show . '</code>',
1000                      '<code>bloginfo()</code>',
1001                      '<code>url</code>'
1002                  )
1003              );
1004              // Intentional fall-through to be handled by the 'url' case.
1005          case 'url':
1006              $output = home_url();
1007              break;
1008          case 'wpurl':
1009              $output = site_url();
1010              break;
1011          case 'description':
1012              $output = get_option( 'blogdescription' );
1013              break;
1014          case 'rdf_url':
1015              $output = get_feed_link( 'rdf' );
1016              break;
1017          case 'rss_url':
1018              $output = get_feed_link( 'rss' );
1019              break;
1020          case 'rss2_url':
1021              $output = get_feed_link( 'rss2' );
1022              break;
1023          case 'atom_url':
1024              $output = get_feed_link( 'atom' );
1025              break;
1026          case 'comments_atom_url':
1027              $output = get_feed_link( 'comments_atom' );
1028              break;
1029          case 'comments_rss2_url':
1030              $output = get_feed_link( 'comments_rss2' );
1031              break;
1032          case 'pingback_url':
1033              $output = site_url( 'xmlrpc.php' );
1034              break;
1035          case 'stylesheet_url':
1036              $output = get_stylesheet_uri();
1037              break;
1038          case 'stylesheet_directory':
1039              $output = get_stylesheet_directory_uri();
1040              break;
1041          case 'template_directory':
1042          case 'template_url':
1043              $output = get_template_directory_uri();
1044              break;
1045          case 'admin_email':
1046              $output = get_option( 'admin_email' );
1047              break;
1048          case 'charset':
1049              $output = get_option( 'blog_charset' );
1050              if ( '' === $output ) {
1051                  $output = 'UTF-8';
1052              }
1053              break;
1054          case 'html_type':
1055              $output = get_option( 'html_type' );
1056              break;
1057          case 'version':
1058              global $wp_version;
1059              $output = $wp_version;
1060              break;
1061          case 'language':
1062              /*
1063               * translators: Translate this to the correct language tag for your locale,
1064               * see https://www.w3.org/International/articles/language-tags/ for reference.
1065               * Do not translate into your own language.
1066               */
1067              $output = __( 'html_lang_attribute' );
1068              if ( 'html_lang_attribute' === $output || preg_match( '/[^a-zA-Z0-9-]/', $output ) ) {
1069                  $output = determine_locale();
1070                  $output = str_replace( '_', '-', $output );
1071              }
1072              break;
1073          case 'text_direction':
1074              _deprecated_argument(
1075                  __FUNCTION__,
1076                  '2.2.0',
1077                  sprintf(
1078                      /* translators: 1: 'text_direction' argument, 2: bloginfo() function name, 3: is_rtl() function name. */
1079                      __( 'The %1$s option is deprecated for the family of %2$s functions. Use the %3$s function instead.' ),
1080                      '<code>' . $show . '</code>',
1081                      '<code>bloginfo()</code>',
1082                      '<code>is_rtl()</code>'
1083                  )
1084              );
1085              if ( function_exists( 'is_rtl' ) ) {
1086                  $output = is_rtl() ? 'rtl' : 'ltr';
1087              } else {
1088                  $output = 'ltr';
1089              }
1090              break;
1091          case 'name':
1092          default:
1093              $output = get_option( 'blogname' );
1094              break;
1095      }
1096  
1097      if ( 'display' === $filter ) {
1098          if (
1099              str_contains( $show, 'url' )
1100              || str_contains( $show, 'directory' )
1101              || str_contains( $show, 'home' )
1102          ) {
1103              /**
1104               * Filters the URL returned by get_bloginfo().
1105               *
1106               * @since 2.0.5
1107               *
1108               * @param string $output The URL returned by bloginfo().
1109               * @param string $show   Type of information requested.
1110               */
1111              $output = apply_filters( 'bloginfo_url', $output, $show );
1112          } else {
1113              /**
1114               * Filters the site information returned by get_bloginfo().
1115               *
1116               * @since 0.71
1117               *
1118               * @param mixed  $output The requested non-URL site information.
1119               * @param string $show   Type of information requested.
1120               */
1121              $output = apply_filters( 'bloginfo', $output, $show );
1122          }
1123      }
1124  
1125      return $output;
1126  }
1127  
1128  /**
1129   * Returns the Site Icon URL.
1130   *
1131   * @since 4.3.0
1132   *
1133   * @param int    $size    Optional. Size of the site icon. Default 512 (pixels).
1134   * @param string $url     Optional. Fallback url if no site icon is found. Default empty.
1135   * @param int    $blog_id Optional. ID of the blog to get the site icon for. Default current blog.
1136   * @return string Site Icon URL.
1137   */
1138  function get_site_icon_url( $size = 512, $url = '', $blog_id = 0 ) {
1139      $switched_blog = false;
1140  
1141      if ( is_multisite() && ! empty( $blog_id ) && get_current_blog_id() !== (int) $blog_id ) {
1142          switch_to_blog( $blog_id );
1143          $switched_blog = true;
1144      }
1145  
1146      $site_icon_id = (int) get_option( 'site_icon' );
1147  
1148      if ( $site_icon_id ) {
1149          if ( $size >= 512 ) {
1150              $size_data = 'full';
1151          } else {
1152              $size_data = array( $size, $size );
1153          }
1154          $attachment_url = wp_get_attachment_image_url( $site_icon_id, $size_data );
1155          if ( $attachment_url ) {
1156              $url = $attachment_url;
1157          }
1158      }
1159  
1160      if ( $switched_blog ) {
1161          restore_current_blog();
1162      }
1163  
1164      /**
1165       * Filters the site icon URL.
1166       *
1167       * @since 4.4.0
1168       *
1169       * @param string $url     Site icon URL.
1170       * @param int    $size    Size of the site icon.
1171       * @param int    $blog_id ID of the blog to get the site icon for.
1172       */
1173      return apply_filters( 'get_site_icon_url', $url, $size, $blog_id );
1174  }
1175  
1176  /**
1177   * Displays the Site Icon URL.
1178   *
1179   * @since 4.3.0
1180   *
1181   * @param int    $size    Optional. Size of the site icon. Default 512 (pixels).
1182   * @param string $url     Optional. Fallback url if no site icon is found. Default empty.
1183   * @param int    $blog_id Optional. ID of the blog to get the site icon for. Default current blog.
1184   */
1185  function site_icon_url( $size = 512, $url = '', $blog_id = 0 ) {
1186      echo esc_url( get_site_icon_url( $size, $url, $blog_id ) );
1187  }
1188  
1189  /**
1190   * Determines whether the site has a Site Icon.
1191   *
1192   * @since 4.3.0
1193   *
1194   * @param int $blog_id Optional. ID of the blog in question. Default current blog.
1195   * @return bool Whether the site has a site icon or not.
1196   */
1197  function has_site_icon( $blog_id = 0 ) {
1198      return (bool) get_site_icon_url( 512, '', $blog_id );
1199  }
1200  
1201  /**
1202   * Determines whether the site has a custom logo.
1203   *
1204   * @since 4.5.0
1205   *
1206   * @param int $blog_id Optional. ID of the blog in question. Default is the ID of the current blog.
1207   * @return bool Whether the site has a custom logo or not.
1208   */
1209  function has_custom_logo( $blog_id = 0 ) {
1210      $switched_blog = false;
1211  
1212      if ( is_multisite() && ! empty( $blog_id ) && get_current_blog_id() !== (int) $blog_id ) {
1213          switch_to_blog( $blog_id );
1214          $switched_blog = true;
1215      }
1216  
1217      $custom_logo_id = get_theme_mod( 'custom_logo' );
1218      $is_image       = ( $custom_logo_id ) ? wp_attachment_is_image( $custom_logo_id ) : false;
1219  
1220      if ( $switched_blog ) {
1221          restore_current_blog();
1222      }
1223  
1224      return $is_image;
1225  }
1226  
1227  /**
1228   * Returns a custom logo, linked to home unless the theme supports removing the link on the home page.
1229   *
1230   * @since 4.5.0
1231   * @since 5.5.0 Added option to remove the link on the home page with `unlink-homepage-logo` theme support
1232   *              for the `custom-logo` theme feature.
1233   * @since 5.5.1 Disabled lazy-loading by default.
1234   *
1235   * @param int $blog_id Optional. ID of the blog in question. Default is the ID of the current blog.
1236   * @return string Custom logo markup.
1237   */
1238  function get_custom_logo( $blog_id = 0 ) {
1239      $html          = '';
1240      $switched_blog = false;
1241  
1242      if ( is_multisite() && ! empty( $blog_id ) && get_current_blog_id() !== (int) $blog_id ) {
1243          switch_to_blog( $blog_id );
1244          $switched_blog = true;
1245      }
1246  
1247      // We have a logo. Logo is go.
1248      if ( has_custom_logo() ) {
1249          $custom_logo_id   = get_theme_mod( 'custom_logo' );
1250          $custom_logo_attr = array(
1251              'class'   => 'custom-logo',
1252              'loading' => false,
1253          );
1254  
1255          $unlink_homepage_logo = (bool) get_theme_support( 'custom-logo', 'unlink-homepage-logo' );
1256  
1257          if ( $unlink_homepage_logo && is_front_page() && ! is_paged() ) {
1258              /*
1259               * If on the home page, set the logo alt attribute to an empty string,
1260               * as the image is decorative and doesn't need its purpose to be described.
1261               */
1262              $custom_logo_attr['alt'] = '';
1263          } else {
1264              /*
1265               * If the logo alt attribute is empty, get the site title and explicitly pass it
1266               * to the attributes used by wp_get_attachment_image().
1267               */
1268              $image_alt = get_post_meta( $custom_logo_id, '_wp_attachment_image_alt', true );
1269              if ( empty( $image_alt ) ) {
1270                  $custom_logo_attr['alt'] = get_bloginfo( 'name', 'display' );
1271              }
1272          }
1273  
1274          /**
1275           * Filters the list of custom logo image attributes.
1276           *
1277           * @since 5.5.0
1278           *
1279           * @param array $custom_logo_attr Custom logo image attributes.
1280           * @param int   $custom_logo_id   Custom logo attachment ID.
1281           * @param int   $blog_id          ID of the blog to get the custom logo for.
1282           */
1283          $custom_logo_attr = apply_filters( 'get_custom_logo_image_attributes', $custom_logo_attr, $custom_logo_id, $blog_id );
1284  
1285          /*
1286           * If the alt attribute is not empty, there's no need to explicitly pass it
1287           * because wp_get_attachment_image() already adds the alt attribute.
1288           */
1289          $image = wp_get_attachment_image( $custom_logo_id, 'full', false, $custom_logo_attr );
1290  
1291          // Check that we have a proper HTML img element.
1292          if ( $image ) {
1293  
1294              if ( $unlink_homepage_logo && is_front_page() && ! is_paged() ) {
1295                  // If on the home page, don't link the logo to home.
1296                  $html = sprintf(
1297                      '<span class="custom-logo-link">%1$s</span>',
1298                      $image
1299                  );
1300              } else {
1301                  $aria_current = ! is_paged() && ( is_front_page() || is_home() && ( (int) get_option( 'page_for_posts' ) !== get_queried_object_id() ) ) ? ' aria-current="page"' : '';
1302  
1303                  $html = sprintf(
1304                      '<a href="%1$s" class="custom-logo-link" rel="home"%2$s>%3$s</a>',
1305                      esc_url( home_url( '/' ) ),
1306                      $aria_current,
1307                      $image
1308                  );
1309              }
1310          }
1311      } elseif ( is_customize_preview() ) {
1312          // If no logo is set but we're in the Customizer, leave a placeholder (needed for the live preview).
1313          $html = sprintf(
1314              '<a href="%1$s" class="custom-logo-link" style="display:none;"><img class="custom-logo" alt="" /></a>',
1315              esc_url( home_url( '/' ) )
1316          );
1317      }
1318  
1319      if ( $switched_blog ) {
1320          restore_current_blog();
1321      }
1322  
1323      /**
1324       * Filters the custom logo output.
1325       *
1326       * @since 4.5.0
1327       * @since 4.6.0 Added the `$blog_id` parameter.
1328       *
1329       * @param string $html    Custom logo HTML output.
1330       * @param int    $blog_id ID of the blog to get the custom logo for.
1331       */
1332      return apply_filters( 'get_custom_logo', $html, $blog_id );
1333  }
1334  
1335  /**
1336   * Displays a custom logo, linked to home unless the theme supports removing the link on the home page.
1337   *
1338   * @since 4.5.0
1339   *
1340   * @param int $blog_id Optional. ID of the blog in question. Default is the ID of the current blog.
1341   */
1342  function the_custom_logo( $blog_id = 0 ) {
1343      echo get_custom_logo( $blog_id );
1344  }
1345  
1346  /**
1347   * Returns document title for the current page.
1348   *
1349   * @since 4.4.0
1350   *
1351   * @global int $page  Page number of a single post.
1352   * @global int $paged Page number of a list of posts.
1353   *
1354   * @return string Tag with the document title.
1355   */
1356  function wp_get_document_title() {
1357  
1358      /**
1359       * Filters the document title before it is generated.
1360       *
1361       * Passing a non-empty value will short-circuit wp_get_document_title(),
1362       * returning that value instead.
1363       *
1364       * @since 4.4.0
1365       *
1366       * @param string $title The document title. Default empty string.
1367       */
1368      $title = apply_filters( 'pre_get_document_title', '' );
1369      if ( ! empty( $title ) ) {
1370          return $title;
1371      }
1372  
1373      global $page, $paged;
1374  
1375      $title = array(
1376          'title' => '',
1377      );
1378  
1379      // If it's a 404 page, use a "Page not found" title.
1380      if ( is_404() ) {
1381          $title['title'] = __( 'Page not found' );
1382  
1383          // If it's a search, use a dynamic search results title.
1384      } elseif ( is_search() ) {
1385          /* translators: %s: Search query. */
1386          $title['title'] = sprintf( __( 'Search Results for &#8220;%s&#8221;' ), get_search_query() );
1387  
1388          // If on the front page, use the site title.
1389      } elseif ( is_front_page() ) {
1390          $title['title'] = get_bloginfo( 'name', 'display' );
1391  
1392          // If on a post type archive, use the post type archive title.
1393      } elseif ( is_post_type_archive() ) {
1394          $title['title'] = post_type_archive_title( '', false );
1395  
1396          // If on a taxonomy archive, use the term title.
1397      } elseif ( is_tax() ) {
1398          $title['title'] = single_term_title( '', false );
1399  
1400          /*
1401          * If we're on the blog page that is not the homepage
1402          * or a single post of any post type, use the post title.
1403          */
1404      } elseif ( is_home() || is_singular() ) {
1405          $title['title'] = single_post_title( '', false );
1406  
1407          // If on a category or tag archive, use the term title.
1408      } elseif ( is_category() || is_tag() ) {
1409          $title['title'] = single_term_title( '', false );
1410  
1411          // If on an author archive, use the author's display name.
1412      } elseif ( is_author() && get_queried_object() ) {
1413          $author         = get_queried_object();
1414          $title['title'] = $author->display_name;
1415  
1416          // If it's a date archive, use the date as the title.
1417      } elseif ( is_year() ) {
1418          $title['title'] = get_the_date( _x( 'Y', 'yearly archives date format' ) );
1419  
1420      } elseif ( is_month() ) {
1421          $title['title'] = get_the_date( _x( 'F Y', 'monthly archives date format' ) );
1422  
1423      } elseif ( is_day() ) {
1424          $title['title'] = get_the_date();
1425      }
1426  
1427      // Add a page number if necessary.
1428      if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
1429          /* translators: %s: Page number. */
1430          $title['page'] = sprintf( __( 'Page %s' ), max( $paged, $page ) );
1431      }
1432  
1433      // Append the description or site title to give context.
1434      if ( is_front_page() ) {
1435          $title['tagline'] = get_bloginfo( 'description', 'display' );
1436      } else {
1437          $title['site'] = get_bloginfo( 'name', 'display' );
1438      }
1439  
1440      /**
1441       * Filters the separator for the document title.
1442       *
1443       * @since 4.4.0
1444       *
1445       * @param string $sep Document title separator. Default '-'.
1446       */
1447      $sep = apply_filters( 'document_title_separator', '-' );
1448  
1449      /**
1450       * Filters the parts of the document title.
1451       *
1452       * @since 4.4.0
1453       *
1454       * @param array $title {
1455       *     The document title parts.
1456       *
1457       *     @type string $title   Title of the viewed page.
1458       *     @type string $page    Optional. Page number if paginated.
1459       *     @type string $tagline Optional. Site description when on home page.
1460       *     @type string $site    Optional. Site title when not on home page.
1461       * }
1462       */
1463      $title = apply_filters( 'document_title_parts', $title );
1464  
1465      $title = implode( " $sep ", array_filter( $title ) );
1466  
1467      /**
1468       * Filters the document title.
1469       *
1470       * @since 5.8.0
1471       *
1472       * @param string $title Document title.
1473       */
1474      $title = apply_filters( 'document_title', $title );
1475  
1476      return $title;
1477  }
1478  
1479  /**
1480   * Displays title tag with content.
1481   *
1482   * @since 4.1.0
1483   * @since 4.4.0 Improved title output replaced `wp_title()`.
1484   * @access private
1485   */
1486  function _wp_render_title_tag() {
1487      if ( ! current_theme_supports( 'title-tag' ) ) {
1488          return;
1489      }
1490  
1491      echo '<title>' . wp_get_document_title() . '</title>' . "\n";
1492  }
1493  
1494  /**
1495   * Displays or retrieves page title for all areas of blog.
1496   *
1497   * By default, the page title will display the separator before the page title,
1498   * so that the blog title will be before the page title. This is not good for
1499   * title display, since the blog title shows up on most tabs and not what is
1500   * important, which is the page that the user is looking at.
1501   *
1502   * There are also SEO benefits to having the blog title after or to the 'right'
1503   * of the page title. However, it is mostly common sense to have the blog title
1504   * to the right with most browsers supporting tabs. You can achieve this by
1505   * using the seplocation parameter and setting the value to 'right'. This change
1506   * was introduced around 2.5.0, in case backward compatibility of themes is
1507   * important.
1508   *
1509   * @since 1.0.0
1510   *
1511   * @global WP_Locale $wp_locale WordPress date and time locale object.
1512   *
1513   * @param string $sep         Optional. How to separate the various items within the page title.
1514   *                            Default '&raquo;'.
1515   * @param bool   $display     Optional. Whether to display or retrieve title. Default true.
1516   * @param string $seplocation Optional. Location of the separator (either 'left' or 'right').
1517   * @return string|null String when `$display` is false, null otherwise.
1518   */
1519  function wp_title( $sep = '&raquo;', $display = true, $seplocation = '' ) {
1520      global $wp_locale;
1521  
1522      $m        = get_query_var( 'm' );
1523      $year     = get_query_var( 'year' );
1524      $monthnum = get_query_var( 'monthnum' );
1525      $day      = get_query_var( 'day' );
1526      $search   = get_query_var( 's' );
1527      $title    = '';
1528  
1529      $t_sep = '%WP_TITLE_SEP%'; // Temporary separator, for accurate flipping, if necessary.
1530  
1531      // If there is a post.
1532      if ( is_single() || ( is_home() && ! is_front_page() ) || ( is_page() && ! is_front_page() ) ) {
1533          $title = single_post_title( '', false );
1534      }
1535  
1536      // If there's a post type archive.
1537      if ( is_post_type_archive() ) {
1538          $post_type = get_query_var( 'post_type' );
1539          if ( is_array( $post_type ) ) {
1540              $post_type = reset( $post_type );
1541          }
1542          $post_type_object = get_post_type_object( $post_type );
1543          if ( ! $post_type_object->has_archive ) {
1544              $title = post_type_archive_title( '', false );
1545          }
1546      }
1547  
1548      // If there's a category or tag.
1549      if ( is_category() || is_tag() ) {
1550          $title = single_term_title( '', false );
1551      }
1552  
1553      // If there's a taxonomy.
1554      if ( is_tax() ) {
1555          $term = get_queried_object();
1556          if ( $term ) {
1557              $tax   = get_taxonomy( $term->taxonomy );
1558              $title = single_term_title( $tax->labels->name . $t_sep, false );
1559          }
1560      }
1561  
1562      // If there's an author.
1563      if ( is_author() && ! is_post_type_archive() ) {
1564          $author = get_queried_object();
1565          if ( $author ) {
1566              $title = $author->display_name;
1567          }
1568      }
1569  
1570      // Post type archives with has_archive should override terms.
1571      if ( is_post_type_archive() && $post_type_object->has_archive ) {
1572          $title = post_type_archive_title( '', false );
1573      }
1574  
1575      // If there's a month.
1576      if ( is_archive() && ! empty( $m ) ) {
1577          $my_year  = substr( $m, 0, 4 );
1578          $my_month = substr( $m, 4, 2 );
1579          $my_day   = (int) substr( $m, 6, 2 );
1580          $title    = $my_year .
1581              ( $my_month ? $t_sep . $wp_locale->get_month( $my_month ) : '' ) .
1582              ( $my_day ? $t_sep . $my_day : '' );
1583      }
1584  
1585      // If there's a year.
1586      if ( is_archive() && ! empty( $year ) ) {
1587          $title = $year;
1588          if ( ! empty( $monthnum ) ) {
1589              $title .= $t_sep . $wp_locale->get_month( $monthnum );
1590          }
1591          if ( ! empty( $day ) ) {
1592              $title .= $t_sep . zeroise( $day, 2 );
1593          }
1594      }
1595  
1596      // If it's a search.
1597      if ( is_search() ) {
1598          /* translators: 1: Separator, 2: Search query. */
1599          $title = sprintf( __( 'Search Results %1$s %2$s' ), $t_sep, strip_tags( $search ) );
1600      }
1601  
1602      // If it's a 404 page.
1603      if ( is_404() ) {
1604          $title = __( 'Page not found' );
1605      }
1606  
1607      if ( ! is_string( $title ) ) {
1608          $title = '';
1609      }
1610  
1611      $prefix      = '';
1612      $title_array = array();
1613      if ( '' !== $title ) {
1614          $prefix      = " $sep ";
1615          $title_array = explode( $t_sep, $title );
1616      }
1617  
1618      /**
1619       * Filters the parts of the page title.
1620       *
1621       * @since 4.0.0
1622       *
1623       * @param string[] $title_array Array of parts of the page title.
1624       */
1625      $title_array = apply_filters( 'wp_title_parts', $title_array );
1626  
1627      // Determines position of the separator and direction of the breadcrumb.
1628      if ( 'right' === $seplocation ) { // Separator on right, so reverse the order.
1629          $title_array = array_reverse( $title_array );
1630          $title       = implode( " $sep ", $title_array ) . $prefix;
1631      } else {
1632          $title = $prefix . implode( " $sep ", $title_array );
1633      }
1634  
1635      /**
1636       * Filters the text of the page title.
1637       *
1638       * @since 2.0.0
1639       *
1640       * @param string $title       Page title.
1641       * @param string $sep         Title separator.
1642       * @param string $seplocation Location of the separator (either 'left' or 'right').
1643       */
1644      $title = apply_filters( 'wp_title', $title, $sep, $seplocation );
1645  
1646      // Send it out.
1647      if ( $display ) {
1648          echo $title;
1649      } else {
1650          return $title;
1651      }
1652  }
1653  
1654  /**
1655   * Displays or retrieves page title for post.
1656   *
1657   * This is optimized for single.php template file for displaying the post title.
1658   *
1659   * It does not support placing the separator after the title, but by leaving the
1660   * prefix parameter empty, you can set the title separator manually. The prefix
1661   * does not automatically place a space between the prefix, so if there should
1662   * be a space, the parameter value will need to have it at the end.
1663   *
1664   * @since 0.71
1665   *
1666   * @param string $prefix  Optional. What to display before the title.
1667   * @param bool   $display Optional. Whether to display or retrieve title. Default true.
1668   * @return string|null Title when retrieving.
1669   */
1670  function single_post_title( $prefix = '', $display = true ) {
1671      $_post = get_queried_object();
1672  
1673      if ( ! isset( $_post->post_title ) ) {
1674          return null;
1675      }
1676  
1677      /**
1678       * Filters the page title for a single post.
1679       *
1680       * @since 0.71
1681       *
1682       * @param string  $_post_title The single post page title.
1683       * @param WP_Post $_post       The current post.
1684       */
1685      $title = apply_filters( 'single_post_title', $_post->post_title, $_post );
1686      if ( $display ) {
1687          echo $prefix . $title;
1688      } else {
1689          return $prefix . $title;
1690      }
1691  }
1692  
1693  /**
1694   * Displays or retrieves title for a post type archive.
1695   *
1696   * This is optimized for archive.php and archive-{$post_type}.php template files
1697   * for displaying the title of the post type.
1698   *
1699   * @since 3.1.0
1700   *
1701   * @param string $prefix  Optional. What to display before the title.
1702   * @param bool   $display Optional. Whether to display or retrieve title. Default true.
1703   * @return string|null Title when retrieving, null when displaying or on failure.
1704   */
1705  function post_type_archive_title( $prefix = '', $display = true ) {
1706      if ( ! is_post_type_archive() ) {
1707          return null;
1708      }
1709  
1710      $post_type = get_query_var( 'post_type' );
1711      if ( is_array( $post_type ) ) {
1712          $post_type = reset( $post_type );
1713      }
1714  
1715      $post_type_obj = get_post_type_object( $post_type );
1716  
1717      /**
1718       * Filters the post type archive title.
1719       *
1720       * @since 3.1.0
1721       *
1722       * @param string $post_type_name Post type 'name' label.
1723       * @param string $post_type      Post type.
1724       */
1725      $title = apply_filters( 'post_type_archive_title', $post_type_obj->labels->name, $post_type );
1726  
1727      if ( $display ) {
1728          echo $prefix . $title;
1729      } else {
1730          return $prefix . $title;
1731      }
1732  }
1733  
1734  /**
1735   * Displays or retrieves page title for category archive.
1736   *
1737   * Useful for category template files for displaying the category page title.
1738   * The prefix does not automatically place a space between the prefix, so if
1739   * there should be a space, the parameter value will need to have it at the end.
1740   *
1741   * @since 0.71
1742   *
1743   * @param string $prefix  Optional. What to display before the title.
1744   * @param bool   $display Optional. Whether to display or retrieve title. Default true.
1745   * @return string|null Title when retrieving.
1746   */
1747  function single_cat_title( $prefix = '', $display = true ) {
1748      return single_term_title( $prefix, $display );
1749  }
1750  
1751  /**
1752   * Displays or retrieves page title for tag post archive.
1753   *
1754   * Useful for tag template files for displaying the tag page title. The prefix
1755   * does not automatically place a space between the prefix, so if there should
1756   * be a space, the parameter value will need to have it at the end.
1757   *
1758   * @since 2.3.0
1759   *
1760   * @param string $prefix  Optional. What to display before the title.
1761   * @param bool   $display Optional. Whether to display or retrieve title. Default true.
1762   * @return string|null Title when retrieving.
1763   */
1764  function single_tag_title( $prefix = '', $display = true ) {
1765      return single_term_title( $prefix, $display );
1766  }
1767  
1768  /**
1769   * Displays or retrieves page title for taxonomy term archive.
1770   *
1771   * Useful for taxonomy term template files for displaying the taxonomy term page title.
1772   * The prefix does not automatically place a space between the prefix, so if there should
1773   * be a space, the parameter value will need to have it at the end.
1774   *
1775   * @since 3.1.0
1776   *
1777   * @param string $prefix  Optional. What to display before the title.
1778   * @param bool   $display Optional. Whether to display or retrieve title. Default true.
1779   * @return string|null Title when retrieving.
1780   */
1781  function single_term_title( $prefix = '', $display = true ) {
1782      $term = get_queried_object();
1783  
1784      if ( ! $term ) {
1785          return null;
1786      }
1787  
1788      if ( is_category() ) {
1789          /**
1790           * Filters the category archive page title.
1791           *
1792           * @since 2.0.10
1793           *
1794           * @param string $term_name Category name for archive being displayed.
1795           */
1796          $term_name = apply_filters( 'single_cat_title', $term->name );
1797      } elseif ( is_tag() ) {
1798          /**
1799           * Filters the tag archive page title.
1800           *
1801           * @since 2.3.0
1802           *
1803           * @param string $term_name Tag name for archive being displayed.
1804           */
1805          $term_name = apply_filters( 'single_tag_title', $term->name );
1806      } elseif ( is_tax() ) {
1807          /**
1808           * Filters the custom taxonomy archive page title.
1809           *
1810           * @since 3.1.0
1811           *
1812           * @param string $term_name Term name for archive being displayed.
1813           */
1814          $term_name = apply_filters( 'single_term_title', $term->name );
1815      } else {
1816          return null;
1817      }
1818  
1819      if ( empty( $term_name ) ) {
1820          return null;
1821      }
1822  
1823      if ( $display ) {
1824          echo $prefix . $term_name;
1825      } else {
1826          return $prefix . $term_name;
1827      }
1828  }
1829  
1830  /**
1831   * Displays or retrieves page title for post archive based on date.
1832   *
1833   * Useful for when the template only needs to display the month and year,
1834   * if either are available. The prefix does not automatically place a space
1835   * between the prefix, so if there should be a space, the parameter value
1836   * will need to have it at the end.
1837   *
1838   * @since 0.71
1839   *
1840   * @global WP_Locale $wp_locale WordPress date and time locale object.
1841   *
1842   * @param string $prefix  Optional. What to display before the title.
1843   * @param bool   $display Optional. Whether to display or retrieve title. Default true.
1844   * @return string|false|null False if there's no valid title for the month. Title when retrieving.
1845   */
1846  function single_month_title( $prefix = '', $display = true ) {
1847      global $wp_locale;
1848  
1849      $m        = get_query_var( 'm' );
1850      $year     = get_query_var( 'year' );
1851      $monthnum = get_query_var( 'monthnum' );
1852  
1853      if ( ! empty( $monthnum ) && ! empty( $year ) ) {
1854          $my_year  = $year;
1855          $my_month = $wp_locale->get_month( $monthnum );
1856      } elseif ( ! empty( $m ) ) {
1857          $my_year  = substr( $m, 0, 4 );
1858          $my_month = $wp_locale->get_month( substr( $m, 4, 2 ) );
1859      }
1860  
1861      if ( empty( $my_month ) ) {
1862          return false;
1863      }
1864  
1865      $result = $prefix . $my_month . $prefix . $my_year;
1866  
1867      if ( ! $display ) {
1868          return $result;
1869      }
1870      echo $result;
1871  }
1872  
1873  /**
1874   * Displays the archive title based on the queried object.
1875   *
1876   * @since 4.1.0
1877   *
1878   * @see get_the_archive_title()
1879   *
1880   * @param string $before Optional. Content to prepend to the title. Default empty.
1881   * @param string $after  Optional. Content to append to the title. Default empty.
1882   */
1883  function the_archive_title( $before = '', $after = '' ) {
1884      $title = get_the_archive_title();
1885  
1886      if ( ! empty( $title ) ) {
1887          echo $before . $title . $after;
1888      }
1889  }
1890  
1891  /**
1892   * Retrieves the archive title based on the queried object.
1893   *
1894   * @since 4.1.0
1895   * @since 5.5.0 The title part is wrapped in a `<span>` element.
1896   *
1897   * @return string Archive title.
1898   */
1899  function get_the_archive_title() {
1900      $title  = __( 'Archives' );
1901      $prefix = '';
1902  
1903      if ( is_category() ) {
1904          $title  = single_cat_title( '', false );
1905          $prefix = _x( 'Category:', 'category archive title prefix' );
1906      } elseif ( is_tag() ) {
1907          $title  = single_tag_title( '', false );
1908          $prefix = _x( 'Tag:', 'tag archive title prefix' );
1909      } elseif ( is_author() ) {
1910          $title  = get_the_author();
1911          $prefix = _x( 'Author:', 'author archive title prefix' );
1912      } elseif ( is_year() ) {
1913          /* translators: See https://www.php.net/manual/datetime.format.php */
1914          $title  = get_the_date( _x( 'Y', 'yearly archives date format' ) );
1915          $prefix = _x( 'Year:', 'date archive title prefix' );
1916      } elseif ( is_month() ) {
1917          /* translators: See https://www.php.net/manual/datetime.format.php */
1918          $title  = get_the_date( _x( 'F Y', 'monthly archives date format' ) );
1919          $prefix = _x( 'Month:', 'date archive title prefix' );
1920      } elseif ( is_day() ) {
1921          /* translators: See https://www.php.net/manual/datetime.format.php */
1922          $title  = get_the_date( _x( 'F j, Y', 'daily archives date format' ) );
1923          $prefix = _x( 'Day:', 'date archive title prefix' );
1924      } elseif ( is_tax( 'post_format' ) ) {
1925          if ( is_tax( 'post_format', 'post-format-aside' ) ) {
1926              $title = _x( 'Asides', 'post format archive title' );
1927          } elseif ( is_tax( 'post_format', 'post-format-gallery' ) ) {
1928              $title = _x( 'Galleries', 'post format archive title' );
1929          } elseif ( is_tax( 'post_format', 'post-format-image' ) ) {
1930              $title = _x( 'Images', 'post format archive title' );
1931          } elseif ( is_tax( 'post_format', 'post-format-video' ) ) {
1932              $title = _x( 'Videos', 'post format archive title' );
1933          } elseif ( is_tax( 'post_format', 'post-format-quote' ) ) {
1934              $title = _x( 'Quotes', 'post format archive title' );
1935          } elseif ( is_tax( 'post_format', 'post-format-link' ) ) {
1936              $title = _x( 'Links', 'post format archive title' );
1937          } elseif ( is_tax( 'post_format', 'post-format-status' ) ) {
1938              $title = _x( 'Statuses', 'post format archive title' );
1939          } elseif ( is_tax( 'post_format', 'post-format-audio' ) ) {
1940              $title = _x( 'Audio', 'post format archive title' );
1941          } elseif ( is_tax( 'post_format', 'post-format-chat' ) ) {
1942              $title = _x( 'Chats', 'post format archive title' );
1943          }
1944      } elseif ( is_post_type_archive() ) {
1945          $title  = post_type_archive_title( '', false );
1946          $prefix = _x( 'Archives:', 'post type archive title prefix' );
1947      } elseif ( is_tax() ) {
1948          $queried_object = get_queried_object();
1949          if ( $queried_object ) {
1950              $tax    = get_taxonomy( $queried_object->taxonomy );
1951              $title  = single_term_title( '', false );
1952              $prefix = sprintf(
1953                  /* translators: %s: Taxonomy singular name. */
1954                  _x( '%s:', 'taxonomy term archive title prefix' ),
1955                  $tax->labels->singular_name
1956              );
1957          }
1958      }
1959  
1960      $original_title = $title;
1961  
1962      /**
1963       * Filters the archive title prefix.
1964       *
1965       * @since 5.5.0
1966       *
1967       * @param string $prefix Archive title prefix.
1968       */
1969      $prefix = apply_filters( 'get_the_archive_title_prefix', $prefix );
1970      if ( $prefix ) {
1971          $title = sprintf(
1972              /* translators: 1: Title prefix. 2: Title. */
1973              _x( '%1$s %2$s', 'archive title' ),
1974              $prefix,
1975              '<span>' . $title . '</span>'
1976          );
1977      }
1978  
1979      /**
1980       * Filters the archive title.
1981       *
1982       * @since 4.1.0
1983       * @since 5.5.0 Added the `$prefix` and `$original_title` parameters.
1984       *
1985       * @param string $title          Archive title to be displayed.
1986       * @param string $original_title Archive title without prefix.
1987       * @param string $prefix         Archive title prefix.
1988       */
1989      return apply_filters( 'get_the_archive_title', $title, $original_title, $prefix );
1990  }
1991  
1992  /**
1993   * Displays category, tag, term, or author description.
1994   *
1995   * @since 4.1.0
1996   *
1997   * @see get_the_archive_description()
1998   *
1999   * @param string $before Optional. Content to prepend to the description. Default empty.
2000   * @param string $after  Optional. Content to append to the description. Default empty.
2001   */
2002  function the_archive_description( $before = '', $after = '' ) {
2003      $description = get_the_archive_description();
2004      if ( $description ) {
2005          echo $before . $description . $after;
2006      }
2007  }
2008  
2009  /**
2010   * Retrieves the description for an author, post type, or term archive.
2011   *
2012   * @since 4.1.0
2013   * @since 4.7.0 Added support for author archives.
2014   * @since 4.9.0 Added support for post type archives.
2015   *
2016   * @see term_description()
2017   *
2018   * @return string Archive description.
2019   */
2020  function get_the_archive_description() {
2021      if ( is_author() ) {
2022          $description = get_the_author_meta( 'description' );
2023      } elseif ( is_post_type_archive() ) {
2024          $description = get_the_post_type_description();
2025      } else {
2026          $description = term_description();
2027      }
2028  
2029      /**
2030       * Filters the archive description.
2031       *
2032       * @since 4.1.0
2033       *
2034       * @param string $description Archive description to be displayed.
2035       */
2036      return apply_filters( 'get_the_archive_description', $description );
2037  }
2038  
2039  /**
2040   * Retrieves the description for a post type archive.
2041   *
2042   * @since 4.9.0
2043   *
2044   * @return string The post type description.
2045   */
2046  function get_the_post_type_description() {
2047      $post_type = get_query_var( 'post_type' );
2048  
2049      if ( is_array( $post_type ) ) {
2050          $post_type = reset( $post_type );
2051      }
2052  
2053      $post_type_obj = get_post_type_object( $post_type );
2054  
2055      // Check if a description is set.
2056      $description = $post_type_obj->description ?? '';
2057  
2058      /**
2059       * Filters the description for a post type archive.
2060       *
2061       * @since 4.9.0
2062       *
2063       * @param string       $description   The post type description.
2064       * @param WP_Post_Type $post_type_obj The post type object.
2065       */
2066      return apply_filters( 'get_the_post_type_description', $description, $post_type_obj );
2067  }
2068  
2069  /**
2070   * Retrieves archive link content based on predefined or custom code.
2071   *
2072   * The format can be one of four styles. The 'link' for head element, 'option'
2073   * for use in the select element, 'html' for use in list (either ol or ul HTML
2074   * elements). Custom content is also supported using the before and after
2075   * parameters.
2076   *
2077   * The 'link' format uses the `<link>` HTML element with the **archives**
2078   * relationship. The before and after parameters are not used. The text
2079   * parameter is used to describe the link.
2080   *
2081   * The 'option' format uses the option HTML element for use in select element.
2082   * The value is the url parameter and the before and after parameters are used
2083   * between the text description.
2084   *
2085   * The 'html' format, which is the default, uses the li HTML element for use in
2086   * the list HTML elements. The before parameter is before the link and the after
2087   * parameter is after the closing link.
2088   *
2089   * The custom format uses the before parameter before the link ('a' HTML
2090   * element) and the after parameter after the closing link tag. If the above
2091   * three values for the format are not used, then custom format is assumed.
2092   *
2093   * @since 1.0.0
2094   * @since 5.2.0 Added the `$selected` parameter.
2095   *
2096   * @param string $url      URL to archive.
2097   * @param string $text     Archive text description.
2098   * @param string $format   Optional. Can be 'link', 'option', 'html', or custom. Default 'html'.
2099   * @param string $before   Optional. Content to prepend to the description. Default empty.
2100   * @param string $after    Optional. Content to append to the description. Default empty.
2101   * @param bool   $selected Optional. Set to true if the current page is the selected archive page. Default false.
2102   * @return string HTML link content for archive.
2103   */
2104  function get_archives_link( $url, $text, $format = 'html', $before = '', $after = '', $selected = false ) {
2105      $text         = wptexturize( $text );
2106      $url          = esc_url( $url );
2107      $aria_current = $selected ? ' aria-current="page"' : '';
2108  
2109      if ( 'link' === $format ) {
2110          $link_html = "\t<link rel='archives' title='" . esc_attr( $text ) . "' href='$url' />\n";
2111      } elseif ( 'option' === $format ) {
2112          $selected_attr = $selected ? " selected='selected'" : '';
2113          $link_html     = "\t<option value='$url'$selected_attr>$before $text $after</option>\n";
2114      } elseif ( 'html' === $format ) {
2115          $link_html = "\t<li>$before<a href='$url'$aria_current>$text</a>$after</li>\n";
2116      } else { // Custom.
2117          $link_html = "\t$before<a href='$url'$aria_current>$text</a>$after\n";
2118      }
2119  
2120      /**
2121       * Filters the archive link content.
2122       *
2123       * @since 2.6.0
2124       * @since 4.5.0 Added the `$url`, `$text`, `$format`, `$before`, and `$after` parameters.
2125       * @since 5.2.0 Added the `$selected` parameter.
2126       *
2127       * @param string $link_html The archive HTML link content.
2128       * @param string $url       URL to archive.
2129       * @param string $text      Archive text description.
2130       * @param string $format    Link format. Can be 'link', 'option', 'html', or custom.
2131       * @param string $before    Content to prepend to the description.
2132       * @param string $after     Content to append to the description.
2133       * @param bool   $selected  True if the current page is the selected archive.
2134       */
2135      return apply_filters( 'get_archives_link', $link_html, $url, $text, $format, $before, $after, $selected );
2136  }
2137  
2138  /**
2139   * Displays archive links based on type and format.
2140   *
2141   * @since 1.2.0
2142   * @since 4.4.0 The `$post_type` argument was added.
2143   * @since 5.2.0 The `$year`, `$monthnum`, `$day`, and `$w` arguments were added.
2144   *
2145   * @see get_archives_link()
2146   *
2147   * @global wpdb      $wpdb      WordPress database abstraction object.
2148   * @global WP_Locale $wp_locale WordPress date and time locale object.
2149   *
2150   * @param string|array $args {
2151   *     Default archive links arguments. Optional.
2152   *
2153   *     @type string     $type            Type of archive to retrieve. Accepts 'daily', 'weekly', 'monthly',
2154   *                                       'yearly', 'postbypost', or 'alpha'. Both 'postbypost' and 'alpha'
2155   *                                       display the same archive link list as well as post titles instead
2156   *                                       of displaying dates. The difference between the two is that 'alpha'
2157   *                                       will order by post title and 'postbypost' will order by post date.
2158   *                                       Default 'monthly'.
2159   *     @type string|int $limit           Number of links to limit the query to. Default empty (no limit).
2160   *     @type string     $format          Format each link should take using the $before and $after args.
2161   *                                       Accepts 'link' (`<link>` tag), 'option' (`<option>` tag), 'html'
2162   *                                       (`<li>` tag), or a custom format, which generates a link anchor
2163   *                                       with $before preceding and $after succeeding. Default 'html'.
2164   *     @type string     $before          Markup to prepend to the beginning of each link. Default empty.
2165   *     @type string     $after           Markup to append to the end of each link. Default empty.
2166   *     @type bool       $show_post_count Whether to display the post count alongside the link. Default false.
2167   *     @type bool|int   $echo            Whether to echo or return the links list. Default 1|true to echo.
2168   *     @type string     $order           Whether to use ascending or descending order. Accepts 'ASC', or 'DESC'.
2169   *                                       Default 'DESC'.
2170   *     @type string     $post_type       Post type. Default 'post'.
2171   *     @type string     $year            Year. Default current year.
2172   *     @type string     $monthnum        Month number. Default current month number.
2173   *     @type string     $day             Day. Default current day.
2174   *     @type string     $w               Week. Default current week.
2175   * }
2176   * @return void|string Void if 'echo' argument is true, archive links if 'echo' is false.
2177   */
2178  function wp_get_archives( $args = '' ) {
2179      global $wpdb, $wp_locale;
2180  
2181      $defaults = array(
2182          'type'            => 'monthly',
2183          'limit'           => '',
2184          'format'          => 'html',
2185          'before'          => '',
2186          'after'           => '',
2187          'show_post_count' => false,
2188          'echo'            => 1,
2189          'order'           => 'DESC',
2190          'post_type'       => 'post',
2191          'year'            => get_query_var( 'year' ),
2192          'monthnum'        => get_query_var( 'monthnum' ),
2193          'day'             => get_query_var( 'day' ),
2194          'w'               => get_query_var( 'w' ),
2195      );
2196  
2197      /**
2198       * Filters the arguments for displaying archive links.
2199       *
2200       * @since 7.0.0
2201       *
2202       * @see wp_get_archives()
2203       *
2204       * @param array<string, string|int|bool> $args Arguments.
2205       */
2206      $args = apply_filters( 'wp_get_archives_args', $args );
2207  
2208      $parsed_args = wp_parse_args( $args, $defaults );
2209  
2210      $post_type_object = get_post_type_object( $parsed_args['post_type'] );
2211      if ( ! is_post_type_viewable( $post_type_object ) ) {
2212          return;
2213      }
2214  
2215      $parsed_args['post_type'] = $post_type_object->name;
2216  
2217      if ( '' === $parsed_args['type'] ) {
2218          $parsed_args['type'] = 'monthly';
2219      }
2220  
2221      if ( ! empty( $parsed_args['limit'] ) ) {
2222          $parsed_args['limit'] = absint( $parsed_args['limit'] );
2223          $parsed_args['limit'] = ' LIMIT ' . $parsed_args['limit'];
2224      }
2225  
2226      $order = strtoupper( $parsed_args['order'] );
2227      if ( 'ASC' !== $order ) {
2228          $order = 'DESC';
2229      }
2230  
2231      // This is what will separate dates on weekly archive links.
2232      $archive_week_separator = '&#8211;';
2233  
2234      $sql_where = $wpdb->prepare( "WHERE post_type = %s AND post_status = 'publish'", $parsed_args['post_type'] );
2235  
2236      /**
2237       * Filters the SQL WHERE clause for retrieving archives.
2238       *
2239       * @since 2.2.0
2240       *
2241       * @param string $sql_where   Portion of SQL query containing the WHERE clause.
2242       * @param array  $parsed_args An array of default arguments.
2243       */
2244      $where = apply_filters( 'getarchives_where', $sql_where, $parsed_args );
2245  
2246      /**
2247       * Filters the SQL JOIN clause for retrieving archives.
2248       *
2249       * @since 2.2.0
2250       *
2251       * @param string $sql_join    Portion of SQL query containing JOIN clause.
2252       * @param array  $parsed_args An array of default arguments.
2253       */
2254      $join = apply_filters( 'getarchives_join', '', $parsed_args );
2255  
2256      $output = '';
2257  
2258      $last_changed = wp_cache_get_last_changed( 'posts' );
2259  
2260      $limit = $parsed_args['limit'];
2261  
2262      if ( 'monthly' === $parsed_args['type'] ) {
2263          $query   = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date $order $limit";
2264          $key     = md5( $query );
2265          $key     = "wp_get_archives:$key";
2266          $results = wp_cache_get_salted( $key, 'post-queries', $last_changed );
2267          if ( ! $results ) {
2268              $results = $wpdb->get_results( $query );
2269              wp_cache_set_salted( $key, $results, 'post-queries', $last_changed );
2270          }
2271          if ( $results ) {
2272              $after = $parsed_args['after'];
2273              foreach ( (array) $results as $result ) {
2274                  $url = get_month_link( $result->year, $result->month );
2275                  if ( 'post' !== $parsed_args['post_type'] ) {
2276                      $url = add_query_arg( 'post_type', $parsed_args['post_type'], $url );
2277                  }
2278                  /* translators: 1: Month name, 2: 4-digit year. */
2279                  $text = sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $result->month ), $result->year );
2280                  if ( $parsed_args['show_post_count'] ) {
2281                      $parsed_args['after'] = '&nbsp;(' . $result->posts . ')' . $after;
2282                  }
2283                  $selected = is_archive() && (string) $parsed_args['year'] === $result->year && (string) $parsed_args['monthnum'] === $result->month;
2284                  $output  .= get_archives_link( $url, $text, $parsed_args['format'], $parsed_args['before'], $parsed_args['after'], $selected );
2285              }
2286          }
2287      } elseif ( 'yearly' === $parsed_args['type'] ) {
2288          $query   = "SELECT YEAR(post_date) AS `year`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date) ORDER BY post_date $order $limit";
2289          $key     = md5( $query );
2290          $key     = "wp_get_archives:$key";
2291          $results = wp_cache_get_salted( $key, 'post-queries', $last_changed );
2292          if ( ! $results ) {
2293              $results = $wpdb->get_results( $query );
2294              wp_cache_set_salted( $key, $results, 'post-queries', $last_changed );
2295          }
2296          if ( $results ) {
2297              $after = $parsed_args['after'];
2298              foreach ( (array) $results as $result ) {
2299                  $url = get_year_link( $result->year );
2300                  if ( 'post' !== $parsed_args['post_type'] ) {
2301                      $url = add_query_arg( 'post_type', $parsed_args['post_type'], $url );
2302                  }
2303                  $text = sprintf( '%d', $result->year );
2304                  if ( $parsed_args['show_post_count'] ) {
2305                      $parsed_args['after'] = '&nbsp;(' . $result->posts . ')' . $after;
2306                  }
2307                  $selected = is_archive() && (string) $parsed_args['year'] === $result->year;
2308                  $output  .= get_archives_link( $url, $text, $parsed_args['format'], $parsed_args['before'], $parsed_args['after'], $selected );
2309              }
2310          }
2311      } elseif ( 'daily' === $parsed_args['type'] ) {
2312          $query   = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date $order $limit";
2313          $key     = md5( $query );
2314          $key     = "wp_get_archives:$key";
2315          $results = wp_cache_get_salted( $key, 'post-queries', $last_changed );
2316          if ( ! $results ) {
2317              $results = $wpdb->get_results( $query );
2318              wp_cache_set_salted( $key, $results, 'post-queries', $last_changed );
2319          }
2320          if ( $results ) {
2321              $after = $parsed_args['after'];
2322              foreach ( (array) $results as $result ) {
2323                  $url = get_day_link( $result->year, $result->month, $result->dayofmonth );
2324                  if ( 'post' !== $parsed_args['post_type'] ) {
2325                      $url = add_query_arg( 'post_type', $parsed_args['post_type'], $url );
2326                  }
2327                  $date = sprintf( '%1$d-%2$02d-%3$02d 00:00:00', $result->year, $result->month, $result->dayofmonth );
2328                  $text = mysql2date( get_option( 'date_format' ), $date );
2329                  if ( $parsed_args['show_post_count'] ) {
2330                      $parsed_args['after'] = '&nbsp;(' . $result->posts . ')' . $after;
2331                  }
2332                  $selected = is_archive() && (string) $parsed_args['year'] === $result->year && (string) $parsed_args['monthnum'] === $result->month && (string) $parsed_args['day'] === $result->dayofmonth;
2333                  $output  .= get_archives_link( $url, $text, $parsed_args['format'], $parsed_args['before'], $parsed_args['after'], $selected );
2334              }
2335          }
2336      } elseif ( 'weekly' === $parsed_args['type'] ) {
2337          $week    = _wp_mysql_week( '`post_date`' );
2338          $query   = "SELECT DISTINCT $week AS `week`, YEAR( `post_date` ) AS `yr`, DATE_FORMAT( `post_date`, '%Y-%m-%d' ) AS `yyyymmdd`, count( `ID` ) AS `posts` FROM `$wpdb->posts` $join $where GROUP BY $week, YEAR( `post_date` ) ORDER BY `post_date` $order $limit";
2339          $key     = md5( $query );
2340          $key     = "wp_get_archives:$key";
2341          $results = wp_cache_get_salted( $key, 'post-queries', $last_changed );
2342          if ( ! $results ) {
2343              $results = $wpdb->get_results( $query );
2344              wp_cache_set_salted( $key, $results, 'post-queries', $last_changed );
2345          }
2346          $arc_w_last = '';
2347          if ( $results ) {
2348              $after = $parsed_args['after'];
2349              foreach ( (array) $results as $result ) {
2350                  if ( $result->week !== $arc_w_last ) {
2351                      $arc_year       = $result->yr;
2352                      $arc_w_last     = $result->week;
2353                      $arc_week       = get_weekstartend( $result->yyyymmdd, get_option( 'start_of_week' ) );
2354                      $arc_week_start = date_i18n( get_option( 'date_format' ), $arc_week['start'] );
2355                      $arc_week_end   = date_i18n( get_option( 'date_format' ), $arc_week['end'] );
2356                      $url            = add_query_arg(
2357                          array(
2358                              'm' => $arc_year,
2359                              'w' => $result->week,
2360                          ),
2361                          home_url( '/' )
2362                      );
2363                      if ( 'post' !== $parsed_args['post_type'] ) {
2364                          $url = add_query_arg( 'post_type', $parsed_args['post_type'], $url );
2365                      }
2366                      $text = $arc_week_start . $archive_week_separator . $arc_week_end;
2367                      if ( $parsed_args['show_post_count'] ) {
2368                          $parsed_args['after'] = '&nbsp;(' . $result->posts . ')' . $after;
2369                      }
2370                      $selected = is_archive() && (string) $parsed_args['year'] === $result->yr && (string) $parsed_args['w'] === $result->week;
2371                      $output  .= get_archives_link( $url, $text, $parsed_args['format'], $parsed_args['before'], $parsed_args['after'], $selected );
2372                  }
2373              }
2374          }
2375      } elseif ( ( 'postbypost' === $parsed_args['type'] ) || ( 'alpha' === $parsed_args['type'] ) ) {
2376          $orderby = ( 'alpha' === $parsed_args['type'] ) ? 'post_title ASC ' : 'post_date DESC, ID DESC ';
2377          $query   = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit";
2378          $key     = md5( $query );
2379          $key     = "wp_get_archives:$key";
2380          $results = wp_cache_get_salted( $key, 'post-queries', $last_changed );
2381          if ( ! $results ) {
2382              $results = $wpdb->get_results( $query );
2383              wp_cache_set_salted( $key, $results, 'post-queries', $last_changed );
2384          }
2385          if ( $results ) {
2386              foreach ( (array) $results as $result ) {
2387                  if ( '0000-00-00 00:00:00' !== $result->post_date ) {
2388                      $url = get_permalink( $result );
2389                      if ( $result->post_title ) {
2390                          /** This filter is documented in wp-includes/post-template.php */
2391                          $text = strip_tags( apply_filters( 'the_title', $result->post_title, $result->ID ) );
2392                      } else {
2393                          $text = $result->ID;
2394                      }
2395                      $selected = get_the_ID() === $result->ID;
2396                      $output  .= get_archives_link( $url, $text, $parsed_args['format'], $parsed_args['before'], $parsed_args['after'], $selected );
2397                  }
2398              }
2399          }
2400      }
2401  
2402      if ( $parsed_args['echo'] ) {
2403          echo $output;
2404      } else {
2405          return $output;
2406      }
2407  }
2408  
2409  /**
2410   * Gets number of days since the start of the week.
2411   *
2412   * @since 1.5.0
2413   *
2414   * @param int $num Number of day.
2415   * @return float Days since the start of the week.
2416   */
2417  function calendar_week_mod( $num ) {
2418      $base = 7;
2419      return ( $num - $base * floor( $num / $base ) );
2420  }
2421  
2422  /**
2423   * Displays calendar with days that have posts as links.
2424   *
2425   * The calendar is cached, which will be retrieved, if it exists. If there are
2426   * no posts for the month, then it will not be displayed.
2427   *
2428   * @since 1.0.0
2429   * @since 6.8.0 Added the `$args` parameter, with backward compatibility
2430   *              for the replaced `$initial` and `$display` parameters.
2431   *
2432   * @global wpdb      $wpdb      WordPress database abstraction object.
2433   * @global int       $m
2434   * @global int       $monthnum
2435   * @global int       $year
2436   * @global WP_Locale $wp_locale WordPress date and time locale object.
2437   * @global array     $posts
2438   *
2439   * @param array $args {
2440   *     Optional. Arguments for the `get_calendar` function.
2441   *
2442   *     @type bool   $initial   Whether to use initial calendar names. Default true.
2443   *     @type bool   $display   Whether to display the calendar output. Default true.
2444   *     @type string $post_type Optional. Post type. Default 'post'.
2445   * }
2446   * @return void|string Void if `$display` argument is true, calendar HTML if `$display` is false.
2447   */
2448  function get_calendar( $args = array() ) {
2449      global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
2450  
2451      $defaults = array(
2452          'initial'   => true,
2453          'display'   => true,
2454          'post_type' => 'post',
2455      );
2456  
2457      $original_args = func_get_args();
2458      $args          = array();
2459  
2460      if ( ! empty( $original_args ) ) {
2461          if ( ! is_array( $original_args[0] ) ) {
2462              if ( isset( $original_args[0] ) && is_bool( $original_args[0] ) ) {
2463                  $defaults['initial'] = $original_args[0];
2464              }
2465              if ( isset( $original_args[1] ) && is_bool( $original_args[1] ) ) {
2466                  $defaults['display'] = $original_args[1];
2467              }
2468          } else {
2469              $args = $original_args[0];
2470          }
2471      }
2472  
2473      /**
2474       * Filter the `get_calendar` function arguments before they are used.
2475       *
2476       * @since 6.8.0
2477       *
2478       * @param array $args {
2479       *     Optional. Arguments for the `get_calendar` function.
2480       *
2481       *     @type bool   $initial   Whether to use initial calendar names. Default true.
2482       *     @type bool   $display   Whether to display the calendar output. Default true.
2483       *     @type string $post_type Optional. Post type. Default 'post'.
2484       * }
2485       */
2486      $args = apply_filters( 'get_calendar_args', wp_parse_args( $args, $defaults ) );
2487  
2488      if ( ! post_type_exists( $args['post_type'] ) ) {
2489          $args['post_type'] = 'post';
2490      }
2491  
2492      $w = 0;
2493      if ( isset( $_GET['w'] ) ) {
2494          $w = (int) $_GET['w'];
2495      }
2496  
2497      /*
2498       * Normalize the cache key.
2499       *
2500       * The following ensures the same cache key is used for the same parameter
2501       * and parameter equivalents. This prevents `post_type > post, initial > true`
2502       * from generating a different key from the same values in the reverse order.
2503       *
2504       * `display` is excluded from the cache key as the cache contains the same
2505       * HTML regardless of this function's need to echo or return the output.
2506       *
2507       * The global values contain data generated by the URL query string variables.
2508       */
2509      $cache_args = $args;
2510      unset( $cache_args['display'] );
2511  
2512      $cache_args['globals'] = array(
2513          'm'        => $m,
2514          'monthnum' => $monthnum,
2515          'year'     => $year,
2516          'week'     => $w,
2517      );
2518  
2519      wp_recursive_ksort( $cache_args );
2520      $key   = md5( serialize( $cache_args ) );
2521      $cache = wp_cache_get( 'get_calendar', 'calendar' );
2522  
2523      if ( $cache && is_array( $cache ) && isset( $cache[ $key ] ) ) {
2524          /** This filter is documented in wp-includes/general-template.php */
2525          $output = apply_filters( 'get_calendar', $cache[ $key ], $args );
2526  
2527          if ( $args['display'] ) {
2528              echo $output;
2529              return;
2530          }
2531  
2532          return $output;
2533      }
2534  
2535      if ( ! is_array( $cache ) ) {
2536          $cache = array();
2537      }
2538  
2539      $post_type = $args['post_type'];
2540  
2541      // Quick check. If we have no posts at all, abort!
2542      if ( ! $posts ) {
2543          $gotsome = $wpdb->get_var(
2544              $wpdb->prepare(
2545                  "SELECT 1 as test
2546                  FROM $wpdb->posts
2547                  WHERE post_type = %s
2548                  AND post_status = 'publish'
2549                  LIMIT 1",
2550                  $post_type
2551              )
2552          );
2553  
2554          if ( ! $gotsome ) {
2555              $cache[ $key ] = '';
2556              wp_cache_set( 'get_calendar', $cache, 'calendar' );
2557              return;
2558          }
2559      }
2560  
2561      // week_begins = 0 stands for Sunday.
2562      $week_begins = (int) get_option( 'start_of_week' );
2563  
2564      // Let's figure out when we are.
2565      if ( ! empty( $monthnum ) && ! empty( $year ) ) {
2566          $thismonth = (int) $monthnum;
2567          $thisyear  = (int) $year;
2568      } elseif ( ! empty( $w ) ) {
2569          // We need to get the month from MySQL.
2570          $thisyear = (int) substr( $m, 0, 4 );
2571          // It seems MySQL's weeks disagree with PHP's.
2572          $d         = ( ( $w - 1 ) * 7 ) + 6;
2573          $thismonth = (int) $wpdb->get_var(
2574              $wpdb->prepare(
2575                  "SELECT DATE_FORMAT((DATE_ADD('%d0101', INTERVAL %d DAY) ), '%%m')",
2576                  $thisyear,
2577                  $d
2578              )
2579          );
2580      } elseif ( ! empty( $m ) ) {
2581          $thisyear = (int) substr( $m, 0, 4 );
2582          if ( strlen( $m ) < 6 ) {
2583              $thismonth = 1;
2584          } else {
2585              $thismonth = (int) substr( $m, 4, 2 );
2586          }
2587      } else {
2588          $thisyear  = (int) current_time( 'Y' );
2589          $thismonth = (int) current_time( 'm' );
2590      }
2591  
2592      $unixmonth = mktime( 0, 0, 0, $thismonth, 1, $thisyear );
2593      $last_day  = gmdate( 't', $unixmonth );
2594  
2595      // Get the next and previous month and year with at least one post.
2596      $previous = $wpdb->get_row(
2597          $wpdb->prepare(
2598              "SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
2599              FROM $wpdb->posts
2600              WHERE post_date < '%d-%d-01'
2601              AND post_type = %s AND post_status = 'publish'
2602              ORDER BY post_date DESC
2603              LIMIT 1",
2604              $thisyear,
2605              zeroise( $thismonth, 2 ),
2606              $post_type
2607          )
2608      );
2609  
2610      $next = $wpdb->get_row(
2611          $wpdb->prepare(
2612              "SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
2613              FROM $wpdb->posts
2614              WHERE post_date > '%d-%d-%d 23:59:59'
2615              AND post_type = %s AND post_status = 'publish'
2616              ORDER BY post_date ASC
2617              LIMIT 1",
2618              $thisyear,
2619              zeroise( $thismonth, 2 ),
2620              $last_day,
2621              $post_type
2622          )
2623      );
2624  
2625      /* translators: Calendar caption: 1: Month name, 2: 4-digit year. */
2626      $calendar_caption = _x( '%1$s %2$s', 'calendar caption' );
2627      $calendar_output  = '<table id="wp-calendar" class="wp-calendar-table">
2628      <caption>' . sprintf(
2629          $calendar_caption,
2630          $wp_locale->get_month( $thismonth ),
2631          gmdate( 'Y', $unixmonth )
2632      ) . '</caption>
2633      <thead>
2634      <tr>';
2635  
2636      $myweek = array();
2637  
2638      for ( $wdcount = 0; $wdcount <= 6; $wdcount++ ) {
2639          $myweek[] = $wp_locale->get_weekday( ( $wdcount + $week_begins ) % 7 );
2640      }
2641  
2642      foreach ( $myweek as $wd ) {
2643          $day_name         = $args['initial'] ? $wp_locale->get_weekday_initial( $wd ) : $wp_locale->get_weekday_abbrev( $wd );
2644          $wd               = esc_attr( $wd );
2645          $calendar_output .= "\n\t\t<th scope=\"col\" aria-label=\"$wd\">$day_name</th>";
2646      }
2647  
2648      $calendar_output .= '
2649      </tr>
2650      </thead>
2651      <tbody>
2652      <tr>';
2653  
2654      $daywithpost = array();
2655  
2656      // Get days with posts.
2657      $dayswithposts = $wpdb->get_results(
2658          $wpdb->prepare(
2659              "SELECT DISTINCT DAYOFMONTH(post_date)
2660              FROM $wpdb->posts WHERE post_date >= '%d-%d-01 00:00:00'
2661              AND post_type = %s AND post_status = 'publish'
2662              AND post_date <= '%d-%d-%d 23:59:59'",
2663              $thisyear,
2664              zeroise( $thismonth, 2 ),
2665              $post_type,
2666              $thisyear,
2667              zeroise( $thismonth, 2 ),
2668              $last_day
2669          ),
2670          ARRAY_N
2671      );
2672  
2673      if ( $dayswithposts ) {
2674          foreach ( (array) $dayswithposts as $daywith ) {
2675              $daywithpost[] = (int) $daywith[0];
2676          }
2677      }
2678  
2679      // See how much we should pad in the beginning.
2680      $pad = calendar_week_mod( (int) gmdate( 'w', $unixmonth ) - $week_begins );
2681      if ( $pad > 0 ) {
2682          $calendar_output .= "\n\t\t" . '<td colspan="' . esc_attr( $pad ) . '" class="pad">&nbsp;</td>';
2683      }
2684  
2685      $newrow      = false;
2686      $daysinmonth = (int) gmdate( 't', $unixmonth );
2687  
2688      for ( $day = 1; $day <= $daysinmonth; ++$day ) {
2689          if ( $newrow ) {
2690              $calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t";
2691          }
2692  
2693          $newrow = false;
2694  
2695          if ( (int) current_time( 'j' ) === $day
2696              && (int) current_time( 'm' ) === $thismonth
2697              && (int) current_time( 'Y' ) === $thisyear
2698          ) {
2699              $calendar_output .= '<td id="today">';
2700          } else {
2701              $calendar_output .= '<td>';
2702          }
2703  
2704          if ( in_array( $day, $daywithpost, true ) ) {
2705              // Any posts today?
2706              $date_format = gmdate( _x( 'F j, Y', 'daily archives date format' ), strtotime( "{$thisyear}-{$thismonth}-{$day}" ) );
2707              /* translators: Post calendar label. %s: Date. */
2708              $label            = sprintf( __( 'Posts published on %s' ), $date_format );
2709              $calendar_output .= sprintf(
2710                  '<a href="%s" aria-label="%s">%s</a>',
2711                  get_day_link( $thisyear, $thismonth, $day ),
2712                  esc_attr( $label ),
2713                  $day
2714              );
2715          } else {
2716              $calendar_output .= $day;
2717          }
2718  
2719          $calendar_output .= '</td>';
2720  
2721          if ( 6 === (int) calendar_week_mod( (int) gmdate( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins ) ) {
2722              $newrow = true;
2723          }
2724      }
2725  
2726      $pad = 7 - calendar_week_mod( (int) gmdate( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins );
2727      if ( 0 < $pad && $pad < 7 ) {
2728          $calendar_output .= "\n\t\t" . '<td class="pad" colspan="' . esc_attr( $pad ) . '">&nbsp;</td>';
2729      }
2730  
2731      $calendar_output .= "\n\t</tr>\n\t</tbody>";
2732  
2733      $calendar_output .= "\n\t</table>";
2734  
2735      $calendar_output .= '<nav aria-label="' . __( 'Previous and next months' ) . '" class="wp-calendar-nav">';
2736  
2737      if ( $previous ) {
2738          $calendar_output .= "\n\t\t" . sprintf(
2739              '<span class="wp-calendar-nav-prev"><a href="%1$s">&laquo; %2$s</a></span>',
2740              get_month_link( $previous->year, $previous->month ),
2741              $wp_locale->get_month_abbrev( $wp_locale->get_month( $previous->month ) )
2742          );
2743      } else {
2744          $calendar_output .= "\n\t\t" . '<span class="wp-calendar-nav-prev">&nbsp;</span>';
2745      }
2746  
2747      $calendar_output .= "\n\t\t" . '<span class="pad">&nbsp;</span>';
2748  
2749      if ( $next ) {
2750          $calendar_output .= "\n\t\t" . sprintf(
2751              '<span class="wp-calendar-nav-next"><a href="%1$s">%2$s &raquo;</a></span>',
2752              get_month_link( $next->year, $next->month ),
2753              $wp_locale->get_month_abbrev( $wp_locale->get_month( $next->month ) )
2754          );
2755      } else {
2756          $calendar_output .= "\n\t\t" . '<span class="wp-calendar-nav-next">&nbsp;</span>';
2757      }
2758  
2759      $calendar_output .= '
2760      </nav>';
2761  
2762      $cache[ $key ] = $calendar_output;
2763      wp_cache_set( 'get_calendar', $cache, 'calendar' );
2764  
2765      /**
2766       * Filters the HTML calendar output.
2767       *
2768       * @since 3.0.0
2769       * @since 6.8.0 Added the `$args` parameter.
2770       *
2771       * @param string $calendar_output HTML output of the calendar.
2772       * @param array  $args {
2773       *     Optional. Array of display arguments.
2774       *
2775       *     @type bool   $initial   Whether to use initial calendar names. Default true.
2776       *     @type bool   $display   Whether to display the calendar output. Default true.
2777       *     @type string $post_type Optional. Post type. Default 'post'.
2778       * }
2779       */
2780      $calendar_output = apply_filters( 'get_calendar', $calendar_output, $args );
2781  
2782      if ( $args['display'] ) {
2783          echo $calendar_output;
2784          return;
2785      }
2786  
2787      return $calendar_output;
2788  }
2789  
2790  /**
2791   * Purges the cached results of get_calendar.
2792   *
2793   * @see get_calendar()
2794   * @since 2.1.0
2795   */
2796  function delete_get_calendar_cache() {
2797      wp_cache_delete( 'get_calendar', 'calendar' );
2798  }
2799  
2800  /**
2801   * Displays all of the allowed tags in HTML format with attributes.
2802   *
2803   * This is useful for displaying in the comment area, which elements and
2804   * attributes are supported. As well as any plugins which want to display it.
2805   *
2806   * @since 1.0.1
2807   * @since 4.4.0 No longer used in core.
2808   *
2809   * @global array $allowedtags
2810   *
2811   * @return string HTML allowed tags entity encoded.
2812   */
2813  function allowed_tags() {
2814      global $allowedtags;
2815      $allowed = '';
2816      foreach ( (array) $allowedtags as $tag => $attributes ) {
2817          $allowed .= '<' . $tag;
2818          if ( 0 < count( $attributes ) ) {
2819              foreach ( $attributes as $attribute => $limits ) {
2820                  $allowed .= ' ' . $attribute . '=""';
2821              }
2822          }
2823          $allowed .= '> ';
2824      }
2825      return htmlentities( $allowed );
2826  }
2827  
2828  /***** Date/Time tags */
2829  
2830  /**
2831   * Outputs the date in iso8601 format for xml files.
2832   *
2833   * @since 1.0.0
2834   */
2835  function the_date_xml() {
2836      echo mysql2date( 'Y-m-d', get_post()->post_date, false );
2837  }
2838  
2839  /**
2840   * Displays or retrieves the date of the post (once per date).
2841   *
2842   * Will only output the date if the current post's date is different from the
2843   * previous one output.
2844   *
2845   * i.e. Only one date listing will show per day worth of posts shown in the loop, even if the
2846   * function is called several times for each post.
2847   *
2848   * HTML output can be filtered with {@see 'the_date'}.
2849   * Date string output can be filtered with {@see 'get_the_date'}.
2850   *
2851   * @since 0.71
2852   *
2853   * @global string $currentday  The day of the current post in the loop.
2854   * @global string $previousday The day of the previous post in the loop.
2855   *
2856   * @param string $format  Optional. PHP date format. Defaults to the 'date_format' option.
2857   * @param string $before  Optional. Output before the date. Default empty.
2858   * @param string $after   Optional. Output after the date. Default empty.
2859   * @param bool   $display Optional. Whether to echo the date or return it. Default true.
2860   * @return string|null String if retrieving.
2861   */
2862  function the_date( $format = '', $before = '', $after = '', $display = true ) {
2863      global $currentday, $previousday;
2864  
2865      $the_date = '';
2866  
2867      if ( is_new_day() ) {
2868          $the_date    = $before . get_the_date( $format ) . $after;
2869          $previousday = $currentday;
2870      }
2871  
2872      /**
2873       * Filters the date of the post, for display.
2874       *
2875       * @since 0.71
2876       *
2877       * @param string $the_date The formatted date string.
2878       * @param string $format   PHP date format.
2879       * @param string $before   HTML output before the date.
2880       * @param string $after    HTML output after the date.
2881       */
2882      $the_date = apply_filters( 'the_date', $the_date, $format, $before, $after );
2883  
2884      if ( $display ) {
2885          echo $the_date;
2886      } else {
2887          return $the_date;
2888      }
2889  }
2890  
2891  /**
2892   * Retrieves the date of the post.
2893   *
2894   * Unlike the_date() this function will always return the date.
2895   * Modify output with the {@see 'get_the_date'} filter.
2896   *
2897   * @since 3.0.0
2898   *
2899   * @param string           $format Optional. PHP date format. Defaults to the 'date_format' option.
2900   * @param int|WP_Post|null $post   Optional. Post ID or WP_Post object. Default current post.
2901   * @return string|int|false Date the current post was written. False on failure.
2902   */
2903  function get_the_date( $format = '', $post = null ) {
2904      $post = get_post( $post );
2905  
2906      if ( ! $post ) {
2907          return false;
2908      }
2909  
2910      $_format = ! empty( $format ) ? $format : get_option( 'date_format' );
2911  
2912      $the_date = get_post_time( $_format, false, $post, true );
2913  
2914      /**
2915       * Filters the date of the post.
2916       *
2917       * @since 3.0.0
2918       *
2919       * @param string|int $the_date Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
2920       * @param string     $format   PHP date format.
2921       * @param WP_Post    $post     The post object.
2922       */
2923      return apply_filters( 'get_the_date', $the_date, $format, $post );
2924  }
2925  
2926  /**
2927   * Displays the date on which the post was last modified.
2928   *
2929   * @since 2.1.0
2930   *
2931   * @param string $format  Optional. PHP date format. Defaults to the 'date_format' option.
2932   * @param string $before  Optional. Output before the date. Default empty.
2933   * @param string $after   Optional. Output after the date. Default empty.
2934   * @param bool   $display Optional. Whether to echo the date or return it. Default true.
2935   * @return string|null String if retrieving.
2936   */
2937  function the_modified_date( $format = '', $before = '', $after = '', $display = true ) {
2938      $the_modified_date = $before . get_the_modified_date( $format ) . $after;
2939  
2940      /**
2941       * Filters the date a post was last modified, for display.
2942       *
2943       * @since 2.1.0
2944       *
2945       * @param string $the_modified_date The last modified date.
2946       * @param string $format            PHP date format.
2947       * @param string $before            HTML output before the date.
2948       * @param string $after             HTML output after the date.
2949       */
2950      $the_modified_date = apply_filters( 'the_modified_date', $the_modified_date, $format, $before, $after );
2951  
2952      if ( $display ) {
2953          echo $the_modified_date;
2954      } else {
2955          return $the_modified_date;
2956      }
2957  }
2958  
2959  /**
2960   * Retrieves the date on which the post was last modified.
2961   *
2962   * @since 2.1.0
2963   * @since 4.6.0 Added the `$post` parameter.
2964   *
2965   * @param string           $format Optional. PHP date format. Defaults to the 'date_format' option.
2966   * @param int|WP_Post|null $post   Optional. Post ID or WP_Post object. Default current post.
2967   * @return string|int|false Date the current post was modified. False on failure.
2968   */
2969  function get_the_modified_date( $format = '', $post = null ) {
2970      $post = get_post( $post );
2971  
2972      if ( ! $post ) {
2973          // For backward compatibility, failures go through the filter below.
2974          $the_time = false;
2975      } else {
2976          $_format = ! empty( $format ) ? $format : get_option( 'date_format' );
2977  
2978          $the_time = get_post_modified_time( $_format, false, $post, true );
2979      }
2980  
2981      /**
2982       * Filters the date a post was last modified.
2983       *
2984       * @since 2.1.0
2985       * @since 4.6.0 Added the `$post` parameter.
2986       *
2987       * @param string|int|false $the_time The formatted date or false if no post is found.
2988       * @param string           $format   PHP date format.
2989       * @param WP_Post|null     $post     WP_Post object or null if no post is found.
2990       */
2991      return apply_filters( 'get_the_modified_date', $the_time, $format, $post );
2992  }
2993  
2994  /**
2995   * Displays the time of the post.
2996   *
2997   * @since 0.71
2998   *
2999   * @param string $format Optional. Format to use for retrieving the time the post
3000   *                       was written. Accepts 'G', 'U', or PHP date format.
3001   *                       Defaults to the 'time_format' option.
3002   */
3003  function the_time( $format = '' ) {
3004      /**
3005       * Filters the time of the post, for display.
3006       *
3007       * @since 0.71
3008       *
3009       * @param string $get_the_time The formatted time.
3010       * @param string $format       Format to use for retrieving the time the post
3011       *                             was written. Accepts 'G', 'U', or PHP date format.
3012       */
3013      echo apply_filters( 'the_time', get_the_time( $format ), $format );
3014  }
3015  
3016  /**
3017   * Retrieves the time of the post.
3018   *
3019   * @since 1.5.0
3020   *
3021   * @param string           $format Optional. Format to use for retrieving the time the post
3022   *                                 was written. Accepts 'G', 'U', or PHP date format.
3023   *                                 Defaults to the 'time_format' option.
3024   * @param int|WP_Post|null $post   Post ID or post object. Default is global `$post` object.
3025   * @return string|int|false Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
3026   *                          False on failure.
3027   */
3028  function get_the_time( $format = '', $post = null ) {
3029      $post = get_post( $post );
3030  
3031      if ( ! $post ) {
3032          return false;
3033      }
3034  
3035      $_format = ! empty( $format ) ? $format : get_option( 'time_format' );
3036  
3037      $the_time = get_post_time( $_format, false, $post, true );
3038  
3039      /**
3040       * Filters the time of the post.
3041       *
3042       * @since 1.5.0
3043       *
3044       * @param string|int $the_time Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
3045       * @param string     $format   Format to use for retrieving the time the post
3046       *                             was written. Accepts 'G', 'U', or PHP date format.
3047       * @param WP_Post    $post     Post object.
3048       */
3049      return apply_filters( 'get_the_time', $the_time, $format, $post );
3050  }
3051  
3052  /**
3053   * Retrieves the localized time of the post.
3054   *
3055   * @since 2.0.0
3056   *
3057   * @param string           $format    Optional. Format to use for retrieving the time the post
3058   *                                    was written. Accepts 'G', 'U', or PHP date format. Default 'U'.
3059   * @param bool             $gmt       Optional. Whether to retrieve the GMT time. Default false.
3060   * @param int|WP_Post|null $post      Post ID or post object. Default is global `$post` object.
3061   * @param bool             $translate Whether to translate the time string. Default false.
3062   * @return string|int|false Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
3063   *                          False on failure.
3064   */
3065  function get_post_time( $format = 'U', $gmt = false, $post = null, $translate = false ) {
3066      $post = get_post( $post );
3067  
3068      if ( ! $post ) {
3069          return false;
3070      }
3071  
3072      $source   = ( $gmt ) ? 'gmt' : 'local';
3073      $datetime = get_post_datetime( $post, 'date', $source );
3074  
3075      if ( false === $datetime ) {
3076          return false;
3077      }
3078  
3079      if ( 'U' === $format || 'G' === $format ) {
3080          $time = $datetime->getTimestamp();
3081  
3082          // Returns a sum of timestamp with timezone offset. Ideally should never be used.
3083          if ( ! $gmt ) {
3084              $time += $datetime->getOffset();
3085          }
3086      } elseif ( $translate ) {
3087          $time = wp_date( $format, $datetime->getTimestamp(), $gmt ? new DateTimeZone( 'UTC' ) : null );
3088      } else {
3089          if ( $gmt ) {
3090              $datetime = $datetime->setTimezone( new DateTimeZone( 'UTC' ) );
3091          }
3092  
3093          $time = $datetime->format( $format );
3094      }
3095  
3096      /**
3097       * Filters the localized time of the post.
3098       *
3099       * @since 2.6.0
3100       *
3101       * @param string|int $time   Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
3102       * @param string     $format Format to use for retrieving the date of the post.
3103       *                           Accepts 'G', 'U', or PHP date format.
3104       * @param bool       $gmt    Whether to retrieve the GMT time.
3105       */
3106      return apply_filters( 'get_post_time', $time, $format, $gmt );
3107  }
3108  
3109  /**
3110   * Retrieves post published or modified time as a `DateTimeImmutable` object instance.
3111   *
3112   * The object will be set to the timezone from WordPress settings.
3113   *
3114   * For legacy reasons, this function allows to choose to instantiate from local or UTC time in database.
3115   * Normally this should make no difference to the result. However, the values might get out of sync in database,
3116   * typically because of timezone setting changes. The parameter ensures the ability to reproduce backwards
3117   * compatible behaviors in such cases.
3118   *
3119   * @since 5.3.0
3120   *
3121   * @param int|WP_Post|null $post   Optional. Post ID or post object. Default is global `$post` object.
3122   * @param string           $field  Optional. Published or modified time to use from database. Accepts 'date' or 'modified'.
3123   *                                 Default 'date'.
3124   * @param string           $source Optional. Local or UTC time to use from database. Accepts 'local' or 'gmt'.
3125   *                                 Default 'local'.
3126   * @return DateTimeImmutable|false Time object on success, false on failure.
3127   */
3128  function get_post_datetime( $post = null, $field = 'date', $source = 'local' ) {
3129      $post = get_post( $post );
3130  
3131      if ( ! $post ) {
3132          return false;
3133      }
3134  
3135      $wp_timezone = wp_timezone();
3136  
3137      if ( 'gmt' === $source ) {
3138          $time     = ( 'modified' === $field ) ? $post->post_modified_gmt : $post->post_date_gmt;
3139          $timezone = new DateTimeZone( 'UTC' );
3140      } else {
3141          $time     = ( 'modified' === $field ) ? $post->post_modified : $post->post_date;
3142          $timezone = $wp_timezone;
3143      }
3144  
3145      if ( empty( $time ) || '0000-00-00 00:00:00' === $time ) {
3146          return false;
3147      }
3148  
3149      $datetime = date_create_immutable_from_format( 'Y-m-d H:i:s', $time, $timezone );
3150  
3151      if ( false === $datetime ) {
3152          return false;
3153      }
3154  
3155      return $datetime->setTimezone( $wp_timezone );
3156  }
3157  
3158  /**
3159   * Retrieves post published or modified time as a Unix timestamp.
3160   *
3161   * Note that this function returns a true Unix timestamp, not summed with timezone offset
3162   * like older WP functions.
3163   *
3164   * @since 5.3.0
3165   *
3166   * @param int|WP_Post|null $post  Optional. Post ID or post object. Default is global `$post` object.
3167   * @param string           $field Optional. Published or modified time to use from database. Accepts 'date' or 'modified'.
3168   *                                Default 'date'.
3169   * @return int|false Unix timestamp on success, false on failure.
3170   */
3171  function get_post_timestamp( $post = null, $field = 'date' ) {
3172      $datetime = get_post_datetime( $post, $field );
3173  
3174      if ( false === $datetime ) {
3175          return false;
3176      }
3177  
3178      return $datetime->getTimestamp();
3179  }
3180  
3181  /**
3182   * Displays the time at which the post was last modified.
3183   *
3184   * @since 2.0.0
3185   *
3186   * @param string $format Optional. Format to use for retrieving the time the post
3187   *                       was modified. Accepts 'G', 'U', or PHP date format.
3188   *                       Defaults to the 'time_format' option.
3189   */
3190  function the_modified_time( $format = '' ) {
3191      /**
3192       * Filters the localized time a post was last modified, for display.
3193       *
3194       * @since 2.0.0
3195       *
3196       * @param string|false $get_the_modified_time The formatted time or false if no post is found.
3197       * @param string       $format                Format to use for retrieving the time the post
3198       *                                            was modified. Accepts 'G', 'U', or PHP date format.
3199       */
3200      echo apply_filters( 'the_modified_time', get_the_modified_time( $format ), $format );
3201  }
3202  
3203  /**
3204   * Retrieves the time at which the post was last modified.
3205   *
3206   * @since 2.0.0
3207   * @since 4.6.0 Added the `$post` parameter.
3208   *
3209   * @param string           $format Optional. Format to use for retrieving the time the post
3210   *                                 was modified. Accepts 'G', 'U', or PHP date format.
3211   *                                 Defaults to the 'time_format' option.
3212   * @param int|WP_Post|null $post   Optional. Post ID or WP_Post object. Default current post.
3213   * @return string|int|false Formatted date string or Unix timestamp. False on failure.
3214   */
3215  function get_the_modified_time( $format = '', $post = null ) {
3216      $post = get_post( $post );
3217  
3218      if ( ! $post ) {
3219          // For backward compatibility, failures go through the filter below.
3220          $the_time = false;
3221      } else {
3222          $_format = ! empty( $format ) ? $format : get_option( 'time_format' );
3223  
3224          $the_time = get_post_modified_time( $_format, false, $post, true );
3225      }
3226  
3227      /**
3228       * Filters the localized time a post was last modified.
3229       *
3230       * @since 2.0.0
3231       * @since 4.6.0 Added the `$post` parameter.
3232       *
3233       * @param string|int|false $the_time The formatted time or false if no post is found.
3234       * @param string           $format   Format to use for retrieving the time the post
3235       *                                   was modified. Accepts 'G', 'U', or PHP date format.
3236       * @param WP_Post|null     $post     WP_Post object or null if no post is found.
3237       */
3238      return apply_filters( 'get_the_modified_time', $the_time, $format, $post );
3239  }
3240  
3241  /**
3242   * Retrieves the time at which the post was last modified.
3243   *
3244   * @since 2.0.0
3245   *
3246   * @param string           $format    Optional. Format to use for retrieving the time the post
3247   *                                    was modified. Accepts 'G', 'U', or PHP date format. Default 'U'.
3248   * @param bool             $gmt       Optional. Whether to retrieve the GMT time. Default false.
3249   * @param int|WP_Post|null $post      Post ID or post object. Default is global `$post` object.
3250   * @param bool             $translate Whether to translate the time string. Default false.
3251   * @return string|int|false Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
3252   *                          False on failure.
3253   */
3254  function get_post_modified_time( $format = 'U', $gmt = false, $post = null, $translate = false ) {
3255      $post = get_post( $post );
3256  
3257      if ( ! $post ) {
3258          return false;
3259      }
3260  
3261      $source   = ( $gmt ) ? 'gmt' : 'local';
3262      $datetime = get_post_datetime( $post, 'modified', $source );
3263  
3264      if ( false === $datetime ) {
3265          return false;
3266      }
3267  
3268      if ( 'U' === $format || 'G' === $format ) {
3269          $time = $datetime->getTimestamp();
3270  
3271          // Returns a sum of timestamp with timezone offset. Ideally should never be used.
3272          if ( ! $gmt ) {
3273              $time += $datetime->getOffset();
3274          }
3275      } elseif ( $translate ) {
3276          $time = wp_date( $format, $datetime->getTimestamp(), $gmt ? new DateTimeZone( 'UTC' ) : null );
3277      } else {
3278          if ( $gmt ) {
3279              $datetime = $datetime->setTimezone( new DateTimeZone( 'UTC' ) );
3280          }
3281  
3282          $time = $datetime->format( $format );
3283      }
3284  
3285      /**
3286       * Filters the localized time a post was last modified.
3287       *
3288       * @since 2.8.0
3289       *
3290       * @param string|int $time   Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
3291       * @param string     $format Format to use for retrieving the time the post was modified.
3292       *                           Accepts 'G', 'U', or PHP date format. Default 'U'.
3293       * @param bool       $gmt    Whether to retrieve the GMT time. Default false.
3294       */
3295      return apply_filters( 'get_post_modified_time', $time, $format, $gmt );
3296  }
3297  
3298  /**
3299   * Displays the localized weekday for the post.
3300   *
3301   * @since 0.71
3302   *
3303   * @global WP_Locale $wp_locale WordPress date and time locale object.
3304   */
3305  function the_weekday() {
3306      global $wp_locale;
3307  
3308      $post = get_post();
3309  
3310      if ( ! $post ) {
3311          return;
3312      }
3313  
3314      $the_weekday = $wp_locale->get_weekday( get_post_time( 'w', false, $post ) );
3315  
3316      /**
3317       * Filters the localized weekday of the post, for display.
3318       *
3319       * @since 0.71
3320       *
3321       * @param string $the_weekday
3322       */
3323      echo apply_filters( 'the_weekday', $the_weekday );
3324  }
3325  
3326  /**
3327   * Displays the localized weekday for the post.
3328   *
3329   * Will only output the weekday if the current post's weekday is different from
3330   * the previous one output.
3331   *
3332   * @since 0.71
3333   *
3334   * @global WP_Locale $wp_locale       WordPress date and time locale object.
3335   * @global string    $currentday      The day of the current post in the loop.
3336   * @global string    $previousweekday The day of the previous post in the loop.
3337   *
3338   * @param string $before Optional. Output before the date. Default empty.
3339   * @param string $after  Optional. Output after the date. Default empty.
3340   */
3341  function the_weekday_date( $before = '', $after = '' ) {
3342      global $wp_locale, $currentday, $previousweekday;
3343  
3344      $post = get_post();
3345  
3346      if ( ! $post ) {
3347          return;
3348      }
3349  
3350      $the_weekday_date = '';
3351  
3352      if ( $currentday !== $previousweekday ) {
3353          $the_weekday_date .= $before;
3354          $the_weekday_date .= $wp_locale->get_weekday( get_post_time( 'w', false, $post ) );
3355          $the_weekday_date .= $after;
3356          $previousweekday   = $currentday;
3357      }
3358  
3359      /**
3360       * Filters the localized weekday of the post, for display.
3361       *
3362       * @since 0.71
3363       *
3364       * @param string $the_weekday_date The weekday on which the post was written.
3365       * @param string $before           The HTML to output before the date.
3366       * @param string $after            The HTML to output after the date.
3367       */
3368      echo apply_filters( 'the_weekday_date', $the_weekday_date, $before, $after );
3369  }
3370  
3371  /**
3372   * Fires the wp_head action.
3373   *
3374   * See {@see 'wp_head'}.
3375   *
3376   * @since 1.2.0
3377   */
3378  function wp_head() {
3379      /**
3380       * Prints scripts or data in the head tag on the front end.
3381       *
3382       * @since 1.5.0
3383       */
3384      do_action( 'wp_head' );
3385  }
3386  
3387  /**
3388   * Fires the wp_footer action.
3389   *
3390   * See {@see 'wp_footer'}.
3391   *
3392   * @since 1.5.1
3393   */
3394  function wp_footer() {
3395      /**
3396       * Prints scripts or data before the closing body tag on the front end.
3397       *
3398       * @since 1.5.1
3399       */
3400      do_action( 'wp_footer' );
3401  }
3402  
3403  /**
3404   * Fires the wp_body_open action.
3405   *
3406   * See {@see 'wp_body_open'}.
3407   *
3408   * @since 5.2.0
3409   */
3410  function wp_body_open() {
3411      /**
3412       * Triggered after the opening body tag.
3413       *
3414       * @since 5.2.0
3415       */
3416      do_action( 'wp_body_open' );
3417  }
3418  
3419  /**
3420   * Displays the links to the general feeds.
3421   *
3422   * @since 2.8.0
3423   *
3424   * @param array $args Optional arguments.
3425   */
3426  function feed_links( $args = array() ) {
3427      if ( ! current_theme_supports( 'automatic-feed-links' ) ) {
3428          return;
3429      }
3430  
3431      $defaults = array(
3432          /* translators: Separator between site name and feed type in feed links. */
3433          'separator' => _x( '&raquo;', 'feed link' ),
3434          /* translators: 1: Site title, 2: Separator (raquo). */
3435          'feedtitle' => __( '%1$s %2$s Feed' ),
3436          /* translators: 1: Site title, 2: Separator (raquo). */
3437          'comstitle' => __( '%1$s %2$s Comments Feed' ),
3438      );
3439  
3440      $args = wp_parse_args( $args, $defaults );
3441  
3442      /**
3443       * Filters the feed links arguments.
3444       *
3445       * @since 6.7.0
3446       *
3447       * @param array $args An array of feed links arguments.
3448       */
3449      $args = apply_filters( 'feed_links_args', $args );
3450  
3451      /**
3452       * Filters whether to display the posts feed link.
3453       *
3454       * @since 4.4.0
3455       *
3456       * @param bool $show Whether to display the posts feed link. Default true.
3457       */
3458      if ( apply_filters( 'feed_links_show_posts_feed', true ) ) {
3459          printf(
3460              '<link rel="alternate" type="%s" title="%s" href="%s" />' . "\n",
3461              feed_content_type(),
3462              esc_attr( sprintf( $args['feedtitle'], get_bloginfo( 'name' ), $args['separator'] ) ),
3463              esc_url( get_feed_link() )
3464          );
3465      }
3466  
3467      /**
3468       * Filters whether to display the comments feed link.
3469       *
3470       * @since 4.4.0
3471       *
3472       * @param bool $show Whether to display the comments feed link. Default true.
3473       */
3474      if ( apply_filters( 'feed_links_show_comments_feed', true ) ) {
3475          printf(
3476              '<link rel="alternate" type="%s" title="%s" href="%s" />' . "\n",
3477              feed_content_type(),
3478              esc_attr( sprintf( $args['comstitle'], get_bloginfo( 'name' ), $args['separator'] ) ),
3479              esc_url( get_feed_link( 'comments_' . get_default_feed() ) )
3480          );
3481      }
3482  }
3483  
3484  /**
3485   * Displays the links to the extra feeds such as category feeds.
3486   *
3487   * @since 2.8.0
3488   *
3489   * @param array $args Optional arguments.
3490   */
3491  function feed_links_extra( $args = array() ) {
3492      $defaults = array(
3493          /* translators: Separator between site name and feed type in feed links. */
3494          'separator'     => _x( '&raquo;', 'feed link' ),
3495          /* translators: 1: Site name, 2: Separator (raquo), 3: Post title. */
3496          'singletitle'   => __( '%1$s %2$s %3$s Comments Feed' ),
3497          /* translators: 1: Site name, 2: Separator (raquo), 3: Category name. */
3498          'cattitle'      => __( '%1$s %2$s %3$s Category Feed' ),
3499          /* translators: 1: Site name, 2: Separator (raquo), 3: Tag name. */
3500          'tagtitle'      => __( '%1$s %2$s %3$s Tag Feed' ),
3501          /* translators: 1: Site name, 2: Separator (raquo), 3: Term name, 4: Taxonomy singular name. */
3502          'taxtitle'      => __( '%1$s %2$s %3$s %4$s Feed' ),
3503          /* translators: 1: Site name, 2: Separator (raquo), 3: Author name. */
3504          'authortitle'   => __( '%1$s %2$s Posts by %3$s Feed' ),
3505          /* translators: 1: Site name, 2: Separator (raquo), 3: Search query. */
3506          'searchtitle'   => __( '%1$s %2$s Search Results for &#8220;%3$s&#8221; Feed' ),
3507          /* translators: 1: Site name, 2: Separator (raquo), 3: Post type name. */
3508          'posttypetitle' => __( '%1$s %2$s %3$s Feed' ),
3509      );
3510  
3511      $args = wp_parse_args( $args, $defaults );
3512  
3513      /**
3514       * Filters the extra feed links arguments.
3515       *
3516       * @since 6.7.0
3517       *
3518       * @param array $args An array of extra feed links arguments.
3519       */
3520      $args = apply_filters( 'feed_links_extra_args', $args );
3521  
3522      /*
3523       * The template conditionals are referring to the global query, so the queried object is used rather than
3524       * depending on a global $post being set.
3525       */
3526      $queried_object = get_queried_object();
3527      if ( is_singular() && $queried_object instanceof WP_Post ) {
3528          $post = $queried_object;
3529  
3530          /** This filter is documented in wp-includes/general-template.php */
3531          $show_comments_feed = apply_filters( 'feed_links_show_comments_feed', true );
3532  
3533          /**
3534           * Filters whether to display the post comments feed link.
3535           *
3536           * This filter allows to enable or disable the feed link for a singular post
3537           * in a way that is independent of {@see 'feed_links_show_comments_feed'}
3538           * (which controls the global comments feed). The result of that filter
3539           * is accepted as a parameter.
3540           *
3541           * @since 6.1.0
3542           *
3543           * @param bool $show_comments_feed Whether to display the post comments feed link. Defaults to
3544           *                                 the {@see 'feed_links_show_comments_feed'} filter result.
3545           */
3546          $show_post_comments_feed = apply_filters( 'feed_links_extra_show_post_comments_feed', $show_comments_feed );
3547  
3548          if ( $show_post_comments_feed && ( comments_open( $post ) || pings_open( $post ) || (int) $post->comment_count > 0 ) ) {
3549              $title = sprintf(
3550                  $args['singletitle'],
3551                  get_bloginfo( 'name' ),
3552                  $args['separator'],
3553                  the_title_attribute(
3554                      array(
3555                          'echo' => false,
3556                          'post' => $post,
3557                      )
3558                  )
3559              );
3560  
3561              $feed_link = get_post_comments_feed_link( $post->ID );
3562  
3563              if ( $feed_link ) {
3564                  $href = $feed_link;
3565              }
3566          }
3567      } elseif ( is_post_type_archive() ) {
3568          /**
3569           * Filters whether to display the post type archive feed link.
3570           *
3571           * @since 6.1.0
3572           *
3573           * @param bool $show Whether to display the post type archive feed link. Default true.
3574           */
3575          $show_post_type_archive_feed = apply_filters( 'feed_links_extra_show_post_type_archive_feed', true );
3576  
3577          if ( $show_post_type_archive_feed ) {
3578              $post_type = get_query_var( 'post_type' );
3579  
3580              if ( is_array( $post_type ) ) {
3581                  $post_type = reset( $post_type );
3582              }
3583  
3584              $post_type_obj = get_post_type_object( $post_type );
3585  
3586              $title = sprintf(
3587                  $args['posttypetitle'],
3588                  get_bloginfo( 'name' ),
3589                  $args['separator'],
3590                  $post_type_obj->labels->name
3591              );
3592  
3593              $href = get_post_type_archive_feed_link( $post_type_obj->name );
3594          }
3595      } elseif ( is_category() ) {
3596          /**
3597           * Filters whether to display the category feed link.
3598           *
3599           * @since 6.1.0
3600           *
3601           * @param bool $show Whether to display the category feed link. Default true.
3602           */
3603          $show_category_feed = apply_filters( 'feed_links_extra_show_category_feed', true );
3604  
3605          if ( $show_category_feed ) {
3606              $term = get_queried_object();
3607  
3608              if ( $term ) {
3609                  $title = sprintf(
3610                      $args['cattitle'],
3611                      get_bloginfo( 'name' ),
3612                      $args['separator'],
3613                      $term->name
3614                  );
3615  
3616                  $href = get_category_feed_link( $term->term_id );
3617              }
3618          }
3619      } elseif ( is_tag() ) {
3620          /**
3621           * Filters whether to display the tag feed link.
3622           *
3623           * @since 6.1.0
3624           *
3625           * @param bool $show Whether to display the tag feed link. Default true.
3626           */
3627          $show_tag_feed = apply_filters( 'feed_links_extra_show_tag_feed', true );
3628  
3629          if ( $show_tag_feed ) {
3630              $term = get_queried_object();
3631  
3632              if ( $term ) {
3633                  $title = sprintf(
3634                      $args['tagtitle'],
3635                      get_bloginfo( 'name' ),
3636                      $args['separator'],
3637                      $term->name
3638                  );
3639  
3640                  $href = get_tag_feed_link( $term->term_id );
3641              }
3642          }
3643      } elseif ( is_tax() ) {
3644          /**
3645           * Filters whether to display the custom taxonomy feed link.
3646           *
3647           * @since 6.1.0
3648           *
3649           * @param bool $show Whether to display the custom taxonomy feed link. Default true.
3650           */
3651          $show_tax_feed = apply_filters( 'feed_links_extra_show_tax_feed', true );
3652  
3653          if ( $show_tax_feed ) {
3654              $term = get_queried_object();
3655  
3656              if ( $term ) {
3657                  $tax = get_taxonomy( $term->taxonomy );
3658  
3659                  $title = sprintf(
3660                      $args['taxtitle'],
3661                      get_bloginfo( 'name' ),
3662                      $args['separator'],
3663                      $term->name,
3664                      $tax->labels->singular_name
3665                  );
3666  
3667                  $href = get_term_feed_link( $term->term_id, $term->taxonomy );
3668              }
3669          }
3670      } elseif ( is_author() ) {
3671          /**
3672           * Filters whether to display the author feed link.
3673           *
3674           * @since 6.1.0
3675           *
3676           * @param bool $show Whether to display the author feed link. Default true.
3677           */
3678          $show_author_feed = apply_filters( 'feed_links_extra_show_author_feed', true );
3679  
3680          if ( $show_author_feed ) {
3681              $author_id = (int) get_query_var( 'author' );
3682  
3683              $title = sprintf(
3684                  $args['authortitle'],
3685                  get_bloginfo( 'name' ),
3686                  $args['separator'],
3687                  get_the_author_meta( 'display_name', $author_id )
3688              );
3689  
3690              $href = get_author_feed_link( $author_id );
3691          }
3692      } elseif ( is_search() ) {
3693          /**
3694           * Filters whether to display the search results feed link.
3695           *
3696           * @since 6.1.0
3697           *
3698           * @param bool $show Whether to display the search results feed link. Default true.
3699           */
3700          $show_search_feed = apply_filters( 'feed_links_extra_show_search_feed', true );
3701  
3702          if ( $show_search_feed ) {
3703              $title = sprintf(
3704                  $args['searchtitle'],
3705                  get_bloginfo( 'name' ),
3706                  $args['separator'],
3707                  get_search_query( false )
3708              );
3709  
3710              $href = get_search_feed_link();
3711          }
3712      }
3713  
3714      if ( isset( $title ) && isset( $href ) ) {
3715          printf(
3716              '<link rel="alternate" type="%s" title="%s" href="%s" />' . "\n",
3717              feed_content_type(),
3718              esc_attr( $title ),
3719              esc_url( $href )
3720          );
3721      }
3722  }
3723  
3724  /**
3725   * Displays the link to the Really Simple Discovery service endpoint.
3726   *
3727   * @link http://archipelago.phrasewise.com/rsd
3728   * @since 2.0.0
3729   */
3730  function rsd_link() {
3731      printf(
3732          '<link rel="EditURI" type="application/rsd+xml" title="RSD" href="%s" />' . "\n",
3733          esc_url( site_url( 'xmlrpc.php?rsd', 'rpc' ) )
3734      );
3735  }
3736  
3737  /**
3738   * Displays a referrer `strict-origin-when-cross-origin` meta tag.
3739   *
3740   * Outputs a referrer `strict-origin-when-cross-origin` meta tag that tells the browser not to send
3741   * the full URL as a referrer to other sites when cross-origin assets are loaded.
3742   *
3743   * Typical usage is as a {@see 'wp_head'} callback:
3744   *
3745   *     add_action( 'wp_head', 'wp_strict_cross_origin_referrer' );
3746   *
3747   * @since 5.7.0
3748   */
3749  function wp_strict_cross_origin_referrer() {
3750      ?>
3751      <meta name='referrer' content='strict-origin-when-cross-origin' />
3752      <?php
3753  }
3754  
3755  /**
3756   * Displays site icon meta tags.
3757   *
3758   * @since 4.3.0
3759   *
3760   * @link https://www.whatwg.org/specs/web-apps/current-work/multipage/links.html#rel-icon HTML5 specification link icon.
3761   */
3762  function wp_site_icon() {
3763      if ( ! has_site_icon() && ! is_customize_preview() ) {
3764          return;
3765      }
3766  
3767      $meta_tags = array();
3768      $icon_32   = get_site_icon_url( 32 );
3769      if ( empty( $icon_32 ) && is_customize_preview() ) {
3770          $icon_32 = '/favicon.ico'; // Serve default favicon URL in customizer so element can be updated for preview.
3771      }
3772      if ( $icon_32 ) {
3773          $meta_tags[] = sprintf( '<link rel="icon" href="%s" sizes="32x32" />', esc_url( $icon_32 ) );
3774      }
3775      $icon_192 = get_site_icon_url( 192 );
3776      if ( $icon_192 ) {
3777          $meta_tags[] = sprintf( '<link rel="icon" href="%s" sizes="192x192" />', esc_url( $icon_192 ) );
3778      }
3779      $icon_180 = get_site_icon_url( 180 );
3780      if ( $icon_180 ) {
3781          $meta_tags[] = sprintf( '<link rel="apple-touch-icon" href="%s" />', esc_url( $icon_180 ) );
3782      }
3783      $icon_270 = get_site_icon_url( 270 );
3784      if ( $icon_270 ) {
3785          $meta_tags[] = sprintf( '<meta name="msapplication-TileImage" content="%s" />', esc_url( $icon_270 ) );
3786      }
3787  
3788      /**
3789       * Filters the site icon meta tags, so plugins can add their own.
3790       *
3791       * @since 4.3.0
3792       *
3793       * @param string[] $meta_tags Array of Site Icon meta tags.
3794       */
3795      $meta_tags = apply_filters( 'site_icon_meta_tags', $meta_tags );
3796      $meta_tags = array_filter( $meta_tags );
3797  
3798      foreach ( $meta_tags as $meta_tag ) {
3799          echo "$meta_tag\n";
3800      }
3801  }
3802  
3803  /**
3804   * Prints resource hints to browsers for pre-fetching, pre-rendering
3805   * and pre-connecting to websites.
3806   *
3807   * Gives hints to browsers to prefetch specific pages or render them
3808   * in the background, to perform DNS lookups or to begin the connection
3809   * handshake (DNS, TCP, TLS) in the background.
3810   *
3811   * These performance improving indicators work by using `<link rel"…">`.
3812   *
3813   * @since 4.6.0
3814   */
3815  function wp_resource_hints() {
3816      $hints = array(
3817          'dns-prefetch' => wp_dependencies_unique_hosts(),
3818          'preconnect'   => array(),
3819          'prefetch'     => array(),
3820          'prerender'    => array(),
3821      );
3822  
3823      foreach ( $hints as $relation_type => $urls ) {
3824          $unique_urls = array();
3825  
3826          /**
3827           * Filters domains and URLs for resource hints of the given relation type.
3828           *
3829           * @since 4.6.0
3830           * @since 4.7.0 The `$urls` parameter accepts arrays of specific HTML attributes
3831           *              as its child elements.
3832           *
3833           * @param array  $urls {
3834           *     Array of resources and their attributes, or URLs to print for resource hints.
3835           *
3836           *     @type array|string ...$0 {
3837           *         Array of resource attributes, or a URL string.
3838           *
3839           *         @type string $href        URL to include in resource hints. Required.
3840           *         @type string $as          How the browser should treat the resource
3841           *                                   (`script`, `style`, `image`, `document`, etc).
3842           *         @type string $crossorigin Indicates the CORS policy of the specified resource.
3843           *         @type float  $pr          Expected probability that the resource hint will be used.
3844           *         @type string $type        Type of the resource (`text/html`, `text/css`, etc).
3845           *     }
3846           * }
3847           * @param string $relation_type The relation type the URLs are printed for. One of
3848           *                              'dns-prefetch', 'preconnect', 'prefetch', or 'prerender'.
3849           */
3850          $urls = apply_filters( 'wp_resource_hints', $urls, $relation_type );
3851  
3852          foreach ( $urls as $key => $url ) {
3853              $atts = array();
3854  
3855              if ( is_array( $url ) ) {
3856                  if ( isset( $url['href'] ) ) {
3857                      $atts = $url;
3858                      $url  = $url['href'];
3859                  } else {
3860                      continue;
3861                  }
3862              }
3863  
3864              $url = esc_url( $url, array( 'http', 'https' ) );
3865  
3866              if ( ! $url ) {
3867                  continue;
3868              }
3869  
3870              if ( isset( $unique_urls[ $url ] ) ) {
3871                  continue;
3872              }
3873  
3874              if ( in_array( $relation_type, array( 'preconnect', 'dns-prefetch' ), true ) ) {
3875                  $parsed = wp_parse_url( $url );
3876  
3877                  if ( empty( $parsed['host'] ) ) {
3878                      continue;
3879                  }
3880  
3881                  if ( 'preconnect' === $relation_type && ! empty( $parsed['scheme'] ) ) {
3882                      $url = $parsed['scheme'] . '://' . $parsed['host'];
3883                  } else {
3884                      // Use protocol-relative URLs for dns-prefetch or if scheme is missing.
3885                      $url = '//' . $parsed['host'];
3886                  }
3887              }
3888  
3889              $atts['rel']  = $relation_type;
3890              $atts['href'] = $url;
3891  
3892              $unique_urls[ $url ] = $atts;
3893          }
3894  
3895          foreach ( $unique_urls as $atts ) {
3896              $html = '';
3897  
3898              foreach ( $atts as $attr => $value ) {
3899                  if ( ! is_scalar( $value )
3900                      || ( ! in_array( $attr, array( 'as', 'crossorigin', 'href', 'pr', 'rel', 'type' ), true ) && ! is_numeric( $attr ) )
3901                  ) {
3902  
3903                      continue;
3904                  }
3905  
3906                  $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
3907  
3908                  if ( ! is_string( $attr ) ) {
3909                      $html .= " $value";
3910                  } else {
3911                      $html .= " $attr='$value'";
3912                  }
3913              }
3914  
3915              $html = trim( $html );
3916  
3917              echo "<link $html />\n";
3918          }
3919      }
3920  }
3921  
3922  /**
3923   * Prints resource preloads directives to browsers.
3924   *
3925   * Gives directive to browsers to preload specific resources that website will
3926   * need very soon, this ensures that they are available earlier and are less
3927   * likely to block the page's render. Preload directives should not be used for
3928   * non-render-blocking elements, as then they would compete with the
3929   * render-blocking ones, slowing down the render.
3930   *
3931   * These performance improving indicators work by using `<link rel="preload">`.
3932   *
3933   * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Link_types/preload
3934   * @link https://web.dev/preload-responsive-images/
3935   *
3936   * @since 6.1.0
3937   */
3938  function wp_preload_resources() {
3939      /**
3940       * Filters domains and URLs for resource preloads.
3941       *
3942       * @since 6.1.0
3943       * @since 6.6.0 Added the `$fetchpriority` attribute.
3944       *
3945       * @param array  $preload_resources {
3946       *     Array of resources and their attributes, or URLs to print for resource preloads.
3947       *
3948       *     @type array ...$0 {
3949       *         Array of resource attributes.
3950       *
3951       *         @type string $href          URL to include in resource preloads. Required.
3952       *         @type string $as            How the browser should treat the resource
3953       *                                     (`script`, `style`, `image`, `document`, etc).
3954       *         @type string $crossorigin   Indicates the CORS policy of the specified resource.
3955       *         @type string $type          Type of the resource (`text/html`, `text/css`, etc).
3956       *         @type string $media         Accepts media types or media queries. Allows responsive preloading.
3957       *         @type string $imagesizes    Responsive source size to the source Set.
3958       *         @type string $imagesrcset   Responsive image sources to the source set.
3959       *         @type string $fetchpriority Fetchpriority value for the resource.
3960       *     }
3961       * }
3962       */
3963      $preload_resources = apply_filters( 'wp_preload_resources', array() );
3964  
3965      if ( ! is_array( $preload_resources ) ) {
3966          return;
3967      }
3968  
3969      $unique_resources = array();
3970  
3971      // Parse the complete resource list and extract unique resources.
3972      foreach ( $preload_resources as $resource ) {
3973          if ( ! is_array( $resource ) ) {
3974              continue;
3975          }
3976  
3977          $attributes = $resource;
3978          if ( isset( $resource['href'] ) ) {
3979              $href = $resource['href'];
3980              if ( isset( $unique_resources[ $href ] ) ) {
3981                  continue;
3982              }
3983              $unique_resources[ $href ] = $attributes;
3984              // Media can use imagesrcset and not href.
3985          } elseif ( ( 'image' === $resource['as'] ) &&
3986              ( isset( $resource['imagesrcset'] ) || isset( $resource['imagesizes'] ) )
3987          ) {
3988              if ( isset( $unique_resources[ $resource['imagesrcset'] ] ) ) {
3989                  continue;
3990              }
3991              $unique_resources[ $resource['imagesrcset'] ] = $attributes;
3992          } else {
3993              continue;
3994          }
3995      }
3996  
3997      // Build and output the HTML for each unique resource.
3998      foreach ( $unique_resources as $unique_resource ) {
3999          $html = '';
4000  
4001          foreach ( $unique_resource as $resource_key => $resource_value ) {
4002              if ( ! is_scalar( $resource_value ) ) {
4003                  continue;
4004              }
4005  
4006              // Ignore non-supported attributes.
4007              $non_supported_attributes = array( 'as', 'crossorigin', 'href', 'imagesrcset', 'imagesizes', 'type', 'media', 'fetchpriority' );
4008              if ( ! in_array( $resource_key, $non_supported_attributes, true ) && ! is_numeric( $resource_key ) ) {
4009                  continue;
4010              }
4011  
4012              // imagesrcset only usable when preloading image, ignore otherwise.
4013              if ( ( 'imagesrcset' === $resource_key ) && ( ! isset( $unique_resource['as'] ) || ( 'image' !== $unique_resource['as'] ) ) ) {
4014                  continue;
4015              }
4016  
4017              // imagesizes only usable when preloading image and imagesrcset present, ignore otherwise.
4018              if ( ( 'imagesizes' === $resource_key ) &&
4019                  ( ! isset( $unique_resource['as'] ) || ( 'image' !== $unique_resource['as'] ) || ! isset( $unique_resource['imagesrcset'] ) )
4020              ) {
4021                  continue;
4022              }
4023  
4024              $resource_value = ( 'href' === $resource_key ) ? esc_url( $resource_value, array( 'http', 'https' ) ) : esc_attr( $resource_value );
4025  
4026              if ( ! is_string( $resource_key ) ) {
4027                  $html .= " $resource_value";
4028              } else {
4029                  $html .= " $resource_key='$resource_value'";
4030              }
4031          }
4032          $html = trim( $html );
4033  
4034          printf( "<link rel='preload' %s />\n", $html );
4035      }
4036  }
4037  
4038  /**
4039   * Retrieves a list of unique hosts of all enqueued scripts and styles.
4040   *
4041   * @since 4.6.0
4042   *
4043   * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
4044   * @global WP_Styles  $wp_styles  The WP_Styles object for printing styles.
4045   *
4046   * @return string[] A list of unique hosts of enqueued scripts and styles.
4047   */
4048  function wp_dependencies_unique_hosts() {
4049      global $wp_scripts, $wp_styles;
4050  
4051      $unique_hosts = array();
4052  
4053      foreach ( array( $wp_scripts, $wp_styles ) as $dependencies ) {
4054          if ( $dependencies instanceof WP_Dependencies && ! empty( $dependencies->queue ) ) {
4055              foreach ( $dependencies->queue as $handle ) {
4056                  if ( ! isset( $dependencies->registered[ $handle ] ) ) {
4057                      continue;
4058                  }
4059  
4060                  /* @var _WP_Dependency $dependency */
4061                  $dependency = $dependencies->registered[ $handle ];
4062                  $parsed     = wp_parse_url( $dependency->src );
4063  
4064                  if ( ! empty( $parsed['host'] )
4065                      && ! in_array( $parsed['host'], $unique_hosts, true ) && $parsed['host'] !== $_SERVER['SERVER_NAME']
4066                  ) {
4067                      $unique_hosts[] = $parsed['host'];
4068                  }
4069              }
4070          }
4071      }
4072  
4073      return $unique_hosts;
4074  }
4075  
4076  /**
4077   * Determines whether the user can access the visual editor.
4078   *
4079   * Checks if the user can access the visual editor and that it's supported by the user's browser.
4080   *
4081   * @since 2.0.0
4082   *
4083   * @global bool $wp_rich_edit Whether the user can access the visual editor.
4084   * @global bool $is_gecko     Whether the browser is Gecko-based.
4085   * @global bool $is_opera     Whether the browser is Opera.
4086   * @global bool $is_safari    Whether the browser is Safari.
4087   * @global bool $is_chrome    Whether the browser is Chrome.
4088   * @global bool $is_IE        Whether the browser is Internet Explorer.
4089   * @global bool $is_edge      Whether the browser is Microsoft Edge.
4090   *
4091   * @return bool True if the user can access the visual editor, false otherwise.
4092   */
4093  function user_can_richedit() {
4094      global $wp_rich_edit, $is_gecko, $is_opera, $is_safari, $is_chrome, $is_IE, $is_edge;
4095  
4096      if ( ! isset( $wp_rich_edit ) ) {
4097          $wp_rich_edit = false;
4098  
4099          if ( 'true' === get_user_option( 'rich_editing' ) || ! is_user_logged_in() ) { // Default to 'true' for logged out users.
4100              if ( $is_safari ) {
4101                  $wp_rich_edit = ! wp_is_mobile() || ( preg_match( '!AppleWebKit/(\d+)!', $_SERVER['HTTP_USER_AGENT'], $match ) && (int) $match[1] >= 534 );
4102              } elseif ( $is_IE ) {
4103                  $wp_rich_edit = str_contains( $_SERVER['HTTP_USER_AGENT'], 'Trident/7.0;' );
4104              } elseif ( $is_gecko || $is_chrome || $is_edge || ( $is_opera && ! wp_is_mobile() ) ) {
4105                  $wp_rich_edit = true;
4106              }
4107          }
4108      }
4109  
4110      /**
4111       * Filters whether the user can access the visual editor.
4112       *
4113       * @since 2.1.0
4114       *
4115       * @param bool $wp_rich_edit Whether the user can access the visual editor.
4116       */
4117      return apply_filters( 'user_can_richedit', $wp_rich_edit );
4118  }
4119  
4120  /**
4121   * Finds out which editor should be displayed by default.
4122   *
4123   * Works out which of the editors to display as the current editor for a
4124   * user. The 'html' setting is for the "Code" editor tab.
4125   *
4126   * @since 2.5.0
4127   *
4128   * @return string Either 'tinymce', 'html', or 'test'
4129   */
4130  function wp_default_editor() {
4131      $r = user_can_richedit() ? 'tinymce' : 'html'; // Defaults.
4132      if ( wp_get_current_user() ) { // Look for cookie.
4133          $ed = get_user_setting( 'editor', 'tinymce' );
4134          $r  = ( in_array( $ed, array( 'tinymce', 'html', 'test' ), true ) ) ? $ed : $r;
4135      }
4136  
4137      /**
4138       * Filters which editor should be displayed by default.
4139       *
4140       * @since 2.5.0
4141       *
4142       * @param string $r Which editor should be displayed by default. Either 'tinymce', 'html', or 'test'.
4143       */
4144      return apply_filters( 'wp_default_editor', $r );
4145  }
4146  
4147  /**
4148   * Renders an editor.
4149   *
4150   * Using this function is the proper way to output all needed components for both TinyMCE and Quicktags.
4151   * _WP_Editors should not be used directly. See https://core.trac.wordpress.org/ticket/17144.
4152   *
4153   * NOTE: Once initialized the TinyMCE editor cannot be safely moved in the DOM. For that reason
4154   * running wp_editor() inside of a meta box is not a good idea unless only Quicktags is used.
4155   * On the post edit screen several actions can be used to include additional editors
4156   * containing TinyMCE: 'edit_page_form', 'edit_form_advanced' and 'dbx_post_sidebar'.
4157   * See https://core.trac.wordpress.org/ticket/19173 for more information.
4158   *
4159   * @see _WP_Editors::editor()
4160   * @see _WP_Editors::parse_settings()
4161   * @since 3.3.0
4162   *
4163   * @param string $content   Initial content for the editor.
4164   * @param string $editor_id HTML ID attribute value for the textarea and TinyMCE.
4165   *                          Should not contain square brackets.
4166   * @param array  $settings  See _WP_Editors::parse_settings() for description.
4167   */
4168  function wp_editor( $content, $editor_id, $settings = array() ) {
4169      if ( ! class_exists( '_WP_Editors', false ) ) {
4170          require  ABSPATH . WPINC . '/class-wp-editor.php';
4171      }
4172      _WP_Editors::editor( $content, $editor_id, $settings );
4173  }
4174  
4175  /**
4176   * Outputs the editor scripts, stylesheets, and default settings.
4177   *
4178   * The editor can be initialized when needed after page load.
4179   * See wp.editor.initialize() in wp-admin/js/editor.js for initialization options.
4180   *
4181   * @uses _WP_Editors
4182   * @since 4.8.0
4183   */
4184  function wp_enqueue_editor() {
4185      if ( ! class_exists( '_WP_Editors', false ) ) {
4186          require  ABSPATH . WPINC . '/class-wp-editor.php';
4187      }
4188  
4189      _WP_Editors::enqueue_default_editor();
4190  }
4191  
4192  /**
4193   * Enqueues assets needed by the code editor for the given settings.
4194   *
4195   * @since 4.9.0
4196   *
4197   * @see wp_enqueue_editor()
4198   * @see wp_get_code_editor_settings()
4199   * @see _WP_Editors::parse_settings()
4200   *
4201   * @param array $args {
4202   *     Args.
4203   *
4204   *     @type string   $type       The MIME type of the file to be edited.
4205   *     @type string   $file       Filename to be edited. Extension is used to sniff the type. Can be supplied as alternative to `$type` param.
4206   *     @type WP_Theme $theme      Theme being edited when on the theme file editor.
4207   *     @type string   $plugin     Plugin being edited when on the plugin file editor.
4208   *     @type array    $codemirror Additional CodeMirror setting overrides.
4209   *     @type array    $csslint    CSSLint rule overrides.
4210   *     @type array    $jshint     JSHint rule overrides.
4211   *     @type array    $htmlhint   HTMLHint rule overrides.
4212   * }
4213   * @return array|false Settings for the enqueued code editor, or false if the editor was not enqueued.
4214   */
4215  function wp_enqueue_code_editor( $args ) {
4216      if ( is_user_logged_in() && 'false' === wp_get_current_user()->syntax_highlighting ) {
4217          return false;
4218      }
4219  
4220      $settings = wp_get_code_editor_settings( $args );
4221  
4222      if ( empty( $settings ) || empty( $settings['codemirror'] ) ) {
4223          return false;
4224      }
4225  
4226      wp_enqueue_script( 'code-editor' );
4227      wp_enqueue_style( 'code-editor' );
4228  
4229      if ( isset( $settings['codemirror']['mode'] ) ) {
4230          $mode = $settings['codemirror']['mode'];
4231          if ( is_string( $mode ) ) {
4232              $mode = array(
4233                  'name' => $mode,
4234              );
4235          }
4236  
4237          if ( ! empty( $settings['codemirror']['lint'] ) ) {
4238              switch ( $mode['name'] ) {
4239                  case 'css':
4240                  case 'text/css':
4241                  case 'text/x-scss':
4242                  case 'text/x-less':
4243                      wp_enqueue_script( 'csslint' );
4244                      break;
4245                  case 'htmlmixed':
4246                  case 'text/html':
4247                  case 'php':
4248                  case 'application/x-httpd-php':
4249                  case 'text/x-php':
4250                      wp_enqueue_script( 'htmlhint' );
4251                      wp_enqueue_script( 'csslint' );
4252                      if ( ! current_user_can( 'unfiltered_html' ) ) {
4253                          wp_enqueue_script( 'htmlhint-kses' );
4254                      }
4255                      break;
4256                  case 'javascript':
4257                  case 'application/ecmascript':
4258                  case 'application/json':
4259                  case 'application/javascript':
4260                  case 'application/ld+json':
4261                  case 'text/typescript':
4262                  case 'application/typescript':
4263                      wp_enqueue_script( 'jsonlint' );
4264                      break;
4265              }
4266          }
4267      }
4268  
4269      wp_add_inline_script( 'code-editor', sprintf( 'jQuery.extend( wp.codeEditor.defaultSettings, %s );', wp_json_encode( $settings, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) ) );
4270  
4271      /**
4272       * Fires when scripts and styles are enqueued for the code editor.
4273       *
4274       * @since 4.9.0
4275       *
4276       * @param array $settings Settings for the enqueued code editor.
4277       */
4278      do_action( 'wp_enqueue_code_editor', $settings );
4279  
4280      return $settings;
4281  }
4282  
4283  /**
4284   * Generates and returns code editor settings.
4285   *
4286   * @since 5.0.0
4287   *
4288   * @see wp_enqueue_code_editor()
4289   *
4290   * @param array $args {
4291   *     Args.
4292   *
4293   *     @type string   $type       The MIME type of the file to be edited.
4294   *     @type string   $file       Filename to be edited. Extension is used to sniff the type. Can be supplied as alternative to `$type` param.
4295   *     @type WP_Theme $theme      Theme being edited when on the theme file editor.
4296   *     @type string   $plugin     Plugin being edited when on the plugin file editor.
4297   *     @type array    $codemirror Additional CodeMirror setting overrides.
4298   *     @type array    $csslint    CSSLint rule overrides.
4299   *     @type array    $jshint     JSHint rule overrides.
4300   *     @type array    $htmlhint   HTMLHint rule overrides.
4301   * }
4302   * @return array|false Settings for the code editor.
4303   */
4304  function wp_get_code_editor_settings( $args ) {
4305      $settings = array(
4306          'codemirror' => array(
4307              'indentUnit'       => 4,
4308              'indentWithTabs'   => true,
4309              'inputStyle'       => 'contenteditable',
4310              'lineNumbers'      => true,
4311              'lineWrapping'     => true,
4312              'styleActiveLine'  => true,
4313              'continueComments' => true,
4314              'extraKeys'        => array(
4315                  'Ctrl-Space' => 'autocomplete',
4316                  'Ctrl-/'     => 'toggleComment',
4317                  'Cmd-/'      => 'toggleComment',
4318                  'Alt-F'      => 'findPersistent',
4319                  'Ctrl-F'     => 'findPersistent',
4320                  'Cmd-F'      => 'findPersistent',
4321              ),
4322              'direction'        => 'ltr', // Code is shown in LTR even in RTL languages.
4323              'gutters'          => array(),
4324          ),
4325          'csslint'    => array(
4326              'errors'                    => true, // Parsing errors.
4327              'box-model'                 => true,
4328              'display-property-grouping' => true,
4329              'duplicate-properties'      => true,
4330              'known-properties'          => true,
4331              'outline-none'              => true,
4332          ),
4333          'jshint'     => array(
4334              'esversion'       => 11,
4335              'module'          => str_ends_with( $args['file'] ?? '', '.mjs' ),
4336  
4337              // This script module URL is intentionally referenced here instead of registering an espree script module
4338              // in wp_default_script_modules(). This is a first stab at a core-only private module.
4339              'espreeModuleUrl' => add_query_arg( 'ver', '9.6.1', includes_url( 'js/codemirror/espree.min.js' ) ),
4340  
4341              // The following JSHint *linting rule* options are copied from
4342              // <https://github.com/WordPress/wordpress-develop/blob/6.9.0/.jshintrc>.
4343              // Parsing-related options such as `esversion` (and, in other contexts, `es5`, `es3`, `module`, `strict`)
4344              // are honored by the Espree-based integration, but these linting-rule options are not interpreted by Espree
4345              // and are kept only for compatibility/documentation with the original JSHint configuration.
4346              'boss'            => true,
4347              'curly'           => true,
4348              'eqeqeq'          => true,
4349              'eqnull'          => true,
4350              'expr'            => true,
4351              'immed'           => true,
4352              'noarg'           => true,
4353              'nonbsp'          => true,
4354              'quotmark'        => 'single',
4355              'undef'           => true,
4356              'unused'          => true,
4357              'browser'         => true,
4358              'globals'         => array(
4359                  '_'                 => false,
4360                  'Backbone'          => false,
4361                  'jQuery'            => false,
4362                  'JSON'              => false,
4363                  'wp'                => false,
4364                  'export'            => false,
4365                  'module'            => false,
4366                  'require'           => false,
4367                  'WorkerGlobalScope' => false,
4368                  'self'              => false,
4369                  'OffscreenCanvas'   => false,
4370                  'Promise'           => false,
4371              ),
4372          ),
4373          'htmlhint'   => array(
4374              'tagname-lowercase'        => true,
4375              'attr-lowercase'           => true,
4376              'attr-value-double-quotes' => false,
4377              'doctype-first'            => false,
4378              'tag-pair'                 => true,
4379              'spec-char-escape'         => true,
4380              'id-unique'                => true,
4381              'src-not-empty'            => true,
4382              'attr-no-duplication'      => true,
4383              'alt-require'              => true,
4384              'space-tab-mixed-disabled' => 'tab',
4385              'attr-unsafe-chars'        => true,
4386          ),
4387      );
4388  
4389      $type = '';
4390      if ( isset( $args['type'] ) ) {
4391          $type = $args['type'];
4392  
4393          // Remap MIME types to ones that CodeMirror modes will recognize.
4394          if ( 'application/x-patch' === $type || 'text/x-patch' === $type ) {
4395              $type = 'text/x-diff';
4396          }
4397      } elseif ( isset( $args['file'] ) && str_contains( basename( $args['file'] ), '.' ) ) {
4398          $extension = strtolower( pathinfo( $args['file'], PATHINFO_EXTENSION ) );
4399          foreach ( wp_get_mime_types() as $exts => $mime ) {
4400              if ( preg_match( '!^(' . $exts . ')$!i', $extension ) ) {
4401                  $type = $mime;
4402                  break;
4403              }
4404          }
4405  
4406          // Supply any types that are not matched by wp_get_mime_types().
4407          if ( empty( $type ) ) {
4408              switch ( $extension ) {
4409                  case 'conf':
4410                      $type = 'text/nginx';
4411                      break;
4412                  case 'css':
4413                      $type = 'text/css';
4414                      break;
4415                  case 'diff':
4416                  case 'patch':
4417                      $type = 'text/x-diff';
4418                      break;
4419                  case 'html':
4420                  case 'htm':
4421                      $type = 'text/html';
4422                      break;
4423                  case 'http':
4424                      $type = 'message/http';
4425                      break;
4426                  case 'js':
4427                  case 'mjs':
4428                      $type = 'text/javascript';
4429                      break;
4430                  case 'json':
4431                      $type = 'application/json';
4432                      break;
4433                  case 'jsx':
4434                      $type = 'text/jsx';
4435                      break;
4436                  case 'less':
4437                      $type = 'text/x-less';
4438                      break;
4439                  case 'md':
4440                      $type = 'text/x-gfm';
4441                      break;
4442                  case 'php':
4443                  case 'phtml':
4444                  case 'php3':
4445                  case 'php4':
4446                  case 'php5':
4447                  case 'php7':
4448                  case 'phps':
4449                      $type = 'application/x-httpd-php';
4450                      break;
4451                  case 'scss':
4452                      $type = 'text/x-scss';
4453                      break;
4454                  case 'sass':
4455                      $type = 'text/x-sass';
4456                      break;
4457                  case 'sh':
4458                  case 'bash':
4459                      $type = 'text/x-sh';
4460                      break;
4461                  case 'sql':
4462                      $type = 'text/x-sql';
4463                      break;
4464                  case 'svg':
4465                      $type = 'application/svg+xml';
4466                      break;
4467                  case 'xml':
4468                      $type = 'text/xml';
4469                      break;
4470                  case 'yml':
4471                  case 'yaml':
4472                      $type = 'text/x-yaml';
4473                      break;
4474                  case 'txt':
4475                  default:
4476                      $type = 'text/plain';
4477                      break;
4478              }
4479          }
4480      }
4481  
4482      if ( in_array( $type, array( 'text/css', 'text/x-scss', 'text/x-less', 'text/x-sass' ), true ) ) {
4483          $settings['codemirror'] = array_merge(
4484              $settings['codemirror'],
4485              array(
4486                  'mode'              => $type,
4487                  'lint'              => false,
4488                  'autoCloseBrackets' => true,
4489                  'matchBrackets'     => true,
4490              )
4491          );
4492      } elseif ( 'text/x-diff' === $type ) {
4493          $settings['codemirror'] = array_merge(
4494              $settings['codemirror'],
4495              array(
4496                  'mode' => 'diff',
4497              )
4498          );
4499      } elseif ( 'text/html' === $type ) {
4500          $settings['codemirror'] = array_merge(
4501              $settings['codemirror'],
4502              array(
4503                  'mode'              => 'htmlmixed',
4504                  'lint'              => true,
4505                  'autoCloseBrackets' => true,
4506                  'autoCloseTags'     => true,
4507                  'matchTags'         => array(
4508                      'bothTags' => true,
4509                  ),
4510              )
4511          );
4512  
4513          if ( ! current_user_can( 'unfiltered_html' ) ) {
4514              $settings['htmlhint']['kses'] = wp_kses_allowed_html( 'post' );
4515          }
4516      } elseif ( 'text/x-gfm' === $type ) {
4517          $settings['codemirror'] = array_merge(
4518              $settings['codemirror'],
4519              array(
4520                  'mode'                => 'gfm',
4521                  'highlightFormatting' => true,
4522              )
4523          );
4524      } elseif ( 'application/javascript' === $type || 'text/javascript' === $type ) {
4525          $settings['codemirror'] = array_merge(
4526              $settings['codemirror'],
4527              array(
4528                  'mode'              => 'javascript',
4529                  'lint'              => true,
4530                  'autoCloseBrackets' => true,
4531                  'matchBrackets'     => true,
4532              )
4533          );
4534      } elseif ( str_contains( $type, 'json' ) ) {
4535          $settings['codemirror'] = array_merge(
4536              $settings['codemirror'],
4537              array(
4538                  'mode'              => array(
4539                      'name' => 'javascript',
4540                  ),
4541                  'lint'              => true,
4542                  'autoCloseBrackets' => true,
4543                  'matchBrackets'     => true,
4544              )
4545          );
4546          if ( 'application/ld+json' === $type ) {
4547              $settings['codemirror']['mode']['jsonld'] = true;
4548          } else {
4549              $settings['codemirror']['mode']['json'] = true;
4550          }
4551      } elseif ( str_contains( $type, 'jsx' ) ) {
4552          $settings['codemirror'] = array_merge(
4553              $settings['codemirror'],
4554              array(
4555                  'mode'              => 'jsx',
4556                  'autoCloseBrackets' => true,
4557                  'matchBrackets'     => true,
4558              )
4559          );
4560      } elseif ( 'text/x-markdown' === $type ) {
4561          $settings['codemirror'] = array_merge(
4562              $settings['codemirror'],
4563              array(
4564                  'mode'                => 'markdown',
4565                  'highlightFormatting' => true,
4566              )
4567          );
4568      } elseif ( 'text/nginx' === $type ) {
4569          $settings['codemirror'] = array_merge(
4570              $settings['codemirror'],
4571              array(
4572                  'mode' => 'nginx',
4573              )
4574          );
4575      } elseif ( 'application/x-httpd-php' === $type ) {
4576          $settings['codemirror'] = array_merge(
4577              $settings['codemirror'],
4578              array(
4579                  'mode'              => 'php',
4580                  'autoCloseBrackets' => true,
4581                  'autoCloseTags'     => true,
4582                  'matchBrackets'     => true,
4583                  'matchTags'         => array(
4584                      'bothTags' => true,
4585                  ),
4586              )
4587          );
4588      } elseif ( 'text/x-sql' === $type || 'text/x-mysql' === $type ) {
4589          $settings['codemirror'] = array_merge(
4590              $settings['codemirror'],
4591              array(
4592                  'mode'              => 'sql',
4593                  'autoCloseBrackets' => true,
4594                  'matchBrackets'     => true,
4595              )
4596          );
4597      } elseif ( str_contains( $type, 'xml' ) ) {
4598          $settings['codemirror'] = array_merge(
4599              $settings['codemirror'],
4600              array(
4601                  'mode'              => 'xml',
4602                  'autoCloseBrackets' => true,
4603                  'autoCloseTags'     => true,
4604                  'matchTags'         => array(
4605                      'bothTags' => true,
4606                  ),
4607              )
4608          );
4609      } elseif ( 'text/x-yaml' === $type ) {
4610          $settings['codemirror'] = array_merge(
4611              $settings['codemirror'],
4612              array(
4613                  'mode' => 'yaml',
4614              )
4615          );
4616      } else {
4617          $settings['codemirror']['mode'] = $type;
4618      }
4619  
4620      if ( ! empty( $settings['codemirror']['lint'] ) ) {
4621          $settings['codemirror']['gutters'][] = 'CodeMirror-lint-markers';
4622      }
4623  
4624      // Let settings supplied via args override any defaults.
4625      foreach ( wp_array_slice_assoc( $args, array( 'codemirror', 'csslint', 'jshint', 'htmlhint' ) ) as $key => $value ) {
4626          $settings[ $key ] = array_merge(
4627              $settings[ $key ],
4628              $value
4629          );
4630      }
4631  
4632      /**
4633       * Filters settings that are passed into the code editor.
4634       *
4635       * Returning a falsey value will disable the syntax-highlighting code editor.
4636       *
4637       * @since 4.9.0
4638       *
4639       * @param array $settings The array of settings passed to the code editor.
4640       *                        A falsey value disables the editor.
4641       * @param array $args {
4642       *     Args passed when calling `get_code_editor_settings()`.
4643       *
4644       *     @type string   $type       The MIME type of the file to be edited.
4645       *     @type string   $file       Filename being edited.
4646       *     @type WP_Theme $theme      Theme being edited when on the theme file editor.
4647       *     @type string   $plugin     Plugin being edited when on the plugin file editor.
4648       *     @type array    $codemirror Additional CodeMirror setting overrides.
4649       *     @type array    $csslint    CSSLint rule overrides.
4650       *     @type array    $jshint     JSHint rule overrides.
4651       *     @type array    $htmlhint   HTMLHint rule overrides.
4652       * }
4653       */
4654      return apply_filters( 'wp_code_editor_settings', $settings, $args );
4655  }
4656  
4657  /**
4658   * Retrieves the contents of the search WordPress query variable.
4659   *
4660   * The search query string is passed through esc_attr() to ensure that it is safe
4661   * for placing in an HTML attribute.
4662   *
4663   * @since 2.3.0
4664   *
4665   * @param bool $escaped Whether the result is escaped. Default true.
4666   *                      Only use when you are later escaping it. Do not use unescaped.
4667   * @return string
4668   */
4669  function get_search_query( $escaped = true ) {
4670      /**
4671       * Filters the contents of the search query variable.
4672       *
4673       * @since 2.3.0
4674       *
4675       * @param mixed $search Contents of the search query variable.
4676       */
4677      $query = apply_filters( 'get_search_query', get_query_var( 's' ) );
4678  
4679      if ( $escaped ) {
4680          $query = esc_attr( $query );
4681      }
4682      return $query;
4683  }
4684  
4685  /**
4686   * Displays the contents of the search query variable.
4687   *
4688   * The search query string is passed through esc_attr() to ensure that it is safe
4689   * for placing in an HTML attribute.
4690   *
4691   * @since 2.1.0
4692   */
4693  function the_search_query() {
4694      /**
4695       * Filters the contents of the search query variable, for display.
4696       *
4697       * @since 2.3.0
4698       *
4699       * @param mixed $search Contents of the search query variable.
4700       */
4701      echo esc_attr( apply_filters( 'the_search_query', get_search_query( false ) ) );
4702  }
4703  
4704  /**
4705   * Gets the language attributes for the 'html' tag.
4706   *
4707   * Builds up a set of HTML attributes containing the text direction and language
4708   * information for the page.
4709   *
4710   * @since 4.3.0
4711   *
4712   * @param string $doctype Optional. The type of HTML document. Accepts 'xhtml' or 'html'. Default 'html'.
4713   * @return string A space-separated list of language attributes.
4714   */
4715  function get_language_attributes( $doctype = 'html' ) {
4716      $attributes = array();
4717  
4718      if ( function_exists( 'is_rtl' ) && is_rtl() ) {
4719          $attributes[] = 'dir="rtl"';
4720      }
4721  
4722      $lang      = get_bloginfo( 'language' );
4723      $html_type = get_option( 'html_type' );
4724  
4725      if ( $lang ) {
4726          if ( 'text/html' === $html_type || 'html' === $doctype ) {
4727              $attributes[] = 'lang="' . esc_attr( $lang ) . '"';
4728          }
4729  
4730          // The $html_type option may be false on a new install on the setup-config.php page.
4731          if ( ( $html_type && 'text/html' !== $html_type ) || 'xhtml' === $doctype ) {
4732              $attributes[] = 'xml:lang="' . esc_attr( $lang ) . '"';
4733          }
4734      }
4735  
4736      $output = implode( ' ', $attributes );
4737  
4738      /**
4739       * Filters the language attributes for display in the 'html' tag.
4740       *
4741       * @since 2.5.0
4742       * @since 4.3.0 Added the `$doctype` parameter.
4743       *
4744       * @param string $output A space-separated list of language attributes.
4745       * @param string $doctype The type of HTML document (xhtml|html).
4746       */
4747      return apply_filters( 'language_attributes', $output, $doctype );
4748  }
4749  
4750  /**
4751   * Displays the language attributes for the 'html' tag.
4752   *
4753   * Builds up a set of HTML attributes containing the text direction and language
4754   * information for the page.
4755   *
4756   * @since 2.1.0
4757   * @since 4.3.0 Converted into a wrapper for get_language_attributes().
4758   *
4759   * @param string $doctype Optional. The type of HTML document. Accepts 'xhtml' or 'html'. Default 'html'.
4760   */
4761  function language_attributes( $doctype = 'html' ) {
4762      echo get_language_attributes( $doctype );
4763  }
4764  
4765  /**
4766   * Retrieves paginated links for archive post pages.
4767   *
4768   * Technically, the function can be used to create paginated link list for any
4769   * area. The 'base' argument is used to reference the url, which will be used to
4770   * create the paginated links. The 'format' argument is then used for replacing
4771   * the page number. It is however, most likely and by default, to be used on the
4772   * archive post pages.
4773   *
4774   * The 'type' argument controls format of the returned value. The default is
4775   * 'plain', which is just a string with the links separated by a newline
4776   * character. The other possible values are either 'array' or 'list'. The
4777   * 'array' value will return an array of the paginated link list to offer full
4778   * control of display. The 'list' value will place all of the paginated links in
4779   * an unordered HTML list.
4780   *
4781   * The 'total' argument is the total amount of pages and is an integer. The
4782   * 'current' argument is the current page number and is also an integer.
4783   *
4784   * An example of the 'base' argument is "http://example.com/all_posts.php%_%"
4785   * and the '%_%' is required. The '%_%' will be replaced by the contents of in
4786   * the 'format' argument. An example for the 'format' argument is "?page=%#%"
4787   * and the '%#%' is also required. The '%#%' will be replaced with the page
4788   * number.
4789   *
4790   * You can include the previous and next links in the list by setting the
4791   * 'prev_next' argument to true, which it is by default. You can set the
4792   * previous text, by using the 'prev_text' argument. You can set the next text
4793   * by setting the 'next_text' argument.
4794   *
4795   * If the 'show_all' argument is set to true, then it will show all of the pages
4796   * instead of a short list of the pages near the current page. By default, the
4797   * 'show_all' is set to false and controlled by the 'end_size' and 'mid_size'
4798   * arguments. The 'end_size' argument is how many numbers on either the start
4799   * and the end list edges, by default is 1. The 'mid_size' argument is how many
4800   * numbers to either side of current page, but not including current page.
4801   *
4802   * It is possible to add query vars to the link by using the 'add_args' argument
4803   * and see add_query_arg() for more information.
4804   *
4805   * The 'before_page_number' and 'after_page_number' arguments allow users to
4806   * augment the links themselves. Typically this might be to add context to the
4807   * numbered links so that screen reader users understand what the links are for.
4808   * The text strings are added before and after the page number - within the
4809   * anchor tag.
4810   *
4811   * @since 2.1.0
4812   * @since 4.9.0 Added the `aria_current` argument.
4813   *
4814   * @global WP_Query   $wp_query   WordPress Query object.
4815   * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
4816   *
4817   * @param string|array $args {
4818   *     Optional. Array or string of arguments for generating paginated links for archives.
4819   *
4820   *     @type string $base               Base of the paginated url. Default empty.
4821   *     @type string $format             Format for the pagination structure. Default empty.
4822   *     @type int    $total              The total amount of pages. Default is the value WP_Query's
4823   *                                      `max_num_pages` or 1.
4824   *     @type int    $current            The current page number. Default is 'paged' query var or 1.
4825   *     @type string $aria_current       The value for the aria-current attribute. Possible values are 'page',
4826   *                                      'step', 'location', 'date', 'time', 'true', 'false'. Default is 'page'.
4827   *     @type bool   $show_all           Whether to show all pages. Default false.
4828   *     @type int    $end_size           How many numbers on either the start and the end list edges.
4829   *                                      Default 1.
4830   *     @type int    $mid_size           How many numbers to either side of the current pages. Default 2.
4831   *     @type bool   $prev_next          Whether to include the previous and next links in the list. Default true.
4832   *     @type string $prev_text          The previous page text. Default '&laquo; Previous'.
4833   *     @type string $next_text          The next page text. Default 'Next &raquo;'.
4834   *     @type string $type               Controls format of the returned value. Possible values are 'plain',
4835   *                                      'array' and 'list'. Default is 'plain'.
4836   *     @type array  $add_args           An array of query args to add. Default false.
4837   *     @type string $add_fragment       A string to append to each link. Default empty.
4838   *     @type string $before_page_number A string to appear before the page number. Default empty.
4839   *     @type string $after_page_number  A string to append after the page number. Default empty.
4840   * }
4841   * @return string|string[]|null String of page links or array of page links, depending on 'type' argument.
4842   *                              Null if total number of pages is less than 2.
4843   */
4844  function paginate_links( $args = '' ) {
4845      global $wp_query, $wp_rewrite;
4846  
4847      // Setting up default values based on the current URL.
4848      $pagenum_link = html_entity_decode( get_pagenum_link() );
4849      $url_parts    = explode( '?', $pagenum_link );
4850  
4851      // Get max pages and current page out of the current query, if available.
4852      $total   = $wp_query->max_num_pages ?? 1;
4853      $current = get_query_var( 'paged' ) ? (int) get_query_var( 'paged' ) : 1;
4854  
4855      /*
4856       * Ensures sites not using trailing slashes get links in the form
4857       * `/page/2` rather than `/page/2/`. On these sites, linking to the
4858       * URL with a trailing slash will result in a 301 redirect from the
4859       * incorrect URL to the correctly formatted one. This presents an
4860       * unnecessary performance hit.
4861       */
4862      if ( $wp_rewrite->using_permalinks() && ! $wp_rewrite->use_trailing_slashes ) {
4863          $pagenum_link = untrailingslashit( $url_parts[0] );
4864      } else {
4865          $pagenum_link = trailingslashit( $url_parts[0] );
4866      }
4867      $pagenum_link .= '%_%';
4868  
4869      // URL base depends on permalink settings.
4870      $format  = $wp_rewrite->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : '';
4871      $format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?paged=%#%';
4872      if ( $wp_rewrite->using_permalinks() && ! $wp_rewrite->use_trailing_slashes ) {
4873          $format = '/' . ltrim( $format, '/' );
4874      }
4875  
4876      $defaults = array(
4877          'base'               => $pagenum_link, // http://example.com/all_posts.php%_% : %_% is replaced by format (below).
4878          'format'             => $format, // ?page=%#% : %#% is replaced by the page number.
4879          'total'              => $total,
4880          'current'            => $current,
4881          'aria_current'       => 'page',
4882          'show_all'           => false,
4883          'prev_next'          => true,
4884          'prev_text'          => __( '&laquo; Previous' ),
4885          'next_text'          => __( 'Next &raquo;' ),
4886          'end_size'           => 1,
4887          'mid_size'           => 2,
4888          'type'               => 'plain',
4889          'add_args'           => array(), // Array of query args to add.
4890          'add_fragment'       => '',
4891          'before_page_number' => '',
4892          'after_page_number'  => '',
4893      );
4894  
4895      $args = wp_parse_args( $args, $defaults );
4896  
4897      if ( ! is_array( $args['add_args'] ) ) {
4898          $args['add_args'] = array();
4899      }
4900  
4901      // Merge additional query vars found in the original URL into 'add_args' array.
4902      if ( isset( $url_parts[1] ) ) {
4903          // Find the format argument.
4904          $format       = explode( '?', str_replace( '%_%', $args['format'], $args['base'] ) );
4905          $format_query = $format[1] ?? '';
4906          wp_parse_str( $format_query, $format_args );
4907  
4908          // Find the query args of the requested URL.
4909          wp_parse_str( $url_parts[1], $url_query_args );
4910  
4911          // Remove the format argument from the array of query arguments, to avoid overwriting custom format.
4912          foreach ( $format_args as $format_arg => $format_arg_value ) {
4913              unset( $url_query_args[ $format_arg ] );
4914          }
4915  
4916          $args['add_args'] = array_merge( $args['add_args'], urlencode_deep( $url_query_args ) );
4917      }
4918  
4919      // Who knows what else people pass in $args.
4920      $total = (int) $args['total'];
4921      if ( $total < 2 ) {
4922          return null;
4923      }
4924      $current  = (int) $args['current'];
4925      $end_size = (int) $args['end_size']; // Out of bounds? Make it the default.
4926      if ( $end_size < 1 ) {
4927          $end_size = 1;
4928      }
4929      $mid_size = (int) $args['mid_size'];
4930      if ( $mid_size < 0 ) {
4931          $mid_size = 2;
4932      }
4933  
4934      $add_args   = $args['add_args'];
4935      $r          = '';
4936      $page_links = array();
4937      $dots       = false;
4938  
4939      if ( $args['prev_next'] && $current && 1 < $current ) :
4940          $link = str_replace( '%_%', 2 === $current ? '' : $args['format'], $args['base'] );
4941          $link = str_replace( '%#%', $current - 1, $link );
4942          if ( $add_args ) {
4943              $link = add_query_arg( $add_args, $link );
4944          }
4945          $link .= $args['add_fragment'];
4946  
4947          $page_links[] = sprintf(
4948              '<a class="prev page-numbers" href="%s">%s</a>',
4949              /**
4950               * Filters the paginated links for the given archive pages.
4951               *
4952               * @since 3.0.0
4953               *
4954               * @param string $link The paginated link URL.
4955               */
4956              esc_url( apply_filters( 'paginate_links', $link ) ),
4957              $args['prev_text']
4958          );
4959      endif;
4960  
4961      for ( $n = 1; $n <= $total; $n++ ) :
4962          if ( $n === $current ) :
4963              $page_links[] = sprintf(
4964                  '<span aria-current="%s" class="page-numbers current">%s</span>',
4965                  esc_attr( $args['aria_current'] ),
4966                  $args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number']
4967              );
4968  
4969              $dots = true;
4970          else :
4971              if ( $args['show_all'] || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :
4972                  $link = str_replace( '%_%', 1 === $n ? '' : $args['format'], $args['base'] );
4973                  $link = str_replace( '%#%', $n, $link );
4974                  if ( $add_args ) {
4975                      $link = add_query_arg( $add_args, $link );
4976                  }
4977                  $link .= $args['add_fragment'];
4978  
4979                  $page_links[] = sprintf(
4980                      '<a class="page-numbers" href="%s">%s</a>',
4981                      /** This filter is documented in wp-includes/general-template.php */
4982                      esc_url( apply_filters( 'paginate_links', $link ) ),
4983                      $args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number']
4984                  );
4985  
4986                  $dots = true;
4987              elseif ( $dots && ! $args['show_all'] ) :
4988                  $page_links[] = '<span class="page-numbers dots">' . __( '&hellip;' ) . '</span>';
4989  
4990                  $dots = false;
4991              endif;
4992          endif;
4993      endfor;
4994  
4995      if ( $args['prev_next'] && $current && $current < $total ) :
4996          $link = str_replace( '%_%', $args['format'], $args['base'] );
4997          $link = str_replace( '%#%', $current + 1, $link );
4998          if ( $add_args ) {
4999              $link = add_query_arg( $add_args, $link );
5000          }
5001          $link .= $args['add_fragment'];
5002  
5003          $page_links[] = sprintf(
5004              '<a class="next page-numbers" href="%s">%s</a>',
5005              /** This filter is documented in wp-includes/general-template.php */
5006              esc_url( apply_filters( 'paginate_links', $link ) ),
5007              $args['next_text']
5008          );
5009      endif;
5010  
5011      switch ( $args['type'] ) {
5012          case 'array':
5013              return $page_links;
5014  
5015          case 'list':
5016              $r .= "<ul class='page-numbers'>\n\t<li>";
5017              $r .= implode( "</li>\n\t<li>", $page_links );
5018              $r .= "</li>\n</ul>\n";
5019              break;
5020  
5021          default:
5022              $r = implode( "\n", $page_links );
5023              break;
5024      }
5025  
5026      /**
5027       * Filters the HTML output of paginated links for archives.
5028       *
5029       * @since 5.7.0
5030       *
5031       * @param string $r    HTML output.
5032       * @param array  $args An array of arguments. See paginate_links()
5033       *                     for information on accepted arguments.
5034       */
5035      $r = apply_filters( 'paginate_links_output', $r, $args );
5036  
5037      return $r;
5038  }
5039  
5040  /**
5041   * Registers an admin color scheme css file.
5042   *
5043   * Allows a plugin to register a new admin color scheme. For example:
5044   *
5045   *     wp_admin_css_color( 'classic', __( 'Classic' ), admin_url( "css/colors-classic.css" ), array(
5046   *         '#07273E', '#14568A', '#D54E21', '#2683AE'
5047   *     ) );
5048   *
5049   * @since 2.5.0
5050   *
5051   * @global array $_wp_admin_css_colors
5052   *
5053   * @param string $key    The unique key for this theme.
5054   * @param string $name   The name of the theme.
5055   * @param string $url    The URL of the CSS file containing the color scheme.
5056   * @param array  $colors Optional. An array of CSS color definition strings which are used
5057   *                       to give the user a feel for the theme.
5058   * @param array  $icons {
5059   *     Optional. CSS color definitions used to color any SVG icons.
5060   *
5061   *     @type string $base    SVG icon base color.
5062   *     @type string $focus   SVG icon color on focus.
5063   *     @type string $current SVG icon color of current admin menu link.
5064   * }
5065   */
5066  function wp_admin_css_color( $key, $name, $url, $colors = array(), $icons = array() ) {
5067      global $_wp_admin_css_colors;
5068  
5069      if ( ! isset( $_wp_admin_css_colors ) ) {
5070          $_wp_admin_css_colors = array();
5071      }
5072  
5073      $_wp_admin_css_colors[ $key ] = (object) array(
5074          'name'        => $name,
5075          'url'         => $url,
5076          'colors'      => $colors,
5077          'icon_colors' => $icons,
5078      );
5079  }
5080  
5081  /**
5082   * Registers the default admin color schemes.
5083   *
5084   * Registers the initial set of eight color schemes in the Profile section
5085   * of the dashboard which allows for styling the admin menu and toolbar.
5086   *
5087   * @see wp_admin_css_color()
5088   *
5089   * @since 3.0.0
5090   */
5091  function register_admin_color_schemes() {
5092      $suffix  = is_rtl() ? '-rtl' : '';
5093      $suffix .= SCRIPT_DEBUG ? '' : '.min';
5094  
5095      wp_admin_css_color(
5096          'modern',
5097          _x( 'Default', 'admin color scheme' ),
5098          admin_url( "css/colors/modern/colors$suffix.css" ),
5099          array( '#1e1e1e', '#3858e9', '#7b90ff' ),
5100          array(
5101              'base'    => '#f3f1f1',
5102              'focus'   => '#fff',
5103              'current' => '#fff',
5104          )
5105      );
5106  
5107      wp_admin_css_color(
5108          'fresh',
5109          _x( 'Fresh', 'admin color scheme' ),
5110          false,
5111          array( '#1d2327', '#2c3338', '#2271b1', '#72aee6' ),
5112          array(
5113              'base'    => '#a7aaad',
5114              'focus'   => '#72aee6',
5115              'current' => '#fff',
5116          )
5117      );
5118  
5119      wp_admin_css_color(
5120          'light',
5121          _x( 'Light', 'admin color scheme' ),
5122          admin_url( "css/colors/light/colors$suffix.css" ),
5123          array( '#e5e5e5', '#6a6a6a', '#c64606', '#007cba' ),
5124          array(
5125              'base'    => '#999',
5126              'focus'   => '#ccc',
5127              'current' => '#ccc',
5128          )
5129      );
5130  
5131      wp_admin_css_color(
5132          'blue',
5133          _x( 'Blue', 'admin color scheme' ),
5134          admin_url( "css/colors/blue/colors$suffix.css" ),
5135          array( '#183751', '#245278', '#437aa8', '#e1a948' ),
5136          array(
5137              'base'    => '#e5f8ff',
5138              'focus'   => '#fff',
5139              'current' => '#fff',
5140          )
5141      );
5142  
5143      wp_admin_css_color(
5144          'midnight',
5145          _x( 'Midnight', 'admin color scheme' ),
5146          admin_url( "css/colors/midnight/colors$suffix.css" ),
5147          array( '#232a2e', '#333c42', '#69a8bb', '#cf4339' ),
5148          array(
5149              'base'    => '#f1f2f3',
5150              'focus'   => '#fff',
5151              'current' => '#fff',
5152          )
5153      );
5154  
5155      wp_admin_css_color(
5156          'sunrise',
5157          _x( 'Sunrise', 'admin color scheme' ),
5158          admin_url( "css/colors/sunrise/colors$suffix.css" ),
5159          array( '#6f2724', '#8a312d', '#ad631e', '#ccaf0b' ),
5160          array(
5161              'base'    => '#f3f1f1',
5162              'focus'   => '#fff',
5163              'current' => '#fff',
5164          )
5165      );
5166  
5167      wp_admin_css_color(
5168          'ectoplasm',
5169          _x( 'Ectoplasm', 'admin color scheme' ),
5170          admin_url( "css/colors/ectoplasm/colors$suffix.css" ),
5171          array( '#392751', '#4a3369', '#646c3e', '#d46f15' ),
5172          array(
5173              'base'    => '#ece6f6',
5174              'focus'   => '#fff',
5175              'current' => '#fff',
5176          )
5177      );
5178  
5179      wp_admin_css_color(
5180          'ocean',
5181          _x( 'Ocean', 'admin color scheme' ),
5182          admin_url( "css/colors/ocean/colors$suffix.css" ),
5183          array( '#2b3f44', '#39535a', '#567958', '#aa9d88' ),
5184          array(
5185              'base'    => '#f2fcff',
5186              'focus'   => '#fff',
5187              'current' => '#fff',
5188          )
5189      );
5190  
5191      wp_admin_css_color(
5192          'coffee',
5193          _x( 'Coffee', 'admin color scheme' ),
5194          admin_url( "css/colors/coffee/colors$suffix.css" ),
5195          array( '#382e27', '#5c4c40', '#916745', '#9ea476' ),
5196          array(
5197              'base'    => '#f3f2f1',
5198              'focus'   => '#fff',
5199              'current' => '#fff',
5200          )
5201      );
5202  }
5203  
5204  /**
5205   * Displays the URL of a WordPress admin CSS file.
5206   *
5207   * @see WP_Styles::_css_href() and its {@see 'style_loader_src'} filter.
5208   *
5209   * @since 2.3.0
5210   *
5211   * @param string $file file relative to wp-admin/ without its ".css" extension.
5212   * @return string
5213   */
5214  function wp_admin_css_uri( $file = 'wp-admin' ) {
5215      if ( defined( 'WP_INSTALLING' ) ) {
5216          $_file = "./$file.css";
5217      } else {
5218          $_file = admin_url( "$file.css" );
5219      }
5220      $_file = add_query_arg( 'version', get_bloginfo( 'version' ), $_file );
5221  
5222      /**
5223       * Filters the URI of a WordPress admin CSS file.
5224       *
5225       * @since 2.3.0
5226       *
5227       * @param string $_file Relative path to the file with query arguments attached.
5228       * @param string $file  Relative path to the file, minus its ".css" extension.
5229       */
5230      return apply_filters( 'wp_admin_css_uri', $_file, $file );
5231  }
5232  
5233  /**
5234   * Enqueues or directly prints a stylesheet link to the specified CSS file.
5235   *
5236   * "Intelligently" decides to enqueue or to print the CSS file. If the
5237   * {@see 'wp_print_styles'} action has *not* yet been called, the CSS file will be
5238   * enqueued. If the {@see 'wp_print_styles'} action has been called, the CSS link will
5239   * be printed. Printing may be forced by passing true as the $force_echo
5240   * (second) parameter.
5241   *
5242   * For backward compatibility with WordPress 2.3 calling method: If the $file
5243   * (first) parameter does not correspond to a registered CSS file, we assume
5244   * $file is a file relative to wp-admin/ without its ".css" extension. A
5245   * stylesheet link to that generated URL is printed.
5246   *
5247   * @since 2.3.0
5248   *
5249   * @param string $file       Optional. Style handle name or file name (without ".css" extension) relative
5250   *                           to wp-admin/. Defaults to 'wp-admin'.
5251   * @param bool   $force_echo Optional. Force the stylesheet link to be printed rather than enqueued.
5252   */
5253  function wp_admin_css( $file = 'wp-admin', $force_echo = false ) {
5254      // For backward compatibility.
5255      $handle = str_starts_with( $file, 'css/' ) ? substr( $file, 4 ) : $file;
5256  
5257      if ( wp_styles()->query( $handle ) ) {
5258          if ( $force_echo || did_action( 'wp_print_styles' ) ) {
5259              // We already printed the style queue. Print this one immediately.
5260              wp_print_styles( $handle );
5261          } else {
5262              // Add to style queue.
5263              wp_enqueue_style( $handle );
5264          }
5265          return;
5266      }
5267  
5268      $stylesheet_link = sprintf(
5269          "<link rel='stylesheet' href='%s' />\n",
5270          esc_url( wp_admin_css_uri( $file ) )
5271      );
5272  
5273      /**
5274       * Filters the stylesheet link to the specified CSS file.
5275       *
5276       * If the site is set to display right-to-left, the RTL stylesheet link
5277       * will be used instead.
5278       *
5279       * @since 2.3.0
5280       * @param string $stylesheet_link HTML link element for the stylesheet.
5281       * @param string $file            Style handle name or filename (without ".css" extension)
5282       *                                relative to wp-admin/. Defaults to 'wp-admin'.
5283       */
5284      echo apply_filters( 'wp_admin_css', $stylesheet_link, $file );
5285  
5286      if ( function_exists( 'is_rtl' ) && is_rtl() ) {
5287          $rtl_stylesheet_link = sprintf(
5288              "<link rel='stylesheet' href='%s' />\n",
5289              esc_url( wp_admin_css_uri( "$file-rtl" ) )
5290          );
5291  
5292          /** This filter is documented in wp-includes/general-template.php */
5293          echo apply_filters( 'wp_admin_css', $rtl_stylesheet_link, "$file-rtl" );
5294      }
5295  }
5296  
5297  /**
5298   * Enqueues the default ThickBox js and css.
5299   *
5300   * If any of the settings need to be changed, this can be done with another js
5301   * file similar to media-upload.js. That file should
5302   * require array('thickbox') to ensure it is loaded after.
5303   *
5304   * @since 2.5.0
5305   */
5306  function add_thickbox() {
5307      wp_enqueue_script( 'thickbox' );
5308      wp_enqueue_style( 'thickbox' );
5309  
5310      if ( is_network_admin() ) {
5311          add_action( 'admin_head', '_thickbox_path_admin_subfolder' );
5312      }
5313  }
5314  
5315  /**
5316   * Displays the XHTML generator that is generated on the wp_head hook.
5317   *
5318   * See {@see 'wp_head'}.
5319   *
5320   * @since 2.5.0
5321   */
5322  function wp_generator() {
5323      /**
5324       * Filters the output of the XHTML generator tag.
5325       *
5326       * @since 2.5.0
5327       *
5328       * @param string $generator_type The XHTML generator.
5329       */
5330      the_generator( apply_filters( 'wp_generator_type', 'xhtml' ) );
5331  }
5332  
5333  /**
5334   * Displays the generator XML or Comment for RSS, ATOM, etc.
5335   *
5336   * Returns the correct generator type for the requested output format. Allows
5337   * for a plugin to filter generators overall the {@see 'the_generator'} filter.
5338   *
5339   * @since 2.5.0
5340   *
5341   * @param string $type The type of generator to output - (html|xhtml|atom|rss2|rdf|comment|export).
5342   */
5343  function the_generator( $type ) {
5344      /**
5345       * Filters the output of the XHTML generator tag, for display.
5346       *
5347       * @since 2.5.0
5348       *
5349       * @param string $generator_type The generator output.
5350       * @param string $type           The type of generator to output. Accepts 'html',
5351       *                               'xhtml', 'atom', 'rss2', 'rdf', 'comment', 'export'.
5352       */
5353      echo apply_filters( 'the_generator', get_the_generator( $type ), $type ) . "\n";
5354  }
5355  
5356  /**
5357   * Creates the generator XML or Comment for RSS, ATOM, etc.
5358   *
5359   * Returns the correct generator type for the requested output format. Allows
5360   * for a plugin to filter generators on an individual basis using the
5361   * {@see 'get_the_generator_$type'} filter.
5362   *
5363   * @since 2.5.0
5364   *
5365   * @param string $type The type of generator to return - (html|xhtml|atom|rss2|rdf|comment|export).
5366   * @return string|null The HTML content for the generator.
5367   */
5368  function get_the_generator( $type = '' ) {
5369      if ( empty( $type ) ) {
5370  
5371          $current_filter = current_filter();
5372          if ( empty( $current_filter ) ) {
5373              return null;
5374          }
5375  
5376          switch ( $current_filter ) {
5377              case 'rss2_head':
5378              case 'commentsrss2_head':
5379                  $type = 'rss2';
5380                  break;
5381              case 'rss_head':
5382              case 'opml_head':
5383                  $type = 'comment';
5384                  break;
5385              case 'rdf_header':
5386                  $type = 'rdf';
5387                  break;
5388              case 'atom_head':
5389              case 'comments_atom_head':
5390              case 'app_head':
5391                  $type = 'atom';
5392                  break;
5393          }
5394      }
5395  
5396      switch ( $type ) {
5397          case 'html':
5398              $gen = '<meta name="generator" content="WordPress ' . esc_attr( get_bloginfo( 'version' ) ) . '">';
5399              break;
5400          case 'xhtml':
5401              $gen = '<meta name="generator" content="WordPress ' . esc_attr( get_bloginfo( 'version' ) ) . '" />';
5402              break;
5403          case 'atom':
5404              $gen = '<generator uri="https://wordpress.org/" version="' . esc_attr( get_bloginfo_rss( 'version' ) ) . '">WordPress</generator>';
5405              break;
5406          case 'rss2':
5407              $gen = '<generator>' . sanitize_url( 'https://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) ) . '</generator>';
5408              break;
5409          case 'rdf':
5410              $gen = '<admin:generatorAgent rdf:resource="' . sanitize_url( 'https://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) ) . '" />';
5411              break;
5412          case 'comment':
5413              $gen = '<!-- generator="WordPress/' . esc_attr( get_bloginfo( 'version' ) ) . '" -->';
5414              break;
5415          case 'export':
5416              $gen = '<!-- generator="WordPress/' . esc_attr( get_bloginfo_rss( 'version' ) ) . '" created="' . gmdate( 'Y-m-d H:i' ) . '" -->';
5417              break;
5418      }
5419  
5420      /**
5421       * Filters the HTML for the retrieved generator type.
5422       *
5423       * The dynamic portion of the hook name, `$type`, refers to the generator type.
5424       *
5425       * Possible hook names include:
5426       *
5427       *  - `get_the_generator_atom`
5428       *  - `get_the_generator_comment`
5429       *  - `get_the_generator_export`
5430       *  - `get_the_generator_html`
5431       *  - `get_the_generator_rdf`
5432       *  - `get_the_generator_rss2`
5433       *  - `get_the_generator_xhtml`
5434       *
5435       * @since 2.5.0
5436       *
5437       * @param string $gen  The HTML markup output to wp_head().
5438       * @param string $type The type of generator. Accepts 'html', 'xhtml', 'atom',
5439       *                     'rss2', 'rdf', 'comment', 'export'.
5440       */
5441      return apply_filters( "get_the_generator_{$type}", $gen, $type );
5442  }
5443  
5444  /**
5445   * Outputs the HTML checked attribute.
5446   *
5447   * Compares the first two arguments and if identical marks as checked.
5448   *
5449   * @since 1.0.0
5450   *
5451   * @param mixed $checked One of the values to compare.
5452   * @param mixed $current Optional. The other value to compare if not just true.
5453   *                       Default true.
5454   * @param bool  $display Optional. Whether to echo or just return the string.
5455   *                       Default true.
5456   * @return string HTML attribute or empty string.
5457   */
5458  function checked( $checked, $current = true, $display = true ) {
5459      return __checked_selected_helper( $checked, $current, $display, 'checked' );
5460  }
5461  
5462  /**
5463   * Outputs the HTML selected attribute.
5464   *
5465   * Compares the first two arguments and if identical marks as selected.
5466   *
5467   * @since 1.0.0
5468   *
5469   * @param mixed $selected One of the values to compare.
5470   * @param mixed $current  Optional. The other value to compare if not just true.
5471   *                        Default true.
5472   * @param bool  $display  Optional. Whether to echo or just return the string.
5473   *                        Default true.
5474   * @return string HTML attribute or empty string.
5475   */
5476  function selected( $selected, $current = true, $display = true ) {
5477      return __checked_selected_helper( $selected, $current, $display, 'selected' );
5478  }
5479  
5480  /**
5481   * Outputs the HTML disabled attribute.
5482   *
5483   * Compares the first two arguments and if identical marks as disabled.
5484   *
5485   * @since 3.0.0
5486   *
5487   * @param mixed $disabled One of the values to compare.
5488   * @param mixed $current  Optional. The other value to compare if not just true.
5489   *                        Default true.
5490   * @param bool  $display  Optional. Whether to echo or just return the string.
5491   *                        Default true.
5492   * @return string HTML attribute or empty string.
5493   */
5494  function disabled( $disabled, $current = true, $display = true ) {
5495      return __checked_selected_helper( $disabled, $current, $display, 'disabled' );
5496  }
5497  
5498  /**
5499   * Outputs the HTML readonly attribute.
5500   *
5501   * Compares the first two arguments and if identical marks as readonly.
5502   *
5503   * @since 5.9.0
5504   *
5505   * @param mixed $readonly_value One of the values to compare.
5506   * @param mixed $current        Optional. The other value to compare if not just true.
5507   *                              Default true.
5508   * @param bool  $display        Optional. Whether to echo or just return the string.
5509   *                              Default true.
5510   * @return string HTML attribute or empty string.
5511   */
5512  function wp_readonly( $readonly_value, $current = true, $display = true ) {
5513      return __checked_selected_helper( $readonly_value, $current, $display, 'readonly' );
5514  }
5515  
5516  /*
5517   * Include a compat `readonly()` function on PHP < 8.1. Since PHP 8.1,
5518   * `readonly` is a reserved keyword and cannot be used as a function name.
5519   * In order to avoid PHP parser errors, this function was extracted
5520   * to a separate file and is only included conditionally on PHP < 8.1.
5521   */
5522  if ( PHP_VERSION_ID < 80100 ) {
5523      require_once  __DIR__ . '/php-compat/readonly.php';
5524  }
5525  
5526  /**
5527   * Private helper function for checked, selected, disabled and readonly.
5528   *
5529   * Compares the first two arguments and if identical marks as `$type`.
5530   *
5531   * @since 2.8.0
5532   * @access private
5533   *
5534   * @param mixed  $helper  One of the values to compare.
5535   * @param mixed  $current The other value to compare if not just true.
5536   * @param bool   $display Whether to echo or just return the string.
5537   * @param string $type    The type of checked|selected|disabled|readonly we are doing.
5538   * @return string HTML attribute or empty string.
5539   */
5540  function __checked_selected_helper( $helper, $current, $display, $type ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore
5541      if ( (string) $helper === (string) $current ) {
5542          $result = " $type='$type'";
5543      } else {
5544          $result = '';
5545      }
5546  
5547      if ( $display ) {
5548          echo $result;
5549      }
5550  
5551      return $result;
5552  }
5553  
5554  /**
5555   * Assigns a visual indicator for required form fields.
5556   *
5557   * @since 6.1.0
5558   *
5559   * @return string Indicator glyph wrapped in a `span` tag.
5560   */
5561  function wp_required_field_indicator() {
5562      /* translators: Character to identify required form fields. */
5563      $glyph     = __( '*' );
5564      $indicator = '<span class="required">' . esc_html( $glyph ) . '</span>';
5565  
5566      /**
5567       * Filters the markup for a visual indicator of required form fields.
5568       *
5569       * @since 6.1.0
5570       *
5571       * @param string $indicator Markup for the indicator element.
5572       */
5573      return apply_filters( 'wp_required_field_indicator', $indicator );
5574  }
5575  
5576  /**
5577   * Creates a message to explain required form fields.
5578   *
5579   * @since 6.1.0
5580   *
5581   * @return string Message text and glyph wrapped in a `span` tag.
5582   */
5583  function wp_required_field_message() {
5584      $message = sprintf(
5585          '<span class="required-field-message">%s</span>',
5586          /* translators: %s: Asterisk symbol (*). */
5587          sprintf( __( 'Required fields are marked %s' ), wp_required_field_indicator() )
5588      );
5589  
5590      /**
5591       * Filters the message to explain required form fields.
5592       *
5593       * @since 6.1.0
5594       *
5595       * @param string $message Message text and glyph wrapped in a `span` tag.
5596       */
5597      return apply_filters( 'wp_required_field_message', $message );
5598  }
5599  
5600  /**
5601   * Default settings for heartbeat.
5602   *
5603   * Outputs the nonce used in the heartbeat XHR.
5604   *
5605   * @since 3.6.0
5606   *
5607   * @param array $settings
5608   * @return array Heartbeat settings.
5609   */
5610  function wp_heartbeat_settings( $settings ) {
5611      if ( ! is_admin() ) {
5612          $settings['ajaxurl'] = admin_url( 'admin-ajax.php', 'relative' );
5613      }
5614  
5615      if ( is_user_logged_in() ) {
5616          $settings['nonce'] = wp_create_nonce( 'heartbeat-nonce' );
5617      }
5618  
5619      return $settings;
5620  }


Generated : Tue Jul 21 08:20:16 2026 Cross-referenced by PHPXref