Skip to content

Commit 9b40da7

Browse files
authored
Query sites through WP_Site_Query in wp site list (#639)
1 parent f7da2b5 commit 9b40da7

3 files changed

Lines changed: 328 additions & 47 deletions

File tree

‎README.md‎

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5443,7 +5443,7 @@ 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=<yyyy-mm-dd-hh-ii-ss>] [--last_updated=<yyyy-mm-dd-hh-ii-ss>] [--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>] [--<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>]
54475447
~~~
54485448

54495449
**OPTIONS**
@@ -5452,8 +5452,10 @@ wp site list [--network=<id>] [--<field>=<value>] [--site__in=<value>] [--site_u
54525452
The network to which the sites belong.
54535453

54545454
[--<field>=<value>]
5455-
Filter by one or more fields (see "Available Fields" section). However,
5456-
'url' isn't an available filter, as it comes from 'home' in wp_options.
5455+
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+
filter, as it comes from 'home' in wp_options.
54575459
Note: '--path' conflicts with the global parameter of the same name; use
54585460
'--site-path' to filter by path instead.
54595461

@@ -5476,11 +5478,13 @@ wp site list [--network=<id>] [--<field>=<value>] [--site__in=<value>] [--site_u
54765478
[--domain=<domain>]
54775479
Filter by domain.
54785480

5479-
[--registered=<yyyy-mm-dd-hh-ii-ss>]
5480-
Filter by the date the site was registered.
5481+
[--registered=<date>]
5482+
Filter by the date the site was registered. Accepts a timestamp or a
5483+
date; a value carrying no time of day matches that whole day.
54815484

5482-
[--last_updated=<yyyy-mm-dd-hh-ii-ss>]
5483-
Filter by the date the site was last updated.
5485+
[--last_updated=<date>]
5486+
Filter by the date the site was last updated. Accepts a timestamp or a
5487+
date; a value carrying no time of day matches that whole day.
54845488

54855489
[--public=<public>]
54865490
Filter by whether the site is public. Accepts 1 or 0.
@@ -5547,6 +5551,15 @@ These fields are optionally available:
55475551
http://www.example.com/
55485552
http://www.example.com/subdir/
55495553

5554+
# Output site URLs, most recently registered first
5555+
$ wp site list --orderby=registered --order=desc --field=url
5556+
http://www.example.com/subdir/
5557+
http://www.example.com/
5558+
5559+
# Search for sites by domain or path
5560+
$ wp site list --search=subdir --field=url
5561+
http://www.example.com/subdir/
5562+
55505563

55515564

55525565
### wp site mature

‎features/site.feature‎

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,3 +1041,178 @@ Feature: Manage sites in a multisite installation
10411041
"""
10421042
3
10431043
"""
1044+
1045+
Scenario: List sites using WP_Site_Query arguments
1046+
Given a WP multisite install
1047+
1048+
When I run `wp site create --slug=alpha --porcelain`
1049+
Then STDOUT should be a number
1050+
And save STDOUT as {ALPHA_ID}
1051+
1052+
When I run `wp site create --slug=beta --porcelain`
1053+
Then STDOUT should be a number
1054+
And save STDOUT as {BETA_ID}
1055+
1056+
# --search, --site__not_in, --number, --offset and --orderby all come from
1057+
# WP_Site_Query and were silently ignored before.
1058+
When I run `wp site list --search=alpha --field=blog_id`
1059+
Then STDOUT should be:
1060+
"""
1061+
{ALPHA_ID}
1062+
"""
1063+
1064+
When I run `wp site list --site__not_in={ALPHA_ID} --format=count`
1065+
Then STDOUT should be:
1066+
"""
1067+
2
1068+
"""
1069+
1070+
When I run `wp site list --number=1 --format=count`
1071+
Then STDOUT should be:
1072+
"""
1073+
1
1074+
"""
1075+
1076+
When I run `wp site list --number=1 --offset=1 --field=blog_id`
1077+
Then STDOUT should be:
1078+
"""
1079+
{ALPHA_ID}
1080+
"""
1081+
1082+
When I run `wp site list --orderby=id --order=desc --field=blog_id`
1083+
Then STDOUT should be:
1084+
"""
1085+
{BETA_ID}
1086+
{ALPHA_ID}
1087+
1
1088+
"""
1089+
1090+
Scenario: Existing site list filters keep working against WP_Site_Query
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+
# --site__in returns rows in the order the IDs were given.
1102+
When I run `wp site list --site__in={BETA_ID},{ALPHA_ID} --field=blog_id`
1103+
Then STDOUT should be:
1104+
"""
1105+
{BETA_ID}
1106+
{ALPHA_ID}
1107+
"""
1108+
1109+
When I run `wp site list --blog_id={ALPHA_ID} --field=blog_id`
1110+
Then STDOUT should be:
1111+
"""
1112+
{ALPHA_ID}
1113+
"""
1114+
1115+
When I run `wp site list --site_id=1 --format=count`
1116+
Then STDOUT should be:
1117+
"""
1118+
3
1119+
"""
1120+
1121+
When I run `wp site list --site_id=2 --format=count`
1122+
Then STDOUT should be:
1123+
"""
1124+
0
1125+
"""
1126+
1127+
When I run `wp site list --site-path=/alpha/ --field=blog_id`
1128+
Then STDOUT should be:
1129+
"""
1130+
{ALPHA_ID}
1131+
"""
1132+
1133+
# admin belongs to every site, bobby only to the one they were created on, so the
1134+
# two counts differ and neither can pass by accident.
1135+
When I run `wp site list --site_user=admin --format=count`
1136+
Then STDOUT should be:
1137+
"""
1138+
3
1139+
"""
1140+
1141+
When I run `wp user create bobby bobby@example.com --role=author --porcelain`
1142+
Then STDOUT should be a number
1143+
1144+
When I run `wp site list --site_user=bobby --field=blog_id`
1145+
Then STDOUT should be:
1146+
"""
1147+
1
1148+
"""
1149+
1150+
# --site__in and --site_user narrow each other rather than one replacing the
1151+
# other, so the pair keeps only the sites satisfying both.
1152+
When I run `wp site list --site__in={ALPHA_ID} --site_user=bobby --format=count`
1153+
Then STDOUT should be:
1154+
"""
1155+
0
1156+
"""
1157+
1158+
When I run `wp site list --site__in=1,{ALPHA_ID} --site_user=bobby --field=blog_id`
1159+
Then STDOUT should be:
1160+
"""
1161+
1
1162+
"""
1163+
1164+
Scenario: Filter the site list by registration or update date
1165+
Given a WP multisite install
1166+
1167+
When I run `wp site create --slug=alpha --porcelain`
1168+
Then STDOUT should be a number
1169+
And save STDOUT as {ALPHA_ID}
1170+
1171+
When I run `wp site list --blog_id={ALPHA_ID} --field=registered`
1172+
Then STDOUT should not be empty
1173+
And save STDOUT as {REGISTERED}
1174+
And save STDOUT '(\d{4}-\d{2}-\d{2})' as {REGISTERED_DAY}
1175+
1176+
When I run `wp site list --registered='{REGISTERED}' --field=blog_id`
1177+
Then STDOUT should contain:
1178+
"""
1179+
{ALPHA_ID}
1180+
"""
1181+
1182+
# A value carrying no time of day matches every site registered that day, and
1183+
# only those - a day nothing was registered on comes back empty.
1184+
When I run `wp site list --registered={REGISTERED_DAY} --field=blog_id`
1185+
Then STDOUT should contain:
1186+
"""
1187+
{ALPHA_ID}
1188+
"""
1189+
1190+
When I run `wp site list --registered=1999-01-01 --format=count`
1191+
Then STDOUT should be:
1192+
"""
1193+
0
1194+
"""
1195+
1196+
When I run `wp site list --registered='1999-01-01 00:00:00' --format=count`
1197+
Then STDOUT should be:
1198+
"""
1199+
0
1200+
"""
1201+
1202+
When I run `wp site list --blog_id={ALPHA_ID} --field=last_updated`
1203+
Then STDOUT should not be empty
1204+
And save STDOUT as {LAST_UPDATED}
1205+
1206+
When I run `wp site list --last_updated='{LAST_UPDATED}' --field=blog_id`
1207+
Then STDOUT should contain:
1208+
"""
1209+
{ALPHA_ID}
1210+
"""
1211+
1212+
# Interpreting the value is left to WP_Date_Query, which resolves anything it
1213+
# cannot parse to a date no site can have registered on.
1214+
When I run `wp site list --registered=notadate --format=count`
1215+
Then STDOUT should be:
1216+
"""
1217+
0
1218+
"""

0 commit comments

Comments
 (0)