Skip to content

Delete legacy mu-plugin files that lived in site filesystem#2655

Merged
sejas merged 2 commits intotrunkfrom
fix/stu-1306-cleanup-legacy-mu-plugins
Feb 25, 2026
Merged

Delete legacy mu-plugin files that lived in site filesystem#2655
sejas merged 2 commits intotrunkfrom
fix/stu-1306-cleanup-legacy-mu-plugins

Conversation

@sejas
Copy link
Copy Markdown
Member

@sejas sejas commented Feb 24, 2026

Related issues

Proposed Changes

Sites created with older Studio versions (e.g June 2024) have physical 0-*.php mu-plugin files in wp-content/mu-plugins/. Newer Studio versions inject the same mu-plugins at runtime via the PHP WASM virtual filesystem (/internal/studio/mu-plugins/). When both copies exist, PHP encounters fatal errors like Cannot redeclare check_current_theme_availability().

This PR adds a cleanupLegacyMuPlugins() function that removes known legacy Studio mu-plugin files from the site's wp-content/mu-plugins/ directory before starting the WordPress server or running WP-CLI commands.

Changes:

  • Added cleanupLegacyMuPlugins(sitePath) in tools/common/lib/mu-plugins.ts with an allowlist of 22 known legacy filenames (current + retired)
  • Called the cleanup in wordpress-server-child.ts before building CLI args
  • Called the cleanup in run-wp-cli-command.ts before mounting mu-plugins
  • Added unit tests covering removal, selective preservation, and error handling

Testing Instructions

  1. Create a local site with Studio
  2. Manually add legacy mu-plugin files to the site's wp-content/mu-plugins/ directory:
    echo '<?php function check_current_theme_availability() {}' > ~/Studio/<site>/wp-content/mu-plugins/0-check-theme-availability.php
    echo '<?php // legacy' > ~/Studio/<site>/wp-content/mu-plugins/0-permalinks.php
    
  3. Start the site — it should start without PHP fatal errors
  4. Verify the legacy files were removed from wp-content/mu-plugins/
  5. Verify user mu-plugins (if any) are NOT removed
rayden-muplugins-remove.mp4

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors? (Tests pass, no errors)

Older Studio versions wrote mu-plugin PHP files directly into
wp-content/mu-plugins/. Newer versions inject them at runtime via the
PHP WASM virtual filesystem. Having both causes "Cannot redeclare"
PHP fatal errors. This adds a cleanup step that removes known legacy
files before starting the server or running WP-CLI commands.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sejas sejas self-assigned this Feb 24, 2026
@sejas sejas changed the title Fix PHP fatal error from legacy mu-plugin files after Studio update Fix PHP fatal error from legacy mu-plugin files that lived in site filesystem Feb 24, 2026
@sejas sejas changed the title Fix PHP fatal error from legacy mu-plugin files that lived in site filesystem Delete legacy mu-plugin files that lived in site filesystem Feb 24, 2026
@sejas sejas marked this pull request as ready for review February 25, 2026 13:21
@sejas sejas requested a review from a team February 25, 2026 13:21
Copy link
Copy Markdown
Contributor

@epeicher epeicher left a comment

Choose a reason for hiding this comment

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

Thanks @sejas for solving this, and thanks for the detailed testing instructions! I have tested it, and I confirm that the deprecated files are deleted after starting Studio as expected. Changes also LGTM! :shipit:

Before starting Studio After starting Studio
Image Image

@sejas sejas merged commit c86ecea into trunk Feb 25, 2026
8 checks passed
@sejas sejas deleted the fix/stu-1306-cleanup-legacy-mu-plugins branch February 25, 2026 15:19
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.

2 participants