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


Generated: Sun Oct 13 01:00:02 2024 Cross-referenced by PHPXref 0.7.1