[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/ -> general-template.php (source)

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


Generated: Mon Mar 1 01:00:03 2021 Cross-referenced by PHPXref 0.7.1