Skip to content

Commit d025fb9

Browse files
committed
Move the site meta filters behind @require-wp-5.1
Multisite gained the site meta table in WordPress 5.1, and WP_Site_Query gained the meta_* parameters that read it in the same release, so `wp site meta add` fails on 4.9 with "The table is not installed" and the filters have nothing to match against. They get a scenario of their own, tagged for the version that has them, and the docblock says so. The rest stays where it is: 'lang_id', 'lang__in' and 'lang__not_in' date from 4.8 and everything else here from 4.6, so only the meta arguments needed separating. Also covers '--last_updated' against an OR date query, not just '--registered', so both filters are pinned against the relation leaking. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014SSZzqMJRDTiLiDxQEPYcL
1 parent 25297bc commit d025fb9

3 files changed

Lines changed: 70 additions & 32 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5538,7 +5538,8 @@ wp site list [--network=<id>|site_id|network_id] [--<field>=<value>] [--site__in
55385538
and 'path'.
55395539

55405540
[--meta_key=<meta_key>]
5541-
Filter by this site 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.
55425543

55435544
[--meta_value=<meta_value>]
55445545
Filter by this site meta value. Used together with `--meta_key`.

features/site.feature

Lines changed: 59 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,35 +1169,7 @@ Feature: Manage sites in a multisite installation
11691169
3
11701170
"""
11711171

1172-
When I run `wp site meta add {ALPHA_ID} colour blue`
1173-
Then STDOUT should not be empty
1174-
1175-
When I run `wp site list --meta_key=colour --meta_value=blue --field=blog_id`
1176-
Then STDOUT should be:
1177-
"""
1178-
{ALPHA_ID}
1179-
"""
1180-
1181-
When I run `wp site list --meta_key=colour --meta_value=red --format=count`
1182-
Then STDOUT should be:
1183-
"""
1184-
0
1185-
"""
1186-
1187-
# --meta_query and --date_query are nested arrays, so they are given as JSON.
1188-
When I run `wp site list --meta_query='[{"key":"colour","value":"blue"}]' --field=blog_id`
1189-
Then STDOUT should be:
1190-
"""
1191-
{ALPHA_ID}
1192-
"""
1193-
1194-
When I run `wp site list --meta_query='[{"key":"colour","compare":"NOT EXISTS"}]' --field=blog_id`
1195-
Then STDOUT should be:
1196-
"""
1197-
1
1198-
{BETA_ID}
1199-
"""
1200-
1172+
# --date_query is a nested array, so it is given as JSON.
12011173
When I run `wp site list --date_query='[{"column":"registered","after":"1999-01-01"}]' --format=count`
12021174
Then STDOUT should be:
12031175
"""
@@ -1236,6 +1208,21 @@ Feature: Manage sites in a multisite installation
12361208
0
12371209
"""
12381210

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+
12391226
When I try `wp site list --meta_query=notjson`
12401227
Then STDERR should contain:
12411228
"""
@@ -1250,6 +1237,49 @@ Feature: Manage sites in a multisite installation
12501237
"""
12511238
And the return code should be 1
12521239

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+
12531283
Scenario: Existing site list filters keep working against WP_Site_Query
12541284
Given a WP multisite install
12551285

src/Site_Command.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,8 @@ private function get_network( $network_id ) {
10721072
* and 'path'.
10731073
*
10741074
* [--meta_key=<meta_key>]
1075-
* : Filter by this site meta key.
1075+
* : Filter by this site meta key. The site meta arguments need WordPress 5.1
1076+
* or later, which is where multisite gained the table they read.
10761077
*
10771078
* [--meta_value=<meta_value>]
10781079
* : Filter by this site meta value. Used together with `--meta_key`.
@@ -1290,7 +1291,13 @@ public function list_( $args, $assoc_args ) {
12901291

12911292
$query_args['date_query'] = empty( $given )
12921293
? $date_query
1293-
: array_merge( [ 'relation' => 'AND', $given ], $date_query );
1294+
: array_merge(
1295+
[
1296+
'relation' => 'AND',
1297+
$given,
1298+
],
1299+
$date_query
1300+
);
12941301
}
12951302

12961303
if ( isset( $assoc_args['site_user'] ) ) {

0 commit comments

Comments
 (0)