Support

Account

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 );