Skip to content

Commit 688c459

Browse files
committed
Apply signup metadata filters before per_page pagination
1 parent 0aa207b commit 688c459

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

features/signup.feature

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,19 @@ Feature: Manage signups in a multisite installation
246246
228
247247
"""
248248

249+
Scenario: Filter signups by metadata with per_page pagination
250+
Given a WP multisite install
251+
And I run `wp eval "wpmu_signup_user( 'plainuser', 'plainuser@example.com' );"`
252+
And I run `wp eval "wpmu_signup_user( 'adminuser', 'adminuser@example.com', array( 'add_to_blog' => 228, 'new_role' => 'administrator' ) );"`
253+
And I run `wp eval "wpmu_signup_user( 'editoruser', 'editoruser@example.com', array( 'add_to_blog' => 228, 'new_role' => 'editor' ) );"`
254+
And I run `wp eval "wpmu_signup_user( 'otherbloguser', 'otherbloguser@example.com', array( 'add_to_blog' => 300, 'new_role' => 'administrator' ) );"`
255+
256+
When I run `wp user signup list --blog_id=228 --per_page=2 --fields=user_login,blog_id --format=csv`
257+
Then STDOUT should be:
258+
"""
259+
user_login,blog_id
260+
adminuser,228
261+
editoruser,228
262+
"""
263+
264+

src/Signup_Command.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,19 +138,19 @@ public function list_( $args, $assoc_args ) {
138138
*/
139139
$per_page = Utils\get_flag_value( $assoc_args, 'per_page' );
140140

141-
$limit = $per_page ? $wpdb->prepare( 'LIMIT %d', (int) $per_page ) : '';
141+
$filter_args = array_diff_key(
142+
$assoc_args,
143+
array_flip( array( 'fields', 'field', 'format', 'per_page' ) )
144+
);
145+
146+
$limit = ( $per_page && empty( $filter_args ) ) ? $wpdb->prepare( 'LIMIT %d', (int) $per_page ) : '';
142147

143148
$query = "SELECT * FROM $wpdb->signups {$limit}";
144149

145150
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Prepared properly above.
146151
$results = $wpdb->get_results( $query, ARRAY_A );
147152

148153
if ( $results ) {
149-
$filter_args = array_diff_key(
150-
$assoc_args,
151-
array_flip( array( 'fields', 'field', 'format', 'per_page' ) )
152-
);
153-
154154
foreach ( $results as $item ) {
155155
$item = $this->prepare_signup_array( $item );
156156

@@ -167,6 +167,10 @@ public function list_( $args, $assoc_args ) {
167167
}
168168
}
169169

170+
if ( $per_page ) {
171+
$signups = array_slice( $signups, 0, (int) $per_page );
172+
}
173+
170174
$format = Utils\get_flag_value( $assoc_args, 'format', 'table' );
171175

172176
$formatter = $this->get_formatter( $assoc_args );

0 commit comments

Comments
 (0)