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


Generated : Sun Jun 28 08:20:12 2026 Cross-referenced by PHPXref