[wp-trac] [WordPress Trac] #16118: Support for wp_enqueue_style with negative conditional comments

WordPress Trac noreply at wordpress.org
Thu Nov 10 01:10:16 UTC 2016


#16118: Support for wp_enqueue_style with negative conditional comments
-------------------------------------------------+-------------------------
 Reporter:  sayontan                             |       Owner:
     Type:  enhancement                          |      Status:  new
 Priority:  normal                               |   Milestone:  Future
Component:  Script Loader                        |  Release
 Severity:  normal                               |     Version:  3.0.4
 Keywords:  has-patch needs-testing dev-         |  Resolution:
  feedback 3.6-early                             |     Focuses:
-------------------------------------------------+-------------------------

Comment (by shaunjeffrey):

 Hi All,

 I submitted a ticket regarding support for script conditionals, which was
 marked as duplicate, and while the code for scripts and styles isn't
 identical, the process is relatively similar for both.

 The most adaptable way to deal with this issue is to apply filters to both
 the before and after conditionals, and pass through at least the handle,
 and possibly whether it's a script or style tag if we want to use the same
 filter for both scripts and styles, and whether it's the before or after
 conditional if we want to use the same filter for both of those as well.

 I propose the following changes, or something similar to that effect:
     /wp-includes/class.wp-styles.php : Lines 224-225
 {{{
 $conditional_pre  = apply_filters( 'wp_conditional', "<!--[if
 {$obj->extra['conditional']}]>\n", $handle, $obj, 'style', 'before' );
 $conditional_post = apply_filters( 'wp_conditional', "<![endif]-->\n",
 $handle, $obj, 'style', 'after' );
 }}}
     /wp-includes/class.wp-scripts.php : Lines 272-273
 {{{
 $cond_before = apply_filters( 'wp_conditional', "<!--[if
 {$conditional}]>\n", $handle, $obj, 'script', 'before' );
 $cond_after  = apply_filters( 'wp_conditional', "<![endif]-->\n", $handle,
 $obj, 'script', 'after' );
 }}}
 Whether we use the same filter or separate filters for each, such as
 {{{wp_style_conditional_before}}}, would be up to the core developers or
 community to decide.

 Other methods of obtaining the desired result, in order of decreasing
 usability and scalability, would be to either:
 1. add a new key when setting extra data
 {{{
 wp_style_add_data( $handle, 'not-conditional', '!IE' );
 }}}
 2. adding a flag specifically for conditionals
 {{{
 wp_style_add_data( $handle, 'conditional', '!IE', $not_flag );
 }}}
 3. or parse the user's data and hope for the best
 {{{
 $conditional_pre  = "<!--[if {$obj->extra['conditional']}]>" .
 (preg_match( "/\!/", $obj->extra['conditional'] ) ? "<!-->" : "") . "\n";
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/16118#comment:20>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list