Created
March 1, 2018 22:36
-
-
Save bacoords/ddeb0f7283ae9cbce182d8e5e6ed86c9 to your computer and use it in GitHub Desktop.
Deletes a batch (max 50) of "expired" S2 Members users
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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