Skip to content

Instantly share code, notes, and snippets.

@greathmaster
Created September 21, 2017 02:35
Show Gist options
  • Save greathmaster/fa983baf74cc0b728835329e6d3f9f1b to your computer and use it in GitHub Desktop.
Save greathmaster/fa983baf74cc0b728835329e6d3f9f1b 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.
/*
When users expire we give them another "expired" level.
When users cancel, just give them level = 0, ie same as a normal WP user.
*/
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(1, $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