Last active
February 19, 2019 23:24
-
-
Save andrewlimaza/1e363602b6d67a942f420010575c96c8 to your computer and use it in GitHub Desktop.
Assign a new WP user role when a user cancels their membership in Paid Memberships Pro
This file contains hidden or 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
| <?php | |
| //Please copy line 5-22 into your active themes functions.php or custom plugin | |
| //code to assign specific WP user role when cancelling | |
| function my_pmpro_after_cancel_change_role($level_id, $user_id) | |
| { | |
| //get user object | |
| $wp_user_object = new WP_User($user_id); | |
| //ignore admins | |
| if(in_array("administrator", $wp_user_object->roles)){ | |
| return; | |
| } | |
| //if user cancels their membership, set their user role. | |
| if(empty($level_id)) { | |
| $wp_user_object->set_role('subscriber'); //choose your default role. | |
| } | |
| } | |
| add_action("pmpro_after_change_membership_level", "my_pmpro_after_cancel_change_role", 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment