From 5cbbab27063e7ee4bf9a981e202926a9b6647ca3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 2 Feb 2026 17:31:07 +0000 Subject: [PATCH 1/5] Initial plan From 6a7e45e346fdc95a95e8b72c8d8076055e6e8d9a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 2 Feb 2026 17:36:35 +0000 Subject: [PATCH 2/5] Fix theme activation when slug and name differ by refreshing theme cache Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/scaffold.feature | 38 ++++++++++++++++++++++++++++++++++++++ src/Scaffold_Command.php | 6 ++++++ 2 files changed, 44 insertions(+) diff --git a/features/scaffold.feature b/features/scaffold.feature index 272e625b..e06dcb58 100644 --- a/features/scaffold.feature +++ b/features/scaffold.feature @@ -58,6 +58,44 @@ Feature: WordPress code scaffolding Success: Network enabled the 'Zombieland' theme. """ + Scenario: Scaffold a child theme and activate it with different slug and name + Given a WP install + + When I run `wp theme install twentytwentyone --force` + Then STDOUT should not be empty + + And I run `wp theme path` + And save STDOUT as {THEME_DIR} + + When I run `wp scaffold child-theme first-run --parent_theme=twentytwentyone --theme_name="First Run Name" --activate` + Then STDOUT should contain: + """ + Success: Created '{THEME_DIR}/first-run'. + """ + And STDOUT should contain: + """ + Success: Switched to 'First Run Name' theme. + """ + + When I run `wp theme list --fields=name,status --format=csv` + Then STDOUT should contain: + """ + First Run Name,active + """ + + # Now delete the theme and create it again to test the fix for the caching issue + When I run `rm -rf {THEME_DIR}/first-run` + And I run `wp theme activate twentytwentyone` + And I run `wp scaffold child-theme first-run --parent_theme=twentytwentyone --theme_name="First Run Name" --activate` + Then STDOUT should contain: + """ + Success: Created '{THEME_DIR}/first-run'. + """ + And STDOUT should contain: + """ + Success: Switched to 'First Run Name' theme. + """ + Scenario: Scaffold a child theme with invalid slug Given a WP install When I try `wp scaffold child-theme . --parent_theme=simple-life` diff --git a/src/Scaffold_Command.php b/src/Scaffold_Command.php index 6ff95389..9e9f3d72 100644 --- a/src/Scaffold_Command.php +++ b/src/Scaffold_Command.php @@ -539,8 +539,14 @@ public function child_theme( $args, $assoc_args ) { $this->log_whether_files_written( $files_written, $skip_message, $success_message ); if ( Utils\get_flag_value( $assoc_args, 'activate' ) ) { + // Refresh theme cache to ensure the newly created theme is recognized. + delete_site_transient( 'theme_roots' ); + search_theme_directories( true ); WP_CLI::run_command( [ 'theme', 'activate', $theme_slug ] ); } elseif ( Utils\get_flag_value( $assoc_args, 'enable-network' ) ) { + // Refresh theme cache to ensure the newly created theme is recognized. + delete_site_transient( 'theme_roots' ); + search_theme_directories( true ); WP_CLI::run_command( [ 'theme', 'enable', $theme_slug ], [ 'network' => true ] ); } } From bef9b616ab20a29eba1ab123a79f46d6277a960a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 2 Feb 2026 17:37:45 +0000 Subject: [PATCH 3/5] Refactor theme cache refresh into dedicated method with improved docs Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/Scaffold_Command.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Scaffold_Command.php b/src/Scaffold_Command.php index 9e9f3d72..ae44b31e 100644 --- a/src/Scaffold_Command.php +++ b/src/Scaffold_Command.php @@ -539,18 +539,26 @@ public function child_theme( $args, $assoc_args ) { $this->log_whether_files_written( $files_written, $skip_message, $success_message ); if ( Utils\get_flag_value( $assoc_args, 'activate' ) ) { - // Refresh theme cache to ensure the newly created theme is recognized. - delete_site_transient( 'theme_roots' ); - search_theme_directories( true ); + $this->refresh_theme_cache(); WP_CLI::run_command( [ 'theme', 'activate', $theme_slug ] ); } elseif ( Utils\get_flag_value( $assoc_args, 'enable-network' ) ) { - // Refresh theme cache to ensure the newly created theme is recognized. - delete_site_transient( 'theme_roots' ); - search_theme_directories( true ); + $this->refresh_theme_cache(); WP_CLI::run_command( [ 'theme', 'enable', $theme_slug ], [ 'network' => true ] ); } } + /** + * Refreshes WordPress theme cache. + * + * Clears the theme_roots transient and rebuilds the theme directory cache. + * This ensures newly created themes are recognized by WordPress before + * attempting to activate or enable them. + */ + private function refresh_theme_cache() { + delete_site_transient( 'theme_roots' ); + search_theme_directories( true ); + } + private function get_output_path( $assoc_args, $subdir ) { if ( $assoc_args['theme'] ) { $theme = $assoc_args['theme']; From eb06c25ddcc523ed2846ff862523498292a926a5 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 3 Feb 2026 21:08:15 -0500 Subject: [PATCH 4/5] Apply suggestion from @swissspidy --- features/scaffold.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/scaffold.feature b/features/scaffold.feature index e06dcb58..a492036f 100644 --- a/features/scaffold.feature +++ b/features/scaffold.feature @@ -80,7 +80,7 @@ Feature: WordPress code scaffolding When I run `wp theme list --fields=name,status --format=csv` Then STDOUT should contain: """ - First Run Name,active + first-run,active """ # Now delete the theme and create it again to test the fix for the caching issue From ca7d210302bd35eb7d90e37fbc709cdf2ec78af3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Feb 2026 03:15:04 +0000 Subject: [PATCH 5/5] Add wp_cache_delete to clear theme object cache Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/Scaffold_Command.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Scaffold_Command.php b/src/Scaffold_Command.php index ae44b31e..e3aaae0f 100644 --- a/src/Scaffold_Command.php +++ b/src/Scaffold_Command.php @@ -550,12 +550,13 @@ public function child_theme( $args, $assoc_args ) { /** * Refreshes WordPress theme cache. * - * Clears the theme_roots transient and rebuilds the theme directory cache. - * This ensures newly created themes are recognized by WordPress before - * attempting to activate or enable them. + * Clears the theme_roots transient, object cache, and rebuilds the theme + * directory cache. This ensures newly created themes are recognized by + * WordPress before attempting to activate or enable them. */ private function refresh_theme_cache() { delete_site_transient( 'theme_roots' ); + wp_cache_delete( 'themes', 'themes' ); search_theme_directories( true ); }