Uh oh!
There was an error while loading. Please reload this page.
Enqueue wp_enqueue_media instead of calling it directly - #50
Conversation
- It should be called from the 'admin_enqueue_scripts' action hook, or later - Resolves loops-and-logic#3 (actually in Tangible Blocks)
@nicolas-jaussaud I'm still working on this one, it needs a function to call
|
…dmin or site frontend; Add tests and utility methods to mock is_admin and did/doing_action
eliot-akira
commented
Aug 24, 2025
OK, it has comprehensive coverage now. The new function
This is currently used by the Also added tests, and utility methods to mock |
nicolas-jaussaud
commented
Aug 25, 2025
Thanks a lot for looking into it and for implementing the tests! I added a small change and set the priority of the action that call wp_enqueue_media to 9, so that it's before the fields script (that are enqueued in footer hooks as well, here) I ran the tests again to be sure my change did break something, and did some manual testing in both the fields examples and in blocks. I didn't notice any issue so it should be ok! |
Uh oh!
There was an error while loading. Please reload this page.
Good catch! That makes sense, because at 10 the Fields' script is enqueued which may need the media uploader. Where that happens, I saw: The media uploader isn't enqueued in the login page footer, so technically the file and gallery field types won't work in that situation. Is that an important use case to cover, using fields in the login page? If so, I can make a change to the new enqueue function: if (is_admin()) {
// Admin
+} elseif (is_login()) {++ // Login page+ $action = 'login_footer';+
} else {
// Site frontend
} |
nicolas-jaussaud
commented
Aug 26, 2025
Oops thank you, I forgot we need to support that context! I added support for it in this commit: 495d445 It discovered there is a } elseif (is_login()) {
// Login// Before document head$action = 'login_enqueue_scripts';
if (doing_action($action) || did_action($action)) {
$action = 'login_footer'; // During and after
}
} else { |
Oh I've never used that one before, Relatedly I was wondering about Tangible Blocks and L&L, which have dynamic frontend features that require JS & CSS, like a gallery or slider. I have a feeling some are only enqueued on the site frontend but not on admin side. And definitely not in the login page. For blocks and templates to support all contexts, it will be good to create a "universal enqueue" function for all those dynamic features to use. I suppose that belongs in the Framework module. OK, created an issue as reminder: |
admin_enqueue_scriptsaction hook or laterIt needs to handle:
admin_enqueue_scriptsaction has run alreadyadmin_enqueue_scriptsis never called