Skip to content

Commit f852acf

Browse files
committed
Add signup command class
1 parent 55f8309 commit f852acf

File tree

7 files changed

+646
-1
lines changed

7 files changed

+646
-1
lines changed

README.md

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3344,6 +3344,185 @@ These fields are optionally available:
33443344

33453345

33463346

3347+
### wp signup
3348+
3349+
Manages signups on a multisite installation.
3350+
3351+
~~~
3352+
wp signup
3353+
~~~
3354+
3355+
**EXAMPLES**
3356+
3357+
# List signups.
3358+
$ wp signup list
3359+
+-----------+------------+---------------------+---------------------+--------+------------------+
3360+
| signup_id | user_login | user_email | registered | active | activation_key |
3361+
+-----------+------------+---------------------+---------------------+--------+------------------+
3362+
| 1 | bobuser | [email protected] | 2024-03-13 05:46:53 | 1 | 7320b2f009266618 |
3363+
| 2 | johndoe | [email protected] | 2024-03-13 06:24:44 | 0 | 9068d859186cd0b5 |
3364+
+-----------+------------+---------------------+---------------------+--------+------------------+
3365+
3366+
# Activate signup.
3367+
$ wp signup activate 2
3368+
Success: Signup activated. Password: bZFSGsfzb9xs
3369+
3370+
# Delete signup.
3371+
$ wp signup delete 3
3372+
Success: Signup deleted.
3373+
3374+
3375+
3376+
### wp signup activate
3377+
3378+
Activates a signup.
3379+
3380+
~~~
3381+
wp signup activate <signup>
3382+
~~~
3383+
3384+
**OPTIONS**
3385+
3386+
<signup>
3387+
Signup ID, user login, user email or activation key.
3388+
3389+
**EXAMPLES**
3390+
3391+
# Activate signup.
3392+
$ wp signup activate 2
3393+
Success: Signup activated. Password: bZFSGsfzb9xs
3394+
3395+
3396+
3397+
### wp signup delete
3398+
3399+
Deletes a signup.
3400+
3401+
~~~
3402+
wp signup delete <signup>
3403+
~~~
3404+
3405+
**OPTIONS**
3406+
3407+
<signup>
3408+
Signup ID, user login, user email or activation key.
3409+
3410+
**EXAMPLES**
3411+
3412+
# Delete signup.
3413+
$ wp signup delete 3
3414+
Success: Signup deleted.
3415+
3416+
3417+
3418+
### wp signup get
3419+
3420+
Gets details about the signup.
3421+
3422+
~~~
3423+
wp signup get <signup> [--field=<field>] [--fields=<fields>] [--format=<format>]
3424+
~~~
3425+
3426+
**OPTIONS**
3427+
3428+
<signup>
3429+
Signup ID, user login, user email or activation key.
3430+
3431+
[--field=<field>]
3432+
Instead of returning the whole signup, returns the value of a single field.
3433+
3434+
[--fields=<fields>]
3435+
Get a specific subset of the signup's fields.
3436+
3437+
[--format=<format>]
3438+
Render output in a particular format.
3439+
---
3440+
default: table
3441+
options:
3442+
- table
3443+
- csv
3444+
- json
3445+
- yaml
3446+
---
3447+
3448+
**EXAMPLES**
3449+
3450+
# Get signup.
3451+
$ wp signup get 1
3452+
+-----------+------------+---------------------+---------------------+--------+------------------+
3453+
| signup_id | user_login | user_email | registered | active | activation_key |
3454+
+-----------+------------+---------------------+---------------------+--------+------------------+
3455+
| 1 | bobuser | [email protected] | 2024-03-13 05:46:53 | 1 | 663b5af63dd930fd |
3456+
+-----------+------------+---------------------+---------------------+--------+------------------+
3457+
3458+
3459+
3460+
### wp signup list
3461+
3462+
Lists signups.
3463+
3464+
~~~
3465+
wp signup list [--field=<field>] [--<field>=<value>] [--fields=<fields>] [--format=<format>]
3466+
~~~
3467+
3468+
[--field=<field>]
3469+
Prints the value of a single field for each signup.
3470+
3471+
[--<field>=<value>]
3472+
Filter results by key=value pairs.
3473+
3474+
[--fields=<fields>]
3475+
Limit the output to specific object fields.
3476+
3477+
[--format=<format>]
3478+
Render output in a particular format.
3479+
---
3480+
default: table
3481+
options:
3482+
- table
3483+
- csv
3484+
- ids
3485+
- json
3486+
- yaml
3487+
- count
3488+
---
3489+
3490+
**AVAILABLE FIELDS**
3491+
3492+
These fields will be displayed by default for each signup:
3493+
3494+
* signup_id
3495+
* user_login
3496+
* user_email
3497+
* registered
3498+
* active
3499+
* activation_key
3500+
3501+
These fields are optionally available:
3502+
3503+
* domain
3504+
* path
3505+
* title
3506+
* activated
3507+
* meta
3508+
3509+
**EXAMPLES**
3510+
3511+
# List signup IDs.
3512+
$ wp signup list --field=signup_id
3513+
1
3514+
3515+
# List all signups.
3516+
$ wp signup list
3517+
+-----------+------------+---------------------+---------------------+--------+------------------+
3518+
| signup_id | user_login | user_email | registered | active | activation_key |
3519+
+-----------+------------+---------------------+---------------------+--------+------------------+
3520+
| 1 | bobuser | [email protected] | 2024-03-13 05:46:53 | 1 | 7320b2f009266618 |
3521+
| 2 | johndoe | [email protected] | 2024-03-13 06:24:44 | 0 | 9068d859186cd0b5 |
3522+
+-----------+------------+---------------------+---------------------+--------+------------------+
3523+
3524+
3525+
33473526
### wp site
33483527

