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