[wp-trac] [WordPress Trac] #41990: wp_add_inline_script() does not print if the handler has already processed
WordPress Trac
noreply at wordpress.org
Wed Apr 12 04:51:08 UTC 2023
#41990: wp_add_inline_script() does not print if the handler has already processed
-------------------------------------------------+-------------------------
Reporter: satollo | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Future
| Release
Component: Script Loader | Version: 4.5
Severity: normal | Resolution:
Keywords: has-patch 2nd-opinion needs-testing | Focuses:
-------------------------------------------------+-------------------------
Changes (by Howdy_McGee):
* keywords: needs-patch => has-patch 2nd-opinion needs-testing
Comment:
I agree that it makes sense to run the 'after' script extras in the footer
if they're missed during the `wp_head` runtime. The provided patch
modifies `WP_Scripts::add_inline_script()` and checks if
`wp_print_scripts` has run. If so, the handle is added to a new
`WP_Scripts::deferred_extras` property which is looped through during
`WP_Scripts::do_footer_items()`. Using `wp_print_scripts` ensures this
functions on both the front-end and admin.
One issue I found while testing this patch is it's all-or-nothing. The
WP_Scripts Class does not keep track of which extras have been printed.
Calling `wp_add_inline_script()` for the same $handle in
`wp_enqueue_scripts` and then a 2nd time in a future hook such as
`wp_body_open` (for example) results in all 'after' extras being printed
to the footer. Should we keep track of which extras have been printed?
This feature needs more discussion. This patch needs more testing and more
feedback.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/41990#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list