Repository navigation
Fix false _doing_it_wrong in ScriptHelper::addInlineScript() on WP 6.9+ block editor - #864
smoen-godaddy wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The fallback can call an unavailable function on supported WordPress 5.6 installations.
1 open finding
What changed in this PR
Prevents block-editor admin notice scripts from triggering _doing_it_wrong on WordPress 6.9+.
Changes:
- Detects when footer scripts were already printed.
- Directly outputs the admin notice JavaScript in that case.
| File | Description |
|---|---|
woocommerce/class-sv-wc-admin-notice-handler.php |
Adds fallback script rendering after footer scripts run. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
Hi @agibson-godaddy , #864 is ready for review (Copilot’s WP 5.6 finding is fixed in the second commit). One question on merge order: Memberships #1313 is on framework 6.2.1, so picking up this fix through a new framework tag would mean a namespace upgrade. Since #1313 already has its own guard for the Memberships override, could it merge independently, with Memberships picking up #864 at its next framework upgrade? |
agibson-godaddy
left a comment
There was a problem hiding this comment.
@smoen-godaddy Thanks for tracking this down. I confirmed the cause in core: _wp_get_iframed_editor_assets() calls wp_print_footer_scripts() against throwaway WP_Scripts instances, which bumps did_action('wp_print_footer_scripts') before admin_footer fires.
I'm not sure this is the right layer for the fix, though. The false positive comes from the guard in ScriptHelper::addInlineScript(), so every other caller of that helper (and every plugin using it) will still hit the notice in the block editor. I'd suggest fixing it once in the helper. In admin, check did_action('admin_print_footer_scripts') instead, since that only fires for the real footer pass. That would let this method go back to the single ScriptHelper::addInlineScript() call.
|
Thanks. I’ve moved the fix into ScriptHelper::addInlineScript() and reverted the change to SV_WC_Admin_Notice_Handler::render_admin_notice_js() (including the WP 5.6 wp_print_inline_script_tag() fallback), so it goes back to the single helper call. In admin, the helper now checks did_action('admin_print_footer_scripts'). I confirmed in core that admin_footer (line 78) fires before admin_print_footer_scripts (line 95), and that _wp_get_iframed_editor_assets() only calls wp_print_footer_scripts() directly, never admin_print_footer_scripts. One open point: the _doing_it_wrong message still says “before the wp_print_footer_scripts action,” which is slightly inaccurate in admin now. I can reword it (e.g. “before the footer scripts are printed”) if you’d like, please let me know. |
Yep let's reword it. We should be able to customize the message per-environment so that the hook name is accurate for both. |

Summary
Fixes a
_doing_it_wrongnotice fired bySV_WC_Admin_Notice_Handler::render_admin_notice_js()on every block editor screen in WP 6.9+, caused by an inline-script timing conflict with WordPress's new iframed editor asset collector.Story: MWC-20359
Release: TBD
Details
WP 6.9+ introduced
_wp_get_iframed_editor_assets(), which callswp_print_footer_scripts()during block editor initialization — beforeadmin_footerfires — incrementing the globaldid_action('wp_print_footer_scripts')counter. Whenrender_admin_notice_js()subsequently runs atadmin_footer:20,ScriptHelper::addInlineScript()sees the counter already elevated and triggers_doing_it_wrong.The fix guards the call with
did_action('wp_print_footer_scripts'): if it has already fired, the script is output directly viawp_print_inline_script_tag()(available since WP 6.0) instead of routing throughScriptHelper.This affects all framework-based plugins on WP 6.9+, not just Memberships companion fix in the
woocommerce-membershipsrepo (MWC-20359) applies the same guard to a plugin-specific override.UI Changes
None.
QA
Setup
WP_DEBUGenabledSteps
_doing_it_wrongnotice referencingScriptHelper::addInlineScriptappears indebug.logBefore merge