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
105 changes: 105 additions & 0 deletions features/site.feature
Original file line number Diff line number Diff line change
Expand Up @@ -936,3 +936,108 @@ Feature: Manage sites in a multisite installation
"""
1
"""

Scenario: Filter the site list by columns of the sites table
Given a WP multisite install

When I run `wp site create --slug=first --porcelain`
Then STDOUT should be a number
And save STDOUT as {FIRST_ID}

When I run `wp site create --slug=second --porcelain`
Then STDOUT should be a number
And save STDOUT as {SECOND_ID}

# Give the two new sites contrasting statuses, so each filter below has
# something to discriminate on and cannot pass by matching every site.
When I run `wp site archive {FIRST_ID}`
Then STDOUT should contain:
"""
Success:
"""

When I run `wp site private {SECOND_ID}`
Then STDOUT should contain:
"""
Success:
"""

When I run `wp site spam {SECOND_ID}`
Then STDOUT should contain:
"""
Success:
"""

When I run `wp site list --format=count`
Then STDOUT should be:
"""
3
"""

When I run `wp site list --archived=1 --field=blog_id`
Then STDOUT should be:
"""
{FIRST_ID}
"""

When I run `wp site list --archived=0 --format=count`
Then STDOUT should be:
"""
2
"""

When I run `wp site list --public=0 --field=blog_id`
Then STDOUT should be:
"""
{SECOND_ID}
"""

When I run `wp site list --public=1 --format=count`
Then STDOUT should be:
"""
2
"""

When I run `wp site list --spam=1 --field=blog_id`
Then STDOUT should be:
"""
{SECOND_ID}
"""

When I run `wp site list --spam=0 --format=count`
Then STDOUT should be:
"""
2
"""

When I run `wp site list --deleted=0 --format=count`
Then STDOUT should be:
"""
3
"""

When I run `wp site list --blog_id={FIRST_ID} --field=blog_id`
Then STDOUT should be:
"""
{FIRST_ID}
"""

# site_id is the ID of the network the site belongs to, not the site's own ID.
When I run `wp site list --site_id=1 --format=count`
Then STDOUT should be:
"""
3
"""

When I run `wp site list --site_id=2 --format=count`
Then STDOUT should be:
"""
0
"""

# --network is an alias for site_id and takes precedence over it.
When I run `wp site list --site_id=2 --network=1 --format=count`
Then STDOUT should be:
"""
3
"""
Comment thread
coderabbitai[bot] marked this conversation as resolved.
90 changes: 90 additions & 0 deletions features/user-application-password.feature
Original file line number Diff line number Diff line change
Expand Up @@ -315,3 +315,93 @@ Feature: Manage user custom fields
"""
true
"""

@require-wp-5.6
Scenario: Filter application passwords by field
Given a WP install
Comment thread
coderabbitai[bot] marked this conversation as resolved.

When I run `wp user application-password create 1 myapp --app-id=abc123 --porcelain`
Then STDOUT should not be empty

When I run `wp user application-password create 1 otherapp --porcelain`
Then STDOUT should not be empty

When I run `wp user application-password list 1 --format=count`
Then STDOUT should be:
"""
2
"""

When I run `wp user application-password list 1 --app_id=abc123 --field=name`
Then STDOUT should be:
"""
myapp
"""

When I run `wp user application-password list 1 --app-id=abc123 --field=name`
Then STDOUT should be:
"""
myapp
"""

When I run `wp user application-password list 1 --name=otherapp --field=name`
Then STDOUT should be:
"""
otherapp
"""

When I run `wp user application-password list 1 --name=myapp --field=uuid`
Then STDOUT should not be empty
And save STDOUT as {UUID}

When I run `wp user application-password list 1 --uuid={UUID} --field=name`
Then STDOUT should be:
"""
myapp
"""

When I run `wp user application-password list 1 --app_id=nosuchapp --format=count`
Then STDOUT should be:
"""
0
"""

