Make WordPress Core

Changeset 36550


Ignore:
Timestamp:
02/17/2016 05:10:53 PM (9 years ago)
Author:
ocean90
Message:

Script/Style Dependencies: Make sure that inline styles for handles without a source are printed.

This prevents breaking plugins which are adding inline styles to the wp-admin handle after [36341].

Props dd32, ocean90.
Fixes #35229.

Location:
trunk
Files:
5 edited

Legend:

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

    r33734 r36550  
    9999        foreach ( $this->to_do as $key => $handle ) {
    100100            if ( !in_array($handle, $this->done, true) && isset($this->registered[$handle]) ) {
    101 
    102                 /*
    103                  * A single item may alias a set of items, by having dependencies,
    104                  * but no source. Queuing the item queues the dependencies.
    105                  *
    106                  * Example: The extending class WP_Scripts is used to register 'scriptaculous' as a set of registered handles:
    107                  *   <code>add( 'scriptaculous', false, array( 'scriptaculous-dragdrop', 'scriptaculous-slider', 'scriptaculous-controls' ) );</code>
    108                  *
    109                  * The src property is false.
    110                  */
    111                 if ( ! $this->registered[$handle]->src ) {
    112                     $this->done[] = $handle;
    113                     continue;
    114                 }
    115 
    116101                /*
    117102                 * Attempt to process the item. If successful,
  • trunk/src/wp-includes/class.wp-scripts.php

    r35965 r36550  
    178178        }
    179179
     180        // A single item may alias a set of items, by having dependencies, but no source.
     181        if ( ! $obj->src ) {
     182            return true;
     183        }
     184
    180185        if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $this->content_url && 0 === strpos( $src, $this->content_url ) ) ) {
    181186            $src = $this->base_url . $src;
  • trunk/src/wp-includes/class.wp-styles.php

    r33222 r36550  
    7373            $media = 'all';
    7474
     75        // A single item may alias a set of items, by having dependencies, but no source.
     76        if ( ! $obj->src ) {
     77            if ( $inline_style = $this->print_inline_style( $handle, false ) ) {
     78                $inline_style = sprintf( "<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr( $handle ), $inline_style );
     79                if ( $this->do_concat ) {
     80                    $this->print_html .= $inline_style;
     81                } else {
     82                    echo $inline_style;
     83                }
     84            }
     85            return true;
     86        }
     87
    7588        $href = $this->_css_href( $obj->src, $ver, $handle );
    76         if ( empty( $href ) ) {
    77             // Turns out there is nothing to print.
    78             return true;
    79         }
    8089        $rel = isset($obj->extra['alt']) && $obj->extra['alt'] ? 'alternate stylesheet' : 'stylesheet';
    8190        $title = isset($obj->extra['title']) ? "title='" . esc_attr( $obj->extra['title'] ) . "'" : '';
  • trunk/tests/phpunit/tests/dependencies/scripts.php

    r36549 r36550  
    167167    }
    168168
     169    /**
     170     * @ticket 35229
     171     */
     172    function test_wp_register_script_with_handle_without_source() {
     173        $expected  = "<script type='text/javascript' src='http://example.com?ver=1'></script>\n";
     174        $expected .= "<script type='text/javascript' src='http://example.com?ver=2'></script>\n";
     175
     176        wp_register_script( 'handle-one', 'http://example.com', array(), 1 );
     177        wp_register_script( 'handle-two', 'http://example.com', array(), 2 );
     178        wp_register_script( 'handle-three', false, array( 'handle-one', 'handle-two' ) );
     179
     180        wp_enqueue_script( 'handle-three' );
     181
     182        $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
     183    }
     184
    169185}
  • trunk/tests/phpunit/tests/dependencies/styles.php

    r36547 r36550  
    235235     * @ticket 31126
    236236     */
    237     function test_wp_register_style(){
     237    function test_wp_register_style() {
    238238        $this->assertTrue( wp_register_style( 'duplicate-handler', 'http://example.com' ) );
    239239        $this->assertFalse( wp_register_style( 'duplicate-handler', 'http://example.com' ) );
    240240    }
    241241
     242    /**
     243     * @ticket 35229
     244     */
     245    function test_wp_add_inline_style_for_handle_without_source() {
     246        $style  = "a { color: blue; }";
     247
     248        $expected  = "<link rel='stylesheet' id='handle-one-css'  href='http://example.com?ver=1' type='text/css' media='all' />\n";
     249        $expected .= "<link rel='stylesheet' id='handle-two-css'  href='http://example.com?ver=1' type='text/css' media='all' />\n";
     250        $expected .= "<style id='handle-three-inline-css' type='text/css'>\n";
     251        $expected .= "$style\n";
     252        $expected .= "</style>\n";
     253
     254        wp_register_style( 'handle-one', 'http://example.com', array(), 1 );
     255        wp_register_style( 'handle-two', 'http://example.com', array(), 1 );
     256        wp_register_style( 'handle-three', false, array( 'handle-one', 'handle-two' ) );
     257
     258        wp_enqueue_style( 'handle-three' );
     259        wp_add_inline_style( 'handle-three', $style );
     260
     261        $this->assertEquals( $expected, get_echo( 'wp_print_styles' ) );
     262    }
     263
    242264}
Note: See TracChangeset for help on using the changeset viewer.