From f852acf60691e5dcb6d6dcf5d35bb13754b586bb Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Fri, 15 Mar 2024 12:33:23 +0545 Subject: [PATCH 01/17] Add signup command class --- README.md | 179 +++++++++++++++++++++++ composer.json | 5 + entity-command.php | 12 ++ features/signup.feature | 126 ++++++++++++++++ phpcs.xml.dist | 3 +- src/Signup_Command.php | 256 +++++++++++++++++++++++++++++++++ src/WP_CLI/Fetchers/Signup.php | 66 +++++++++ 7 files changed, 646 insertions(+), 1 deletion(-) create mode 100644 features/signup.feature create mode 100644 src/Signup_Command.php create mode 100644 src/WP_CLI/Fetchers/Signup.php diff --git a/README.md b/README.md index 1e71a5ab0..a10980304 100644 --- a/README.md +++ b/README.md @@ -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 +~~~ + +**OPTIONS** + + + 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 +~~~ + +**OPTIONS** + + + 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 [--field=] [--fields=] [--format=] +~~~ + +**OPTIONS** + + + Signup ID, user login, user email or activation key. + + [--field=] + Instead of returning the whole signup, returns the value of a single field. + + [--fields=] + Get a specific subset of the signup's fields. + + [--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=] [--=] [--fields=] [--format=] +~~~ + + [--field=] + Prints the value of a single field for each signup. + + [--=] + Filter results by key=value pairs. + + [--fields=] + Limit the output to specific object fields. + + [--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. diff --git a/composer.json b/composer.json index 163b0bd43..3cbed3d51 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/entity-command.php b/entity-command.php index a9e5381d9..25caf1fba 100644 --- a/entity-command.php +++ b/entity-command.php @@ -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.' ); + } + }, + ) +); diff --git a/features/signup.feature b/features/signup.feature new file mode 100644 index 000000000..f0246202f --- /dev/null +++ b/features/signup.feature @@ -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/ | diff --git a/phpcs.xml.dist b/phpcs.xml.dist index b0a3612e4..1e08f6e16 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -53,7 +53,7 @@ - */src/WP_CLI/Fetchers/(Comment|Post|Site|User)\.php$ + */src/WP_CLI/Fetchers/(Comment|Post|Signup|Site|User)\.php$ */src/WP_CLI/CommandWith(DBObject|Meta|Terms)\.php$ @@ -65,6 +65,7 @@ */src/Network_Namespace\.php$ */src/Option_Command\.php$ */src/Post(_Meta|_Term|_Type)?_Command\.php$ + */src/Signup_Command\.php$ */src/Site(_Meta|_Option)?_Command\.php$ */src/Term(_Meta)?_Command\.php$ */src/User(_Application_Password|_Meta|_Session|_Term)?_Command\.php$ diff --git a/src/Signup_Command.php b/src/Signup_Command.php new file mode 100644 index 000000000..39547bc6b --- /dev/null +++ b/src/Signup_Command.php @@ -0,0 +1,256 @@ +fetcher = new SignupFetcher(); + } + + /** + * Lists signups. + * + * [--field=] + * : Prints the value of a single field for each signup. + * + * [--=] + * : Filter results by key=value pairs. + * + * [--fields=] + * : Limit the output to specific object fields. + * + * [--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 | + * +-----------+------------+---------------------+---------------------+--------+------------------+ + * + * @subcommand list + * + * @package wp-cli + */ + public function list_( $args, $assoc_args ) { + global $wpdb; + + if ( isset( $assoc_args['fields'] ) ) { + $assoc_args['fields'] = explode( ',', $assoc_args['fields'] ); + } else { + $assoc_args['fields'] = $this->obj_fields; + } + + $signups = array(); + + $results = $wpdb->get_results( "SELECT * FROM $wpdb->signups", ARRAY_A ); + + if ( $results ) { + foreach ( $results as $item ) { + // Support features like --active=0. + foreach ( array_keys( $item ) as $field ) { + if ( isset( $assoc_args[ $field ] ) && $assoc_args[ $field ] !== $item[ $field ] ) { + continue 2; + } + } + + $signups[] = $item; + } + } + + $format = Utils\get_flag_value( $assoc_args, 'format', 'table' ); + + $formatter = $this->get_formatter( $assoc_args ); + + if ( 'ids' === $format ) { + WP_CLI::line( implode( ' ', wp_list_pluck( $signups, 'signup_id' ) ) ); + } else { + $formatter->display_items( $signups ); + } + } + + /** + * Gets details about the signup. + * + * ## OPTIONS + * + * + * : Signup ID, user login, user email or activation key. + * + * [--field=] + * : Instead of returning the whole signup, returns the value of a single field. + * + * [--fields=] + * : Get a specific subset of the signup's fields. + * + * [--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 | + * +-----------+------------+---------------------+---------------------+--------+------------------+ + * + * @package wp-cli + */ + public function get( $args, $assoc_args ) { + $signup = $this->fetcher->get_check( $args[0] ); + + $formatter = $this->get_formatter( $assoc_args ); + + $formatter->display_items( array( $signup ) ); + } + + /** + * Activates a signup. + * + * ## OPTIONS + * + * + * : Signup ID, user login, user email or activation key. + * + * ## EXAMPLES + * + * # Activate signup. + * $ wp signup activate 2 + * Success: Signup activated. Password: bZFSGsfzb9xs + * + * @package wp-cli + */ + public function activate( $args, $assoc_args ) { + $signup = $this->fetcher->get_check( $args[0] ); + + if ( $signup ) { + $result = wpmu_activate_signup( $signup->activation_key ); + } + + if ( is_wp_error( $result ) ) { + WP_CLI::error( 'Signup could not be activated. Reason: ' . $result->get_error_message() ); + } else { + WP_CLI::success( "Signup activated. Password: {$result['password']}" ); + } + } + + /** + * Deletes a signup. + * + * ## OPTIONS + * + * + * : Signup ID, user login, user email or activation key. + * + * ## EXAMPLES + * + * # Delete signup. + * $ wp signup delete 3 + * Success: Signup deleted. + * + * @package wp-cli + */ + public function delete( $args, $assoc_args ) { + global $wpdb; + + $signup = $this->fetcher->get_check( $args[0] ); + + $result = $wpdb->delete( $wpdb->signups, array( 'signup_id' => $signup->signup_id ), array( '%d' ) ); + + if ( $result ) { + WP_CLI::success( 'Signup deleted.' ); + } else { + WP_CLI::error( 'Error occurred while deleting signup.' ); + } + } +} diff --git a/src/WP_CLI/Fetchers/Signup.php b/src/WP_CLI/Fetchers/Signup.php new file mode 100644 index 000000000..7126b9f09 --- /dev/null +++ b/src/WP_CLI/Fetchers/Signup.php @@ -0,0 +1,66 @@ +get_signup( $signup ); + } + + /** + * Get a signup by one of its identifying attributes. + * + * @param string $arg The raw CLI argument. + * @return stdClass|false The item if found; false otherwise. + */ + protected function get_signup( $arg ) { + global $wpdb; + + $signup_object = null; + + // Fetch signup with signup_id. + if ( is_numeric( $arg ) ) { + $result = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE signup_id = %d", $arg ) ); + + if ( $result ) { + $signup_object = $result; + } + } + + if ( ! $signup_object ) { + // Try to fetch with other keys. + foreach ( array( 'user_login', 'user_email', 'activation_key' ) as $field ) { + // phpcs:ignore WordPress.DB.PreparedSQL + $result = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE $field = %s", $arg ) ); + + if ( $result ) { + $signup_object = $result; + break; + } + } + } + + if ( $signup_object ) { + return $signup_object; + } + + return false; + } +} From 660fff5ea72a5df53958d426f7b01672b20c6f71 Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Mon, 18 Mar 2024 17:53:48 +0545 Subject: [PATCH 02/17] Update command docs --- README.md | 20 ++++++++++---------- features/signup.feature | 2 +- src/Signup_Command.php | 22 +++++++++++++--------- src/WP_CLI/Fetchers/Signup.php | 2 +- 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index a10980304..6446713db 100644 --- a/README.md +++ b/README.md @@ -3384,7 +3384,7 @@ wp signup activate **OPTIONS** - Signup ID, user login, user email or activation key. + Signup ID, user login, user email, or activation key. **EXAMPLES** @@ -3405,7 +3405,7 @@ wp signup delete **OPTIONS** - Signup ID, user login, user email or activation key. + Signup ID, user login, user email, or activation key. **EXAMPLES** @@ -3417,7 +3417,7 @@ wp signup delete ### wp signup get -Gets details about the signup. +Gets details about a signup. ~~~ wp signup get [--field=] [--fields=] [--format=] @@ -3426,13 +3426,13 @@ wp signup get [--field=] [--fields=] [--format=] **OPTIONS** - Signup ID, user login, user email or activation key. + Signup ID, user login, user email, or activation key. [--field=] Instead of returning the whole signup, returns the value of a single field. [--fields=] - Get a specific subset of the signup's fields. + Limit the output to specific fields. Defaults to all fields. [--format=] Render output in a particular format. @@ -3462,15 +3462,15 @@ wp signup get [--field=] [--fields=] [--format=] Lists signups. ~~~ -wp signup list [--field=] [--=] [--fields=] [--format=] +wp signup list [--=] [--field=] [--fields=] [--format=] ~~~ + [--=] + Filter the list by a specific field. + [--field=] Prints the value of a single field for each signup. - [--=] - Filter results by key=value pairs. - [--fields=] Limit the output to specific object fields. @@ -3483,8 +3483,8 @@ wp signup list [--field=] [--=] [--fields=] [--form - csv - ids - json - - yaml - count + - yaml --- **AVAILABLE FIELDS** diff --git a/features/signup.feature b/features/signup.feature index f0246202f..96bb604e0 100644 --- a/features/signup.feature +++ b/features/signup.feature @@ -71,7 +71,7 @@ Feature: Manage signups in a multisite installation When I try `wp signup get bobuser` Then STDERR should be: """ - Error: Invalid signup ID, email, login or activation key: 'bobuser' + Error: Invalid signup ID, email, login, or activation key: 'bobuser' """ Scenario: Activate signup diff --git a/src/Signup_Command.php b/src/Signup_Command.php index 39547bc6b..3d44acc1a 100644 --- a/src/Signup_Command.php +++ b/src/Signup_Command.php @@ -52,12 +52,12 @@ public function __construct() { /** * Lists signups. * + * [--=] + * : Filter the list by a specific field. + * * [--field=] * : Prints the value of a single field for each signup. * - * [--=] - * : Filter results by key=value pairs. - * * [--fields=] * : Limit the output to specific object fields. * @@ -70,8 +70,8 @@ public function __construct() { * - csv * - ids * - json - * - yaml * - count + * - yaml * --- * * ## AVAILABLE FIELDS @@ -150,18 +150,18 @@ public function list_( $args, $assoc_args ) { } /** - * Gets details about the signup. + * Gets details about a signup. * * ## OPTIONS * * - * : Signup ID, user login, user email or activation key. + * : Signup ID, user login, user email, or activation key. * * [--field=] * : Instead of returning the whole signup, returns the value of a single field. * * [--fields=] - * : Get a specific subset of the signup's fields. + * : Limit the output to specific fields. Defaults to all fields. * * [--format=] * : Render output in a particular format. @@ -189,6 +189,10 @@ public function list_( $args, $assoc_args ) { public function get( $args, $assoc_args ) { $signup = $this->fetcher->get_check( $args[0] ); + if ( empty( $assoc_args['fields'] ) ) { + $assoc_args['fields'] = array_keys( (array) $signup ); + } + $formatter = $this->get_formatter( $assoc_args ); $formatter->display_items( array( $signup ) ); @@ -200,7 +204,7 @@ public function get( $args, $assoc_args ) { * ## OPTIONS * * - * : Signup ID, user login, user email or activation key. + * : Signup ID, user login, user email, or activation key. * * ## EXAMPLES * @@ -230,7 +234,7 @@ public function activate( $args, $assoc_args ) { * ## OPTIONS * * - * : Signup ID, user login, user email or activation key. + * : Signup ID, user login, user email, or activation key. * * ## EXAMPLES * diff --git a/src/WP_CLI/Fetchers/Signup.php b/src/WP_CLI/Fetchers/Signup.php index 7126b9f09..2e68e72c9 100644 --- a/src/WP_CLI/Fetchers/Signup.php +++ b/src/WP_CLI/Fetchers/Signup.php @@ -12,7 +12,7 @@ class Signup extends Base { * * @var string */ - protected $msg = "Invalid signup ID, email, login or activation key: '%s'"; + protected $msg = "Invalid signup ID, email, login, or activation key: '%s'"; /** * Get a signup. From 986adb99387f7898194d23cc2e52507a2eb1ffe1 Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Tue, 19 Mar 2024 11:49:39 +0545 Subject: [PATCH 03/17] Update success and error messages --- features/signup.feature | 8 ++++---- src/Signup_Command.php | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/features/signup.feature b/features/signup.feature index 96bb604e0..5fbcf571d 100644 --- a/features/signup.feature +++ b/features/signup.feature @@ -31,7 +31,7 @@ Feature: Manage signups in a multisite installation When I run `wp signup activate bobuser` Then STDOUT should contain: """ - Success: Signup activated. + Success: Signup 1 activated. """ When I run `wp signup list --fields=signup_id,user_login,user_email,active --format=csv --active=1` @@ -65,7 +65,7 @@ Feature: Manage signups in a multisite installation When I run `wp signup delete bobuser@example.com` Then STDOUT should be: """ - Success: Signup deleted. + Success: Signup 1 deleted. """ When I try `wp signup get bobuser` @@ -87,7 +87,7 @@ Feature: Manage signups in a multisite installation When I run `wp signup activate bobuser` Then STDOUT should contain: """ - Success: Signup activated. + Success: Signup 1 activated. """ When I run `wp signup get bobuser --field=active` @@ -116,7 +116,7 @@ Feature: Manage signups in a multisite installation When I run `wp signup activate bobuser` Then STDOUT should contain: """ - Success: Signup activated. + Success: Signup 1 activated. """ When I run `wp site list --fields=domain,path` diff --git a/src/Signup_Command.php b/src/Signup_Command.php index 3d44acc1a..820973e4d 100644 --- a/src/Signup_Command.php +++ b/src/Signup_Command.php @@ -222,9 +222,9 @@ public function activate( $args, $assoc_args ) { } if ( is_wp_error( $result ) ) { - WP_CLI::error( 'Signup could not be activated. Reason: ' . $result->get_error_message() ); + WP_CLI::error( "Failed activating signup {$signup->signup_id}." ); } else { - WP_CLI::success( "Signup activated. Password: {$result['password']}" ); + WP_CLI::success( "Signup {$signup->signup_id} activated. Password: {$result['password']}" ); } } @@ -252,9 +252,9 @@ public function delete( $args, $assoc_args ) { $result = $wpdb->delete( $wpdb->signups, array( 'signup_id' => $signup->signup_id ), array( '%d' ) ); if ( $result ) { - WP_CLI::success( 'Signup deleted.' ); + WP_CLI::success( "Signup {$signup->signup_id} deleted." ); } else { - WP_CLI::error( 'Error occurred while deleting signup.' ); + WP_CLI::error( "Failed deleting signup {$signup->signup_id}." ); } } } From 5aee1c4f140ad62fa577978f46e607dfc25adf8c Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Tue, 19 Mar 2024 12:39:39 +0545 Subject: [PATCH 04/17] Update readme based on new success messages --- README.md | 19 +++++++++---------- src/Signup_Command.php | 19 +++++++++---------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 6446713db..cd2f670a3 100644 --- a/README.md +++ b/README.md @@ -3365,11 +3365,11 @@ wp signup # Activate signup. $ wp signup activate 2 - Success: Signup activated. Password: bZFSGsfzb9xs + Success: Signup 2 activated. Password: bZFSGsfzb9xs # Delete signup. $ wp signup delete 3 - Success: Signup deleted. + Success: Signup 3 deleted. @@ -3390,7 +3390,7 @@ wp signup activate # Activate signup. $ wp signup activate 2 - Success: Signup activated. Password: bZFSGsfzb9xs + Success: Signup 2 activated. Password: bZFSGsfzb9xs @@ -3411,7 +3411,7 @@ wp signup delete # Delete signup. $ wp signup delete 3 - Success: Signup deleted. + Success: Signup 3 deleted. @@ -3448,12 +3448,11 @@ wp signup get [--field=] [--fields=] [--format=] **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 get 1 --field=user_login + bobuser + + # Get signup and export to JSON file. + $ wp signup get bobuser --format=json > bobuser.json diff --git a/src/Signup_Command.php b/src/Signup_Command.php index 820973e4d..5837a3b8b 100644 --- a/src/Signup_Command.php +++ b/src/Signup_Command.php @@ -20,11 +20,11 @@ * * # Activate signup. * $ wp signup activate 2 - * Success: Signup activated. Password: bZFSGsfzb9xs + * Success: Signup 2 activated. Password: bZFSGsfzb9xs * * # Delete signup. * $ wp signup delete 3 - * Success: Signup deleted. + * Success: Signup 3 deleted. * * @package wp-cli */ @@ -177,12 +177,11 @@ public function list_( $args, $assoc_args ) { * ## 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 get 1 --field=user_login + * bobuser + * + * # Get signup and export to JSON file. + * $ wp signup get bobuser --format=json > bobuser.json * * @package wp-cli */ @@ -210,7 +209,7 @@ public function get( $args, $assoc_args ) { * * # Activate signup. * $ wp signup activate 2 - * Success: Signup activated. Password: bZFSGsfzb9xs + * Success: Signup 2 activated. Password: bZFSGsfzb9xs * * @package wp-cli */ @@ -240,7 +239,7 @@ public function activate( $args, $assoc_args ) { * * # Delete signup. * $ wp signup delete 3 - * Success: Signup deleted. + * Success: Signup 3 deleted. * * @package wp-cli */ From e3bfbbc79346028633b5ff160382636a384b416c Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Tue, 19 Mar 2024 15:17:10 +0545 Subject: [PATCH 05/17] Update delete method to user callback function --- src/Signup_Command.php | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/Signup_Command.php b/src/Signup_Command.php index 5837a3b8b..f8f45e105 100644 --- a/src/Signup_Command.php +++ b/src/Signup_Command.php @@ -228,12 +228,12 @@ public function activate( $args, $assoc_args ) { } /** - * Deletes a signup. + * Deletes one or more signups. * * ## OPTIONS * - * - * : Signup ID, user login, user email, or activation key. + * ... + * : Signup ID, user login, user email, or activation key of the signup(s) to delete. * * ## EXAMPLES * @@ -244,16 +244,29 @@ public function activate( $args, $assoc_args ) { * @package wp-cli */ public function delete( $args, $assoc_args ) { + $signups = $this->fetcher->get_many( $args ); + + parent::_delete( $signups, $assoc_args, [ $this, 'delete_callback' ] ); + } + + /** + * Callback used to delete a signup. + * + * @param $signup + * @param $assoc_args + * @return array + */ + protected function delete_callback( $signup, $assoc_args ) { global $wpdb; - $signup = $this->fetcher->get_check( $args[0] ); + $signup_id = $signup->signup_id; - $result = $wpdb->delete( $wpdb->signups, array( 'signup_id' => $signup->signup_id ), array( '%d' ) ); + $result = $wpdb->delete( $wpdb->signups, array( 'signup_id' => $signup_id ), array( '%d' ) ); if ( $result ) { - WP_CLI::success( "Signup {$signup->signup_id} deleted." ); + return [ 'success', "Signup {$signup_id} deleted." ]; } else { - WP_CLI::error( "Failed deleting signup {$signup->signup_id}." ); + return [ 'error', "Failed deleting signup {$signup_id}." ]; } } } From 75b5b55a9e85143def7be201f8f989c8c8e44fc7 Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Tue, 19 Mar 2024 16:01:19 +0545 Subject: [PATCH 06/17] Accept multiple signups in activate command --- features/signup.feature | 85 ++++++++++++++++++++++++++++++++--------- src/Signup_Command.php | 20 +++++----- 2 files changed, 76 insertions(+), 29 deletions(-) diff --git a/features/signup.feature b/features/signup.feature index 5fbcf571d..dbc0619c4 100644 --- a/features/signup.feature +++ b/features/signup.feature @@ -45,6 +45,12 @@ Feature: Manage signups in a multisite installation Given a WP multisite install And I run `wp eval 'wpmu_signup_user( "bobuser", "bobuser@example.com" );'` + When I run `wp signup get 1 --field=user_login` + Then STDOUT should be: + """ + bobuser + """ + When I run `wp signup get bobuser --fields=signup_id,user_login,user_email,active --format=csv` Then STDOUT should be: """ @@ -52,54 +58,65 @@ Feature: Manage signups in a multisite installation 1,bobuser,bobuser@example.com,0 """ - Scenario: Delete signup + Scenario: Activate signup Given a WP multisite install + And I run `wp eval 'wpmu_signup_user( "bobuser", "bobuser@example.com" );'` - When I run `wp eval 'wpmu_signup_user( "bobuser", "bobuser@example.com" );'` - And I run `wp signup get bobuser --field=user_login` + When I run `wp signup get bobuser --field=active` Then STDOUT should be: """ - bobuser + 0 """ - When I run `wp signup delete bobuser@example.com` - Then STDOUT should be: + When I run `wp signup activate bobuser` + Then STDOUT should contain: """ - Success: Signup 1 deleted. + Success: Signup 1 activated. """ - When I try `wp signup get bobuser` + When I try the previous command again Then STDERR should be: """ - Error: Invalid signup ID, email, login, or activation key: 'bobuser' + Warning: Failed activating signup 1. """ - Scenario: Activate signup + 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 multiple 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" );'` - And I run `wp signup get bobuser --field=active` + When I run `wp signup list --active=0 --format=count` Then STDOUT should be: """ - 0 + 2 """ - When I run `wp signup activate bobuser` + When I run `wp signup activate bobuser johnuser` Then STDOUT should contain: """ Success: Signup 1 activated. """ - - When I run `wp signup get bobuser --field=active` - Then STDOUT should be: + And STDOUT should contain: """ - 1 + Success: Signup 2 activated. """ - When I run `wp user get bobuser --field=user_email` + When I run `wp signup list --active=1 --format=count` Then STDOUT should be: """ - bobuser@example.com + 2 """ Scenario: Activate blog signup entry @@ -124,3 +141,33 @@ Feature: Manage signups in a multisite installation | domain | path | | example.com | / | | example.com | /bobsite/ | + + Scenario: Delete 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 get bobuser --field=user_email` + Then STDOUT should be: + """ + bobuser@example.com + """ + + When I run `wp signup get johnuser --field=user_email` + Then STDOUT should be: + """ + johnuser@example.com + """ + + When I run `wp signup delete bobuser@example.com johnuser@example.com` + Then STDOUT should be: + """ + Success: Signup 1 deleted. + Success: Signup 2 deleted. + """ + + When I try `wp signup get bobuser` + Then STDERR should be: + """ + Error: Invalid signup ID, email, login, or activation key: 'bobuser' + """ diff --git a/src/Signup_Command.php b/src/Signup_Command.php index f8f45e105..0898f5f74 100644 --- a/src/Signup_Command.php +++ b/src/Signup_Command.php @@ -198,12 +198,12 @@ public function get( $args, $assoc_args ) { } /** - * Activates a signup. + * Activates one or more signups. * * ## OPTIONS * - * - * : Signup ID, user login, user email, or activation key. + * ... + * : Signup ID, user login, user email, or activation key of the signup(s) to activate. * * ## EXAMPLES * @@ -214,16 +214,16 @@ public function get( $args, $assoc_args ) { * @package wp-cli */ public function activate( $args, $assoc_args ) { - $signup = $this->fetcher->get_check( $args[0] ); + $signups = $this->fetcher->get_many( $args ); - if ( $signup ) { + foreach ( $signups as $signup ) { $result = wpmu_activate_signup( $signup->activation_key ); - } - if ( is_wp_error( $result ) ) { - WP_CLI::error( "Failed activating signup {$signup->signup_id}." ); - } else { - WP_CLI::success( "Signup {$signup->signup_id} activated. Password: {$result['password']}" ); + if ( is_wp_error( $result ) ) { + WP_CLI::warning( "Failed activating signup {$signup->signup_id}." ); + } else { + WP_CLI::success( "Signup {$signup->signup_id} activated. Password: {$result['password']}" ); + } } } From d5592a639455d443fc4491419b1c31a81f4b57e1 Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Tue, 19 Mar 2024 16:17:24 +0545 Subject: [PATCH 07/17] Update arguments description --- README.md | 18 +++++++++--------- src/Signup_Command.php | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index cd2f670a3..67957d88f 100644 --- a/README.md +++ b/README.md @@ -3375,16 +3375,16 @@ wp signup ### wp signup activate -Activates a signup. +Activates one or more signups. ~~~ -wp signup activate +wp signup activate ... ~~~ **OPTIONS** - - Signup ID, user login, user email, or activation key. + ... + The signup ID, user login, user email, or activation key of the signup(s) to activate. **EXAMPLES** @@ -3396,16 +3396,16 @@ wp signup activate ### wp signup delete -Deletes a signup. +Deletes one or more signups. ~~~ -wp signup delete +wp signup delete ... ~~~ **OPTIONS** - - Signup ID, user login, user email, or activation key. + ... + The signup ID, user login, user email, or activation key of the signup(s) to delete. **EXAMPLES** @@ -3426,7 +3426,7 @@ wp signup get [--field=] [--fields=] [--format=] **OPTIONS** - Signup ID, user login, user email, or activation key. + The signup ID, user login, user email, or activation key. [--field=] Instead of returning the whole signup, returns the value of a single field. diff --git a/src/Signup_Command.php b/src/Signup_Command.php index 0898f5f74..a463a32da 100644 --- a/src/Signup_Command.php +++ b/src/Signup_Command.php @@ -155,7 +155,7 @@ public function list_( $args, $assoc_args ) { * ## OPTIONS * * - * : Signup ID, user login, user email, or activation key. + * : The signup ID, user login, user email, or activation key. * * [--field=] * : Instead of returning the whole signup, returns the value of a single field. @@ -203,7 +203,7 @@ public function get( $args, $assoc_args ) { * ## OPTIONS * * ... - * : Signup ID, user login, user email, or activation key of the signup(s) to activate. + * : The signup ID, user login, user email, or activation key of the signup(s) to activate. * * ## EXAMPLES * @@ -233,7 +233,7 @@ public function activate( $args, $assoc_args ) { * ## OPTIONS * * ... - * : Signup ID, user login, user email, or activation key of the signup(s) to delete. + * : The signup ID, user login, user email, or activation key of the signup(s) to delete. * * ## EXAMPLES * From a02a3e66cb45e0519dd59f7ac8bade6762e284d9 Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Mon, 8 Apr 2024 17:24:34 +0545 Subject: [PATCH 08/17] Move signup under user command --- README.md | 358 ++++++++++++++++++++-------------------- composer.json | 10 +- entity-command.php | 2 +- features/signup.feature | 38 ++--- src/Signup_Command.php | 18 +- 5 files changed, 214 insertions(+), 212 deletions(-) diff --git a/README.md b/README.md index 67957d88f..b5a882ce2 100644 --- a/README.md +++ b/README.md @@ -3344,184 +3344,6 @@ 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 2 activated. Password: bZFSGsfzb9xs - - # Delete signup. - $ wp signup delete 3 - Success: Signup 3 deleted. - - - -### wp signup activate - -Activates one or more signups. - -~~~ -wp signup activate ... -~~~ - -**OPTIONS** - - ... - The signup ID, user login, user email, or activation key of the signup(s) to activate. - -**EXAMPLES** - - # Activate signup. - $ wp signup activate 2 - Success: Signup 2 activated. Password: bZFSGsfzb9xs - - - -### wp signup delete - -Deletes one or more signups. - -~~~ -wp signup delete ... -~~~ - -**OPTIONS** - - ... - The signup ID, user login, user email, or activation key of the signup(s) to delete. - -**EXAMPLES** - - # Delete signup. - $ wp signup delete 3 - Success: Signup 3 deleted. - - - -### wp signup get - -Gets details about a signup. - -~~~ -wp signup get [--field=] [--fields=] [--format=] -~~~ - -**OPTIONS** - - - The signup ID, user login, user email, or activation key. - - [--field=] - Instead of returning the whole signup, returns the value of a single field. - - [--fields=] - Limit the output to specific fields. Defaults to all fields. - - [--format=] - Render output in a particular format. - --- - default: table - options: - - table - - csv - - json - - yaml - --- - -**EXAMPLES** - - # Get signup. - $ wp signup get 1 --field=user_login - bobuser - - # Get signup and export to JSON file. - $ wp signup get bobuser --format=json > bobuser.json - - - -### wp signup list - -Lists signups. - -~~~ -wp signup list [--=] [--field=] [--fields=] [--format=] -~~~ - - [--=] - Filter the list by a specific field. - - [--field=] - Prints the value of a single field for each signup. - - [--fields=] - Limit the output to specific object fields. - - [--format=] - Render output in a particular format. - --- - default: table - options: - - table - - csv - - ids - - json - - count - - yaml - --- - -**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. @@ -6472,6 +6294,186 @@ wp user set-role [] +### wp user signup + +Manages signups on a multisite installation. + +~~~ +wp user signup +~~~ + +**EXAMPLES** + + # List signups. + $ wp user 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 user signup activate 2 + Success: Signup 2 activated. Password: bZFSGsfzb9xs + + # Delete signup. + $ wp user signup delete 3 + Success: Signup 3 deleted. + + + + + +### wp user signup activate + +Activates one or more signups. + +~~~ +wp user signup activate ... +~~~ + +**OPTIONS** + + ... + The signup ID, user login, user email, or activation key of the signup(s) to activate. + +**EXAMPLES** + + # Activate signup. + $ wp user signup activate 2 + Success: Signup 2 activated. Password: bZFSGsfzb9xs + + + +### wp user signup delete + +Deletes one or more signups. + +~~~ +wp user signup delete ... +~~~ + +**OPTIONS** + + ... + The signup ID, user login, user email, or activation key of the signup(s) to delete. + +**EXAMPLES** + + # Delete signup. + $ wp user signup delete 3 + Success: Signup 3 deleted. + + + +### wp user signup get + +Gets details about a signup. + +~~~ +wp user signup get [--field=] [--fields=] [--format=] +~~~ + +**OPTIONS** + + + The signup ID, user login, user email, or activation key. + + [--field=] + Instead of returning the whole signup, returns the value of a single field. + + [--fields=] + Limit the output to specific fields. Defaults to all fields. + + [--format=] + Render output in a particular format. + --- + default: table + options: + - table + - csv + - json + - yaml + --- + +**EXAMPLES** + + # Get signup. + $ wp user signup get 1 --field=user_login + bobuser + + # Get signup and export to JSON file. + $ wp user signup get bobuser --format=json > bobuser.json + + + +### wp user signup list + +Lists signups. + +~~~ +wp user signup list [--=] [--field=] [--fields=] [--format=] +~~~ + + [--=] + Filter the list by a specific field. + + [--field=] + Prints the value of a single field for each signup. + + [--fields=] + Limit the output to specific object fields. + + [--format=] + Render output in a particular format. + --- + default: table + options: + - table + - csv + - ids + - json + - count + - yaml + --- + +**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 user signup list --field=signup_id + 1 + + # List all signups. + $ wp user 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 user spam Marks one or more users as spam on multisite. diff --git a/composer.json b/composer.json index 3cbed3d51..de68918a5 100644 --- a/composer.json +++ b/composer.json @@ -121,11 +121,6 @@ "post-type", "post-type get", "post-type list", - "signup", - "signup activate", - "signup delete", - "signup get", - "signup list", "site", "site activate", "site archive", @@ -203,6 +198,11 @@ "user session destroy", "user session list", "user set-role", + "user signup", + "user signup activate", + "user signup delete", + "user signup get", + "user signup list", "user spam", "user term", "user term add", diff --git a/entity-command.php b/entity-command.php index 25caf1fba..2146f8867 100644 --- a/entity-command.php +++ b/entity-command.php @@ -102,7 +102,7 @@ } WP_CLI::add_command( - 'signup', + 'user signup', 'Signup_Command', array( 'before_invoke' => function () { diff --git a/features/signup.feature b/features/signup.feature index dbc0619c4..af8e36344 100644 --- a/features/signup.feature +++ b/features/signup.feature @@ -3,7 +3,7 @@ Feature: Manage signups in a multisite installation Scenario: Not applicable in single installation site Given a WP install - When I try `wp signup list` + When I try `wp user signup list` Then STDERR should be: """ Error: This is not a multisite installation. @@ -14,7 +14,7 @@ Feature: Manage signups in a multisite installation 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` + When I run `wp user signup list --fields=signup_id,user_login,user_email,active --format=csv` Then STDOUT should be: """ signup_id,user_login,user_email,active @@ -22,19 +22,19 @@ Feature: Manage signups in a multisite installation 2,johnuser,johnuser@example.com,0 """ - When I run `wp signup list --format=count --active=1` + When I run `wp user signup list --format=count --active=1` Then STDOUT should be: """ 0 """ - When I run `wp signup activate bobuser` + When I run `wp user signup activate bobuser` Then STDOUT should contain: """ Success: Signup 1 activated. """ - When I run `wp signup list --fields=signup_id,user_login,user_email,active --format=csv --active=1` + When I run `wp user 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 @@ -45,13 +45,13 @@ Feature: Manage signups in a multisite installation Given a WP multisite install And I run `wp eval 'wpmu_signup_user( "bobuser", "bobuser@example.com" );'` - When I run `wp signup get 1 --field=user_login` + When I run `wp user signup get 1 --field=user_login` Then STDOUT should be: """ bobuser """ - When I run `wp signup get bobuser --fields=signup_id,user_login,user_email,active --format=csv` + When I run `wp user signup get bobuser --fields=signup_id,user_login,user_email,active --format=csv` Then STDOUT should be: """ signup_id,user_login,user_email,active @@ -62,13 +62,13 @@ Feature: Manage signups in a multisite installation Given a WP multisite install And I run `wp eval 'wpmu_signup_user( "bobuser", "bobuser@example.com" );'` - When I run `wp signup get bobuser --field=active` + When I run `wp user signup get bobuser --field=active` Then STDOUT should be: """ 0 """ - When I run `wp signup activate bobuser` + When I run `wp user signup activate bobuser` Then STDOUT should contain: """ Success: Signup 1 activated. @@ -80,7 +80,7 @@ Feature: Manage signups in a multisite installation Warning: Failed activating signup 1. """ - When I run `wp signup get bobuser --field=active` + When I run `wp user signup get bobuser --field=active` Then STDOUT should be: """ 1 @@ -97,13 +97,13 @@ Feature: Manage signups in a multisite installation 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 --active=0 --format=count` + When I run `wp user signup list --active=0 --format=count` Then STDOUT should be: """ 2 """ - When I run `wp signup activate bobuser johnuser` + When I run `wp user signup activate bobuser johnuser` Then STDOUT should contain: """ Success: Signup 1 activated. @@ -113,7 +113,7 @@ Feature: Manage signups in a multisite installation Success: Signup 2 activated. """ - When I run `wp signup list --active=1 --format=count` + When I run `wp user signup list --active=1 --format=count` Then STDOUT should be: """ 2 @@ -123,14 +123,14 @@ Feature: Manage signups in a multisite installation 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` + When I run `wp user 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` + When I run `wp user signup activate bobuser` Then STDOUT should contain: """ Success: Signup 1 activated. @@ -147,26 +147,26 @@ Feature: Manage signups in a multisite installation 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 get bobuser --field=user_email` + When I run `wp user signup get bobuser --field=user_email` Then STDOUT should be: """ bobuser@example.com """ - When I run `wp signup get johnuser --field=user_email` + When I run `wp user signup get johnuser --field=user_email` Then STDOUT should be: """ johnuser@example.com """ - When I run `wp signup delete bobuser@example.com johnuser@example.com` + When I run `wp user signup delete bobuser@example.com johnuser@example.com` Then STDOUT should be: """ Success: Signup 1 deleted. Success: Signup 2 deleted. """ - When I try `wp signup get bobuser` + When I try `wp user signup get bobuser` Then STDERR should be: """ Error: Invalid signup ID, email, login, or activation key: 'bobuser' diff --git a/src/Signup_Command.php b/src/Signup_Command.php index a463a32da..42222ed26 100644 --- a/src/Signup_Command.php +++ b/src/Signup_Command.php @@ -10,7 +10,7 @@ * ## EXAMPLES * * # List signups. - * $ wp signup list + * $ wp user signup list * +-----------+------------+---------------------+---------------------+--------+------------------+ * | signup_id | user_login | user_email | registered | active | activation_key | * +-----------+------------+---------------------+---------------------+--------+------------------+ @@ -19,11 +19,11 @@ * +-----------+------------+---------------------+---------------------+--------+------------------+ * * # Activate signup. - * $ wp signup activate 2 + * $ wp user signup activate 2 * Success: Signup 2 activated. Password: bZFSGsfzb9xs * * # Delete signup. - * $ wp signup delete 3 + * $ wp user signup delete 3 * Success: Signup 3 deleted. * * @package wp-cli @@ -96,11 +96,11 @@ public function __construct() { * ## EXAMPLES * * # List signup IDs. - * $ wp signup list --field=signup_id + * $ wp user signup list --field=signup_id * 1 * * # List all signups. - * $ wp signup list + * $ wp user signup list * +-----------+------------+---------------------+---------------------+--------+------------------+ * | signup_id | user_login | user_email | registered | active | activation_key | * +-----------+------------+---------------------+---------------------+--------+------------------+ @@ -177,11 +177,11 @@ public function list_( $args, $assoc_args ) { * ## EXAMPLES * * # Get signup. - * $ wp signup get 1 --field=user_login + * $ wp user signup get 1 --field=user_login * bobuser * * # Get signup and export to JSON file. - * $ wp signup get bobuser --format=json > bobuser.json + * $ wp user signup get bobuser --format=json > bobuser.json * * @package wp-cli */ @@ -208,7 +208,7 @@ public function get( $args, $assoc_args ) { * ## EXAMPLES * * # Activate signup. - * $ wp signup activate 2 + * $ wp user signup activate 2 * Success: Signup 2 activated. Password: bZFSGsfzb9xs * * @package wp-cli @@ -238,7 +238,7 @@ public function activate( $args, $assoc_args ) { * ## EXAMPLES * * # Delete signup. - * $ wp signup delete 3 + * $ wp user signup delete 3 * Success: Signup 3 deleted. * * @package wp-cli From 32b75d40e44782d90a20a4e9bc2e6b1044444a50 Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Tue, 9 Apr 2024 16:26:13 +0545 Subject: [PATCH 09/17] Remove Signup fetcher class --- src/WP_CLI/Fetchers/Signup.php | 66 ---------------------------------- 1 file changed, 66 deletions(-) delete mode 100644 src/WP_CLI/Fetchers/Signup.php diff --git a/src/WP_CLI/Fetchers/Signup.php b/src/WP_CLI/Fetchers/Signup.php deleted file mode 100644 index 2e68e72c9..000000000 --- a/src/WP_CLI/Fetchers/Signup.php +++ /dev/null @@ -1,66 +0,0 @@ -get_signup( $signup ); - } - - /** - * Get a signup by one of its identifying attributes. - * - * @param string $arg The raw CLI argument. - * @return stdClass|false The item if found; false otherwise. - */ - protected function get_signup( $arg ) { - global $wpdb; - - $signup_object = null; - - // Fetch signup with signup_id. - if ( is_numeric( $arg ) ) { - $result = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE signup_id = %d", $arg ) ); - - if ( $result ) { - $signup_object = $result; - } - } - - if ( ! $signup_object ) { - // Try to fetch with other keys. - foreach ( array( 'user_login', 'user_email', 'activation_key' ) as $field ) { - // phpcs:ignore WordPress.DB.PreparedSQL - $result = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE $field = %s", $arg ) ); - - if ( $result ) { - $signup_object = $result; - break; - } - } - } - - if ( $signup_object ) { - return $signup_object; - } - - return false; - } -} From ef4f8dcdbb0369ab7c0dc792236cd063eae14854 Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Fri, 26 Apr 2024 14:27:07 +0545 Subject: [PATCH 10/17] Update wp-cli version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index de68918a5..4aea09387 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ } ], "require": { - "wp-cli/wp-cli": "^2.10" + "wp-cli/wp-cli": "^2.11" }, "require-dev": { "wp-cli/cache-command": "^1 || ^2", From 778ca3e305b205dfce408d552317a4d25c341d2b Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Fri, 26 Apr 2024 17:06:48 +0545 Subject: [PATCH 11/17] Revert cli version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4aea09387..de68918a5 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ } ], "require": { - "wp-cli/wp-cli": "^2.11" + "wp-cli/wp-cli": "^2.10" }, "require-dev": { "wp-cli/cache-command": "^1 || ^2", From adde1d755c5198e141053189554688b5a3b9e017 Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Fri, 26 Apr 2024 17:15:59 +0545 Subject: [PATCH 12/17] Use fetcher from main library --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index de68918a5..4aea09387 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ } ], "require": { - "wp-cli/wp-cli": "^2.10" + "wp-cli/wp-cli": "^2.11" }, "require-dev": { "wp-cli/cache-command": "^1 || ^2", From b266645365be54669f695b8ad88ed022573f4201 Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Fri, 26 Apr 2024 21:56:26 +0545 Subject: [PATCH 13/17] Use batch results helper for signup activate --- features/signup.feature | 14 +++++--------- src/Signup_Command.php | 7 +++++++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/features/signup.feature b/features/signup.feature index af8e36344..966615e02 100644 --- a/features/signup.feature +++ b/features/signup.feature @@ -31,7 +31,7 @@ Feature: Manage signups in a multisite installation When I run `wp user signup activate bobuser` Then STDOUT should contain: """ - Success: Signup 1 activated. + Success: Activated 1 of 1 signups. """ When I run `wp user signup list --fields=signup_id,user_login,user_email,active --format=csv --active=1` @@ -71,11 +71,11 @@ Feature: Manage signups in a multisite installation When I run `wp user signup activate bobuser` Then STDOUT should contain: """ - Success: Signup 1 activated. + Success: Activated 1 of 1 signups. """ When I try the previous command again - Then STDERR should be: + Then STDERR should contain: """ Warning: Failed activating signup 1. """ @@ -106,11 +106,7 @@ Feature: Manage signups in a multisite installation When I run `wp user signup activate bobuser johnuser` Then STDOUT should contain: """ - Success: Signup 1 activated. - """ - And STDOUT should contain: - """ - Success: Signup 2 activated. + Success: Activated 2 of 2 signups. """ When I run `wp user signup list --active=1 --format=count` @@ -133,7 +129,7 @@ Feature: Manage signups in a multisite installation When I run `wp user signup activate bobuser` Then STDOUT should contain: """ - Success: Signup 1 activated. + Success: Activated 1 of 1 signups. """ When I run `wp site list --fields=domain,path` diff --git a/src/Signup_Command.php b/src/Signup_Command.php index 42222ed26..b7838fde6 100644 --- a/src/Signup_Command.php +++ b/src/Signup_Command.php @@ -216,15 +216,22 @@ public function get( $args, $assoc_args ) { public function activate( $args, $assoc_args ) { $signups = $this->fetcher->get_many( $args ); + $successes = 0; + $errors = 0; + foreach ( $signups as $signup ) { $result = wpmu_activate_signup( $signup->activation_key ); if ( is_wp_error( $result ) ) { WP_CLI::warning( "Failed activating signup {$signup->signup_id}." ); + ++$errors; } else { WP_CLI::success( "Signup {$signup->signup_id} activated. Password: {$result['password']}" ); + ++$successes; } } + + Utils\report_batch_operation_results( 'signup', 'activate', count( $args ), $successes, $errors ); } /** From 0d2e74aa116d5d7c6dc7d4d355a320a6c1f3a8f3 Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Fri, 26 Apr 2024 23:59:36 +0545 Subject: [PATCH 14/17] Implement --all in signup delete command --- README.md | 17 ++++++++-- features/signup.feature | 29 +++++++++++++++-- src/Signup_Command.php | 69 ++++++++++++++++++++++++++++++++++------- 3 files changed, 98 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index b5a882ce2..fa0071844 100644 --- a/README.md +++ b/README.md @@ -1685,6 +1685,8 @@ Errors if the option already exists. Should this option be automatically loaded. --- options: + - 'on' + - 'off' - 'yes' - 'no' --- @@ -1990,6 +1992,8 @@ wp option update [] [--autoload=] [--format=] Requires WP 4.2. Should this option be automatically loaded. --- options: + - 'on' + - 'off' - 'yes' - 'no' --- @@ -2053,6 +2057,8 @@ wp option set-autoload Should this option be automatically loaded. --- options: + - 'on' + - 'off' - 'yes' - 'no' --- @@ -6316,10 +6322,12 @@ wp user signup # Activate signup. $ wp user signup activate 2 Success: Signup 2 activated. Password: bZFSGsfzb9xs + Success: Activated 1 of 1 signups. # Delete signup. $ wp user signup delete 3 Success: Signup 3 deleted. + Success: Deleted 1 of 1 signups. @@ -6343,6 +6351,7 @@ wp user signup activate ... # Activate signup. $ wp user signup activate 2 Success: Signup 2 activated. Password: bZFSGsfzb9xs + Success: Activated 1 of 1 signups. @@ -6351,19 +6360,23 @@ wp user signup activate ... Deletes one or more signups. ~~~ -wp user signup delete ... +wp user signup delete [...] [--all] ~~~ **OPTIONS** - ... + [...] The signup ID, user login, user email, or activation key of the signup(s) to delete. + [--all] + If set, all signups will be deleted. + **EXAMPLES** # Delete signup. $ wp user signup delete 3 Success: Signup 3 deleted. + Success: Deleted 1 of 1 signups. diff --git a/features/signup.feature b/features/signup.feature index 966615e02..eaa5da1bd 100644 --- a/features/signup.feature +++ b/features/signup.feature @@ -156,10 +156,9 @@ Feature: Manage signups in a multisite installation """ When I run `wp user signup delete bobuser@example.com johnuser@example.com` - Then STDOUT should be: + Then STDOUT should contain: """ - Success: Signup 1 deleted. - Success: Signup 2 deleted. + Success: Deleted 2 of 2 signups. """ When I try `wp user signup get bobuser` @@ -167,3 +166,27 @@ Feature: Manage signups in a multisite installation """ Error: Invalid signup ID, email, login, or activation key: 'bobuser' """ + + Scenario: Delete all 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 try `wp user signup delete` + Then STDERR should be: + """ + Error: You need to specify either one or more signups or provide the --all flag. + """ + + When I run `wp user signup delete --all` + Then STDOUT should contain: + """ + Success: Deleted all signups. + """ + + When I run `wp user signup list --format=count` + Then STDOUT should be: + """ + 0 + """ + diff --git a/src/Signup_Command.php b/src/Signup_Command.php index b7838fde6..89c8f0238 100644 --- a/src/Signup_Command.php +++ b/src/Signup_Command.php @@ -21,10 +21,12 @@ * # Activate signup. * $ wp user signup activate 2 * Success: Signup 2 activated. Password: bZFSGsfzb9xs + * Success: Activated 1 of 1 signups. * * # Delete signup. * $ wp user signup delete 3 * Success: Signup 3 deleted. + * Success: Deleted 1 of 1 signups. * * @package wp-cli */ @@ -210,6 +212,7 @@ public function get( $args, $assoc_args ) { * # Activate signup. * $ wp user signup activate 2 * Success: Signup 2 activated. Password: bZFSGsfzb9xs + * Success: Activated 1 of 1 signups. * * @package wp-cli */ @@ -239,41 +242,83 @@ public function activate( $args, $assoc_args ) { * * ## OPTIONS * - * ... + * [...] * : The signup ID, user login, user email, or activation key of the signup(s) to delete. * + * [--all] + * : If set, all signups will be deleted. + * * ## EXAMPLES * * # Delete signup. * $ wp user signup delete 3 * Success: Signup 3 deleted. + * Success: Deleted 1 of 1 signups. * * @package wp-cli */ public function delete( $args, $assoc_args ) { + $count = count( $args ); + + $all = Utils\get_flag_value( $assoc_args, 'all', false ); + + if ( ( 0 < $count && true === $all ) || ( 0 === $count && true !== $all ) ) { + WP_CLI::error( 'You need to specify either one or more signups or provide the --all flag.' ); + } + + if ( true === $all ) { + if ( ! $this->delete_all_signups() ) { + WP_CLI::error( 'Error deleting signups.' ); + } + + WP_CLI::success( 'Deleted all signups.' ); + WP_CLI::halt( 0 ); + } + $signups = $this->fetcher->get_many( $args ); - parent::_delete( $signups, $assoc_args, [ $this, 'delete_callback' ] ); + $successes = 0; + $errors = 0; + + foreach ( $signups as $signup ) { + if ( $this->delete_signup( $signup ) ) { + WP_CLI::success( "Signup {$signup->signup_id} deleted." ); + ++$successes; + } else { + WP_CLI::error( "Failed deleting signup {$signup->signup_id}." ); + ++$errors; + } + } + + Utils\report_batch_operation_results( 'signup', 'delete', $count, $successes, $errors ); } /** - * Callback used to delete a signup. + * Deletes signup. * - * @param $signup - * @param $assoc_args - * @return array + * @param stdClasss $signup + * @return bool True if success; otherwise false. */ - protected function delete_callback( $signup, $assoc_args ) { + private function delete_signup( $signup ) { global $wpdb; $signup_id = $signup->signup_id; $result = $wpdb->delete( $wpdb->signups, array( 'signup_id' => $signup_id ), array( '%d' ) ); - if ( $result ) { - return [ 'success', "Signup {$signup_id} deleted." ]; - } else { - return [ 'error', "Failed deleting signup {$signup_id}." ]; - } + return $result ? true : false; + } + + /** + * Deletes all signup. + * + * @return bool True if success; otherwise false. + */ + private function delete_all_signups() { + global $wpdb; + + $results = $wpdb->query( 'DELETE FROM ' . $wpdb->signups ); + + return $results ? true : false; } } From d0d5a84225e3f44a3ed52e6ced1b7ffc19c09fce Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Sat, 27 Apr 2024 14:56:24 +0545 Subject: [PATCH 15/17] Use log method instead of success --- README.md | 8 ++++---- features/signup.feature | 1 - src/Signup_Command.php | 14 +++++++------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index fa0071844..86c389101 100644 --- a/README.md +++ b/README.md @@ -6321,12 +6321,12 @@ wp user signup # Activate signup. $ wp user signup activate 2 - Success: Signup 2 activated. Password: bZFSGsfzb9xs + Signup 2 activated. Password: bZFSGsfzb9xs Success: Activated 1 of 1 signups. # Delete signup. $ wp user signup delete 3 - Success: Signup 3 deleted. + Signup 3 deleted. Success: Deleted 1 of 1 signups. @@ -6350,7 +6350,7 @@ wp user signup activate ... # Activate signup. $ wp user signup activate 2 - Success: Signup 2 activated. Password: bZFSGsfzb9xs + Signup 2 activated. Password: bZFSGsfzb9xs Success: Activated 1 of 1 signups. @@ -6375,7 +6375,7 @@ wp user signup delete [...] [--all] # Delete signup. $ wp user signup delete 3 - Success: Signup 3 deleted. + Signup 3 deleted. Success: Deleted 1 of 1 signups. diff --git a/features/signup.feature b/features/signup.feature index eaa5da1bd..73fce301c 100644 --- a/features/signup.feature +++ b/features/signup.feature @@ -189,4 +189,3 @@ Feature: Manage signups in a multisite installation """ 0 """ - diff --git a/src/Signup_Command.php b/src/Signup_Command.php index 89c8f0238..dcd1ec670 100644 --- a/src/Signup_Command.php +++ b/src/Signup_Command.php @@ -20,12 +20,12 @@ * * # Activate signup. * $ wp user signup activate 2 - * Success: Signup 2 activated. Password: bZFSGsfzb9xs + * Signup 2 activated. Password: bZFSGsfzb9xs * Success: Activated 1 of 1 signups. * * # Delete signup. * $ wp user signup delete 3 - * Success: Signup 3 deleted. + * Signup 3 deleted. * Success: Deleted 1 of 1 signups. * * @package wp-cli @@ -211,7 +211,7 @@ public function get( $args, $assoc_args ) { * * # Activate signup. * $ wp user signup activate 2 - * Success: Signup 2 activated. Password: bZFSGsfzb9xs + * Signup 2 activated. Password: bZFSGsfzb9xs * Success: Activated 1 of 1 signups. * * @package wp-cli @@ -229,7 +229,7 @@ public function activate( $args, $assoc_args ) { WP_CLI::warning( "Failed activating signup {$signup->signup_id}." ); ++$errors; } else { - WP_CLI::success( "Signup {$signup->signup_id} activated. Password: {$result['password']}" ); + WP_CLI::log( "Signup {$signup->signup_id} activated. Password: {$result['password']}" ); ++$successes; } } @@ -252,7 +252,7 @@ public function activate( $args, $assoc_args ) { * * # Delete signup. * $ wp user signup delete 3 - * Success: Signup 3 deleted. + * Signup 3 deleted. * Success: Deleted 1 of 1 signups. * * @package wp-cli @@ -282,10 +282,10 @@ public function delete( $args, $assoc_args ) { foreach ( $signups as $signup ) { if ( $this->delete_signup( $signup ) ) { - WP_CLI::success( "Signup {$signup->signup_id} deleted." ); + WP_CLI::log( "Signup {$signup->signup_id} deleted." ); ++$successes; } else { - WP_CLI::error( "Failed deleting signup {$signup->signup_id}." ); + WP_CLI::warning( "Failed deleting signup {$signup->signup_id}." ); ++$errors; } } From 5fd36573b2b9af2e2ea6344a07d580aca91bc54c Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Mon, 29 Apr 2024 11:45:41 +0545 Subject: [PATCH 16/17] Fix indenting issue in feature test file --- features/signup.feature | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/features/signup.feature b/features/signup.feature index 73fce301c..ad290f2a2 100644 --- a/features/signup.feature +++ b/features/signup.feature @@ -3,8 +3,8 @@ Feature: Manage signups in a multisite installation Scenario: Not applicable in single installation site Given a WP install - When I try `wp user signup list` - Then STDERR should be: + When I try `wp user signup list` + Then STDERR should be: """ Error: This is not a multisite installation. """ From 889336b786e0e22403ca72ba68343ffde85a8c9e Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Mon, 29 Apr 2024 12:19:42 +0545 Subject: [PATCH 17/17] Introduce --per_page argument in signup list command --- README.md | 5 ++++- features/signup.feature | 7 +++++++ src/Signup_Command.php | 12 +++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 86c389101..918c3bce2 100644 --- a/README.md +++ b/README.md @@ -6426,7 +6426,7 @@ wp user signup get [--field=] [--fields=] [--format==] [--field=] [--fields=] [--format=] +wp user signup list [--=] [--field=] [--fields=] [--format=] [--per_page=] ~~~ [--=] @@ -6451,6 +6451,9 @@ wp user signup list [--=] [--field=] [--fields=] [- - yaml --- + [--per_page=] + Limits the signups to the given number. Defaults to none. + **AVAILABLE FIELDS** These fields will be displayed by default for each signup: diff --git a/features/signup.feature b/features/signup.feature index ad290f2a2..d7c729767 100644 --- a/features/signup.feature +++ b/features/signup.feature @@ -41,6 +41,13 @@ Feature: Manage signups in a multisite installation 1,bobuser,bobuser@example.com,1 """ + When I run `wp user signup list --fields=signup_id,user_login,user_email,active --format=csv --per_page=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" );'` diff --git a/src/Signup_Command.php b/src/Signup_Command.php index dcd1ec670..21a647ac5 100644 --- a/src/Signup_Command.php +++ b/src/Signup_Command.php @@ -76,6 +76,9 @@ public function __construct() { * - yaml * --- * + * [--per_page=] + * : Limits the signups to the given number. Defaults to none. + * * ## AVAILABLE FIELDS * * These fields will be displayed by default for each signup: @@ -125,7 +128,14 @@ public function list_( $args, $assoc_args ) { $signups = array(); - $results = $wpdb->get_results( "SELECT * FROM $wpdb->signups", ARRAY_A ); + $per_page = (int) Utils\get_flag_value( $assoc_args, 'per_page' ); + + $limit = $per_page ? $wpdb->prepare( 'LIMIT %d', $per_page ) : ''; + + $query = "SELECT * FROM $wpdb->signups {$limit}"; + + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Prepared properly above. + $results = $wpdb->get_results( $query, ARRAY_A ); if ( $results ) { foreach ( $results as $item ) {