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


Generated: Tue Oct 26 01:00:02 2021 Cross-referenced by PHPXref 0.7.1