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


Generated : Sat Nov 23 08:20:01 2024 Cross-referenced by PHPXref