Skip to content

Instantly share code, notes, and snippets.

@JudeRosario
Last active May 25, 2017 18:15
Show Gist options
  • Save JudeRosario/709ce480cd60bd081149 to your computer and use it in GitHub Desktop.
Save JudeRosario/709ce480cd60bd081149 to your computer and use it in GitHub Desktop.
Delete user on membership cancel
add_action('ms_gateway_cancel_membership', 'm2_delete_user', 999, 1) ;
function m2_delete_user( $sub ) {
wp_delete_user( $sub->user_id );
}
function corn_activation() {
if ( !wp_next_scheduled( 'daily_membership_check' ) ) {
wp_schedule_event( current_time( 'timestamp' ), 'daily', 'daily_membership_check');
}
}
add_action('wp', 'corn_activation');
add_action('daily_membership_check', 'do_this_daily');
function do_this_daily() {
$blogusers = get_users( array( 'role' => 'subscriber' ) );
// Array of WP_User objects.
foreach ( $blogusers as $user ) {
$member = MS_Factory::load( 'MS_Model_Member', $user->ID );
if ( $member->has_membership() )
wp_delete_user( $user->ID ) ;
}
}
@musamamasood
Copy link

Code has bug in it. Above code delete all users with membership.

Please replace if ( $member->has_membership() ) with if ( ! $member->has_membership() )

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment