[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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

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


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