Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,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`
Expand Down
16 changes: 16 additions & 0 deletions src/Scaffold_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -539,12 +539,28 @@ 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 PHP's filesystem cache, WordPress 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() {
clearstatcache();
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'];
Expand Down