[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

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


Generated: Sun Sep 22 08:20:01 2019 Cross-referenced by PHPXref 0.7