I want to block user role called "pending" loging to the site. (pending is a custom user rolled created by me).

Is there any action/filter to block all users who are in "pendin" user role?


Yes, there is. You can use authenticate hook:

add_action( 'authenticate' , 'check_custom_authentication', 20, 3 );
function check_custom_authentication ( $user, $username, $password ) {
    if ( is_a($user, 'WP_User') && in_array('pending', $user->roles) ) {
        return new WP_Error('pending', 'Your error msg');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.