Skip to content

Commit 2b58da7

Browse files
Copilotswissspidy
andcommitted
Validate plugin/theme names using filter_item_list
Use filter_item_list() to validate plugin and theme names before checking for updates. This ensures that invalid names produce errors instead of silent success messages, consistent with other commands like update and auto-updates. Also added test scenarios to verify error handling for invalid plugin/theme names. Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 6a204af commit 2b58da7

File tree

4 files changed

+32
-12
lines changed

4 files changed

+32
-12
lines changed

features/plugin-check-update.feature

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,13 @@ Feature: Check for plugin updates
9090
Then STDOUT should be a table containing rows:
9191
| name | version |
9292
| wordpress-importer | 0.5 |
93+
94+
Scenario: Check for invalid plugin should error
95+
Given a WP install
96+
97+
When I try `wp plugin check-update invalid-plugin-name`
98+
Then the return code should be 1
99+
And STDERR should contain:
100+
"""
101+
Error:
102+
"""

features/theme-check-update.feature

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,13 @@ Feature: Check for theme updates
8888
Then STDOUT should be a table containing rows:
8989
| name | version |
9090
| twentyfourteen | 1.0 |
91+
92+
Scenario: Check for invalid theme should error
93+
Given a WP install
94+
95+
When I try `wp theme check-update invalid-theme-name`
96+
Then the return code should be 1
97+
And STDERR should contain:
98+
"""
99+
Error:
100+
"""

src/Plugin_Command.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ public function check_update( $args, $assoc_args ) {
174174

175175
$items = $this->get_item_list();
176176

177+
// If specific plugins requested, validate and filter to those
178+
if ( ! $all ) {
179+
$items = $this->filter_item_list( $items, $args );
180+
}
181+
177182
// Filter to only plugins with available updates
178183
$items_with_updates = array_filter(
179184
$items,
@@ -182,16 +187,6 @@ function ( $item ) {
182187
}
183188
);
184189

185-
// If specific plugins requested, filter to those
186-
if ( ! empty( $args ) ) {
187-
$items_with_updates = array_filter(
188-
$items_with_updates,
189-
function ( $item ) use ( $args ) {
190-
return in_array( $item['name'], $args, true );
191-
}
192-
);
193-
}
194-
195190
if ( empty( $items_with_updates ) ) {
196191
WP_CLI::success( 'All plugins are up to date.' );
197192
return;

src/Theme_Command.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,16 @@ public function check_update( $args, $assoc_args ) {
168168

169169
$items = $this->get_item_list();
170170

171+
// If specific themes requested, validate and filter to those
172+
if ( ! $all ) {
173+
$items = $this->filter_item_list( $items, $args );
174+
}
175+
171176
// Filter to only themes with available updates
172177
$items_with_updates = array_filter(
173178
$items,
174-
function ( $item ) use ( $args ) {
175-
return in_array( $item['name'], $args, true ) && 'available' === $item['update'];
179+
function ( $item ) {
180+
return 'available' === $item['update'];
176181
}
177182
);
178183

0 commit comments

Comments
 (0)