diff --git a/features/scaffold.feature b/features/scaffold.feature index 272e625b..a492036f 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,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..e3aaae0f 100644 --- a/src/Scaffold_Command.php +++ b/src/Scaffold_Command.php @@ -539,12 +539,27 @@ 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' ) ) { + $this->refresh_theme_cache(); WP_CLI::run_command( [ 'theme', 'activate', $theme_slug ] ); } elseif ( Utils\get_flag_value( $assoc_args, 'enable-network' ) ) { + $this->refresh_theme_cache(); WP_CLI::run_command( [ 'theme', 'enable', $theme_slug ], [ 'network' => true ] ); } } + /** + * Refreshes WordPress theme cache. + * + * 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 ); + } + private function get_output_path( $assoc_args, $subdir ) { if ( $assoc_args['theme'] ) { $theme = $assoc_args['theme'];