Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ionatan-israel/eb84e5794666402d6dfcb6759b899d6d to your computer and use it in GitHub Desktop.
Save ionatan-israel/eb84e5794666402d6dfcb6759b899d6d 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 ) ;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment