Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Feb 2, 2026

WordPress caches theme metadata in transients and directory listings. When wp scaffold child-theme --activate creates a theme, the cache isn't refreshed before activation. First run succeeds because no cache exists yet. Subsequent runs fail with "theme directory does not exist" because WordPress reads stale cache.

Changes

  • Added refresh_theme_cache() method that clears theme_roots transient and rebuilds directory cache via delete_site_transient() and search_theme_directories(true)
  • Called before activation/enablement in both --activate and --enable-network code paths
  • Added test scenario reproducing the bug: create child theme with --activate, delete it, recreate with same command
if ( Utils\get_flag_value( $assoc_args, 'activate' ) ) {
    $this->refresh_theme_cache();
    WP_CLI::run_command( [ 'theme', 'activate', $theme_slug ] );
}

The issue manifests when theme_slug differs from theme_name (e.g., slug: first-run, name: First Run Name) because WordPress theme lookups depend on accurate cache state.

Original prompt

This section details on the original issue you should resolve

<issue_title>--activate fails after running second time if theme_slug and theme_name are different.</issue_title>
<issue_description>## Bug Report

Describe the current, buggy behavior
Run the following commands in order:

$ vendor/bin/wp scaffold child-theme first_run --parent_theme=twentytwenty --theme_name="first_run_name" --activate --path=../../
Success: Created '/srv/www/wordpress-one/public_html/wp-cli-dev/scaffold-command/../../wp-content/themes/first_run'.
Success: Switched to 'first_run_name' theme.
$ rm -rf ../../wp-content/themes/first_run/
$ wp theme activate twentytwenty
$ vendor/bin/wp scaffold child-theme first_run --parent_theme=twentytwenty --theme_name="first_run_name" --activate --path=../../
Success: Created '/srv/www/wordpress-one/public_html/wp-cli-dev/scaffold-command/../../wp-content/themes/first_run'.
Error: The theme directory "first_run" does not exist.

During the second run the command incorrectly looks for first_run instead of first_run_name to switch to.

Describe what you would expect as the correct outcome

I would expect the server to switch to the correct theme.

Let us know what environment you are running this on

$ vendor/bin/wp cli info
OS:	Linux 5.4.0-91-generic wp-cli/scaffold-command#102-Ubuntu SMP Fri Nov 5 16:31:28 UTC 2021 x86_64
Shell:	/bin/bash
PHP binary:	/usr/bin/php
PHP version:	7.4.29
php.ini used:	/etc/php/7.4/cli/php.ini
MySQL binary:	/usr/bin/mysql
MySQL version:	mysql  Ver 15.1 Distrib 10.5.16-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
SQL modes:	STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
WP-CLI root dir:	/srv/www/wordpress-one/public_html/wp-cli-dev/wp-cli
WP-CLI vendor dir:	/srv/www/wordpress-one/public_html/wp-cli-dev/wp-cli/vendor
WP_CLI phar path:	
WP-CLI packages dir:	/home/vagrant/.wp-cli/packages/
WP-CLI global config:	
WP-CLI project config:	/srv/www/wordpress-one/public_html/wp-cli-dev/scaffold-command/wp-cli.yml
WP-CLI version:	2.7.0-alpha

Provide a possible solution

Provide additional context/Screenshots
Is partially related to #251 as @michaelandre0 already spotted this and I ran into the same situation fixing the path issue. </issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits February 2, 2026 17:36
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
Copilot AI requested a review from swissspidy February 2, 2026 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--activate fails after running second time if theme_slug and theme_name are different.

2 participants