| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
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 …', '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 “%s”' ), 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 '»'. 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 = '»', $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 * @phpstan-return ( $display is true ? false|null : string|false ) 1934 */ 1935 function single_month_title( $prefix = '', $display = true ) { 1936 global $wp_locale; 1937 1938 $m = get_query_var( 'm' ); 1939 $year = get_query_var( 'year' ); 1940 $monthnum = get_query_var( 'monthnum' ); 1941 1942 if ( ! empty( $monthnum ) && ! empty( $year ) ) { 1943 $my_year = $year; 1944 $my_month = $wp_locale->get_month( $monthnum ); 1945 } elseif ( ! empty( $m ) ) { 1946 $my_year = substr( $m, 0, 4 ); 1947 $my_month = $wp_locale->get_month( substr( $m, 4, 2 ) ); 1948 } 1949 1950 if ( empty( $my_month ) ) { 1951 return false; 1952 } 1953 1954 $result = $prefix . $my_month . $prefix . $my_year; 1955 1956 if ( ! $display ) { 1957 return $result; 1958 } 1959 1960 echo $result; 1961 1962 return null; 1963 } 1964 1965 /** 1966 * Displays the archive title based on the queried object. 1967 * 1968 * @since 4.1.0 1969 * 1970 * @see get_the_archive_title() 1971 * 1972 * @param string $before Optional. Content to prepend to the title. Default empty. 1973 * @param string $after Optional. Content to append to the title. Default empty. 1974 */ 1975 function the_archive_title( $before = '', $after = '' ) { 1976 $title = get_the_archive_title(); 1977 1978 if ( ! empty( $title ) ) { 1979 echo $before . $title . $after; 1980 } 1981 } 1982 1983 /** 1984 * Retrieves the archive title based on the queried object. 1985 * 1986 * @since 4.1.0 1987 * @since 5.5.0 The title part is wrapped in a `<span>` element. 1988 * 1989 * @return string Archive title. 1990 */ 1991 function get_the_archive_title() { 1992 $title = __( 'Archives' ); 1993 $prefix = ''; 1994 1995 if ( is_category() ) { 1996 $title = single_cat_title( '', false ); 1997 $prefix = _x( 'Category:', 'category archive title prefix' ); 1998 } elseif ( is_tag() ) { 1999 $title = single_tag_title( '', false ); 2000 $prefix = _x( 'Tag:', 'tag archive title prefix' ); 2001 } elseif ( is_author() ) { 2002 $title = get_the_author(); 2003 $prefix = _x( 'Author:', 'author archive title prefix' ); 2004 } elseif ( is_year() ) { 2005 /* translators: See https://www.php.net/manual/datetime.format.php */ 2006 $title = get_the_date( _x( 'Y', 'yearly archives date format' ) ); 2007 $prefix = _x( 'Year:', 'date archive title prefix' ); 2008 } elseif ( is_month() ) { 2009 /* translators: See https://www.php.net/manual/datetime.format.php */ 2010 $title = get_the_date( _x( 'F Y', 'monthly archives date format' ) ); 2011 $prefix = _x( 'Month:', 'date archive title prefix' ); 2012 } elseif ( is_day() ) { 2013 /* translators: See https://www.php.net/manual/datetime.format.php */ 2014 $title = get_the_date( _x( 'F j, Y', 'daily archives date format' ) ); 2015 $prefix = _x( 'Day:', 'date archive title prefix' ); 2016 } elseif ( is_tax( 'post_format' ) ) { 2017 if ( is_tax( 'post_format', 'post-format-aside' ) ) { 2018 $title = _x( 'Asides', 'post format archive title' ); 2019 } elseif ( is_tax( 'post_format', 'post-format-gallery' ) ) { 2020 $title = _x( 'Galleries', 'post format archive title' ); 2021 } elseif ( is_tax( 'post_format', 'post-format-image' ) ) { 2022 $title = _x( 'Images', 'post format archive title' ); 2023 } elseif ( is_tax( 'post_format', 'post-format-video' ) ) { 2024 $title = _x( 'Videos', 'post format archive title' ); 2025 } elseif ( is_tax( 'post_format', 'post-format-quote' ) ) { 2026 $title = _x( 'Quotes', 'post format archive title' ); 2027 } elseif ( is_tax( 'post_format', 'post-format-link' ) ) { 2028 $title = _x( 'Links', 'post format archive title' ); 2029 } elseif ( is_tax( 'post_format', 'post-format-status' ) ) { 2030 $title = _x( 'Statuses', 'post format archive title' ); 2031 } elseif ( is_tax( 'post_format', 'post-format-audio' ) ) { 2032 $title = _x( 'Audio', 'post format archive title' ); 2033 } elseif ( is_tax( 'post_format', 'post-format-chat' ) ) { 2034 $title = _x( 'Chats', 'post format archive title' ); 2035 } 2036 } elseif ( is_post_type_archive() ) { 2037 $title = post_type_archive_title( '', false ); 2038 $prefix = _x( 'Archives:', 'post type archive title prefix' ); 2039 } elseif ( is_tax() ) { 2040 $queried_object = get_queried_object(); 2041 if ( $queried_object ) { 2042 $tax = get_taxonomy( $queried_object->taxonomy ); 2043 $title = single_term_title( '', false ); 2044 $prefix = sprintf( 2045 /* translators: %s: Taxonomy singular name. */ 2046 _x( '%s:', 'taxonomy term archive title prefix' ), 2047 $tax->labels->singular_name 2048 ); 2049 } 2050 } 2051 2052 $original_title = $title; 2053 2054 /** 2055 * Filters the archive title prefix. 2056 * 2057 * @since 5.5.0 2058 * 2059 * @param string $prefix Archive title prefix. 2060 */ 2061 $prefix = apply_filters( 'get_the_archive_title_prefix', $prefix ); 2062 if ( $prefix ) { 2063 $title = sprintf( 2064 /* translators: 1: Title prefix. 2: Title. */ 2065 _x( '%1$s %2$s', 'archive title' ), 2066 $prefix, 2067 '<span>' . $title . '</span>' 2068 ); 2069 } 2070 2071 /** 2072 * Filters the archive title. 2073 * 2074 * @since 4.1.0 2075 * @since 5.5.0 Added the `$prefix` and `$original_title` parameters. 2076 * 2077 * @param string $title Archive title to be displayed. 2078 * @param string $original_title Archive title without prefix. 2079 * @param string $prefix Archive title prefix. 2080 */ 2081 return apply_filters( 'get_the_archive_title', $title, $original_title, $prefix ); 2082 } 2083 2084 /** 2085 * Displays category, tag, term, or author description. 2086 * 2087 * @since 4.1.0 2088 * 2089 * @see get_the_archive_description() 2090 * 2091 * @param string $before Optional. Content to prepend to the description. Default empty. 2092 * @param string $after Optional. Content to append to the description. Default empty. 2093 */ 2094 function the_archive_description( $before = '', $after = '' ) { 2095 $description = get_the_archive_description(); 2096 if ( $description ) { 2097 echo $before . $description . $after; 2098 } 2099 } 2100 2101 /** 2102 * Retrieves the description for an author, post type, or term archive. 2103 * 2104 * @since 4.1.0 2105 * @since 4.7.0 Added support for author archives. 2106 * @since 4.9.0 Added support for post type archives. 2107 * 2108 * @see term_description() 2109 * 2110 * @return string Archive description. 2111 */ 2112 function get_the_archive_description() { 2113 if ( is_author() ) { 2114 $description = get_the_author_meta( 'description' ); 2115 } elseif ( is_post_type_archive() ) { 2116 $description = get_the_post_type_description(); 2117 } else { 2118 $description = term_description(); 2119 } 2120 2121 /** 2122 * Filters the archive description. 2123 * 2124 * @since 4.1.0 2125 * 2126 * @param string $description Archive description to be displayed. 2127 */ 2128 return apply_filters( 'get_the_archive_description', $description ); 2129 } 2130 2131 /** 2132 * Retrieves the description for a post type archive. 2133 * 2134 * @since 4.9.0 2135 * 2136 * @return string The post type description. 2137 */ 2138 function get_the_post_type_description() { 2139 $post_type = get_query_var( 'post_type' ); 2140 2141 if ( is_array( $post_type ) ) { 2142 $post_type = reset( $post_type ); 2143 } 2144 2145 $post_type_obj = get_post_type_object( $post_type ); 2146 2147 // Check if a description is set. 2148 $description = $post_type_obj->description ?? ''; 2149 2150 /** 2151 * Filters the description for a post type archive. 2152 * 2153 * @since 4.9.0 2154 * 2155 * @param string $description The post type description. 2156 * @param WP_Post_Type $post_type_obj The post type object. 2157 */ 2158 return apply_filters( 'get_the_post_type_description', $description, $post_type_obj ); 2159 } 2160 2161 /** 2162 * Retrieves archive link content based on predefined or custom code. 2163 * 2164 * The format can be one of four styles. The 'link' for head element, 'option' 2165 * for use in the select element, 'html' for use in list (either ol or ul HTML 2166 * elements). Custom content is also supported using the before and after 2167 * parameters. 2168 * 2169 * The 'link' format uses the `<link>` HTML element with the **archives** 2170 * relationship. The before and after parameters are not used. The text 2171 * parameter is used to describe the link. 2172 * 2173 * The 'option' format uses the option HTML element for use in select element. 2174 * The value is the url parameter and the before and after parameters are used 2175 * between the text description. 2176 * 2177 * The 'html' format, which is the default, uses the li HTML element for use in 2178 * the list HTML elements. The before parameter is before the link and the after 2179 * parameter is after the closing link. 2180 * 2181 * The custom format uses the before parameter before the link ('a' HTML 2182 * element) and the after parameter after the closing link tag. If the above 2183 * three values for the format are not used, then custom format is assumed. 2184 * 2185 * @since 1.0.0 2186 * @since 5.2.0 Added the `$selected` parameter. 2187 * 2188 * @param string $url URL to archive. 2189 * @param string $text Archive text description. 2190 * @param string $format Optional. Can be 'link', 'option', 'html', or custom. Default 'html'. 2191 * @param string $before Optional. Content to prepend to the description. Default empty. 2192 * @param string $after Optional. Content to append to the description. Default empty. 2193 * @param bool $selected Optional. Set to true if the current page is the selected archive page. Default false. 2194 * @return string HTML link content for archive. 2195 */ 2196 function get_archives_link( $url, $text, $format = 'html', $before = '', $after = '', $selected = false ) { 2197 $text = wptexturize( $text ); 2198 $url = esc_url( $url ); 2199 $aria_current = $selected ? ' aria-current="page"' : ''; 2200 2201 if ( 'link' === $format ) { 2202 $link_html = "\t<link rel='archives' title='" . esc_attr( $text ) . "' href='$url' />\n"; 2203 } elseif ( 'option' === $format ) { 2204 $selected_attr = $selected ? " selected='selected'" : ''; 2205 $link_html = "\t<option value='$url'$selected_attr>$before $text $after</option>\n"; 2206 } elseif ( 'html' === $format ) { 2207 $link_html = "\t<li>$before<a href='$url'$aria_current>$text</a>$after</li>\n"; 2208 } else { // Custom. 2209 $link_html = "\t$before<a href='$url'$aria_current>$text</a>$after\n"; 2210 } 2211 2212 /** 2213 * Filters the archive link content. 2214 * 2215 * @since 2.6.0 2216 * @since 4.5.0 Added the `$url`, `$text`, `$format`, `$before`, and `$after` parameters. 2217 * @since 5.2.0 Added the `$selected` parameter. 2218 * 2219 * @param string $link_html The archive HTML link content. 2220 * @param string $url URL to archive. 2221 * @param string $text Archive text description. 2222 * @param string $format Link format. Can be 'link', 'option', 'html', or custom. 2223 * @param string $before Content to prepend to the description. 2224 * @param string $after Content to append to the description. 2225 * @param bool $selected True if the current page is the selected archive. 2226 */ 2227 return apply_filters( 'get_archives_link', $link_html, $url, $text, $format, $before, $after, $selected ); 2228 } 2229 2230 /** 2231 * Displays archive links based on type and format. 2232 * 2233 * @since 1.2.0 2234 * @since 4.4.0 The `$post_type` argument was added. 2235 * @since 5.2.0 The `$year`, `$monthnum`, `$day`, and `$w` arguments were added. 2236 * 2237 * @see get_archives_link() 2238 * 2239 * @global wpdb $wpdb WordPress database abstraction object. 2240 * @global WP_Locale $wp_locale WordPress date and time locale object. 2241 * 2242 * @param string|array $args { 2243 * Default archive links arguments. Optional. 2244 * 2245 * @type string $type Type of archive to retrieve. Accepts 'daily', 'weekly', 'monthly', 2246 * 'yearly', 'postbypost', or 'alpha'. Both 'postbypost' and 'alpha' 2247 * display the same archive link list as well as post titles instead 2248 * of displaying dates. The difference between the two is that 'alpha' 2249 * will order by post title and 'postbypost' will order by post date. 2250 * Default 'monthly'. 2251 * @type string|int $limit Number of links to limit the query to. Default empty (no limit). 2252 * @type string $format Format each link should take using the $before and $after args. 2253 * Accepts 'link' (`<link>` tag), 'option' (`<option>` tag), 'html' 2254 * (`<li>` tag), or a custom format, which generates a link anchor 2255 * with $before preceding and $after succeeding. Default 'html'. 2256 * @type string $before Markup to prepend to the beginning of each link. Default empty. 2257 * @type string $after Markup to append to the end of each link. Default empty. 2258 * @type bool $show_post_count Whether to display the post count alongside the link. Default false. 2259 * @type bool|int $echo Whether to echo or return the links list. Default 1|true to echo. 2260 * @type string $order Whether to use ascending or descending order. Accepts 'ASC', or 'DESC'. 2261 * Default 'DESC'. 2262 * @type string $post_type Post type. Default 'post'. 2263 * @type string $year Year. Default current year. 2264 * @type string $monthnum Month number. Default current month number. 2265 * @type string $day Day. Default current day. 2266 * @type string $w Week. Default current week. 2267 * } 2268 * @return string|null|void Archive links when 'echo' is false, null when the post type is 2269 * not viewable. Nothing otherwise. 2270 * @phpstan-return ( 2271 * $args is array{ echo: false|0|''|'0', ... } 2272 * ? string|null 2273 * : ( $args is ''|'0'|array ? void : string|null ) 2274 * ) 2275 */ 2276 function wp_get_archives( $args = '' ) { 2277 global $wpdb, $wp_locale; 2278 2279 $defaults = array( 2280 'type' => 'monthly', 2281 'limit' => '', 2282 'format' => 'html', 2283 'before' => '', 2284 'after' => '', 2285 'show_post_count' => false, 2286 'echo' => 1, 2287 'order' => 'DESC', 2288 'post_type' => 'post', 2289 'year' => get_query_var( 'year' ), 2290 'monthnum' => get_query_var( 'monthnum' ), 2291 'day' => get_query_var( 'day' ), 2292 'w' => get_query_var( 'w' ), 2293 ); 2294 2295 /** 2296 * Filters the arguments for displaying archive links. 2297 * 2298 * @since 7.0.0 2299 * 2300 * @see wp_get_archives() 2301 * 2302 * @param array<string, string|int|bool> $args Arguments. 2303 */ 2304 $args = apply_filters( 'wp_get_archives_args', $args ); 2305 2306 $parsed_args = wp_parse_args( $args, $defaults ); 2307 2308 $post_type_object = get_post_type_object( $parsed_args['post_type'] ); 2309 if ( ! is_post_type_viewable( $post_type_object ) ) { 2310 return null; 2311 } 2312 2313 $parsed_args['post_type'] = $post_type_object->name; 2314 2315 if ( '' === $parsed_args['type'] ) { 2316 $parsed_args['type'] = 'monthly'; 2317 } 2318 2319 if ( ! empty( $parsed_args['limit'] ) ) { 2320 $parsed_args['limit'] = absint( $parsed_args['limit'] ); 2321 $parsed_args['limit'] = ' LIMIT ' . $parsed_args['limit']; 2322 } 2323 2324 $order = strtoupper( $parsed_args['order'] ); 2325 if ( 'ASC' !== $order ) { 2326 $order = 'DESC'; 2327 } 2328 2329 // This is what will separate dates on weekly archive links. 2330 $archive_week_separator = '–'; 2331 2332 $sql_where = $wpdb->prepare( "WHERE post_type = %s AND post_status = 'publish'", $parsed_args['post_type'] ); 2333 2334 /** 2335 * Filters the SQL WHERE clause for retrieving archives. 2336 * 2337 * @since 2.2.0 2338 * 2339 * @param string $sql_where Portion of SQL query containing the WHERE clause. 2340 * @param array $parsed_args An array of default arguments. 2341 */ 2342 $where = apply_filters( 'getarchives_where', $sql_where, $parsed_args ); 2343 2344 /** 2345 * Filters the SQL JOIN clause for retrieving archives. 2346 * 2347 * @since 2.2.0 2348 * 2349 * @param string $sql_join Portion of SQL query containing JOIN clause. 2350 * @param array $parsed_args An array of default arguments. 2351 */ 2352 $join = apply_filters( 'getarchives_join', '', $parsed_args ); 2353 2354 $output = ''; 2355 2356 $last_changed = wp_cache_get_last_changed( 'posts' ); 2357 2358 $limit = $parsed_args['limit']; 2359 2360 if ( 'monthly' === $parsed_args['type'] ) { 2361 $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"; 2362 $key = md5( $query ); 2363 $key = "wp_get_archives:$key"; 2364 $results = wp_cache_get_salted( $key, 'post-queries', $last_changed ); 2365 if ( ! $results ) { 2366 $results = $wpdb->get_results( $query ); 2367 wp_cache_set_salted( $key, $results, 'post-queries', $last_changed ); 2368 } 2369 if ( $results ) { 2370 $after = $parsed_args['after']; 2371 foreach ( (array) $results as $result ) { 2372 $url = get_month_link( $result->year, $result->month ); 2373 if ( 'post' !== $parsed_args['post_type'] ) { 2374 $url = add_query_arg( 'post_type', $parsed_args['post_type'], $url ); 2375 } 2376 /* translators: 1: Month name, 2: 4-digit year. */ 2377 $text = sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $result->month ), $result->year ); 2378 if ( $parsed_args['show_post_count'] ) { 2379 $parsed_args['after'] = ' (' . $result->posts . ')' . $after; 2380 } 2381 $selected = is_archive() && (string) $parsed_args['year'] === $result->year && (string) $parsed_args['monthnum'] === $result->month; 2382 $output .= get_archives_link( $url, $text, $parsed_args['format'], $parsed_args['before'], $parsed_args['after'], $selected ); 2383 } 2384 } 2385 } elseif ( 'yearly' === $parsed_args['type'] ) { 2386 $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"; 2387 $key = md5( $query ); 2388 $key = "wp_get_archives:$key"; 2389 $results = wp_cache_get_salted( $key, 'post-queries', $last_changed ); 2390 if ( ! $results ) { 2391 $results = $wpdb->get_results( $query ); 2392 wp_cache_set_salted( $key, $results, 'post-queries', $last_changed ); 2393 } 2394 if ( $results ) { 2395 $after = $parsed_args['after']; 2396 foreach ( (array) $results as $result ) { 2397 $url = get_year_link( $result->year ); 2398 if ( 'post' !== $parsed_args['post_type'] ) { 2399 $url = add_query_arg( 'post_type', $parsed_args['post_type'], $url ); 2400 } 2401 $text = sprintf( '%d', $result->year ); 2402 if ( $parsed_args['show_post_count'] ) { 2403 $parsed_args['after'] = ' (' . $result->posts . ')' . $after; 2404 } 2405 $selected = is_archive() && (string) $parsed_args['year'] === $result->year; 2406 $output .= get_archives_link( $url, $text, $parsed_args['format'], $parsed_args['before'], $parsed_args['after'], $selected ); 2407 } 2408 } 2409 } elseif ( 'daily' === $parsed_args['type'] ) { 2410 $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"; 2411 $key = md5( $query ); 2412 $key = "wp_get_archives:$key"; 2413 $results = wp_cache_get_salted( $key, 'post-queries', $last_changed ); 2414 if ( ! $results ) { 2415 $results = $wpdb->get_results( $query ); 2416 wp_cache_set_salted( $key, $results, 'post-queries', $last_changed ); 2417 } 2418 if ( $results ) { 2419 $after = $parsed_args['after']; 2420 $date_format = get_option( 'date_format' ); 2421 foreach ( (array) $results as $result ) { 2422 $url = get_day_link( $result->year, $result->month, $result->dayofmonth ); 2423 if ( 'post' !== $parsed_args['post_type'] ) { 2424 $url = add_query_arg( 'post_type', $parsed_args['post_type'], $url ); 2425 } 2426 $date = sprintf( '%1$d-%2$02d-%3$02d 00:00:00', $result->year, $result->month, $result->dayofmonth ); 2427 $text = mysql2date( $date_format, $date ); 2428 if ( $parsed_args['show_post_count'] ) { 2429 $parsed_args['after'] = ' (' . $result->posts . ')' . $after; 2430 } 2431 $selected = is_archive() && (string) $parsed_args['year'] === $result->year && (string) $parsed_args['monthnum'] === $result->month && (string) $parsed_args['day'] === $result->dayofmonth; 2432 $output .= get_archives_link( $url, $text, $parsed_args['format'], $parsed_args['before'], $parsed_args['after'], $selected ); 2433 } 2434 } 2435 } elseif ( 'weekly' === $parsed_args['type'] ) { 2436 $week = _wp_mysql_week( '`post_date`' ); 2437 $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"; 2438 $key = md5( $query ); 2439 $key = "wp_get_archives:$key"; 2440 $results = wp_cache_get_salted( $key, 'post-queries', $last_changed ); 2441 if ( ! $results ) { 2442 $results = $wpdb->get_results( $query ); 2443 wp_cache_set_salted( $key, $results, 'post-queries', $last_changed ); 2444 } 2445 $arc_w_last = ''; 2446 if ( $results ) { 2447 $after = $parsed_args['after']; 2448 $start_of_week = get_option( 'start_of_week' ); 2449 $date_format = get_option( 'date_format' ); 2450 foreach ( (array) $results as $result ) { 2451 if ( $result->week !== $arc_w_last ) { 2452 $arc_year = $result->yr; 2453 $arc_w_last = $result->week; 2454 $arc_week = get_weekstartend( $result->yyyymmdd, $start_of_week ); 2455 $arc_week_start = date_i18n( $date_format, $arc_week['start'] ); 2456 $arc_week_end = date_i18n( $date_format, $arc_week['end'] ); 2457 $url = add_query_arg( 2458 array( 2459 'm' => $arc_year, 2460 'w' => $result->week, 2461 ), 2462 home_url( '/' ) 2463 ); 2464 if ( 'post' !== $parsed_args['post_type'] ) { 2465 $url = add_query_arg( 'post_type', $parsed_args['post_type'], $url ); 2466 } 2467 $text = $arc_week_start . $archive_week_separator . $arc_week_end; 2468 if ( $parsed_args['show_post_count'] ) { 2469 $parsed_args['after'] = ' (' . $result->posts . ')' . $after; 2470 } 2471 $selected = is_archive() && (string) $parsed_args['year'] === $result->yr && (string) $parsed_args['w'] === $result->week; 2472 $output .= get_archives_link( $url, $text, $parsed_args['format'], $parsed_args['before'], $parsed_args['after'], $selected ); 2473 } 2474 } 2475 } 2476 } elseif ( ( 'postbypost' === $parsed_args['type'] ) || ( 'alpha' === $parsed_args['type'] ) ) { 2477 $orderby = ( 'alpha' === $parsed_args['type'] ) ? 'post_title ASC ' : 'post_date DESC, ID DESC '; 2478 $query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit"; 2479 $key = md5( $query ); 2480 $key = "wp_get_archives:$key"; 2481 $results = wp_cache_get_salted( $key, 'post-queries', $last_changed ); 2482 if ( ! $results ) { 2483 $results = $wpdb->get_results( $query ); 2484 wp_cache_set_salted( $key, $results, 'post-queries', $last_changed ); 2485 } 2486 if ( $results ) { 2487 foreach ( (array) $results as $result ) { 2488 if ( '0000-00-00 00:00:00' !== $result->post_date ) { 2489 $url = get_permalink( $result ); 2490 if ( $result->post_title ) { 2491 /** This filter is documented in wp-includes/post-template.php */ 2492 $text = strip_tags( apply_filters( 'the_title', $result->post_title, $result->ID ) ); 2493 } else { 2494 $text = $result->ID; 2495 } 2496 $selected = get_the_ID() === $result->ID; 2497 $output .= get_archives_link( $url, $text, $parsed_args['format'], $parsed_args['before'], $parsed_args['after'], $selected ); 2498 } 2499 } 2500 } 2501 } 2502 2503 if ( $parsed_args['echo'] ) { 2504 echo $output; 2505 } else { 2506 return $output; 2507 } 2508 } 2509 2510 /** 2511 * Gets number of days since the start of the week. 2512 * 2513 * @since 1.5.0 2514 * 2515 * @param int $num Number of day. 2516 * @return float Days since the start of the week. 2517 */ 2518 function calendar_week_mod( $num ) { 2519 $base = 7; 2520 return ( $num - $base * floor( $num / $base ) ); 2521 } 2522 2523 /** 2524 * Displays calendar with days that have posts as links. 2525 * 2526 * The calendar is cached, which will be retrieved, if it exists. If there are 2527 * no posts for the month, then it will not be displayed. 2528 * 2529 * @since 1.0.0 2530 * @since 6.8.0 Added the `$args` parameter, with backward compatibility 2531 * for the replaced `$initial` and `$display` parameters. 2532 * 2533 * @global wpdb $wpdb WordPress database abstraction object. 2534 * @global int $m 2535 * @global int $monthnum 2536 * @global int $year 2537 * @global WP_Locale $wp_locale WordPress date and time locale object. 2538 * @global array $posts 2539 * 2540 * @param array $args { 2541 * Optional. Arguments for the `get_calendar` function. 2542 * 2543 * @type bool $initial Whether to use initial calendar names. Default true. 2544 * @type bool $display Whether to display the calendar output. Default true. 2545 * @type string $post_type Optional. Post type. Default 'post'. 2546 * } 2547 * @return string|null|void Calendar HTML when `$display` is false, null when the site has 2548 * no posts. Nothing otherwise. 2549 * @phpstan-return ( $args is array{ display: false|0|''|'0', ... } ? string|null : void ) 2550 */ 2551 function get_calendar( $args = array() ) { 2552 global $wpdb, $m, $monthnum, $year, $wp_locale, $posts; 2553 2554 $defaults = array( 2555 'initial' => true, 2556 'display' => true, 2557 'post_type' => 'post', 2558 ); 2559 2560 $original_args = func_get_args(); 2561 $args = array(); 2562 2563 if ( ! empty( $original_args ) ) { 2564 if ( ! is_array( $original_args[0] ) ) { 2565 if ( isset( $original_args[0] ) && is_bool( $original_args[0] ) ) { 2566 $defaults['initial'] = $original_args[0]; 2567 } 2568 if ( isset( $original_args[1] ) && is_bool( $original_args[1] ) ) { 2569 $defaults['display'] = $original_args[1]; 2570 } 2571 } else { 2572 $args = $original_args[0]; 2573 } 2574 } 2575 2576 /** 2577 * Filter the `get_calendar` function arguments before they are used. 2578 * 2579 * @since 6.8.0 2580 * 2581 * @param array $args { 2582 * Optional. Arguments for the `get_calendar` function. 2583 * 2584 * @type bool $initial Whether to use initial calendar names. Default true. 2585 * @type bool $display Whether to display the calendar output. Default true. 2586 * @type string $post_type Optional. Post type. Default 'post'. 2587 * } 2588 */ 2589 $args = apply_filters( 'get_calendar_args', wp_parse_args( $args, $defaults ) ); 2590 2591 if ( ! post_type_exists( $args['post_type'] ) ) { 2592 $args['post_type'] = 'post'; 2593 } 2594 2595 $w = 0; 2596 if ( isset( $_GET['w'] ) ) { 2597 $w = (int) $_GET['w']; 2598 } 2599 2600 /* 2601 * Normalize the cache key. 2602 * 2603 * The following ensures the same cache key is used for the same parameter 2604 * and parameter equivalents. This prevents `post_type > post, initial > true` 2605 * from generating a different key from the same values in the reverse order. 2606 * 2607 * `display` is excluded from the cache key as the cache contains the same 2608 * HTML regardless of this function's need to echo or return the output. 2609 * 2610 * The global values contain data generated by the URL query string variables. 2611 */ 2612 $cache_args = $args; 2613 unset( $cache_args['display'] ); 2614 2615 $cache_args['globals'] = array( 2616 'm' => $m, 2617 'monthnum' => $monthnum, 2618 'year' => $year, 2619 'week' => $w, 2620 ); 2621 2622 wp_recursive_ksort( $cache_args ); 2623 $key = md5( serialize( $cache_args ) ); 2624 $cache = wp_cache_get( 'get_calendar', 'calendar' ); 2625 2626 if ( $cache && is_array( $cache ) && isset( $cache[ $key ] ) ) { 2627 /** This filter is documented in wp-includes/general-template.php */ 2628 $output = apply_filters( 'get_calendar', $cache[ $key ], $args ); 2629 2630 if ( $args['display'] ) { 2631 echo $output; 2632 return; 2633 } 2634 2635 return $output; 2636 } 2637 2638 if ( ! is_array( $cache ) ) { 2639 $cache = array(); 2640 } 2641 2642 $post_type = $args['post_type']; 2643 2644 // Quick check. If we have no posts at all, abort! 2645 if ( ! $posts ) { 2646 $gotsome = $wpdb->get_var( 2647 $wpdb->prepare( 2648 "SELECT 1 as test 2649 FROM $wpdb->posts 2650 WHERE post_type = %s 2651 AND post_status = 'publish' 2652 LIMIT 1", 2653 $post_type 2654 ) 2655 ); 2656 2657 if ( ! $gotsome ) { 2658 $cache[ $key ] = ''; 2659 wp_cache_set( 'get_calendar', $cache, 'calendar' ); 2660 return null; 2661 } 2662 } 2663 2664 // week_begins = 0 stands for Sunday. 2665 $week_begins = (int) get_option( 'start_of_week' ); 2666 2667 // Read the current date. 2668 list( $current_year, $current_month, $current_day ) = array_map( 'intval', explode( '-', current_time( 'Y-m-j' ) ) ); 2669 2670 // Let's figure out when we are. 2671 if ( ! empty( $monthnum ) && ! empty( $year ) ) { 2672 $thismonth = (int) $monthnum; 2673 $thisyear = (int) $year; 2674 } elseif ( ! empty( $w ) ) { 2675 // We need to get the month from MySQL. 2676 $thisyear = (int) substr( $m, 0, 4 ); 2677 // It seems MySQL's weeks disagree with PHP's. 2678 $d = ( ( $w - 1 ) * 7 ) + 6; 2679 $thismonth = (int) $wpdb->get_var( 2680 $wpdb->prepare( 2681 "SELECT DATE_FORMAT((DATE_ADD('%d0101', INTERVAL %d DAY) ), '%%m')", 2682 $thisyear, 2683 $d 2684 ) 2685 ); 2686 } elseif ( ! empty( $m ) ) { 2687 $thisyear = (int) substr( $m, 0, 4 ); 2688 if ( strlen( $m ) < 6 ) { 2689 $thismonth = 1; 2690 } else { 2691 $thismonth = (int) substr( $m, 4, 2 ); 2692 } 2693 } else { 2694 $thisyear = $current_year; 2695 $thismonth = $current_month; 2696 } 2697 2698 $unixmonth = mktime( 0, 0, 0, $thismonth, 1, $thisyear ); 2699 $last_day = gmdate( 't', $unixmonth ); 2700 2701 // Get the next and previous month and year with at least one post. 2702 $previous = $wpdb->get_row( 2703 $wpdb->prepare( 2704 "SELECT MONTH(post_date) AS month, YEAR(post_date) AS year 2705 FROM $wpdb->posts 2706 WHERE post_date < '%d-%d-01' 2707 AND post_type = %s AND post_status = 'publish' 2708 ORDER BY post_date DESC 2709 LIMIT 1", 2710 $thisyear, 2711 zeroise( $thismonth, 2 ), 2712 $post_type 2713 ) 2714 ); 2715 2716 $next = $wpdb->get_row( 2717 $wpdb->prepare( 2718 "SELECT MONTH(post_date) AS month, YEAR(post_date) AS year 2719 FROM $wpdb->posts 2720 WHERE post_date > '%d-%d-%d 23:59:59' 2721 AND post_type = %s AND post_status = 'publish' 2722 ORDER BY post_date ASC 2723 LIMIT 1", 2724 $thisyear, 2725 zeroise( $thismonth, 2 ), 2726 $last_day, 2727 $post_type 2728 ) 2729 ); 2730 2731 /* translators: Calendar caption: 1: Month name, 2: 4-digit year. */ 2732 $calendar_caption = _x( '%1$s %2$s', 'calendar caption' ); 2733 $calendar_output = '<table id="wp-calendar" class="wp-calendar-table"> 2734 <caption>' . sprintf( 2735 $calendar_caption, 2736 $wp_locale->get_month( $thismonth ), 2737 gmdate( 'Y', $unixmonth ) 2738 ) . '</caption> 2739 <thead> 2740 <tr>'; 2741 2742 $myweek = array(); 2743 2744 for ( $wdcount = 0; $wdcount <= 6; $wdcount++ ) { 2745 $myweek[] = $wp_locale->get_weekday( ( $wdcount + $week_begins ) % 7 ); 2746 } 2747 2748 foreach ( $myweek as $wd ) { 2749 $day_name = $args['initial'] ? $wp_locale->get_weekday_initial( $wd ) : $wp_locale->get_weekday_abbrev( $wd ); 2750 $wd = esc_attr( $wd ); 2751 $calendar_output .= "\n\t\t<th scope=\"col\" aria-label=\"$wd\">$day_name</th>"; 2752 } 2753 2754 $calendar_output .= ' 2755 </tr> 2756 </thead> 2757 <tbody> 2758 <tr>'; 2759 2760 $daywithpost = array(); 2761 2762 // Get days with posts. 2763 $dayswithposts = $wpdb->get_results( 2764 $wpdb->prepare( 2765 "SELECT DISTINCT DAYOFMONTH(post_date) 2766 FROM $wpdb->posts WHERE post_date >= '%d-%d-01 00:00:00' 2767 AND post_type = %s AND post_status = 'publish' 2768 AND post_date <= '%d-%d-%d 23:59:59'", 2769 $thisyear, 2770 zeroise( $thismonth, 2 ), 2771 $post_type, 2772 $thisyear, 2773 zeroise( $thismonth, 2 ), 2774 $last_day 2775 ), 2776 ARRAY_N 2777 ); 2778 2779 if ( $dayswithposts ) { 2780 foreach ( (array) $dayswithposts as $daywith ) { 2781 $daywithpost[] = (int) $daywith[0]; 2782 } 2783 } 2784 2785 // See how much we should pad in the beginning. 2786 $pad = calendar_week_mod( (int) gmdate( 'w', $unixmonth ) - $week_begins ); 2787 if ( $pad > 0 ) { 2788 $calendar_output .= "\n\t\t" . '<td colspan="' . esc_attr( $pad ) . '" class="pad"> </td>'; 2789 } 2790 2791 $newrow = false; 2792 $daysinmonth = (int) gmdate( 't', $unixmonth ); 2793 2794 for ( $day = 1; $day <= $daysinmonth; ++$day ) { 2795 if ( $newrow ) { 2796 $calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t"; 2797 } 2798 2799 $newrow = false; 2800 2801 if ( $current_day === $day 2802 && $current_month === $thismonth 2803 && $current_year === $thisyear 2804 ) { 2805 $calendar_output .= '<td id="today">'; 2806 } else { 2807 $calendar_output .= '<td>'; 2808 } 2809 2810 if ( in_array( $day, $daywithpost, true ) ) { 2811 // Any posts today? 2812 $date_format = gmdate( _x( 'F j, Y', 'daily archives date format' ), strtotime( "{$thisyear}-{$thismonth}-{$day}" ) ); 2813 /* translators: Post calendar label. %s: Date. */ 2814 $label = sprintf( __( 'Posts published on %s' ), $date_format ); 2815 $calendar_output .= sprintf( 2816 '<a href="%s" aria-label="%s">%s</a>', 2817 get_day_link( $thisyear, $thismonth, $day ), 2818 esc_attr( $label ), 2819 $day 2820 ); 2821 } else { 2822 $calendar_output .= $day; 2823 } 2824 2825 $calendar_output .= '</td>'; 2826 2827 if ( 6 === (int) calendar_week_mod( (int) gmdate( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins ) ) { 2828 $newrow = true; 2829 } 2830 } 2831 2832 $pad = 7 - calendar_week_mod( (int) gmdate( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins ); 2833 if ( 0 < $pad && $pad < 7 ) { 2834 $calendar_output .= "\n\t\t" . '<td class="pad" colspan="' . esc_attr( $pad ) . '"> </td>'; 2835 } 2836 2837 $calendar_output .= "\n\t</tr>\n\t</tbody>"; 2838 2839 $calendar_output .= "\n\t</table>"; 2840 2841 $calendar_output .= '<nav aria-label="' . __( 'Previous and next months' ) . '" class="wp-calendar-nav">'; 2842 2843 if ( $previous ) { 2844 $calendar_output .= "\n\t\t" . sprintf( 2845 '<span class="wp-calendar-nav-prev"><a href="%1$s">« %2$s</a></span>', 2846 get_month_link( $previous->year, $previous->month ), 2847 $wp_locale->get_month_abbrev( $wp_locale->get_month( $previous->month ) ) 2848 ); 2849 } else { 2850 $calendar_output .= "\n\t\t" . '<span class="wp-calendar-nav-prev"> </span>'; 2851 } 2852 2853 $calendar_output .= "\n\t\t" . '<span class="pad"> </span>'; 2854 2855 if ( $next ) { 2856 $calendar_output .= "\n\t\t" . sprintf( 2857 '<span class="wp-calendar-nav-next"><a href="%1$s">%2$s »</a></span>', 2858 get_month_link( $next->year, $next->month ), 2859 $wp_locale->get_month_abbrev( $wp_locale->get_month( $next->month ) ) 2860 ); 2861 } else { 2862 $calendar_output .= "\n\t\t" . '<span class="wp-calendar-nav-next"> </span>'; 2863 } 2864 2865 $calendar_output .= ' 2866 </nav>'; 2867 2868 $cache[ $key ] = $calendar_output; 2869 wp_cache_set( 'get_calendar', $cache, 'calendar' ); 2870 2871 /** 2872 * Filters the HTML calendar output. 2873 * 2874 * @since 3.0.0 2875 * @since 6.8.0 Added the `$args` parameter. 2876 * 2877 * @param string $calendar_output HTML output of the calendar. 2878 * @param array $args { 2879 * Optional. Array of display arguments. 2880 * 2881 * @type bool $initial Whether to use initial calendar names. Default true. 2882 * @type bool $display Whether to display the calendar output. Default true. 2883 * @type string $post_type Optional. Post type. Default 'post'. 2884 * } 2885 */ 2886 $calendar_output = apply_filters( 'get_calendar', $calendar_output, $args ); 2887 2888 if ( $args['display'] ) { 2889 echo $calendar_output; 2890 return; 2891 } 2892 2893 return $calendar_output; 2894 } 2895 2896 /** 2897 * Purges the cached results of get_calendar. 2898 * 2899 * @see get_calendar() 2900 * @since 2.1.0 2901 */ 2902 function delete_get_calendar_cache() { 2903 wp_cache_delete( 'get_calendar', 'calendar' ); 2904 } 2905 2906 /** 2907 * Displays all of the allowed tags in HTML format with attributes. 2908 * 2909 * This is useful for displaying in the comment area, which elements and 2910 * attributes are supported. As well as any plugins which want to display it. 2911 * 2912 * @since 1.0.1 2913 * @since 4.4.0 No longer used in core. 2914 * 2915 * @global array $allowedtags 2916 * 2917 * @return string HTML allowed tags entity encoded. 2918 */ 2919 function allowed_tags() { 2920 global $allowedtags; 2921 $allowed = ''; 2922 foreach ( (array) $allowedtags as $tag => $attributes ) { 2923 $allowed .= '<' . $tag; 2924 if ( 0 < count( $attributes ) ) { 2925 foreach ( $attributes as $attribute => $limits ) { 2926 $allowed .= ' ' . $attribute . '=""'; 2927 } 2928 } 2929 $allowed .= '> '; 2930 } 2931 return htmlentities( $allowed ); 2932 } 2933 2934 /***** Date/Time tags */ 2935 2936 /** 2937 * Outputs the date in iso8601 format for xml files. 2938 * 2939 * @since 1.0.0 2940 */ 2941 function the_date_xml() { 2942 echo mysql2date( 'Y-m-d', get_post()->post_date, false ); 2943 } 2944 2945 /** 2946 * Displays or retrieves the date of the post (once per date). 2947 * 2948 * Will only output the date if the current post's date is different from the 2949 * previous one output. 2950 * 2951 * i.e. Only one date listing will show per day worth of posts shown in the loop, even if the 2952 * function is called several times for each post. 2953 * 2954 * HTML output can be filtered with {@see 'the_date'}. 2955 * Date string output can be filtered with {@see 'get_the_date'}. 2956 * 2957 * @since 0.71 2958 * 2959 * @global string $currentday The day of the current post in the loop. 2960 * @global string $previousday The day of the previous post in the loop. 2961 * 2962 * @param string $format Optional. PHP date format. Defaults to the 'date_format' option. 2963 * @param string $before Optional. Output before the date. Default empty. 2964 * @param string $after Optional. Output after the date. Default empty. 2965 * @param bool $display Optional. Whether to echo the date or return it. Default true. 2966 * @return string|void The date when `$display` is false, or an empty string when the post's 2967 * date matches the previously output one. Nothing otherwise. 2968 * @phpstan-return ( $display is true ? void : string ) 2969 */ 2970 function the_date( $format = '', $before = '', $after = '', $display = true ) { 2971 global $currentday, $previousday; 2972 2973 $the_date = ''; 2974 2975 if ( is_new_day() ) { 2976 $the_date = $before . get_the_date( $format ) . $after; 2977 $previousday = $currentday; 2978 } 2979 2980 /** 2981 * Filters the date of the post, for display. 2982 * 2983 * @since 0.71 2984 * 2985 * @param string $the_date The formatted date string. 2986 * @param string $format PHP date format. 2987 * @param string $before HTML output before the date. 2988 * @param string $after HTML output after the date. 2989 */ 2990 $the_date = apply_filters( 'the_date', $the_date, $format, $before, $after ); 2991 2992 if ( ! $display ) { 2993 return $the_date; 2994 } 2995 2996 echo $the_date; 2997 } 2998 2999 /** 3000 * Retrieves the date of the post. 3001 * 3002 * Unlike the_date() this function will always return the date. 3003 * Modify output with the {@see 'get_the_date'} filter. 3004 * 3005 * @since 3.0.0 3006 * 3007 * @param string $format Optional. PHP date format. Defaults to the 'date_format' option. 3008 * @param int|WP_Post|null $post Optional. Post ID or WP_Post object. Default current post. 3009 * @return string|int|false Date the current post was written. False on failure. 3010 * 3011 * @phpstan-return ( $format is 'U'|'G' ? int|false : string|false ) 3012 */ 3013 function get_the_date( $format = '', $post = null ) { 3014 $post = get_post( $post ); 3015 3016 if ( ! $post ) { 3017 return false; 3018 } 3019 3020 $_format = ! empty( $format ) ? $format : get_option( 'date_format' ); 3021 3022 $the_date = get_post_time( $_format, false, $post, true ); 3023 3024 /** 3025 * Filters the date of the post. 3026 * 3027 * @since 3.0.0 3028 * 3029 * @param string|int $the_date Formatted date string or Unix timestamp if `$format` is 'U' or 'G'. 3030 * @param string $format PHP date format. 3031 * @param WP_Post $post The post object. 3032 */ 3033 return apply_filters( 'get_the_date', $the_date, $format, $post ); 3034 } 3035 3036 /** 3037 * Displays the date on which the post was last modified. 3038 * 3039 * @since 2.1.0 3040 * 3041 * @param string $format Optional. PHP date format. Defaults to the 'date_format' option. 3042 * @param string $before Optional. Output before the date. Default empty. 3043 * @param string $after Optional. Output after the date. Default empty. 3044 * @param bool $display Optional. Whether to echo the date or return it. Default true. 3045 * @return string|void The modified date when `$display` is false, nothing otherwise. 3046 * @phpstan-return ( $display is true ? void : string ) 3047 */ 3048 function the_modified_date( $format = '', $before = '', $after = '', $display = true ) { 3049 $the_modified_date = $before . get_the_modified_date( $format ) . $after; 3050 3051 /** 3052 * Filters the date a post was last modified, for display. 3053 * 3054 * @since 2.1.0 3055 * 3056 * @param string $the_modified_date The last modified date. 3057 * @param string $format PHP date format. 3058 * @param string $before HTML output before the date. 3059 * @param string $after HTML output after the date. 3060 */ 3061 $the_modified_date = apply_filters( 'the_modified_date', $the_modified_date, $format, $before, $after ); 3062 3063 if ( ! $display ) { 3064 return $the_modified_date; 3065 } 3066 3067 echo $the_modified_date; 3068 } 3069 3070 /** 3071 * Retrieves the date on which the post was last modified. 3072 * 3073 * @since 2.1.0 3074 * @since 4.6.0 Added the `$post` parameter. 3075 * 3076 * @param string $format Optional. PHP date format. Defaults to the 'date_format' option. 3077 * @param int|WP_Post|null $post Optional. Post ID or WP_Post object. Default current post. 3078 * @return string|int|false Date the current post was modified. False on failure. 3079 * 3080 * @phpstan-return ( $format is 'U'|'G' ? int|false : string|false ) 3081 */ 3082 function get_the_modified_date( $format = '', $post = null ) { 3083 $post = get_post( $post ); 3084 3085 if ( ! $post ) { 3086 // For backward compatibility, failures go through the filter below. 3087 $the_time = false; 3088 } else { 3089 $_format = ! empty( $format ) ? $format : get_option( 'date_format' ); 3090 3091 $the_time = get_post_modified_time( $_format, false, $post, true ); 3092 } 3093 3094 /** 3095 * Filters the date a post was last modified. 3096 * 3097 * @since 2.1.0 3098 * @since 4.6.0 Added the `$post` parameter. 3099 * 3100 * @param string|int|false $the_time The formatted date or false if no post is found. 3101 * @param string $format PHP date format. 3102 * @param WP_Post|null $post WP_Post object or null if no post is found. 3103 */ 3104 return apply_filters( 'get_the_modified_date', $the_time, $format, $post ); 3105 } 3106 3107 /** 3108 * Displays the time of the post. 3109 * 3110 * @since 0.71 3111 * 3112 * @param string $format Optional. Format to use for retrieving the time the post 3113 * was written. Accepts 'G', 'U', or PHP date format. 3114 * Defaults to the 'time_format' option. 3115 */ 3116 function the_time( $format = '' ) { 3117 /** 3118 * Filters the time of the post, for display. 3119 * 3120 * @since 0.71 3121 * 3122 * @param string $get_the_time The formatted time. 3123 * @param string $format Format to use for retrieving the time the post 3124 * was written. Accepts 'G', 'U', or PHP date format. 3125 */ 3126 echo apply_filters( 'the_time', get_the_time( $format ), $format ); 3127 } 3128 3129 /** 3130 * Retrieves the time of the post. 3131 * 3132 * @since 1.5.0 3133 * 3134 * @param string $format Optional. Format to use for retrieving the time the post 3135 * was written. Accepts 'G', 'U', or PHP date format. 3136 * Defaults to the 'time_format' option. 3137 * @param int|WP_Post|null $post Post ID or post object. Default is global `$post` object. 3138 * @return string|int|false Formatted date string or Unix timestamp if `$format` is 'U' or 'G'. 3139 * False on failure. 3140 * 3141 * @phpstan-return ( $format is 'U'|'G' ? int|false : string|false ) 3142 */ 3143 function get_the_time( $format = '', $post = null ) { 3144 $post = get_post( $post ); 3145 3146 if ( ! $post ) { 3147 return false; 3148 } 3149 3150 $_format = ! empty( $format ) ? $format : get_option( 'time_format' ); 3151 3152 $the_time = get_post_time( $_format, false, $post, true ); 3153 3154 /** 3155 * Filters the time of the post. 3156 * 3157 * @since 1.5.0 3158 * 3159 * @param string|int $the_time Formatted date string or Unix timestamp if `$format` is 'U' or 'G'. 3160 * @param string $format Format to use for retrieving the time the post 3161 * was written. Accepts 'G', 'U', or PHP date format. 3162 * @param WP_Post $post Post object. 3163 */ 3164 return apply_filters( 'get_the_time', $the_time, $format, $post ); 3165 } 3166 3167 /** 3168 * Retrieves the localized time of the post. 3169 * 3170 * @since 2.0.0 3171 * 3172 * @param string $format Optional. Format to use for retrieving the time the post 3173 * was written. Accepts 'G', 'U', or PHP date format. Default 'U'. 3174 * @param bool $gmt Optional. Whether to retrieve the GMT time. Default false. 3175 * @param int|WP_Post|null $post Post ID or post object. Default is global `$post` object. 3176 * @param bool $translate Whether to translate the time string. Default false. 3177 * @return string|int|false Formatted date string or Unix timestamp if `$format` is 'U' or 'G'. 3178 * False on failure. 3179 * 3180 * @phpstan-return ( $format is 'U'|'G' ? int|false : string|false ) 3181 */ 3182 function get_post_time( $format = 'U', $gmt = false, $post = null, $translate = false ) { 3183 $post = get_post( $post ); 3184 3185 if ( ! $post ) { 3186 return false; 3187 } 3188 3189 $source = ( $gmt ) ? 'gmt' : 'local'; 3190 $datetime = get_post_datetime( $post, 'date', $source ); 3191 3192 if ( false === $datetime ) { 3193 return false; 3194 } 3195 3196 if ( 'U' === $format || 'G' === $format ) { 3197 $time = $datetime->getTimestamp(); 3198 3199 // Returns a sum of timestamp with timezone offset. Ideally should never be used. 3200 if ( ! $gmt ) { 3201 $time += $datetime->getOffset(); 3202 } 3203 } elseif ( $translate ) { 3204 $time = wp_date( $format, $datetime->getTimestamp(), $gmt ? new DateTimeZone( 'UTC' ) : null ); 3205 } else { 3206 if ( $gmt ) { 3207 $datetime = $datetime->setTimezone( new DateTimeZone( 'UTC' ) ); 3208 } 3209 3210 $time = $datetime->format( $format ); 3211 } 3212 3213 /** 3214 * Filters the localized time of the post. 3215 * 3216 * @since 2.6.0 3217 * 3218 * @param string|int $time Formatted date string or Unix timestamp if `$format` is 'U' or 'G'. 3219 * @param string $format Format to use for retrieving the date of the post. 3220 * Accepts 'G', 'U', or PHP date format. 3221 * @param bool $gmt Whether to retrieve the GMT time. 3222 */ 3223 return apply_filters( 'get_post_time', $time, $format, $gmt ); 3224 } 3225 3226 /** 3227 * Retrieves post published or modified time as a `DateTimeImmutable` object instance. 3228 * 3229 * The object will be set to the timezone from WordPress settings. 3230 * 3231 * For legacy reasons, this function allows to choose to instantiate from local or UTC time in database. 3232 * Normally this should make no difference to the result. However, the values might get out of sync in database, 3233 * typically because of timezone setting changes. The parameter ensures the ability to reproduce backwards 3234 * compatible behaviors in such cases. 3235 * 3236 * @since 5.3.0 3237 * 3238 * @param int|WP_Post|null $post Optional. Post ID or post object. Default is global `$post` object. 3239 * @param string $field Optional. Published or modified time to use from database. Accepts 'date' or 'modified'. 3240 * Default 'date'. 3241 * @param string $source Optional. Local or UTC time to use from database. Accepts 'local' or 'gmt'. 3242 * Default 'local'. 3243 * @return DateTimeImmutable|false Time object on success, false on failure. 3244 */ 3245 function get_post_datetime( $post = null, $field = 'date', $source = 'local' ) { 3246 $post = get_post( $post ); 3247 3248 if ( ! $post ) { 3249 return false; 3250 } 3251 3252 $wp_timezone = wp_timezone(); 3253 3254 if ( 'gmt' === $source ) { 3255 $time = ( 'modified' === $field ) ? $post->post_modified_gmt : $post->post_date_gmt; 3256 $timezone = new DateTimeZone( 'UTC' ); 3257 } else { 3258 $time = ( 'modified' === $field ) ? $post->post_modified : $post->post_date; 3259 $timezone = $wp_timezone; 3260 } 3261 3262 if ( empty( $time ) || '0000-00-00 00:00:00' === $time ) { 3263 return false; 3264 } 3265 3266 $datetime = date_create_immutable_from_format( 'Y-m-d H:i:s', $time, $timezone ); 3267 3268 if ( false === $datetime ) { 3269 return false; 3270 } 3271 3272 return $datetime->setTimezone( $wp_timezone ); 3273 } 3274 3275 /** 3276 * Retrieves post published or modified time as a Unix timestamp. 3277 * 3278 * Note that this function returns a true Unix timestamp, not summed with timezone offset 3279 * like older WP functions. 3280 * 3281 * @since 5.3.0 3282 * 3283 * @param int|WP_Post|null $post Optional. Post ID or post object. Default is global `$post` object. 3284 * @param string $field Optional. Published or modified time to use from database. Accepts 'date' or 'modified'. 3285 * Default 'date'. 3286 * @return int|false Unix timestamp on success, false on failure. 3287 */ 3288 function get_post_timestamp( $post = null, $field = 'date' ) { 3289 $datetime = get_post_datetime( $post, $field ); 3290 3291 if ( false === $datetime ) { 3292 return false; 3293 } 3294 3295 return $datetime->getTimestamp(); 3296 } 3297 3298 /** 3299 * Displays the time at which the post was last modified. 3300 * 3301 * @since 2.0.0 3302 * 3303 * @param string $format Optional. Format to use for retrieving the time the post 3304 * was modified. Accepts 'G', 'U', or PHP date format. 3305 * Defaults to the 'time_format' option. 3306 */ 3307 function the_modified_time( $format = '' ) { 3308 /** 3309 * Filters the localized time a post was last modified, for display. 3310 * 3311 * @since 2.0.0 3312 * 3313 * @param string|false $get_the_modified_time The formatted time or false if no post is found. 3314 * @param string $format Format to use for retrieving the time the post 3315 * was modified. Accepts 'G', 'U', or PHP date format. 3316 */ 3317 echo apply_filters( 'the_modified_time', get_the_modified_time( $format ), $format ); 3318 } 3319 3320 /** 3321 * Retrieves the time at which the post was last modified. 3322 * 3323 * @since 2.0.0 3324 * @since 4.6.0 Added the `$post` parameter. 3325 * 3326 * @param string $format Optional. Format to use for retrieving the time the post 3327 * was modified. Accepts 'G', 'U', or PHP date format. 3328 * Defaults to the 'time_format' option. 3329 * @param int|WP_Post|null $post Optional. Post ID or WP_Post object. Default current post. 3330 * @return string|int|false Formatted date string or Unix timestamp. False on failure. 3331 * 3332 * @phpstan-return ( $format is 'U'|'G' ? int|false : string|false ) 3333 */ 3334 function get_the_modified_time( $format = '', $post = null ) { 3335 $post = get_post( $post ); 3336 3337 if ( ! $post ) { 3338 // For backward compatibility, failures go through the filter below. 3339 $the_time = false; 3340 } else { 3341 $_format = ! empty( $format ) ? $format : get_option( 'time_format' ); 3342 3343 $the_time = get_post_modified_time( $_format, false, $post, true ); 3344 } 3345 3346 /** 3347 * Filters the localized time a post was last modified. 3348 * 3349 * @since 2.0.0 3350 * @since 4.6.0 Added the `$post` parameter. 3351 * 3352 * @param string|int|false $the_time The formatted time or false if no post is found. 3353 * @param string $format Format to use for retrieving the time the post 3354 * was modified. Accepts 'G', 'U', or PHP date format. 3355 * @param WP_Post|null $post WP_Post object or null if no post is found. 3356 */ 3357 return apply_filters( 'get_the_modified_time', $the_time, $format, $post ); 3358 } 3359 3360 /** 3361 * Retrieves the time at which the post was last modified. 3362 * 3363 * @since 2.0.0 3364 * 3365 * @param string $format Optional. Format to use for retrieving the time the post 3366 * was modified. Accepts 'G', 'U', or PHP date format. Default 'U'. 3367 * @param bool $gmt Optional. Whether to retrieve the GMT time. Default false. 3368 * @param int|WP_Post|null $post Post ID or post object. Default is global `$post` object. 3369 * @param bool $translate Whether to translate the time string. Default false. 3370 * @return string|int|false Formatted date string or Unix timestamp if `$format` is 'U' or 'G'. 3371 * False on failure. 3372 * 3373 * @phpstan-return ( $format is 'U'|'G' ? int|false : string|false ) 3374 */ 3375 function get_post_modified_time( $format = 'U', $gmt = false, $post = null, $translate = false ) { 3376 $post = get_post( $post ); 3377 3378 if ( ! $post ) { 3379 return false; 3380 } 3381 3382 $source = ( $gmt ) ? 'gmt' : 'local'; 3383 $datetime = get_post_datetime( $post, 'modified', $source ); 3384 3385 if ( false === $datetime ) { 3386 return false; 3387 } 3388 3389 if ( 'U' === $format || 'G' === $format ) { 3390 $time = $datetime->getTimestamp(); 3391 3392 // Returns a sum of timestamp with timezone offset. Ideally should never be used. 3393 if ( ! $gmt ) { 3394 $time += $datetime->getOffset(); 3395 } 3396 } elseif ( $translate ) { 3397 $time = wp_date( $format, $datetime->getTimestamp(), $gmt ? new DateTimeZone( 'UTC' ) : null ); 3398 } else { 3399 if ( $gmt ) { 3400 $datetime = $datetime->setTimezone( new DateTimeZone( 'UTC' ) ); 3401 } 3402 3403 $time = $datetime->format( $format ); 3404 } 3405 3406 /** 3407 * Filters the localized time a post was last modified. 3408 * 3409 * @since 2.8.0 3410 * 3411 * @param string|int $time Formatted date string or Unix timestamp if `$format` is 'U' or 'G'. 3412 * @param string $format Format to use for retrieving the time the post was modified. 3413 * Accepts 'G', 'U', or PHP date format. Default 'U'. 3414 * @param bool $gmt Whether to retrieve the GMT time. Default false. 3415 */ 3416 return apply_filters( 'get_post_modified_time', $time, $format, $gmt ); 3417 } 3418 3419 /** 3420 * Displays the localized weekday for the post. 3421 * 3422 * @since 0.71 3423 * 3424 * @global WP_Locale $wp_locale WordPress date and time locale object. 3425 */ 3426 function the_weekday() { 3427 global $wp_locale; 3428 3429 $post = get_post(); 3430 3431 if ( ! $post ) { 3432 return; 3433 } 3434 3435 $the_weekday = $wp_locale->get_weekday( get_post_time( 'w', false, $post ) ); 3436 3437 /** 3438 * Filters the localized weekday of the post, for display. 3439 * 3440 * @since 0.71 3441 * 3442 * @param string $the_weekday 3443 */ 3444 echo apply_filters( 'the_weekday', $the_weekday ); 3445 } 3446 3447 /** 3448 * Displays the localized weekday for the post. 3449 * 3450 * Will only output the weekday if the current post's weekday is different from 3451 * the previous one output. 3452 * 3453 * @since 0.71 3454 * 3455 * @global WP_Locale $wp_locale WordPress date and time locale object. 3456 * @global string $currentday The day of the current post in the loop. 3457 * @global string $previousweekday The day of the previous post in the loop. 3458 * 3459 * @param string $before Optional. Output before the date. Default empty. 3460 * @param string $after Optional. Output after the date. Default empty. 3461 */ 3462 function the_weekday_date( $before = '', $after = '' ) { 3463 global $wp_locale, $currentday, $previousweekday; 3464 3465 $post = get_post(); 3466 3467 if ( ! $post ) { 3468 return; 3469 } 3470 3471 $the_weekday_date = ''; 3472 3473 if ( $currentday !== $previousweekday ) { 3474 $the_weekday_date .= $before; 3475 $the_weekday_date .= $wp_locale->get_weekday( get_post_time( 'w', false, $post ) ); 3476 $the_weekday_date .= $after; 3477 $previousweekday = $currentday; 3478 } 3479 3480 /** 3481 * Filters the localized weekday of the post, for display. 3482 * 3483 * @since 0.71 3484 * 3485 * @param string $the_weekday_date The weekday on which the post was written. 3486 * @param string $before The HTML to output before the date. 3487 * @param string $after The HTML to output after the date. 3488 */ 3489 echo apply_filters( 'the_weekday_date', $the_weekday_date, $before, $after ); 3490 } 3491 3492 /** 3493 * Fires the wp_head action. 3494 * 3495 * See {@see 'wp_head'}. 3496 * 3497 * @since 1.2.0 3498 */ 3499 function wp_head() { 3500 /** 3501 * Prints scripts or data in the head tag on the front end. 3502 * 3503 * @since 1.5.0 3504 */ 3505 do_action( 'wp_head' ); 3506 } 3507 3508 /** 3509 * Fires the wp_footer action. 3510 * 3511 * See {@see 'wp_footer'}. 3512 * 3513 * @since 1.5.1 3514 */ 3515 function wp_footer() { 3516 /** 3517 * Prints scripts or data before the closing body tag on the front end. 3518 * 3519 * @since 1.5.1 3520 */ 3521 do_action( 'wp_footer' ); 3522 } 3523 3524 /** 3525 * Fires the wp_body_open action. 3526 * 3527 * See {@see 'wp_body_open'}. 3528 * 3529 * @since 5.2.0 3530 */ 3531 function wp_body_open() { 3532 /** 3533 * Triggered after the opening body tag. 3534 * 3535 * @since 5.2.0 3536 */ 3537 do_action( 'wp_body_open' ); 3538 } 3539 3540 /** 3541 * Displays the links to the general feeds. 3542 * 3543 * @since 2.8.0 3544 * 3545 * @param array $args Optional arguments. 3546 */ 3547 function feed_links( $args = array() ) { 3548 if ( ! current_theme_supports( 'automatic-feed-links' ) ) { 3549 return; 3550 } 3551 3552 $defaults = array( 3553 /* translators: Separator between site name and feed type in feed links. */ 3554 'separator' => _x( '»', 'feed link' ), 3555 /* translators: 1: Site title, 2: Separator (raquo). */ 3556 'feedtitle' => __( '%1$s %2$s Feed' ), 3557 /* translators: 1: Site title, 2: Separator (raquo). */ 3558 'comstitle' => __( '%1$s %2$s Comments Feed' ), 3559 ); 3560 3561 $args = wp_parse_args( $args, $defaults ); 3562 3563 /** 3564 * Filters the feed links arguments. 3565 * 3566 * @since 6.7.0 3567 * 3568 * @param array $args An array of feed links arguments. 3569 */ 3570 $args = apply_filters( 'feed_links_args', $args ); 3571 3572 /** 3573 * Filters whether to display the posts feed link. 3574 * 3575 * @since 4.4.0 3576 * 3577 * @param bool $show Whether to display the posts feed link. Default true. 3578 */ 3579 if ( apply_filters( 'feed_links_show_posts_feed', true ) ) { 3580 printf( 3581 '<link rel="alternate" type="%s" title="%s" href="%s" />' . "\n", 3582 feed_content_type(), 3583 esc_attr( sprintf( $args['feedtitle'], get_bloginfo( 'name' ), $args['separator'] ) ), 3584 esc_url( get_feed_link() ) 3585 ); 3586 } 3587 3588 /** 3589 * Filters whether to display the comments feed link. 3590 * 3591 * @since 4.4.0 3592 * 3593 * @param bool $show Whether to display the comments feed link. Default true. 3594 */ 3595 if ( apply_filters( 'feed_links_show_comments_feed', true ) ) { 3596 printf( 3597 '<link rel="alternate" type="%s" title="%s" href="%s" />' . "\n", 3598 feed_content_type(), 3599 esc_attr( sprintf( $args['comstitle'], get_bloginfo( 'name' ), $args['separator'] ) ), 3600 esc_url( get_feed_link( 'comments_' . get_default_feed() ) ) 3601 ); 3602 } 3603 } 3604 3605 /** 3606 * Displays the links to the extra feeds such as category feeds. 3607 * 3608 * @since 2.8.0 3609 * 3610 * @param array $args Optional arguments. 3611 */ 3612 function feed_links_extra( $args = array() ) { 3613 $defaults = array( 3614 /* translators: Separator between site name and feed type in feed links. */ 3615 'separator' => _x( '»', 'feed link' ), 3616 /* translators: 1: Site name, 2: Separator (raquo), 3: Post title. */ 3617 'singletitle' => __( '%1$s %2$s %3$s Comments Feed' ), 3618 /* translators: 1: Site name, 2: Separator (raquo), 3: Category name. */ 3619 'cattitle' => __( '%1$s %2$s %3$s Category Feed' ), 3620 /* translators: 1: Site name, 2: Separator (raquo), 3: Tag name. */ 3621 'tagtitle' => __( '%1$s %2$s %3$s Tag Feed' ), 3622 /* translators: 1: Site name, 2: Separator (raquo), 3: Term name, 4: Taxonomy singular name. */ 3623 'taxtitle' => __( '%1$s %2$s %3$s %4$s Feed' ), 3624 /* translators: 1: Site name, 2: Separator (raquo), 3: Author name. */ 3625 'authortitle' => __( '%1$s %2$s Posts by %3$s Feed' ), 3626 /* translators: 1: Site name, 2: Separator (raquo), 3: Search query. */ 3627 'searchtitle' => __( '%1$s %2$s Search Results for “%3$s” Feed' ), 3628 /* translators: 1: Site name, 2: Separator (raquo), 3: Post type name. */ 3629 'posttypetitle' => __( '%1$s %2$s %3$s Feed' ), 3630 ); 3631 3632 $args = wp_parse_args( $args, $defaults ); 3633 3634 /** 3635 * Filters the extra feed links arguments. 3636 * 3637 * @since 6.7.0 3638 * 3639 * @param array $args An array of extra feed links arguments. 3640 */ 3641 $args = apply_filters( 'feed_links_extra_args', $args ); 3642 3643 /* 3644 * The template conditionals are referring to the global query, so the queried object is used rather than 3645 * depending on a global $post being set. 3646 */ 3647 $queried_object = get_queried_object(); 3648 if ( is_singular() && $queried_object instanceof WP_Post ) { 3649 $post = $queried_object; 3650 3651 /** This filter is documented in wp-includes/general-template.php */ 3652 $show_comments_feed = apply_filters( 'feed_links_show_comments_feed', true ); 3653 3654 /** 3655 * Filters whether to display the post comments feed link. 3656 * 3657 * This filter allows to enable or disable the feed link for a singular post 3658 * in a way that is independent of {@see 'feed_links_show_comments_feed'} 3659 * (which controls the global comments feed). The result of that filter 3660 * is accepted as a parameter. 3661 * 3662 * @since 6.1.0 3663 * 3664 * @param bool $show_comments_feed Whether to display the post comments feed link. Defaults to 3665 * the {@see 'feed_links_show_comments_feed'} filter result. 3666 */ 3667 $show_post_comments_feed = apply_filters( 'feed_links_extra_show_post_comments_feed', $show_comments_feed ); 3668 3669 if ( $show_post_comments_feed && ( comments_open( $post ) || pings_open( $post ) || (int) $post->comment_count > 0 ) ) { 3670 $title = sprintf( 3671 $args['singletitle'], 3672 get_bloginfo( 'name' ), 3673 $args['separator'], 3674 the_title_attribute( 3675 array( 3676 'echo' => false, 3677 'post' => $post, 3678 ) 3679 ) 3680 ); 3681 3682 $feed_link = get_post_comments_feed_link( $post->ID ); 3683 3684 if ( $feed_link ) { 3685 $href = $feed_link; 3686 } 3687 } 3688 } elseif ( is_post_type_archive() ) { 3689 /** 3690 * Filters whether to display the post type archive feed link. 3691 * 3692 * @since 6.1.0 3693 * 3694 * @param bool $show Whether to display the post type archive feed link. Default true. 3695 */ 3696 $show_post_type_archive_feed = apply_filters( 'feed_links_extra_show_post_type_archive_feed', true ); 3697 3698 if ( $show_post_type_archive_feed ) { 3699 $post_type = get_query_var( 'post_type' ); 3700 3701 if ( is_array( $post_type ) ) { 3702 $post_type = reset( $post_type ); 3703 } 3704 3705 $post_type_obj = get_post_type_object( $post_type ); 3706 3707 $title = sprintf( 3708 $args['posttypetitle'], 3709 get_bloginfo( 'name' ), 3710 $args['separator'], 3711 $post_type_obj->labels->name 3712 ); 3713 3714 $href = get_post_type_archive_feed_link( $post_type_obj->name ); 3715 } 3716 } elseif ( is_category() ) { 3717 /** 3718 * Filters whether to display the category feed link. 3719 * 3720 * @since 6.1.0 3721 * 3722 * @param bool $show Whether to display the category feed link. Default true. 3723 */ 3724 $show_category_feed = apply_filters( 'feed_links_extra_show_category_feed', true ); 3725 3726 if ( $show_category_feed ) { 3727 $term = get_queried_object(); 3728 3729 if ( $term ) { 3730 $title = sprintf( 3731 $args['cattitle'], 3732 get_bloginfo( 'name' ), 3733 $args['separator'], 3734 $term->name 3735 ); 3736 3737 $href = get_category_feed_link( $term->term_id ); 3738 } 3739 } 3740 } elseif ( is_tag() ) { 3741 /** 3742 * Filters whether to display the tag feed link. 3743 * 3744 * @since 6.1.0 3745 * 3746 * @param bool $show Whether to display the tag feed link. Default true. 3747 */ 3748 $show_tag_feed = apply_filters( 'feed_links_extra_show_tag_feed', true ); 3749 3750 if ( $show_tag_feed ) { 3751 $term = get_queried_object(); 3752 3753 if ( $term ) { 3754 $title = sprintf( 3755 $args['tagtitle'], 3756 get_bloginfo( 'name' ), 3757 $args['separator'], 3758 $term->name 3759 ); 3760 3761 $href = get_tag_feed_link( $term->term_id ); 3762 } 3763 } 3764 } elseif ( is_tax() ) { 3765 /** 3766 * Filters whether to display the custom taxonomy feed link. 3767 * 3768 * @since 6.1.0 3769 * 3770 * @param bool $show Whether to display the custom taxonomy feed link. Default true. 3771 */ 3772 $show_tax_feed = apply_filters( 'feed_links_extra_show_tax_feed', true ); 3773 3774 if ( $show_tax_feed ) { 3775 $term = get_queried_object(); 3776 3777 if ( $term ) { 3778 $tax = get_taxonomy( $term->taxonomy ); 3779 3780 $title = sprintf( 3781 $args['taxtitle'], 3782 get_bloginfo( 'name' ), 3783 $args['separator'], 3784 $term->name, 3785 $tax->labels->singular_name 3786 ); 3787 3788 $href = get_term_feed_link( $term->term_id, $term->taxonomy ); 3789 } 3790 } 3791 } elseif ( is_author() ) { 3792 /** 3793 * Filters whether to display the author feed link. 3794 * 3795 * @since 6.1.0 3796 * 3797 * @param bool $show Whether to display the author feed link. Default true. 3798 */ 3799 $show_author_feed = apply_filters( 'feed_links_extra_show_author_feed', true ); 3800 3801 if ( $show_author_feed ) { 3802 $author_id = (int) get_query_var( 'author' ); 3803 3804 $title = sprintf( 3805 $args['authortitle'], 3806 get_bloginfo( 'name' ), 3807 $args['separator'], 3808 get_the_author_meta( 'display_name', $author_id ) 3809 ); 3810 3811 $href = get_author_feed_link( $author_id ); 3812 } 3813 } elseif ( is_search() ) { 3814 /** 3815 * Filters whether to display the search results feed link. 3816 * 3817 * @since 6.1.0 3818 * 3819 * @param bool $show Whether to display the search results feed link. Default true. 3820 */ 3821 $show_search_feed = apply_filters( 'feed_links_extra_show_search_feed', true ); 3822 3823 if ( $show_search_feed ) { 3824 $title = sprintf( 3825 $args['searchtitle'], 3826 get_bloginfo( 'name' ), 3827 $args['separator'], 3828 get_search_query( false ) 3829 ); 3830 3831 $href = get_search_feed_link(); 3832 } 3833 } 3834 3835 if ( isset( $title ) && isset( $href ) ) { 3836 printf( 3837 '<link rel="alternate" type="%s" title="%s" href="%s" />' . "\n", 3838 feed_content_type(), 3839 esc_attr( $title ), 3840 esc_url( $href ) 3841 ); 3842 } 3843 } 3844 3845 /** 3846 * Displays the link to the Really Simple Discovery service endpoint. 3847 * 3848 * @link http://archipelago.phrasewise.com/rsd 3849 * @since 2.0.0 3850 */ 3851 function rsd_link() { 3852 printf( 3853 '<link rel="EditURI" type="application/rsd+xml" title="RSD" href="%s" />' . "\n", 3854 esc_url( site_url( 'xmlrpc.php?rsd', 'rpc' ) ) 3855 ); 3856 } 3857 3858 /** 3859 * Displays a referrer `strict-origin-when-cross-origin` meta tag. 3860 * 3861 * Outputs a referrer `strict-origin-when-cross-origin` meta tag that tells the browser not to send 3862 * the full URL as a referrer to other sites when cross-origin assets are loaded. 3863 * 3864 * Typical usage is as a {@see 'wp_head'} callback: 3865 * 3866 * add_action( 'wp_head', 'wp_strict_cross_origin_referrer' ); 3867 * 3868 * @since 5.7.0 3869 */ 3870 function wp_strict_cross_origin_referrer() { 3871 ?> 3872 <meta name='referrer' content='strict-origin-when-cross-origin' /> 3873 <?php 3874 } 3875 3876 /** 3877 * Displays site icon meta tags. 3878 * 3879 * @since 4.3.0 3880 * 3881 * @link https://www.whatwg.org/specs/web-apps/current-work/multipage/links.html#rel-icon HTML5 specification link icon. 3882 */ 3883 function wp_site_icon() { 3884 if ( ! has_site_icon() && ! is_customize_preview() ) { 3885 return; 3886 } 3887 3888 $meta_tags = array(); 3889 $icon_32 = get_site_icon_url( 32 ); 3890 if ( empty( $icon_32 ) && is_customize_preview() ) { 3891 $icon_32 = '/favicon.ico'; // Serve default favicon URL in customizer so element can be updated for preview. 3892 } 3893 if ( $icon_32 ) { 3894 $meta_tags[] = sprintf( '<link rel="icon" href="%s" sizes="32x32" />', esc_url( $icon_32 ) ); 3895 } 3896 $icon_192 = get_site_icon_url( 192 ); 3897 if ( $icon_192 ) { 3898 $meta_tags[] = sprintf( '<link rel="icon" href="%s" sizes="192x192" />', esc_url( $icon_192 ) ); 3899 } 3900 $icon_180 = get_site_icon_url( 180 ); 3901 if ( $icon_180 ) { 3902 $meta_tags[] = sprintf( '<link rel="apple-touch-icon" href="%s" />', esc_url( $icon_180 ) ); 3903 } 3904 $icon_270 = get_site_icon_url( 270 ); 3905 if ( $icon_270 ) { 3906 $meta_tags[] = sprintf( '<meta name="msapplication-TileImage" content="%s" />', esc_url( $icon_270 ) ); 3907 } 3908 3909 /** 3910 * Filters the site icon meta tags, so plugins can add their own. 3911 * 3912 * @since 4.3.0 3913 * 3914 * @param string[] $meta_tags Array of Site Icon meta tags. 3915 */ 3916 $meta_tags = apply_filters( 'site_icon_meta_tags', $meta_tags ); 3917 $meta_tags = array_filter( $meta_tags ); 3918 3919 foreach ( $meta_tags as $meta_tag ) { 3920 echo "$meta_tag\n"; 3921 } 3922 } 3923 3924 /** 3925 * Prints resource hints to browsers for pre-fetching, pre-rendering 3926 * and pre-connecting to websites. 3927 * 3928 * Gives hints to browsers to prefetch specific pages or render them 3929 * in the background, to perform DNS lookups or to begin the connection 3930 * handshake (DNS, TCP, TLS) in the background. 3931 * 3932 * These performance improving indicators work by using `<link rel"…">`. 3933 * 3934 * @since 4.6.0 3935 */ 3936 function wp_resource_hints() { 3937 $hints = array( 3938 'dns-prefetch' => wp_dependencies_unique_hosts(), 3939 'preconnect' => array(), 3940 'prefetch' => array(), 3941 'prerender' => array(), 3942 ); 3943 3944 foreach ( $hints as $relation_type => $urls ) { 3945 $unique_urls = array(); 3946 3947 /** 3948 * Filters domains and URLs for resource hints of the given relation type. 3949 * 3950 * @since 4.6.0 3951 * @since 4.7.0 The `$urls` parameter accepts arrays of specific HTML attributes 3952 * as its child elements. 3953 * 3954 * @param array $urls { 3955 * Array of resources and their attributes, or URLs to print for resource hints. 3956 * 3957 * @type array|string ...$0 { 3958 * Array of resource attributes, or a URL string. 3959 * 3960 * @type string $href URL to include in resource hints. Required. 3961 * @type string $as How the browser should treat the resource 3962 * (`script`, `style`, `image`, `document`, etc). 3963 * @type string $crossorigin Indicates the CORS policy of the specified resource. 3964 * @type float $pr Expected probability that the resource hint will be used. 3965 * @type string $type Type of the resource (`text/html`, `text/css`, etc). 3966 * } 3967 * } 3968 * @param string $relation_type The relation type the URLs are printed for. One of 3969 * 'dns-prefetch', 'preconnect', 'prefetch', or 'prerender'. 3970 */ 3971 $urls = apply_filters( 'wp_resource_hints', $urls, $relation_type ); 3972 3973 foreach ( $urls as $key => $url ) { 3974 $atts = array(); 3975 3976 if ( is_array( $url ) ) { 3977 if ( isset( $url['href'] ) ) { 3978 $atts = $url; 3979 $url = $url['href']; 3980 } else { 3981 continue; 3982 } 3983 } 3984 3985 $url = esc_url( $url, array( 'http', 'https' ) ); 3986 3987 if ( ! $url ) { 3988 continue; 3989 } 3990 3991 if ( isset( $unique_urls[ $url ] ) ) { 3992 continue; 3993 } 3994 3995 if ( in_array( $relation_type, array( 'preconnect', 'dns-prefetch' ), true ) ) { 3996 $parsed = wp_parse_url( $url ); 3997 3998 if ( empty( $parsed['host'] ) ) { 3999 continue; 4000 } 4001 4002 if ( 'preconnect' === $relation_type && ! empty( $parsed['scheme'] ) ) { 4003 $url = $parsed['scheme'] . '://' . $parsed['host']; 4004 } else { 4005 // Use protocol-relative URLs for dns-prefetch or if scheme is missing. 4006 $url = '//' . $parsed['host']; 4007 } 4008 } 4009 4010 $atts['rel'] = $relation_type; 4011 $atts['href'] = $url; 4012 4013 $unique_urls[ $url ] = $atts; 4014 } 4015 4016 foreach ( $unique_urls as $atts ) { 4017 $html = ''; 4018 4019 foreach ( $atts as $attr => $value ) { 4020 if ( ! is_scalar( $value ) 4021 || ( ! in_array( $attr, array( 'as', 'crossorigin', 'href', 'pr', 'rel', 'type' ), true ) && ! is_numeric( $attr ) ) 4022 ) { 4023 4024 continue; 4025 } 4026 4027 $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); 4028 4029 if ( ! is_string( $attr ) ) { 4030 $html .= " $value"; 4031 } else { 4032 $html .= " $attr='$value'"; 4033 } 4034 } 4035 4036 $html = trim( $html ); 4037 4038 echo "<link $html />\n"; 4039 } 4040 } 4041 } 4042 4043 /** 4044 * Prints resource preloads directives to browsers. 4045 * 4046 * Gives directive to browsers to preload specific resources that website will 4047 * need very soon, this ensures that they are available earlier and are less 4048 * likely to block the page's render. Preload directives should not be used for 4049 * non-render-blocking elements, as then they would compete with the 4050 * render-blocking ones, slowing down the render. 4051 * 4052 * These performance improving indicators work by using `<link rel="preload">`. 4053 * 4054 * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Link_types/preload 4055 * @link https://web.dev/preload-responsive-images/ 4056 * 4057 * @since 6.1.0 4058 */ 4059 function wp_preload_resources() { 4060 /** 4061 * Filters domains and URLs for resource preloads. 4062 * 4063 * @since 6.1.0 4064 * @since 6.6.0 Added the `$fetchpriority` attribute. 4065 * 4066 * @param array $preload_resources { 4067 * Array of resources and their attributes, or URLs to print for resource preloads. 4068 * 4069 * @type array ...$0 { 4070 * Array of resource attributes. 4071 * 4072 * @type string $href URL to include in resource preloads. Required. 4073 * @type string $as How the browser should treat the resource 4074 * (`script`, `style`, `image`, `document`, etc). 4075 * @type string $crossorigin Indicates the CORS policy of the specified resource. 4076 * @type string $type Type of the resource (`text/html`, `text/css`, etc). 4077 * @type string $media Accepts media types or media queries. Allows responsive preloading. 4078 * @type string $imagesizes Responsive source size to the source Set. 4079 * @type string $imagesrcset Responsive image sources to the source set. 4080 * @type string $fetchpriority Fetchpriority value for the resource. 4081 * } 4082 * } 4083 */ 4084 $preload_resources = apply_filters( 'wp_preload_resources', array() ); 4085 4086 if ( ! is_array( $preload_resources ) ) { 4087 return; 4088 } 4089 4090 $unique_resources = array(); 4091 4092 // Parse the complete resource list and extract unique resources. 4093 foreach ( $preload_resources as $resource ) { 4094 if ( ! is_array( $resource ) ) { 4095 continue; 4096 } 4097 4098 $attributes = $resource; 4099 if ( isset( $resource['href'] ) ) { 4100 $href = $resource['href']; 4101 if ( isset( $unique_resources[ $href ] ) ) { 4102 continue; 4103 } 4104 $unique_resources[ $href ] = $attributes; 4105 // Media can use imagesrcset and not href. 4106 } elseif ( ( 'image' === $resource['as'] ) && 4107 ( isset( $resource['imagesrcset'] ) || isset( $resource['imagesizes'] ) ) 4108 ) { 4109 if ( isset( $unique_resources[ $resource['imagesrcset'] ] ) ) { 4110 continue; 4111 } 4112 $unique_resources[ $resource['imagesrcset'] ] = $attributes; 4113 } else { 4114 continue; 4115 } 4116 } 4117 4118 // Build and output the HTML for each unique resource. 4119 foreach ( $unique_resources as $unique_resource ) { 4120 $html = ''; 4121 4122 foreach ( $unique_resource as $resource_key => $resource_value ) { 4123 if ( ! is_scalar( $resource_value ) ) { 4124 continue; 4125 } 4126 4127 // Ignore non-supported attributes. 4128 $non_supported_attributes = array( 'as', 'crossorigin', 'href', 'imagesrcset', 'imagesizes', 'type', 'media', 'fetchpriority' ); 4129 if ( ! in_array( $resource_key, $non_supported_attributes, true ) && ! is_numeric( $resource_key ) ) { 4130 continue; 4131 } 4132 4133 // imagesrcset only usable when preloading image, ignore otherwise. 4134 if ( ( 'imagesrcset' === $resource_key ) && ( ! isset( $unique_resource['as'] ) || ( 'image' !== $unique_resource['as'] ) ) ) { 4135 continue; 4136 } 4137 4138 // imagesizes only usable when preloading image and imagesrcset present, ignore otherwise. 4139 if ( ( 'imagesizes' === $resource_key ) && 4140 ( ! isset( $unique_resource['as'] ) || ( 'image' !== $unique_resource['as'] ) || ! isset( $unique_resource['imagesrcset'] ) ) 4141 ) { 4142 continue; 4143 } 4144 4145 $resource_value = ( 'href' === $resource_key ) ? esc_url( $resource_value, array( 'http', 'https' ) ) : esc_attr( $resource_value ); 4146 4147 if ( ! is_string( $resource_key ) ) { 4148 $html .= " $resource_value"; 4149 } else { 4150 $html .= " $resource_key='$resource_value'"; 4151 } 4152 } 4153 $html = trim( $html ); 4154 4155 printf( "<link rel='preload' %s />\n", $html ); 4156 } 4157 } 4158 4159 /** 4160 * Retrieves a list of unique hosts of all enqueued scripts and styles. 4161 * 4162 * @since 4.6.0 4163 * 4164 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts. 4165 * @global WP_Styles $wp_styles The WP_Styles object for printing styles. 4166 * 4167 * @return string[] A list of unique hosts of enqueued scripts and styles. 4168 */ 4169 function wp_dependencies_unique_hosts() { 4170 global $wp_scripts, $wp_styles; 4171 4172 $unique_hosts = array(); 4173 4174 foreach ( array( $wp_scripts, $wp_styles ) as $dependencies ) { 4175 if ( $dependencies instanceof WP_Dependencies && ! empty( $dependencies->queue ) ) { 4176 foreach ( $dependencies->queue as $handle ) { 4177 if ( ! isset( $dependencies->registered[ $handle ] ) ) { 4178 continue; 4179 } 4180 4181 /* @var _WP_Dependency $dependency */ 4182 $dependency = $dependencies->registered[ $handle ]; 4183 $parsed = wp_parse_url( $dependency->src ); 4184 4185 if ( ! empty( $parsed['host'] ) 4186 && ! in_array( $parsed['host'], $unique_hosts, true ) && $parsed['host'] !== $_SERVER['SERVER_NAME'] 4187 ) { 4188 $unique_hosts[] = $parsed['host']; 4189 } 4190 } 4191 } 4192 } 4193 4194 return $unique_hosts; 4195 } 4196 4197 /** 4198 * Determines whether the user can access the visual editor. 4199 * 4200 * Checks if the user can access the visual editor and that it's supported by the user's browser. 4201 * 4202 * @since 2.0.0 4203 * 4204 * @global bool $wp_rich_edit Whether the user can access the visual editor. 4205 * @global bool $is_gecko Whether the browser is Gecko-based. 4206 * @global bool $is_opera Whether the browser is Opera. 4207 * @global bool $is_safari Whether the browser is Safari. 4208 * @global bool $is_chrome Whether the browser is Chrome. 4209 * @global bool $is_IE Whether the browser is Internet Explorer. 4210 * @global bool $is_edge Whether the browser is Microsoft Edge. 4211 * 4212 * @return bool True if the user can access the visual editor, false otherwise. 4213 */ 4214 function user_can_richedit() { 4215 global $wp_rich_edit, $is_gecko, $is_opera, $is_safari, $is_chrome, $is_IE, $is_edge; 4216 4217 if ( ! isset( $wp_rich_edit ) ) { 4218 $wp_rich_edit = false; 4219 4220 if ( 'true' === get_user_option( 'rich_editing' ) || ! is_user_logged_in() ) { // Default to 'true' for logged out users. 4221 if ( $is_safari ) { 4222 $wp_rich_edit = ! wp_is_mobile() || ( preg_match( '!AppleWebKit/(\d+)!', $_SERVER['HTTP_USER_AGENT'], $match ) && (int) $match[1] >= 534 ); 4223 } elseif ( $is_IE ) { 4224 $wp_rich_edit = str_contains( $_SERVER['HTTP_USER_AGENT'], 'Trident/7.0;' ); 4225 } elseif ( $is_gecko || $is_chrome || $is_edge || ( $is_opera && ! wp_is_mobile() ) ) { 4226 $wp_rich_edit = true; 4227 } 4228 } 4229 } 4230 4231 /** 4232 * Filters whether the user can access the visual editor. 4233 * 4234 * @since 2.1.0 4235 * 4236 * @param bool $wp_rich_edit Whether the user can access the visual editor. 4237 */ 4238 return apply_filters( 'user_can_richedit', $wp_rich_edit ); 4239 } 4240 4241 /** 4242 * Finds out which editor should be displayed by default. 4243 * 4244 * Works out which of the editors to display as the current editor for a 4245 * user. The 'html' setting is for the "Code" editor tab. 4246 * 4247 * @since 2.5.0 4248 * 4249 * @return string Either 'tinymce', 'html', or 'test' 4250 */ 4251 function wp_default_editor() { 4252 $r = user_can_richedit() ? 'tinymce' : 'html'; // Defaults. 4253 if ( wp_get_current_user() ) { // Look for cookie. 4254 $ed = get_user_setting( 'editor', 'tinymce' ); 4255 $r = ( in_array( $ed, array( 'tinymce', 'html', 'test' ), true ) ) ? $ed : $r; 4256 } 4257 4258 /** 4259 * Filters which editor should be displayed by default. 4260 * 4261 * @since 2.5.0 4262 * 4263 * @param string $r Which editor should be displayed by default. Either 'tinymce', 'html', or 'test'. 4264 */ 4265 return apply_filters( 'wp_default_editor', $r ); 4266 } 4267 4268 /** 4269 * Renders an editor. 4270 * 4271 * Using this function is the proper way to output all needed components for both TinyMCE and Quicktags. 4272 * _WP_Editors should not be used directly. See https://core.trac.wordpress.org/ticket/17144. 4273 * 4274 * NOTE: Once initialized the TinyMCE editor cannot be safely moved in the DOM. For that reason 4275 * running wp_editor() inside of a meta box is not a good idea unless only Quicktags is used. 4276 * On the post edit screen several actions can be used to include additional editors 4277 * containing TinyMCE: 'edit_page_form', 'edit_form_advanced' and 'dbx_post_sidebar'. 4278 * See https://core.trac.wordpress.org/ticket/19173 for more information. 4279 * 4280 * @see _WP_Editors::editor() 4281 * @see _WP_Editors::parse_settings() 4282 * @since 3.3.0 4283 * 4284 * @param string $content Initial content for the editor. 4285 * @param string $editor_id HTML ID attribute value for the textarea and TinyMCE. 4286 * Should not contain square brackets. 4287 * @param array $settings See _WP_Editors::parse_settings() for description. 4288 */ 4289 function wp_editor( $content, $editor_id, $settings = array() ) { 4290 if ( ! class_exists( '_WP_Editors', false ) ) { 4291 require ABSPATH . WPINC . '/class-wp-editor.php'; 4292 } 4293 _WP_Editors::editor( $content, $editor_id, $settings ); 4294 } 4295 4296 /** 4297 * Outputs the editor scripts, stylesheets, and default settings. 4298 * 4299 * The editor can be initialized when needed after page load. 4300 * See wp.editor.initialize() in wp-admin/js/editor.js for initialization options. 4301 * 4302 * @uses _WP_Editors 4303 * @since 4.8.0 4304 */ 4305 function wp_enqueue_editor() { 4306 if ( ! class_exists( '_WP_Editors', false ) ) { 4307 require ABSPATH . WPINC . '/class-wp-editor.php'; 4308 } 4309 4310 _WP_Editors::enqueue_default_editor(); 4311 } 4312 4313 /** 4314 * Enqueues assets needed by the code editor for the given settings. 4315 * 4316 * @since 4.9.0 4317 * 4318 * @see wp_enqueue_editor() 4319 * @see wp_get_code_editor_settings() 4320 * @see _WP_Editors::parse_settings() 4321 * 4322 * @param array $args { 4323 * Args. 4324 * 4325 * @type string $type The MIME type of the file to be edited. 4326 * @type string $file Filename to be edited. Extension is used to sniff the type. Can be supplied as alternative to `$type` param. 4327 * @type WP_Theme $theme Theme being edited when on the theme file editor. 4328 * @type string $plugin Plugin being edited when on the plugin file editor. 4329 * @type array $codemirror Additional CodeMirror setting overrides. 4330 * @type array $csslint CSSLint rule overrides. 4331 * @type array $jshint JSHint rule overrides. 4332 * @type array $htmlhint HTMLHint rule overrides. 4333 * } 4334 * @return array|false Settings for the enqueued code editor, or false if the editor was not enqueued. 4335 */ 4336 function wp_enqueue_code_editor( $args ) { 4337 if ( is_user_logged_in() && 'false' === wp_get_current_user()->syntax_highlighting ) { 4338 return false; 4339 } 4340 4341 $settings = wp_get_code_editor_settings( $args ); 4342 4343 if ( empty( $settings ) || empty( $settings['codemirror'] ) ) { 4344 return false; 4345 } 4346 4347 wp_enqueue_script( 'code-editor' ); 4348 wp_enqueue_style( 'code-editor' ); 4349 4350 if ( isset( $settings['codemirror']['mode'] ) ) { 4351 $mode = $settings['codemirror']['mode']; 4352 if ( is_string( $mode ) ) { 4353 $mode = array( 4354 'name' => $mode, 4355 ); 4356 } 4357 4358 if ( ! empty( $settings['codemirror']['lint'] ) ) { 4359 switch ( $mode['name'] ) { 4360 case 'css': 4361 case 'text/css': 4362 case 'text/x-scss': 4363 case 'text/x-less': 4364 wp_enqueue_script( 'csslint' ); 4365 break; 4366 case 'htmlmixed': 4367 case 'text/html': 4368 case 'php': 4369 case 'application/x-httpd-php': 4370 case 'text/x-php': 4371 wp_enqueue_script( 'htmlhint' ); 4372 wp_enqueue_script( 'csslint' ); 4373 if ( ! current_user_can( 'unfiltered_html' ) ) { 4374 wp_enqueue_script( 'htmlhint-kses' ); 4375 } 4376 break; 4377 case 'javascript': 4378 case 'application/ecmascript': 4379 case 'application/json': 4380 case 'application/javascript': 4381 case 'application/ld+json': 4382 case 'text/typescript': 4383 case 'application/typescript': 4384 wp_enqueue_script( 'jsonlint' ); 4385 break; 4386 } 4387 } 4388 } 4389 4390 wp_add_inline_script( 'code-editor', sprintf( 'jQuery.extend( wp.codeEditor.defaultSettings, %s );', wp_json_encode( $settings, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) ) ); 4391 4392 /** 4393 * Fires when scripts and styles are enqueued for the code editor. 4394 * 4395 * @since 4.9.0 4396 * 4397 * @param array $settings Settings for the enqueued code editor. 4398 */ 4399 do_action( 'wp_enqueue_code_editor', $settings ); 4400 4401 return $settings; 4402 } 4403 4404 /** 4405 * Generates and returns code editor settings. 4406 * 4407 * @since 5.0.0 4408 * 4409 * @see wp_enqueue_code_editor() 4410 * 4411 * @param array $args { 4412 * Args. 4413 * 4414 * @type string $type The MIME type of the file to be edited. 4415 * @type string $file Filename to be edited. Extension is used to sniff the type. Can be supplied as alternative to `$type` param. 4416 * @type WP_Theme $theme Theme being edited when on the theme file editor. 4417 * @type string $plugin Plugin being edited when on the plugin file editor. 4418 * @type array $codemirror Additional CodeMirror setting overrides. 4419 * @type array $csslint CSSLint rule overrides. 4420 * @type array $jshint JSHint rule overrides. 4421 * @type array $htmlhint HTMLHint rule overrides. 4422 * } 4423 * @return array|false Settings for the code editor. 4424 */ 4425 function wp_get_code_editor_settings( $args ) { 4426 $settings = array( 4427 'codemirror' => array( 4428 'indentUnit' => 4, 4429 'indentWithTabs' => true, 4430 'inputStyle' => 'contenteditable', 4431 'lineNumbers' => true, 4432 'lineWrapping' => true, 4433 'styleActiveLine' => true, 4434 'continueComments' => true, 4435 'extraKeys' => array( 4436 'Ctrl-Space' => 'autocomplete', 4437 'Ctrl-/' => 'toggleComment', 4438 'Cmd-/' => 'toggleComment', 4439 'Alt-F' => 'findPersistent', 4440 'Ctrl-F' => 'findPersistent', 4441 'Cmd-F' => 'findPersistent', 4442 ), 4443 'direction' => 'ltr', // Code is shown in LTR even in RTL languages. 4444 'gutters' => array(), 4445 ), 4446 'csslint' => array( 4447 'errors' => true, // Parsing errors. 4448 'box-model' => true, 4449 'display-property-grouping' => true, 4450 'duplicate-properties' => true, 4451 'known-properties' => true, 4452 'outline-none' => true, 4453 ), 4454 'jshint' => array( 4455 'esversion' => 11, 4456 'module' => str_ends_with( $args['file'] ?? '', '.mjs' ), 4457 4458 // This script module URL is intentionally referenced here instead of registering an espree script module 4459 // in wp_default_script_modules(). This is a first stab at a core-only private module. 4460 'espreeModuleUrl' => add_query_arg( 'ver', '9.6.1', includes_url( 'js/codemirror/espree.min.js' ) ), 4461 4462 // The following JSHint *linting rule* options are copied from 4463 // <https://github.com/WordPress/wordpress-develop/blob/6.9.0/.jshintrc>. 4464 // Parsing-related options such as `esversion` (and, in other contexts, `es5`, `es3`, `module`, `strict`) 4465 // are honored by the Espree-based integration, but these linting-rule options are not interpreted by Espree 4466 // and are kept only for compatibility/documentation with the original JSHint configuration. 4467 'boss' => true, 4468 'curly' => true, 4469 'eqeqeq' => true, 4470 'eqnull' => true, 4471 'expr' => true, 4472 'immed' => true, 4473 'noarg' => true, 4474 'nonbsp' => true, 4475 'quotmark' => 'single', 4476 'undef' => true, 4477 'unused' => true, 4478 'browser' => true, 4479 'globals' => array( 4480 '_' => false, 4481 'Backbone' => false, 4482 'jQuery' => false, 4483 'JSON' => false, 4484 'wp' => false, 4485 'export' => false, 4486 'module' => false, 4487 'require' => false, 4488 'WorkerGlobalScope' => false, 4489 'self' => false, 4490 'OffscreenCanvas' => false, 4491 'Promise' => false, 4492 ), 4493 ), 4494 'htmlhint' => array( 4495 'tagname-lowercase' => true, 4496 'attr-lowercase' => true, 4497 'attr-value-double-quotes' => false, 4498 'doctype-first' => false, 4499 'tag-pair' => true, 4500 'spec-char-escape' => true, 4501 'id-unique' => true, 4502 'src-not-empty' => true, 4503 'attr-no-duplication' => true, 4504 'alt-require' => true, 4505 'space-tab-mixed-disabled' => 'tab', 4506 'attr-unsafe-chars' => true, 4507 ), 4508 ); 4509 4510 $type = ''; 4511 if ( isset( $args['type'] ) ) { 4512 $type = $args['type']; 4513 4514 // Remap MIME types to ones that CodeMirror modes will recognize. 4515 if ( 'application/x-patch' === $type || 'text/x-patch' === $type ) { 4516 $type = 'text/x-diff'; 4517 } 4518 } elseif ( isset( $args['file'] ) && str_contains( basename( $args['file'] ), '.' ) ) { 4519 $extension = strtolower( pathinfo( $args['file'], PATHINFO_EXTENSION ) ); 4520 foreach ( wp_get_mime_types() as $exts => $mime ) { 4521 if ( preg_match( '!^(' . $exts . ')$!i', $extension ) ) { 4522 $type = $mime; 4523 break; 4524 } 4525 } 4526 4527 // Supply any types that are not matched by wp_get_mime_types(). 4528 if ( empty( $type ) ) { 4529 switch ( $extension ) { 4530 case 'conf': 4531 $type = 'text/nginx'; 4532 break; 4533 case 'css': 4534 $type = 'text/css'; 4535 break; 4536 case 'diff': 4537 case 'patch': 4538 $type = 'text/x-diff'; 4539 break; 4540 case 'html': 4541 case 'htm': 4542 $type = 'text/html'; 4543 break; 4544 case 'http': 4545 $type = 'message/http'; 4546 break; 4547 case 'js': 4548 case 'mjs': 4549 $type = 'text/javascript'; 4550 break; 4551 case 'json': 4552 $type = 'application/json'; 4553 break; 4554 case 'jsx': 4555 $type = 'text/jsx'; 4556 break; 4557 case 'less': 4558 $type = 'text/x-less'; 4559 break; 4560 case 'md': 4561 $type = 'text/x-gfm'; 4562 break; 4563 case 'php': 4564 case 'phtml': 4565 case 'php3': 4566 case 'php4': 4567 case 'php5': 4568 case 'php7': 4569 case 'phps': 4570 $type = 'application/x-httpd-php'; 4571 break; 4572 case 'scss': 4573 $type = 'text/x-scss'; 4574 break; 4575 case 'sass': 4576 $type = 'text/x-sass'; 4577 break; 4578 case 'sh': 4579 case 'bash': 4580 $type = 'text/x-sh'; 4581 break; 4582 case 'sql': 4583 $type = 'text/x-sql'; 4584 break; 4585 case 'svg': 4586 $type = 'application/svg+xml'; 4587 break; 4588 case 'xml': 4589 $type = 'text/xml'; 4590 break; 4591 case 'yml': 4592 case 'yaml': 4593 $type = 'text/x-yaml'; 4594 break; 4595 case 'txt': 4596 default: 4597 $type = 'text/plain'; 4598 break; 4599 } 4600 } 4601 } 4602 4603 if ( in_array( $type, array( 'text/css', 'text/x-scss', 'text/x-less', 'text/x-sass' ), true ) ) { 4604 $settings['codemirror'] = array_merge( 4605 $settings['codemirror'], 4606 array( 4607 'mode' => $type, 4608 'lint' => false, 4609 'autoCloseBrackets' => true, 4610 'matchBrackets' => true, 4611 ) 4612 ); 4613 } elseif ( 'text/x-diff' === $type ) { 4614 $settings['codemirror'] = array_merge( 4615 $settings['codemirror'], 4616 array( 4617 'mode' => 'diff', 4618 ) 4619 ); 4620 } elseif ( 'text/html' === $type ) { 4621 $settings['codemirror'] = array_merge( 4622 $settings['codemirror'], 4623 array( 4624 'mode' => 'htmlmixed', 4625 'lint' => true, 4626 'autoCloseBrackets' => true, 4627 'autoCloseTags' => true, 4628 'matchTags' => array( 4629 'bothTags' => true, 4630 ), 4631 ) 4632 ); 4633 4634 if ( ! current_user_can( 'unfiltered_html' ) ) { 4635 $settings['htmlhint']['kses'] = wp_kses_allowed_html( 'post' ); 4636 } 4637 } elseif ( 'text/x-gfm' === $type ) { 4638 $settings['codemirror'] = array_merge( 4639 $settings['codemirror'], 4640 array( 4641 'mode' => 'gfm', 4642 'highlightFormatting' => true, 4643 ) 4644 ); 4645 } elseif ( 'application/javascript' === $type || 'text/javascript' === $type ) { 4646 $settings['codemirror'] = array_merge( 4647 $settings['codemirror'], 4648 array( 4649 'mode' => 'javascript', 4650 'lint' => true, 4651 'autoCloseBrackets' => true, 4652 'matchBrackets' => true, 4653 ) 4654 ); 4655 } elseif ( str_contains( $type, 'json' ) ) { 4656 $settings['codemirror'] = array_merge( 4657 $settings['codemirror'], 4658 array( 4659 'mode' => array( 4660 'name' => 'javascript', 4661 ), 4662 'lint' => true, 4663 'autoCloseBrackets' => true, 4664 'matchBrackets' => true, 4665 ) 4666 ); 4667 if ( 'application/ld+json' === $type ) { 4668 $settings['codemirror']['mode']['jsonld'] = true; 4669 } else { 4670 $settings['codemirror']['mode']['json'] = true; 4671 } 4672 } elseif ( str_contains( $type, 'jsx' ) ) { 4673 $settings['codemirror'] = array_merge( 4674 $settings['codemirror'], 4675 array( 4676 'mode' => 'jsx', 4677 'autoCloseBrackets' => true, 4678 'matchBrackets' => true, 4679 ) 4680 ); 4681 } elseif ( 'text/x-markdown' === $type ) { 4682 $settings['codemirror'] = array_merge( 4683 $settings['codemirror'], 4684 array( 4685 'mode' => 'markdown', 4686 'highlightFormatting' => true, 4687 ) 4688 ); 4689 } elseif ( 'text/nginx' === $type ) { 4690 $settings['codemirror'] = array_merge( 4691 $settings['codemirror'], 4692 array( 4693 'mode' => 'nginx', 4694 ) 4695 ); 4696 } elseif ( 'application/x-httpd-php' === $type ) { 4697 $settings['codemirror'] = array_merge( 4698 $settings['codemirror'], 4699 array( 4700 'mode' => 'php', 4701 'autoCloseBrackets' => true, 4702 'autoCloseTags' => true, 4703 'matchBrackets' => true, 4704 'matchTags' => array( 4705 'bothTags' => true, 4706 ), 4707 ) 4708 ); 4709 } elseif ( 'text/x-sql' === $type || 'text/x-mysql' === $type ) { 4710 $settings['codemirror'] = array_merge( 4711 $settings['codemirror'], 4712 array( 4713 'mode' => 'sql', 4714 'autoCloseBrackets' => true, 4715 'matchBrackets' => true, 4716 ) 4717 ); 4718 } elseif ( str_contains( $type, 'xml' ) ) { 4719 $settings['codemirror'] = array_merge( 4720 $settings['codemirror'], 4721 array( 4722 'mode' => 'xml', 4723 'autoCloseBrackets' => true, 4724 'autoCloseTags' => true, 4725 'matchTags' => array( 4726 'bothTags' => true, 4727 ), 4728 ) 4729 ); 4730 } elseif ( 'text/x-yaml' === $type ) { 4731 $settings['codemirror'] = array_merge( 4732 $settings['codemirror'], 4733 array( 4734 'mode' => 'yaml', 4735 ) 4736 ); 4737 } else { 4738 $settings['codemirror']['mode'] = $type; 4739 } 4740 4741 if ( ! empty( $settings['codemirror']['lint'] ) ) { 4742 $settings['codemirror']['gutters'][] = 'CodeMirror-lint-markers'; 4743 } 4744 4745 // Let settings supplied via args override any defaults. 4746 foreach ( wp_array_slice_assoc( $args, array( 'codemirror', 'csslint', 'jshint', 'htmlhint' ) ) as $key => $value ) { 4747 $settings[ $key ] = array_merge( 4748 $settings[ $key ], 4749 $value 4750 ); 4751 } 4752 4753 /** 4754 * Filters settings that are passed into the code editor. 4755 * 4756 * Returning a falsey value will disable the syntax-highlighting code editor. 4757 * 4758 * @since 4.9.0 4759 * 4760 * @param array $settings The array of settings passed to the code editor. 4761 * A falsey value disables the editor. 4762 * @param array $args { 4763 * Args passed when calling `get_code_editor_settings()`. 4764 * 4765 * @type string $type The MIME type of the file to be edited. 4766 * @type string $file Filename being edited. 4767 * @type WP_Theme $theme Theme being edited when on the theme file editor. 4768 * @type string $plugin Plugin being edited when on the plugin file editor. 4769 * @type array $codemirror Additional CodeMirror setting overrides. 4770 * @type array $csslint CSSLint rule overrides. 4771 * @type array $jshint JSHint rule overrides. 4772 * @type array $htmlhint HTMLHint rule overrides. 4773 * } 4774 */ 4775 return apply_filters( 'wp_code_editor_settings', $settings, $args ); 4776 } 4777 4778 /** 4779 * Retrieves the contents of the search WordPress query variable. 4780 * 4781 * The search query string is passed through esc_attr() to ensure that it is safe 4782 * for placing in an HTML attribute. 4783 * 4784 * @since 2.3.0 4785 * 4786 * @param bool $escaped Whether the result is escaped. Default true. 4787 * Only use when you are later escaping it. Do not use unescaped. 4788 * @return string 4789 */ 4790 function get_search_query( $escaped = true ) { 4791 /** 4792 * Filters the contents of the search query variable. 4793 * 4794 * @since 2.3.0 4795 * 4796 * @param mixed $search Contents of the search query variable. 4797 */ 4798 $query = apply_filters( 'get_search_query', get_query_var( 's' ) ); 4799 4800 if ( $escaped ) { 4801 $query = esc_attr( $query ); 4802 } 4803 return $query; 4804 } 4805 4806 /** 4807 * Displays the contents of the search query variable. 4808 * 4809 * The search query string is passed through esc_attr() to ensure that it is safe 4810 * for placing in an HTML attribute. 4811 * 4812 * @since 2.1.0 4813 */ 4814 function the_search_query() { 4815 /** 4816 * Filters the contents of the search query variable, for display. 4817 * 4818 * @since 2.3.0 4819 * 4820 * @param mixed $search Contents of the search query variable. 4821 */ 4822 echo esc_attr( apply_filters( 'the_search_query', get_search_query( false ) ) ); 4823 } 4824 4825 /** 4826 * Gets the language attributes for the 'html' tag. 4827 * 4828 * Builds up a set of HTML attributes containing the text direction and language 4829 * information for the page. 4830 * 4831 * @since 4.3.0 4832 * 4833 * @param string $doctype Optional. The type of HTML document. Accepts 'xhtml' or 'html'. Default 'html'. 4834 * @return string A space-separated list of language attributes. 4835 */ 4836 function get_language_attributes( $doctype = 'html' ) { 4837 $attributes = array(); 4838 4839 if ( function_exists( 'is_rtl' ) && is_rtl() ) { 4840 $attributes[] = 'dir="rtl"'; 4841 } 4842 4843 $lang = get_bloginfo( 'language' ); 4844 $html_type = get_option( 'html_type' ); 4845 4846 if ( $lang ) { 4847 if ( 'text/html' === $html_type || 'html' === $doctype ) { 4848 $attributes[] = 'lang="' . esc_attr( $lang ) . '"'; 4849 } 4850 4851 // The $html_type option may be false on a new install on the setup-config.php page. 4852 if ( ( $html_type && 'text/html' !== $html_type ) || 'xhtml' === $doctype ) { 4853 $attributes[] = 'xml:lang="' . esc_attr( $lang ) . '"'; 4854 } 4855 } 4856 4857 $output = implode( ' ', $attributes ); 4858 4859 /** 4860 * Filters the language attributes for display in the 'html' tag. 4861 * 4862 * @since 2.5.0 4863 * @since 4.3.0 Added the `$doctype` parameter. 4864 * 4865 * @param string $output A space-separated list of language attributes. 4866 * @param string $doctype The type of HTML document (xhtml|html). 4867 */ 4868 return apply_filters( 'language_attributes', $output, $doctype ); 4869 } 4870 4871 /** 4872 * Displays the language attributes for the 'html' tag. 4873 * 4874 * Builds up a set of HTML attributes containing the text direction and language 4875 * information for the page. 4876 * 4877 * @since 2.1.0 4878 * @since 4.3.0 Converted into a wrapper for get_language_attributes(). 4879 * 4880 * @param string $doctype Optional. The type of HTML document. Accepts 'xhtml' or 'html'. Default 'html'. 4881 */ 4882 function language_attributes( $doctype = 'html' ) { 4883 echo get_language_attributes( $doctype ); 4884 } 4885 4886 /** 4887 * Retrieves paginated links for archive post pages. 4888 * 4889 * Technically, the function can be used to create paginated link list for any 4890 * area. The 'base' argument is used to reference the url, which will be used to 4891 * create the paginated links. The 'format' argument is then used for replacing 4892 * the page number. It is however, most likely and by default, to be used on the 4893 * archive post pages. 4894 * 4895 * The 'type' argument controls format of the returned value. The default is 4896 * 'plain', which is just a string with the links separated by a newline 4897 * character. The other possible values are either 'array' or 'list'. The 4898 * 'array' value will return an array of the paginated link list to offer full 4899 * control of display. The 'list' value will place all of the paginated links in 4900 * an unordered HTML list. 4901 * 4902 * The 'total' argument is the total amount of pages and is an integer. The 4903 * 'current' argument is the current page number and is also an integer. 4904 * 4905 * An example of the 'base' argument is "http://example.com/all_posts.php%_%" 4906 * and the '%_%' is required. The '%_%' will be replaced by the contents of in 4907 * the 'format' argument. An example for the 'format' argument is "?page=%#%" 4908 * and the '%#%' is also required. The '%#%' will be replaced with the page 4909 * number. 4910 * 4911 * You can include the previous and next links in the list by setting the 4912 * 'prev_next' argument to true, which it is by default. You can set the 4913 * previous text, by using the 'prev_text' argument. You can set the next text 4914 * by setting the 'next_text' argument. 4915 * 4916 * If the 'show_all' argument is set to true, then it will show all of the pages 4917 * instead of a short list of the pages near the current page. By default, the 4918 * 'show_all' is set to false and controlled by the 'end_size' and 'mid_size' 4919 * arguments. The 'end_size' argument is how many numbers on either the start 4920 * and the end list edges, by default is 1. The 'mid_size' argument is how many 4921 * numbers to either side of current page, but not including current page. 4922 * 4923 * It is possible to add query vars to the link by using the 'add_args' argument 4924 * and see add_query_arg() for more information. 4925 * 4926 * The 'before_page_number' and 'after_page_number' arguments allow users to 4927 * augment the links themselves. Typically this might be to add context to the 4928 * numbered links so that screen reader users understand what the links are for. 4929 * The text strings are added before and after the page number - within the 4930 * anchor tag. 4931 * 4932 * @since 2.1.0 4933 * @since 4.9.0 Added the `aria_current` argument. 4934 * 4935 * @global WP_Query $wp_query WordPress Query object. 4936 * @global WP_Rewrite $wp_rewrite WordPress rewrite component. 4937 * 4938 * @param string|array $args { 4939 * Optional. Array or string of arguments for generating paginated links for archives. 4940 * 4941 * @type string $base Base of the paginated url. Default empty. 4942 * @type string $format Format for the pagination structure. Default empty. 4943 * @type int $total The total amount of pages. Default is the value WP_Query's 4944 * `max_num_pages` or 1. 4945 * @type int $current The current page number. Default is 'paged' query var or 1. 4946 * @type string $aria_current The value for the aria-current attribute. Possible values are 'page', 4947 * 'step', 'location', 'date', 'time', 'true', 'false'. Default is 'page'. 4948 * @type bool $show_all Whether to show all pages. Default false. 4949 * @type int $end_size How many numbers on either the start and the end list edges. 4950 * Default 1. 4951 * @type int $mid_size How many numbers to either side of the current pages. Default 2. 4952 * @type bool $prev_next Whether to include the previous and next links in the list. Default true. 4953 * @type string $prev_text The previous page text. Default '« Previous'. 4954 * @type string $next_text The next page text. Default 'Next »'. 4955 * @type string $type Controls format of the returned value. Possible values are 'plain', 4956 * 'array' and 'list'. Default is 'plain'. 4957 * @type array $add_args An array of query args to add. Default false. 4958 * @type string $add_fragment A string to append to each link. Default empty. 4959 * @type string $before_page_number A string to appear before the page number. Default empty. 4960 * @type string $after_page_number A string to append after the page number. Default empty. 4961 * } 4962 * @return string|string[]|null String of page links or array of page links, depending on 'type' argument. 4963 * Null if total number of pages is less than 2. 4964 * 4965 * @phpstan-return ( 4966 * $args is array{ total: int<min, 1>, ... } 4967 * ? null 4968 * : ( 4969 * $args is array{ total: int<2, max>, ... } 4970 * ? ( $args is array{ type: 'array', ... } ? list<string> : string ) 4971 * : ( $args is array{ type: 'array', ... } ? list<string> : string )|null 4972 * ) 4973 * ) 4974 */ 4975 function paginate_links( $args = '' ) { 4976 global $wp_query, $wp_rewrite; 4977 4978 // Setting up default values based on the current URL. 4979 $pagenum_link = html_entity_decode( get_pagenum_link() ); 4980 $url_parts = explode( '?', $pagenum_link ); 4981 4982 // Get max pages and current page out of the current query, if available. 4983 $total = $wp_query->max_num_pages ?? 1; 4984 $current = get_query_var( 'paged' ) ? (int) get_query_var( 'paged' ) : 1; 4985 4986 /* 4987 * Ensures sites not using trailing slashes get links in the form 4988 * `/page/2` rather than `/page/2/`. On these sites, linking to the 4989 * URL with a trailing slash will result in a 301 redirect from the 4990 * incorrect URL to the correctly formatted one. This presents an 4991 * unnecessary performance hit. 4992 */ 4993 if ( $wp_rewrite->using_permalinks() && ! $wp_rewrite->use_trailing_slashes ) { 4994 $pagenum_link = untrailingslashit( $url_parts[0] ); 4995 } else { 4996 $pagenum_link = trailingslashit( $url_parts[0] ); 4997 } 4998 $pagenum_link .= '%_%'; 4999 5000 // URL base depends on permalink settings. 5001 $format = $wp_rewrite->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : ''; 5002 $format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?paged=%#%'; 5003 if ( $wp_rewrite->using_permalinks() && ! $wp_rewrite->use_trailing_slashes ) { 5004 $format = '/' . ltrim( $format, '/' ); 5005 } 5006 5007 $defaults = array( 5008 'base' => $pagenum_link, // http://example.com/all_posts.php%_% : %_% is replaced by format (below). 5009 'format' => $format, // ?page=%#% : %#% is replaced by the page number. 5010 'total' => $total, 5011 'current' => $current, 5012 'aria_current' => 'page', 5013 'show_all' => false, 5014 'prev_next' => true, 5015 'prev_text' => __( '« Previous' ), 5016 'next_text' => __( 'Next »' ), 5017 'end_size' => 1, 5018 'mid_size' => 2, 5019 'type' => 'plain', 5020 'add_args' => array(), // Array of query args to add. 5021 'add_fragment' => '', 5022 'before_page_number' => '', 5023 'after_page_number' => '', 5024 ); 5025 5026 $args = wp_parse_args( $args, $defaults ); 5027 5028 if ( ! is_array( $args['add_args'] ) ) { 5029 $args['add_args'] = array(); 5030 } 5031 5032 // Merge additional query vars found in the original URL into 'add_args' array. 5033 if ( isset( $url_parts[1] ) ) { 5034 // Find the format argument. 5035 $format = explode( '?', str_replace( '%_%', $args['format'], $args['base'] ) ); 5036 $format_query = $format[1] ?? ''; 5037 wp_parse_str( $format_query, $format_args ); 5038 5039 // Find the query args of the requested URL. 5040 wp_parse_str( $url_parts[1], $url_query_args ); 5041 5042 // Remove the format argument from the array of query arguments, to avoid overwriting custom format. 5043 foreach ( $format_args as $format_arg => $format_arg_value ) { 5044 unset( $url_query_args[ $format_arg ] ); 5045 } 5046 5047 $args['add_args'] = array_merge( $args['add_args'], urlencode_deep( $url_query_args ) ); 5048 } 5049 5050 // Who knows what else people pass in $args. 5051 $total = (int) $args['total']; 5052 if ( $total < 2 ) { 5053 return null; 5054 } 5055 $current = (int) $args['current']; 5056 $end_size = (int) $args['end_size']; // Out of bounds? Make it the default. 5057 if ( $end_size < 1 ) { 5058 $end_size = 1; 5059 } 5060 $mid_size = (int) $args['mid_size']; 5061 if ( $mid_size < 0 ) { 5062 $mid_size = 2; 5063 } 5064 5065 $add_args = $args['add_args']; 5066 $r = ''; 5067 $page_links = array(); 5068 $dots = false; 5069 5070 if ( $args['prev_next'] && $current && 1 < $current ) : 5071 $link = str_replace( '%_%', 2 === $current ? '' : $args['format'], $args['base'] ); 5072 $link = str_replace( '%#%', $current - 1, $link ); 5073 if ( $add_args ) { 5074 $link = add_query_arg( $add_args, $link ); 5075 } 5076 $link .= $args['add_fragment']; 5077 5078 $page_links[] = sprintf( 5079 '<a class="prev page-numbers" href="%s">%s</a>', 5080 /** 5081 * Filters the paginated links for the given archive pages. 5082 * 5083 * @since 3.0.0 5084 * 5085 * @param string $link The paginated link URL. 5086 */ 5087 esc_url( apply_filters( 'paginate_links', $link ) ), 5088 $args['prev_text'] 5089 ); 5090 endif; 5091 5092 for ( $n = 1; $n <= $total; $n++ ) : 5093 if ( $n === $current ) : 5094 $page_links[] = sprintf( 5095 '<span aria-current="%s" class="page-numbers current">%s</span>', 5096 esc_attr( $args['aria_current'] ), 5097 $args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number'] 5098 ); 5099 5100 $dots = true; 5101 else : 5102 if ( $args['show_all'] || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) : 5103 $link = str_replace( '%_%', 1 === $n ? '' : $args['format'], $args['base'] ); 5104 $link = str_replace( '%#%', $n, $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="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['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number'] 5115 ); 5116 5117 $dots = true; 5118 elseif ( $dots && ! $args['show_all'] ) : 5119 $page_links[] = '<span class="page-numbers dots">' . __( '…' ) . '</span>'; 5120 5121 $dots = false; 5122 endif; 5123 endif; 5124 endfor; 5125 5126 if ( $args['prev_next'] && $current && $current < $total ) : 5127 $link = str_replace( '%_%', $args['format'], $args['base'] ); 5128 $link = str_replace( '%#%', $current + 1, $link ); 5129 if ( $add_args ) { 5130 $link = add_query_arg( $add_args, $link ); 5131 } 5132 $link .= $args['add_fragment']; 5133 5134 $page_links[] = sprintf( 5135 '<a class="next page-numbers" href="%s">%s</a>', 5136 /** This filter is documented in wp-includes/general-template.php */ 5137 esc_url( apply_filters( 'paginate_links', $link ) ), 5138 $args['next_text'] 5139 ); 5140 endif; 5141 5142 switch ( $args['type'] ) { 5143 case 'array': 5144 return $page_links; 5145 5146 case 'list': 5147 $r .= "<ul class='page-numbers'>\n\t<li>"; 5148 $r .= implode( "</li>\n\t<li>", $page_links ); 5149 $r .= "</li>\n</ul>\n"; 5150 break; 5151 5152 default: 5153 $r = implode( "\n", $page_links ); 5154 break; 5155 } 5156 5157 /** 5158 * Filters the HTML output of paginated links for archives. 5159 * 5160 * @since 5.7.0 5161 * 5162 * @param string $r HTML output. 5163 * @param array $args An array of arguments. See paginate_links() 5164 * for information on accepted arguments. 5165 */ 5166 $r = apply_filters( 'paginate_links_output', $r, $args ); 5167 5168 return $r; 5169 } 5170 5171 /** 5172 * Registers an admin color scheme css file. 5173 * 5174 * Allows a plugin to register a new admin color scheme. For example: 5175 * 5176 * wp_admin_css_color( 'classic', __( 'Classic' ), admin_url( "css/colors-classic.css" ), array( 5177 * '#07273E', '#14568A', '#D54E21', '#2683AE' 5178 * ) ); 5179 * 5180 * @since 2.5.0 5181 * 5182 * @global array $_wp_admin_css_colors 5183 * 5184 * @param string $key The unique key for this theme. 5185 * @param string $name The name of the theme. 5186 * @param string $url The URL of the CSS file containing the color scheme. 5187 * @param array $colors Optional. An array of CSS color definition strings which are used 5188 * to give the user a feel for the theme. 5189 * @param array $icons { 5190 * Optional. CSS color definitions used to color any SVG icons. 5191 * 5192 * @type string $base SVG icon base color. 5193 * @type string $focus SVG icon color on focus. 5194 * @type string $current SVG icon color of current admin menu link. 5195 * } 5196 */ 5197 function wp_admin_css_color( $key, $name, $url, $colors = array(), $icons = array() ) { 5198 global $_wp_admin_css_colors; 5199 5200 if ( ! isset( $_wp_admin_css_colors ) ) { 5201 $_wp_admin_css_colors = array(); 5202 } 5203 5204 $_wp_admin_css_colors[ $key ] = (object) array( 5205 'name' => $name, 5206 'url' => $url, 5207 'colors' => $colors, 5208 'icon_colors' => $icons, 5209 ); 5210 } 5211 5212 /** 5213 * Registers the default admin color schemes. 5214 * 5215 * Registers the initial set of eight color schemes in the Profile section 5216 * of the dashboard which allows for styling the admin menu and toolbar. 5217 * 5218 * @see wp_admin_css_color() 5219 * 5220 * @since 3.0.0 5221 */ 5222 function register_admin_color_schemes() { 5223 $suffix = is_rtl() ? '-rtl' : ''; 5224 $suffix .= SCRIPT_DEBUG ? '' : '.min'; 5225 5226 wp_admin_css_color( 5227 'modern', 5228 _x( 'Default', 'admin color scheme' ), 5229 admin_url( "css/colors/modern/colors$suffix.css" ), 5230 array( '#1e1e1e', '#3858e9', '#7b90ff' ), 5231 array( 5232 'base' => '#f3f1f1', 5233 'focus' => '#fff', 5234 'current' => '#fff', 5235 ) 5236 ); 5237 5238 wp_admin_css_color( 5239 'fresh', 5240 _x( 'Fresh', 'admin color scheme' ), 5241 false, 5242 array( '#1d2327', '#2c3338', '#2271b1', '#72aee6' ), 5243 array( 5244 'base' => '#a7aaad', 5245 'focus' => '#72aee6', 5246 'current' => '#fff', 5247 ) 5248 ); 5249 5250 wp_admin_css_color( 5251 'light', 5252 _x( 'Light', 'admin color scheme' ), 5253 admin_url( "css/colors/light/colors$suffix.css" ), 5254 array( '#e5e5e5', '#6a6a6a', '#c64606', '#007cba' ), 5255 array( 5256 'base' => '#999', 5257 'focus' => '#ccc', 5258 'current' => '#ccc', 5259 ) 5260 ); 5261 5262 wp_admin_css_color( 5263 'blue', 5264 _x( 'Blue', 'admin color scheme' ), 5265 admin_url( "css/colors/blue/colors$suffix.css" ), 5266 array( '#183751', '#245278', '#437aa8', '#e1a948' ), 5267 array( 5268 'base' => '#e5f8ff', 5269 'focus' => '#fff', 5270 'current' => '#fff', 5271 ) 5272 ); 5273 5274 wp_admin_css_color( 5275 'midnight', 5276 _x( 'Midnight', 'admin color scheme' ), 5277 admin_url( "css/colors/midnight/colors$suffix.css" ), 5278 array( '#232a2e', '#333c42', '#69a8bb', '#cf4339' ), 5279 array( 5280 'base' => '#f1f2f3', 5281 'focus' => '#fff', 5282 'current' => '#fff', 5283 ) 5284 ); 5285 5286 wp_admin_css_color( 5287 'sunrise', 5288 _x( 'Sunrise', 'admin color scheme' ), 5289 admin_url( "css/colors/sunrise/colors$suffix.css" ), 5290 array( '#6f2724', '#8a312d', '#ad631e', '#ccaf0b' ), 5291 array( 5292 'base' => '#f3f1f1', 5293 'focus' => '#fff', 5294 'current' => '#fff', 5295 ) 5296 ); 5297 5298 wp_admin_css_color( 5299 'ectoplasm', 5300 _x( 'Ectoplasm', 'admin color scheme' ), 5301 admin_url( "css/colors/ectoplasm/colors$suffix.css" ), 5302 array( '#392751', '#4a3369', '#646c3e', '#d46f15' ), 5303 array( 5304 'base' => '#ece6f6', 5305 'focus' => '#fff', 5306 'current' => '#fff', 5307 ) 5308 ); 5309 5310 wp_admin_css_color( 5311 'ocean', 5312 _x( 'Ocean', 'admin color scheme' ), 5313 admin_url( "css/colors/ocean/colors$suffix.css" ), 5314 array( '#2b3f44', '#39535a', '#567958', '#aa9d88' ), 5315 array( 5316 'base' => '#f2fcff', 5317 'focus' => '#fff', 5318 'current' => '#fff', 5319 ) 5320 ); 5321 5322 wp_admin_css_color( 5323 'coffee', 5324 _x( 'Coffee', 'admin color scheme' ), 5325 admin_url( "css/colors/coffee/colors$suffix.css" ), 5326 array( '#382e27', '#5c4c40', '#916745', '#9ea476' ), 5327 array( 5328 'base' => '#f3f2f1', 5329 'focus' => '#fff', 5330 'current' => '#fff', 5331 ) 5332 ); 5333 } 5334 5335 /** 5336 * Displays the URL of a WordPress admin CSS file. 5337 * 5338 * @see WP_Styles::_css_href() and its {@see 'style_loader_src'} filter. 5339 * 5340 * @since 2.3.0 5341 * 5342 * @param string $file file relative to wp-admin/ without its ".css" extension. 5343 * @return string 5344 */ 5345 function wp_admin_css_uri( $file = 'wp-admin' ) { 5346 if ( defined( 'WP_INSTALLING' ) ) { 5347 $_file = "./$file.css"; 5348 } else { 5349 $_file = admin_url( "$file.css" ); 5350 } 5351 $_file = add_query_arg( 'version', get_bloginfo( 'version' ), $_file ); 5352 5353 /** 5354 * Filters the URI of a WordPress admin CSS file. 5355 * 5356 * @since 2.3.0 5357 * 5358 * @param string $_file Relative path to the file with query arguments attached. 5359 * @param string $file Relative path to the file, minus its ".css" extension. 5360 */ 5361 return apply_filters( 'wp_admin_css_uri', $_file, $file ); 5362 } 5363 5364 /** 5365 * Enqueues or directly prints a stylesheet link to the specified CSS file. 5366 * 5367 * "Intelligently" decides to enqueue or to print the CSS file. If the 5368 * {@see 'wp_print_styles'} action has *not* yet been called, the CSS file will be 5369 * enqueued. If the {@see 'wp_print_styles'} action has been called, the CSS link will 5370 * be printed. Printing may be forced by passing true as the $force_echo 5371 * (second) parameter. 5372 * 5373 * For backward compatibility with WordPress 2.3 calling method: If the $file 5374 * (first) parameter does not correspond to a registered CSS file, we assume 5375 * $file is a file relative to wp-admin/ without its ".css" extension. A 5376 * stylesheet link to that generated URL is printed. 5377 * 5378 * @since 2.3.0 5379 * 5380 * @param string $file Optional. Style handle name or file name (without ".css" extension) relative 5381 * to wp-admin/. Defaults to 'wp-admin'. 5382 * @param bool $force_echo Optional. Force the stylesheet link to be printed rather than enqueued. 5383 */ 5384 function wp_admin_css( $file = 'wp-admin', $force_echo = false ) { 5385 // For backward compatibility. 5386 $handle = str_starts_with( $file, 'css/' ) ? substr( $file, 4 ) : $file; 5387 5388 if ( wp_styles()->query( $handle ) ) { 5389 if ( $force_echo || did_action( 'wp_print_styles' ) ) { 5390 // We already printed the style queue. Print this one immediately. 5391 wp_print_styles( $handle ); 5392 } else { 5393 // Add to style queue. 5394 wp_enqueue_style( $handle ); 5395 } 5396 return; 5397 } 5398 5399 $stylesheet_link = sprintf( 5400 "<link rel='stylesheet' href='%s' />\n", 5401 esc_url( wp_admin_css_uri( $file ) ) 5402 ); 5403 5404 /** 5405 * Filters the stylesheet link to the specified CSS file. 5406 * 5407 * If the site is set to display right-to-left, the RTL stylesheet link 5408 * will be used instead. 5409 * 5410 * @since 2.3.0 5411 * @param string $stylesheet_link HTML link element for the stylesheet. 5412 * @param string $file Style handle name or filename (without ".css" extension) 5413 * relative to wp-admin/. Defaults to 'wp-admin'. 5414 */ 5415 echo apply_filters( 'wp_admin_css', $stylesheet_link, $file ); 5416 5417 if ( function_exists( 'is_rtl' ) && is_rtl() ) { 5418 $rtl_stylesheet_link = sprintf( 5419 "<link rel='stylesheet' href='%s' />\n", 5420 esc_url( wp_admin_css_uri( "$file-rtl" ) ) 5421 ); 5422 5423 /** This filter is documented in wp-includes/general-template.php */ 5424 echo apply_filters( 'wp_admin_css', $rtl_stylesheet_link, "$file-rtl" ); 5425 } 5426 } 5427 5428 /** 5429 * Enqueues the default ThickBox js and css. 5430 * 5431 * If any of the settings need to be changed, this can be done with another js 5432 * file similar to media-upload.js. That file should 5433 * require array('thickbox') to ensure it is loaded after. 5434 * 5435 * @since 2.5.0 5436 */ 5437 function add_thickbox() { 5438 wp_enqueue_script( 'thickbox' ); 5439 wp_enqueue_style( 'thickbox' ); 5440 5441 if ( is_network_admin() ) { 5442 add_action( 'admin_head', '_thickbox_path_admin_subfolder' ); 5443 } 5444 } 5445 5446 /** 5447 * Displays the XHTML generator that is generated on the wp_head hook. 5448 * 5449 * See {@see 'wp_head'}. 5450 * 5451 * @since 2.5.0 5452 */ 5453 function wp_generator() { 5454 /** 5455 * Filters the output of the XHTML generator tag. 5456 * 5457 * @since 2.5.0 5458 * 5459 * @param string $generator_type The XHTML generator. 5460 */ 5461 the_generator( apply_filters( 'wp_generator_type', 'xhtml' ) ); 5462 } 5463 5464 /** 5465 * Displays the generator XML or Comment for RSS, ATOM, etc. 5466 * 5467 * Returns the correct generator type for the requested output format. Allows 5468 * for a plugin to filter generators overall the {@see 'the_generator'} filter. 5469 * 5470 * @since 2.5.0 5471 * 5472 * @param string $type The type of generator to output - (html|xhtml|atom|rss2|rdf|comment|export). 5473 */ 5474 function the_generator( $type ) { 5475 /** 5476 * Filters the output of the XHTML generator tag, for display. 5477 * 5478 * @since 2.5.0 5479 * 5480 * @param string $generator_type The generator output. 5481 * @param string $type The type of generator to output. Accepts 'html', 5482 * 'xhtml', 'atom', 'rss2', 'rdf', 'comment', 'export'. 5483 */ 5484 echo apply_filters( 'the_generator', get_the_generator( $type ), $type ) . "\n"; 5485 } 5486 5487 /** 5488 * Creates the generator XML or Comment for RSS, ATOM, etc. 5489 * 5490 * Returns the correct generator type for the requested output format. Allows 5491 * for a plugin to filter generators on an individual basis using the 5492 * {@see 'get_the_generator_$type'} filter. 5493 * 5494 * @since 2.5.0 5495 * 5496 * @param string $type The type of generator to return - (html|xhtml|atom|rss2|rdf|comment|export). 5497 * @return string|null The HTML content for the generator. 5498 */ 5499 function get_the_generator( $type = '' ) { 5500 if ( empty( $type ) ) { 5501 5502 $current_filter = current_filter(); 5503 if ( empty( $current_filter ) ) { 5504 return null; 5505 } 5506 5507 switch ( $current_filter ) { 5508 case 'rss2_head': 5509 case 'commentsrss2_head': 5510 $type = 'rss2'; 5511 break; 5512 case 'rss_head': 5513 case 'opml_head': 5514 $type = 'comment'; 5515 break; 5516 case 'rdf_header': 5517 $type = 'rdf'; 5518 break; 5519 case 'atom_head': 5520 case 'comments_atom_head': 5521 case 'app_head': 5522 $type = 'atom'; 5523 break; 5524 } 5525 } 5526 5527 switch ( $type ) { 5528 case 'html': 5529 $gen = '<meta name="generator" content="WordPress ' . esc_attr( get_bloginfo( 'version' ) ) . '">'; 5530 break; 5531 case 'xhtml': 5532 $gen = '<meta name="generator" content="WordPress ' . esc_attr( get_bloginfo( 'version' ) ) . '" />'; 5533 break; 5534 case 'atom': 5535 $gen = '<generator uri="https://wordpress.org/" version="' . esc_attr( get_bloginfo_rss( 'version' ) ) . '">WordPress</generator>'; 5536 break; 5537 case 'rss2': 5538 $gen = '<generator>' . sanitize_url( 'https://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) ) . '</generator>'; 5539 break; 5540 case 'rdf': 5541 $gen = '<admin:generatorAgent rdf:resource="' . sanitize_url( 'https://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) ) . '" />'; 5542 break; 5543 case 'comment': 5544 $gen = '<!-- generator="WordPress/' . esc_attr( get_bloginfo( 'version' ) ) . '" -->'; 5545 break; 5546 case 'export': 5547 $gen = '<!-- generator="WordPress/' . esc_attr( get_bloginfo_rss( 'version' ) ) . '" created="' . gmdate( 'Y-m-d H:i' ) . '" -->'; 5548 break; 5549 } 5550 5551 /** 5552 * Filters the HTML for the retrieved generator type. 5553 * 5554 * The dynamic portion of the hook name, `$type`, refers to the generator type. 5555 * 5556 * Possible hook names include: 5557 * 5558 * - `get_the_generator_atom` 5559 * - `get_the_generator_comment` 5560 * - `get_the_generator_export` 5561 * - `get_the_generator_html` 5562 * - `get_the_generator_rdf` 5563 * - `get_the_generator_rss2` 5564 * - `get_the_generator_xhtml` 5565 * 5566 * @since 2.5.0 5567 * 5568 * @param string $gen The HTML markup output to wp_head(). 5569 * @param string $type The type of generator. Accepts 'html', 'xhtml', 'atom', 5570 * 'rss2', 'rdf', 'comment', 'export'. 5571 */ 5572 return apply_filters( "get_the_generator_{$type}", $gen, $type ); 5573 } 5574 5575 /** 5576 * Outputs the HTML checked attribute. 5577 * 5578 * Compares the first two arguments and if identical marks as checked. 5579 * 5580 * @since 1.0.0 5581 * 5582 * @param mixed $checked One of the values to compare. 5583 * @param mixed $current Optional. The other value to compare if not just true. 5584 * Default true. 5585 * @param bool $display Optional. Whether to echo or just return the string. 5586 * Default true. 5587 * @return string HTML attribute or empty string. 5588 */ 5589 function checked( $checked, $current = true, $display = true ) { 5590 return __checked_selected_helper( $checked, $current, $display, 'checked' ); 5591 } 5592 5593 /** 5594 * Outputs the HTML selected attribute. 5595 * 5596 * Compares the first two arguments and if identical marks as selected. 5597 * 5598 * @since 1.0.0 5599 * 5600 * @param mixed $selected One of the values to compare. 5601 * @param mixed $current Optional. The other value to compare if not just true. 5602 * Default true. 5603 * @param bool $display Optional. Whether to echo or just return the string. 5604 * Default true. 5605 * @return string HTML attribute or empty string. 5606 */ 5607 function selected( $selected, $current = true, $display = true ) { 5608 return __checked_selected_helper( $selected, $current, $display, 'selected' ); 5609 } 5610 5611 /** 5612 * Outputs the HTML disabled attribute. 5613 * 5614 * Compares the first two arguments and if identical marks as disabled. 5615 * 5616 * @since 3.0.0 5617 * 5618 * @param mixed $disabled One of the values to compare. 5619 * @param mixed $current Optional. The other value to compare if not just true. 5620 * Default true. 5621 * @param bool $display Optional. Whether to echo or just return the string. 5622 * Default true. 5623 * @return string HTML attribute or empty string. 5624 */ 5625 function disabled( $disabled, $current = true, $display = true ) { 5626 return __checked_selected_helper( $disabled, $current, $display, 'disabled' ); 5627 } 5628 5629 /** 5630 * Outputs the HTML readonly attribute. 5631 * 5632 * Compares the first two arguments and if identical marks as readonly. 5633 * 5634 * @since 5.9.0 5635 * 5636 * @param mixed $readonly_value One of the values to compare. 5637 * @param mixed $current Optional. The other value to compare if not just true. 5638 * Default true. 5639 * @param bool $display Optional. Whether to echo or just return the string. 5640 * Default true. 5641 * @return string HTML attribute or empty string. 5642 */ 5643 function wp_readonly( $readonly_value, $current = true, $display = true ) { 5644 return __checked_selected_helper( $readonly_value, $current, $display, 'readonly' ); 5645 } 5646 5647 /* 5648 * Include a compat `readonly()` function on PHP < 8.1. Since PHP 8.1, 5649 * `readonly` is a reserved keyword and cannot be used as a function name. 5650 * In order to avoid PHP parser errors, this function was extracted 5651 * to a separate file and is only included conditionally on PHP < 8.1. 5652 */ 5653 if ( PHP_VERSION_ID < 80100 ) { 5654 require_once __DIR__ . '/php-compat/readonly.php'; 5655 } 5656 5657 /** 5658 * Private helper function for checked, selected, disabled and readonly. 5659 * 5660 * Compares the first two arguments and if identical marks as `$type`. 5661 * 5662 * @since 2.8.0 5663 * @access private 5664 * 5665 * @param mixed $helper One of the values to compare. 5666 * @param mixed $current The other value to compare if not just true. 5667 * @param bool $display Whether to echo or just return the string. 5668 * @param string $type The type of checked|selected|disabled|readonly we are doing. 5669 * @return string HTML attribute or empty string. 5670 */ 5671 function __checked_selected_helper( $helper, $current, $display, $type ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore 5672 if ( (string) $helper === (string) $current ) { 5673 $result = " $type='$type'"; 5674 } else { 5675 $result = ''; 5676 } 5677 5678 if ( $display ) { 5679 echo $result; 5680 } 5681 5682 return $result; 5683 } 5684 5685 /** 5686 * Assigns a visual indicator for required form fields. 5687 * 5688 * @since 6.1.0 5689 * 5690 * @return string Indicator glyph wrapped in a `span` tag. 5691 */ 5692 function wp_required_field_indicator() { 5693 /* translators: Character to identify required form fields. */ 5694 $glyph = __( '*' ); 5695 $indicator = '<span class="required">' . esc_html( $glyph ) . '</span>'; 5696 5697 /** 5698 * Filters the markup for a visual indicator of required form fields. 5699 * 5700 * @since 6.1.0 5701 * 5702 * @param string $indicator Markup for the indicator element. 5703 */ 5704 return apply_filters( 'wp_required_field_indicator', $indicator ); 5705 } 5706 5707 /** 5708 * Creates a message to explain required form fields. 5709 * 5710 * @since 6.1.0 5711 * 5712 * @return string Message text and glyph wrapped in a `span` tag. 5713 */ 5714 function wp_required_field_message() { 5715 $message = sprintf( 5716 '<span class="required-field-message">%s</span>', 5717 /* translators: %s: Asterisk symbol (*). */ 5718 sprintf( __( 'Required fields are marked %s' ), wp_required_field_indicator() ) 5719 ); 5720 5721 /** 5722 * Filters the message to explain required form fields. 5723 * 5724 * @since 6.1.0 5725 * 5726 * @param string $message Message text and glyph wrapped in a `span` tag. 5727 */ 5728 return apply_filters( 'wp_required_field_message', $message ); 5729 } 5730 5731 /** 5732 * Default settings for heartbeat. 5733 * 5734 * Outputs the nonce used in the heartbeat XHR. 5735 * 5736 * @since 3.6.0 5737 * 5738 * @param array $settings 5739 * @return array Heartbeat settings. 5740 */ 5741 function wp_heartbeat_settings( $settings ) { 5742 if ( ! is_admin() ) { 5743 $settings['ajaxurl'] = admin_url( 'admin-ajax.php', 'relative' ); 5744 } 5745 5746 if ( is_user_logged_in() ) { 5747 $settings['nonce'] = wp_create_nonce( 'heartbeat-nonce' ); 5748 } 5749 5750 return $settings; 5751 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Mon Oct 5 08:20:36 2026 | Cross-referenced by PHPXref |