33493528
Creates, deletes, empties, moderates, and lists one or more sites on a multisite installation.

composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@
121121
"post-type",
122122
"post-type get",
123123
"post-type list",
124+
"signup",
125+
"signup activate",
126+
"signup delete",
127+
"signup get",
128+
"signup list",
124129
"site",
125130
"site activate",
126131
"site archive",

entity-command.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,15 @@
100100
if ( class_exists( 'WP_CLI\Dispatcher\CommandNamespace' ) ) {
101101
WP_CLI::add_command( 'network', 'Network_Namespace' );
102102
}
103+
104+
WP_CLI::add_command(
105+
'signup',
106+
'Signup_Command',
107+
array(
108+
'before_invoke' => function () {
109+
if ( ! is_multisite() ) {
110+
WP_CLI::error( 'This is not a multisite installation.' );
111+
}
112+
},
113+
)
114+
);

features/signup.feature

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
Feature: Manage signups in a multisite installation
2+
3+
Scenario: Not applicable in single installation site
4+
Given a WP install
5+
6+
When I try `wp signup list`
7+
Then STDERR should be:
8+
"""
9+
Error: This is not a multisite installation.
10+
"""
11+
12+
Scenario: List signups
13+
Given a WP multisite install
14+
And I run `wp eval 'wpmu_signup_user( "bobuser", "[email protected]" );'`
15+
And I run `wp eval 'wpmu_signup_user( "johnuser", "[email protected]" );'`
16+
17+
When I run `wp signup list --fields=signup_id,user_login,user_email,active --format=csv`
18+
Then STDOUT should be:
19+
"""
20+
signup_id,user_login,user_email,active
21+
1,bobuser,[email protected],0
22+
2,johnuser,[email protected],0
23+
"""
24+
25+
When I run `wp signup list --format=count --active=1`
26+
Then STDOUT should be:
27+
"""
28+
0
29+
"""
30+
31+
When I run `wp signup activate bobuser`
32+
Then STDOUT should contain:
33+
"""
34+
Success: Signup activated.
35+
"""
36+
37+
When I run `wp signup list --fields=signup_id,user_login,user_email,active --format=csv --active=1`
38+
Then STDOUT should be:
39+
"""
40+
signup_id,user_login,user_email,active
41+
1,bobuser,[email protected],1
42+
"""
43+
44+
Scenario: Get signup
45+
Given a WP multisite install
46+
And I run `wp eval 'wpmu_signup_user( "bobuser", "[email protected]" );'`
47+
48+
When I run `wp signup get bobuser --fields=signup_id,user_login,user_email,active --format=csv`
49+
Then STDOUT should be:
50+
"""
51+
signup_id,user_login,user_email,active
52+
1,bobuser,[email protected],0
53+
"""
54+
55+
Scenario: Delete signup
56+
Given a WP multisite install
57+
58+
When I run `wp eval 'wpmu_signup_user( "bobuser", "[email protected]" );'`
59+
And I run `wp signup get bobuser --field=user_login`
60+
Then STDOUT should be:
61+
"""
62+
bobuser
63+
"""
64+
65+
When I run `wp signup delete bobuser@example.com`
66+
Then STDOUT should be:
67+
"""
68+
Success: Signup deleted.
69+
"""
70+
71+
When I try `wp signup get bobuser`
72+
Then STDERR should be:
73+
"""
74+
Error: Invalid signup ID, email, login or activation key: 'bobuser'
75+
"""
76+
77+
Scenario: Activate signup
78+
Given a WP multisite install
79+
And I run `wp eval 'wpmu_signup_user( "bobuser", "[email protected]" );'`
80+
81+
And I run `wp signup get bobuser --field=active`
82+
Then STDOUT should be:
83+
"""
84+
0
85+
"""
86+
87+
When I run `wp signup activate bobuser`
88+
Then STDOUT should contain:
89+
"""
90+
Success: Signup activated.
91+
"""
92+
93+
When I run `wp signup get bobuser --field=active`
94+
Then STDOUT should be:
95+
"""
96+
1
97+
"""
98+
99+
When I run `wp user get bobuser --field=user_email`
100+
Then STDOUT should be:
101+
"""
102+
103+
"""
104+
105+
Scenario: Activate blog signup entry
106+
Given a WP multisite install
107+
And I run `wp eval 'wpmu_signup_blog( "example.com", "/bobsite/", "My Awesome Title", "bobuser", "[email protected]" );'`
108+
109+
When I run `wp signup get bobuser --fields=user_login,domain,path,active --format=csv`
110+
Then STDOUT should be:
111+
"""
112+
user_login,domain,path,active
113+
bobuser,example.com,/bobsite/,0
114+
"""
115+
116+
When I run `wp signup activate bobuser`
117+
Then STDOUT should contain:
118+
"""
119+
Success: Signup activated.
120+
"""
121+
122+
When I run `wp site list --fields=domain,path`
123+
Then STDOUT should be a table containing rows:
124+
| domain | path |
125+
| example.com | / |
126+
| example.com | /bobsite/ |

