Skip to content

Commit

Permalink
Set any pending users to pending
Browse files Browse the repository at this point in the history
  • Loading branch information
obenland committed Oct 27, 2024
1 parent ec713bf commit c3110f1
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,40 @@ function wpau_upgrade_to_12() {
)
);
// phpcs:enable WordPress.DB

wpau_set_users_pending();
}

/**
* Set 100 users to pending per cron run.
*
* @param int $processed Number of users processed.
*/
function wpau_set_users_pending( $processed = 0 ) {
$users = get_users(
array(
'fields' => 'ID',
'number' => 100,
'offset' => $processed,
'meta_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
array(
'key' => 'wp-approve-user',
'compare' => 'NOT EXISTS',
),
),
)
);
$users = array_diff( $users, array( get_user_by( 'email', get_bloginfo( 'admin_email' ) )->ID ) );

foreach ( $users as $user_id ) {
update_user_meta( $user_id, 'wp-approve-user', 'pending' );
}

$processed += count( $users );
$count = count_users();

if ( $processed < $count['total_users'] ) {
wp_schedule_single_event( time() + 5, 'wpau_pending_users_cron', array( $processed ) );
}
}
add_action( 'wpau_pending_users_cron', 'wpau_set_users_pending' );

0 comments on commit c3110f1

Please sign in to comment.