Created
September 1, 2014 02:07
-
-
Save strangerstudios/6444cf520667ac69dbfd to your computer and use it in GitHub Desktop.
Remove user role when users cancel in Paid Memberships Pro
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
/* | |
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