[wp-trac] [WordPress Trac] #22249: Add ability to set or remove attributes on enqueued scripts and styles.
WordPress Trac
noreply at wordpress.org
Thu Oct 23 21:45:57 UTC 2014
#22249: Add ability to set or remove attributes on enqueued scripts and styles.
-------------------------------------------------+-------------------------
Reporter: ryanve | Owner:
Type: feature request | Status: new
Priority: normal | Milestone: Awaiting
Component: Script Loader | Review
Severity: normal | Version:
Keywords: dev-feedback has-patch reporter- | Resolution:
feedback 2nd-opinion needs-testing | Focuses:
-------------------------------------------------+-------------------------
Comment (by boonebgorges):
[attachment:22249.diff] is a pretty cool idea. A couple thoughts I had
while looking the patch over:
* There was a suggestion earlier about making `wp_register_script()`
accept an array for `$src`. 22249.diff doesn't include this, but hides
everything in a filter. By not making this accessible as a function
argument, it buries the functionality a bit. It also suggests that changes
to these attributes are generally something you'd want to do on a specific
site or with a specific theme - acting on *someone else's* scripts -
rather than in a plugin that registers its own scripts. I can imagine
situations where the plugin/theme registering the script would want to
pass some custom attributes, and it seems pretty hackish to require them
to add a filter for that purpose. So I'd suggest adding array support.
(I'm not 100% sure that it makes sense to do this by allowing `$src` to be
an array - in which case the variable name and docs would certainly have
to be changed - or if another param should be added to the function for
the attributes.)
* Related: 'src' is not being passed to the new filter, but is hardcoded
into the `<script>` tag. I can imagine some benefits of putting 'src' into
the `$default_attributes` array and allowing it to be filtered as well.
You'd probably need some sanity checks after the filter to make sure that
'src' hasn't been removed from the array.
* Could stylesheets use the same treatment?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/22249#comment:13>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list