Skip to content

Commit

Permalink
Fix --skip-themes for WordPress 6.4 (wp-cli#5840)
Browse files Browse the repository at this point in the history
WordPress 6.4 added some memoization that impacts
`get_template_directory()` and `get_stylesheet_directory()`.
Fortunately, we only need to noop the global to fix `--skip-themes`.
  • Loading branch information
danielbachhuber authored Sep 29, 2023
1 parent 8114cb4 commit 70c20e7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions features/requests.feature
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Feature: Requests integration with both v1 and v2

Given a WP installation
And I run `vendor/bin/wp core update --version=5.8 --force`
And I run `rm -r wp-content/themes/*`

When I run `vendor/bin/wp core version`
Then STDOUT should contain:
Expand All @@ -46,6 +47,7 @@ Feature: Requests integration with both v1 and v2
Scenario: Current version with WordPress-bundled Requests v1
Given a WP installation
And I run `wp core update --version=5.8 --force`
And I run `rm -r wp-content/themes/*`

When I run `wp core version`
Then STDOUT should contain:
Expand Down
11 changes: 11 additions & 0 deletions php/WP_CLI/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -1793,6 +1793,12 @@ public function action_setup_theme_wp_cli_skip_themes() {
add_filter( $hook, $wp_cli_filter_active_theme, 999 );
}

// Noop memoization added in WP 6.4.
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- WordPress core global.
$GLOBALS['wp_stylesheet_path'] = null;
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- WordPress core global.
$GLOBALS['wp_template_path'] = null;

// Remove theme-related actions not directly tied into the theme lifecycle.
if ( WP_CLI::get_runner()->config['skip-themes'] ) {
$theme_related_actions = [
Expand All @@ -1812,6 +1818,11 @@ static function () use ( $hooks, $wp_cli_filter_active_theme ) {
foreach ( $hooks as $hook ) {
remove_filter( $hook, $wp_cli_filter_active_theme, 999 );
}
// Noop memoization added in WP 6.4 again.
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- WordPress core global.
$GLOBALS['wp_stylesheet_path'] = null;
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- WordPress core global.
$GLOBALS['wp_template_path'] = null;
},
0
);
Expand Down

0 comments on commit 70c20e7

Please sign in to comment.