diff --git src/wp-includes/class.wp-scripts.php src/wp-includes/class.wp-scripts.php
index fbb8b22..a831ff9 100644
|
|
class WP_Scripts extends WP_Dependencies { |
95 | 95 | if ( false === $group && in_array($handle, $this->in_footer, true) ) |
96 | 96 | $this->in_footer = array_diff( $this->in_footer, (array) $handle ); |
97 | 97 | |
98 | | if ( null === $this->registered[$handle]->ver ) |
| 98 | $obj = $this->registered[$handle]; |
| 99 | |
| 100 | if ( null === $obj->ver ) |
99 | 101 | $ver = ''; |
100 | 102 | else |
101 | | $ver = $this->registered[$handle]->ver ? $this->registered[$handle]->ver : $this->default_version; |
| 103 | $ver = $obj->ver ? $obj->ver : $this->default_version; |
102 | 104 | |
103 | 105 | if ( isset($this->args[$handle]) ) |
104 | 106 | $ver = $ver ? $ver . '&' . $this->args[$handle] : $this->args[$handle]; |
105 | 107 | |
106 | | $src = $this->registered[$handle]->src; |
| 108 | $src = $obj->src; |
| 109 | $cond_before = $cond_after = ''; |
| 110 | $conditional = isset( $obj->extra['conditional'] ) ? $obj->extra['conditional'] : ''; |
| 111 | |
| 112 | if ( $conditional ) { |
| 113 | $cond_before = "<!--[if {$conditional}]>\n"; |
| 114 | $cond_after = "\n<![endif]-->"; |
| 115 | } |
107 | 116 | |
108 | 117 | if ( $this->do_concat ) { |
109 | 118 | /** |
… |
… |
class WP_Scripts extends WP_Dependencies { |
115 | 124 | * @param string $handle Script handle. |
116 | 125 | */ |
117 | 126 | $srce = apply_filters( 'script_loader_src', $src, $handle ); |
118 | | if ( $this->in_default_dir($srce) ) { |
| 127 | if ( $this->in_default_dir( $srce ) && ! $conditional ) { |
119 | 128 | $this->print_code .= $this->print_extra_script( $handle, false ); |
120 | 129 | $this->concat .= "$handle,"; |
121 | 130 | $this->concat_version .= "$handle$ver"; |
… |
… |
class WP_Scripts extends WP_Dependencies { |
140 | 149 | if ( ! $src ) |
141 | 150 | return true; |
142 | 151 | |
143 | | $tag = "<script type='text/javascript' src='$src'></script>\n"; |
| 152 | $tag = "{$cond_before}<script type='text/javascript' src='$src'></script>{$cond_after}\n"; |
144 | 153 | |
145 | 154 | /** |
146 | 155 | * Filter the HTML script tag of an enqueued script. |
diff --git src/wp-includes/functions.wp-scripts.php src/wp-includes/functions.wp-scripts.php
index 6eb7a44..1a77df8 100644
|
|
function wp_script_is( $handle, $list = 'enqueued' ) { |
258 | 258 | |
259 | 259 | return (bool) $wp_scripts->query( $handle, $list ); |
260 | 260 | } |
| 261 | |
| 262 | |
| 263 | /** |
| 264 | * Add metadata to a script. |
| 265 | * |
| 266 | * Works only if the script has already been added. |
| 267 | * |
| 268 | * Possible values for $key and $value: |
| 269 | * 'conditional' string Comments for IE 6, lte IE 7, etc. |
| 270 | * |
| 271 | * @see WP_Dependency::add_data() |
| 272 | * |
| 273 | * @since 4.2.0 |
| 274 | * |
| 275 | * @param string $handle Name of the script. |
| 276 | * @param string $key Name of data point for which we're storing a value. |
| 277 | * @param mixed $value String containing the data to be added. |
| 278 | * @return bool True on success, false on failure. |
| 279 | */ |
| 280 | function wp_script_add_data( $handle, $key, $value ){ |
| 281 | global $wp_scripts; |
| 282 | return $wp_scripts->add_data( $handle, $key, $value ); |
| 283 | } |
diff --git tests/phpunit/tests/dependencies/scripts.php tests/phpunit/tests/dependencies/scripts.php
index 3f4e724..783cf00 100644
|
|
class Tests_Dependencies_Scripts extends WP_UnitTestCase { |
84 | 84 | // Cleanup |
85 | 85 | $wp_scripts->base_url = $base_url_backup; |
86 | 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Test Conditional Comments |
| 90 | * @ticket 10624 |
| 91 | */ |
| 92 | function test_wp_script_add_data() { |
| 93 | // Enqueue & add conditional comments |
| 94 | wp_enqueue_script( 'twentytwelve-html5', 'example.com', array(), '1.0' ); |
| 95 | wp_script_add_data( 'twentytwelve-html5', 'conditional', 'lt IE 9' ); |
| 96 | $expected = "<!--[if lt IE 9]>\n<script type='text/javascript' src='http://example.com?ver=1.0'></script>\n<![endif]-->\n"; |
| 97 | |
| 98 | // Go! |
| 99 | $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) ); |
| 100 | |
| 101 | // No scripts left to print |
| 102 | $this->assertEquals( '', get_echo( 'wp_print_scripts' ) ); |
| 103 | } |
87 | 104 | } |