Fix child theme activation failure on subsequent runs with different slug and name#369
Merged
swissspidy merged 9 commits intomainfrom Feb 16, 2026
Merged
Conversation
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix activate fails after running second time with different theme
Fix child theme activation failure on subsequent runs with different slug and name
Feb 2, 2026
swissspidy
reviewed
Feb 4, 2026
This comment was marked as resolved.
This comment was marked as resolved.
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
swissspidy
approved these changes
Feb 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix child theme activation failure on subsequent runs with different slug and name
Problem
When running
wp scaffold child-themewith--activateflag wheretheme_slugandtheme_nameare different, the activation works on the first run but fails on the second run after deleting and recreating the theme.Test failure: The theme activate command was reporting "The theme directory 'first-run' does not exist" even after clearing WordPress transients, object cache, and PHP filesystem cache.
Root Cause
WordPress caches theme information in multiple layers, including individual
WP_Themeobject caches that persist error states. When a theme is deleted, WordPress creates aWP_Themeobject with an error state ("The theme directory ... does not exist") that gets cached. When the theme is recreated, this cached error object prevents activation even after clearing global caches.The caching layers involved:
clearstatcache()✓theme_roots- cleared withdelete_site_transient()✓themesin thethemesgroup - cleared withwp_cache_delete()✓search_theme_directories()- rebuilt ✓Solution
Updated
refresh_theme_cache()method to clear all cache layers including individualWP_Themeobject caches. The cache keys are calculated usingmd5($theme_root . '/' . $theme_slug)and cleared for all four cache types:theme,screenshot,headers, andpage_templates. This follows the same pattern used in WP-CLI'sTheme_Commandwhich includes the comment "Clear cache so WP_Theme doesn't create a 'missing theme' object."Changes
clearstatcache()to clear PHP's filesystem stat cacherefresh_theme_cache()to accept$theme_slugparameterTesting
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.