Skip to content

Commit f71bfa0

Browse files
Member Export outputs duplicates when using pmpro_set_max_user_per_export_loop filter
* Ensure the filter doesn't lead to a fatal error by ensuring the returned value is valid or set the default * Fix array_slice start and end params to calculations.
1 parent c51eb7c commit f71bfa0

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

adminpages/memberslist-csv.php

+9-10
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@
3030
* @since 1.8.7
3131
*/
3232
//set the number of users we'll load to try and protect ourselves from OOM errors
33-
$max_users_per_loop = apply_filters('pmpro_set_max_user_per_export_loop', 2000);
33+
$max_users_per_loop = intval( apply_filters( 'pmpro_set_max_user_per_export_loop', 2000 ) );
3434

35+
//If the filter returns odd value, reset to default.
36+
if ( $max_users_per_loop < 1 ) {
37+
$max_users_per_loop = 2000;
38+
}
3539
global $wpdb;
3640

3741
//get users (search input field)
@@ -309,16 +313,11 @@
309313

310314
$start = current_time('timestamp');
311315

312-
// Get the last record to output, will depend on which iteration we're on.
313-
if ( $ic != $iterations ) {
314-
$i_end = ($i_start + ( $max_users_per_loop - 1));
315-
} else {
316-
// Final iteration, so last UID is the last record in the users array
317-
$i_end = ($users_found - 1);
318-
}
319-
$spl = array_slice($theusers, $i_start, $i_end + 1);
316+
$i_end = min( $i_start + $max_users_per_loop - 1, $users_found - 1 );
317+
318+
$spl = array_slice( $theusers, $i_start, $i_end - $i_start + 1 );
320319
//increment starting position
321-
$i_start += $max_users_per_loop;
320+
$i_start = $i_end + 1;
322321

323322
//escape the % for LIKE comparison with $wpdb
324323
if(!empty($search))

0 commit comments

Comments
 (0)