[wp-trac] [WordPress Trac] #22249: Add ability to set or remove attributes on enqueued scripts and styles.

WordPress Trac noreply at wordpress.org
Tue Feb 23 00:54:22 UTC 2016


#22249: Add ability to set or remove attributes on enqueued scripts and styles.
----------------------------------------+------------------------
 Reporter:  ryanve                      |       Owner:  chriscct7
     Type:  feature request             |      Status:  assigned
 Priority:  normal                      |   Milestone:  4.5
Component:  Script Loader               |     Version:
 Severity:  normal                      |  Resolution:
 Keywords:  has-patch needs-unit-tests  |     Focuses:
----------------------------------------+------------------------

Comment (by ericlewis):

 Replying to [comment:27 boonebgorges]:
 > The method name `get_concatenated_script_attributes()` threw me for a
 loop, because 'concatenated' has a different and more frequently used
 meaning in the context of scripts/styles. I'd suggest something like
 `get_script_attribute_html()`.

 Totally.

 > Did we actively decide not to give the same treatment to
 `wp_enqueue_style()`?

 Let's land on an implementation for scripts first.

 > Why are we passing around `$handle` and `$src` in
 `get_concatenated_script_attributes()`, etc, but getting `$args` and
 `$attributes` from object properties?

 The script object's property for `$src` is not an expanded URL (no base
 URL or version query string). That happens in `WP_Scripts->do_item()`.
 I've introduced `WP_Scripts->get_script_src()` in attachment:22249.4.diff
 which extracts this src expansion logic. Using this in
 `get_script_attributes()` removes the need to toss around `$src`. Also has
 tests.

 > Can we not do the weird ternary formatting in `get_script_attributes()`?
 If it's so confusing, just make it an `if/else` :)

 100% yes.

 Also in attachment:22249.4.diff, I've renamed the filter for a script's
 attributes from `script_loader_attributes` to just `script_attributes`,
 and removed the `$src` parameter. Handle should be useful enough.

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


More information about the wp-trac mailing list