I have custom login form and i used wp_signon() to authenticate. However, i wanted to run an additional check for usermeta and if the user has account_status === pending, throw an error or or prevent them from getting logged in. How do i do that? I can't seem to find a filter

  • @Rup Thanks for the heads up, i missed the title when i was typing it. As i was saying, i plan to intercept any login authentication. I wanted to run a usermeta check to see if their account_status is pending or active. If it's active then continue to log them in and if not, throw an error and prevent them from logging in. Yes this is a custom login form and i used wp_signon() as mentioned above.
    – CruzZ
    Commented Feb 1, 2023 at 10:14

1 Answer 1


You could do this with a low-priority authenticate filter. I'm surprised there aren't more appropriate hooks in the login process, but I can't see one. (There is already an example of a filter like this though: wp_authenticate_spam_check.)

If the value the filter is given is a user, that means a previous filter has accepted the username & password. We can then perform our check and then either return the user if good or an error if not:

function authenticate_reject_account_status_pending( $user, $username, $password ) {
    if ( $user instanceof WP_User ) {
        if ( $user[ 'account_status' ] === 'pending' ) {
            return new WP_Error( 'user_is_pending',
                __( 'Account is pending approval. Please contact support for help.' )

    return $user;
add_filter( 'authenticate', 'authenticate_reject_account_status_pending', 999999, 3 );

I have not tested this, but the general pattern should work even if this code doesn't. This runs before the cookie is created etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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