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


Generated : Thu Sep 24 08:20:34 2026 Cross-referenced by PHPXref