mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-01 11:14:36 +00: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.
git-svn-id: https://develop.svn.wordpress.org/trunk@31223 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -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,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 = "<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.
|
||||
|
||||
Reference in New Issue
Block a user