Skip to content

GH#1006 GH#1007: fix: WP-CLI command registration + Site_Exporter before requirements gate#1036

Merged
superdav42 merged 2 commits intomainfrom
feature/auto-20260430-005158-gh1007
Apr 30, 2026
Merged

GH#1006 GH#1007: fix: WP-CLI command registration + Site_Exporter before requirements gate#1036
superdav42 merged 2 commits intomainfrom
feature/auto-20260430-005158-gh1007

Conversation

@superdav42
Copy link
Copy Markdown
Collaborator

@superdav42 superdav42 commented Apr 30, 2026

Summary

This PR combines two closely related fixes for the Site Exporter:

  1. GH#1007 — Site Exporter was initialized after the Requirements gate, making export unavailable during migration scenarios
  2. GH#1006 — mu-migration WP-CLI commands were not registered because load_dependencies() was called too late for WP-CLI command discovery

These two issues compound each other: #1007 means the Site_Exporter never loads in migration scenarios; #1006 means even when it does load, the WP-CLI commands are never registered.

Changes

EDIT: inc/class-wp-ultimo.php (GH#1007)

  • Move \WP_Ultimo\Site_Exporter\Site_Exporter::get_instance() from the fully-loaded section (~line 584) to immediately before the requirements gate
  • Remove the now-redundant call in the fully-loaded section
  • Add an explanatory comment describing why this is safe and intentional

EDIT: inc/site-exporter/class-site-exporter.php (GH#1006)

  • Add early load_dependencies() call in setup() guarded by defined('WP_CLI') && WP_CLI
  • Each mu-migration class file ends with a bare WP_CLI::add_command() call that fires at include-time; calling load_dependencies() early ensures these run before WP-CLI finishes its bootstrap phase
  • The require_once calls inside load_dependencies() are idempotent, so the lazy call from handle_site_export() is harmless

Testing

# WP-CLI commands should now be discoverable
wp help mu-migration
wp mu-migration export all /tmp/export.zip --blog_id=2 --url=http://wordpress.local:8080
wp mu-migration import all /tmp/export.zip --new_url=http://newsite.example.com

# Syntax check
php -l inc/site-exporter/class-site-exporter.php

Resolves #1006
Resolves #1007

…gate

Move Site_Exporter::get_instance() from the fully-loaded section (~line 584)
to before the Requirements::met() / run_setup() early-return (~line 188).

This ensures that all Site_Exporter functionality is available even when
Ultimate Multisite is not fully configured:

- Sites > Export & Import admin menu item is registered
- Export/import row actions appear on the WordPress Sites page
- Export/import form handlers and download endpoint are hooked
- WP Ultimo-specific hooks (wu_export_site, wu_import_site, etc.) are
  also available for when WP Ultimo IS set up (no change in behaviour)

The Singleton trait ensures init() runs exactly once, so hoisting the
call is safe even though the fully-loaded boot path no longer calls it a
second time.

Resolves #1007
…orter::setup()

WP-CLI performs command discovery early in its bootstrap process. The
mu-migration command class files each end with a bare WP_CLI::add_command()
call that fires at file-include time, but load_dependencies() was only
ever called lazily from handle_site_export() / handle_site_import() -
far too late for WP-CLI to discover them.

Add an early call to load_dependencies() in setup() when WP_CLI is defined
and truthy. This mirrors the pattern in inc/apis/trait-wp-cli.php
(enable_wp_cli()) used by every other manager that registers WP-CLI
commands. The require_once calls inside load_dependencies() are idempotent,
so the lazy call from handle_site_export() remains harmless.

Combined with the GH#1007 fix (Site_Exporter now loads before the
requirements gate), this makes the commands available even when Ultimate
Multisite is not fully set up - which is the primary migration use case.

Resolves #1006
@superdav42 superdav42 added bug Something isn't working origin:interactive Created by interactive user session labels Apr 30, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 30, 2026

Warning

Rate limit exceeded

@superdav42 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 46 minutes and 8 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 256db5da-e964-4fb2-9975-51a5a3afcbcf

📥 Commits

Reviewing files that changed from the base of the PR and between 5f498b9 and 2a555e4.

📒 Files selected for processing (2)
  • inc/class-wp-ultimo.php
  • inc/site-exporter/class-site-exporter.php
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/auto-20260430-005158-gh1007

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 46 minutes and 8 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@superdav42 superdav42 changed the title GH#1007: fix: initialize Site_Exporter before the requirements/setup gate GH#1006 GH#1007: fix: WP-CLI command registration + Site_Exporter before requirements gate Apr 30, 2026
@github-actions
Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

@github-actions
Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 30, 2026

Performance Test Results

Performance test results for c5a94c4 are in 🛎️!

Note: the numbers in parentheses show the difference to the previous (baseline) test run. Differences below 2% or 0.5 in absolute values are not shown.

URL: /

Run DB Queries Memory Before Template Template WP Total LCP TTFB LCP - TTFB
0 40 (-2 / -4% ) 37.73 MB 860.00 ms (-37.50 ms / -4% ) 163.50 ms (-12.00 ms / -7% ) 1063.00 ms (-23.50 ms / -2% ) 1992.00 ms (-60.00 ms / -3% ) 1900.90 ms (-68.70 ms / -4% ) 90.90 ms (+2.75 ms / +3% )
1 56 49.10 MB 908.00 ms (-27.00 ms / -3% ) 150.50 ms (+4.00 ms / +3% ) 1064.50 ms 2068.00 ms 1985.30 ms 81.75 ms

@superdav42
Copy link
Copy Markdown
Collaborator Author

What was done

Fixed the 'mu-migration' is not a registered wp command error (GH#1006) by registering the mu-migration WP-CLI commands early in the plugin lifecycle, and ensured the Site_Exporter loads before the requirements gate (GH#1007) so export/import works during migration scenarios.

GH#1006 — WP-CLI commands not registered

The mu-migration class files each end with a bare WP_CLI::add_command() call that fires at require_once time. Previously, load_dependencies() was only called from handle_site_export() / handle_site_import() — far too late for WP-CLI command discovery. Added an early call to load_dependencies() in Site_Exporter::setup() guarded by defined('WP_CLI') && WP_CLI.

GH#1007 — Site_Exporter not loaded before requirements gate

Site_Exporter::get_instance() was at ~line 584, after the Requirements::met() early-return gate. Moved it to before the gate so the WordPress Sites page export/import integration (and WP-CLI) work even when Ultimate Multisite is not fully configured.

Files changed

  • inc/site-exporter/class-site-exporter.phpsetup() now calls load_dependencies() early when WP-CLI is active
  • inc/class-wp-ultimo.php — Site_Exporter initialized before requirements gate

Verification

All CI checks passed: PHP 8.2–8.5, Code Quality, E2E (Cypress), PHP Lint.

@superdav42 superdav42 merged commit fcc5d42 into main Apr 30, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working origin:interactive Created by interactive user session

Projects

None yet

1 participant