Last active
July 10, 2020 19:36
-
-
Save dparker1005/a6f941c516661f5e1c874d92bb1f1658 to your computer and use it in GitHub Desktop.
Prevent users from seeing their PMPro account page until they confirm their email while using the PMPro Email Confirmation Add On.
This file contains 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 | |
// Copy from below here... | |
/* | |
* Prevent users from seeing their PMPro account page until they confirm | |
* their email while using the PMPro Email Confirmation Add On. | |
* | |
* 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 the user has a membership level | |
$myuser = wp_get_current_user(); | |
$user_membership_level = pmpro_getMembershipLevelForUser($myuser->ID); | |
if(!isset($user_membership_level)){ | |
return; | |
} | |
//Check if the user is navigating to the Accounts page | |
$permalinkURL = rtrim(get_permalink(),'/')."-2/"; | |
$pmproURL = pmpro_url('account'); | |
if($permalinkURL != $pmproURL && get_permalink() != $pmproURL){ | |
return; | |
} | |
//Check if the level requires confirmation | |
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