phpcs.xml.dist

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353

5454
<!-- Exclude existing classes from the prefix rule as it would break BC to prefix them now. -->
5555
<rule ref="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedNamespaceFound">
56-
<exclude-pattern>*/src/WP_CLI/Fetchers/(Comment|Post|Site|User)\.php$</exclude-pattern>
56+
<exclude-pattern>*/src/WP_CLI/Fetchers/(Comment|Post|Signup|Site|User)\.php$</exclude-pattern>
5757
<exclude-pattern>*/src/WP_CLI/CommandWith(DBObject|Meta|Terms)\.php$</exclude-pattern>
5858
</rule>
5959

@@ -65,6 +65,7 @@
6565
<exclude-pattern>*/src/Network_Namespace\.php$</exclude-pattern>
6666
<exclude-pattern>*/src/Option_Command\.php$</exclude-pattern>
6767
<exclude-pattern>*/src/Post(_Meta|_Term|_Type)?_Command\.php$</exclude-pattern>
68+
<exclude-pattern>*/src/Signup_Command\.php$</exclude-pattern>
6869
<exclude-pattern>*/src/Site(_Meta|_Option)?_Command\.php$</exclude-pattern>
6970
<exclude-pattern>*/src/Term(_Meta)?_Command\.php$</exclude-pattern>
7071
<exclude-pattern>*/src/User(_Application_Password|_Meta|_Session|_Term)?_Command\.php$</exclude-pattern>

0 commit comments

Comments
 (0)