Skip to content

Commit 889336b

Browse files
committed
Introduce --per_page argument in signup list command
1 parent 5fd3657 commit 889336b

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6426,7 +6426,7 @@ wp user signup get <signup> [--field=<field>] [--fields=<fields>] [--format=<for
64266426
Lists signups.
64276427

64286428
~~~
6429-
wp user signup list [--<field>=<value>] [--field=<field>] [--fields=<fields>] [--format=<format>]
6429+
wp user signup list [--<field>=<value>] [--field=<field>] [--fields=<fields>] [--format=<format>] [--per_page=<per_page>]
64306430
~~~
64316431

64326432
[--<field>=<value>]
@@ -6451,6 +6451,9 @@ wp user signup list [--<field>=<value>] [--field=<field>] [--fields=<fields>] [-
64516451
- yaml
64526452
---
64536453

6454+
[--per_page=<per_page>]
6455+
Limits the signups to the given number. Defaults to none.
6456+
64546457
**AVAILABLE FIELDS**
64556458

64566459
These fields will be displayed by default for each signup:

features/signup.feature

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ Feature: Manage signups in a multisite installation
4141
1,bobuser,[email protected],1
4242
"""
4343

44+
When I run `wp user signup list --fields=signup_id,user_login,user_email,active --format=csv --per_page=1`
45+
Then STDOUT should be:
46+
"""
47+
signup_id,user_login,user_email,active
48+
1,bobuser,[email protected],1
49+
"""
50+
4451
Scenario: Get signup
4552
Given a WP multisite install
4653
And I run `wp eval 'wpmu_signup_user( "bobuser", "[email protected]" );'`

src/Signup_Command.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public function __construct() {
7676
* - yaml
7777
* ---
7878
*
79+
* [--per_page=<per_page>]
80+
* : Limits the signups to the given number. Defaults to none.
81+
*
7982
* ## AVAILABLE FIELDS
8083
*
8184
* These fields will be displayed by default for each signup:
@@ -125,7 +128,14 @@ public function list_( $args, $assoc_args ) {
125128

126129
$signups = array();
127130

128-
$results = $wpdb->get_results( "SELECT * FROM $wpdb->signups", ARRAY_A );
131+
$per_page = (int) Utils\get_flag_value( $assoc_args, 'per_page' );
132+
133+
$limit = $per_page ? $wpdb->prepare( 'LIMIT %d', $per_page ) : '';
134+
135+
$query = "SELECT * FROM $wpdb->signups {$limit}";
136+
137+
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Prepared properly above.
138+
$results = $wpdb->get_results( $query, ARRAY_A );
129139

130140
if ( $results ) {
131141
foreach ( $results as $item ) {

0 commit comments

Comments
 (0)