Home › Forums › General Issues › Deny user login/redirect based on ACF values › Reply To: Deny user login/redirect based on ACF values
Many thanks John! For anyone looking for a similar functionality, this is what I did and it worked well.
function pm_login_redirect( $redirect_to, $request, $user ) {
$redirect_to = '/dashboard';
if ( isset( $user->roles ) && is_array( $user->roles ) ) {
//check for subscribers
if ( in_array( 'subscriber', $user->roles ) ) {
//check the user status
$userstatus = get_field('Status', $user);
if ($userstatus ==='Disabled') {
wp_logout();
wp_redirect('https://www.google.com' );
exit();
}
} else {
// redirect the other subscribers to the default place
return $redirect_to;
}
}
}
add_filter( 'login_redirect', 'pm_login_redirect', 10, 3 );
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.