Last active
November 23, 2022 14:13
-
-
Save kimwhite/c89b36bd08791322294e2332a42bda87 to your computer and use it in GitHub Desktop.
Stop users from logging in if they are not validated (PMPro Email Confirmation)
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 | |
/** | |
* This function will stop any user's that aren't validated from logging into your WordPress website. | |
* This requires PMPro Email Confirmation - https://www.paidmembershipspro.com/add-ons/email-confirmation-add-on/ | |
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
* Visit https://paidmembershipspro.com for further assistance. | |
*/ | |
function my_pmpro_check_login( $user, $password ) { | |
$validated = get_user_meta( $user->ID, "pmpro_email_confirmation_key", true ); | |
if( $validated != 'validated' && !empty( $validated ) ) { | |
return new WP_Error( 'user_not_verified', 'User has not validated their email' ); | |
} | |
return $user; | |
} | |
add_filter( 'wp_authenticate_user', 'my_pmpro_check_login', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was forked from a previous gist that's more up-to-date with the latest standards. See full article - https://www.paidmembershipspro.com/restrict-user-login-for-members-only/