Skip to content

fix: keep MU-Migration WP-CLI shim out of autoloaders#1628

Merged
superdav42 merged 3 commits into
mainfrom
fix/exclude-mu-migration-autoload
Jul 11, 2026
Merged

fix: keep MU-Migration WP-CLI shim out of autoloaders#1628
superdav42 merged 3 commits into
mainfrom
fix/exclude-mu-migration-autoload

Conversation

@superdav42

@superdav42 superdav42 commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

Why

The 2.14.0/2.14.1 package could expose the bundled fake global WP_CLI facade through generated autoload maps. Third-party plugins that use class_exists( 'WP_CLI' ) as a CLI detector can then load CLI-only code during web/bootstrap requests.

Verification

  • composer dump-autoload --optimize
  • Generated Composer and Jetpack maps contain no global WP_CLI, WP_CLI_Command, or inc/site-exporter/mu-migration entries.
  • Composer autoload harness: class_exists( 'WP_CLI' ) stays false, explicit polyfill require still works.
  • Jetpack autoload harness: class_exists( 'WP_CLI' ) stays false.
  • vendor/bin/phpcs composer-plugins/wp-ultimo-autoloader-plugin/src/class-wp-ultimo-autoloader-plugin.php tests/WP_Ultimo/Autoloader_Test.php
  • php -l for touched PHP files.
  • composer validate --no-check-publish (warnings only for existing package metadata).
  • Built a corrected-slug ZIP and installed it on Jurassic Ninja over 2.14.0: plugin remained network-active at 2.14.1; home returned 200, wp-admin returned 302, wp-cron returned 200; wp php-errors produced no fatal output.

Note

vendor/bin/phpunit --filter Autoloader_Test is blocked locally because the WordPress test library is not installed.


aidevops.sh v3.32.32 plugin for OpenCode v1.17.18

Summary by CodeRabbit

  • Bug Fixes
    • Improved Ultimate Multisite autoloader/classmap handling to exclude MU-Migration entries and ensure the correct Jetpack classmap output.
    • Added additional safeguards for missing or unexpected classmap content, and refined the confirmation message when classmap updates occur.
  • Tests
    • Added coverage to verify the MU-Migration WP-CLI polyfill is not autoloaded during web requests.

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 71971fa3-493b-4122-86a0-2e65f4adffe2

📥 Commits

Reviewing files that changed from the base of the PR and between 1c6defa and 2d7b0f0.

📒 Files selected for processing (2)
  • composer-plugins/wp-ultimo-autoloader-plugin/src/class-wp-ultimo-autoloader-plugin.php
  • tests/WP_Ultimo/Autoloader_Test.php
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/WP_Ultimo/Autoloader_Test.php
  • composer-plugins/wp-ultimo-autoloader-plugin/src/class-wp-ultimo-autoloader-plugin.php

📝 Walkthrough

Walkthrough

The change excludes MU-Migration classes from Composer and Jetpack classmaps, updates the WP Ultimo autoloader plugin’s classmap handling, and adds a regression test confirming the WP-CLI polyfill is not autoloadable.

Changes

MU-Migration autoload handling

Layer / File(s) Summary
Composer autoload configuration
composer.json, composer-plugins/wp-ultimo-autoloader-plugin/composer.json
Composer excludes the MU-Migration directory from generated classmaps, while the plugin uses an explicit classmap entry for its main class.
Jetpack classmap filtering and validation
composer-plugins/wp-ultimo-autoloader-plugin/src/class-wp-ultimo-autoloader-plugin.php, tests/WP_Ultimo/Autoloader_Test.php
The plugin handles failed classmap reads, removes MU-Migration entries, conditionally adds its guard, and tests that WP_CLI cannot be autoloaded.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Composer
  participant modifyJetpackAutoloader
  participant Autoloader_Test
  Composer->>modifyJetpackAutoloader: Provide generated classmap
  modifyJetpackAutoloader->>modifyJetpackAutoloader: Filter MU-Migration entries
  modifyJetpackAutoloader-->>Composer: Write modified classmap
  Autoloader_Test->>Composer: Resolve WP_CLI
  Composer-->>Autoloader_Test: WP_CLI is not autoloadable
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: keeping the MU-Migration WP-CLI shim out of autoloaders.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/exclude-mu-migration-autoload

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

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

