From c89962511b04fc93dda5e6c5996834906328ca8f Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 11 Aug 2018 17:42:24 +0000 Subject: [PATCH] Script/Style Dependencies: Simplify some logic in `WP_Styles::do_item()`. Combine repetitive assignments, make the code more consistent with `WP_Scripts::do_item()`. See #44551. Built from https://develop.svn.wordpress.org/trunk@43564 git-svn-id: http://core.svn.wordpress.org/trunk@43393 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class.wp-styles.php | 55 ++++++++++++++++++++------------- wp-includes/version.php | 2 +- 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/wp-includes/class.wp-styles.php b/wp-includes/class.wp-styles.php index aadf7669af..ef62f9553b 100644 --- a/wp-includes/class.wp-styles.php +++ b/wp-includes/class.wp-styles.php @@ -132,6 +132,7 @@ class WP_Styles extends WP_Dependencies { } $obj = $this->registered[ $handle ]; + if ( null === $obj->ver ) { $ver = ''; } else { @@ -142,12 +143,29 @@ class WP_Styles extends WP_Dependencies { $ver = $ver ? $ver . '&' . $this->args[ $handle ] : $this->args[ $handle ]; } + $src = $obj->src; + $cond_before = $cond_after = ''; + $conditional = isset( $obj->extra['conditional'] ) ? $obj->extra['conditional'] : ''; + + if ( $conditional ) { + $cond_before = "\n"; + } + + $inline_style = $this->print_inline_style( $handle, false ); + + if ( $inline_style ) { + $inline_style_tag = sprintf( "\n", esc_attr( $handle ), $inline_style ); + } else { + $inline_style_tag = ''; + } + if ( $this->do_concat ) { - if ( $this->in_default_dir( $obj->src ) && ! isset( $obj->extra['conditional'] ) && ! isset( $obj->extra['alt'] ) ) { + if ( $this->in_default_dir( $src ) && ! $conditional && ! isset( $obj->extra['alt'] ) ) { $this->concat .= "$handle,"; $this->concat_version .= "$handle$ver"; - $this->print_code .= $this->print_inline_style( $handle, false ); + $this->print_code .= $inline_style; return true; } @@ -160,19 +178,19 @@ class WP_Styles extends WP_Dependencies { } // A single item may alias a set of items, by having dependencies, but no source. - if ( ! $obj->src ) { - if ( $inline_style = $this->print_inline_style( $handle, false ) ) { - $inline_style = sprintf( "\n", esc_attr( $handle ), $inline_style ); + if ( ! $src ) { + if ( $inline_style_tag ) { if ( $this->do_concat ) { - $this->print_html .= $inline_style; + $this->print_html .= $inline_style_tag; } else { - echo $inline_style; + echo $inline_style_tag; } } + return true; } - $href = $this->_css_href( $obj->src, $ver, $handle ); + $href = $this->_css_href( $src, $ver, $handle ); if ( ! $href ) { return true; } @@ -193,10 +211,11 @@ class WP_Styles extends WP_Dependencies { * @param string $media The stylesheet's media attribute. */ $tag = apply_filters( 'style_loader_tag', "\n", $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'] ) { $suffix = isset( $obj->extra['suffix'] ) ? $obj->extra['suffix'] : ''; - $rtl_href = str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $this->_css_href( $obj->src, $ver, "$handle-rtl" ) ); + $rtl_href = str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $this->_css_href( $src, $ver, "$handle-rtl" ) ); } else { $rtl_href = $this->_css_href( $obj->extra['rtl'], $ver, "$handle-rtl" ); } @@ -211,24 +230,18 @@ class WP_Styles extends WP_Dependencies { } } - $conditional_pre = $conditional_post = ''; - if ( isset( $obj->extra['conditional'] ) && $obj->extra['conditional'] ) { - $conditional_pre = "\n"; - } - if ( $this->do_concat ) { - $this->print_html .= $conditional_pre; + $this->print_html .= $cond_before; $this->print_html .= $tag; - if ( $inline_style = $this->print_inline_style( $handle, false ) ) { - $this->print_html .= sprintf( "\n", esc_attr( $handle ), $inline_style ); + if ( $inline_style_tag ) { + $this->print_html .= $inline_style_tag; } - $this->print_html .= $conditional_post; + $this->print_html .= $cond_after; } else { - echo $conditional_pre; + echo $cond_before; echo $tag; $this->print_inline_style( $handle ); - echo $conditional_post; + echo $cond_after; } return true; diff --git a/wp-includes/version.php b/wp-includes/version.php index 49bcf31e76..26ffe755dc 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '5.0-alpha-43563'; +$wp_version = '5.0-alpha-43564'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.