Skip to content

Commit f05f337

Browse files
authored
Merge branch 'main' into copilot/add-ranges-to-commands
2 parents 0854b02 + 36afb61 commit f05f337

File tree

11 files changed

+180
-8
lines changed

11 files changed

+180
-8
lines changed

.gitattributes

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/.actrc export-ignore
2+
/.distignore export-ignore
3+
/.editorconfig export-ignore
4+
/.github export-ignore
5+
/.gitignore export-ignore
6+
/.typos.toml export-ignore
7+
/AGENTS.md export-ignore
8+
/behat.yml export-ignore
9+
/features export-ignore
10+
/phpcs.xml.dist export-ignore
11+
/phpstan.neon.dist export-ignore
12+
/phpunit.xml.dist export-ignore
13+
/tests export-ignore
14+
/wp-cli.yml export-ignore

.github/workflows/copilot-setup-steps.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525

2626
- name: Set up PHP environment
2727
if: steps.check_composer_file.outputs.files_exists == 'true'
28-
uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 # v2
28+
uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # v2
2929
with:
3030
php-version: 'latest'
3131
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
@@ -36,7 +36,7 @@ jobs:
3636

3737
- name: Install Composer dependencies & cache dependencies
3838
if: steps.check_composer_file.outputs.files_exists == 'true'
39-
uses: ramsey/composer-install@a35c6ebd3d08125aaf8852dff361e686a1a67947 # v3
39+
uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # v3
4040
env:
4141
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
4242
with:

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5339,7 +5339,7 @@ These fields are optionally available:
53395339
Lists all sites in a multisite installation.
53405340

53415341
~~~
5342-
wp site list [--network=<id>] [--<field>=<value>] [--site__in=<value>] [--site_user=<value>] [--field=<field>] [--fields=<fields>] [--format=<format>]
5342+
wp site list [--network=<id>] [--<field>=<value>] [--site__in=<value>] [--site_user=<value>] [--site-path=<path>] [--field=<field>] [--fields=<fields>] [--format=<format>]
53435343
~~~
53445344

