Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions features/plugin.feature
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,30 @@ Feature: Manage WordPress plugins
| akismet | active | akismet/akismet.php |
| wordpress-importer | inactive | wordpress-importer/wordpress-importer.php |

When I run `wp plugin list --status=active --status=inactive --fields=name,status,file`
Then STDOUT should be a table containing rows:
| name | status | file |
| akismet | active | akismet/akismet.php |
| wordpress-importer | inactive | wordpress-importer/wordpress-importer.php |

Scenario: Filter plugin list by multiple names
Given a WP install

When I run `wp plugin install wordpress-importer --ignore-requirements`
Then STDOUT should not be empty

When I run `wp plugin list --name=akismet,wordpress-importer --fields=name,status`
Then STDOUT should be a table containing rows:
| name | status |
| akismet | inactive |
| wordpress-importer | inactive |

When I run `wp plugin list --name=akismet --name=wordpress-importer --fields=name,status`
Then STDOUT should be a table containing rows:
| name | status |
| akismet | inactive |
| wordpress-importer | inactive |

@require-wp-5.2
Scenario: Flag `--skip-update-check` skips update check when running `wp plugin list`
Given a WP install
Expand Down
30 changes: 30 additions & 0 deletions features/theme.feature
Original file line number Diff line number Diff line change
Expand Up @@ -807,3 +807,33 @@ Feature: Manage WordPress themes
"""
classic
"""

Scenario: Filter theme list by multiple names
Given a WP install
And I run `wp theme delete --all --force`
And I run `wp theme install twentyeleven --activate`
And I run `wp theme install twentytwelve`

When I run `wp theme list --name=twentytwelve,twentyeleven --fields=name,status`
Then STDOUT should be a table containing rows:
| name | status |
| twentyeleven | active |
| twentytwelve | inactive |

When I run `wp theme list --name=twentytwelve --name=twentyeleven --fields=name,status`
Then STDOUT should be a table containing rows:
| name | status |
| twentyeleven | active |
| twentytwelve | inactive |

When I run `wp theme list --status=active,inactive --fields=name,status`
Then STDOUT should be a table containing rows:
| name | status |
| twentyeleven | active |
| twentytwelve | inactive |

When I run `wp theme list --status=active --status=inactive --fields=name,status`
Then STDOUT should be a table containing rows:
| name | status |
| twentyeleven | active |
| twentytwelve | inactive |
2 changes: 1 addition & 1 deletion src/Plugin_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -1872,7 +1872,7 @@ public function delete( $args, $assoc_args ) {
* - yaml
* ---
*
* [--status=<status>]
* [--status=<status>...]
* : Filter the output by plugin status.
* ---
* options:
Expand Down
2 changes: 1 addition & 1 deletion src/Theme_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ public function delete( $args, $assoc_args ) {
* - yaml
* ---
*
* [--status=<status>]
* [--status=<status>...]
* : Filter the output by theme status.
* ---
* options:
Expand Down
12 changes: 9 additions & 3 deletions src/WP_CLI/CommandWithUpgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -926,10 +926,16 @@ function ( $value ) {
continue;
}

// This can be either a value to filter by or a comma-separated list of values.
// Also, it is not forbidden for a value to contain a comma (in which case we can filter only by one).
$field_filter = $assoc_args[ $field ];
if (
if ( is_array( $field_filter ) ) {
// Multiple values passed by repeating the argument (e.g., --name=plugin1 --name=plugin2).
/** @var string[] $field_filter */
if ( ! in_array( $item[ $field ], $field_filter, true ) ) {
unset( $all_items[ $key ] );
}
} elseif (
// This can be either a value to filter by or a comma-separated list of values.
// Also, it is not forbidden for a value to contain a comma (in which case we can filter only by one).
$item[ $field ] !== $field_filter
&& ! in_array( $item[ $field ], array_map( 'trim', explode( ',', $field_filter ) ), true )
) {
Expand Down