Skip to content

Instantly share code, notes, and snippets.

@bacoords
Created March 1, 2018 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bacoords/ddeb0f7283ae9cbce182d8e5e6ed86c9 to your computer and use it in GitHub Desktop.
Save bacoords/ddeb0f7283ae9cbce182d8e5e6ed86c9 to your computer and use it in GitHub Desktop.
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