diff --git a/extension-command.php b/extension-command.php index 18b87efd..3cc65c80 100644 --- a/extension-command.php +++ b/extension-command.php @@ -22,3 +22,33 @@ WP_CLI::add_command( 'theme', 'Theme_Command' ); WP_CLI::add_command( 'theme auto-updates', 'Theme_AutoUpdates_Command', $wpcli_extension_requires_wp_5_5 ); WP_CLI::add_command( 'theme mod', 'Theme_Mod_Command' ); + +// In admin context, WordPress hooks wp_update_plugins/wp_update_themes to +// various actions, causing update checks to run even when --skip-update-check is passed. + +WP_CLI::add_hook( + 'before_wp_load', + static function () { + if ( ! \WP_CLI\Utils\get_flag_value( WP_CLI::get_runner()->assoc_args, 'skip-update-check' ) ) { + return; + } + + WP_CLI::add_wp_hook( + 'wp_loaded', + static function () { + remove_action( 'load-plugins.php', 'wp_update_plugins' ); + remove_action( 'load-update.php', 'wp_update_plugins' ); + remove_action( 'load-update-core.php', 'wp_update_plugins' ); + remove_action( 'admin_init', '_maybe_update_plugins' ); + remove_action( 'wp_update_plugins', 'wp_update_plugins' ); + + remove_action( 'load-themes.php', 'wp_update_themes' ); + remove_action( 'load-update.php', 'wp_update_themes' ); + remove_action( 'load-update-core.php', 'wp_update_themes' ); + remove_action( 'admin_init', '_maybe_update_themes' ); + remove_action( 'wp_update_themes', 'wp_update_themes' ); + }, + PHP_INT_MIN + ); + } +); diff --git a/features/plugin-auto-updates-disable.feature b/features/plugin-auto-updates-disable.feature index af988a46..57eb1c5b 100644 --- a/features/plugin-auto-updates-disable.feature +++ b/features/plugin-auto-updates-disable.feature @@ -2,7 +2,7 @@ Feature: Disable auto-updates for WordPress plugins Background: Given a WP install - And I run `wp plugin install duplicate-post https://github.com/wp-cli/sample-plugin/archive/refs/heads/master.zip --ignore-requirements` + And I run `wp plugin install debug-bar https://github.com/wp-cli/sample-plugin/archive/refs/heads/master.zip --ignore-requirements` And I run `wp plugin auto-updates enable --all` @require-wp-5.5 @@ -25,7 +25,7 @@ Feature: Disable auto-updates for WordPress plugins @require-wp-5.5 Scenario: Disable auto-updates for multiple plugins - When I run `wp plugin auto-updates disable sample-plugin duplicate-post` + When I run `wp plugin auto-updates disable sample-plugin debug-bar` Then STDOUT should be: """ Success: Disabled 2 of 2 plugin auto-updates. @@ -73,7 +73,7 @@ Feature: Disable auto-updates for WordPress plugins @require-wp-5.5 Scenario: Filter when disabling auto-updates for already disabled selection of plugins When I run `wp plugin auto-updates disable sample-plugin` - And I run `wp plugin auto-updates disable sample-plugin duplicate-post --enabled-only` + And I run `wp plugin auto-updates disable sample-plugin debug-bar --enabled-only` Then STDOUT should be: """ Success: Disabled 1 of 1 plugin auto-updates. diff --git a/features/plugin-auto-updates-enable.feature b/features/plugin-auto-updates-enable.feature index 73de4ba5..19b6384a 100644 --- a/features/plugin-auto-updates-enable.feature +++ b/features/plugin-auto-updates-enable.feature @@ -2,7 +2,7 @@ Feature: Enable auto-updates for WordPress plugins Background: Given a WP install - And I run `wp plugin install duplicate-post https://github.com/wp-cli/sample-plugin/archive/refs/heads/master.zip --ignore-requirements` + And I run `wp plugin install debug-bar https://github.com/wp-cli/sample-plugin/archive/refs/heads/master.zip --ignore-requirements` @require-wp-5.5 Scenario: Show an error if required params are missing @@ -24,7 +24,7 @@ Feature: Enable auto-updates for WordPress plugins @require-wp-5.5 Scenario: Enable auto-updates for multiple plugins - When I run `wp plugin auto-updates enable sample-plugin duplicate-post` + When I run `wp plugin auto-updates enable sample-plugin debug-bar` Then STDOUT should be: """ Success: Enabled 2 of 2 plugin auto-updates. @@ -72,7 +72,7 @@ Feature: Enable auto-updates for WordPress plugins @require-wp-5.5 Scenario: Filter when enabling auto-updates for already enabled selection of plugins When I run `wp plugin auto-updates enable sample-plugin` - And I run `wp plugin auto-updates enable sample-plugin duplicate-post --disabled-only` + And I run `wp plugin auto-updates enable sample-plugin debug-bar --disabled-only` Then STDOUT should be: """ Success: Enabled 1 of 1 plugin auto-updates. diff --git a/features/plugin-auto-updates-status.feature b/features/plugin-auto-updates-status.feature index d4a7c424..4bda9736 100644 --- a/features/plugin-auto-updates-status.feature +++ b/features/plugin-auto-updates-status.feature @@ -2,7 +2,7 @@ Feature: Show the status of auto-updates for WordPress plugins Background: Given a WP install - And I run `wp plugin install duplicate-post https://github.com/wp-cli/sample-plugin/archive/refs/heads/master.zip --ignore-requirements` + And I run `wp plugin install debug-bar https://github.com/wp-cli/sample-plugin/archive/refs/heads/master.zip --ignore-requirements` @require-wp-5.5 Scenario: Show an error if required params are missing @@ -23,10 +23,10 @@ Feature: Show the status of auto-updates for WordPress plugins @require-wp-5.5 Scenario: Show the status of auto-updates multiple plugins - When I run `wp plugin auto-updates status duplicate-post sample-plugin` + When I run `wp plugin auto-updates status debug-bar sample-plugin` Then STDOUT should be a table containing rows: | name | status | - | duplicate-post | disabled | + | debug-bar | disabled | | sample-plugin | disabled | And the return code should be 0 @@ -36,7 +36,7 @@ Feature: Show the status of auto-updates for WordPress plugins Then STDOUT should be a table containing rows: | name | status | | akismet | disabled | - | duplicate-post | disabled | + | debug-bar | disabled | | sample-plugin | disabled | And the return code should be 0 @@ -45,7 +45,7 @@ Feature: Show the status of auto-updates for WordPress plugins Then STDOUT should be a table containing rows: | name | status | | akismet | enabled | - | duplicate-post | enabled | + | debug-bar | enabled | | sample-plugin | enabled | And the return code should be 0 @@ -57,7 +57,7 @@ Feature: Show the status of auto-updates for WordPress plugins Then STDOUT should be a table containing rows: | name | status | | akismet | disabled | - | duplicate-post | disabled | + | debug-bar | disabled | | sample-plugin | enabled | And the return code should be 0 @@ -71,7 +71,7 @@ Feature: Show the status of auto-updates for WordPress plugins Then STDOUT should be a table containing rows: | name | status | | akismet | disabled | - | duplicate-post | disabled | + | debug-bar | disabled | And the return code should be 0 When I try `wp plugin auto-updates status --all --enabled-only --disabled-only` @@ -92,7 +92,7 @@ Feature: Show the status of auto-updates for WordPress plugins """ And STDOUT should contain: """ - duplicate-post + debug-bar """ When I run `wp plugin auto-updates status sample-plugin --field=status` @@ -114,7 +114,7 @@ Feature: Show the status of auto-updates for WordPress plugins """ And STDOUT should contain: """ - {"name":"duplicate-post","status":"disabled"} + {"name":"debug-bar","status":"disabled"} """ When I run `wp plugin auto-updates status --all --format=csv` @@ -128,7 +128,7 @@ Feature: Show the status of auto-updates for WordPress plugins """ And STDOUT should contain: """ - duplicate-post,disabled + debug-bar,disabled """ @require-wp-5.5 diff --git a/features/plugin-dependencies.feature b/features/plugin-dependencies.feature index 96c0f41b..0faae774 100644 --- a/features/plugin-dependencies.feature +++ b/features/plugin-dependencies.feature @@ -61,7 +61,7 @@ Feature: Plugin dependencies support get_error_message() ); - if ( 'already_installed' !== $result->get_error_code() ) { + if ( 'already_installed' === $result->get_error_code() ) { + if ( $result->get_error_data( 'slug' ) ) { + $slug = $result->get_error_data( 'slug' ); + } + } else { ++$errors; } } @@ -338,6 +342,11 @@ public function install( $args, $assoc_args ) { } } + // Only plugins cache really exists. + if ( 'plugin' === $this->item_type ) { + wp_cache_delete( 'plugins', 'plugins' ); + } + // Check extension is available or not. $extension = $this->fetcher->get_many( array( $slug ) ); @@ -411,7 +420,10 @@ protected function install_from_php_file( $url, $assoc_args ) { // Check if plugin is already installed before downloading. if ( file_exists( $dest_path ) && ! Utils\get_flag_value( $assoc_args, 'force' ) ) { - return new WP_Error( 'already_installed', 'Plugin already installed.' ); + $error = new WP_Error( 'already_installed', 'Plugin already installed.' ); + // An easy way to provide the slug of the installed plugin. + $error->add_data( $dest_filename, 'slug' ); + return $error; } // Ensure plugin directory exists.