Index: src/wp-content/themes/twentytwelve/functions.php
===================================================================
--- src/wp-content/themes/twentytwelve/functions.php (revision 31054)
+++ src/wp-content/themes/twentytwelve/functions.php (working copy)
@@ -133,6 +133,12 @@
global $wp_styles;
/*
+ * Loads HTML5 JavaScript file to add support for HTML5 elements in older IE versions.
+ */
+ wp_enqueue_script( 'twentytwelve-html5', get_template_directory_uri() . '/js/html5.js', array(), '1.0' );
+ wp_script_add_data( 'twentytwelve-html5', 'conditional', 'lt IE 9' );
+
+ /*
* Adds JavaScript to pages with the comment form to support
* sites with threaded comments (when in use).
*/
@@ -151,7 +157,7 @@
// Loads the Internet Explorer specific stylesheet.
wp_enqueue_style( 'twentytwelve-ie', get_template_directory_uri() . '/css/ie.css', array( 'twentytwelve-style' ), '20121010' );
- $wp_styles->add_data( 'twentytwelve-ie', 'conditional', 'lt IE 9' );
+ wp_style_add_data( 'twentytwelve-ie', 'conditional', 'lt IE 9' );
}
add_action( 'wp_enqueue_scripts', 'twentytwelve_scripts_styles' );
Index: src/wp-content/themes/twentytwelve/header.php
===================================================================
--- src/wp-content/themes/twentytwelve/header.php (revision 31054)
+++ src/wp-content/themes/twentytwelve/header.php (working copy)
@@ -24,10 +24,6 @@
-
-
Index: src/wp-includes/class.wp-scripts.php
===================================================================
--- src/wp-includes/class.wp-scripts.php (revision 31054)
+++ src/wp-includes/class.wp-scripts.php (working copy)
@@ -98,16 +98,26 @@
if ( false === $group && in_array($handle, $this->in_footer, true) )
$this->in_footer = array_diff( $this->in_footer, (array) $handle );
- if ( null === $this->registered[$handle]->ver )
+ $obj = $this->registered[$handle];
+
+ if ( null === $obj->ver ) {
$ver = '';
- else
- $ver = $this->registered[$handle]->ver ? $this->registered[$handle]->ver : $this->default_version;
+ } else {
+ $ver = $obj->ver ? $obj->ver : $this->default_version;
+ }
if ( isset($this->args[$handle]) )
$ver = $ver ? $ver . '&' . $this->args[$handle] : $this->args[$handle];
- $src = $this->registered[$handle]->src;
+ $src = $obj->src;
+ $cond_before = $cond_after = '';
+ $conditional = isset( $obj->extra['conditional'] ) ? $obj->extra['conditional'] : '';
+ if ( $conditional ) {
+ $cond_before = "\n";
+ }
+
if ( $this->do_concat ) {
/**
* Filter the script loader source.
@@ -118,7 +128,7 @@
* @param string $handle Script handle.
*/
$srce = apply_filters( 'script_loader_src', $src, $handle );
- if ( $this->in_default_dir($srce) ) {
+ if ( $this->in_default_dir( $srce ) && ! $conditional ) {
$this->print_code .= $this->print_extra_script( $handle, false );
$this->print_after_html .= "\n" . $this->print_extra_script( $handle, false, 'data-after' );
$this->concat .= "$handle,";
@@ -130,13 +140,25 @@
}
}
+ $has_conditional_data = $conditional && $this->get_data( $handle, 'data' );
+ $has_conditional_data_after = $conditional && $this->get_data( $handle, 'data-after' );
+
+ if ( $has_conditional_data ) {
+ echo $cond_before;
+ }
+
$this->print_extra_script( $handle );
- if ( !preg_match('|^(https?:)?//|', $src) && ! ( $this->content_url && 0 === strpos($src, $this->content_url) ) ) {
+
+ if ( $has_conditional_data ) {
+ echo $cond_after;
+ }
+
+ if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $this->content_url && 0 === strpos( $src, $this->content_url ) ) ) {
$src = $this->base_url . $src;
}
- if ( !empty($ver) )
- $src = add_query_arg('ver', $ver, $src);
+ if ( ! empty( $ver ) )
+ $src = add_query_arg( 'ver', $ver, $src );
/** This filter is documented in wp-includes/class.wp-scripts.php */
$src = esc_url( apply_filters( 'script_loader_src', $src, $handle ) );
@@ -144,7 +166,7 @@
if ( ! $src )
return true;
- $tag = "\n";
+ $tag = "{$cond_before}\n{$cond_after}";
/**
* Filter the HTML script tag of an enqueued script.
@@ -159,10 +181,26 @@
if ( $this->do_concat ) {
$this->print_html .= $tag;
- $this->print_after_html .= $this->print_extra_script( $handle, false, 'data-after' ) . "\n";
+
+ if ( $has_conditional_data_after ) {
+ $this->print_html .= $cond_before . '\n" . $cond_after;
+ } else {
+ $this->print_after_html .= $this->print_extra_script( $handle, false, 'data-after' ) . "\n";
+ }
} else {
echo $tag;
+
+ if ( $has_conditional_data_after ) {
+ echo $cond_before;
+ }
+
$this->print_extra_script( $handle, true, 'data-after' );
+
+ if ( $has_conditional_data_after ) {
+ echo $cond_after;
+ }
}
return true;
Index: src/wp-includes/functions.wp-scripts.php
===================================================================
--- src/wp-includes/functions.wp-scripts.php (revision 31054)
+++ src/wp-includes/functions.wp-scripts.php (working copy)
@@ -263,3 +263,25 @@
return (bool) $wp_scripts->query( $handle, $list );
}
+
+/**
+ * Add metadata to a script.
+ *
+ * Works only if the script has already been added.
+ *
+ * Possible values for $key and $value:
+ * 'conditional' string Comments for IE 6, lte IE 7, etc.
+ *
+ * @see WP_Dependency::add_data()
+ *
+ * @since 4.2.0
+ *
+ * @param string $handle Name of the script.
+ * @param string $key Name of data point for which we're storing a value.
+ * @param mixed $value String containing the data to be added.
+ * @return bool True on success, false on failure.
+ */
+function wp_script_add_data( $handle, $key, $value ){
+ global $wp_scripts;
+ return $wp_scripts->add_data( $handle, $key, $value );
+}
Index: tests/phpunit/tests/dependencies/scripts.php
===================================================================
--- tests/phpunit/tests/dependencies/scripts.php (revision 31054)
+++ tests/phpunit/tests/dependencies/scripts.php (working copy)
@@ -84,4 +84,39 @@
// Cleanup
$wp_scripts->base_url = $base_url_backup;
}
+
+ /**
+ * Testing add data & conditional
+ * @ticket 16024
+ */
+ function test_wp_script_add_data() {
+ // Enqueue & add data
+ wp_enqueue_script( 'test-only-data', 'example.com', array(), null );
+ wp_script_add_data( 'test-only-data', 'data', 'testing' );
+ $expected = "\n";
+ $expected.= "\n";
+
+ // Enqueue & add conditional comments
+ wp_enqueue_script( 'test-only-conditional', 'example.com', array(), null );
+ wp_script_add_data( 'test-only-conditional', 'conditional', 'gt IE 7' );
+ $expected.= "\n";
+
+ // Enqueue & add data plus conditional comments for both
+ wp_enqueue_script( 'test-conditional-with-data', 'example.com', array(), null );
+ wp_script_add_data( 'test-conditional-with-data', 'data', 'testing' );
+ wp_script_add_data( 'test-conditional-with-data', 'conditional', 'lt IE 9' );
+ $expected.= "\n";
+ $expected.= "\n";
+
+ // Enqueue & add an invalid key for brevity
+ wp_enqueue_script( 'test-invalid', 'example.com', array(), null );
+ wp_script_add_data( 'test-invalid', 'invalid', 'testing' );
+ $expected.= "\n";
+
+ // Go!
+ $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
+
+ // No scripts left to print
+ $this->assertEquals( '', get_echo( 'wp_print_scripts' ) );
+ }
}