Opened 9 years ago
Last modified 4 months ago
#38548 new enhancement
Add new filters on wp_script_is/wp_style_is
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Awaiting Review | Priority: | normal |
| Severity: | normal | Version: | 4.7 |
| Component: | Script Loader | Keywords: | close |
| Focuses: | Cc: |
Description
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 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?
Note: See
TracTickets for help on using
tickets.
Linking wp_style_is() documentation here.
I want to check whether folks are still interested and find this relevant today. The request seems reasonable, but this ticket is 9 years old and hasn't had much activity.
I'll clarify what I understand. Imagine plugins Style and Minifier. The Style plugin produces some styles and needs to query using
wp_style_is()for whatever reason. The Minifier plugin has changed the references that the Style plugin was aware of, causingwp_style_is()to report inaccurate information since the status ofgroup-1implies the status ofstyle-1, althoughstyle-1doesn't exist.By filtering, the Minifier plugin (which is aware of the link between
group-1andstyle-1) can modify the response to report what the Style plugin really wants to know.