Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add signup command class
  • Loading branch information
ernilambar committed Apr 26, 2024
commit f852acf60691e5dcb6d6dcf5d35bb13754b586bb
179 changes: 179 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3344,6 +3344,185 @@ These fields are optionally available:



### wp signup

Manages signups on a multisite installation.

~~~
wp signup
~~~

**EXAMPLES**

# List signups.
$ wp signup list
+-----------+------------+---------------------+---------------------+--------+------------------+
| signup_id | user_login | user_email | registered | active | activation_key |
+-----------+------------+---------------------+---------------------+--------+------------------+
| 1 | bobuser | bobuser@example.com | 2024-03-13 05:46:53 | 1 | 7320b2f009266618 |
| 2 | johndoe | johndoe@example.com | 2024-03-13 06:24:44 | 0 | 9068d859186cd0b5 |
+-----------+------------+---------------------+---------------------+--------+------------------+

# Activate signup.
$ wp signup activate 2
Success: Signup activated. Password: bZFSGsfzb9xs

# Delete signup.
$ wp signup delete 3
Success: Signup deleted.



### wp signup activate

Activates a signup.

~~~
wp signup activate <signup>
~~~

**OPTIONS**

<signup>
Signup ID, user login, user email or activation key.

**EXAMPLES**

# Activate signup.
$ wp signup activate 2
Success: Signup activated. Password: bZFSGsfzb9xs



### wp signup delete

Deletes a signup.

~~~
wp signup delete <signup>
~~~

**OPTIONS**

<signup>
Signup ID, user login, user email or activation key.

**EXAMPLES**

# Delete signup.
$ wp signup delete 3
Success: Signup deleted.



### wp signup get

Gets details about the signup.

~~~
wp signup get <signup> [--field=<field>] [--fields=<fields>] [--format=<format>]
~~~

**OPTIONS**

<signup>
Signup ID, user login, user email or activation key.

[--field=<field>]
Instead of returning the whole signup, returns the value of a single field.

[--fields=<fields>]
Get a specific subset of the signup's fields.

[--format=<format>]
Render output in a particular format.
---
default: table
options:
- table
- csv
- json
- yaml
---

**EXAMPLES**

# Get signup.
$ wp signup get 1
+-----------+------------+---------------------+---------------------+--------+------------------+
| signup_id | user_login | user_email | registered | active | activation_key |
+-----------+------------+---------------------+---------------------+--------+------------------+
| 1 | bobuser | bobuser@example.com | 2024-03-13 05:46:53 | 1 | 663b5af63dd930fd |
+-----------+------------+---------------------+---------------------+--------+------------------+



### wp signup list

Lists signups.

~~~
wp signup list [--field=<field>] [--<field>=<value>] [--fields=<fields>] [--format=<format>]
~~~

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

[--<field>=<value>]
Filter results by key=value pairs.

[--fields=<fields>]
Limit the output to specific object fields.

[--format=<format>]
Render output in a particular format.
---
default: table
options:
- table
- csv
- ids
- json
- yaml
- count
---

**AVAILABLE FIELDS**

These fields will be displayed by default for each signup:

* signup_id
* user_login
* user_email
* registered
* active
* activation_key

These fields are optionally available:

* domain
* path
* title
* activated
* meta

**EXAMPLES**

# List signup IDs.
$ wp signup list --field=signup_id
1

# List all signups.
$ wp signup list
+-----------+------------+---------------------+---------------------+--------+------------------+
| signup_id | user_login | user_email | registered | active | activation_key |
+-----------+------------+---------------------+---------------------+--------+------------------+
| 1 | bobuser | bobuser@example.com | 2024-03-13 05:46:53 | 1 | 7320b2f009266618 |
| 2 | johndoe | johndoe@example.com | 2024-03-13 06:24:44 | 0 | 9068d859186cd0b5 |
+-----------+------------+---------------------+---------------------+--------+------------------+



### wp site

Creates, deletes, empties, moderates, and lists one or more sites on a multisite installation.
Expand Down
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@
"post-type",
"post-type get",
"post-type list",
"signup",
"signup activate",
"signup delete",
"signup get",
"signup list",
"site",
"site activate",
"site archive",
Expand Down
12 changes: 12 additions & 0 deletions entity-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,15 @@
if ( class_exists( 'WP_CLI\Dispatcher\CommandNamespace' ) ) {
WP_CLI::add_command( 'network', 'Network_Namespace' );
}

