mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-22 17:18:32 +01:00
Add support for IE conditional comments for WP_Scripts to match the functionality of WP_Styles, including unit tests. Props filosofo, aaroncampbell, ethitter, georgestephanis, valendesigns. Fixes #16024.
Built from https://develop.svn.wordpress.org/trunk@31223 git-svn-id: http://core.svn.wordpress.org/trunk@31204 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
f609d9d89a
commit
9d3ea188d7
@ -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 = "<!--[if {$conditional}]>\n";
|
||||
$cond_after = "<![endif]-->\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,7 +136,18 @@ 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 ( $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;
|
||||
}
|
||||
@ -140,7 +161,7 @@ class WP_Scripts extends WP_Dependencies {
|
||||
if ( ! $src )
|
||||
return true;
|
||||
|
||||
$tag = "<script type='text/javascript' src='$src'></script>\n";
|
||||
$tag = "{$cond_before}<script type='text/javascript' src='$src'></script>\n{$cond_after}";
|
||||
|
||||
/**
|
||||
* Filter the HTML script tag of an enqueued script.
|
||||
|
@ -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 );
|
||||
}
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user