Skip to content

Commit bef9b61

Browse files
Copilotswissspidy
andcommitted
Refactor theme cache refresh into dedicated method with improved docs
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 6a7e45e commit bef9b61

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/Scaffold_Command.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -539,18 +539,26 @@ 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 );
542+
$this->refresh_theme_cache();
545543
WP_CLI::run_command( [ 'theme', 'activate', $theme_slug ] );
546544
} 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 );
545+
$this->refresh_theme_cache();
550546
WP_CLI::run_command( [ 'theme', 'enable', $theme_slug ], [ 'network' => true ] );
551547
}
552548
}
553549

550+
/**
551+
* Refreshes WordPress theme cache.
552+
*
553+
* Clears the theme_roots transient and rebuilds the theme directory cache.
554+
* This ensures newly created themes are recognized by WordPress before
555+
* attempting to activate or enable them.
556+
*/
557+
private function refresh_theme_cache() {
558+
delete_site_transient( 'theme_roots' );
559+
search_theme_directories( true );
560+
}
561+
554562
private function get_output_path( $assoc_args, $subdir ) {
555563
if ( $assoc_args['theme'] ) {
556564
$theme = $assoc_args['theme'];

0 commit comments

Comments
 (0)