[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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

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


Generated: Sat Sep 19 01:00:03 2020 Cross-referenced by PHPXref 0.7.1