Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save strangerstudios/6444cf520667ac69dbfd to your computer and use it in GitHub Desktop.
Save strangerstudios/6444cf520667ac69dbfd to your computer and use it in GitHub Desktop.
Remove user role when users cancel in Paid Memberships Pro
/*
Remove user role when users cancel.
*/
function my_pmpro_after_change_membership_level($level_id, $user_id)
{
if(empty($level_id))
{
//If they are a subscriber, remove their role.
$wp_user_object = new WP_User($user_id);
if(in_array("subscriber", $wp_user_object->roles))
$wp_user_object->set_role('');
}
else
{
//If they have no role, make them a subscriber.
$wp_user_object = new WP_User($user_id);
if(empty($wp_user_object->roles))
$wp_user_object->set_role('subscriber');
}
}
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