diff --git a/wp-includes/class.wp-scripts.php b/wp-includes/class.wp-scripts.php index ae0148ee8d..988ba792b0 100644 --- a/wp-includes/class.wp-scripts.php +++ b/wp-includes/class.wp-scripts.php @@ -95,15 +95,25 @@ class WP_Scripts extends WP_Dependencies { 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 ) { /** @@ -115,7 +125,7 @@ class WP_Scripts extends WP_Dependencies { * @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->concat .= "$handle,"; $this->concat_version .= "$handle$ver"; @@ -126,13 +136,24 @@ class WP_Scripts extends WP_Dependencies { } } + $has_conditional_data = $conditional && $this->get_data( $handle, 'data' ); + + 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 ) ); @@ -140,7 +161,7 @@ class WP_Scripts extends WP_Dependencies { if ( ! $src ) return true; - $tag = "\n"; + $tag = "{$cond_before}\n{$cond_after}"; /** * Filter the HTML script tag of an enqueued script. diff --git a/wp-includes/functions.wp-scripts.php b/wp-includes/functions.wp-scripts.php index afa46be271..9fd5d87d80 100644 --- a/wp-includes/functions.wp-scripts.php +++ b/wp-includes/functions.wp-scripts.php @@ -271,3 +271,25 @@ function wp_script_is( $handle, $list = 'enqueued' ) { 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 ); +} diff --git a/wp-includes/version.php b/wp-includes/version.php index 2232685262..ec940ba6ca 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.2-alpha-31222'; +$wp_version = '4.2-alpha-31223'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.