Skip to content

Commit 6a7e45e

Browse files
Copilotswissspidy
andcommitted
Fix theme activation when slug and name differ by refreshing theme cache
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 5cbbab2 commit 6a7e45e

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

features/scaffold.feature

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,44 @@ Feature: WordPress code scaffolding
5858
Success: Network enabled the 'Zombieland' theme.
5959
"""
6060

61+
Scenario: Scaffold a child theme and activate it with different slug and name
62+
Given a WP install
63+
64+
When I run `wp theme install twentytwentyone --force`
65+
Then STDOUT should not be empty
66+
67+
And I run `wp theme path`
68+
And save STDOUT as {THEME_DIR}
69+
70+
When I run `wp scaffold child-theme first-run --parent_theme=twentytwentyone --theme_name="First Run Name" --activate`
71+
Then STDOUT should contain:
72+
"""
73+
Success: Created '{THEME_DIR}/first-run'.
74+
"""
75+
And STDOUT should contain:
76+
"""
77+
Success: Switched to 'First Run Name' theme.
78+
"""
79+
80+
When I run `wp theme list --fields=name,status --format=csv`
81+
Then STDOUT should contain:
82+
"""
83+
First Run Name,active
84+
"""
85+
86+
# Now delete the theme and create it again to test the fix for the caching issue
87+
When I run `rm -rf {THEME_DIR}/first-run`
88+
And I run `wp theme activate twentytwentyone`
89+
And I run `wp scaffold child-theme first-run --parent_theme=twentytwentyone --theme_name="First Run Name" --activate`
90+
Then STDOUT should contain:
91+
"""
92+
Success: Created '{THEME_DIR}/first-run'.
93+
"""
94+
And STDOUT should contain:
95+
"""
96+
Success: Switched to 'First Run Name' theme.
97+
"""
98+
6199
Scenario: Scaffold a child theme with invalid slug
62100
Given a WP install
63101
When I try `wp scaffold child-theme . --parent_theme=simple-life`

src/Scaffold_Command.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,8 +539,14 @@ public function child_theme( $args, $assoc_args ) {
539539
$this->log_whether_files_written( $files_written, $skip_message, $success_message );
540540

541541
if ( Utils\get_flag_value( $assoc_args, 'activate' ) ) {
542+
// Refresh theme cache to ensure the newly created theme is recognized.
543+
delete_site_transient( 'theme_roots' );
544+
search_theme_directories( true );
542545
WP_CLI::run_command( [ 'theme', 'activate', $theme_slug ] );
543546
} elseif ( Utils\get_flag_value( $assoc_args, 'enable-network' ) ) {
547+
// Refresh theme cache to ensure the newly created theme is recognized.
548+
delete_site_transient( 'theme_roots' );
549+
search_theme_directories( true );
544550
WP_CLI::run_command( [ 'theme', 'enable', $theme_slug ], [ 'network' => true ] );
545551
}
546552
}

0 commit comments

Comments
 (0)