One Lock, One Key: Why a WordPress Login Breaks From a Single Wrong Return
The Problem A developer adds a custom check to the authenticate filter — say, blocking login for users with an unverified email. The simplest approach: return false if…

Filter Hook since 2.8.0
The core WordPress login/authentication filter
authenticate is the chain that decides whether login credentials are valid — every auth method, from core's own password check to SSO plugins, hooks into this same filter.
Called from wp_authenticate() (used by wp-login.php and wp_signon()) — runs through a priority chain of default core checks (username/password, cookie, application passwords).
apply_filters( 'authenticate', WP_User|WP_Error|null $user, string $username, string $password );$user WP_User|WP_Error|null — Current authentication result so far.$username string — Submitted username.$password string — Submitted password.add_filter( 'authenticate', function( $user, $username ) {
if ( 'blocked_user' === $username ) {
return new WP_Error( 'blocked', 'This account is disabled.' );
}
return $user;
}, 30, 3 );Block a specific username from logging in regardless of password.
add_filter( 'authenticate', function( $user ) {
if ( $user instanceof WP_User && ! get_user_meta( $user->ID, '2fa_verified', true ) ) {
return new WP_Error( '2fa_required', 'Two-factor verification required.' );
}
return $user;
}, 40, 1 );Add an extra gate after core's own check already resolved a valid WP_User, before login completes.
The Problem A developer adds a custom check to the authenticate filter — say, blocking login for users with an unverified email. The simplest approach: return false if…
Return a WP_Error object. Returning null lets WordPress continue checking other registered authenticate callbacks instead of stopping the login outright.
Source: wp-includes/user.php
One session: this hook, then each related_hooks entry. Walk it and tell us what to change.
authenticate → wp_login → wp_logout
Practice the authenticate WordPress filter hook in our interactive sandbox — a VS Code-style editor with a step-by-step authenticate tutorial, add_filter exercises, and instant feedback. No local WordPress install required.