From 252628652e7706cabb3913f4aa57218fa5012e4b Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 18 Sep 2019 14:50:56 +0000 Subject: [PATCH] Script Loader: Introduce HTML5 support for scripts and styles. When a theme declares HTML5 support for script and styles via `add_theme_support( 'html5', array( 'script', 'style' ) )`, the `type="text/javascript"` and `type="text/css"` attributes are omitted. These attributes are unnecessary in HTML5 and cause warnings in the W3C Markup Validation Service. Props sasiddiqui, swissspidy, knutsp, SergeyBiryukov. See #42804. Built from https://develop.svn.wordpress.org/trunk@46164 git-svn-id: http://core.svn.wordpress.org/trunk@45976 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/admin-bar.php | 7 +-- wp-includes/class.wp-scripts.php | 33 +++++++++--- wp-includes/class.wp-styles.php | 52 +++++++++++++++++-- wp-includes/embed.php | 6 ++- wp-includes/formatting.php | 11 ++-- wp-includes/media.php | 4 +- wp-includes/script-loader.php | 14 ++--- wp-includes/theme.php | 39 +++++++++----- wp-includes/version.php | 2 +- .../widgets/class-wp-widget-archives.php | 4 +- .../widgets/class-wp-widget-categories.php | 4 +- .../class-wp-widget-recent-comments.php | 10 ++-- 12 files changed, 138 insertions(+), 48 deletions(-) diff --git a/wp-includes/admin-bar.php b/wp-includes/admin-bar.php index c16ffc99a1..19d668c633 100644 --- a/wp-includes/admin-bar.php +++ b/wp-includes/admin-bar.php @@ -1117,8 +1117,9 @@ function wp_admin_bar_add_secondary_groups( $wp_admin_bar ) { * @since 3.1.0 */ function wp_admin_bar_header() { + $type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"'; ?> - + media="print">#wpadminbar { display:none; } -\n", esc_attr( $handle ), $inline_style ); + $inline_style_tag = sprintf( + "\n", + esc_attr( $handle ), + $this->type_attr, + $inline_style + ); } else { $inline_style_tag = ''; } @@ -197,9 +217,17 @@ class WP_Styles extends WP_Dependencies { } $rel = isset( $obj->extra['alt'] ) && $obj->extra['alt'] ? 'alternate stylesheet' : 'stylesheet'; - $title = isset( $obj->extra['title'] ) ? "title='" . esc_attr( $obj->extra['title'] ) . "'" : ''; + $title = isset( $obj->extra['title'] ) ? sprintf( "title='%s'", esc_attr( $obj->extra['title'] ) ) : ''; - $tag = "\n"; + $tag = sprintf( + "\n", + $rel, + $handle, + $title, + $href, + $this->type_attr, + $media + ); /** * Filters the HTML link tag of an enqueued style. @@ -223,7 +251,16 @@ class WP_Styles extends WP_Dependencies { $rtl_href = $this->_css_href( $obj->extra['rtl'], $ver, "$handle-rtl" ); } - $rtl_tag = "\n"; + $rtl_tag = sprintf( + "\n", + $rel, + $handle, + $title, + $rtl_href, + $this->type_attr, + $media + ); + /** This filter is documented in wp-includes/class.wp-styles.php */ $rtl_tag = apply_filters( 'style_loader_tag', $rtl_tag, $handle, $rtl_href, $media ); @@ -298,7 +335,12 @@ class WP_Styles extends WP_Dependencies { return $output; } - printf( "\n", esc_attr( $handle ), $output ); + printf( + "\n", + esc_attr( $handle ), + $this->type_attr, + $output + ); return true; } diff --git a/wp-includes/embed.php b/wp-includes/embed.php index c46b4b1cec..06e4472e44 100644 --- a/wp-includes/embed.php +++ b/wp-includes/embed.php @@ -1000,8 +1000,9 @@ function enqueue_embed_scripts() { * @since 4.4.0 */ function print_embed_styles() { + $type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"'; ?> - \n"; } diff --git a/wp-includes/theme.php b/wp-includes/theme.php index 730ff902d6..e4cc8802f5 100644 --- a/wp-includes/theme.php +++ b/wp-includes/theme.php @@ -702,7 +702,14 @@ function locale_stylesheet() { if ( empty( $stylesheet ) ) { return; } - echo ''; + + $type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"'; + + printf( + '', + $stylesheet, + $type_attr + ); } /** @@ -1641,7 +1648,8 @@ function _custom_background_cb() { if ( ! $background && ! $color ) { if ( is_customize_preview() ) { - echo ''; + $type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"'; + printf( '', $type_attr ); } return; } @@ -1693,9 +1701,11 @@ function _custom_background_cb() { $attachment = " background-attachment: $attachment;"; $style .= $image . $position . $size . $repeat . $attachment; + + $type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"'; } ?> - } function wp_custom_css_cb() { $styles = wp_get_custom_css(); if ( $styles || is_customize_preview() ) : + $type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"'; ?> - - - .recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}', + $type_attr + ); } /**