Last active
May 25, 2017 18:15
-
-
Save JudeRosario/709ce480cd60bd081149 to your computer and use it in GitHub Desktop.
Delete user on membership cancel
This file contains 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
add_action('ms_gateway_cancel_membership', 'm2_delete_user', 999, 1) ; | |
function m2_delete_user( $sub ) { | |
wp_delete_user( $sub->user_id ); | |
} |
This file contains 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
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
Code has bug in it. Above code delete all users with membership.
Please replace
if ( $member->has_membership() )
withif ( ! $member->has_membership() )
Thanks.