Skip to content

Instantly share code, notes, and snippets.

@JarrydLong
Created June 14, 2024 06:21
Show Gist options
  • Save JarrydLong/198550c880c1cbb123fb046e111148ad to your computer and use it in GitHub Desktop.
Save JarrydLong/198550c880c1cbb123fb046e111148ad to your computer and use it in GitHub Desktop.
<?php //do not copy
/**
* This recipe can either be run by adding /wp-admin/?cleanup=1 to your URL
* Or add the mypmpro_cleanup_spam_users function as a callback to a cron using WP Crontrol
*
* USE AT YOUR OWN RISK - Bulk deleting user data is irreversible and can result in active memberships
* and subscriptions being cancelled.
*
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function mypmpro_cleanup_spam_users(){
// Get the 'abandoned-signup' term.
$abandoned_signup_term = get_term_by( 'slug', 'abandoned-signup', 'pmpro_abandoned_signup' );
if ( empty( $abandoned_signup_term ) ) {
return;
}
// Get all users with the 'abandoned-signup' term.
$abandoned_signup_users = get_objects_in_term( $abandoned_signup_term->term_id, 'pmpro_abandoned_signup' );
$limit = 500;
if( ! empty( $abandoned_signup_users ) ){
$abandoned_signup_users = array_slice( $abandoned_signup_users, 0, $limit );
foreach( $abandoned_signup_users as $user_id ){
if( ! pmpro_hasMembershipLevel( null, $user_id ) ) {
//They don't have a membership level so we can delete them.
wp_delete_user( $user_id );
}
}
}
}
if( isset( $_GET['cleanup'] ) && $_GET['cleanup'] == '1' ){
add_action( 'admin_init', 'mypmpro_cleanup_spam_users' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment