Make WordPress Core

Ticket #35229: 35229.7.diff

File 35229.7.diff, 5.0 KB (added by ocean90, 9 years ago)
  • src/wp-includes/class.wp-dependencies.php

     
    9898
    9999                foreach ( $this->to_do as $key => $handle ) {
    100100                        if ( !in_array($handle, $this->done, true) && isset($this->registered[$handle]) ) {
    101 
    102101                                /*
    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 
    116                                 /*
    117102                                 * Attempt to process the item. If successful,
    118103                                 * add the handle to the done array.
    119104                                 *
  • src/wp-includes/class.wp-scripts.php

     
    177177                        echo $cond_after;
    178178                }
    179179
     180                if ( ! $obj->src ) {
     181                        return true;
     182                }
     183
    180184                if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $this->content_url && 0 === strpos( $src, $this->content_url ) ) ) {
    181185                        $src = $this->base_url . $src;
    182186                }
  • src/wp-includes/class.wp-styles.php

     
    7272                else
    7373                        $media = 'all';
    7474
    75                 $href = $this->_css_href( $obj->src, $ver, $handle );
    76                 if ( empty( $href ) ) {
    77                         // Turns out there is nothing to print.
     75                if ( ! $obj->src ) {
     76                        if ( $inline_style = $this->print_inline_style( $handle, false ) ) {
     77                                $inline_style = sprintf( "<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr( $handle ), $inline_style );
     78                                if ( $this->do_concat ) {
     79                                        $this->print_html .= $inline_style;
     80                                } else {
     81                                        echo $inline_style;
     82                                }
     83                        }
    7884                        return true;
    7985                }
     86
     87                $href = $this->_css_href( $obj->src, $ver, $handle );
    8088                $rel = isset($obj->extra['alt']) && $obj->extra['alt'] ? 'alternate stylesheet' : 'stylesheet';
    8189                $title = isset($obj->extra['title']) ? "title='" . esc_attr( $obj->extra['title'] ) . "'" : '';
    8290
  • tests/phpunit/tests/dependencies/scripts.php

     
    166166                $this->assertFalse( wp_register_script( 'duplicate-handler', 'http://example.com' ) );
    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}
  • tests/phpunit/tests/dependencies/styles.php

     
    234234         *
    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}