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


Generated : Fri Aug 19 08:20:02 2022 Cross-referenced by PHPXref