# 'created' and 'last_used' are integers in core but strings on the command
# line, so these only match if the comparison normalizes them.
When I run `wp user application-password list 1 --name=myapp --field=created`
Then STDOUT should not be empty
And save STDOUT as {CREATED}

When I run `wp user application-password list 1 --created={CREATED} --field=name`
Then STDOUT should contain:
"""
myapp
"""

When I run `wp user application-password list 1 --created=1 --format=count`
Then STDOUT should be:
"""
0
"""

When I run `wp user application-password record-usage 1 {UUID}`
Then STDOUT should contain:
"""
Success:
"""

When I run `wp user application-password list 1 --name=myapp --field=last_used`
Then STDOUT should not be empty
And save STDOUT as {LAST_USED}

When I run `wp user application-password list 1 --last_used={LAST_USED} --field=name`
Then STDOUT should be:
"""
myapp
"""

When I run `wp user application-password list 1 --last-used={LAST_USED} --field=name`
Then STDOUT should be:
"""
myapp
"""
34 changes: 34 additions & 0 deletions src/Site_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,40 @@ private function get_network( $network_id ) {
* [--site-path=<path>]
* : Filter by path. Avoids conflict with the global `--path` parameter.
*
* [--blog_id=<blog_id>]
* : Filter by site ID.
*
* [--site_id=<site_id>]
* : Filter by the ID of the network the site belongs to. `--network` is an
* alias for this, and takes precedence when both are given.
*
* [--domain=<domain>]
* : Filter by domain.
*
* [--registered=<yyyy-mm-dd-hh-ii-ss>]
* : Filter by the date the site was registered.
*
* [--last_updated=<yyyy-mm-dd-hh-ii-ss>]
* : Filter by the date the site was last updated.
*
* [--public=<public>]
* : Filter by whether the site is public. Accepts 1 or 0.
*
* [--archived=<archived>]
* : Filter by whether the site is archived. Accepts 1 or 0.
*
* [--mature=<mature>]
* : Filter by whether the site is flagged as mature. Accepts 1 or 0.
*
* [--spam=<spam>]
* : Filter by whether the site is flagged as spam. Accepts 1 or 0.
*
* [--deleted=<deleted>]
* : Filter by whether the site is flagged as deleted. Accepts 1 or 0.
*
* [--lang_id=<lang_id>]
* : Filter by language ID.
*
* [--field=<field>]
* : Prints the value of a single field for each site.
*
Expand Down
35 changes: 33 additions & 2 deletions src/User_Application_Password_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,29 @@ final class User_Application_Password_Command {
* [--<field>=<value>]
* : Filter the list by a specific field.
*
* [--uuid=<uuid>]
* : Filter by the universally unique ID of the application password.
*
* [--app_id=<app_id>]
* : Filter by the application ID. `--app-id` is also accepted.
*
* [--name=<name>]
* : Filter by the name of the application password.
*
* [--password=<password>]
* : Filter by the hashed password.
*
* [--created=<created>]
* : Filter by the Unix timestamp the application password was created at.
*
* [--last_used=<last_used>]
* : Filter by the Unix timestamp the application password was last used at.
* `--last-used` is also accepted.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
*
* [--last_ip=<last_ip>]
* : Filter by the IP address the application password was last used from.
* `--last-ip` is also accepted.
*
* [--field=<field>]
* : Prints the value of a single field for each application password.
*
Expand Down Expand Up @@ -186,10 +209,18 @@ static function ( $a, $b ) use ( $orderby, $order ) {

$value = Utils\get_flag_value( $assoc_args, $field );

// 'created' and 'last_used' come back from core as integers, while an
// argument always arrives as a string, so compare them as strings.
$filter_value = is_scalar( $value ) ? (string) $value : '';

$application_passwords = array_filter(
$application_passwords,
static function ( $application_password ) use ( $field, $value ) {
return $application_password[ $field ] === $value;
static function ( $application_password ) use ( $field, $filter_value ) {
$item_value = isset( $application_password[ $field ] ) && is_scalar( $application_password[ $field ] )
? (string) $application_password[ $field ]
: '';

return $item_value === $filter_value;
}
);
}
Expand Down