Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Deletes a batch (max 50) of "expired" S2 Members users
<?php
/**
* Deletes a batch (max 50) of S2 Members users
* @return int number of users deleted
*/
public function delete_batch_of_expired_users(){
$max_users = 50;
$args = array(
'role' => 'subscriber',
'number' => $max_users,
'date_query' => array(
array(
'before' => '-6 months',
'inclusive' => true,
),
),
);
$user_query = new WP_User_Query($args);
$count = 0;
if ( ! empty( $user_query->get_results() ) ) {
foreach ( $user_query->get_results() as $user ) {
if( s2member_last_login_time($user->ID) <= strtotime('-6 months') ){
if( wp_delete_user( $user->ID ) ){
$count++;
}
}
}
}
return $count;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.