Make WordPress Core

Opened 8 years ago

Last modified 5 years ago

#38548 new enhancement

Add new filters on wp_script_is/wp_style_is

Reported by: igmoweb's profile igmoweb Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.7
Component: Script Loader Keywords:
Focuses: Cc:


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:

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 ];

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

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

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

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

Any thoughts?

Change History (0)

Note: See TracTickets for help on using tickets.