Skip to content

Instantly share code, notes, and snippets.

@labsecrets
Forked from strangerstudios/gist:2185226
Created July 7, 2012 04:21
Show Gist options
  • Save labsecrets/3064591 to your computer and use it in GitHub Desktop.
Save labsecrets/3064591 to your computer and use it in GitHub Desktop.
Delete the WordPress User When a Paid Memberships Pro Member Cancels His Account
/*
Requires PMPro v1.4+
Code to delete WP user accounts when a member cancels their PMPro account.
Users are not deleted if:
(1) They are not cancelling their membership (i.e. $level_id != 0)
(2) They are an admin.
(3) The level change was initiated from the WP Admin Dashboard
(e.g. when an admin changes a user's level via the edit user's page)
*/
function my_pmpro_after_change_membership_level($level_id, $user_id)
{
//are they cancelling? and don't do this from admin (e.g. when admin's are changing levels)
if(empty($level_id) && !is_admin())
{
//only delete non-admins
if(!user_can($user_id, "manage_options"))
{
require_once(ABSPATH . "/wp-admin/includes/user.php");
wp_delete_user($user_id);
}
}
}
add_action("pmpro_after_change_membership_level", "my_pmpro_after_change_membership_level", 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment