Skip to content

Commit a3e2649

Browse files
Merge pull request #16 from Nikschavan/exclude-updates
Add --exclude=<name> argument to exclude plugins or themes from updating
2 parents 26d045f + 64bdcae commit a3e2649

5 files changed

Lines changed: 123 additions & 0 deletions

File tree

features/plugin-update.feature

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,33 @@ Feature: Update WordPress plugins
4343
Error: --minor and --patch cannot be used together.
4444
"""
4545

46+
Scenario: Exclude plugin updates from bulk updates.
47+
Given a WP install
48+
49+
When I run `wp plugin install akismet --version=3.0.0 --force`
50+
Then STDOUT should contain:
51+
""""
52+
Downloading install package from https://downloads.wordpress.org/plugin/akismet.3.0.0.zip...
53+
""""
54+
55+
When I run `wp plugin status akismet`
56+
Then STDOUT should contain:
57+
""""
58+
Update available
59+
""""
60+
61+
When I run `wp plugin update --all --exclude=akismet | grep 'Skipped'`
62+
Then STDOUT should contain:
63+
"""
64+
akismet
65+
"""
66+
67+
When I run `wp plugin status akismet`
68+
Then STDOUT should contain:
69+
""""
70+
Update available
71+
""""
72+
4673
Scenario: Update a plugin to its latest patch release
4774
Given a WP install
4875
And I run `wp plugin install --force akismet --version=2.5.4`

features/theme.feature

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,33 @@ Feature: Manage WordPress themes
108108
Success: Updated 1 of 1 themes.
109109
"""
110110

111+
Scenario: Exclude theme from bulk updates.
112+
Given a WP install
113+
114+
When I run `wp theme install p2 --version=1.4.1 --force`
115+
Then STDOUT should contain:
116+
""""
117+
Downloading install package from https://downloads.wordpress.org/theme/p2.1.4.1.zip...
118+
""""
119+
120+
When I run `wp theme status p2`
121+
Then STDOUT should contain:
122+
""""
123+
Update available
124+
""""
125+
126+
When I run `wp theme update --all --exclude=p2 | grep 'Skipped'`
127+
Then STDOUT should contain:
128+
"""
129+
p2
130+
"""
131+
132+
When I run `wp theme status p2`
133+
Then STDOUT should contain:
134+
""""
135+
Update available
136+
""""
137+
111138
Scenario: Get the path of an installed theme
112139
Given a WP install
113140

src/Plugin_Command.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,9 @@ protected function install_from_repo( $slug, $assoc_args ) {
498498
*
499499
* [--all]
500500
* : If set, all plugins that have updates will be updated.
501+
*
502+
* [--exclude=<name>]
503+
* : Comma separated list of plugin names that should be excluded from updating.
501504
*
502505
* [--minor]
503506
* : Only perform updates for minor releases (e.g. from 1.3 to 1.4 instead of 2.0)
@@ -545,6 +548,20 @@ protected function install_from_repo( $slug, $assoc_args ) {
545548
* | nginx-cache-controller | 3.1.1 | 3.2.0 | Updated |
546549
* +------------------------+-------------+-------------+---------+
547550
* Success: Updated 2 of 2 plugins.
551+
*
552+
* $ wp plugin update --all --exclude=akismet
553+
* Enabling Maintenance mode...
554+
* Downloading update from https://downloads.wordpress.org/plugin/nginx-champuru.3.2.0.zip...
555+
* Unpacking the update...
556+
* Installing the latest version...
557+
* Removing the old version of the plugin...
558+
* Plugin updated successfully.
559+
* Disabling Maintenance mode...
560+
* +------------------------+-------------+-------------+---------+
561+
* | name | old_version | new_version | status |
562+
* +------------------------+-------------+-------------+---------+
563+
* | nginx-cache-controller | 3.1.1 | 3.2.0 | Updated |
564+
* +------------------------+-------------+-------------+---------+
548565
*
549566
* @alias upgrade
550567
*/

src/Theme_Command.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,9 @@ public function get( $args, $assoc_args ) {
589589
*
590590
* [--all]
591591
* : If set, all themes that have updates will be updated.
592+
*
593+
* [--exclude=<theme-names>]
594+
* : Comma separated list of theme names that should be excluded from updating.
592595
*
593596
* [--format=<format>]
594597
* : Output summary as table or summary. Defaults to table.
@@ -620,6 +623,26 @@ public function get( $args, $assoc_args ) {
620623
* | twentysixteen | 1.1 | 1.2 | Updated |
621624
* +---------------+-------------+-------------+---------+
622625
* Success: Updated 2 of 2 themes.
626+
*
627+
* # Exclude themes updates when bulk updating the themes
628+
* $ wp theme update --all --exclude=twentyfifteen
629+
* Downloading update from https://downloads.wordpress.org/theme/astra.1.0.5.1.zip...
630+
* Unpacking the update...
631+
* Installing the latest version...
632+
* Removing the old version of the theme...
633+
* Theme updated successfully.
634+
* Downloading update from https://downloads.wordpress.org/theme/twentyseventeen.1.2.zip...
635+
* Unpacking the update...
636+
* Installing the latest version...
637+
* Removing the old version of the theme...
638+
* Theme updated successfully.
639+
* +-----------------+----------+---------+----------------+
640+
* | name | status | version | update_version |
641+
* +-----------------+----------+---------+----------------+
642+
* | astra | inactive | 1.0.1 | 1.0.5.1 |
643+
* | twentyseventeen | inactive | 1.1 | 1.2 |
644+
* +-----------------+----------+---------+----------------+
645+
* Success: Updated 2 of 2 themes.
623646
*
624647
* # Update all themes
625648
* $ wp theme update --all

src/WP_CLI/CommandWithUpgrade.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public function __construct() {
2121
add_action( 'upgrader_process_complete', function() {
2222
remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 );
2323
}, 1 );
24+
25+
$this->fetcher = new \WP_CLI\Fetchers\Plugin;
2426
}
2527

2628
abstract protected function get_upgrader_class( $force );
@@ -301,9 +303,29 @@ protected function update_many( $args, $assoc_args ) {
301303
$items_to_update = self::get_minor_or_patch_updates( $items_to_update, $type );
302304
}
303305

306+
$exclude = WP_CLI\Utils\get_flag_value( $assoc_args, 'exclude' );
307+
if ( isset( $exclude ) ) {
308+
$exclude_items = explode( ',', trim( $assoc_args['exclude'], ',' ) );
309+
unset( $assoc_args['exclude'] );
310+
foreach ( $exclude_items as $item ) {
311+
if ( 'plugin' === $this->item_type ) {
312+
$plugin = $this->fetcher->get( $item );
313+
unset( $items_to_update[ $plugin->file ] );
314+
} elseif ( 'theme' === $this->item_type ) {
315+
$theme_root = get_theme_root() . '/' . $item;
316+
unset( $items_to_update[ $theme_root ] );
317+
}
318+
}
319+
}
320+
304321
if ( \WP_CLI\Utils\get_flag_value( $assoc_args, 'dry-run' ) ) {
305322
if ( empty( $items_to_update ) ) {
306323
\WP_CLI::log( "No {$this->item_type} updates available." );
324+
325+
if ( NULL !== $exclude ) {
326+
\WP_CLI::log( "Skipped updates for: $exclude" );
327+
}
328+
307329
return;
308330
}
309331

@@ -319,6 +341,10 @@ protected function update_many( $args, $assoc_args ) {
319341
\WP_CLI\Utils\format_items( 'table', $items_to_update, array( 'name', 'status', 'version', 'update_version' ) );
320342
}
321343

344+
if ( NULL !== $exclude ) {
345+
\WP_CLI::log( "Skipped updates for: $exclude" );
346+
}
347+
322348
return;
323349
}
324350

@@ -378,6 +404,9 @@ protected function update_many( $args, $assoc_args ) {
378404

379405
$total_updated = Utils\get_flag_value( $assoc_args, 'all' ) ? $num_to_update : count( $args );
380406
Utils\report_batch_operation_results( $this->item_type, 'update', $total_updated, $num_updated, $errors );
407+
if ( NULL !== $exclude ) {
408+
\WP_CLI::log( "Skipped updates for: $exclude" );
409+
}
381410
}
382411

383412
protected function _list( $_, $assoc_args ) {

0 commit comments

Comments
 (0)