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


Generated: Sat May 15 01:00:05 2021 Cross-referenced by PHPXref 0.7.1