Skip to content

Move render_js() call to enqueue scripts callback#848

Merged
agibson-godaddy merged 2 commits into
release/6.2.3from
mwc-20065
Jun 23, 2026
Merged

Move render_js() call to enqueue scripts callback#848
agibson-godaddy merged 2 commits into
release/6.2.3from
mwc-20065

Conversation

@agibson-godaddy

@agibson-godaddy agibson-godaddy commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Summary

SV_WP_Job_Batch_Handler::__construct() was calling $this->render_js() directly. Consumers typically instantiate the handler during plugins_loaded (e.g. CSV Export's includes()), so render_js() — which calls ScriptHelper::addInlineScript()wp_register_script() — ran before admin_enqueue_scripts. As of WP 6.7, that trips a _doing_it_wrong notice on every admin page load.

This PR moves the render_js() call into enqueue_scripts(), which is already hooked to admin_enqueue_scripts in add_hooks() and is also where the script handle the inline JS attaches to is registered.

Story: MWC-20065

Release: #847

Details

  • __construct() no longer calls render_js().
  • enqueue_scripts() calls render_js() after enqueuing the handler script, so the inline new SV_WP_Job_Batch_Handler(...) snippet is still attached to the right handle and emitted on the same admin pages as before.
  • No public API changes; subclasses that override enqueue_scripts() and call parent::enqueue_scripts() (the documented pattern) pick up the new behavior automatically.

QA

Setup

  • WordPress 6.7 or newer (so the _doing_it_wrong notice is emitted).
  • WP_DEBUG and WP_DEBUG_LOG enabled, or define( 'WP_DEBUG_DISPLAY', true ) so notices surface.
  • WooCommerce Customer/Order/Coupon Export plugin installed and active. Point its composer.json at this branch (mwc-20065) and composer update skyverge/wc-plugin-framework so it loads the patched framework copy.
  • At least one order exists in the store so an export has something to process.

Steps

  1. With the unpatched framework still in place, load any WP admin page (e.g. WP dashboard).
    • debug.log / on-screen notice contains: "Function wp_register_script was called incorrectly... triggered by the wc_customer_order_export_background_export_batch_handler handle." (baseline — confirm the bug reproduces before fixing)
  2. Switch the CSV Export plugin to the patched framework branch and reload the same admin page.
    • The _doing_it_wrong notice is gone from debug.log and the page.
  3. Go to WooCommerce → Exports → Export, tick Enable batch processing, and run a manual orders export.
    • The progress modal appears and the progress bar advances from 0% to 100%.
    • The export completes and the file downloads (or is delivered per the chosen method).
  4. On the same export screen, open browser DevTools → Console and evaluate window.wc_customer_order_export_background_export_batch_handler.
    • It is an instance of SV_WP_Job_Batch_Handler (not undefined). This proves the inline render_js() snippet executed on the page.
  5. View page source / Network tab on the export screen and search for new SV_WP_Job_Batch_Handler(.
    • The inline script tag is present in the rendered HTML.
  6. Cancel a batch export mid-run via the modal's Cancel button.
    • The job stops and the modal closes cleanly (exercises the cancel_job AJAX path wired up via the same inline JS).
image

Before merge

  • I have confirmed these changes in each supported minor WooCommerce version

@agibson-godaddy agibson-godaddy self-assigned this Jun 23, 2026
@agibson-godaddy agibson-godaddy mentioned this pull request Jun 23, 2026
2 tasks
@agibson-godaddy agibson-godaddy marked this pull request as ready for review June 23, 2026 13:48
@agibson-godaddy agibson-godaddy merged commit 5573a3d into release/6.2.3 Jun 23, 2026
5 checks passed
@agibson-godaddy agibson-godaddy deleted the mwc-20065 branch June 23, 2026 13:49
agibson-godaddy added a commit that referenced this pull request Jun 23, 2026
* Version 6.2.3

* Move render_js() call to enqueue scripts callback (#848)

* Move render_js() call to enqueue scripts callback

* Switch to inline jQuery

* Fill out date

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Ashley Gibson <99189195+agibson-godaddy@users.noreply.github.com>
Co-authored-by: Ashley Gibson <agibson@godaddy.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant