WordPress.org

Make WordPress Core

Changeset 43564


Ignore:
Timestamp:
08/11/2018 05:41:02 PM (18 months ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class.wp-styles.php

    r42876 r43564  
    133133
    134134        $obj = $this->registered[ $handle ];
     135
    135136        if ( null === $obj->ver ) {
    136137            $ver = '';
     
    143144        }
    144145
     146        $src         = $obj->src;
     147        $cond_before = $cond_after = '';
     148        $conditional = isset( $obj->extra['conditional'] ) ? $obj->extra['conditional'] : '';
     149
     150        if ( $conditional ) {
     151            $cond_before = "<!--[if {$conditional}]>\n";
     152            $cond_after  = "<![endif]-->\n";
     153        }
     154
     155        $inline_style = $this->print_inline_style( $handle, false );
     156
     157        if ( $inline_style ) {
     158            $inline_style_tag = sprintf( "<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr( $handle ), $inline_style );
     159        } else {
     160            $inline_style_tag = '';
     161        }
     162
    145163        if ( $this->do_concat ) {
    146             if ( $this->in_default_dir( $obj->src ) && ! isset( $obj->extra['conditional'] ) && ! isset( $obj->extra['alt'] ) ) {
     164            if ( $this->in_default_dir( $src ) && ! $conditional && ! isset( $obj->extra['alt'] ) ) {
    147165                $this->concat         .= "$handle,";
    148166                $this->concat_version .= "$handle$ver";
    149167
    150                 $this->print_code .= $this->print_inline_style( $handle, false );
     168                $this->print_code .= $inline_style;
    151169
    152170                return true;
     
    161179
    162180        // A single item may alias a set of items, by having dependencies, but no source.
    163         if ( ! $obj->src ) {
    164             if ( $inline_style = $this->print_inline_style( $handle, false ) ) {
    165                 $inline_style = sprintf( "<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr( $handle ), $inline_style );
     181        if ( ! $src ) {
     182            if ( $inline_style_tag ) {
    166183                if ( $this->do_concat ) {
    167                     $this->print_html .= $inline_style;
     184                    $this->print_html .= $inline_style_tag;
    168185                } else {
    169                     echo $inline_style;
     186                    echo $inline_style_tag;
    170187                }
    171188            }
     189
    172190            return true;
    173191        }
    174192
    175         $href = $this->_css_href( $obj->src, $ver, $handle );
     193        $href = $this->_css_href( $src, $ver, $handle );
    176194        if ( ! $href ) {
    177195            return true;
     
    194212         */
    195213        $tag = apply_filters( 'style_loader_tag', "<link rel='$rel' id='$handle-css' $title href='$href' type='text/css' media='$media' />\n", $handle, $href, $media );
     214
    196215        if ( 'rtl' === $this->text_direction && isset( $obj->extra['rtl'] ) && $obj->extra['rtl'] ) {
    197216            if ( is_bool( $obj->extra['rtl'] ) || 'replace' === $obj->extra['rtl'] ) {
    198217                $suffix   = isset( $obj->extra['suffix'] ) ? $obj->extra['suffix'] : '';
    199                 $rtl_href = str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $this->_css_href( $obj->src, $ver, "$handle-rtl" ) );
     218                $rtl_href = str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $this->_css_href( $src, $ver, "$handle-rtl" ) );
    200219            } else {
    201220                $rtl_href = $this->_css_href( $obj->extra['rtl'], $ver, "$handle-rtl" );
     
    212231        }
    213232
    214         $conditional_pre = $conditional_post = '';
    215         if ( isset( $obj->extra['conditional'] ) && $obj->extra['conditional'] ) {
    216             $conditional_pre  = "<!--[if {$obj->extra['conditional']}]>\n";
    217             $conditional_post = "<![endif]-->\n";
    218         }
    219 
    220233        if ( $this->do_concat ) {
    221             $this->print_html .= $conditional_pre;
     234            $this->print_html .= $cond_before;
    222235            $this->print_html .= $tag;
    223             if ( $inline_style = $this->print_inline_style( $handle, false ) ) {
    224                 $this->print_html .= sprintf( "<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr( $handle ), $inline_style );
    225             }
    226             $this->print_html .= $conditional_post;
     236            if ( $inline_style_tag ) {
     237                $this->print_html .= $inline_style_tag;
     238            }
     239            $this->print_html .= $cond_after;
    227240        } else {
    228             echo $conditional_pre;
     241            echo $cond_before;
    229242            echo $tag;
    230243            $this->print_inline_style( $handle );
    231             echo $conditional_post;
     244            echo $cond_after;
    232245        }
    233246
Note: See TracChangeset for help on using the changeset viewer.