Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save michaelbeil/178afaded3014bdc1bf53c72bdf571b8 to your computer and use it in GitHub Desktop.
Save michaelbeil/178afaded3014bdc1bf53c72bdf571b8 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.
<?php
/**
* Update your membership confirmation text then to include a reminder about confirming your email.
*
* This recipe assumes the PMPro Email Validation Add On is installed & actived.
*
* 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_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