[wp-trac] [WordPress Trac] #40485: Add function for retrieving metadata from registered script
WordPress Trac
noreply at wordpress.org
Thu Aug 21 15:55:32 UTC 2025
#40485: Add function for retrieving metadata from registered script
-------------------------------------------------+-------------------------
Reporter: desrosj | Owner: (none)
Type: feature request | Status: new
Priority: normal | Milestone: Awaiting
| Review
Component: Script Loader | Version: 4.2
Severity: normal | Resolution:
Keywords: has-patch has-unit-tests needs- | Focuses:
testing 2nd-opinion |
-------------------------------------------------+-------------------------
Changes (by desrosj):
* keywords: has-patch has-unit-tests needs-testing reporter-feedback =>
has-patch has-unit-tests needs-testing 2nd-opinion
Comment:
Looking back and considering the original use case for this ticket, I
think that there's a better approach. Instead of relying on a function or
method to retrieve the value, confirming that the expected value is
present by inspecting the global `$wp_scripts` variable directly would be
a better methodology.
I do think it's good practice to provide symmetry for these types of
wrapper functions. But we should consider compelling, real-world use
cases.
A [https://wpdirectory.net/search/01K344YGASY26WPZSH18Y5J0MZ preliminary
search of the plugin directory] reveals that while it's relatively
uncommon, some plugins do call `$wp_scripts->get_data()` directly. The
search found 121 matches, including 13 across 7 plugins with over 100,000
installs. Interestingly,
[https://core.trac.wordpress.org/browser/trunk/src/wp-
content/themes/twentytwenty/classes/class-twentytwenty-script-loader.php
Twenty Twenty has 4 occurrences] in `class-twentytwenty-script-
loader.php`.
As for precedent, here are a couple of examples of introducing adding
`get_*` functions to accompany `(add|register)_*` ones (though admittedly
these had stronger rationale and aren't "wrapper" functions):
- `get_theme_support()` was added in 3.1 ([16174]) while
`add_theme_support()` was introduced in 2.9 ([12132]).
- `get_post_type_object()` was added in 3.0 ([12597]) while
`register_post_type()` was introduced in 2.9 ([11998]).
Also of note is that the Dependencies APi is consistent between scripts
and styles: `wp_style_add_data()` exists but `wp_style_get_data()` does
not.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/40485#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list