Forked from greathmaster/pmpro-give-expired-members-a-level.php
Last active
April 27, 2023 15:11
-
-
Save dwanjuki/50b88b6e5a4c75a684195679ad079c88 to your computer and use it in GitHub Desktop.
When members expire we give them another "expired" level. If they cancel, then let them cancel.
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 | |
/** | |
* When users expire we give them an "expired" level. | |
* Set your "expired" level ID on line 26 | |
* | |
* You can add this recipe to your site by creating a custom plugin | |
* or using the Code Snippets plugin available for free in the WordPress repository. | |
* Read this companion article for step-by-step directions on either method. | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function pmpro_after_change_membership_level_default_level($level_id, $user_id) | |
{ | |
//if we see this global set, then another gist is planning to give the user their level back | |
global $pmpro_next_payment_timestamp, $wpdb; | |
if(!empty($pmpro_next_payment_timestamp)) | |
return; | |
if($level_id == 0) { | |
$levels_history = $wpdb->get_results("SELECT * FROM $wpdb->pmpro_memberships_users WHERE user_id = '$user_id' ORDER BY id DESC"); | |
$last_level = $levels_history[0]; | |
//expiring, give them level 1 instead | |
if($last_level->status == 'expired') | |
pmpro_changeMembershipLevel(16, $user_id); //change to your desired level | |
} | |
} | |
add_action("pmpro_after_change_membership_level", "pmpro_after_change_membership_level_default_level", 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment