Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Created July 24, 2018 10:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save andrewlimaza/c34c596f1705803e941a32269ba6ceaa to your computer and use it in GitHub Desktop.
Save andrewlimaza/c34c596f1705803e941a32269ba6ceaa to your computer and use it in GitHub Desktop.
Stop non-approved users from logging in.
<?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 );
@gdeguglielmo
Copy link

Hello there, thanks a lot, how it is possible to add a custom error message? thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment