100% Free · Open Source GPLv2 · Zero setup requiredGet the Plugin

Opens in a new tab
ITX UserOps

Back to Blog

Disabling a WordPress user is not one hook

WordPress has four authentication channels, not one. Three converge on a single filter — but only if you hook late enough — and the fourth bypasses it entirely.

Engineering

Diagram: three authentication channels converge on a single barrier while a fourth passes straight through it.

There is no disabled flag in WordPress. Core has no concept of a suspended account. A user exists or they are deleted, and deletion takes their content with it unless you reassign first. Everything in between — every “disable user” plugin, every snippet in a Stack Overflow answer — is bolted on top of the authentication stack.

That matters because WordPress does not have one front door. It has several, and they do not all behave the same way.

The channels

A WordPress account can authenticate through at least four routes:

  • The login form at wp-login.php — the one everybody thinks of.
  • XML-RPC at xmlrpc.php — still enabled by default, still accepts username and password on every call.
  • The REST API, authenticated with application passwords over HTTP basic auth. Core has shipped these since 5.6.
  • An existing session cookie — someone who logged in an hour ago and never closed the tab.
The ITX UserOps user dashboard with a row menu open, listing View profile, Edit in WordPress, Disable account, Log out everywhere, Send password reset and Delete. The table behind shows accounts with Active and Disabled status badges.
“Disable account” and “Delete…” are separate operations, and keeping them separate is the whole point — one revokes access in a second, the other destroys the work and forces an irreversible decision about the content.

A disable feature that only covers the first one is not a disable feature. It is a speed bump on the most visible path while three others stay open.

The good news: three of them converge

The first three all funnel through the same filter. WordPress resolves credentials into a user object through authenticate, and that applies whether the credentials arrived from a login form, an XML-RPC call, or an application password on a REST request.

So a single well-placed filter closes three doors at once:

add_filter( 'authenticate', function ( $user ) {
    if ( ! $user instanceof WP_User ) {
        return $user;
    }

    if ( is_account_disabled( $user->ID ) ) {
        return new WP_Error( 'account_disabled', 'This account has been disabled.' );
    }

    return $user;
}, 30 );

That looks unremarkable. The interesting part is the 30.

The priority trap

authenticate does not hand you a user. It hands you whatever the previous callback returned, and early in the chain that is null.

Core attaches wp_authenticate_username_password at priority 20. It also attaches wp_authenticate_application_password at priority 20. Those are the callbacks that turn a username and password into a WP_User object.

Hook at the default priority of 10 and your callback runs before core has resolved anything. You get null, your instanceof check fails, you return early, and the login proceeds. The code looks correct. It reviews fine. It does nothing.

This is a genuinely easy mistake, and it fails silently — there is no error, no warning, just an account you believe is disabled that can still log in. If you have written this filter yourself, the priority is the first thing to check.

The fourth door does not use that filter at all

Here is the part that catches people out.

authenticate runs when credentials are exchanged for a session. It does not run on subsequent requests. Once someone holds a valid auth cookie, WordPress validates that cookie against the session token store — and never consults your filter again.

So a user who was logged in before you disabled them stays logged in. They keep their admin access, keep their REST access, keep publishing. Your filter is working perfectly and is simply never invoked.

This is exactly backwards from what you need. The moment you most want an account gone — a compromised login, a contractor who just left badly — is precisely the moment they already have a live session.

The fix is not another filter. Disabling has to destroy the account’s sessions as an action, not just refuse future ones:

$sessions = WP_Session_Tokens::get_instance( $user_id );
$sessions->destroy_all();

Without that call, “disabled” means “disabled from the next login onwards”, which for an attacker already inside is no protection at all.

Application passwords deserve a second lock

Application passwords are the channel most likely to be forgotten, because they are invisible in normal use. They live under the user’s profile, they are often created for an integration and never looked at again, and they keep working long after the human has stopped logging in.

They do route through authenticate, so a correctly prioritised filter catches them. But it is worth adding a second, independent guard:

add_filter( 'wp_is_application_passwords_available_for_user', function ( $available, $user ) {
    if ( $available && $user instanceof WP_User && is_account_disabled( $user->ID ) ) {
        return false;
    }

    return $available;
}, 10, 2 );

Belt and braces. If some other plugin rearranges the authentication stack in a way that skips your filter, this still holds. Security controls on separate mechanisms fail independently, which is the entire point of having two.

Test it yourself

Do not take anyone’s word for this, including ours. Whatever you currently use to disable accounts, check it in about two minutes.

  • Create a throwaway account and give it an application password.
  • Log in as that account in a private browser window and leave the tab open.
  • Disable the account from your admin.
  • Reload the private window. Are they still logged in?
  • Then run the application password against the REST API.
curl -u 'someuser:xxxx xxxx xxxx xxxx xxxx xxxx' 
  https://example.com/wp-json/wp/v2/users/me

A properly disabled account returns a 401. If you get back a JSON user object, that account is not disabled in any meaningful sense — it just cannot use the login form.

Why not just delete them?

Because deletion is the wrong tool for almost every real situation.

Deleting a user forces an immediate decision about their content, and that decision is irreversible. Reassign to the wrong account and authorship is wrong forever. Delete without reassigning and you lose posts. Neither is a thing you want to be doing at speed during an incident.

Disabling separates the two questions that deletion forces together: should this person have access? and what happens to their work? The first is urgent and needs answering in seconds. The second is an editorial decision that can wait until Monday.

It also keeps the audit trail intact. A deleted user is a hole in your history; a disabled one still has a name attached to every action they took.

Two rails worth enforcing

Whatever implements this, two conditions should be impossible rather than merely discouraged: you should not be able to disable your own account, and you should not be able to disable the last remaining administrator.

Both are one misclick away from locking every human out of the site, and both have to be enforced server-side. A disabled button in the UI is not a safety rail — the REST route behind it is still there.

How ITX UserOps handles it

All of the above, as one action. Disabling an account blocks the login form, XML-RPC, the REST API and application passwords, destroys every live session immediately, and leaves posts, comments and history untouched. The lockout message is editable, and both safety rails are enforced in the REST layer rather than the interface.

It is free and GPL. The documentation covers the behaviour in detail, and the source is on GitHub if you would rather read the implementation than trust the description — which, given the subject, is a reasonable preference.

A clearer WordPress admin
starts here.

Start with the free plugin. Add more control when you need it.

Log in

Vote on ideas, submit your own and join the discussion.