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