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