Skip to content

Commit 784c78e

Browse files
swissspidyclaude
andauthored
Document every argument wp site list accepts (#642)
Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: Claude <noreply@anthropic.com>
1 parent eaabf13 commit 784c78e

3 files changed

Lines changed: 434 additions & 23 deletions

File tree

‎README.md‎

Lines changed: 95 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5443,41 +5443,60 @@ These fields are optionally available:
54435443
Lists all sites in a multisite installation.
54445444

54455445
~~~
5446-
wp site list [--network=<id>] [--<field>=<value>] [--site__in=<value>] [--site_user=<value>] [--site-path=<path>] [--blog_id=<blog_id>] [--site_id=<site_id>] [--domain=<domain>] [--registered=<date>] [--last_updated=<date>] [--public=<public>] [--archived=<archived>] [--mature=<mature>] [--spam=<spam>] [--deleted=<deleted>] [--lang_id=<lang_id>] [--field=<field>] [--fields=<fields>] [--format=<format>]
5446+
wp site list [--network=<id>|site_id|network_id] [--<field>=<value>] [--site__in=<value>] [--site__not_in=<value>] [--site_user=<value>] [--site-path=<path>] [--path__in=<value>] [--path__not_in=<value>] [--blog_id=<blog_id>|ID] [--network__in=<value>] [--network__not_in=<value>] [--domain=<domain>] [--domain__in=<value>] [--domain__not_in=<value>] [--registered=<date>] [--last_updated=<date>] [--public=<public>] [--archived=<archived>] [--mature=<mature>] [--spam=<spam>] [--deleted=<deleted>] [--lang_id=<lang_id>] [--lang__in=<value>] [--lang__not_in=<value>] [--search=<string>] [--search_columns=<columns>] [--meta_key=<meta_key>] [--meta_value=<meta_value>] [--meta_compare=<meta_compare>] [--meta_type=<meta_type>] [--meta_query=<meta_query>] [--date_query=<date_query>] [--number=<number>] [--offset=<offset>] [--no_found_rows=<no_found_rows>] [--update_site_cache=<update_site_cache>] [--update_site_meta_cache=<update_site_meta_cache>] [--orderby=<field>] [--order=<order>] [--field=<field>] [--fields=<fields>] [--format=<format>]
54475447
~~~
54485448

54495449
**OPTIONS**
54505450

5451-
[--network=<id>]
5452-
The network to which the sites belong.
5451+
[--network=<id>|site_id|network_id]
5452+
The network to which the sites belong. `--site_id` is the name of the
5453+
column this filters, `--network_id` is WP_Site_Query's name for it, and
5454+
both are accepted as aliases. `--network` wins when more than one is given.
54535455

54545456
[--<field>=<value>]
54555457
Filter by one or more fields (see "Available Fields" section), or pass any
5456-
other argument accepted by WP_Site_Query, such as 'search', 'site__not_in',
5457-
'number', 'offset', 'orderby' or 'order'. However, 'url' isn't an available
5458+
other argument accepted by WP_Site_Query. However, 'url' isn't an available
54585459
filter, as it comes from 'home' in wp_options.
54595460
Note: '--path' conflicts with the global parameter of the same name; use
54605461
'--site-path' to filter by path instead.
54615462

54625463
[--site__in=<value>]
54635464
Only list the sites with these blog_id values (comma-separated).
54645465

5466+
[--site__not_in=<value>]
5467+
Exclude the sites with these blog_id values (comma-separated).
5468+
54655469
[--site_user=<value>]
54665470
Only list the sites with this user.
54675471

54685472
[--site-path=<path>]
54695473
Filter by path. Avoids conflict with the global `--path` parameter.
54705474

5471-
[--blog_id=<blog_id>]
5472-
Filter by site ID.
5475+
[--path__in=<value>]
5476+
Only list the sites with these paths (comma-separated).
5477+
5478+
[--path__not_in=<value>]
5479+
Exclude the sites with these paths (comma-separated).
5480+
5481+
[--blog_id=<blog_id>|ID]
5482+
Filter by site ID. `--ID` is WP_Site_Query's name for the same filter
5483+
and is accepted as an alias.
5484+
5485+
[--network__in=<value>]
5486+
Only list the sites belonging to these network IDs (comma-separated).
54735487

5474-
[--site_id=<site_id>]
5475-
Filter by the ID of the network the site belongs to. `--network` is an
5476-
alias for this, and takes precedence when both are given.
5488+
[--network__not_in=<value>]
5489+
Exclude the sites belonging to these network IDs (comma-separated).
54775490

54785491
[--domain=<domain>]
54795492
Filter by domain.
54805493

5494+
[--domain__in=<value>]
5495+
Only list the sites with these domains (comma-separated).
5496+
5497+
[--domain__not_in=<value>]
5498+
Exclude the sites with these domains (comma-separated).
5499+
54815500
[--registered=<date>]
54825501
Filter by the date the site was registered. Accepts a timestamp or a
54835502
date; a value carrying no time of day matches that whole day.
@@ -5504,6 +5523,72 @@ wp site list [--network=<id>] [--<field>=<value>] [--site__in=<value>] [--site_u
55045523
[--lang_id=<lang_id>]
55055524
Filter by language ID.
55065525

5526+
[--lang__in=<value>]
5527+
Only list the sites with these language IDs (comma-separated).
5528+
5529+
[--lang__not_in=<value>]
5530+
Exclude the sites with these language IDs (comma-separated).
5531+
5532+
[--search=<string>]
5533+
Only list the sites matching this search term. Searches the domain and
5534+
path columns unless `--search_columns` narrows it.
5535+
5536+
[--search_columns=<columns>]
5537+
Comma-separated list of columns `--search` looks in. Accepts 'domain'
5538+
and 'path'.
5539+
5540+
[--meta_key=<meta_key>]
5541+
Filter by this site meta key. The site meta arguments need WordPress 5.1
5542+
or later, which is where multisite gained the table they read.
5543+
5544+
[--meta_value=<meta_value>]
5545+
Filter by this site meta value. Used together with `--meta_key`.
5546+
5547+
[--meta_compare=<meta_compare>]
5548+
Operator to test the meta value against. Accepts the operators
5549+
WP_Meta_Query supports, such as '=', '!=', 'LIKE' or 'IN'.
5550+
5551+
[--meta_type=<meta_type>]
5552+
Cast the meta value to this type, such as 'NUMERIC' or 'DATE'.
5553+
5554+
[--meta_query=<meta_query>]
5555+
A WP_Meta_Query clause list, as JSON, for conditions the meta_* arguments
5556+
above cannot express.
5557+
5558+
[--date_query=<date_query>]
5559+
A WP_Date_Query clause list, as JSON, for ranges `--registered` and
5560+
`--last_updated` cannot express. Giving those as well narrows this further
5561+
rather than replacing it.
5562+
5563+
[--number=<number>]
5564+
Limit the number of sites returned.
5565+
5566+
[--offset=<offset>]
5567+
Number of sites to skip. Used together with `--number`.
5568+
5569+
[--no_found_rows=<no_found_rows>]
5570+
Whether to skip counting the total rows the query matches. Accepts 1 or 0.
5571+
5572+
[--update_site_cache=<update_site_cache>]
5573+
Whether to prime the object cache with the sites found. Accepts 1 or 0.
5574+
Turning it off saves work when listing a large network once.
5575+
5576+
[--update_site_meta_cache=<update_site_meta_cache>]
5577+
Whether to prime the object cache with the site meta of the sites found.
5578+
Accepts 1 or 0.
5579+
5580+
[--orderby=<field>]
5581+
Order the results by this field, such as 'blog_id', 'domain', 'path',
5582+
'registered', 'last_updated' or 'site__in'.
5583+
5584+
[--order=<order>]
5585+
Whether to order the results ascending or descending.
5586+
---
5587+
options:
5588+
- asc
5589+
- desc
5590+
---
5591+
55075592
[--field=<field>]
55085593
Prints the value of a single field for each site.
55095594

‎features/site.feature‎

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,199 @@ Feature: Manage sites in a multisite installation
10871087
1
10881088
"""
10891089

1090+
Scenario: List sites using the WP_Site_Query arguments that take a list
1091+
Given a WP multisite install
1092+
1093+
When I run `wp site create --slug=alpha --porcelain`
1094+
Then STDOUT should be a number
1095+
And save STDOUT as {ALPHA_ID}
1096+
1097+
When I run `wp site create --slug=beta --porcelain`
1098+
Then STDOUT should be a number
1099+
And save STDOUT as {BETA_ID}
1100+
1101+
# WP_Site_Query reads these through is_array(), so before they were split
1102+
# they were skipped without a word and every site came back.
1103+
When I run `wp site list --path__in=/alpha/,/beta/ --field=blog_id`
1104+
Then STDOUT should be:
1105+
"""
1106+
{ALPHA_ID}
1107+
{BETA_ID}
1108+
"""
1109+
1110+
When I run `wp site list --path__not_in=/alpha/,/beta/ --field=blog_id`
1111+
Then STDOUT should be:
1112+
"""
1113+
1
1114+
"""
1115+
1116+
When I run `wp site list --domain__in=example.com --format=count`
1117+
Then STDOUT should be:
1118+
"""
1119+
3
1120+
"""
1121+
1122+
When I run `wp site list --domain__not_in=example.com --format=count`
1123+
Then STDOUT should be:
1124+
"""
1125+
0
1126+
"""
1127+
1128+
# --search_columns reaches array_intersect(), which is fatal on a string.
1129+
When I run `wp site list --search=alpha --search_columns=path --field=blog_id`
1130+
Then STDOUT should be:
1131+
"""
1132+
{ALPHA_ID}
1133+
"""
1134+
1135+
When I run `wp site list --search=alpha --search_columns=domain --format=count`
1136+
Then STDOUT should be:
1137+
"""
1138+
0
1139+
"""
1140+
1141+
# The remaining newly documented filters.
1142+
When I run `wp site list --network__in=1 --format=count`
1143+
Then STDOUT should be:
1144+
"""
1145+
3
1146+
"""
1147+
1148+
When I run `wp site list --network__not_in=1 --format=count`
1149+
Then STDOUT should be:
1150+
"""
1151+
0
1152+
"""
1153+
1154+
When I run `wp site list --lang__in=0 --format=count`
1155+
Then STDOUT should be:
1156+
"""
1157+
3
1158+
"""
1159+
1160+
When I run `wp site list --ID={ALPHA_ID} --field=blog_id`
1161+
Then STDOUT should be:
1162+
"""
1163+
{ALPHA_ID}
1164+
"""
1165+
1166+
When I run `wp site list --network_id=1 --format=count`
1167+
Then STDOUT should be:
1168+
"""
1169+
3
1170+
"""
1171+
1172+
# --date_query is a nested array, so it is given as JSON.
1173+
When I run `wp site list --date_query='[{"column":"registered","after":"1999-01-01"}]' --format=count`
1174+
Then STDOUT should be:
1175+
"""
1176+
3
1177+
"""
1178+
1179+
When I run `wp site list --date_query='[{"column":"registered","before":"1999-01-01"}]' --format=count`
1180+
Then STDOUT should be:
1181+
"""
1182+
0
1183+
"""
1184+
1185+
# --registered narrows a --date_query of its own rather than replacing it. The
1186+
# date on its own has to match first, or the pair below would prove nothing.
1187+
When I run `wp site list --blog_id={ALPHA_ID} --field=registered`
1188+
Then save STDOUT as {ALPHA_REGISTERED}
1189+
1190+
When I run `wp site list --blog_id={ALPHA_ID} --registered='{ALPHA_REGISTERED}' --format=count`
1191+
Then STDOUT should be:
1192+
"""
1193+
1
1194+
"""
1195+
1196+
When I run `wp site list --blog_id={ALPHA_ID} --date_query='[{"column":"registered","before":"1999-01-01"}]' --registered='{ALPHA_REGISTERED}' --format=count`
1197+
Then STDOUT should be:
1198+
"""
1199+
0
1200+
"""
1201+
1202+
# The relation of a given --date_query governs only its own clauses. Appending
1203+
# to the same list would let an 'OR' reach the clause --registered adds and
1204+
# match a site that satisfies neither half of what was asked for.
1205+
When I run `wp site list --blog_id={ALPHA_ID} --date_query='{"relation":"OR","0":{"column":"registered","before":"1999-01-01"},"1":{"column":"registered","before":"1998-01-01"}}' --registered='{ALPHA_REGISTERED}' --format=count`
1206+
Then STDOUT should be:
1207+
"""
1208+
0
1209+
"""
1210+
1211+
When I run `wp site list --blog_id={ALPHA_ID} --field=last_updated`
1212+
Then save STDOUT as {ALPHA_UPDATED}
1213+
1214+
When I run `wp site list --blog_id={ALPHA_ID} --last_updated='{ALPHA_UPDATED}' --format=count`
1215+
Then STDOUT should be:
1216+
"""
1217+
1
1218+
"""
1219+
1220+
When I run `wp site list --blog_id={ALPHA_ID} --date_query='{"relation":"OR","0":{"column":"last_updated","before":"1999-01-01"},"1":{"column":"last_updated","before":"1998-01-01"}}' --last_updated='{ALPHA_UPDATED}' --format=count`
1221+
Then STDOUT should be:
1222+
"""
1223+
0
1224+
"""
1225+
1226+
When I try `wp site list --meta_query=notjson`
1227+
Then STDERR should contain:
1228+
"""
1229+
Invalid JSON passed to --meta_query.
1230+
"""
1231+
And the return code should be 1
1232+
1233+
When I try `wp site list --date_query=notjson`
1234+
Then STDERR should contain:
1235+
"""
1236+
Invalid JSON passed to --date_query.
1237+
"""
1238+
And the return code should be 1
1239+
1240+
# WP_Site_Query gained the meta_* parameters, and multisite gained the site meta
1241+
# table they read, in WordPress 5.1.
1242+
@require-wp-5.1
1243+
Scenario: Filter the site list by site meta
1244+
Given a WP multisite install
1245+
1246+
When I run `wp site create --slug=alpha --porcelain`
1247+
Then STDOUT should be a number
1248+
And save STDOUT as {ALPHA_ID}
1249+
1250+
When I run `wp site create --slug=beta --porcelain`
1251+
Then STDOUT should be a number
1252+
And save STDOUT as {BETA_ID}
1253+
1254+
When I run `wp site meta add {ALPHA_ID} colour blue`
1255+
Then STDOUT should not be empty
1256+
1257+
When I run `wp site list --meta_key=colour --meta_value=blue --field=blog_id`
1258+
Then STDOUT should be:
1259+
"""
1260+
{ALPHA_ID}
1261+
"""
1262+
1263+
When I run `wp site list --meta_key=colour --meta_value=red --format=count`
1264+
Then STDOUT should be:
1265+
"""
1266+
0
1267+
"""
1268+
1269+
# --meta_query is a nested array, so it is given as JSON.
1270+
When I run `wp site list --meta_query='[{"key":"colour","value":"blue"}]' --field=blog_id`
1271+
Then STDOUT should be:
1272+
"""
1273+
{ALPHA_ID}
1274+
"""
1275+
1276+
When I run `wp site list --meta_query='[{"key":"colour","compare":"NOT EXISTS"}]' --field=blog_id`
1277+
Then STDOUT should be:
1278+
"""
1279+
1
1280+
{BETA_ID}
1281+
"""
1282+
10901283
Scenario: Existing site list filters keep working against WP_Site_Query
10911284
Given a WP multisite install
10921285

0 commit comments

Comments
 (0)