WP_CLI::add_command(
'signup',
'Signup_Command',
array(
'before_invoke' => function () {
if ( ! is_multisite() ) {
WP_CLI::error( 'This is not a multisite installation.' );
}
},
)
);
126 changes: 126 additions & 0 deletions features/signup.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
Feature: Manage signups in a multisite installation

Scenario: Not applicable in single installation site
Given a WP install

When I try `wp signup list`
Then STDERR should be:
"""
Error: This is not a multisite installation.
"""

Scenario: List signups
Given a WP multisite install
And I run `wp eval 'wpmu_signup_user( "bobuser", "bobuser@example.com" );'`
And I run `wp eval 'wpmu_signup_user( "johnuser", "johnuser@example.com" );'`

When I run `wp signup list --fields=signup_id,user_login,user_email,active --format=csv`
Then STDOUT should be:
"""
signup_id,user_login,user_email,active
1,bobuser,bobuser@example.com,0
2,johnuser,johnuser@example.com,0
"""

When I run `wp signup list --format=count --active=1`
Then STDOUT should be:
"""
0
"""

When I run `wp signup activate bobuser`
Then STDOUT should contain:
"""
Success: Signup activated.
"""

When I run `wp signup list --fields=signup_id,user_login,user_email,active --format=csv --active=1`
Then STDOUT should be:
"""
signup_id,user_login,user_email,active
1,bobuser,bobuser@example.com,1
"""

Scenario: Get signup
Given a WP multisite install
And I run `wp eval 'wpmu_signup_user( "bobuser", "bobuser@example.com" );'`

When I run `wp signup get bobuser --fields=signup_id,user_login,user_email,active --format=csv`
Then STDOUT should be:
"""
signup_id,user_login,user_email,active
1,bobuser,bobuser@example.com,0
"""

Scenario: Delete signup
Given a WP multisite install

When I run `wp eval 'wpmu_signup_user( "bobuser", "bobuser@example.com" );'`
And I run `wp signup get bobuser --field=user_login`
Then STDOUT should be:
"""
bobuser
"""

When I run `wp signup delete bobuser@example.com`
Then STDOUT should be:
"""
Success: Signup deleted.
"""

When I try `wp signup get bobuser`
Then STDERR should be:
"""
Error: Invalid signup ID, email, login or activation key: 'bobuser'
"""

Scenario: Activate signup
Given a WP multisite install
And I run `wp eval 'wpmu_signup_user( "bobuser", "bobuser@example.com" );'`

And I run `wp signup get bobuser --field=active`
Then STDOUT should be:
"""
0
"""

When I run `wp signup activate bobuser`
Then STDOUT should contain:
"""
Success: Signup activated.
"""

When I run `wp signup get bobuser --field=active`
Then STDOUT should be:
"""
1
"""

When I run `wp user get bobuser --field=user_email`
Then STDOUT should be:
"""
bobuser@example.com
"""

Scenario: Activate blog signup entry
Given a WP multisite install
And I run `wp eval 'wpmu_signup_blog( "example.com", "/bobsite/", "My Awesome Title", "bobuser", "bobuser@example.com" );'`

When I run `wp signup get bobuser --fields=user_login,domain,path,active --format=csv`
Then STDOUT should be:
"""
user_login,domain,path,active
bobuser,example.com,/bobsite/,0
"""

When I run `wp signup activate bobuser`
Then STDOUT should contain:
"""
Success: Signup activated.
"""

When I run `wp site list --fields=domain,path`
Then STDOUT should be a table containing rows:
| domain | path |
| example.com | / |
| example.com | /bobsite/ |
3 changes: 2 additions & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

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

Expand All @@ -65,6 +65,7 @@
<exclude-pattern>*/src/Network_Namespace\.php$</exclude-pattern>
<exclude-pattern>*/src/Option_Command\.php$</exclude-pattern>
<exclude-pattern>*/src/Post(_Meta|_Term|_Type)?_Command\.php$</exclude-pattern>
<exclude-pattern>*/src/Signup_Command\.php$</exclude-pattern>
<exclude-pattern>*/src/Site(_Meta|_Option)?_Command\.php$</exclude-pattern>
<exclude-pattern>*/src/Term(_Meta)?_Command\.php$</exclude-pattern>
<exclude-pattern>*/src/User(_Application_Password|_Meta|_Session|_Term)?_Command\.php$</exclude-pattern>
Expand Down
Loading