wp/wp-includes/general-template.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
     5  * @package WordPress
     5  * @package WordPress
     6  * @subpackage Template
     6  * @subpackage Template
     7  */
     7  */
     8 
     8 
     9 /**
     9 /**
    10  * Load header template.
    10  * Loads header template.
    11  *
    11  *
    12  * Includes the header template for a theme or if a name is specified then a
    12  * Includes the header template for a theme or if a name is specified then a
    13  * specialised header will be included.
    13  * specialized header will be included.
    14  *
    14  *
    15  * For the parameter, if the file is called "header-special.php" then specify
    15  * For the parameter, if the file is called "header-special.php" then specify
    16  * "special".
    16  * "special".
    17  *
    17  *
    18  * @since 1.5.0
    18  * @since 1.5.0
    19  * @since 5.5.0 A return value was added.
    19  * @since 5.5.0 A return value was added.
    20  * @since 5.5.0 The `$args` parameter was added.
    20  * @since 5.5.0 The `$args` parameter was added.
    21  *
    21  *
    22  * @param string $name The name of the specialised header.
    22  * @param string $name The name of the specialized header.
    23  * @param array  $args Optional. Additional arguments passed to the header template.
    23  * @param array  $args Optional. Additional arguments passed to the header template.
    24  *                     Default empty array.
    24  *                     Default empty array.
    25  * @return void|false Void on success, false if the template does not exist.
    25  * @return void|false Void on success, false if the template does not exist.
    26  */
    26  */
    27 function get_header( $name = null, $args = array() ) {
    27 function get_header( $name = null, $args = array() ) {
    49 		return false;
    49 		return false;
    50 	}
    50 	}
    51 }
    51 }
    52 
    52 
    53 /**
    53 /**
    54  * Load footer template.
    54  * Loads footer template.
    55  *
    55  *
    56  * Includes the footer template for a theme or if a name is specified then a
    56  * Includes the footer template for a theme or if a name is specified then a
    57  * specialised footer will be included.
    57  * specialized footer will be included.
    58  *
    58  *
    59  * For the parameter, if the file is called "footer-special.php" then specify
    59  * For the parameter, if the file is called "footer-special.php" then specify
    60  * "special".
    60  * "special".
    61  *
    61  *
    62  * @since 1.5.0
    62  * @since 1.5.0
    63  * @since 5.5.0 A return value was added.
    63  * @since 5.5.0 A return value was added.
    64  * @since 5.5.0 The `$args` parameter was added.
    64  * @since 5.5.0 The `$args` parameter was added.
    65  *
    65  *
    66  * @param string $name The name of the specialised footer.
    66  * @param string $name The name of the specialized footer.
    67  * @param array  $args Optional. Additional arguments passed to the footer template.
    67  * @param array  $args Optional. Additional arguments passed to the footer template.
    68  *                     Default empty array.
    68  *                     Default empty array.
    69  * @return void|false Void on success, false if the template does not exist.
    69  * @return void|false Void on success, false if the template does not exist.
    70  */
    70  */
    71 function get_footer( $name = null, $args = array() ) {
    71 function get_footer( $name = null, $args = array() ) {
    93 		return false;
    93 		return false;
    94 	}
    94 	}
    95 }
    95 }
    96 
    96 
    97 /**
    97 /**
    98  * Load sidebar template.
    98  * Loads sidebar template.
    99  *
    99  *
   100  * Includes the sidebar template for a theme or if a name is specified then a
   100  * Includes the sidebar template for a theme or if a name is specified then a
   101  * specialised sidebar will be included.
   101  * specialized sidebar will be included.
   102  *
   102  *
   103  * For the parameter, if the file is called "sidebar-special.php" then specify
   103  * For the parameter, if the file is called "sidebar-special.php" then specify
   104  * "special".
   104  * "special".
   105  *
   105  *
   106  * @since 1.5.0
   106  * @since 1.5.0
   107  * @since 5.5.0 A return value was added.
   107  * @since 5.5.0 A return value was added.
   108  * @since 5.5.0 The `$args` parameter was added.
   108  * @since 5.5.0 The `$args` parameter was added.
   109  *
   109  *
   110  * @param string $name The name of the specialised sidebar.
   110  * @param string $name The name of the specialized sidebar.
   111  * @param array  $args Optional. Additional arguments passed to the sidebar template.
   111  * @param array  $args Optional. Additional arguments passed to the sidebar template.
   112  *                     Default empty array.
   112  *                     Default empty array.
   113  * @return void|false Void on success, false if the template does not exist.
   113  * @return void|false Void on success, false if the template does not exist.
   114  */
   114  */
   115 function get_sidebar( $name = null, $args = array() ) {
   115 function get_sidebar( $name = null, $args = array() ) {
   143  *
   143  *
   144  * Provides a simple mechanism for child themes to overload reusable sections of code
   144  * Provides a simple mechanism for child themes to overload reusable sections of code
   145  * in the theme.
   145  * in the theme.
   146  *
   146  *
   147  * Includes the named template part for a theme or if a name is specified then a
   147  * Includes the named template part for a theme or if a name is specified then a
   148  * specialised part will be included. If the theme contains no {slug}.php file
   148  * specialized part will be included. If the theme contains no {slug}.php file
   149  * then no template will be included.
   149  * then no template will be included.
   150  *
   150  *
   151  * The template is included using require, not require_once, so you may include the
   151  * The template is included using require, not require_once, so you may include the
   152  * same template part multiple times.
   152  * same template part multiple times.
   153  *
   153  *
   156  *
   156  *
   157  * @since 3.0.0
   157  * @since 3.0.0
   158  * @since 5.5.0 A return value was added.
   158  * @since 5.5.0 A return value was added.
   159  * @since 5.5.0 The `$args` parameter was added.
   159  * @since 5.5.0 The `$args` parameter was added.
   160  *
   160  *
   161  * @param string $slug The slug name for the generic template.
   161  * @param string      $slug The slug name for the generic template.
   162  * @param string $name The name of the specialised template.
   162  * @param string|null $name Optional. The name of the specialized template.
   163  * @param array  $args Optional. Additional arguments passed to the template.
   163  * @param array       $args Optional. Additional arguments passed to the template.
   164  *                     Default empty array.
   164  *                          Default empty array.
   165  * @return void|false Void on success, false if the template does not exist.
   165  * @return void|false Void on success, false if the template does not exist.
   166  */
   166  */
   167 function get_template_part( $slug, $name = null, $args = array() ) {
   167 function get_template_part( $slug, $name = null, $args = array() ) {
   168 	/**
   168 	/**
   169 	 * Fires before the specified template part file is loaded.
   169 	 * Fires before the specified template part file is loaded.
   173 	 *
   173 	 *
   174 	 * @since 3.0.0
   174 	 * @since 3.0.0
   175 	 * @since 5.5.0 The `$args` parameter was added.
   175 	 * @since 5.5.0 The `$args` parameter was added.
   176 	 *
   176 	 *
   177 	 * @param string      $slug The slug name for the generic template.
   177 	 * @param string      $slug The slug name for the generic template.
   178 	 * @param string|null $name The name of the specialized template.
   178 	 * @param string|null $name The name of the specialized template or null if
       
   179 	 *                          there is none.
   179 	 * @param array       $args Additional arguments passed to the template.
   180 	 * @param array       $args Additional arguments passed to the template.
   180 	 */
   181 	 */
   181 	do_action( "get_template_part_{$slug}", $slug, $name, $args );
   182 	do_action( "get_template_part_{$slug}", $slug, $name, $args );
   182 
   183 
   183 	$templates = array();
   184 	$templates = array();
   193 	 *
   194 	 *
   194 	 * @since 5.2.0
   195 	 * @since 5.2.0
   195 	 * @since 5.5.0 The `$args` parameter was added.
   196 	 * @since 5.5.0 The `$args` parameter was added.
   196 	 *
   197 	 *
   197 	 * @param string   $slug      The slug name for the generic template.
   198 	 * @param string   $slug      The slug name for the generic template.
   198 	 * @param string   $name      The name of the specialized template.
   199 	 * @param string   $name      The name of the specialized template or an empty
       
   200 	 *                            string if there is none.
   199 	 * @param string[] $templates Array of template files to search for, in order.
   201 	 * @param string[] $templates Array of template files to search for, in order.
   200 	 * @param array    $args      Additional arguments passed to the template.
   202 	 * @param array    $args      Additional arguments passed to the template.
   201 	 */
   203 	 */
   202 	do_action( 'get_template_part', $slug, $name, $templates, $args );
   204 	do_action( 'get_template_part', $slug, $name, $templates, $args );
   203 
   205 
   205 		return false;
   207 		return false;
   206 	}
   208 	}
   207 }
   209 }
   208 
   210 
   209 /**
   211 /**
   210  * Display search form.
   212  * Displays search form.
   211  *
   213  *
   212  * Will first attempt to locate the searchform.php file in either the child or
   214  * Will first attempt to locate the searchform.php file in either the child or
   213  * the parent, then load it. If it doesn't exist, then the default search form
   215  * the parent, then load it. If it doesn't exist, then the default search form
   214  * will be displayed. The default search form is HTML, which will be displayed.
   216  * will be displayed. The default search form is HTML, which will be displayed.
   215  * There is a filter applied to the search form HTML in order to edit or replace
   217  * There is a filter applied to the search form HTML in order to edit or replace
   320 		}
   322 		}
   321 
   323 
   322 		if ( 'html5' === $format ) {
   324 		if ( 'html5' === $format ) {
   323 			$form = '<form role="search" ' . $aria_label . 'method="get" class="search-form" action="' . esc_url( home_url( '/' ) ) . '">
   325 			$form = '<form role="search" ' . $aria_label . 'method="get" class="search-form" action="' . esc_url( home_url( '/' ) ) . '">
   324 				<label>
   326 				<label>
   325 					<span class="screen-reader-text">' . _x( 'Search for:', 'label' ) . '</span>
   327 					<span class="screen-reader-text">' .
       
   328 					/* translators: Hidden accessibility text. */
       
   329 					_x( 'Search for:', 'label' ) .
       
   330 					'</span>
   326 					<input type="search" class="search-field" placeholder="' . esc_attr_x( 'Search &hellip;', 'placeholder' ) . '" value="' . get_search_query() . '" name="s" />
   331 					<input type="search" class="search-field" placeholder="' . esc_attr_x( 'Search &hellip;', 'placeholder' ) . '" value="' . get_search_query() . '" name="s" />
   327 				</label>
   332 				</label>
   328 				<input type="submit" class="search-submit" value="' . esc_attr_x( 'Search', 'submit button' ) . '" />
   333 				<input type="submit" class="search-submit" value="' . esc_attr_x( 'Search', 'submit button' ) . '" />
   329 			</form>';
   334 			</form>';
   330 		} else {
   335 		} else {
   331 			$form = '<form role="search" ' . $aria_label . 'method="get" id="searchform" class="searchform" action="' . esc_url( home_url( '/' ) ) . '">
   336 			$form = '<form role="search" ' . $aria_label . 'method="get" id="searchform" class="searchform" action="' . esc_url( home_url( '/' ) ) . '">
   332 				<div>
   337 				<div>
   333 					<label class="screen-reader-text" for="s">' . _x( 'Search for:', 'label' ) . '</label>
   338 					<label class="screen-reader-text" for="s">' .
       
   339 					/* translators: Hidden accessibility text. */
       
   340 					_x( 'Search for:', 'label' ) .
       
   341 					'</label>
   334 					<input type="text" value="' . get_search_query() . '" name="s" id="s" />
   342 					<input type="text" value="' . get_search_query() . '" name="s" id="s" />
   335 					<input type="submit" id="searchsubmit" value="' . esc_attr_x( 'Search', 'submit button' ) . '" />
   343 					<input type="submit" id="searchsubmit" value="' . esc_attr_x( 'Search', 'submit button' ) . '" />
   336 				</div>
   344 				</div>
   337 			</form>';
   345 			</form>';
   338 		}
   346 		}
   360 		return $result;
   368 		return $result;
   361 	}
   369 	}
   362 }
   370 }
   363 
   371 
   364 /**
   372 /**
   365  * Display the Log In/Out link.
   373  * Displays the Log In/Out link.
   366  *
   374  *
   367  * Displays a link, which allows users to navigate to the Log In page to log in
   375  * Displays a link, which allows users to navigate to the Log In page to log in
   368  * or log out depending on whether they are currently logged in.
   376  * or log out depending on whether they are currently logged in.
   369  *
   377  *
   370  * @since 1.5.0
   378  * @since 1.5.0
   371  *
   379  *
   372  * @param string $redirect Optional path to redirect to on login/logout.
   380  * @param string $redirect Optional path to redirect to on login/logout.
   373  * @param bool   $echo     Default to echo and not return the link.
   381  * @param bool   $display  Default to echo and not return the link.
   374  * @return void|string Void if `$echo` argument is true, log in/out link if `$echo` is false.
   382  * @return void|string Void if `$display` argument is true, log in/out link if `$display` is false.
   375  */
   383  */
   376 function wp_loginout( $redirect = '', $echo = true ) {
   384 function wp_loginout( $redirect = '', $display = true ) {
   377 	if ( ! is_user_logged_in() ) {
   385 	if ( ! is_user_logged_in() ) {
   378 		$link = '<a href="' . esc_url( wp_login_url( $redirect ) ) . '">' . __( 'Log in' ) . '</a>';
   386 		$link = '<a href="' . esc_url( wp_login_url( $redirect ) ) . '">' . __( 'Log in' ) . '</a>';
   379 	} else {
   387 	} else {
   380 		$link = '<a href="' . esc_url( wp_logout_url( $redirect ) ) . '">' . __( 'Log out' ) . '</a>';
   388 		$link = '<a href="' . esc_url( wp_logout_url( $redirect ) ) . '">' . __( 'Log out' ) . '</a>';
   381 	}
   389 	}
   382 
   390 
   383 	if ( $echo ) {
   391 	if ( $display ) {
   384 		/**
   392 		/**
   385 		 * Filters the HTML output for the Log In/Log Out link.
   393 		 * Filters the HTML output for the Log In/Log Out link.
   386 		 *
   394 		 *
   387 		 * @since 1.5.0
   395 		 * @since 1.5.0
   388 		 *
   396 		 *
   481  * Provides a simple login form for use anywhere within WordPress.
   489  * Provides a simple login form for use anywhere within WordPress.
   482  *
   490  *
   483  * The login form HTML is echoed by default. Pass a false value for `$echo` to return it instead.
   491  * The login form HTML is echoed by default. Pass a false value for `$echo` to return it instead.
   484  *
   492  *
   485  * @since 3.0.0
   493  * @since 3.0.0
       
   494  * @since 6.6.0 Added `required_username` and `required_password` arguments.
   486  *
   495  *
   487  * @param array $args {
   496  * @param array $args {
   488  *     Optional. Array of options to control the form output. Default empty array.
   497  *     Optional. Array of options to control the form output. Default empty array.
   489  *
   498  *
   490  *     @type bool   $echo           Whether to display the login form or return the form HTML code.
   499  *     @type bool   $echo              Whether to display the login form or return the form HTML code.
   491  *                                  Default true (echo).
   500  *                                     Default true (echo).
   492  *     @type string $redirect       URL to redirect to. Must be absolute, as in "https://example.com/mypage/".
   501  *     @type string $redirect          URL to redirect to. Must be absolute, as in "https://example.com/mypage/".
   493  *                                  Default is to redirect back to the request URI.
   502  *                                     Default is to redirect back to the request URI.
   494  *     @type string $form_id        ID attribute value for the form. Default 'loginform'.
   503  *     @type string $form_id           ID attribute value for the form. Default 'loginform'.
   495  *     @type string $label_username Label for the username or email address field. Default 'Username or Email Address'.
   504  *     @type string $label_username    Label for the username or email address field. Default 'Username or Email Address'.
   496  *     @type string $label_password Label for the password field. Default 'Password'.
   505  *     @type string $label_password    Label for the password field. Default 'Password'.
   497  *     @type string $label_remember Label for the remember field. Default 'Remember Me'.
   506  *     @type string $label_remember    Label for the remember field. Default 'Remember Me'.
   498  *     @type string $label_log_in   Label for the submit button. Default 'Log In'.
   507  *     @type string $label_log_in      Label for the submit button. Default 'Log In'.
   499  *     @type string $id_username    ID attribute value for the username field. Default 'user_login'.
   508  *     @type string $id_username       ID attribute value for the username field. Default 'user_login'.
   500  *     @type string $id_password    ID attribute value for the password field. Default 'user_pass'.
   509  *     @type string $id_password       ID attribute value for the password field. Default 'user_pass'.
   501  *     @type string $id_remember    ID attribute value for the remember field. Default 'rememberme'.
   510  *     @type string $id_remember       ID attribute value for the remember field. Default 'rememberme'.
   502  *     @type string $id_submit      ID attribute value for the submit button. Default 'wp-submit'.
   511  *     @type string $id_submit         ID attribute value for the submit button. Default 'wp-submit'.
   503  *     @type bool   $remember       Whether to display the "rememberme" checkbox in the form.
   512  *     @type bool   $remember          Whether to display the "rememberme" checkbox in the form.
   504  *     @type string $value_username Default value for the username field. Default empty.
   513  *     @type string $value_username    Default value for the username field. Default empty.
   505  *     @type bool   $value_remember Whether the "Remember Me" checkbox should be checked by default.
   514  *     @type bool   $value_remember    Whether the "Remember Me" checkbox should be checked by default.
   506  *                                  Default false (unchecked).
   515  *                                     Default false (unchecked).
       
   516  *     @type bool   $required_username Whether the username field has the 'required' attribute.
       
   517  *                                     Default false.
       
   518  *     @type bool   $required_password Whether the password field has the 'required' attribute.
       
   519  *                                     Default false.
   507  *
   520  *
   508  * }
   521  * }
   509  * @return void|string Void if 'echo' argument is true, login form HTML if 'echo' is false.
   522  * @return void|string Void if 'echo' argument is true, login form HTML if 'echo' is false.
   510  */
   523  */
   511 function wp_login_form( $args = array() ) {
   524 function wp_login_form( $args = array() ) {
   512 	$defaults = array(
   525 	$defaults = array(
   513 		'echo'           => true,
   526 		'echo'              => true,
   514 		// Default 'redirect' value takes the user back to the request URI.
   527 		// Default 'redirect' value takes the user back to the request URI.
   515 		'redirect'       => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'],
   528 		'redirect'          => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'],
   516 		'form_id'        => 'loginform',
   529 		'form_id'           => 'loginform',
   517 		'label_username' => __( 'Username or Email Address' ),
   530 		'label_username'    => __( 'Username or Email Address' ),
   518 		'label_password' => __( 'Password' ),
   531 		'label_password'    => __( 'Password' ),
   519 		'label_remember' => __( 'Remember Me' ),
   532 		'label_remember'    => __( 'Remember Me' ),
   520 		'label_log_in'   => __( 'Log In' ),
   533 		'label_log_in'      => __( 'Log In' ),
   521 		'id_username'    => 'user_login',
   534 		'id_username'       => 'user_login',
   522 		'id_password'    => 'user_pass',
   535 		'id_password'       => 'user_pass',
   523 		'id_remember'    => 'rememberme',
   536 		'id_remember'       => 'rememberme',
   524 		'id_submit'      => 'wp-submit',
   537 		'id_submit'         => 'wp-submit',
   525 		'remember'       => true,
   538 		'remember'          => true,
   526 		'value_username' => '',
   539 		'value_username'    => '',
   527 		// Set 'value_remember' to true to default the "Remember me" checkbox to checked.
   540 		// Set 'value_remember' to true to default the "Remember me" checkbox to checked.
   528 		'value_remember' => false,
   541 		'value_remember'    => false,
       
   542 		// Set 'required_username' to true to add the required attribute to username field.
       
   543 		'required_username' => false,
       
   544 		// Set 'required_password' to true to add the required attribute to password field.
       
   545 		'required_password' => false,
   529 	);
   546 	);
   530 
   547 
   531 	/**
   548 	/**
   532 	 * Filters the default login form output arguments.
   549 	 * Filters the default login form output arguments.
   533 	 *
   550 	 *
   584 		) .
   601 		) .
   585 		$login_form_top .
   602 		$login_form_top .
   586 		sprintf(
   603 		sprintf(
   587 			'<p class="login-username">
   604 			'<p class="login-username">
   588 				<label for="%1$s">%2$s</label>
   605 				<label for="%1$s">%2$s</label>
   589 				<input type="text" name="log" id="%1$s" autocomplete="username" class="input" value="%3$s" size="20" />
   606 				<input type="text" name="log" id="%1$s" autocomplete="username" class="input" value="%3$s" size="20"%4$s />
   590 			</p>',
   607 			</p>',
   591 			esc_attr( $args['id_username'] ),
   608 			esc_attr( $args['id_username'] ),
   592 			esc_html( $args['label_username'] ),
   609 			esc_html( $args['label_username'] ),
   593 			esc_attr( $args['value_username'] )
   610 			esc_attr( $args['value_username'] ),
       
   611 			( $args['required_username'] ? ' required="required"' : '' )
   594 		) .
   612 		) .
   595 		sprintf(
   613 		sprintf(
   596 			'<p class="login-password">
   614 			'<p class="login-password">
   597 				<label for="%1$s">%2$s</label>
   615 				<label for="%1$s">%2$s</label>
   598 				<input type="password" name="pwd" id="%1$s" autocomplete="current-password" class="input" value="" size="20" />
   616 				<input type="password" name="pwd" id="%1$s" autocomplete="current-password" spellcheck="false" class="input" value="" size="20"%3$s />
   599 			</p>',
   617 			</p>',
   600 			esc_attr( $args['id_password'] ),
   618 			esc_attr( $args['id_password'] ),
   601 			esc_html( $args['label_password'] )
   619 			esc_html( $args['label_password'] ),
       
   620 			( $args['required_password'] ? ' required="required"' : '' )
   602 		) .
   621 		) .
   603 		$login_form_middle .
   622 		$login_form_middle .
   604 		( $args['remember'] ?
   623 		( $args['remember'] ?
   605 			sprintf(
   624 			sprintf(
   606 				'<p class="login-remember"><label><input name="rememberme" type="checkbox" id="%1$s" value="forever"%2$s /> %3$s</label></p>',
   625 				'<p class="login-remember"><label><input name="rememberme" type="checkbox" id="%1$s" value="forever"%2$s /> %3$s</label></p>',
   627 		return $form;
   646 		return $form;
   628 	}
   647 	}
   629 }
   648 }
   630 
   649 
   631 /**
   650 /**
   632  * Returns the URL that allows the user to retrieve the lost password
   651  * Returns the URL that allows the user to reset the lost password.
   633  *
   652  *
   634  * @since 2.8.0
   653  * @since 2.8.0
   635  *
   654  *
   636  * @param string $redirect Path to redirect to on login.
   655  * @param string $redirect Path to redirect to on login.
   637  * @return string Lost password URL.
   656  * @return string Lost password URL.
   644 	if ( ! empty( $redirect ) ) {
   663 	if ( ! empty( $redirect ) ) {
   645 		$args['redirect_to'] = urlencode( $redirect );
   664 		$args['redirect_to'] = urlencode( $redirect );
   646 	}
   665 	}
   647 
   666 
   648 	if ( is_multisite() ) {
   667 	if ( is_multisite() ) {
   649 		$blog_details  = get_blog_details();
   668 		$blog_details  = get_site();
   650 		$wp_login_path = $blog_details->path . 'wp-login.php';
   669 		$wp_login_path = $blog_details->path . 'wp-login.php';
   651 	} else {
   670 	} else {
   652 		$wp_login_path = 'wp-login.php';
   671 		$wp_login_path = 'wp-login.php';
   653 	}
   672 	}
   654 
   673 
   664 	 */
   683 	 */
   665 	return apply_filters( 'lostpassword_url', $lostpassword_url, $redirect );
   684 	return apply_filters( 'lostpassword_url', $lostpassword_url, $redirect );
   666 }
   685 }
   667 
   686 
   668 /**
   687 /**
   669  * Display the Registration or Admin link.
   688  * Displays the Registration or Admin link.
   670  *
   689  *
   671  * Display a link which allows the user to navigate to the registration page if
   690  * Display a link which allows the user to navigate to the registration page if
   672  * not logged in and registration is enabled or to the dashboard if logged in.
   691  * not logged in and registration is enabled or to the dashboard if logged in.
   673  *
   692  *
   674  * @since 1.5.0
   693  * @since 1.5.0
   675  *
   694  *
   676  * @param string $before Text to output before the link. Default `<li>`.
   695  * @param string $before  Text to output before the link. Default `<li>`.
   677  * @param string $after  Text to output after the link. Default `</li>`.
   696  * @param string $after   Text to output after the link. Default `</li>`.
   678  * @param bool   $echo   Default to echo and not return the link.
   697  * @param bool   $display Default to echo and not return the link.
   679  * @return void|string Void if `$echo` argument is true, registration or admin link
   698  * @return void|string Void if `$display` argument is true, registration or admin link
   680  *                     if `$echo` is false.
   699  *                     if `$display` is false.
   681  */
   700  */
   682 function wp_register( $before = '<li>', $after = '</li>', $echo = true ) {
   701 function wp_register( $before = '<li>', $after = '</li>', $display = true ) {
   683 	if ( ! is_user_logged_in() ) {
   702 	if ( ! is_user_logged_in() ) {
   684 		if ( get_option( 'users_can_register' ) ) {
   703 		if ( get_option( 'users_can_register' ) ) {
   685 			$link = $before . '<a href="' . esc_url( wp_registration_url() ) . '">' . __( 'Register' ) . '</a>' . $after;
   704 			$link = $before . '<a href="' . esc_url( wp_registration_url() ) . '">' . __( 'Register' ) . '</a>' . $after;
   686 		} else {
   705 		} else {
   687 			$link = '';
   706 			$link = '';
   702 	 *
   721 	 *
   703 	 * @param string $link The HTML code for the link to the Registration or Admin page.
   722 	 * @param string $link The HTML code for the link to the Registration or Admin page.
   704 	 */
   723 	 */
   705 	$link = apply_filters( 'register', $link );
   724 	$link = apply_filters( 'register', $link );
   706 
   725 
   707 	if ( $echo ) {
   726 	if ( $display ) {
   708 		echo $link;
   727 		echo $link;
   709 	} else {
   728 	} else {
   710 		return $link;
   729 		return $link;
   711 	}
   730 	}
   712 }
   731 }
   753  * - 'wpurl' - The WordPress address (URL) (set in Settings > General)
   772  * - 'wpurl' - The WordPress address (URL) (set in Settings > General)
   754  * - 'url' - The Site address (URL) (set in Settings > General)
   773  * - 'url' - The Site address (URL) (set in Settings > General)
   755  * - 'admin_email' - Admin email (set in Settings > General)
   774  * - 'admin_email' - Admin email (set in Settings > General)
   756  * - 'charset' - The "Encoding for pages and feeds"  (set in Settings > Reading)
   775  * - 'charset' - The "Encoding for pages and feeds"  (set in Settings > Reading)
   757  * - 'version' - The current WordPress version
   776  * - 'version' - The current WordPress version
   758  * - 'html_type' - The content-type (default: "text/html"). Themes and plugins
   777  * - 'html_type' - The Content-Type (default: "text/html"). Themes and plugins
   759  *   can override the default value using the {@see 'pre_option_html_type'} filter
   778  *   can override the default value using the {@see 'pre_option_html_type'} filter
   760  * - 'text_direction' - The text direction determined by the site's language. is_rtl()
   779  * - 'text_direction' - The text direction determined by the site's language. is_rtl()
   761  *   should be used instead
   780  *   should be used instead
   762  * - 'language' - Language code for the current site
   781  * - 'language' - Language code for the current site
   763  * - 'stylesheet_url' - URL to the stylesheet for the active theme. An active child theme
   782  * - 'stylesheet_url' - URL to the stylesheet for the active theme. An active child theme
   896 		default:
   915 		default:
   897 			$output = get_option( 'blogname' );
   916 			$output = get_option( 'blogname' );
   898 			break;
   917 			break;
   899 	}
   918 	}
   900 
   919 
   901 	$url = true;
       
   902 	if ( strpos( $show, 'url' ) === false &&
       
   903 		strpos( $show, 'directory' ) === false &&
       
   904 		strpos( $show, 'home' ) === false ) {
       
   905 		$url = false;
       
   906 	}
       
   907 
       
   908 	if ( 'display' === $filter ) {
   920 	if ( 'display' === $filter ) {
   909 		if ( $url ) {
   921 		if (
       
   922 			str_contains( $show, 'url' )
       
   923 			|| str_contains( $show, 'directory' )
       
   924 			|| str_contains( $show, 'home' )
       
   925 		) {
   910 			/**
   926 			/**
   911 			 * Filters the URL returned by get_bloginfo().
   927 			 * Filters the URL returned by get_bloginfo().
   912 			 *
   928 			 *
   913 			 * @since 2.0.5
   929 			 * @since 2.0.5
   914 			 *
   930 			 *
   948 	if ( is_multisite() && ! empty( $blog_id ) && get_current_blog_id() !== (int) $blog_id ) {
   964 	if ( is_multisite() && ! empty( $blog_id ) && get_current_blog_id() !== (int) $blog_id ) {
   949 		switch_to_blog( $blog_id );
   965 		switch_to_blog( $blog_id );
   950 		$switched_blog = true;
   966 		$switched_blog = true;
   951 	}
   967 	}
   952 
   968 
   953 	$site_icon_id = get_option( 'site_icon' );
   969 	$site_icon_id = (int) get_option( 'site_icon' );
   954 
   970 
   955 	if ( $site_icon_id ) {
   971 	if ( $site_icon_id ) {
   956 		if ( $size >= 512 ) {
   972 		if ( $size >= 512 ) {
   957 			$size_data = 'full';
   973 			$size_data = 'full';
   958 		} else {
   974 		} else {
   989 function site_icon_url( $size = 512, $url = '', $blog_id = 0 ) {
  1005 function site_icon_url( $size = 512, $url = '', $blog_id = 0 ) {
   990 	echo esc_url( get_site_icon_url( $size, $url, $blog_id ) );
  1006 	echo esc_url( get_site_icon_url( $size, $url, $blog_id ) );
   991 }
  1007 }
   992 
  1008 
   993 /**
  1009 /**
   994  * Whether the site has a Site Icon.
  1010  * Determines whether the site has a Site Icon.
   995  *
  1011  *
   996  * @since 4.3.0
  1012  * @since 4.3.0
   997  *
  1013  *
   998  * @param int $blog_id Optional. ID of the blog in question. Default current blog.
  1014  * @param int $blog_id Optional. ID of the blog in question. Default current blog.
   999  * @return bool Whether the site has a site icon or not.
  1015  * @return bool Whether the site has a site icon or not.
  1017 		switch_to_blog( $blog_id );
  1033 		switch_to_blog( $blog_id );
  1018 		$switched_blog = true;
  1034 		$switched_blog = true;
  1019 	}
  1035 	}
  1020 
  1036 
  1021 	$custom_logo_id = get_theme_mod( 'custom_logo' );
  1037 	$custom_logo_id = get_theme_mod( 'custom_logo' );
       
  1038 	$is_image       = ( $custom_logo_id ) ? wp_attachment_is_image( $custom_logo_id ) : false;
  1022 
  1039 
  1023 	if ( $switched_blog ) {
  1040 	if ( $switched_blog ) {
  1024 		restore_current_blog();
  1041 		restore_current_blog();
  1025 	}
  1042 	}
  1026 
  1043 
  1027 	return (bool) $custom_logo_id;
  1044 	return $is_image;
  1028 }
  1045 }
  1029 
  1046 
  1030 /**
  1047 /**
  1031  * Returns a custom logo, linked to home unless the theme supports removing the link on the home page.
  1048  * Returns a custom logo, linked to home unless the theme supports removing the link on the home page.
  1032  *
  1049  *
  1045 	if ( is_multisite() && ! empty( $blog_id ) && get_current_blog_id() !== (int) $blog_id ) {
  1062 	if ( is_multisite() && ! empty( $blog_id ) && get_current_blog_id() !== (int) $blog_id ) {
  1046 		switch_to_blog( $blog_id );
  1063 		switch_to_blog( $blog_id );
  1047 		$switched_blog = true;
  1064 		$switched_blog = true;
  1048 	}
  1065 	}
  1049 
  1066 
  1050 	$custom_logo_id = get_theme_mod( 'custom_logo' );
       
  1051 
       
  1052 	// We have a logo. Logo is go.
  1067 	// We have a logo. Logo is go.
  1053 	if ( $custom_logo_id ) {
  1068 	if ( has_custom_logo() ) {
       
  1069 		$custom_logo_id   = get_theme_mod( 'custom_logo' );
  1054 		$custom_logo_attr = array(
  1070 		$custom_logo_attr = array(
  1055 			'class'   => 'custom-logo',
  1071 			'class'   => 'custom-logo',
  1056 			'loading' => false,
  1072 			'loading' => false,
  1057 		);
  1073 		);
  1058 
  1074 
  1090 		 * If the alt attribute is not empty, there's no need to explicitly pass it
  1106 		 * If the alt attribute is not empty, there's no need to explicitly pass it
  1091 		 * because wp_get_attachment_image() already adds the alt attribute.
  1107 		 * because wp_get_attachment_image() already adds the alt attribute.
  1092 		 */
  1108 		 */
  1093 		$image = wp_get_attachment_image( $custom_logo_id, 'full', false, $custom_logo_attr );
  1109 		$image = wp_get_attachment_image( $custom_logo_id, 'full', false, $custom_logo_attr );
  1094 
  1110 
  1095 		if ( $unlink_homepage_logo && is_front_page() && ! is_paged() ) {
  1111 		// Check that we have a proper HTML img element.
  1096 			// If on the home page, don't link the logo to home.
  1112 		if ( $image ) {
  1097 			$html = sprintf(
  1113 
  1098 				'<span class="custom-logo-link">%1$s</span>',
  1114 			if ( $unlink_homepage_logo && is_front_page() && ! is_paged() ) {
  1099 				$image
  1115 				// If on the home page, don't link the logo to home.
  1100 			);
  1116 				$html = sprintf(
  1101 		} else {
  1117 					'<span class="custom-logo-link">%1$s</span>',
  1102 			$aria_current = is_front_page() && ! is_paged() ? ' aria-current="page"' : '';
  1118 					$image
  1103 
  1119 				);
  1104 			$html = sprintf(
  1120 			} else {
  1105 				'<a href="%1$s" class="custom-logo-link" rel="home"%2$s>%3$s</a>',
  1121 				$aria_current = is_front_page() && ! is_paged() ? ' aria-current="page"' : '';
  1106 				esc_url( home_url( '/' ) ),
  1122 
  1107 				$aria_current,
  1123 				$html = sprintf(
  1108 				$image
  1124 					'<a href="%1$s" class="custom-logo-link" rel="home"%2$s>%3$s</a>',
  1109 			);
  1125 					esc_url( home_url( '/' ) ),
       
  1126 					$aria_current,
       
  1127 					$image
       
  1128 				);
       
  1129 			}
  1110 		}
  1130 		}
  1111 	} elseif ( is_customize_preview() ) {
  1131 	} elseif ( is_customize_preview() ) {
  1112 		// If no logo is set but we're in the Customizer, leave a placeholder (needed for the live preview).
  1132 		// If no logo is set but we're in the Customizer, leave a placeholder (needed for the live preview).
  1113 		$html = sprintf(
  1133 		$html = sprintf(
  1114 			'<a href="%1$s" class="custom-logo-link" style="display:none;"><img class="custom-logo" alt="" /></a>',
  1134 			'<a href="%1$s" class="custom-logo-link" style="display:none;"><img class="custom-logo" alt="" /></a>',
  1291 
  1311 
  1292 	echo '<title>' . wp_get_document_title() . '</title>' . "\n";
  1312 	echo '<title>' . wp_get_document_title() . '</title>' . "\n";
  1293 }
  1313 }
  1294 
  1314 
  1295 /**
  1315 /**
  1296  * Display or retrieve page title for all areas of blog.
  1316  * Displays or retrieves page title for all areas of blog.
  1297  *
  1317  *
  1298  * By default, the page title will display the separator before the page title,
  1318  * By default, the page title will display the separator before the page title,
  1299  * so that the blog title will be before the page title. This is not good for
  1319  * so that the blog title will be before the page title. This is not good for
  1300  * title display, since the blog title shows up on most tabs and not what is
  1320  * title display, since the blog title shows up on most tabs and not what is
  1301  * important, which is the page that the user is looking at.
  1321  * important, which is the page that the user is looking at.
  1312  * @global WP_Locale $wp_locale WordPress date and time locale object.
  1332  * @global WP_Locale $wp_locale WordPress date and time locale object.
  1313  *
  1333  *
  1314  * @param string $sep         Optional. How to separate the various items within the page title.
  1334  * @param string $sep         Optional. How to separate the various items within the page title.
  1315  *                            Default '&raquo;'.
  1335  *                            Default '&raquo;'.
  1316  * @param bool   $display     Optional. Whether to display or retrieve title. Default true.
  1336  * @param bool   $display     Optional. Whether to display or retrieve title. Default true.
  1317  * @param string $seplocation Optional. Location of the separator ('left' or 'right').
  1337  * @param string $seplocation Optional. Location of the separator (either 'left' or 'right').
  1318  * @return string|void String when `$display` is false, nothing otherwise.
  1338  * @return string|void String when `$display` is false, nothing otherwise.
  1319  */
  1339  */
  1320 function wp_title( $sep = '&raquo;', $display = true, $seplocation = '' ) {
  1340 function wp_title( $sep = '&raquo;', $display = true, $seplocation = '' ) {
  1321 	global $wp_locale;
  1341 	global $wp_locale;
  1322 
  1342 
  1432 	 *
  1452 	 *
  1433 	 * @since 2.0.0
  1453 	 * @since 2.0.0
  1434 	 *
  1454 	 *
  1435 	 * @param string $title       Page title.
  1455 	 * @param string $title       Page title.
  1436 	 * @param string $sep         Title separator.
  1456 	 * @param string $sep         Title separator.
  1437 	 * @param string $seplocation Location of the separator ('left' or 'right').
  1457 	 * @param string $seplocation Location of the separator (either 'left' or 'right').
  1438 	 */
  1458 	 */
  1439 	$title = apply_filters( 'wp_title', $title, $sep, $seplocation );
  1459 	$title = apply_filters( 'wp_title', $title, $sep, $seplocation );
  1440 
  1460 
  1441 	// Send it out.
  1461 	// Send it out.
  1442 	if ( $display ) {
  1462 	if ( $display ) {
  1445 		return $title;
  1465 		return $title;
  1446 	}
  1466 	}
  1447 }
  1467 }
  1448 
  1468 
  1449 /**
  1469 /**
  1450  * Display or retrieve page title for post.
  1470  * Displays or retrieves page title for post.
  1451  *
  1471  *
  1452  * This is optimized for single.php template file for displaying the post title.
  1472  * This is optimized for single.php template file for displaying the post title.
  1453  *
  1473  *
  1454  * It does not support placing the separator after the title, but by leaving the
  1474  * It does not support placing the separator after the title, but by leaving the
  1455  * prefix parameter empty, you can set the title separator manually. The prefix
  1475  * prefix parameter empty, you can set the title separator manually. The prefix
  1484 		return $prefix . $title;
  1504 		return $prefix . $title;
  1485 	}
  1505 	}
  1486 }
  1506 }
  1487 
  1507 
  1488 /**
  1508 /**
  1489  * Display or retrieve title for a post type archive.
  1509  * Displays or retrieves title for a post type archive.
  1490  *
  1510  *
  1491  * This is optimized for archive.php and archive-{$post_type}.php template files
  1511  * This is optimized for archive.php and archive-{$post_type}.php template files
  1492  * for displaying the title of the post type.
  1512  * for displaying the title of the post type.
  1493  *
  1513  *
  1494  * @since 3.1.0
  1514  * @since 3.1.0
  1525 		return $prefix . $title;
  1545 		return $prefix . $title;
  1526 	}
  1546 	}
  1527 }
  1547 }
  1528 
  1548 
  1529 /**
  1549 /**
  1530  * Display or retrieve page title for category archive.
  1550  * Displays or retrieves page title for category archive.
  1531  *
  1551  *
  1532  * Useful for category template files for displaying the category page title.
  1552  * Useful for category template files for displaying the category page title.
  1533  * The prefix does not automatically place a space between the prefix, so if
  1553  * The prefix does not automatically place a space between the prefix, so if
  1534  * there should be a space, the parameter value will need to have it at the end.
  1554  * there should be a space, the parameter value will need to have it at the end.
  1535  *
  1555  *
  1542 function single_cat_title( $prefix = '', $display = true ) {
  1562 function single_cat_title( $prefix = '', $display = true ) {
  1543 	return single_term_title( $prefix, $display );
  1563 	return single_term_title( $prefix, $display );
  1544 }
  1564 }
  1545 
  1565 
  1546 /**
  1566 /**
  1547  * Display or retrieve page title for tag post archive.
  1567  * Displays or retrieves page title for tag post archive.
  1548  *
  1568  *
  1549  * Useful for tag template files for displaying the tag page title. The prefix
  1569  * Useful for tag template files for displaying the tag page title. The prefix
  1550  * does not automatically place a space between the prefix, so if there should
  1570  * does not automatically place a space between the prefix, so if there should
  1551  * be a space, the parameter value will need to have it at the end.
  1571  * be a space, the parameter value will need to have it at the end.
  1552  *
  1572  *
  1559 function single_tag_title( $prefix = '', $display = true ) {
  1579 function single_tag_title( $prefix = '', $display = true ) {
  1560 	return single_term_title( $prefix, $display );
  1580 	return single_term_title( $prefix, $display );
  1561 }
  1581 }
  1562 
  1582 
  1563 /**
  1583 /**
  1564  * Display or retrieve page title for taxonomy term archive.
  1584  * Displays or retrieves page title for taxonomy term archive.
  1565  *
  1585  *
  1566  * Useful for taxonomy term template files for displaying the taxonomy term page title.
  1586  * Useful for taxonomy term template files for displaying the taxonomy term page title.
  1567  * The prefix does not automatically place a space between the prefix, so if there should
  1587  * The prefix does not automatically place a space between the prefix, so if there should
  1568  * be a space, the parameter value will need to have it at the end.
  1588  * be a space, the parameter value will need to have it at the end.
  1569  *
  1589  *
  1621 		return $prefix . $term_name;
  1641 		return $prefix . $term_name;
  1622 	}
  1642 	}
  1623 }
  1643 }
  1624 
  1644 
  1625 /**
  1645 /**
  1626  * Display or retrieve page title for post archive based on date.
  1646  * Displays or retrieves page title for post archive based on date.
  1627  *
  1647  *
  1628  * Useful for when the template only needs to display the month and year,
  1648  * Useful for when the template only needs to display the month and year,
  1629  * if either are available. The prefix does not automatically place a space
  1649  * if either are available. The prefix does not automatically place a space
  1630  * between the prefix, so if there should be a space, the parameter value
  1650  * between the prefix, so if there should be a space, the parameter value
  1631  * will need to have it at the end.
  1651  * will need to have it at the end.
  1664 	}
  1684 	}
  1665 	echo $result;
  1685 	echo $result;
  1666 }
  1686 }
  1667 
  1687 
  1668 /**
  1688 /**
  1669  * Display the archive title based on the queried object.
  1689  * Displays the archive title based on the queried object.
  1670  *
  1690  *
  1671  * @since 4.1.0
  1691  * @since 4.1.0
  1672  *
  1692  *
  1673  * @see get_the_archive_title()
  1693  * @see get_the_archive_title()
  1674  *
  1694  *
  1682 		echo $before . $title . $after;
  1702 		echo $before . $title . $after;
  1683 	}
  1703 	}
  1684 }
  1704 }
  1685 
  1705 
  1686 /**
  1706 /**
  1687  * Retrieve the archive title based on the queried object.
  1707  * Retrieves the archive title based on the queried object.
  1688  *
  1708  *
  1689  * @since 4.1.0
  1709  * @since 4.1.0
  1690  * @since 5.5.0 The title part is wrapped in a `<span>` element.
  1710  * @since 5.5.0 The title part is wrapped in a `<span>` element.
  1691  *
  1711  *
  1692  * @return string Archive title.
  1712  * @return string Archive title.
  1703 		$prefix = _x( 'Tag:', 'tag archive title prefix' );
  1723 		$prefix = _x( 'Tag:', 'tag archive title prefix' );
  1704 	} elseif ( is_author() ) {
  1724 	} elseif ( is_author() ) {
  1705 		$title  = get_the_author();
  1725 		$title  = get_the_author();
  1706 		$prefix = _x( 'Author:', 'author archive title prefix' );
  1726 		$prefix = _x( 'Author:', 'author archive title prefix' );
  1707 	} elseif ( is_year() ) {
  1727 	} elseif ( is_year() ) {
       
  1728 		/* translators: See https://www.php.net/manual/datetime.format.php */
  1708 		$title  = get_the_date( _x( 'Y', 'yearly archives date format' ) );
  1729 		$title  = get_the_date( _x( 'Y', 'yearly archives date format' ) );
  1709 		$prefix = _x( 'Year:', 'date archive title prefix' );
  1730 		$prefix = _x( 'Year:', 'date archive title prefix' );
  1710 	} elseif ( is_month() ) {
  1731 	} elseif ( is_month() ) {
       
  1732 		/* translators: See https://www.php.net/manual/datetime.format.php */
  1711 		$title  = get_the_date( _x( 'F Y', 'monthly archives date format' ) );
  1733 		$title  = get_the_date( _x( 'F Y', 'monthly archives date format' ) );
  1712 		$prefix = _x( 'Month:', 'date archive title prefix' );
  1734 		$prefix = _x( 'Month:', 'date archive title prefix' );
  1713 	} elseif ( is_day() ) {
  1735 	} elseif ( is_day() ) {
       
  1736 		/* translators: See https://www.php.net/manual/datetime.format.php */
  1714 		$title  = get_the_date( _x( 'F j, Y', 'daily archives date format' ) );
  1737 		$title  = get_the_date( _x( 'F j, Y', 'daily archives date format' ) );
  1715 		$prefix = _x( 'Day:', 'date archive title prefix' );
  1738 		$prefix = _x( 'Day:', 'date archive title prefix' );
  1716 	} elseif ( is_tax( 'post_format' ) ) {
  1739 	} elseif ( is_tax( 'post_format' ) ) {
  1717 		if ( is_tax( 'post_format', 'post-format-aside' ) ) {
  1740 		if ( is_tax( 'post_format', 'post-format-aside' ) ) {
  1718 			$title = _x( 'Asides', 'post format archive title' );
  1741 			$title = _x( 'Asides', 'post format archive title' );
  1780 	 */
  1803 	 */
  1781 	return apply_filters( 'get_the_archive_title', $title, $original_title, $prefix );
  1804 	return apply_filters( 'get_the_archive_title', $title, $original_title, $prefix );
  1782 }
  1805 }
  1783 
  1806 
  1784 /**
  1807 /**
  1785  * Display category, tag, term, or author description.
  1808  * Displays category, tag, term, or author description.
  1786  *
  1809  *
  1787  * @since 4.1.0
  1810  * @since 4.1.0
  1788  *
  1811  *
  1789  * @see get_the_archive_description()
  1812  * @see get_the_archive_description()
  1790  *
  1813  *
  1861 	 */
  1884 	 */
  1862 	return apply_filters( 'get_the_post_type_description', $description, $post_type_obj );
  1885 	return apply_filters( 'get_the_post_type_description', $description, $post_type_obj );
  1863 }
  1886 }
  1864 
  1887 
  1865 /**
  1888 /**
  1866  * Retrieve archive link content based on predefined or custom code.
  1889  * Retrieves archive link content based on predefined or custom code.
  1867  *
  1890  *
  1868  * The format can be one of four styles. The 'link' for head element, 'option'
  1891  * The format can be one of four styles. The 'link' for head element, 'option'
  1869  * for use in the select element, 'html' for use in list (either ol or ul HTML
  1892  * for use in the select element, 'html' for use in list (either ol or ul HTML
  1870  * elements). Custom content is also supported using the before and after
  1893  * elements). Custom content is also supported using the before and after
  1871  * parameters.
  1894  * parameters.
  1930 	 */
  1953 	 */
  1931 	return apply_filters( 'get_archives_link', $link_html, $url, $text, $format, $before, $after, $selected );
  1954 	return apply_filters( 'get_archives_link', $link_html, $url, $text, $format, $before, $after, $selected );
  1932 }
  1955 }
  1933 
  1956 
  1934 /**
  1957 /**
  1935  * Display archive links based on type and format.
  1958  * Displays archive links based on type and format.
  1936  *
  1959  *
  1937  * @since 1.2.0
  1960  * @since 1.2.0
  1938  * @since 4.4.0 The `$post_type` argument was added.
  1961  * @since 4.4.0 The `$post_type` argument was added.
  1939  * @since 5.2.0 The `$year`, `$monthnum`, `$day`, and `$w` arguments were added.
  1962  * @since 5.2.0 The `$year`, `$monthnum`, `$day`, and `$w` arguments were added.
  1940  *
  1963  *
  2046 
  2069 
  2047 	if ( 'monthly' === $parsed_args['type'] ) {
  2070 	if ( 'monthly' === $parsed_args['type'] ) {
  2048 		$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";
  2071 		$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";
  2049 		$key     = md5( $query );
  2072 		$key     = md5( $query );
  2050 		$key     = "wp_get_archives:$key:$last_changed";
  2073 		$key     = "wp_get_archives:$key:$last_changed";
  2051 		$results = wp_cache_get( $key, 'posts' );
  2074 		$results = wp_cache_get( $key, 'post-queries' );
  2052 		if ( ! $results ) {
  2075 		if ( ! $results ) {
  2053 			$results = $wpdb->get_results( $query );
  2076 			$results = $wpdb->get_results( $query );
  2054 			wp_cache_set( $key, $results, 'posts' );
  2077 			wp_cache_set( $key, $results, 'post-queries' );
  2055 		}
  2078 		}
  2056 		if ( $results ) {
  2079 		if ( $results ) {
  2057 			$after = $parsed_args['after'];
  2080 			$after = $parsed_args['after'];
  2058 			foreach ( (array) $results as $result ) {
  2081 			foreach ( (array) $results as $result ) {
  2059 				$url = get_month_link( $result->year, $result->month );
  2082 				$url = get_month_link( $result->year, $result->month );
  2071 		}
  2094 		}
  2072 	} elseif ( 'yearly' === $parsed_args['type'] ) {
  2095 	} elseif ( 'yearly' === $parsed_args['type'] ) {
  2073 		$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";
  2096 		$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";
  2074 		$key     = md5( $query );
  2097 		$key     = md5( $query );
  2075 		$key     = "wp_get_archives:$key:$last_changed";
  2098 		$key     = "wp_get_archives:$key:$last_changed";
  2076 		$results = wp_cache_get( $key, 'posts' );
  2099 		$results = wp_cache_get( $key, 'post-queries' );
  2077 		if ( ! $results ) {
  2100 		if ( ! $results ) {
  2078 			$results = $wpdb->get_results( $query );
  2101 			$results = $wpdb->get_results( $query );
  2079 			wp_cache_set( $key, $results, 'posts' );
  2102 			wp_cache_set( $key, $results, 'post-queries' );
  2080 		}
  2103 		}
  2081 		if ( $results ) {
  2104 		if ( $results ) {
  2082 			$after = $parsed_args['after'];
  2105 			$after = $parsed_args['after'];
  2083 			foreach ( (array) $results as $result ) {
  2106 			foreach ( (array) $results as $result ) {
  2084 				$url = get_year_link( $result->year );
  2107 				$url = get_year_link( $result->year );
  2095 		}
  2118 		}
  2096 	} elseif ( 'daily' === $parsed_args['type'] ) {
  2119 	} elseif ( 'daily' === $parsed_args['type'] ) {
  2097 		$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";
  2120 		$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";
  2098 		$key     = md5( $query );
  2121 		$key     = md5( $query );
  2099 		$key     = "wp_get_archives:$key:$last_changed";
  2122 		$key     = "wp_get_archives:$key:$last_changed";
  2100 		$results = wp_cache_get( $key, 'posts' );
  2123 		$results = wp_cache_get( $key, 'post-queries' );
  2101 		if ( ! $results ) {
  2124 		if ( ! $results ) {
  2102 			$results = $wpdb->get_results( $query );
  2125 			$results = $wpdb->get_results( $query );
  2103 			wp_cache_set( $key, $results, 'posts' );
  2126 			wp_cache_set( $key, $results, 'post-queries' );
  2104 		}
  2127 		}
  2105 		if ( $results ) {
  2128 		if ( $results ) {
  2106 			$after = $parsed_args['after'];
  2129 			$after = $parsed_args['after'];
  2107 			foreach ( (array) $results as $result ) {
  2130 			foreach ( (array) $results as $result ) {
  2108 				$url = get_day_link( $result->year, $result->month, $result->dayofmonth );
  2131 				$url = get_day_link( $result->year, $result->month, $result->dayofmonth );
  2121 	} elseif ( 'weekly' === $parsed_args['type'] ) {
  2144 	} elseif ( 'weekly' === $parsed_args['type'] ) {
  2122 		$week    = _wp_mysql_week( '`post_date`' );
  2145 		$week    = _wp_mysql_week( '`post_date`' );
  2123 		$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";
  2146 		$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";
  2124 		$key     = md5( $query );
  2147 		$key     = md5( $query );
  2125 		$key     = "wp_get_archives:$key:$last_changed";
  2148 		$key     = "wp_get_archives:$key:$last_changed";
  2126 		$results = wp_cache_get( $key, 'posts' );
  2149 		$results = wp_cache_get( $key, 'post-queries' );
  2127 		if ( ! $results ) {
  2150 		if ( ! $results ) {
  2128 			$results = $wpdb->get_results( $query );
  2151 			$results = $wpdb->get_results( $query );
  2129 			wp_cache_set( $key, $results, 'posts' );
  2152 			wp_cache_set( $key, $results, 'post-queries' );
  2130 		}
  2153 		}
  2131 		$arc_w_last = '';
  2154 		$arc_w_last = '';
  2132 		if ( $results ) {
  2155 		if ( $results ) {
  2133 			$after = $parsed_args['after'];
  2156 			$after = $parsed_args['after'];
  2134 			foreach ( (array) $results as $result ) {
  2157 			foreach ( (array) $results as $result ) {
  2160 	} elseif ( ( 'postbypost' === $parsed_args['type'] ) || ( 'alpha' === $parsed_args['type'] ) ) {
  2183 	} elseif ( ( 'postbypost' === $parsed_args['type'] ) || ( 'alpha' === $parsed_args['type'] ) ) {
  2161 		$orderby = ( 'alpha' === $parsed_args['type'] ) ? 'post_title ASC ' : 'post_date DESC, ID DESC ';
  2184 		$orderby = ( 'alpha' === $parsed_args['type'] ) ? 'post_title ASC ' : 'post_date DESC, ID DESC ';
  2162 		$query   = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit";
  2185 		$query   = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit";
  2163 		$key     = md5( $query );
  2186 		$key     = md5( $query );
  2164 		$key     = "wp_get_archives:$key:$last_changed";
  2187 		$key     = "wp_get_archives:$key:$last_changed";
  2165 		$results = wp_cache_get( $key, 'posts' );
  2188 		$results = wp_cache_get( $key, 'post-queries' );
  2166 		if ( ! $results ) {
  2189 		if ( ! $results ) {
  2167 			$results = $wpdb->get_results( $query );
  2190 			$results = $wpdb->get_results( $query );
  2168 			wp_cache_set( $key, $results, 'posts' );
  2191 			wp_cache_set( $key, $results, 'post-queries' );
  2169 		}
  2192 		}
  2170 		if ( $results ) {
  2193 		if ( $results ) {
  2171 			foreach ( (array) $results as $result ) {
  2194 			foreach ( (array) $results as $result ) {
  2172 				if ( '0000-00-00 00:00:00' !== $result->post_date ) {
  2195 				if ( '0000-00-00 00:00:00' !== $result->post_date ) {
  2173 					$url = get_permalink( $result );
  2196 					$url = get_permalink( $result );
  2190 		return $output;
  2213 		return $output;
  2191 	}
  2214 	}
  2192 }
  2215 }
  2193 
  2216 
  2194 /**
  2217 /**
  2195  * Get number of days since the start of the week.
  2218  * Gets number of days since the start of the week.
  2196  *
  2219  *
  2197  * @since 1.5.0
  2220  * @since 1.5.0
  2198  *
  2221  *
  2199  * @param int $num Number of day.
  2222  * @param int $num Number of day.
  2200  * @return float Days since the start of the week.
  2223  * @return float Days since the start of the week.
  2203 	$base = 7;
  2226 	$base = 7;
  2204 	return ( $num - $base * floor( $num / $base ) );
  2227 	return ( $num - $base * floor( $num / $base ) );
  2205 }
  2228 }
  2206 
  2229 
  2207 /**
  2230 /**
  2208  * Display calendar with days that have posts as links.
  2231  * Displays calendar with days that have posts as links.
  2209  *
  2232  *
  2210  * The calendar is cached, which will be retrieved, if it exists. If there are
  2233  * The calendar is cached, which will be retrieved, if it exists. If there are
  2211  * no posts for the month, then it will not be displayed.
  2234  * no posts for the month, then it will not be displayed.
  2212  *
  2235  *
  2213  * @since 1.0.0
  2236  * @since 1.0.0
  2218  * @global int       $year
  2241  * @global int       $year
  2219  * @global WP_Locale $wp_locale WordPress date and time locale object.
  2242  * @global WP_Locale $wp_locale WordPress date and time locale object.
  2220  * @global array     $posts
  2243  * @global array     $posts
  2221  *
  2244  *
  2222  * @param bool $initial Optional. Whether to use initial calendar names. Default true.
  2245  * @param bool $initial Optional. Whether to use initial calendar names. Default true.
  2223  * @param bool $echo    Optional. Whether to display the calendar output. Default true.
  2246  * @param bool $display Optional. Whether to display the calendar output. Default true.
  2224  * @return void|string Void if `$echo` argument is true, calendar HTML if `$echo` is false.
  2247  * @return void|string Void if `$display` argument is true, calendar HTML if `$display` is false.
  2225  */
  2248  */
  2226 function get_calendar( $initial = true, $echo = true ) {
  2249 function get_calendar( $initial = true, $display = true ) {
  2227 	global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
  2250 	global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
  2228 
  2251 
  2229 	$key   = md5( $m . $monthnum . $year );
  2252 	$key   = md5( $m . $monthnum . $year );
  2230 	$cache = wp_cache_get( 'get_calendar', 'calendar' );
  2253 	$cache = wp_cache_get( 'get_calendar', 'calendar' );
  2231 
  2254 
  2232 	if ( $cache && is_array( $cache ) && isset( $cache[ $key ] ) ) {
  2255 	if ( $cache && is_array( $cache ) && isset( $cache[ $key ] ) ) {
  2233 		/** This filter is documented in wp-includes/general-template.php */
  2256 		/** This filter is documented in wp-includes/general-template.php */
  2234 		$output = apply_filters( 'get_calendar', $cache[ $key ] );
  2257 		$output = apply_filters( 'get_calendar', $cache[ $key ] );
  2235 
  2258 
  2236 		if ( $echo ) {
  2259 		if ( $display ) {
  2237 			echo $output;
  2260 			echo $output;
  2238 			return;
  2261 			return;
  2239 		}
  2262 		}
  2240 
  2263 
  2241 		return $output;
  2264 		return $output;
  2290 	$previous = $wpdb->get_row(
  2313 	$previous = $wpdb->get_row(
  2291 		"SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
  2314 		"SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
  2292 		FROM $wpdb->posts
  2315 		FROM $wpdb->posts
  2293 		WHERE post_date < '$thisyear-$thismonth-01'
  2316 		WHERE post_date < '$thisyear-$thismonth-01'
  2294 		AND post_type = 'post' AND post_status = 'publish'
  2317 		AND post_type = 'post' AND post_status = 'publish'
  2295 			ORDER BY post_date DESC
  2318 		ORDER BY post_date DESC
  2296 			LIMIT 1"
  2319 		LIMIT 1"
  2297 	);
  2320 	);
  2298 	$next     = $wpdb->get_row(
  2321 	$next     = $wpdb->get_row(
  2299 		"SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
  2322 		"SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
  2300 		FROM $wpdb->posts
  2323 		FROM $wpdb->posts
  2301 		WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59'
  2324 		WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59'
  2302 		AND post_type = 'post' AND post_status = 'publish'
  2325 		AND post_type = 'post' AND post_status = 'publish'
  2303 			ORDER BY post_date ASC
  2326 		ORDER BY post_date ASC
  2304 			LIMIT 1"
  2327 		LIMIT 1"
  2305 	);
  2328 	);
  2306 
  2329 
  2307 	/* translators: Calendar caption: 1: Month name, 2: 4-digit year. */
  2330 	/* translators: Calendar caption: 1: Month name, 2: 4-digit year. */
  2308 	$calendar_caption = _x( '%1$s %2$s', 'calendar caption' );
  2331 	$calendar_caption = _x( '%1$s %2$s', 'calendar caption' );
  2309 	$calendar_output  = '<table id="wp-calendar" class="wp-calendar-table">
  2332 	$calendar_output  = '<table id="wp-calendar" class="wp-calendar-table">
  2428 	</nav>';
  2451 	</nav>';
  2429 
  2452 
  2430 	$cache[ $key ] = $calendar_output;
  2453 	$cache[ $key ] = $calendar_output;
  2431 	wp_cache_set( 'get_calendar', $cache, 'calendar' );
  2454 	wp_cache_set( 'get_calendar', $cache, 'calendar' );
  2432 
  2455 
  2433 	if ( $echo ) {
  2456 	if ( $display ) {
  2434 		/**
  2457 		/**
  2435 		 * Filters the HTML calendar output.
  2458 		 * Filters the HTML calendar output.
  2436 		 *
  2459 		 *
  2437 		 * @since 3.0.0
  2460 		 * @since 3.0.0
  2438 		 *
  2461 		 *
  2444 	/** This filter is documented in wp-includes/general-template.php */
  2467 	/** This filter is documented in wp-includes/general-template.php */
  2445 	return apply_filters( 'get_calendar', $calendar_output );
  2468 	return apply_filters( 'get_calendar', $calendar_output );
  2446 }
  2469 }
  2447 
  2470 
  2448 /**
  2471 /**
  2449  * Purge the cached results of get_calendar.
  2472  * Purges the cached results of get_calendar.
  2450  *
  2473  *
  2451  * @see get_calendar()
  2474  * @see get_calendar()
  2452  * @since 2.1.0
  2475  * @since 2.1.0
  2453  */
  2476  */
  2454 function delete_get_calendar_cache() {
  2477 function delete_get_calendar_cache() {
  2455 	wp_cache_delete( 'get_calendar', 'calendar' );
  2478 	wp_cache_delete( 'get_calendar', 'calendar' );
  2456 }
  2479 }
  2457 
  2480 
  2458 /**
  2481 /**
  2459  * Display all of the allowed tags in HTML format with attributes.
  2482  * Displays all of the allowed tags in HTML format with attributes.
  2460  *
  2483  *
  2461  * This is useful for displaying in the comment area, which elements and
  2484  * This is useful for displaying in the comment area, which elements and
  2462  * attributes are supported. As well as any plugins which want to display it.
  2485  * attributes are supported. As well as any plugins which want to display it.
  2463  *
  2486  *
  2464  * @since 1.0.1
  2487  * @since 1.0.1
       
  2488  * @since 4.4.0 No longer used in core.
  2465  *
  2489  *
  2466  * @global array $allowedtags
  2490  * @global array $allowedtags
  2467  *
  2491  *
  2468  * @return string HTML allowed tags entity encoded.
  2492  * @return string HTML allowed tags entity encoded.
  2469  */
  2493  */
  2492 function the_date_xml() {
  2516 function the_date_xml() {
  2493 	echo mysql2date( 'Y-m-d', get_post()->post_date, false );
  2517 	echo mysql2date( 'Y-m-d', get_post()->post_date, false );
  2494 }
  2518 }
  2495 
  2519 
  2496 /**
  2520 /**
  2497  * Display or Retrieve the date the current post was written (once per date)
  2521  * Displays or retrieves the date the current post was written (once per date)
  2498  *
  2522  *
  2499  * Will only output the date if the current post's date is different from the
  2523  * Will only output the date if the current post's date is different from the
  2500  * previous one output.
  2524  * previous one output.
  2501  *
  2525  *
  2502  * i.e. Only one date listing will show per day worth of posts shown in the loop, even if the
  2526  * i.e. Only one date listing will show per day worth of posts shown in the loop, even if the
  2508  * @since 0.71
  2532  * @since 0.71
  2509  *
  2533  *
  2510  * @global string $currentday  The day of the current post in the loop.
  2534  * @global string $currentday  The day of the current post in the loop.
  2511  * @global string $previousday The day of the previous post in the loop.
  2535  * @global string $previousday The day of the previous post in the loop.
  2512  *
  2536  *
  2513  * @param string $format Optional. PHP date format. Defaults to the 'date_format' option.
  2537  * @param string $format  Optional. PHP date format. Defaults to the 'date_format' option.
  2514  * @param string $before Optional. Output before the date. Default empty.
  2538  * @param string $before  Optional. Output before the date. Default empty.
  2515  * @param string $after  Optional. Output after the date. Default empty.
  2539  * @param string $after   Optional. Output after the date. Default empty.
  2516  * @param bool   $echo   Optional. Whether to echo the date or return it. Default true.
  2540  * @param bool   $display Optional. Whether to echo the date or return it. Default true.
  2517  * @return string|void String if retrieving.
  2541  * @return string|void String if retrieving.
  2518  */
  2542  */
  2519 function the_date( $format = '', $before = '', $after = '', $echo = true ) {
  2543 function the_date( $format = '', $before = '', $after = '', $display = true ) {
  2520 	global $currentday, $previousday;
  2544 	global $currentday, $previousday;
  2521 
  2545 
  2522 	$the_date = '';
  2546 	$the_date = '';
  2523 
  2547 
  2524 	if ( is_new_day() ) {
  2548 	if ( is_new_day() ) {
  2536 	 * @param string $before   HTML output before the date.
  2560 	 * @param string $before   HTML output before the date.
  2537 	 * @param string $after    HTML output after the date.
  2561 	 * @param string $after    HTML output after the date.
  2538 	 */
  2562 	 */
  2539 	$the_date = apply_filters( 'the_date', $the_date, $format, $before, $after );
  2563 	$the_date = apply_filters( 'the_date', $the_date, $format, $before, $after );
  2540 
  2564 
  2541 	if ( $echo ) {
  2565 	if ( $display ) {
  2542 		echo $the_date;
  2566 		echo $the_date;
  2543 	} else {
  2567 	} else {
  2544 		return $the_date;
  2568 		return $the_date;
  2545 	}
  2569 	}
  2546 }
  2570 }
  2547 
  2571 
  2548 /**
  2572 /**
  2549  * Retrieve the date on which the post was written.
  2573  * Retrieves the date on which the post was written.
  2550  *
  2574  *
  2551  * Unlike the_date() this function will always return the date.
  2575  * Unlike the_date() this function will always return the date.
  2552  * Modify output with the {@see 'get_the_date'} filter.
  2576  * Modify output with the {@see 'get_the_date'} filter.
  2553  *
  2577  *
  2554  * @since 3.0.0
  2578  * @since 3.0.0
  2579 	 */
  2603 	 */
  2580 	return apply_filters( 'get_the_date', $the_date, $format, $post );
  2604 	return apply_filters( 'get_the_date', $the_date, $format, $post );
  2581 }
  2605 }
  2582 
  2606 
  2583 /**
  2607 /**
  2584  * Display the date on which the post was last modified.
  2608  * Displays the date on which the post was last modified.
  2585  *
  2609  *
  2586  * @since 2.1.0
  2610  * @since 2.1.0
  2587  *
  2611  *
  2588  * @param string $format Optional. PHP date format. Defaults to the 'date_format' option.
  2612  * @param string $format  Optional. PHP date format. Defaults to the 'date_format' option.
  2589  * @param string $before Optional. Output before the date. Default empty.
  2613  * @param string $before  Optional. Output before the date. Default empty.
  2590  * @param string $after  Optional. Output after the date. Default empty.
  2614  * @param string $after   Optional. Output after the date. Default empty.
  2591  * @param bool   $echo   Optional. Whether to echo the date or return it. Default true.
  2615  * @param bool   $display Optional. Whether to echo the date or return it. Default true.
  2592  * @return string|void String if retrieving.
  2616  * @return string|void String if retrieving.
  2593  */
  2617  */
  2594 function the_modified_date( $format = '', $before = '', $after = '', $echo = true ) {
  2618 function the_modified_date( $format = '', $before = '', $after = '', $display = true ) {
  2595 	$the_modified_date = $before . get_the_modified_date( $format ) . $after;
  2619 	$the_modified_date = $before . get_the_modified_date( $format ) . $after;
  2596 
  2620 
  2597 	/**
  2621 	/**
  2598 	 * Filters the date a post was last modified for display.
  2622 	 * Filters the date a post was last modified for display.
  2599 	 *
  2623 	 *
  2604 	 * @param string       $before            HTML output before the date.
  2628 	 * @param string       $before            HTML output before the date.
  2605 	 * @param string       $after             HTML output after the date.
  2629 	 * @param string       $after             HTML output after the date.
  2606 	 */
  2630 	 */
  2607 	$the_modified_date = apply_filters( 'the_modified_date', $the_modified_date, $format, $before, $after );
  2631 	$the_modified_date = apply_filters( 'the_modified_date', $the_modified_date, $format, $before, $after );
  2608 
  2632 
  2609 	if ( $echo ) {
  2633 	if ( $display ) {
  2610 		echo $the_modified_date;
  2634 		echo $the_modified_date;
  2611 	} else {
  2635 	} else {
  2612 		return $the_modified_date;
  2636 		return $the_modified_date;
  2613 	}
  2637 	}
  2614 
  2638 }
  2615 }
  2639 
  2616 
  2640 /**
  2617 /**
  2641  * Retrieves the date on which the post was last modified.
  2618  * Retrieve the date on which the post was last modified.
       
  2619  *
  2642  *
  2620  * @since 2.1.0
  2643  * @since 2.1.0
  2621  * @since 4.6.0 Added the `$post` parameter.
  2644  * @since 4.6.0 Added the `$post` parameter.
  2622  *
  2645  *
  2623  * @param string      $format Optional. PHP date format. Defaults to the 'date_format' option.
  2646  * @param string      $format Optional. PHP date format. Defaults to the 'date_format' option.
  2648 	 */
  2671 	 */
  2649 	return apply_filters( 'get_the_modified_date', $the_time, $format, $post );
  2672 	return apply_filters( 'get_the_modified_date', $the_time, $format, $post );
  2650 }
  2673 }
  2651 
  2674 
  2652 /**
  2675 /**
  2653  * Display the time at which the post was written.
  2676  * Displays the time at which the post was written.
  2654  *
  2677  *
  2655  * @since 0.71
  2678  * @since 0.71
  2656  *
  2679  *
  2657  * @param string $format Optional. Format to use for retrieving the time the post
  2680  * @param string $format Optional. Format to use for retrieving the time the post
  2658  *                       was written. Accepts 'G', 'U', or PHP date format.
  2681  *                       was written. Accepts 'G', 'U', or PHP date format.
  2670 	 */
  2693 	 */
  2671 	echo apply_filters( 'the_time', get_the_time( $format ), $format );
  2694 	echo apply_filters( 'the_time', get_the_time( $format ), $format );
  2672 }
  2695 }
  2673 
  2696 
  2674 /**
  2697 /**
  2675  * Retrieve the time at which the post was written.
  2698  * Retrieves the time at which the post was written.
  2676  *
  2699  *
  2677  * @since 1.5.0
  2700  * @since 1.5.0
  2678  *
  2701  *
  2679  * @param string      $format Optional. Format to use for retrieving the time the post
  2702  * @param string      $format Optional. Format to use for retrieving the time the post
  2680  *                            was written. Accepts 'G', 'U', or PHP date format.
  2703  *                            was written. Accepts 'G', 'U', or PHP date format.
  2681  *                            Defaults to the 'time_format' option.
  2704  *                            Defaults to the 'time_format' option.
  2682  * @param int|WP_Post $post   WP_Post object or ID. Default is global `$post` object.
  2705  * @param int|WP_Post $post   Post ID or post object. Default is global `$post` object.
  2683  * @return string|int|false Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
  2706  * @return string|int|false Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
  2684  *                          False on failure.
  2707  *                          False on failure.
  2685  */
  2708  */
  2686 function get_the_time( $format = '', $post = null ) {
  2709 function get_the_time( $format = '', $post = null ) {
  2687 	$post = get_post( $post );
  2710 	$post = get_post( $post );
  2706 	 */
  2729 	 */
  2707 	return apply_filters( 'get_the_time', $the_time, $format, $post );
  2730 	return apply_filters( 'get_the_time', $the_time, $format, $post );
  2708 }
  2731 }
  2709 
  2732 
  2710 /**
  2733 /**
  2711  * Retrieve the time at which the post was written.
  2734  * Retrieves the time at which the post was written.
  2712  *
  2735  *
  2713  * @since 2.0.0
  2736  * @since 2.0.0
  2714  *
  2737  *
  2715  * @param string      $format    Optional. Format to use for retrieving the time the post
  2738  * @param string      $format    Optional. Format to use for retrieving the time the post
  2716  *                               was written. Accepts 'G', 'U', or PHP date format. Default 'U'.
  2739  *                               was written. Accepts 'G', 'U', or PHP date format. Default 'U'.
  2717  * @param bool        $gmt       Optional. Whether to retrieve the GMT time. Default false.
  2740  * @param bool        $gmt       Optional. Whether to retrieve the GMT time. Default false.
  2718  * @param int|WP_Post $post      WP_Post object or ID. Default is global `$post` object.
  2741  * @param int|WP_Post $post      Post ID or post object. Default is global `$post` object.
  2719  * @param bool        $translate Whether to translate the time string. Default false.
  2742  * @param bool        $translate Whether to translate the time string. Default false.
  2720  * @return string|int|false Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
  2743  * @return string|int|false Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
  2721  *                          False on failure.
  2744  *                          False on failure.
  2722  */
  2745  */
  2723 function get_post_time( $format = 'U', $gmt = false, $post = null, $translate = false ) {
  2746 function get_post_time( $format = 'U', $gmt = false, $post = null, $translate = false ) {
  2763 	 */
  2786 	 */
  2764 	return apply_filters( 'get_post_time', $time, $format, $gmt );
  2787 	return apply_filters( 'get_post_time', $time, $format, $gmt );
  2765 }
  2788 }
  2766 
  2789 
  2767 /**
  2790 /**
  2768  * Retrieve post published or modified time as a `DateTimeImmutable` object instance.
  2791  * Retrieves post published or modified time as a `DateTimeImmutable` object instance.
  2769  *
  2792  *
  2770  * The object will be set to the timezone from WordPress settings.
  2793  * The object will be set to the timezone from WordPress settings.
  2771  *
  2794  *
  2772  * For legacy reasons, this function allows to choose to instantiate from local or UTC time in database.
  2795  * For legacy reasons, this function allows to choose to instantiate from local or UTC time in database.
  2773  * Normally this should make no difference to the result. However, the values might get out of sync in database,
  2796  * Normally this should make no difference to the result. However, the values might get out of sync in database,
  2774  * typically because of timezone setting changes. The parameter ensures the ability to reproduce backwards
  2797  * typically because of timezone setting changes. The parameter ensures the ability to reproduce backwards
  2775  * compatible behaviors in such cases.
  2798  * compatible behaviors in such cases.
  2776  *
  2799  *
  2777  * @since 5.3.0
  2800  * @since 5.3.0
  2778  *
  2801  *
  2779  * @param int|WP_Post $post   Optional. WP_Post object or ID. Default is global `$post` object.
  2802  * @param int|WP_Post $post   Optional. Post ID or post object. Default is global `$post` object.
  2780  * @param string      $field  Optional. Published or modified time to use from database. Accepts 'date' or 'modified'.
  2803  * @param string      $field  Optional. Published or modified time to use from database. Accepts 'date' or 'modified'.
  2781  *                            Default 'date'.
  2804  *                            Default 'date'.
  2782  * @param string      $source Optional. Local or UTC time to use from database. Accepts 'local' or 'gmt'.
  2805  * @param string      $source Optional. Local or UTC time to use from database. Accepts 'local' or 'gmt'.
  2783  *                            Default 'local'.
  2806  *                            Default 'local'.
  2784  * @return DateTimeImmutable|false Time object on success, false on failure.
  2807  * @return DateTimeImmutable|false Time object on success, false on failure.
  2812 
  2835 
  2813 	return $datetime->setTimezone( $wp_timezone );
  2836 	return $datetime->setTimezone( $wp_timezone );
  2814 }
  2837 }
  2815 
  2838 
  2816 /**
  2839 /**
  2817  * Retrieve post published or modified time as a Unix timestamp.
  2840  * Retrieves post published or modified time as a Unix timestamp.
  2818  *
  2841  *
  2819  * Note that this function returns a true Unix timestamp, not summed with timezone offset
  2842  * Note that this function returns a true Unix timestamp, not summed with timezone offset
  2820  * like older WP functions.
  2843  * like older WP functions.
  2821  *
  2844  *
  2822  * @since 5.3.0
  2845  * @since 5.3.0
  2823  *
  2846  *
  2824  * @param int|WP_Post $post  Optional. WP_Post object or ID. Default is global `$post` object.
  2847  * @param int|WP_Post $post  Optional. Post ID or post object. Default is global `$post` object.
  2825  * @param string      $field Optional. Published or modified time to use from database. Accepts 'date' or 'modified'.
  2848  * @param string      $field Optional. Published or modified time to use from database. Accepts 'date' or 'modified'.
  2826  *                           Default 'date'.
  2849  *                           Default 'date'.
  2827  * @return int|false Unix timestamp on success, false on failure.
  2850  * @return int|false Unix timestamp on success, false on failure.
  2828  */
  2851  */
  2829 function get_post_timestamp( $post = null, $field = 'date' ) {
  2852 function get_post_timestamp( $post = null, $field = 'date' ) {
  2835 
  2858 
  2836 	return $datetime->getTimestamp();
  2859 	return $datetime->getTimestamp();
  2837 }
  2860 }
  2838 
  2861 
  2839 /**
  2862 /**
  2840  * Display the time at which the post was last modified.
  2863  * Displays the time at which the post was last modified.
  2841  *
  2864  *
  2842  * @since 2.0.0
  2865  * @since 2.0.0
  2843  *
  2866  *
  2844  * @param string $format Optional. Format to use for retrieving the time the post
  2867  * @param string $format Optional. Format to use for retrieving the time the post
  2845  *                       was modified. Accepts 'G', 'U', or PHP date format.
  2868  *                       was modified. Accepts 'G', 'U', or PHP date format.
  2857 	 */
  2880 	 */
  2858 	echo apply_filters( 'the_modified_time', get_the_modified_time( $format ), $format );
  2881 	echo apply_filters( 'the_modified_time', get_the_modified_time( $format ), $format );
  2859 }
  2882 }
  2860 
  2883 
  2861 /**
  2884 /**
  2862  * Retrieve the time at which the post was last modified.
  2885  * Retrieves the time at which the post was last modified.
  2863  *
  2886  *
  2864  * @since 2.0.0
  2887  * @since 2.0.0
  2865  * @since 4.6.0 Added the `$post` parameter.
  2888  * @since 4.6.0 Added the `$post` parameter.
  2866  *
  2889  *
  2867  * @param string      $format Optional. Format to use for retrieving the time the post
  2890  * @param string      $format Optional. Format to use for retrieving the time the post
  2895 	 */
  2918 	 */
  2896 	return apply_filters( 'get_the_modified_time', $the_time, $format, $post );
  2919 	return apply_filters( 'get_the_modified_time', $the_time, $format, $post );
  2897 }
  2920 }
  2898 
  2921 
  2899 /**
  2922 /**
  2900  * Retrieve the time at which the post was last modified.
  2923  * Retrieves the time at which the post was last modified.
  2901  *
  2924  *
  2902  * @since 2.0.0
  2925  * @since 2.0.0
  2903  *
  2926  *
  2904  * @param string      $format    Optional. Format to use for retrieving the time the post
  2927  * @param string      $format    Optional. Format to use for retrieving the time the post
  2905  *                               was modified. Accepts 'G', 'U', or PHP date format. Default 'U'.
  2928  *                               was modified. Accepts 'G', 'U', or PHP date format. Default 'U'.
  2906  * @param bool        $gmt       Optional. Whether to retrieve the GMT time. Default false.
  2929  * @param bool        $gmt       Optional. Whether to retrieve the GMT time. Default false.
  2907  * @param int|WP_Post $post      WP_Post object or ID. Default is global `$post` object.
  2930  * @param int|WP_Post $post      Post ID or post object. Default is global `$post` object.
  2908  * @param bool        $translate Whether to translate the time string. Default false.
  2931  * @param bool        $translate Whether to translate the time string. Default false.
  2909  * @return string|int|false Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
  2932  * @return string|int|false Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
  2910  *                          False on failure.
  2933  *                          False on failure.
  2911  */
  2934  */
  2912 function get_post_modified_time( $format = 'U', $gmt = false, $post = null, $translate = false ) {
  2935 function get_post_modified_time( $format = 'U', $gmt = false, $post = null, $translate = false ) {
  2952 	 */
  2975 	 */
  2953 	return apply_filters( 'get_post_modified_time', $time, $format, $gmt );
  2976 	return apply_filters( 'get_post_modified_time', $time, $format, $gmt );
  2954 }
  2977 }
  2955 
  2978 
  2956 /**
  2979 /**
  2957  * Display the weekday on which the post was written.
  2980  * Displays the weekday on which the post was written.
  2958  *
  2981  *
  2959  * @since 0.71
  2982  * @since 0.71
  2960  *
  2983  *
  2961  * @global WP_Locale $wp_locale WordPress date and time locale object.
  2984  * @global WP_Locale $wp_locale WordPress date and time locale object.
  2962  */
  2985  */
  2980 	 */
  3003 	 */
  2981 	echo apply_filters( 'the_weekday', $the_weekday );
  3004 	echo apply_filters( 'the_weekday', $the_weekday );
  2982 }
  3005 }
  2983 
  3006 
  2984 /**
  3007 /**
  2985  * Display the weekday on which the post was written.
  3008  * Displays the weekday on which the post was written.
  2986  *
  3009  *
  2987  * Will only output the weekday if the current post's weekday is different from
  3010  * Will only output the weekday if the current post's weekday is different from
  2988  * the previous one output.
  3011  * the previous one output.
  2989  *
  3012  *
  2990  * @since 0.71
  3013  * @since 0.71
  3025 	 */
  3048 	 */
  3026 	echo apply_filters( 'the_weekday_date', $the_weekday_date, $before, $after );
  3049 	echo apply_filters( 'the_weekday_date', $the_weekday_date, $before, $after );
  3027 }
  3050 }
  3028 
  3051 
  3029 /**
  3052 /**
  3030  * Fire the wp_head action.
  3053  * Fires the wp_head action.
  3031  *
  3054  *
  3032  * See {@see 'wp_head'}.
  3055  * See {@see 'wp_head'}.
  3033  *
  3056  *
  3034  * @since 1.2.0
  3057  * @since 1.2.0
  3035  */
  3058  */
  3041 	 */
  3064 	 */
  3042 	do_action( 'wp_head' );
  3065 	do_action( 'wp_head' );
  3043 }
  3066 }
  3044 
  3067 
  3045 /**
  3068 /**
  3046  * Fire the wp_footer action.
  3069  * Fires the wp_footer action.
  3047  *
  3070  *
  3048  * See {@see 'wp_footer'}.
  3071  * See {@see 'wp_footer'}.
  3049  *
  3072  *
  3050  * @since 1.5.1
  3073  * @since 1.5.1
  3051  */
  3074  */
  3057 	 */
  3080 	 */
  3058 	do_action( 'wp_footer' );
  3081 	do_action( 'wp_footer' );
  3059 }
  3082 }
  3060 
  3083 
  3061 /**
  3084 /**
  3062  * Fire the wp_body_open action.
  3085  * Fires the wp_body_open action.
  3063  *
  3086  *
  3064  * See {@see 'wp_body_open'}.
  3087  * See {@see 'wp_body_open'}.
  3065  *
  3088  *
  3066  * @since 5.2.0
  3089  * @since 5.2.0
  3067  */
  3090  */
  3073 	 */
  3096 	 */
  3074 	do_action( 'wp_body_open' );
  3097 	do_action( 'wp_body_open' );
  3075 }
  3098 }
  3076 
  3099 
  3077 /**
  3100 /**
  3078  * Display the links to the general feeds.
  3101  * Displays the links to the general feeds.
  3079  *
  3102  *
  3080  * @since 2.8.0
  3103  * @since 2.8.0
  3081  *
  3104  *
  3082  * @param array $args Optional arguments.
  3105  * @param array $args Optional arguments.
  3083  */
  3106  */
  3085 	if ( ! current_theme_supports( 'automatic-feed-links' ) ) {
  3108 	if ( ! current_theme_supports( 'automatic-feed-links' ) ) {
  3086 		return;
  3109 		return;
  3087 	}
  3110 	}
  3088 
  3111 
  3089 	$defaults = array(
  3112 	$defaults = array(
  3090 		/* translators: Separator between blog name and feed type in feed links. */
  3113 		/* translators: Separator between site name and feed type in feed links. */
  3091 		'separator' => _x( '&raquo;', 'feed link' ),
  3114 		'separator' => _x( '&raquo;', 'feed link' ),
  3092 		/* translators: 1: Blog title, 2: Separator (raquo). */
  3115 		/* translators: 1: Site title, 2: Separator (raquo). */
  3093 		'feedtitle' => __( '%1$s %2$s Feed' ),
  3116 		'feedtitle' => __( '%1$s %2$s Feed' ),
  3094 		/* translators: 1: Blog title, 2: Separator (raquo). */
  3117 		/* translators: 1: Site title, 2: Separator (raquo). */
  3095 		'comstitle' => __( '%1$s %2$s Comments Feed' ),
  3118 		'comstitle' => __( '%1$s %2$s Comments Feed' ),
  3096 	);
  3119 	);
  3097 
  3120 
  3098 	$args = wp_parse_args( $args, $defaults );
  3121 	$args = wp_parse_args( $args, $defaults );
  3099 
  3122 
  3103 	 * @since 4.4.0
  3126 	 * @since 4.4.0
  3104 	 *
  3127 	 *
  3105 	 * @param bool $show Whether to display the posts feed link. Default true.
  3128 	 * @param bool $show Whether to display the posts feed link. Default true.
  3106 	 */
  3129 	 */
  3107 	if ( apply_filters( 'feed_links_show_posts_feed', true ) ) {
  3130 	if ( apply_filters( 'feed_links_show_posts_feed', true ) ) {
  3108 		echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr( sprintf( $args['feedtitle'], get_bloginfo( 'name' ), $args['separator'] ) ) . '" href="' . esc_url( get_feed_link() ) . "\" />\n";
  3131 		printf(
       
  3132 			'<link rel="alternate" type="%s" title="%s" href="%s" />' . "\n",
       
  3133 			feed_content_type(),
       
  3134 			esc_attr( sprintf( $args['feedtitle'], get_bloginfo( 'name' ), $args['separator'] ) ),
       
  3135 			esc_url( get_feed_link() )
       
  3136 		);
  3109 	}
  3137 	}
  3110 
  3138 
  3111 	/**
  3139 	/**
  3112 	 * Filters whether to display the comments feed link.
  3140 	 * Filters whether to display the comments feed link.
  3113 	 *
  3141 	 *
  3114 	 * @since 4.4.0
  3142 	 * @since 4.4.0
  3115 	 *
  3143 	 *
  3116 	 * @param bool $show Whether to display the comments feed link. Default true.
  3144 	 * @param bool $show Whether to display the comments feed link. Default true.
  3117 	 */
  3145 	 */
  3118 	if ( apply_filters( 'feed_links_show_comments_feed', true ) ) {
  3146 	if ( apply_filters( 'feed_links_show_comments_feed', true ) ) {
  3119 		echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr( sprintf( $args['comstitle'], get_bloginfo( 'name' ), $args['separator'] ) ) . '" href="' . esc_url( get_feed_link( 'comments_' . get_default_feed() ) ) . "\" />\n";
  3147 		printf(
  3120 	}
  3148 			'<link rel="alternate" type="%s" title="%s" href="%s" />' . "\n",
  3121 }
  3149 			feed_content_type(),
  3122 
  3150 			esc_attr( sprintf( $args['comstitle'], get_bloginfo( 'name' ), $args['separator'] ) ),
  3123 /**
  3151 			esc_url( get_feed_link( 'comments_' . get_default_feed() ) )
  3124  * Display the links to the extra feeds such as category feeds.
  3152 		);
       
  3153 	}
       
  3154 }
       
  3155 
       
  3156 /**
       
  3157  * Displays the links to the extra feeds such as category feeds.
  3125  *
  3158  *
  3126  * @since 2.8.0
  3159  * @since 2.8.0
  3127  *
  3160  *
  3128  * @param array $args Optional arguments.
  3161  * @param array $args Optional arguments.
  3129  */
  3162  */
  3130 function feed_links_extra( $args = array() ) {
  3163 function feed_links_extra( $args = array() ) {
  3131 	$defaults = array(
  3164 	$defaults = array(
  3132 		/* translators: Separator between blog name and feed type in feed links. */
  3165 		/* translators: Separator between site name and feed type in feed links. */
  3133 		'separator'     => _x( '&raquo;', 'feed link' ),
  3166 		'separator'     => _x( '&raquo;', 'feed link' ),
  3134 		/* translators: 1: Blog name, 2: Separator (raquo), 3: Post title. */
  3167 		/* translators: 1: Site name, 2: Separator (raquo), 3: Post title. */
  3135 		'singletitle'   => __( '%1$s %2$s %3$s Comments Feed' ),
  3168 		'singletitle'   => __( '%1$s %2$s %3$s Comments Feed' ),
  3136 		/* translators: 1: Blog name, 2: Separator (raquo), 3: Category name. */
  3169 		/* translators: 1: Site name, 2: Separator (raquo), 3: Category name. */
  3137 		'cattitle'      => __( '%1$s %2$s %3$s Category Feed' ),
  3170 		'cattitle'      => __( '%1$s %2$s %3$s Category Feed' ),
  3138 		/* translators: 1: Blog name, 2: Separator (raquo), 3: Tag name. */
  3171 		/* translators: 1: Site name, 2: Separator (raquo), 3: Tag name. */
  3139 		'tagtitle'      => __( '%1$s %2$s %3$s Tag Feed' ),
  3172 		'tagtitle'      => __( '%1$s %2$s %3$s Tag Feed' ),
  3140 		/* translators: 1: Blog name, 2: Separator (raquo), 3: Term name, 4: Taxonomy singular name. */
  3173 		/* translators: 1: Site name, 2: Separator (raquo), 3: Term name, 4: Taxonomy singular name. */
  3141 		'taxtitle'      => __( '%1$s %2$s %3$s %4$s Feed' ),
  3174 		'taxtitle'      => __( '%1$s %2$s %3$s %4$s Feed' ),
  3142 		/* translators: 1: Blog name, 2: Separator (raquo), 3: Author name. */
  3175 		/* translators: 1: Site name, 2: Separator (raquo), 3: Author name. */
  3143 		'authortitle'   => __( '%1$s %2$s Posts by %3$s Feed' ),
  3176 		'authortitle'   => __( '%1$s %2$s Posts by %3$s Feed' ),
  3144 		/* translators: 1: Blog name, 2: Separator (raquo), 3: Search query. */
  3177 		/* translators: 1: Site name, 2: Separator (raquo), 3: Search query. */
  3145 		'searchtitle'   => __( '%1$s %2$s Search Results for &#8220;%3$s&#8221; Feed' ),
  3178 		'searchtitle'   => __( '%1$s %2$s Search Results for &#8220;%3$s&#8221; Feed' ),
  3146 		/* translators: 1: Blog name, 2: Separator (raquo), 3: Post type name. */
  3179 		/* translators: 1: Site name, 2: Separator (raquo), 3: Post type name. */
  3147 		'posttypetitle' => __( '%1$s %2$s %3$s Feed' ),
  3180 		'posttypetitle' => __( '%1$s %2$s %3$s Feed' ),
  3148 	);
  3181 	);
  3149 
  3182 
  3150 	$args = wp_parse_args( $args, $defaults );
  3183 	$args = wp_parse_args( $args, $defaults );
  3151 
  3184 
  3154 		$post = get_post( $id );
  3187 		$post = get_post( $id );
  3155 
  3188 
  3156 		/** This filter is documented in wp-includes/general-template.php */
  3189 		/** This filter is documented in wp-includes/general-template.php */
  3157 		$show_comments_feed = apply_filters( 'feed_links_show_comments_feed', true );
  3190 		$show_comments_feed = apply_filters( 'feed_links_show_comments_feed', true );
  3158 
  3191 
  3159 		if ( $show_comments_feed && ( comments_open() || pings_open() || $post->comment_count > 0 ) ) {
  3192 		/**
  3160 			$title     = sprintf( $args['singletitle'], get_bloginfo( 'name' ), $args['separator'], the_title_attribute( array( 'echo' => false ) ) );
  3193 		 * Filters whether to display the post comments feed link.
       
  3194 		 *
       
  3195 		 * This filter allows to enable or disable the feed link for a singular post
       
  3196 		 * in a way that is independent of {@see 'feed_links_show_comments_feed'}
       
  3197 		 * (which controls the global comments feed). The result of that filter
       
  3198 		 * is accepted as a parameter.
       
  3199 		 *
       
  3200 		 * @since 6.1.0
       
  3201 		 *
       
  3202 		 * @param bool $show_comments_feed Whether to display the post comments feed link. Defaults to
       
  3203 		 *                                 the {@see 'feed_links_show_comments_feed'} filter result.
       
  3204 		 */
       
  3205 		$show_post_comments_feed = apply_filters( 'feed_links_extra_show_post_comments_feed', $show_comments_feed );
       
  3206 
       
  3207 		if ( $show_post_comments_feed && ( comments_open() || pings_open() || $post->comment_count > 0 ) ) {
       
  3208 			$title = sprintf(
       
  3209 				$args['singletitle'],
       
  3210 				get_bloginfo( 'name' ),
       
  3211 				$args['separator'],
       
  3212 				the_title_attribute( array( 'echo' => false ) )
       
  3213 			);
       
  3214 
  3161 			$feed_link = get_post_comments_feed_link( $post->ID );
  3215 			$feed_link = get_post_comments_feed_link( $post->ID );
  3162 
  3216 
  3163 			if ( $feed_link ) {
  3217 			if ( $feed_link ) {
  3164 				$href = $feed_link;
  3218 				$href = $feed_link;
  3165 			}
  3219 			}
  3166 		}
  3220 		}
  3167 	} elseif ( is_post_type_archive() ) {
  3221 	} elseif ( is_post_type_archive() ) {
  3168 		$post_type = get_query_var( 'post_type' );
  3222 		/**
  3169 		if ( is_array( $post_type ) ) {
  3223 		 * Filters whether to display the post type archive feed link.
  3170 			$post_type = reset( $post_type );
  3224 		 *
  3171 		}
  3225 		 * @since 6.1.0
  3172 
  3226 		 *
  3173 		$post_type_obj = get_post_type_object( $post_type );
  3227 		 * @param bool $show Whether to display the post type archive feed link. Default true.
  3174 		$title         = sprintf( $args['posttypetitle'], get_bloginfo( 'name' ), $args['separator'], $post_type_obj->labels->name );
  3228 		 */
  3175 		$href          = get_post_type_archive_feed_link( $post_type_obj->name );
  3229 		$show_post_type_archive_feed = apply_filters( 'feed_links_extra_show_post_type_archive_feed', true );
       
  3230 
       
  3231 		if ( $show_post_type_archive_feed ) {
       
  3232 			$post_type = get_query_var( 'post_type' );
       
  3233 
       
  3234 			if ( is_array( $post_type ) ) {
       
  3235 				$post_type = reset( $post_type );
       
  3236 			}
       
  3237 
       
  3238 			$post_type_obj = get_post_type_object( $post_type );
       
  3239 
       
  3240 			$title = sprintf(
       
  3241 				$args['posttypetitle'],
       
  3242 				get_bloginfo( 'name' ),
       
  3243 				$args['separator'],
       
  3244 				$post_type_obj->labels->name
       
  3245 			);
       
  3246 
       
  3247 			$href = get_post_type_archive_feed_link( $post_type_obj->name );
       
  3248 		}
  3176 	} elseif ( is_category() ) {
  3249 	} elseif ( is_category() ) {
  3177 		$term = get_queried_object();
  3250 		/**
  3178 
  3251 		 * Filters whether to display the category feed link.
  3179 		if ( $term ) {
  3252 		 *
  3180 			$title = sprintf( $args['cattitle'], get_bloginfo( 'name' ), $args['separator'], $term->name );
  3253 		 * @since 6.1.0
  3181 			$href  = get_category_feed_link( $term->term_id );
  3254 		 *
       
  3255 		 * @param bool $show Whether to display the category feed link. Default true.
       
  3256 		 */
       
  3257 		$show_category_feed = apply_filters( 'feed_links_extra_show_category_feed', true );
       
  3258 
       
  3259 		if ( $show_category_feed ) {
       
  3260 			$term = get_queried_object();
       
  3261 
       
  3262 			if ( $term ) {
       
  3263 				$title = sprintf(
       
  3264 					$args['cattitle'],
       
  3265 					get_bloginfo( 'name' ),
       
  3266 					$args['separator'],
       
  3267 					$term->name
       
  3268 				);
       
  3269 
       
  3270 				$href = get_category_feed_link( $term->term_id );
       
  3271 			}
  3182 		}
  3272 		}
  3183 	} elseif ( is_tag() ) {
  3273 	} elseif ( is_tag() ) {
  3184 		$term = get_queried_object();
  3274 		/**
  3185 
  3275 		 * Filters whether to display the tag feed link.
  3186 		if ( $term ) {
  3276 		 *
  3187 			$title = sprintf( $args['tagtitle'], get_bloginfo( 'name' ), $args['separator'], $term->name );
  3277 		 * @since 6.1.0
  3188 			$href  = get_tag_feed_link( $term->term_id );
  3278 		 *
       
  3279 		 * @param bool $show Whether to display the tag feed link. Default true.
       
  3280 		 */
       
  3281 		$show_tag_feed = apply_filters( 'feed_links_extra_show_tag_feed', true );
       
  3282 
       
  3283 		if ( $show_tag_feed ) {
       
  3284 			$term = get_queried_object();
       
  3285 
       
  3286 			if ( $term ) {
       
  3287 				$title = sprintf(
       
  3288 					$args['tagtitle'],
       
  3289 					get_bloginfo( 'name' ),
       
  3290 					$args['separator'],
       
  3291 					$term->name
       
  3292 				);
       
  3293 
       
  3294 				$href = get_tag_feed_link( $term->term_id );
       
  3295 			}
  3189 		}
  3296 		}
  3190 	} elseif ( is_tax() ) {
  3297 	} elseif ( is_tax() ) {
  3191 		$term = get_queried_object();
  3298 		/**
  3192 
  3299 		 * Filters whether to display the custom taxonomy feed link.
  3193 		if ( $term ) {
  3300 		 *
  3194 			$tax   = get_taxonomy( $term->taxonomy );
  3301 		 * @since 6.1.0
  3195 			$title = sprintf( $args['taxtitle'], get_bloginfo( 'name' ), $args['separator'], $term->name, $tax->labels->singular_name );
  3302 		 *
  3196 			$href  = get_term_feed_link( $term->term_id, $term->taxonomy );
  3303 		 * @param bool $show Whether to display the custom taxonomy feed link. Default true.
       
  3304 		 */
       
  3305 		$show_tax_feed = apply_filters( 'feed_links_extra_show_tax_feed', true );
       
  3306 
       
  3307 		if ( $show_tax_feed ) {
       
  3308 			$term = get_queried_object();
       
  3309 
       
  3310 			if ( $term ) {
       
  3311 				$tax = get_taxonomy( $term->taxonomy );
       
  3312 
       
  3313 				$title = sprintf(
       
  3314 					$args['taxtitle'],
       
  3315 					get_bloginfo( 'name' ),
       
  3316 					$args['separator'],
       
  3317 					$term->name,
       
  3318 					$tax->labels->singular_name
       
  3319 				);
       
  3320 
       
  3321 				$href = get_term_feed_link( $term->term_id, $term->taxonomy );
       
  3322 			}
  3197 		}
  3323 		}
  3198 	} elseif ( is_author() ) {
  3324 	} elseif ( is_author() ) {
  3199 		$author_id = (int) get_query_var( 'author' );
  3325 		/**
  3200 
  3326 		 * Filters whether to display the author feed link.
  3201 		$title = sprintf( $args['authortitle'], get_bloginfo( 'name' ), $args['separator'], get_the_author_meta( 'display_name', $author_id ) );
  3327 		 *
  3202 		$href  = get_author_feed_link( $author_id );
  3328 		 * @since 6.1.0
       
  3329 		 *
       
  3330 		 * @param bool $show Whether to display the author feed link. Default true.
       
  3331 		 */
       
  3332 		$show_author_feed = apply_filters( 'feed_links_extra_show_author_feed', true );
       
  3333 
       
  3334 		if ( $show_author_feed ) {
       
  3335 			$author_id = (int) get_query_var( 'author' );
       
  3336 
       
  3337 			$title = sprintf(
       
  3338 				$args['authortitle'],
       
  3339 				get_bloginfo( 'name' ),
       
  3340 				$args['separator'],
       
  3341 				get_the_author_meta( 'display_name', $author_id )
       
  3342 			);
       
  3343 
       
  3344 			$href = get_author_feed_link( $author_id );
       
  3345 		}
  3203 	} elseif ( is_search() ) {
  3346 	} elseif ( is_search() ) {
  3204 		$title = sprintf( $args['searchtitle'], get_bloginfo( 'name' ), $args['separator'], get_search_query( false ) );
  3347 		/**
  3205 		$href  = get_search_feed_link();
  3348 		 * Filters whether to display the search results feed link.
       
  3349 		 *
       
  3350 		 * @since 6.1.0
       
  3351 		 *
       
  3352 		 * @param bool $show Whether to display the search results feed link. Default true.
       
  3353 		 */
       
  3354 		$show_search_feed = apply_filters( 'feed_links_extra_show_search_feed', true );
       
  3355 
       
  3356 		if ( $show_search_feed ) {
       
  3357 			$title = sprintf(
       
  3358 				$args['searchtitle'],
       
  3359 				get_bloginfo( 'name' ),
       
  3360 				$args['separator'],
       
  3361 				get_search_query( false )
       
  3362 			);
       
  3363 
       
  3364 			$href = get_search_feed_link();
       
  3365 		}
  3206 	}
  3366 	}
  3207 
  3367 
  3208 	if ( isset( $title ) && isset( $href ) ) {
  3368 	if ( isset( $title ) && isset( $href ) ) {
  3209 		echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr( $title ) . '" href="' . esc_url( $href ) . '" />' . "\n";
  3369 		printf(
  3210 	}
  3370 			'<link rel="alternate" type="%s" title="%s" href="%s" />' . "\n",
  3211 }
  3371 			feed_content_type(),
  3212 
  3372 			esc_attr( $title ),
  3213 /**
  3373 			esc_url( $href )
  3214  * Display the link to the Really Simple Discovery service endpoint.
  3374 		);
       
  3375 	}
       
  3376 }
       
  3377 
       
  3378 /**
       
  3379  * Displays the link to the Really Simple Discovery service endpoint.
  3215  *
  3380  *
  3216  * @link http://archipelago.phrasewise.com/rsd
  3381  * @link http://archipelago.phrasewise.com/rsd
  3217  * @since 2.0.0
  3382  * @since 2.0.0
  3218  */
  3383  */
  3219 function rsd_link() {
  3384 function rsd_link() {
  3220 	echo '<link rel="EditURI" type="application/rsd+xml" title="RSD" href="' . esc_url( site_url( 'xmlrpc.php?rsd', 'rpc' ) ) . '" />' . "\n";
  3385 	printf(
  3221 }
  3386 		'<link rel="EditURI" type="application/rsd+xml" title="RSD" href="%s" />' . "\n",
  3222 
  3387 		esc_url( site_url( 'xmlrpc.php?rsd', 'rpc' ) )
  3223 /**
  3388 	);
  3224  * Display the link to the Windows Live Writer manifest file.
       
  3225  *
       
  3226  * @link https://msdn.microsoft.com/en-us/library/bb463265.aspx
       
  3227  * @since 2.3.1
       
  3228  */
       
  3229 function wlwmanifest_link() {
       
  3230 	echo '<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="' . includes_url( 'wlwmanifest.xml' ) . '" /> ' . "\n";
       
  3231 }
  3389 }
  3232 
  3390 
  3233 /**
  3391 /**
  3234  * Displays a referrer `strict-origin-when-cross-origin` meta tag.
  3392  * Displays a referrer `strict-origin-when-cross-origin` meta tag.
  3235  *
  3393  *
  3247 	<meta name='referrer' content='strict-origin-when-cross-origin' />
  3405 	<meta name='referrer' content='strict-origin-when-cross-origin' />
  3248 	<?php
  3406 	<?php
  3249 }
  3407 }
  3250 
  3408 
  3251 /**
  3409 /**
  3252  * Display site icon meta tags.
  3410  * Displays site icon meta tags.
  3253  *
  3411  *
  3254  * @since 4.3.0
  3412  * @since 4.3.0
  3255  *
  3413  *
  3256  * @link https://www.whatwg.org/specs/web-apps/current-work/multipage/links.html#rel-icon HTML5 specification link icon.
  3414  * @link https://www.whatwg.org/specs/web-apps/current-work/multipage/links.html#rel-icon HTML5 specification link icon.
  3257  */
  3415  */
  3296 	}
  3454 	}
  3297 }
  3455 }
  3298 
  3456 
  3299 /**
  3457 /**
  3300  * Prints resource hints to browsers for pre-fetching, pre-rendering
  3458  * Prints resource hints to browsers for pre-fetching, pre-rendering
  3301  * and pre-connecting to web sites.
  3459  * and pre-connecting to websites.
  3302  *
  3460  *
  3303  * Gives hints to browsers to prefetch specific pages or render them
  3461  * Gives hints to browsers to prefetch specific pages or render them
  3304  * in the background, to perform DNS lookups or to begin the connection
  3462  * in the background, to perform DNS lookups or to begin the connection
  3305  * handshake (DNS, TCP, TLS) in the background.
  3463  * handshake (DNS, TCP, TLS) in the background.
  3306  *
  3464  *
  3314 		'preconnect'   => array(),
  3472 		'preconnect'   => array(),
  3315 		'prefetch'     => array(),
  3473 		'prefetch'     => array(),
  3316 		'prerender'    => array(),
  3474 		'prerender'    => array(),
  3317 	);
  3475 	);
  3318 
  3476 
  3319 	/*
       
  3320 	 * Add DNS prefetch for the Emoji CDN.
       
  3321 	 * The path is removed in the foreach loop below.
       
  3322 	 */
       
  3323 	/** This filter is documented in wp-includes/formatting.php */
       
  3324 	$hints['dns-prefetch'][] = apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/13.0.0/svg/' );
       
  3325 
       
  3326 	foreach ( $hints as $relation_type => $urls ) {
  3477 	foreach ( $hints as $relation_type => $urls ) {
  3327 		$unique_urls = array();
  3478 		$unique_urls = array();
  3328 
  3479 
  3329 		/**
  3480 		/**
  3330 		 * Filters domains and URLs for resource hints of relation type.
  3481 		 * Filters domains and URLs for resource hints of the given relation type.
  3331 		 *
  3482 		 *
  3332 		 * @since 4.6.0
  3483 		 * @since 4.6.0
  3333 		 * @since 4.7.0 The `$urls` parameter accepts arrays of specific HTML attributes
  3484 		 * @since 4.7.0 The `$urls` parameter accepts arrays of specific HTML attributes
  3334 		 *              as its child elements.
  3485 		 *              as its child elements.
  3335 		 *
  3486 		 *
  3345 		 *         @type string $crossorigin Indicates the CORS policy of the specified resource.
  3496 		 *         @type string $crossorigin Indicates the CORS policy of the specified resource.
  3346 		 *         @type float  $pr          Expected probability that the resource hint will be used.
  3497 		 *         @type float  $pr          Expected probability that the resource hint will be used.
  3347 		 *         @type string $type        Type of the resource (`text/html`, `text/css`, etc).
  3498 		 *         @type string $type        Type of the resource (`text/html`, `text/css`, etc).
  3348 		 *     }
  3499 		 *     }
  3349 		 * }
  3500 		 * }
  3350 		 * @param string $relation_type The relation type the URLs are printed for,
  3501 		 * @param string $relation_type The relation type the URLs are printed for. One of
  3351 		 *                              e.g. 'preconnect' or 'prerender'.
  3502 		 *                              'dns-prefetch', 'preconnect', 'prefetch', or 'prerender'.
  3352 		 */
  3503 		 */
  3353 		$urls = apply_filters( 'wp_resource_hints', $urls, $relation_type );
  3504 		$urls = apply_filters( 'wp_resource_hints', $urls, $relation_type );
  3354 
  3505 
  3355 		foreach ( $urls as $key => $url ) {
  3506 		foreach ( $urls as $key => $url ) {
  3356 			$atts = array();
  3507 			$atts = array();
  3421 		}
  3572 		}
  3422 	}
  3573 	}
  3423 }
  3574 }
  3424 
  3575 
  3425 /**
  3576 /**
       
  3577  * Prints resource preloads directives to browsers.
       
  3578  *
       
  3579  * Gives directive to browsers to preload specific resources that website will
       
  3580  * need very soon, this ensures that they are available earlier and are less
       
  3581  * likely to block the page's render. Preload directives should not be used for
       
  3582  * non-render-blocking elements, as then they would compete with the
       
  3583  * render-blocking ones, slowing down the render.
       
  3584  *
       
  3585  * These performance improving indicators work by using `<link rel="preload">`.
       
  3586  *
       
  3587  * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Link_types/preload
       
  3588  * @link https://web.dev/preload-responsive-images/
       
  3589  *
       
  3590  * @since 6.1.0
       
  3591  */
       
  3592 function wp_preload_resources() {
       
  3593 	/**
       
  3594 	 * Filters domains and URLs for resource preloads.
       
  3595 	 *
       
  3596 	 * @since 6.1.0
       
  3597 	 * @since 6.6.0 Added the `$fetchpriority` attribute.
       
  3598 	 *
       
  3599 	 * @param array  $preload_resources {
       
  3600 	 *     Array of resources and their attributes, or URLs to print for resource preloads.
       
  3601 	 *
       
  3602 	 *     @type array ...$0 {
       
  3603 	 *         Array of resource attributes.
       
  3604 	 *
       
  3605 	 *         @type string $href          URL to include in resource preloads. Required.
       
  3606 	 *         @type string $as            How the browser should treat the resource
       
  3607 	 *                                     (`script`, `style`, `image`, `document`, etc).
       
  3608 	 *         @type string $crossorigin   Indicates the CORS policy of the specified resource.
       
  3609 	 *         @type string $type          Type of the resource (`text/html`, `text/css`, etc).
       
  3610 	 *         @type string $media         Accepts media types or media queries. Allows responsive preloading.
       
  3611 	 *         @type string $imagesizes    Responsive source size to the source Set.
       
  3612 	 *         @type string $imagesrcset   Responsive image sources to the source set.
       
  3613 	 *         @type string $fetchpriority Fetchpriority value for the resource.
       
  3614 	 *     }
       
  3615 	 * }
       
  3616 	 */
       
  3617 	$preload_resources = apply_filters( 'wp_preload_resources', array() );
       
  3618 
       
  3619 	if ( ! is_array( $preload_resources ) ) {
       
  3620 		return;
       
  3621 	}
       
  3622 
       
  3623 	$unique_resources = array();
       
  3624 
       
  3625 	// Parse the complete resource list and extract unique resources.
       
  3626 	foreach ( $preload_resources as $resource ) {
       
  3627 		if ( ! is_array( $resource ) ) {
       
  3628 			continue;
       
  3629 		}
       
  3630 
       
  3631 		$attributes = $resource;
       
  3632 		if ( isset( $resource['href'] ) ) {
       
  3633 			$href = $resource['href'];
       
  3634 			if ( isset( $unique_resources[ $href ] ) ) {
       
  3635 				continue;
       
  3636 			}
       
  3637 			$unique_resources[ $href ] = $attributes;
       
  3638 			// Media can use imagesrcset and not href.
       
  3639 		} elseif ( ( 'image' === $resource['as'] ) &&
       
  3640 			( isset( $resource['imagesrcset'] ) || isset( $resource['imagesizes'] ) )
       
  3641 		) {
       
  3642 			if ( isset( $unique_resources[ $resource['imagesrcset'] ] ) ) {
       
  3643 				continue;
       
  3644 			}
       
  3645 			$unique_resources[ $resource['imagesrcset'] ] = $attributes;
       
  3646 		} else {
       
  3647 			continue;
       
  3648 		}
       
  3649 	}
       
  3650 
       
  3651 	// Build and output the HTML for each unique resource.
       
  3652 	foreach ( $unique_resources as $unique_resource ) {
       
  3653 		$html = '';
       
  3654 
       
  3655 		foreach ( $unique_resource as $resource_key => $resource_value ) {
       
  3656 			if ( ! is_scalar( $resource_value ) ) {
       
  3657 				continue;
       
  3658 			}
       
  3659 
       
  3660 			// Ignore non-supported attributes.
       
  3661 			$non_supported_attributes = array( 'as', 'crossorigin', 'href', 'imagesrcset', 'imagesizes', 'type', 'media', 'fetchpriority' );
       
  3662 			if ( ! in_array( $resource_key, $non_supported_attributes, true ) && ! is_numeric( $resource_key ) ) {
       
  3663 				continue;
       
  3664 			}
       
  3665 
       
  3666 			// imagesrcset only usable when preloading image, ignore otherwise.
       
  3667 			if ( ( 'imagesrcset' === $resource_key ) && ( ! isset( $unique_resource['as'] ) || ( 'image' !== $unique_resource['as'] ) ) ) {
       
  3668 				continue;
       
  3669 			}
       
  3670 
       
  3671 			// imagesizes only usable when preloading image and imagesrcset present, ignore otherwise.
       
  3672 			if ( ( 'imagesizes' === $resource_key ) &&
       
  3673 				( ! isset( $unique_resource['as'] ) || ( 'image' !== $unique_resource['as'] ) || ! isset( $unique_resource['imagesrcset'] ) )
       
  3674 			) {
       
  3675 				continue;
       
  3676 			}
       
  3677 
       
  3678 			$resource_value = ( 'href' === $resource_key ) ? esc_url( $resource_value, array( 'http', 'https' ) ) : esc_attr( $resource_value );
       
  3679 
       
  3680 			if ( ! is_string( $resource_key ) ) {
       
  3681 				$html .= " $resource_value";
       
  3682 			} else {
       
  3683 				$html .= " $resource_key='$resource_value'";
       
  3684 			}
       
  3685 		}
       
  3686 		$html = trim( $html );
       
  3687 
       
  3688 		printf( "<link rel='preload' %s />\n", $html );
       
  3689 	}
       
  3690 }
       
  3691 
       
  3692 /**
  3426  * Retrieves a list of unique hosts of all enqueued scripts and styles.
  3693  * Retrieves a list of unique hosts of all enqueued scripts and styles.
  3427  *
  3694  *
  3428  * @since 4.6.0
  3695  * @since 4.6.0
       
  3696  *
       
  3697  * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
       
  3698  * @global WP_Styles  $wp_styles  The WP_Styles object for printing styles.
  3429  *
  3699  *
  3430  * @return string[] A list of unique hosts of enqueued scripts and styles.
  3700  * @return string[] A list of unique hosts of enqueued scripts and styles.
  3431  */
  3701  */
  3432 function wp_dependencies_unique_hosts() {
  3702 function wp_dependencies_unique_hosts() {
  3433 	global $wp_scripts, $wp_styles;
  3703 	global $wp_scripts, $wp_styles;
  3456 
  3726 
  3457 	return $unique_hosts;
  3727 	return $unique_hosts;
  3458 }
  3728 }
  3459 
  3729 
  3460 /**
  3730 /**
  3461  * Whether the user can access the visual editor.
  3731  * Determines whether the user can access the visual editor.
  3462  *
  3732  *
  3463  * Checks if the user can access the visual editor and that it's supported by the user's browser.
  3733  * Checks if the user can access the visual editor and that it's supported by the user's browser.
  3464  *
  3734  *
  3465  * @since 2.0.0
  3735  * @since 2.0.0
  3466  *
  3736  *
  3482 
  3752 
  3483 		if ( 'true' === get_user_option( 'rich_editing' ) || ! is_user_logged_in() ) { // Default to 'true' for logged out users.
  3753 		if ( 'true' === get_user_option( 'rich_editing' ) || ! is_user_logged_in() ) { // Default to 'true' for logged out users.
  3484 			if ( $is_safari ) {
  3754 			if ( $is_safari ) {
  3485 				$wp_rich_edit = ! wp_is_mobile() || ( preg_match( '!AppleWebKit/(\d+)!', $_SERVER['HTTP_USER_AGENT'], $match ) && (int) $match[1] >= 534 );
  3755 				$wp_rich_edit = ! wp_is_mobile() || ( preg_match( '!AppleWebKit/(\d+)!', $_SERVER['HTTP_USER_AGENT'], $match ) && (int) $match[1] >= 534 );
  3486 			} elseif ( $is_IE ) {
  3756 			} elseif ( $is_IE ) {
  3487 				$wp_rich_edit = ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Trident/7.0;' ) !== false );
  3757 				$wp_rich_edit = str_contains( $_SERVER['HTTP_USER_AGENT'], 'Trident/7.0;' );
  3488 			} elseif ( $is_gecko || $is_chrome || $is_edge || ( $is_opera && ! wp_is_mobile() ) ) {
  3758 			} elseif ( $is_gecko || $is_chrome || $is_edge || ( $is_opera && ! wp_is_mobile() ) ) {
  3489 				$wp_rich_edit = true;
  3759 				$wp_rich_edit = true;
  3490 			}
  3760 			}
  3491 		}
  3761 		}
  3492 	}
  3762 	}
  3500 	 */
  3770 	 */
  3501 	return apply_filters( 'user_can_richedit', $wp_rich_edit );
  3771 	return apply_filters( 'user_can_richedit', $wp_rich_edit );
  3502 }
  3772 }
  3503 
  3773 
  3504 /**
  3774 /**
  3505  * Find out which editor should be displayed by default.
  3775  * Finds out which editor should be displayed by default.
  3506  *
  3776  *
  3507  * Works out which of the two editors to display as the current editor for a
  3777  * Works out which of the editors to display as the current editor for a
  3508  * user. The 'html' setting is for the "Text" editor tab.
  3778  * user. The 'html' setting is for the "Text" editor tab.
  3509  *
  3779  *
  3510  * @since 2.5.0
  3780  * @since 2.5.0
  3511  *
  3781  *
  3512  * @return string Either 'tinymce', or 'html', or 'test'
  3782  * @return string Either 'tinymce', 'html', or 'test'
  3513  */
  3783  */
  3514 function wp_default_editor() {
  3784 function wp_default_editor() {
  3515 	$r = user_can_richedit() ? 'tinymce' : 'html'; // Defaults.
  3785 	$r = user_can_richedit() ? 'tinymce' : 'html'; // Defaults.
  3516 	if ( wp_get_current_user() ) { // Look for cookie.
  3786 	if ( wp_get_current_user() ) { // Look for cookie.
  3517 		$ed = get_user_setting( 'editor', 'tinymce' );
  3787 		$ed = get_user_setting( 'editor', 'tinymce' );
  3572 
  3842 
  3573 	_WP_Editors::enqueue_default_editor();
  3843 	_WP_Editors::enqueue_default_editor();
  3574 }
  3844 }
  3575 
  3845 
  3576 /**
  3846 /**
  3577  * Enqueue assets needed by the code editor for the given settings.
  3847  * Enqueues assets needed by the code editor for the given settings.
  3578  *
  3848  *
  3579  * @since 4.9.0
  3849  * @since 4.9.0
  3580  *
  3850  *
  3581  * @see wp_enqueue_editor()
  3851  * @see wp_enqueue_editor()
  3582  * @see wp_get_code_editor_settings();
  3852  * @see wp_get_code_editor_settings();
  3665 
  3935 
  3666 	return $settings;
  3936 	return $settings;
  3667 }
  3937 }
  3668 
  3938 
  3669 /**
  3939 /**
  3670  * Generate and return code editor settings.
  3940  * Generates and returns code editor settings.
  3671  *
  3941  *
  3672  * @since 5.0.0
  3942  * @since 5.0.0
  3673  *
  3943  *
  3674  * @see wp_enqueue_code_editor()
  3944  * @see wp_enqueue_code_editor()
  3675  *
  3945  *
  3765 
  4035 
  3766 		// Remap MIME types to ones that CodeMirror modes will recognize.
  4036 		// Remap MIME types to ones that CodeMirror modes will recognize.
  3767 		if ( 'application/x-patch' === $type || 'text/x-patch' === $type ) {
  4037 		if ( 'application/x-patch' === $type || 'text/x-patch' === $type ) {
  3768 			$type = 'text/x-diff';
  4038 			$type = 'text/x-diff';
  3769 		}
  4039 		}
  3770 	} elseif ( isset( $args['file'] ) && false !== strpos( basename( $args['file'] ), '.' ) ) {
  4040 	} elseif ( isset( $args['file'] ) && str_contains( basename( $args['file'] ), '.' ) ) {
  3771 		$extension = strtolower( pathinfo( $args['file'], PATHINFO_EXTENSION ) );
  4041 		$extension = strtolower( pathinfo( $args['file'], PATHINFO_EXTENSION ) );
  3772 		foreach ( wp_get_mime_types() as $exts => $mime ) {
  4042 		foreach ( wp_get_mime_types() as $exts => $mime ) {
  3773 			if ( preg_match( '!^(' . $exts . ')$!i', $extension ) ) {
  4043 			if ( preg_match( '!^(' . $exts . ')$!i', $extension ) ) {
  3774 				$type = $mime;
  4044 				$type = $mime;
  3775 				break;
  4045 				break;
  3901 				'lint'              => true,
  4171 				'lint'              => true,
  3902 				'autoCloseBrackets' => true,
  4172 				'autoCloseBrackets' => true,
  3903 				'matchBrackets'     => true,
  4173 				'matchBrackets'     => true,
  3904 			)
  4174 			)
  3905 		);
  4175 		);
  3906 	} elseif ( false !== strpos( $type, 'json' ) ) {
  4176 	} elseif ( str_contains( $type, 'json' ) ) {
  3907 		$settings['codemirror'] = array_merge(
  4177 		$settings['codemirror'] = array_merge(
  3908 			$settings['codemirror'],
  4178 			$settings['codemirror'],
  3909 			array(
  4179 			array(
  3910 				'mode'              => array(
  4180 				'mode'              => array(
  3911 					'name' => 'javascript',
  4181 					'name' => 'javascript',
  3918 		if ( 'application/ld+json' === $type ) {
  4188 		if ( 'application/ld+json' === $type ) {
  3919 			$settings['codemirror']['mode']['jsonld'] = true;
  4189 			$settings['codemirror']['mode']['jsonld'] = true;
  3920 		} else {
  4190 		} else {
  3921 			$settings['codemirror']['mode']['json'] = true;
  4191 			$settings['codemirror']['mode']['json'] = true;
  3922 		}
  4192 		}
  3923 	} elseif ( false !== strpos( $type, 'jsx' ) ) {
  4193 	} elseif ( str_contains( $type, 'jsx' ) ) {
  3924 		$settings['codemirror'] = array_merge(
  4194 		$settings['codemirror'] = array_merge(
  3925 			$settings['codemirror'],
  4195 			$settings['codemirror'],
  3926 			array(
  4196 			array(
  3927 				'mode'              => 'jsx',
  4197 				'mode'              => 'jsx',
  3928 				'autoCloseBrackets' => true,
  4198 				'autoCloseBrackets' => true,
  3964 				'mode'              => 'sql',
  4234 				'mode'              => 'sql',
  3965 				'autoCloseBrackets' => true,
  4235 				'autoCloseBrackets' => true,
  3966 				'matchBrackets'     => true,
  4236 				'matchBrackets'     => true,
  3967 			)
  4237 			)
  3968 		);
  4238 		);
  3969 	} elseif ( false !== strpos( $type, 'xml' ) ) {
  4239 	} elseif ( str_contains( $type, 'xml' ) ) {
  3970 		$settings['codemirror'] = array_merge(
  4240 		$settings['codemirror'] = array_merge(
  3971 			$settings['codemirror'],
  4241 			$settings['codemirror'],
  3972 			array(
  4242 			array(
  3973 				'mode'              => 'xml',
  4243 				'mode'              => 'xml',
  3974 				'autoCloseBrackets' => true,
  4244 				'autoCloseBrackets' => true,
  4080  * information for the page.
  4350  * information for the page.
  4081  *
  4351  *
  4082  * @since 4.3.0
  4352  * @since 4.3.0
  4083  *
  4353  *
  4084  * @param string $doctype Optional. The type of HTML document. Accepts 'xhtml' or 'html'. Default 'html'.
  4354  * @param string $doctype Optional. The type of HTML document. Accepts 'xhtml' or 'html'. Default 'html'.
       
  4355  * @return string A space-separated list of language attributes.
  4085  */
  4356  */
  4086 function get_language_attributes( $doctype = 'html' ) {
  4357 function get_language_attributes( $doctype = 'html' ) {
  4087 	$attributes = array();
  4358 	$attributes = array();
  4088 
  4359 
  4089 	if ( function_exists( 'is_rtl' ) && is_rtl() ) {
  4360 	if ( function_exists( 'is_rtl' ) && is_rtl() ) {
  4195  *     @type bool   $show_all           Whether to show all pages. Default false.
  4466  *     @type bool   $show_all           Whether to show all pages. Default false.
  4196  *     @type int    $end_size           How many numbers on either the start and the end list edges.
  4467  *     @type int    $end_size           How many numbers on either the start and the end list edges.
  4197  *                                      Default 1.
  4468  *                                      Default 1.
  4198  *     @type int    $mid_size           How many numbers to either side of the current pages. Default 2.
  4469  *     @type int    $mid_size           How many numbers to either side of the current pages. Default 2.
  4199  *     @type bool   $prev_next          Whether to include the previous and next links in the list. Default true.
  4470  *     @type bool   $prev_next          Whether to include the previous and next links in the list. Default true.
  4200  *     @type bool   $prev_text          The previous page text. Default '&laquo; Previous'.
  4471  *     @type string $prev_text          The previous page text. Default '&laquo; Previous'.
  4201  *     @type bool   $next_text          The next page text. Default 'Next &raquo;'.
  4472  *     @type string $next_text          The next page text. Default 'Next &raquo;'.
  4202  *     @type string $type               Controls format of the returned value. Possible values are 'plain',
  4473  *     @type string $type               Controls format of the returned value. Possible values are 'plain',
  4203  *                                      'array' and 'list'. Default is 'plain'.
  4474  *                                      'array' and 'list'. Default is 'plain'.
  4204  *     @type array  $add_args           An array of query args to add. Default false.
  4475  *     @type array  $add_args           An array of query args to add. Default false.
  4205  *     @type string $add_fragment       A string to append to each link. Default empty.
  4476  *     @type string $add_fragment       A string to append to each link. Default empty.
  4206  *     @type string $before_page_number A string to appear before the page number. Default empty.
  4477  *     @type string $before_page_number A string to appear before the page number. Default empty.
  4207  *     @type string $after_page_number  A string to append after the page number. Default empty.
  4478  *     @type string $after_page_number  A string to append after the page number. Default empty.
  4208  * }
  4479  * }
  4209  * @return string|array|void String of page links or array of page links, depending on 'type' argument.
  4480  * @return string|string[]|void String of page links or array of page links, depending on 'type' argument.
  4210  *                           Void if total number of pages is less than 2.
  4481  *                              Void if total number of pages is less than 2.
  4211  */
  4482  */
  4212 function paginate_links( $args = '' ) {
  4483 function paginate_links( $args = '' ) {
  4213 	global $wp_query, $wp_rewrite;
  4484 	global $wp_query, $wp_rewrite;
  4214 
  4485 
  4215 	// Setting up default values based on the current URL.
  4486 	// Setting up default values based on the current URL.
  4551 			'base'    => '#f3f2f1',
  4822 			'base'    => '#f3f2f1',
  4552 			'focus'   => '#fff',
  4823 			'focus'   => '#fff',
  4553 			'current' => '#fff',
  4824 			'current' => '#fff',
  4554 		)
  4825 		)
  4555 	);
  4826 	);
  4556 
       
  4557 }
  4827 }
  4558 
  4828 
  4559 /**
  4829 /**
  4560  * Displays the URL of a WordPress admin CSS file.
  4830  * Displays the URL of a WordPress admin CSS file.
  4561  *
  4831  *
  4562  * @see WP_Styles::_css_href and its {@see 'style_loader_src'} filter.
  4832  * @see WP_Styles::_css_href() and its {@see 'style_loader_src'} filter.
  4563  *
  4833  *
  4564  * @since 2.3.0
  4834  * @since 2.3.0
  4565  *
  4835  *
  4566  * @param string $file file relative to wp-admin/ without its ".css" extension.
  4836  * @param string $file file relative to wp-admin/ without its ".css" extension.
  4567  * @return string
  4837  * @return string
  4605  *                           to wp-admin/. Defaults to 'wp-admin'.
  4875  *                           to wp-admin/. Defaults to 'wp-admin'.
  4606  * @param bool   $force_echo Optional. Force the stylesheet link to be printed rather than enqueued.
  4876  * @param bool   $force_echo Optional. Force the stylesheet link to be printed rather than enqueued.
  4607  */
  4877  */
  4608 function wp_admin_css( $file = 'wp-admin', $force_echo = false ) {
  4878 function wp_admin_css( $file = 'wp-admin', $force_echo = false ) {
  4609 	// For backward compatibility.
  4879 	// For backward compatibility.
  4610 	$handle = 0 === strpos( $file, 'css/' ) ? substr( $file, 4 ) : $file;
  4880 	$handle = str_starts_with( $file, 'css/' ) ? substr( $file, 4 ) : $file;
  4611 
  4881 
  4612 	if ( wp_styles()->query( $handle ) ) {
  4882 	if ( wp_styles()->query( $handle ) ) {
  4613 		if ( $force_echo || did_action( 'wp_print_styles' ) ) {
  4883 		if ( $force_echo || did_action( 'wp_print_styles' ) ) {
  4614 			// We already printed the style queue. Print this one immediately.
  4884 			// We already printed the style queue. Print this one immediately.
  4615 			wp_print_styles( $handle );
  4885 			wp_print_styles( $handle );
  4684 	 */
  4954 	 */
  4685 	the_generator( apply_filters( 'wp_generator_type', 'xhtml' ) );
  4955 	the_generator( apply_filters( 'wp_generator_type', 'xhtml' ) );
  4686 }
  4956 }
  4687 
  4957 
  4688 /**
  4958 /**
  4689  * Display the generator XML or Comment for RSS, ATOM, etc.
  4959  * Displays the generator XML or Comment for RSS, ATOM, etc.
  4690  *
  4960  *
  4691  * Returns the correct generator type for the requested output format. Allows
  4961  * Returns the correct generator type for the requested output format. Allows
  4692  * for a plugin to filter generators overall the {@see 'the_generator'} filter.
  4962  * for a plugin to filter generators overall the {@see 'the_generator'} filter.
  4693  *
  4963  *
  4694  * @since 2.5.0
  4964  * @since 2.5.0
  4757 			break;
  5027 			break;
  4758 		case 'atom':
  5028 		case 'atom':
  4759 			$gen = '<generator uri="https://wordpress.org/" version="' . esc_attr( get_bloginfo_rss( 'version' ) ) . '">WordPress</generator>';
  5029 			$gen = '<generator uri="https://wordpress.org/" version="' . esc_attr( get_bloginfo_rss( 'version' ) ) . '">WordPress</generator>';
  4760 			break;
  5030 			break;
  4761 		case 'rss2':
  5031 		case 'rss2':
  4762 			$gen = '<generator>' . esc_url_raw( 'https://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) ) . '</generator>';
  5032 			$gen = '<generator>' . sanitize_url( 'https://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) ) . '</generator>';
  4763 			break;
  5033 			break;
  4764 		case 'rdf':
  5034 		case 'rdf':
  4765 			$gen = '<admin:generatorAgent rdf:resource="' . esc_url_raw( 'https://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) ) . '" />';
  5035 			$gen = '<admin:generatorAgent rdf:resource="' . sanitize_url( 'https://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) ) . '" />';
  4766 			break;
  5036 			break;
  4767 		case 'comment':
  5037 		case 'comment':
  4768 			$gen = '<!-- generator="WordPress/' . esc_attr( get_bloginfo( 'version' ) ) . '" -->';
  5038 			$gen = '<!-- generator="WordPress/' . esc_attr( get_bloginfo( 'version' ) ) . '" -->';
  4769 			break;
  5039 			break;
  4770 		case 'export':
  5040 		case 'export':
  4804  * @since 1.0.0
  5074  * @since 1.0.0
  4805  *
  5075  *
  4806  * @param mixed $checked One of the values to compare.
  5076  * @param mixed $checked One of the values to compare.
  4807  * @param mixed $current Optional. The other value to compare if not just true.
  5077  * @param mixed $current Optional. The other value to compare if not just true.
  4808  *                       Default true.
  5078  *                       Default true.
  4809  * @param bool  $echo    Optional. Whether to echo or just return the string.
  5079  * @param bool  $display Optional. Whether to echo or just return the string.
  4810  *                       Default true.
  5080  *                       Default true.
  4811  * @return string HTML attribute or empty string.
  5081  * @return string HTML attribute or empty string.
  4812  */
  5082  */
  4813 function checked( $checked, $current = true, $echo = true ) {
  5083 function checked( $checked, $current = true, $display = true ) {
  4814 	return __checked_selected_helper( $checked, $current, $echo, 'checked' );
  5084 	return __checked_selected_helper( $checked, $current, $display, 'checked' );
  4815 }
  5085 }
  4816 
  5086 
  4817 /**
  5087 /**
  4818  * Outputs the HTML selected attribute.
  5088  * Outputs the HTML selected attribute.
  4819  *
  5089  *
  4822  * @since 1.0.0
  5092  * @since 1.0.0
  4823  *
  5093  *
  4824  * @param mixed $selected One of the values to compare.
  5094  * @param mixed $selected One of the values to compare.
  4825  * @param mixed $current  Optional. The other value to compare if not just true.
  5095  * @param mixed $current  Optional. The other value to compare if not just true.
  4826  *                        Default true.
  5096  *                        Default true.
  4827  * @param bool  $echo     Optional. Whether to echo or just return the string.
  5097  * @param bool  $display  Optional. Whether to echo or just return the string.
  4828  *                        Default true.
  5098  *                        Default true.
  4829  * @return string HTML attribute or empty string.
  5099  * @return string HTML attribute or empty string.
  4830  */
  5100  */
  4831 function selected( $selected, $current = true, $echo = true ) {
  5101 function selected( $selected, $current = true, $display = true ) {
  4832 	return __checked_selected_helper( $selected, $current, $echo, 'selected' );
  5102 	return __checked_selected_helper( $selected, $current, $display, 'selected' );
  4833 }
  5103 }
  4834 
  5104 
  4835 /**
  5105 /**
  4836  * Outputs the HTML disabled attribute.
  5106  * Outputs the HTML disabled attribute.
  4837  *
  5107  *
  4840  * @since 3.0.0
  5110  * @since 3.0.0
  4841  *
  5111  *
  4842  * @param mixed $disabled One of the values to compare.
  5112  * @param mixed $disabled One of the values to compare.
  4843  * @param mixed $current  Optional. The other value to compare if not just true.
  5113  * @param mixed $current  Optional. The other value to compare if not just true.
  4844  *                        Default true.
  5114  *                        Default true.
  4845  * @param bool  $echo     Optional. Whether to echo or just return the string.
  5115  * @param bool  $display  Optional. Whether to echo or just return the string.
  4846  *                        Default true.
  5116  *                        Default true.
  4847  * @return string HTML attribute or empty string.
  5117  * @return string HTML attribute or empty string.
  4848  */
  5118  */
  4849 function disabled( $disabled, $current = true, $echo = true ) {
  5119 function disabled( $disabled, $current = true, $display = true ) {
  4850 	return __checked_selected_helper( $disabled, $current, $echo, 'disabled' );
  5120 	return __checked_selected_helper( $disabled, $current, $display, 'disabled' );
  4851 }
  5121 }
  4852 
  5122 
  4853 /**
  5123 /**
  4854  * Outputs the HTML readonly attribute.
  5124  * Outputs the HTML readonly attribute.
  4855  *
  5125  *
  4856  * Compares the first two arguments and if identical marks as readonly.
  5126  * Compares the first two arguments and if identical marks as readonly.
  4857  *
  5127  *
  4858  * @since 5.9.0
  5128  * @since 5.9.0
  4859  *
  5129  *
  4860  * @param mixed $readonly One of the values to compare.
  5130  * @param mixed $readonly_value One of the values to compare.
  4861  * @param mixed $current  Optional. The other value to compare if not just true.
  5131  * @param mixed $current        Optional. The other value to compare if not just true.
  4862  *                        Default true.
  5132  *                              Default true.
  4863  * @param bool  $echo     Optional. Whether to echo or just return the string.
  5133  * @param bool  $display        Optional. Whether to echo or just return the string.
  4864  *                        Default true.
  5134  *                              Default true.
  4865  * @return string HTML attribute or empty string.
  5135  * @return string HTML attribute or empty string.
  4866  */
  5136  */
  4867 function wp_readonly( $readonly, $current = true, $echo = true ) {
  5137 function wp_readonly( $readonly_value, $current = true, $display = true ) {
  4868 	return __checked_selected_helper( $readonly, $current, $echo, 'readonly' );
  5138 	return __checked_selected_helper( $readonly_value, $current, $display, 'readonly' );
  4869 }
  5139 }
  4870 
  5140 
  4871 /*
  5141 /*
  4872  * Include a compat `readonly()` function on PHP < 8.1. Since PHP 8.1,
  5142  * Include a compat `readonly()` function on PHP < 8.1. Since PHP 8.1,
  4873  * `readonly` is a reserved keyword and cannot be used as a function name.
  5143  * `readonly` is a reserved keyword and cannot be used as a function name.
  4886  * @since 2.8.0
  5156  * @since 2.8.0
  4887  * @access private
  5157  * @access private
  4888  *
  5158  *
  4889  * @param mixed  $helper  One of the values to compare.
  5159  * @param mixed  $helper  One of the values to compare.
  4890  * @param mixed  $current The other value to compare if not just true.
  5160  * @param mixed  $current The other value to compare if not just true.
  4891  * @param bool   $echo    Whether to echo or just return the string.
  5161  * @param bool   $display Whether to echo or just return the string.
  4892  * @param string $type    The type of checked|selected|disabled|readonly we are doing.
  5162  * @param string $type    The type of checked|selected|disabled|readonly we are doing.
  4893  * @return string HTML attribute or empty string.
  5163  * @return string HTML attribute or empty string.
  4894  */
  5164  */
  4895 function __checked_selected_helper( $helper, $current, $echo, $type ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore
  5165 function __checked_selected_helper( $helper, $current, $display, $type ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore
  4896 	if ( (string) $helper === (string) $current ) {
  5166 	if ( (string) $helper === (string) $current ) {
  4897 		$result = " $type='$type'";
  5167 		$result = " $type='$type'";
  4898 	} else {
  5168 	} else {
  4899 		$result = '';
  5169 		$result = '';
  4900 	}
  5170 	}
  4901 
  5171 
  4902 	if ( $echo ) {
  5172 	if ( $display ) {
  4903 		echo $result;
  5173 		echo $result;
  4904 	}
  5174 	}
  4905 
  5175 
  4906 	return $result;
  5176 	return $result;
  4907 }
  5177 }
  4908 
  5178 
  4909 /**
  5179 /**
  4910  * Default settings for heartbeat
  5180  * Assigns a visual indicator for required form fields.
  4911  *
  5181  *
  4912  * Outputs the nonce used in the heartbeat XHR
  5182  * @since 6.1.0
       
  5183  *
       
  5184  * @return string Indicator glyph wrapped in a `span` tag.
       
  5185  */
       
  5186 function wp_required_field_indicator() {
       
  5187 	/* translators: Character to identify required form fields. */
       
  5188 	$glyph     = __( '*' );
       
  5189 	$indicator = '<span class="required">' . esc_html( $glyph ) . '</span>';
       
  5190 
       
  5191 	/**
       
  5192 	 * Filters the markup for a visual indicator of required form fields.
       
  5193 	 *
       
  5194 	 * @since 6.1.0
       
  5195 	 *
       
  5196 	 * @param string $indicator Markup for the indicator element.
       
  5197 	 */
       
  5198 	return apply_filters( 'wp_required_field_indicator', $indicator );
       
  5199 }
       
  5200 
       
  5201 /**
       
  5202  * Creates a message to explain required form fields.
       
  5203  *
       
  5204  * @since 6.1.0
       
  5205  *
       
  5206  * @return string Message text and glyph wrapped in a `span` tag.
       
  5207  */
       
  5208 function wp_required_field_message() {
       
  5209 	$message = sprintf(
       
  5210 		'<span class="required-field-message">%s</span>',
       
  5211 		/* translators: %s: Asterisk symbol (*). */
       
  5212 		sprintf( __( 'Required fields are marked %s' ), wp_required_field_indicator() )
       
  5213 	);
       
  5214 
       
  5215 	/**
       
  5216 	 * Filters the message to explain required form fields.
       
  5217 	 *
       
  5218 	 * @since 6.1.0
       
  5219 	 *
       
  5220 	 * @param string $message Message text and glyph wrapped in a `span` tag.
       
  5221 	 */
       
  5222 	return apply_filters( 'wp_required_field_message', $message );
       
  5223 }
       
  5224 
       
  5225 /**
       
  5226  * Default settings for heartbeat.
       
  5227  *
       
  5228  * Outputs the nonce used in the heartbeat XHR.
  4913  *
  5229  *
  4914  * @since 3.6.0
  5230  * @since 3.6.0
  4915  *
  5231  *
  4916  * @param array $settings
  5232  * @param array $settings
  4917  * @return array Heartbeat settings.
  5233  * @return array Heartbeat settings.