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


Generated : Thu May 9 08:20:02 2024 Cross-referenced by PHPXref