[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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

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


Generated: Sat Apr 4 01:00:03 2020 Cross-referenced by PHPXref 0.7.1