Skip to content

Commit

Permalink
Introduce --per_page argument in signup list command
Browse files Browse the repository at this point in the history
  • Loading branch information
ernilambar committed Apr 29, 2024
1 parent 5fd3657 commit 889336b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6426,7 +6426,7 @@ wp user signup get <signup> [--field=<field>] [--fields=<fields>] [--format=<for
Lists signups.

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

[--<field>=<value>]
Expand All @@ -6451,6 +6451,9 @@ wp user signup list [--<field>=<value>] [--field=<field>] [--fields=<fields>] [-
- yaml
---

[--per_page=<per_page>]
Limits the signups to the given number. Defaults to none.

**AVAILABLE FIELDS**

These fields will be displayed by default for each signup:
Expand Down
7 changes: 7 additions & 0 deletions features/signup.feature
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ Feature: Manage signups in a multisite installation
1,bobuser,[email protected],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,[email protected],1
"""

Scenario: Get signup
Given a WP multisite install
And I run `wp eval 'wpmu_signup_user( "bobuser", "[email protected]" );'`
Expand Down
12 changes: 11 additions & 1 deletion src/Signup_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ public function __construct() {
* - yaml
* ---
*
* [--per_page=<per_page>]
* : Limits the signups to the given number. Defaults to none.
*
* ## AVAILABLE FIELDS
*
* These fields will be displayed by default for each signup:
Expand Down Expand Up @@ -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 ) {
Expand Down

0 comments on commit 889336b

Please sign in to comment.