Skip to content

Commit 9d2efaf

Browse files
authored
Merge pull request #369 from wp-cli/copilot/fix-theme-activate-issue
Fix child theme activation failure on subsequent runs with different slug and name
2 parents 5a690ec + 80c8473 commit 9d2efaf

2 files changed

Lines changed: 40 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,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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,8 +539,10 @@ 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+
wp_get_theme( $theme_slug )->cache_delete();
542543
WP_CLI::run_command( [ 'theme', 'activate', $theme_slug ] );
543544
} elseif ( Utils\get_flag_value( $assoc_args, 'enable-network' ) ) {
545+
wp_get_theme( $theme_slug )->cache_delete();
544546
WP_CLI::run_command( [ 'theme', 'enable', $theme_slug ], [ 'network' => true ] );
545547
}
546548
}

0 commit comments

Comments
 (0)