[ Index ]

PHP Cross Reference of WordPress

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


Generated: Wed Dec 2 01:00:04 2020 Cross-referenced by PHPXref 0.7.1