Skip to content

Commit 5cafad9

Browse files
Copilotswissspidy
andcommitted
Fix wp site list path filter conflict by adding --site-path parameter
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent e94f60d commit 5cafad9

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

features/site.feature

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ Feature: Manage sites in a multisite installation
9898
{SCHEME}://example.com/first/
9999
"""
100100

101+
When I run `wp site list --field=url --site-path=/first/`
102+
Then STDOUT should be:
103+
"""
104+
{SCHEME}://example.com/first/
105+
"""
106+
101107
Scenario: Filter site list by user
102108
Given a WP multisite install
103109

src/Site_Command.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -961,14 +961,19 @@ private function get_network( $network_id ) {
961961
*
962962
* [--<field>=<value>]
963963
* : Filter by one or more fields (see "Available Fields" section). However,
964-
* 'url' isn't an available filter, as it comes from 'home' in wp_options.
964+
* 'url' isn't an available filter, as it comes from 'home' in wp_options,
965+
* and 'path' isn't an available filter, as it conflicts with the global
966+
* `--path` parameter. Use `--site-path` to filter by path instead.
965967
*
966968
* [--site__in=<value>]
967969
* : Only list the sites with these blog_id values (comma-separated).
968970
*
969971
* [--site_user=<value>]
970972
* : Only list the sites with this user.
971973
*
974+
* [--site-path=<path>]
975+
* : Filter by path. Avoids conflict with the global `--path` parameter.
976+
*
972977
* [--field=<field>]
973978
* : Prints the value of a single field for each site.
974979
*
@@ -1038,13 +1043,17 @@ public function list_( $args, $assoc_args ) {
10381043
$where = [];
10391044
$append = '';
10401045

1041-
$site_cols = [ 'blog_id', 'last_updated', 'registered', 'site_id', 'domain', 'path', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id' ];
1046+
$site_cols = [ 'blog_id', 'last_updated', 'registered', 'site_id', 'domain', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id' ];
10421047
foreach ( $site_cols as $col ) {
10431048
if ( isset( $assoc_args[ $col ] ) ) {
10441049
$where[ $col ] = $assoc_args[ $col ];
10451050
}
10461051
}
10471052

1053+
if ( isset( $assoc_args['site-path'] ) ) {
1054+
$where['path'] = $assoc_args['site-path'];
1055+
}
1056+
10481057
if ( isset( $assoc_args['site__in'] ) ) {
10491058
$where['blog_id'] = explode( ',', $assoc_args['site__in'] );
10501059
$append = 'ORDER BY FIELD( blog_id, ' . implode( ',', array_map( 'intval', $where['blog_id'] ) ) . ' )';

0 commit comments

Comments
 (0)