Make WordPress Core


Ignore:
Timestamp:
01/17/2015 01:36:55 AM (10 years ago)
Author:
azaozz
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class.wp-scripts.php

    r31189 r31223  
    9696            $this->in_footer = array_diff( $this->in_footer, (array) $handle );
    9797
    98         if ( null === $this->registered[$handle]->ver )
     98        $obj = $this->registered[$handle];
     99
     100        if ( null === $obj->ver ) {
    99101            $ver = '';
    100         else
    101             $ver = $this->registered[$handle]->ver ? $this->registered[$handle]->ver : $this->default_version;
     102        } else {
     103            $ver = $obj->ver ? $obj->ver : $this->default_version;
     104        }
    102105
    103106        if ( isset($this->args[$handle]) )
    104107            $ver = $ver ? $ver . '&' . $this->args[$handle] : $this->args[$handle];
    105108
    106         $src = $this->registered[$handle]->src;
     109        $src = $obj->src;
     110        $cond_before = $cond_after = '';
     111        $conditional = isset( $obj->extra['conditional'] ) ? $obj->extra['conditional'] : '';
     112
     113        if ( $conditional ) {
     114            $cond_before = "<!--[if {$conditional}]>\n";
     115            $cond_after = "<![endif]-->\n";
     116        }
    107117
    108118        if ( $this->do_concat ) {
     
    116126             */
    117127            $srce = apply_filters( 'script_loader_src', $src, $handle );
    118             if ( $this->in_default_dir($srce) ) {
     128            if ( $this->in_default_dir( $srce ) && ! $conditional ) {
    119129                $this->print_code .= $this->print_extra_script( $handle, false );
    120130                $this->concat .= "$handle,";
     
    127137        }
    128138
     139        $has_conditional_data = $conditional && $this->get_data( $handle, 'data' );
     140
     141        if ( $has_conditional_data ) {
     142            echo $cond_before;
     143        }
     144
    129145        $this->print_extra_script( $handle );
    130         if ( !preg_match('|^(https?:)?//|', $src) && ! ( $this->content_url && 0 === strpos($src, $this->content_url) ) ) {
     146
     147        if ( $has_conditional_data ) {
     148            echo $cond_after;
     149        }
     150
     151        if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $this->content_url && 0 === strpos( $src, $this->content_url ) ) ) {
    131152            $src = $this->base_url . $src;
    132153        }
    133154
    134         if ( !empty($ver) )
    135             $src = add_query_arg('ver', $ver, $src);
     155        if ( ! empty( $ver ) )
     156            $src = add_query_arg( 'ver', $ver, $src );
    136157
    137158        /** This filter is documented in wp-includes/class.wp-scripts.php */
     
    141162            return true;
    142163
    143         $tag = "<script type='text/javascript' src='$src'></script>\n";
     164        $tag = "{$cond_before}<script type='text/javascript' src='$src'></script>\n{$cond_after}";
    144165
    145166        /**
Note: See TracChangeset for help on using the changeset viewer.