[wp-trac] [WordPress Trac] #38548: Add new filters on wp_script_is/wp_style_is

WordPress Trac noreply at wordpress.org
Fri Oct 28 13:41:54 UTC 2016


#38548: Add new filters on wp_script_is/wp_style_is
---------------------------+-----------------------------
 Reporter:  igmoweb        |      Owner:
     Type:  enhancement    |     Status:  new
 Priority:  normal         |  Milestone:  Awaiting Review
Component:  Script Loader  |    Version:  trunk
 Severity:  normal         |   Keywords:
  Focuses:                 |
---------------------------+-----------------------------
 Minification engines tend to group dependencies and then enqueue them in a
 single file so enqueues handles change their names. So imagine this
 situation:

 Handles `style-1` and `style-2` are now grouped into a file and the new
 handle name is `group-1`

 Once grouping is done `wp_style_is('style-1', 'done')` won't work as
 style-1 and 2 are now inside `group-1` so `wp_style_is('group-1', 'done')`
 would work but this is just known by the plugin that minifies the
 styles/scripts. I don't know if the point is clear enough.

 By adding a new filter this would help a lot to remap those handles names.
 The filter can be placed easily in `WP_Dependencies::query()` method like
 this:

 {{{#!php
 <?php
 public function query( $handle, $list = 'registered' ) {
                 $query = false;
                 switch ( $list ) {
                         case 'registered' :
                         case 'scripts': // back compat
                                 if ( isset( $this->registered[ $handle ] )
 ) {
                                         $query = $this->registered[
 $handle ];
                                 }
                                 break;

                         case 'enqueued' :
                         case 'queue' :
                                 if ( in_array( $handle, $this->queue ) ) {
                                         $query = true;
                                 }
                                 else {
                                         $query = $this->recurse_deps(
 $this->queue, $handle );
                                 }
                                 break;

                         case 'to_do' :
                         case 'to_print': // back compat
                                 $query = in_array( $handle, $this->to_do
 );
                                 break;

                         case 'done' :
                         case 'printed': // back compat
                                 $query = in_array( $handle, $this->done );
                                 break;

                 }
                 return apply_filters( 'script_is_query', $query, $handle,
 $list, $this );
         }
 }}}

 Any thoughts?

--
Ticket URL: <https://core.trac.wordpress.org/ticket/38548>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list