@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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
composer-plugins/wp-ultimo-autoloader-plugin/src/class-wp-ultimo-autoloader-plugin.php (1)

124-140: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Regex is fragile against Jetpack classmap format changes.

The regex on line 136 assumes specific formatting (tabs, array() syntax, field ordering version then path). If a future Jetpack Autoloader version changes its classmap format — e.g., switching to [] short array syntax, different indentation, or reordered fields — the regex will silently fail to match, leaving MU-Migration entries in the classmap. The is_string($filtered) fallback on line 139 ensures safety (no crash), but the exclusion would be silently ineffective.

Consider adding a log warning when the regex doesn't match any entries, so a format change is detectable rather than silent.

♻️ Suggested: log when no entries are removed
 private function exclude_mu_migration_from_jetpack_classmap($content) {

 	$pattern  = "/\n\t'[^']+' => array\(\n\t\t'version' => '[^']+',\n\t\t'path'\s*=> [^\n]*\\/inc\\/site-exporter\\/mu-migration\\/[^\n]*\n\t\),/";
 	$filtered = preg_replace($pattern, '', $content);
 
-	return is_string($filtered) ? $filtered : $content;
+	if ( ! is_string($filtered) ) {
+		return $content;
+	}
+
+	if ( $filtered === $content && strpos($content, 'mu-migration') !== false ) {
+		$this->io->write('<warning> MU-Migration entries found in Jetpack classmap but regex did not match — classmap format may have changed.</warning>');
+	}
+
+	return $filtered;
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@composer-plugins/wp-ultimo-autoloader-plugin/src/class-wp-ultimo-autoloader-plugin.php`
around lines 124 - 140, Update exclude_mu_migration_from_jetpack_classmap to
detect when the MU-Migration exclusion pattern removes no entries and emit a
warning through the plugin’s existing logging mechanism. Preserve the current
content fallback when preg_replace fails, and ensure the warning only signals an
unmatched or unsupported classmap format rather than normal successful removal.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/WP_Ultimo/Autoloader_Test.php`:
- Around line 66-74: Update the skip condition in
test_mu_migration_wp_cli_polyfill_is_not_autoloadable to use
class_exists('WP_CLI', false) instead of checking the WP_CLI constant, so the
test skips when the real WP-CLI class is already loaded. Preserve the existing
skip message and assertions.

---

Nitpick comments:
In
`@composer-plugins/wp-ultimo-autoloader-plugin/src/class-wp-ultimo-autoloader-plugin.php`:
- Around line 124-140: Update exclude_mu_migration_from_jetpack_classmap to
detect when the MU-Migration exclusion pattern removes no entries and emit a
warning through the plugin’s existing logging mechanism. Preserve the current
content fallback when preg_replace fails, and ensure the warning only signals an
unmatched or unsupported classmap format rather than normal successful removal.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 44fe293a-629a-4c1d-a567-a807843e3947

📥 Commits

Reviewing files that changed from the base of the PR and between 06901b4 and 1c6defa.

⛔ Files ignored due to path filters (1)
  • composer.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • composer-plugins/wp-ultimo-autoloader-plugin/composer.json
  • composer-plugins/wp-ultimo-autoloader-plugin/src/class-wp-ultimo-autoloader-plugin.php
  • composer.json
  • tests/WP_Ultimo/Autoloader_Test.php

Comment thread tests/WP_Ultimo/Autoloader_Test.php
@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

Performance Test Results

Performance test results for 9c37294 are in 🛎️!

@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

@superdav42 superdav42 merged commit 0f16108 into main Jul 11, 2026
11 checks passed
@superdav42 superdav42 added the review-feedback-scanned Merged PR already scanned for quality feedback label Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review-feedback-scanned Merged PR already scanned for quality feedback

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant