Ticket #16024: 16024.9.diff
File 16024.9.diff, 8.5 KB (added by , 9 years ago) |
---|
-
src/wp-content/themes/twentytwelve/functions.php
133 133 global $wp_styles; 134 134 135 135 /* 136 * Loads HTML5 JavaScript file to add support for HTML5 elements in older IE versions. 137 */ 138 wp_enqueue_script( 'twentytwelve-html5', get_template_directory_uri() . '/js/html5.js', array(), '1.0' ); 139 wp_script_add_data( 'twentytwelve-html5', 'conditional', 'lt IE 9' ); 140 141 /* 136 142 * Adds JavaScript to pages with the comment form to support 137 143 * sites with threaded comments (when in use). 138 144 */ … … 151 157 152 158 // Loads the Internet Explorer specific stylesheet. 153 159 wp_enqueue_style( 'twentytwelve-ie', get_template_directory_uri() . '/css/ie.css', array( 'twentytwelve-style' ), '20121010' ); 154 $wp_styles->add_data( 'twentytwelve-ie', 'conditional', 'lt IE 9' );160 wp_style_add_data( 'twentytwelve-ie', 'conditional', 'lt IE 9' ); 155 161 } 156 162 add_action( 'wp_enqueue_scripts', 'twentytwelve_scripts_styles' ); 157 163 -
src/wp-content/themes/twentytwelve/header.php
24 24 <title><?php wp_title( '|', true, 'right' ); ?></title> 25 25 <link rel="profile" href="http://gmpg.org/xfn/11" /> 26 26 <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" /> 27 <?php // Loads HTML5 JavaScript file to add support for HTML5 elements in older IE versions. ?>28 <!--[if lt IE 9]>29 <script src="<?php echo get_template_directory_uri(); ?>/js/html5.js" type="text/javascript"></script>30 <![endif]-->31 27 <?php wp_head(); ?> 32 28 </head> 33 29 -
src/wp-includes/class.wp-scripts.php
98 98 if ( false === $group && in_array($handle, $this->in_footer, true) ) 99 99 $this->in_footer = array_diff( $this->in_footer, (array) $handle ); 100 100 101 if ( null === $this->registered[$handle]->ver ) 101 $obj = $this->registered[$handle]; 102 103 if ( null === $obj->ver ) { 102 104 $ver = ''; 103 else 104 $ver = $this->registered[$handle]->ver ? $this->registered[$handle]->ver : $this->default_version; 105 } else { 106 $ver = $obj->ver ? $obj->ver : $this->default_version; 107 } 105 108 106 109 if ( isset($this->args[$handle]) ) 107 110 $ver = $ver ? $ver . '&' . $this->args[$handle] : $this->args[$handle]; 108 111 109 $src = $this->registered[$handle]->src; 112 $src = $obj->src; 113 $cond_before = $cond_after = ''; 114 $conditional = isset( $obj->extra['conditional'] ) ? $obj->extra['conditional'] : ''; 110 115 116 if ( $conditional ) { 117 $cond_before = "<!--[if {$conditional}]>\n"; 118 $cond_after = "<![endif]-->\n"; 119 } 120 111 121 if ( $this->do_concat ) { 112 122 /** 113 123 * Filter the script loader source. … … 118 128 * @param string $handle Script handle. 119 129 */ 120 130 $srce = apply_filters( 'script_loader_src', $src, $handle ); 121 if ( $this->in_default_dir( $srce)) {131 if ( $this->in_default_dir( $srce ) && ! $conditional ) { 122 132 $this->print_code .= $this->print_extra_script( $handle, false ); 123 133 $this->print_after_html .= "\n" . $this->print_extra_script( $handle, false, 'data-after' ); 124 134 $this->concat .= "$handle,"; … … 130 140 } 131 141 } 132 142 143 $has_conditional_data = $conditional && $this->get_data( $handle, 'data' ); 144 $has_conditional_data_after = $conditional && $this->get_data( $handle, 'data-after' ); 145 146 if ( $has_conditional_data ) { 147 echo $cond_before; 148 } 149 133 150 $this->print_extra_script( $handle ); 134 if ( !preg_match('|^(https?:)?//|', $src) && ! ( $this->content_url && 0 === strpos($src, $this->content_url) ) ) { 151 152 if ( $has_conditional_data ) { 153 echo $cond_after; 154 } 155 156 if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $this->content_url && 0 === strpos( $src, $this->content_url ) ) ) { 135 157 $src = $this->base_url . $src; 136 158 } 137 159 138 if ( ! empty($ver) )139 $src = add_query_arg( 'ver', $ver, $src);160 if ( ! empty( $ver ) ) 161 $src = add_query_arg( 'ver', $ver, $src ); 140 162 141 163 /** This filter is documented in wp-includes/class.wp-scripts.php */ 142 164 $src = esc_url( apply_filters( 'script_loader_src', $src, $handle ) ); … … 144 166 if ( ! $src ) 145 167 return true; 146 168 147 $tag = " <script type='text/javascript' src='$src'></script>\n";169 $tag = "{$cond_before}<script type='text/javascript' src='$src'></script>\n{$cond_after}"; 148 170 149 171 /** 150 172 * Filter the HTML script tag of an enqueued script. … … 159 181 160 182 if ( $this->do_concat ) { 161 183 $this->print_html .= $tag; 162 $this->print_after_html .= $this->print_extra_script( $handle, false, 'data-after' ) . "\n"; 184 185 if ( $has_conditional_data_after ) { 186 $this->print_html .= $cond_before . '<script type="text/javascript">'; 187 $this->print_html .= $this->print_extra_script( $handle, false, 'data-after' ); 188 $this->print_html .= "</script>\n" . $cond_after; 189 } else { 190 $this->print_after_html .= $this->print_extra_script( $handle, false, 'data-after' ) . "\n"; 191 } 163 192 } else { 164 193 echo $tag; 194 195 if ( $has_conditional_data_after ) { 196 echo $cond_before; 197 } 198 165 199 $this->print_extra_script( $handle, true, 'data-after' ); 200 201 if ( $has_conditional_data_after ) { 202 echo $cond_after; 203 } 166 204 } 167 205 168 206 return true; -
src/wp-includes/functions.wp-scripts.php
263 263 264 264 return (bool) $wp_scripts->query( $handle, $list ); 265 265 } 266 267 /** 268 * Add metadata to a script. 269 * 270 * Works only if the script has already been added. 271 * 272 * Possible values for $key and $value: 273 * 'conditional' string Comments for IE 6, lte IE 7, etc. 274 * 275 * @see WP_Dependency::add_data() 276 * 277 * @since 4.2.0 278 * 279 * @param string $handle Name of the script. 280 * @param string $key Name of data point for which we're storing a value. 281 * @param mixed $value String containing the data to be added. 282 * @return bool True on success, false on failure. 283 */ 284 function wp_script_add_data( $handle, $key, $value ){ 285 global $wp_scripts; 286 return $wp_scripts->add_data( $handle, $key, $value ); 287 } -
tests/phpunit/tests/dependencies/scripts.php
84 84 // Cleanup 85 85 $wp_scripts->base_url = $base_url_backup; 86 86 } 87 88 /** 89 * Testing add data & conditional 90 * @ticket 16024 91 */ 92 function test_wp_script_add_data() { 93 // Enqueue & add data 94 wp_enqueue_script( 'test-only-data', 'example.com', array(), null ); 95 wp_script_add_data( 'test-only-data', 'data', 'testing' ); 96 $expected = "<script type='text/javascript'>\n/* <![CDATA[ */\ntesting\n/* ]]> */\n</script>\n"; 97 $expected.= "<script type='text/javascript' src='http://example.com'></script>\n"; 98 99 // Enqueue & add conditional comments 100 wp_enqueue_script( 'test-only-conditional', 'example.com', array(), null ); 101 wp_script_add_data( 'test-only-conditional', 'conditional', 'gt IE 7' ); 102 $expected.= "<!--[if gt IE 7]>\n<script type='text/javascript' src='http://example.com'></script>\n<![endif]-->\n"; 103 104 // Enqueue & add data plus conditional comments for both 105 wp_enqueue_script( 'test-conditional-with-data', 'example.com', array(), null ); 106 wp_script_add_data( 'test-conditional-with-data', 'data', 'testing' ); 107 wp_script_add_data( 'test-conditional-with-data', 'conditional', 'lt IE 9' ); 108 $expected.= "<!--[if lt IE 9]>\n<script type='text/javascript'>\n/* <![CDATA[ */\ntesting\n/* ]]> */\n</script>\n<![endif]-->\n"; 109 $expected.= "<!--[if lt IE 9]>\n<script type='text/javascript' src='http://example.com'></script>\n<![endif]-->\n"; 110 111 // Enqueue & add an invalid key for brevity 112 wp_enqueue_script( 'test-invalid', 'example.com', array(), null ); 113 wp_script_add_data( 'test-invalid', 'invalid', 'testing' ); 114 $expected.= "<script type='text/javascript' src='http://example.com'></script>\n"; 115 116 // Go! 117 $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) ); 118 119 // No scripts left to print 120 $this->assertEquals( '', get_echo( 'wp_print_scripts' ) ); 121 } 87 122 }