X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/febc815b2c9d85be5717da9e8d164bd2daa97e31..16e7b37c7914d753890c1a05a9335f3b43751eb8:/wp-includes/general-template.php diff --git a/wp-includes/general-template.php b/wp-includes/general-template.php index a5d5ea7d..ed91e5bd 100644 --- a/wp-includes/general-template.php +++ b/wp-includes/general-template.php @@ -30,7 +30,7 @@ function get_header( $name = null ) { * @since 2.1.0 * @since 2.8.0 $name parameter added. * - * @param string $name Name of the specific header file to use. + * @param string|null $name Name of the specific header file to use. null for the default header. */ do_action( 'get_header', $name ); @@ -69,7 +69,7 @@ function get_footer( $name = null ) { * @since 2.1.0 * @since 2.8.0 $name parameter added. * - * @param string $name Name of the specific footer file to use. + * @param string|null $name Name of the specific footer file to use. null for the default footer. */ do_action( 'get_footer', $name ); @@ -108,7 +108,7 @@ function get_sidebar( $name = null ) { * @since 2.2.0 * @since 2.8.0 $name parameter added. * - * @param string $name Name of the specific sidebar file to use. + * @param string|null $name Name of the specific sidebar file to use. null for the default sidebar. */ do_action( 'get_sidebar', $name ); @@ -152,8 +152,8 @@ function get_template_part( $slug, $name = null ) { * * @since 3.0.0 * - * @param string $slug The slug name for the generic template. - * @param string $name The name of the specialized template. + * @param string $slug The slug name for the generic template. + * @param string|null $name The name of the specialized template. */ do_action( "get_template_part_{$slug}", $slug, $name ); @@ -383,7 +383,7 @@ function wp_registration_url() { * @type string $redirect URL to redirect to. Must be absolute, as in "https://example.com/mypage/". * Default is to redirect back to the request URI. * @type string $form_id ID attribute value for the form. Default 'loginform'. - * @type string $label_username Label for the username or email address field. Default 'Username or Email'. + * @type string $label_username Label for the username or email address field. Default 'Username or Email Address'. * @type string $label_password Label for the password field. Default 'Password'. * @type string $label_remember Label for the remember field. Default 'Remember Me'. * @type string $label_log_in Label for the submit button. Default 'Log In'. @@ -405,7 +405,7 @@ function wp_login_form( $args = array() ) { // Default 'redirect' value takes the user back to the request URI. 'redirect' => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'form_id' => 'loginform', - 'label_username' => __( 'Username or Email' ), + 'label_username' => __( 'Username or Email Address' ), 'label_password' => __( 'Password' ), 'label_remember' => __( 'Remember Me' ), 'label_log_in' => __( 'Log In' ), @@ -481,7 +481,7 @@ function wp_login_form( $args = array() ) { ' . $login_form_middle . ' ' . ( $args['remember'] ? '

' : '' ) . '

- +

' . $login_form_bottom . ' @@ -783,8 +783,11 @@ function get_bloginfo( $show = '', $filter = 'raw' ) { * @return string Site Icon URL. */ function get_site_icon_url( $size = 512, $url = '', $blog_id = 0 ) { - if ( is_multisite() && (int) $blog_id !== get_current_blog_id() ) { + $switched_blog = false; + + if ( is_multisite() && ! empty( $blog_id ) && (int) $blog_id !== get_current_blog_id() ) { switch_to_blog( $blog_id ); + $switched_blog = true; } $site_icon_id = get_option( 'site_icon' ); @@ -798,7 +801,7 @@ function get_site_icon_url( $size = 512, $url = '', $blog_id = 0 ) { $url = wp_get_attachment_image_url( $site_icon_id, $size_data ); } - if ( is_multisite() && ms_is_switched() ) { + if ( $switched_blog ) { restore_current_blog(); } @@ -848,13 +851,16 @@ function has_site_icon( $blog_id = 0 ) { * @return bool Whether the site has a custom logo or not. */ function has_custom_logo( $blog_id = 0 ) { - if ( is_multisite() && (int) $blog_id !== get_current_blog_id() ) { + $switched_blog = false; + + if ( is_multisite() && ! empty( $blog_id ) && (int) $blog_id !== get_current_blog_id() ) { switch_to_blog( $blog_id ); + $switched_blog = true; } $custom_logo_id = get_theme_mod( 'custom_logo' ); - if ( is_multisite() && ms_is_switched() ) { + if ( $switched_blog ) { restore_current_blog(); } @@ -871,9 +877,11 @@ function has_custom_logo( $blog_id = 0 ) { */ function get_custom_logo( $blog_id = 0 ) { $html = ''; + $switched_blog = false; - if ( is_multisite() && (int) $blog_id !== get_current_blog_id() ) { + if ( is_multisite() && ! empty( $blog_id ) && (int) $blog_id !== get_current_blog_id() ) { switch_to_blog( $blog_id ); + $switched_blog = true; } $custom_logo_id = get_theme_mod( 'custom_logo' ); @@ -896,7 +904,7 @@ function get_custom_logo( $blog_id = 0 ) { ); } - if ( is_multisite() && ms_is_switched() ) { + if ( $switched_blog ) { restore_current_blog(); } @@ -1453,16 +1461,22 @@ function the_archive_title( $before = '', $after = '' ) { */ function get_the_archive_title() { if ( is_category() ) { + /* translators: Category archive title. 1: Category name */ $title = sprintf( __( 'Category: %s' ), single_cat_title( '', false ) ); } elseif ( is_tag() ) { + /* translators: Tag archive title. 1: Tag name */ $title = sprintf( __( 'Tag: %s' ), single_tag_title( '', false ) ); } elseif ( is_author() ) { + /* translators: Author archive title. 1: Author name */ $title = sprintf( __( 'Author: %s' ), '' . get_the_author() . '' ); } elseif ( is_year() ) { + /* translators: Yearly archive title. 1: Year */ $title = sprintf( __( 'Year: %s' ), get_the_date( _x( 'Y', 'yearly archives date format' ) ) ); } elseif ( is_month() ) { + /* translators: Monthly archive title. 1: Month name and year */ $title = sprintf( __( 'Month: %s' ), get_the_date( _x( 'F Y', 'monthly archives date format' ) ) ); } elseif ( is_day() ) { + /* translators: Daily archive title. 1: Date */ $title = sprintf( __( 'Day: %s' ), get_the_date( _x( 'F j, Y', 'daily archives date format' ) ) ); } elseif ( is_tax( 'post_format' ) ) { if ( is_tax( 'post_format', 'post-format-aside' ) ) { @@ -1485,10 +1499,11 @@ function get_the_archive_title() { $title = _x( 'Chats', 'post format archive title' ); } } elseif ( is_post_type_archive() ) { + /* translators: Post type archive title. 1: Post type name */ $title = sprintf( __( 'Archives: %s' ), post_type_archive_title( '', false ) ); } elseif ( is_tax() ) { $tax = get_taxonomy( get_queried_object()->taxonomy ); - /* translators: 1: Taxonomy singular name, 2: Current taxonomy term */ + /* translators: Taxonomy term archive title. 1: Taxonomy singular name, 2: Current taxonomy term */ $title = sprintf( __( '%1$s: %2$s' ), $tax->labels->singular_name, single_term_title( '', false ) ); } else { $title = __( 'Archives' ); @@ -1505,7 +1520,7 @@ function get_the_archive_title() { } /** - * Display category, tag, or term description. + * Display category, tag, term, or author description. * * @since 4.1.0 * @@ -1522,23 +1537,30 @@ function the_archive_description( $before = '', $after = '' ) { } /** - * Retrieve category, tag, or term description. + * Retrieve category, tag, term, or author description. * * @since 4.1.0 + * @since 4.7.0 Added support for author archives. + * + * @see term_description() * * @return string Archive description. */ function get_the_archive_description() { + if ( is_author() ) { + $description = get_the_author_meta( 'description' ); + } else { + $description = term_description(); + } + /** * Filters the archive description. * * @since 4.1.0 * - * @see term_description() - * * @param string $description Archive description to be displayed. */ - return apply_filters( 'get_the_archive_description', term_description() ); + return apply_filters( 'get_the_archive_description', $description ); } /** @@ -1698,11 +1720,7 @@ function wp_get_archives( $args = '' ) { $output = ''; - $last_changed = wp_cache_get( 'last_changed', 'posts' ); - if ( ! $last_changed ) { - $last_changed = microtime(); - wp_cache_set( 'last_changed', $last_changed, 'posts' ); - } + $last_changed = wp_cache_get_last_changed( 'posts' ); $limit = $r['limit']; @@ -2040,6 +2058,7 @@ function get_calendar( $initial = true, $echo = true ) { if ( in_array( $day, $daywithpost ) ) { // any posts today? $date_format = date( _x( 'F j, Y', 'daily archives date format' ), strtotime( "{$thisyear}-{$thismonth}-{$day}" ) ); + /* translators: Post calendar label. 1: Date */ $label = sprintf( __( 'Posts published on %s' ), $date_format ); $calendar_output .= sprintf( '%s', @@ -2765,12 +2784,26 @@ function wp_site_icon() { return; } - $meta_tags = array( - sprintf( '', esc_url( get_site_icon_url( 32 ) ) ), - sprintf( '', esc_url( get_site_icon_url( 192 ) ) ), - sprintf( '', esc_url( get_site_icon_url( 180 ) ) ), - sprintf( '', esc_url( get_site_icon_url( 270 ) ) ), - ); + $meta_tags = array(); + $icon_32 = get_site_icon_url( 32 ); + if ( empty( $icon_32 ) && is_customize_preview() ) { + $icon_32 = '/favicon.ico'; // Serve default favicon URL in customizer so element can be updated for preview. + } + if ( $icon_32 ) { + $meta_tags[] = sprintf( '', esc_url( $icon_32 ) ); + } + $icon_192 = get_site_icon_url( 192 ); + if ( $icon_192 ) { + $meta_tags[] = sprintf( '', esc_url( $icon_192 ) ); + } + $icon_180 = get_site_icon_url( 180 ); + if ( $icon_180 ) { + $meta_tags[] = sprintf( '', esc_url( $icon_180 ) ); + } + $icon_270 = get_site_icon_url( 270 ); + if ( $icon_270 ) { + $meta_tags[] = sprintf( '', esc_url( $icon_270 ) ); + } /** * Filters the site icon meta tags, so Plugins can add their own. @@ -2812,9 +2845,11 @@ function wp_resource_hints() { * The path is removed in the foreach loop below. */ /** This filter is documented in wp-includes/formatting.php */ - $hints['dns-prefetch'][] = apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/2/svg/' ); + $hints['dns-prefetch'][] = apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/2.2.1/svg/' ); foreach ( $hints as $relation_type => $urls ) { + $unique_urls = array(); + /** * Filters domains and URLs for resource hints of relation type. * @@ -2826,16 +2861,31 @@ function wp_resource_hints() { $urls = apply_filters( 'wp_resource_hints', $urls, $relation_type ); foreach ( $urls as $key => $url ) { + $atts = array(); + + if ( is_array( $url ) ) { + if ( isset( $url['href'] ) ) { + $atts = $url; + $url = $url['href']; + } else { + continue; + } + } + $url = esc_url( $url, array( 'http', 'https' ) ); + if ( ! $url ) { - unset( $urls[ $key ] ); + continue; + } + + if ( isset( $unique_urls[ $url ] ) ) { continue; } if ( in_array( $relation_type, array( 'preconnect', 'dns-prefetch' ) ) ) { $parsed = wp_parse_url( $url ); + if ( empty( $parsed['host'] ) ) { - unset( $urls[ $key ] ); continue; } @@ -2847,13 +2897,34 @@ function wp_resource_hints() { } } - $urls[ $key ] = $url; + $atts['rel'] = $relation_type; + $atts['href'] = $url; + + $unique_urls[ $url ] = $atts; } - $urls = array_unique( $urls ); + foreach ( $unique_urls as $atts ) { + $html = ''; + + foreach ( $atts as $attr => $value ) { + if ( ! is_scalar( $value ) || + ( ! in_array( $attr, array( 'as', 'crossorigin', 'href', 'pr', 'rel', 'type' ), true ) && ! is_numeric( $attr )) + ) { + continue; + } + + $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); + + if ( ! is_string( $attr ) ) { + $html .= " $value"; + } else { + $html .= " $attr='$value'"; + } + } + + $html = trim( $html ); - foreach ( $urls as $url ) { - printf( "\n", $relation_type, $url ); + echo "\n"; } } } @@ -2892,21 +2963,21 @@ function wp_dependencies_unique_hosts() { } /** - * Whether the user should have a WYSIWIG editor. + * Whether the user can access the visual editor. * - * Checks that the user requires a WYSIWIG editor and that the editor is - * supported in the users browser. + * Checks if the user can access the visual editor and that it's supported by the user's browser. * * @since 2.0.0 * - * @global bool $wp_rich_edit - * @global bool $is_gecko - * @global bool $is_opera - * @global bool $is_safari - * @global bool $is_chrome - * @global bool $is_IE + * @global bool $wp_rich_edit Whether the user can access the visual editor. + * @global bool $is_gecko Whether the browser is Gecko-based. + * @global bool $is_opera Whether the browser is Opera. + * @global bool $is_safari Whether the browser is Safari. + * @global bool $is_chrome Whether the browser is Chrome. + * @global bool $is_IE Whether the browser is Internet Explorer. + * @global bool $is_edge Whether the browser is Microsoft Edge. * - * @return bool + * @return bool True if the user can access the visual editor, false otherwise. */ function user_can_richedit() { global $wp_rich_edit, $is_gecko, $is_opera, $is_safari, $is_chrome, $is_IE, $is_edge; @@ -2924,11 +2995,11 @@ function user_can_richedit() { } /** - * Filters whether the user can access the rich (Visual) editor. + * Filters whether the user can access the visual editor. * * @since 2.1.0 * - * @param bool $wp_rich_edit Whether the user can access to the rich (Visual) editor. + * @param bool $wp_rich_edit Whether the user can access the visual editor. */ return apply_filters( 'user_can_richedit', $wp_rich_edit ); } @@ -2955,7 +3026,7 @@ function wp_default_editor() { * * @since 2.5.0 * - * @param array $r An array of editors. Accepts 'tinymce', 'html', 'test'. + * @param string $r Which editor should be displayed by default. Either 'tinymce', 'html', or 'test'. */ return apply_filters( 'wp_default_editor', $r ); } @@ -2982,7 +3053,6 @@ function wp_default_editor() { function wp_editor( $content, $editor_id, $settings = array() ) { if ( ! class_exists( '_WP_Editors', false ) ) require( ABSPATH . WPINC . '/class-wp-editor.php' ); - _WP_Editors::editor($content, $editor_id, $settings); } @@ -3149,8 +3219,8 @@ function language_attributes( $doctype = 'html' ) { * Default 1. * @type int $mid_size How many numbers to either side of the current pages. Default 2. * @type bool $prev_next Whether to include the previous and next links in the list. Default true. - * @type bool $prev_text The previous page text. Default '« Previous'. - * @type bool $next_text The next page text. Default '« Previous'. + * @type bool $prev_text The previous page text. Default '« Previous'. + * @type bool $next_text The next page text. Default 'Next »'. * @type string $type Controls format of the returned value. Possible values are 'plain', * 'array' and 'list'. Default is 'plain'. * @type array $add_args An array of query args to add. Default false. @@ -3276,7 +3346,7 @@ function paginate_links( $args = '' ) { endif; endif; endfor; - if ( $args['prev_next'] && $current && ( $current < $total || -1 == $total ) ) : + if ( $args['prev_next'] && $current && $current < $total ) : $link = str_replace( '%_%', $args['format'], $args['base'] ); $link = str_replace( '%#%', $current + 1, $link ); if ( $add_args ) @@ -3347,8 +3417,6 @@ function wp_admin_css_color( $key, $name, $url, $colors = array(), $icons = arra * Registers the default Admin color schemes * * @since 3.0.0 - * - * @global string $wp_version */ function register_admin_color_schemes() { $suffix = is_rtl() ? '-rtl' : ''; @@ -3361,8 +3429,9 @@ function register_admin_color_schemes() { ); // Other color schemes are not available when running out of src - if ( false !== strpos( $GLOBALS['wp_version'], '-src' ) ) + if ( false !== strpos( get_bloginfo( 'version' ), '-src' ) ) { return; + } wp_admin_css_color( 'light', _x( 'Light', 'admin color scheme' ), admin_url( "css/colors/light/colors$suffix.css" ),