[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

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


Generated : Sun Jul 19 08:20:17 2026 Cross-referenced by PHPXref