Created
July 24, 2018 10:34
-
-
Save andrewlimaza/c34c596f1705803e941a32269ba6ceaa to your computer and use it in GitHub Desktop.
Stop non-approved users from logging in.
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 is an example to stop non-approved user's from logging in using the Approvals Add On For Paid Memberships Pro. | |
* Add this code below to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function my_pmpro_stop_users_logging_in( $user, $password ) { | |
$user_id = $user->ID; | |
if( !empty( $user_id ) ) { | |
$level = pmpro_getMembershipLevelForUser( $user_id ); | |
// Get approval status | |
if( class_exists( 'PMPro_Approvals') ) { | |
$approval = PMPro_Approvals::getUserApproval( $user_id ); | |
// User currently does not need approval. | |
if ( empty( $approval ) ) { | |
return $user; | |
} | |
$approval_status = $approval['status']; | |
if ( ! empty( $approval_status ) && $approval_status != 'approved' ) { | |
$access = false; | |
} else { | |
$access = true; | |
} | |
} | |
} | |
if ( ! $access ) { | |
return; | |
} | |
return $user; | |
} | |
add_filter( 'wp_authenticate_user', 'my_pmpro_stop_users_logging_in', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello there, thanks a lot, how it is possible to add a custom error message? thanks