wp/wp-includes/class.wp-styles.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
--- a/wp/wp-includes/class.wp-styles.php	Tue Oct 22 16:11:46 2019 +0200
+++ b/wp/wp-includes/class.wp-styles.php	Tue Dec 15 13:49:49 2020 +0100
@@ -101,11 +101,30 @@
 	public $default_dirs;
 
 	/**
+	 * Holds a string which contains the type attribute for style tag.
+	 *
+	 * If the current theme does not declare HTML5 support for 'style',
+	 * then it initializes as `type='text/css'`.
+	 *
+	 * @since 5.3.0
+	 * @var string
+	 */
+	private $type_attr = '';
+
+	/**
 	 * Constructor.
 	 *
 	 * @since 2.6.0
 	 */
 	public function __construct() {
+		if (
+			function_exists( 'is_admin' ) && ! is_admin()
+		&&
+			function_exists( 'current_theme_supports' ) && ! current_theme_supports( 'html5', 'style' )
+		) {
+			$this->type_attr = " type='text/css'";
+		}
+
 		/**
 		 * Fires when the WP_Styles instance is initialized.
 		 *
@@ -120,13 +139,16 @@
 	 * Processes a style dependency.
 	 *
 	 * @since 2.6.0
+	 * @since 5.5.0 Added the `$group` parameter.
 	 *
 	 * @see WP_Dependencies::do_item()
 	 *
-	 * @param string $handle The style's registered handle.
+	 * @param string    $handle The style's registered handle.
+	 * @param int|false $group  Optional. Group level: level (int), no groups (false).
+	 *                          Default false.
 	 * @return bool True on success, false on failure.
 	 */
-	public function do_item( $handle ) {
+	public function do_item( $handle, $group = false ) {
 		if ( ! parent::do_item( $handle ) ) {
 			return false;
 		}
@@ -144,7 +166,8 @@
 		}
 
 		$src         = $obj->src;
-		$cond_before = $cond_after = '';
+		$cond_before = '';
+		$cond_after  = '';
 		$conditional = isset( $obj->extra['conditional'] ) ? $obj->extra['conditional'] : '';
 
 		if ( $conditional ) {
@@ -155,7 +178,12 @@
 		$inline_style = $this->print_inline_style( $handle, false );
 
 		if ( $inline_style ) {
-			$inline_style_tag = sprintf( "<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr( $handle ), $inline_style );
+			$inline_style_tag = sprintf(
+				"<style id='%s-inline-css'%s>\n%s\n</style>\n",
+				esc_attr( $handle ),
+				$this->type_attr,
+				$inline_style
+			);
 		} else {
 			$inline_style_tag = '';
 		}
@@ -196,7 +224,17 @@
 		}
 
 		$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 = sprintf(
+			"<link rel='%s' id='%s-css' %s href='%s'%s media='%s' />\n",
+			$rel,
+			$handle,
+			$title,
+			$href,
+			$this->type_attr,
+			$media
+		);
 
 		/**
 		 * Filters the HTML link tag of an enqueued style.
@@ -210,7 +248,7 @@
 		 * @param string $href   The stylesheet's source URL.
 		 * @param string $media  The stylesheet's media attribute.
 		 */
-		$tag = apply_filters( 'style_loader_tag', "<link rel='$rel' id='$handle-css' $title href='$href' type='text/css' media='$media' />\n", $handle, $href, $media );
+		$tag = apply_filters( 'style_loader_tag', $tag, $handle, $href, $media );
 
 		if ( 'rtl' === $this->text_direction && isset( $obj->extra['rtl'] ) && $obj->extra['rtl'] ) {
 			if ( is_bool( $obj->extra['rtl'] ) || 'replace' === $obj->extra['rtl'] ) {
@@ -220,10 +258,20 @@
 				$rtl_href = $this->_css_href( $obj->extra['rtl'], $ver, "$handle-rtl" );
 			}
 
+			$rtl_tag = sprintf(
+				"<link rel='%s' id='%s-rtl-css' %s href='%s'%s media='%s' />\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', "<link rel='$rel' id='$handle-rtl-css' $title href='$rtl_href' type='text/css' media='$media' />\n", $handle, $rtl_href, $media );
+			$rtl_tag = apply_filters( 'style_loader_tag', $rtl_tag, $handle, $rtl_href, $media );
 
-			if ( $obj->extra['rtl'] === 'replace' ) {
+			if ( 'replace' === $obj->extra['rtl'] ) {
 				$tag = $rtl_tag;
 			} else {
 				$tag .= $rtl_tag;
@@ -277,9 +325,10 @@
 	 * @since 3.3.0
 	 *
 	 * @param string $handle The style's registered handle.
-	 * @param bool   $echo   Optional. Whether to echo the inline style instead of just returning it.
-	 *                       Default true.
-	 * @return string|bool False if no data exists, inline styles if `$echo` is true, true otherwise.
+	 * @param bool   $echo   Optional. Whether to echo the inline style
+	 *                       instead of just returning it. Default true.
+	 * @return string|bool False if no data exists, inline styles if `$echo` is true,
+	 *                     true otherwise.
 	 */
 	public function print_inline_style( $handle, $echo = true ) {
 		$output = $this->get_data( $handle, 'after' );
@@ -294,7 +343,12 @@
 			return $output;
 		}
 
-		printf( "<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr( $handle ), $output );
+		printf(
+			"<style id='%s-inline-css'%s>\n%s\n</style>\n",
+			esc_attr( $handle ),
+			$this->type_attr,
+			$output
+		);
 
 		return true;
 	}
@@ -306,9 +360,11 @@
 	 *
 	 * @see WP_Dependencies::all_deps()
 	 *
-	 * @param mixed     $handles   Item handle and argument (string) or item handles and arguments (array of strings).
-	 * @param bool      $recursion Internal flag that function is calling itself.
-	 * @param int|false $group     Group level: (int) level, (false) no groups.
+	 * @param string|string[] $handles   Item handle (string) or item handles (array of strings).
+	 * @param bool            $recursion Optional. Internal flag that function is calling itself.
+	 *                                   Default false.
+	 * @param int|false       $group     Optional. Group level: level (int), no groups (false).
+	 *                                   Default false.
 	 * @return bool True on success, false on failure.
 	 */
 	public function all_deps( $handles, $recursion = false, $group = false ) {
@@ -331,8 +387,8 @@
 	 *
 	 * @since 2.6.0
 	 *
-	 * @param string $src The source of the enqueued style.
-	 * @param string $ver The version of the enqueued style.
+	 * @param string $src    The source of the enqueued style.
+	 * @param string $ver    The version of the enqueued style.
 	 * @param string $handle The style's registered handle.
 	 * @return string Style's fully-qualified URL.
 	 */
@@ -387,7 +443,7 @@
 	 *
 	 * @see WP_Dependencies::do_items()
 	 *
-	 * @return array Handles of items that have been processed.
+	 * @return string[] Handles of items that have been processed.
 	 */
 	public function do_footer_items() {
 		$this->do_items( false, 1 );