Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save strangerstudios/2c1bab3cdb9fb16ec34f22741faf947c to your computer and use it in GitHub Desktop.
Save strangerstudios/2c1bab3cdb9fb16ec34f22741faf947c to your computer and use it in GitHub Desktop.
Hide the PMPro Account page until a user confirms their email address via the PMPro Email Confirmation addon.
/*
Add this function to a custom plugin.
Update your membership confirmation text then to include a reminder about confirming your email.
*/
function pmpro_hide_account_page_until_validated() {
//bail if pmpro or the email confirmation addon is not loaded
if(!function_exists('pmpro_getMembershipLevelForUser') || !function_exists('pmproec_isEmailConfirmationLevel'))
return;
//check if we're on the account page
global $pmpro_pages;
if(!is_page($pmpro_pages['account']))
return;
//get user and level
$myuser = wp_get_current_user();
$user_membership_level = pmpro_getMembershipLevelForUser($myuser->ID);
if(pmproec_isEmailConfirmationLevel($user_membership_level->id)) {
//if they still have a validation key, they haven't clicked on the validation link yet
$validation_key = get_user_meta($myuser->ID, "pmpro_email_confirmation_key", true);
if(!empty($validation_key) && $validation_key != "validated") {
wp_redirect(pmpro_url('confirmation', 'level=' . $user_membership_level->id));
exit;
}
}
}
add_filter('template_redirect', 'pmpro_hide_account_page_until_validated');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment