Skip to content
38 changes: 38 additions & 0 deletions features/scaffold.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
swissspidy marked this conversation as resolved.
Outdated
"""

# 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`
Expand Down
14 changes: 14 additions & 0 deletions src/Scaffold_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -539,12 +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' ) ) {
$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 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'];
Expand Down
Loading