53455345
**OPTIONS**
@@ -5350,13 +5350,18 @@ wp site list [--network=<id>] [--<field>=<value>] [--site__in=<value>] [--site_u
53505350
[--<field>=<value>]
53515351
Filter by one or more fields (see "Available Fields" section). However,
53525352
'url' isn't an available filter, as it comes from 'home' in wp_options.
5353+
Note: '--path' conflicts with the global parameter of the same name; use
5354+
'--site-path' to filter by path instead.
53535355

53545356
[--site__in=<value>]
53555357
Only list the sites with these blog_id values (comma-separated).
53565358

53575359
[--site_user=<value>]
53585360
Only list the sites with this user.
53595361

5362+
[--site-path=<path>]
5363+
Filter by path. Avoids conflict with the global `--path` parameter.
5364+
53605365
[--field=<field>]
53615366
Prints the value of a single field for each site.
53625367

@@ -7768,7 +7773,7 @@ Display WordPress users based on all arguments supported by
77687773
Control output by one or more arguments of WP_User_Query().
77697774

77707775
[--network]
7771-
List all users in the network for multisite.
7776+
List all users in the network for multisite. Roles are not included when using this flag, as users can have different roles on different sites in a multisite network.
77727777

77737778
[--field=<field>]
77747779
Prints the value of a single field for each user.

features/menu-item.feature

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,27 @@ Feature: Manage WordPress menu items
252252
"""
253253
And the return code should be 1
254254

255+
Scenario: Add a post type archive as a menu item
256+
257+
When I run `wp menu create "Archive Menu"`
258+
Then STDOUT should not be empty
259+
260+
When I run `wp menu item add-post-type-archive archive-menu post --porcelain`
261+
Then STDOUT should be a number
262+
And save STDOUT as {ITEM_ID}
263+
264+
When I run `wp menu item list archive-menu --fields=db_id,type,object`
265+
Then STDOUT should be a table containing rows:
266+
| db_id | type | object |
267+
| {ITEM_ID} | post_type_archive | post |
268+
269+
When I run `wp menu item get {ITEM_ID} --field=link`
270+
Then STDOUT should not be empty
271+
272+
When I try `wp menu item add-post-type-archive archive-menu invalidposttype`
273+
Then STDERR should be:
274+
"""
275+
Error: Invalid post type.
276+
"""
277+
And the return code should be 1
278+

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

features/user-list.feature

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@ Feature: List WordPress users
2727
bobjones
2828
"""
2929

30+
Scenario: List network users excludes roles field
31+
Given a WP multisite install
32+
And I run `wp user create bobjones bob@example.com --role=author`
33+
34+
When I run `wp user list --network --format=csv`
35+
Then STDOUT should contain:
36+
"""
37+
ID,user_login,display_name,user_email,user_registered
38+
"""
39+
And STDOUT should not contain:
40+
"""
41+
roles
42+
"""
43+
3044
@require-wp-4.9
3145
Scenario: List users without roles
3246
Given a WP install

features/user.feature

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,43 @@ Feature: Manage WordPress users
267267
Bob Jones
268268
"""
269269
270+
# The error message changed in WP 5.9.
271+
@less-than-wp-5.9
272+
Scenario: Creating a user with an existing email in multisite shows a clean error message
273+
Given a WP multisite install
274+
275+
When I run `wp user create bobjones bobjones@example.com`
276+
Then STDOUT should not be empty
277+
278+
When I try `wp user create bobjones2 bobjones@example.com`
279+
Then STDERR should contain:
280+
"""
281+
Sorry, that email address is already used!
282+
"""
283+
And STDERR should not contain:
284+
"""
285+
<
286+
"""
287+
And the return code should be 1
288+
289+
@require-wp-5.9
290+
Scenario: Creating a user with an existing email in multisite shows a clean error message
291+
Given a WP multisite install
292+
293+
When I run `wp user create bobjones bobjones@example.com`
294+
Then STDOUT should not be empty
295+
296+
When I try `wp user create bobjones2 bobjones@example.com`
297+
Then STDERR should contain:
298+
"""
299+
This email address is already registered.
300+
"""
301+
And STDERR should not contain:
302+
"""
303+
<
304+
"""
305+
And the return code should be 1
306+
270307
Scenario: Managing user roles
271308
Given a WP install
272309

src/Menu_Item_Command.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,69 @@ public function add_term( $args, $assoc_args ) {
329329
$this->add_or_update_item( 'add', 'taxonomy', $args, $assoc_args );
330330
}
331331

332+
/**
333+
* Adds a post type archive as a menu item.
334+
*
335+
* ## OPTIONS
336+
*
337+
* <menu>
338+
* : The name, slug, or term ID for the menu.
339+
*
340+
* <post-type>
341+
* : Post type slug.
342+
*
343+
* [--title=<title>]
344+
* : Set a custom title for the menu item.
345+
*
346+
* [--link=<link>]
347+
* : Set a custom url for the menu item.
348+
*
349+
* [--description=<description>]
350+
* : Set a custom description for the menu item.
351+
*
352+
* [--attr-title=<attr-title>]
353+
* : Set a custom title attribute for the menu item.
354+
*
355+
* [--target=<target>]
356+
* : Set a custom link target for the menu item.
357+
*
358+
* [--classes=<classes>]
359+
* : Set a custom link classes for the menu item.
360+
*
361+
* [--position=<position>]
362+
* : Specify the position of this menu item.
363+
*
364+
* [--parent-id=<parent-id>]
365+
* : Make this menu item a child of another menu item.
366+
*
367+
* [--porcelain]
368+
* : Output just the new menu item id.
369+
*
370+
* ## EXAMPLES
371+
*
372+
* $ wp menu item add-post-type-archive sidebar-menu post
373+
* Success: Menu item added.
374+
*
375+
* @subcommand add-post-type-archive
376+
*/
377+
public function add_post_type_archive( $args, $assoc_args ) {
378+
379+
$assoc_args['object'] = $args[1];
380+
unset( $args[1] );
381+
382+
$post_type = $assoc_args['object'];
383+
384+
if ( ! get_post_type_object( $post_type ) ) {
385+
WP_CLI::error( 'Invalid post type.' );
386+
}
387+
388+
if ( false === get_post_type_archive_link( $post_type ) ) {
389+
WP_CLI::error( 'Post type does not have an archive.' );
390+
}
391+
392+
$this->add_or_update_item( 'add', 'post_type_archive', $args, $assoc_args );
393+
}
394+
332395
/**
333396
* Adds a custom menu item.
334397
*

src/Menu_Location_Command.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
22

33
use WP_CLI\Formatter;
4-
use WP_CLI\Utils;
54

65
/**
76
* Assigns, removes, and lists a menu's locations.

src/Site_Command.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,13 +962,18 @@ private function get_network( $network_id ) {
962962
* [--<field>=<value>]
963963
* : Filter by one or more fields (see "Available Fields" section). However,
964964
* 'url' isn't an available filter, as it comes from 'home' in wp_options.
965+
* Note: '--path' conflicts with the global parameter of the same name; use
966+
* '--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
*
@@ -1045,6 +1050,10 @@ public function list_( $args, $assoc_args ) {
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)