-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use global variable in wp_script_modules()
#5945
Use global variable in wp_script_modules()
#5945
Conversation
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
The idea of
The idea to avoid loading/instantiating the class early in the WordPress bootstrap also came from Felix:
Taking into account what Felix said, I thought it would be even nicer to add the hooks inside the first call to the Again, as Felix said, it's probably not a big deal, just an optimization. I don't have strong preferences over any of the options, though, so feel free to change it if you want 🙂 |
Hmm I see. Well in that case I suppose keeping the function is fine, but not a fan of adding the hooks in there as well. |
wp_script_modules
functionwp_script_modules
function
wp_script_modules
functionwp_script_modules()
Committed in https://core.trac.wordpress.org/changeset/57503 |
Could you please take a look at the class initialization at #5953? I'm doing something similar there to what I did here, and I don't know what the correct way to do it would be. Thanks 🙏 |
Only noticed this while looking at #5888
wp_script_modules()
is an odd function because a) it doesn't use aget_instance()
method like elsewhere in core, b) it does more than just returning an instance. The first time you call it, it adds hooks.Curious to hear thoughts on this alternative suggestion.
cc @luisherranz
Trac ticket: https://core.trac.wordpress.org/ticket/56313
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.