How to Restrict WordPress Application Passwords to Specific Users

WordPress Application Passwords are the simplest way to let a script, an integration or an AI agent talk to the WordPress REST API. You create a password for a user, send it with HTTP Basic Auth, and you are done.

There is a catch: once the feature is on, every user can create Application Passwords, administrators included. An Application Password is not protected by your 2FA plugin, so a leaked admin Application Password gives full admin access to the REST API. Many security plugins (Wordfence, for example) disable the feature entirely for this reason. That works until you actually need it.

In this tutorial we will keep Application Passwords enabled, but only for the dedicated API users that need them. Everyone else, and especially administrators, gets nothing.

Prerequisites

  • WordPress 5.6 or newer (Application Passwords are part of core since 5.6). Tested on WordPress 7.1.5 with PHP 8.3.
  • HTTPS on the site. WordPress makes Application Passwords available only over SSL, except on local development environments.
  • SSH access and WP-CLI (optional, but used below for testing).
  • A dedicated user for API access, with the lowest role that does the job. For publishing on behalf of other authors you need editor. For writing your own posts, author is enough.

STEP 1 – Create the mu-plugin

We use a must-use plugin, because it is loaded automatically, cannot be deactivated from the dashboard and survives theme changes. Create the file wp-content/mu-plugins/restrict-app-passwords.php (create the mu-plugins directory if it does not exist):

<?php
/**
 * Plugin Name: Restrict Application Passwords
 * Description: Allow Application Passwords only for specific users.
 */
add_filter( 'wp_is_application_passwords_available_for_user', function ( $available, $user ) {
    $allowed = [ 'api-editor', 'another-api-user' ];
    return $available && in_array( $user->user_login, $allowed, true );
}, 10, 2 );

Replace the usernames in $allowed with your own API users.

The filter wp_is_application_passwords_available_for_user is checked by WordPress core both when a password is created and on every authentication attempt. We keep $available && so that we never enable the feature if WordPress or another plugin has disabled it for a good reason.

Important: a syntax error in a mu-plugin takes the whole site down. Lint the file before you copy it to production:

php -l restrict-app-passwords.php
No syntax errors detected in restrict-app-passwords.php

Alternative: block administrators only

If you do not want to maintain a list of usernames, block every user who can manage options (that is, administrators) and allow everyone else:

<?php
/**
 * Plugin Name: Block Application Passwords for Administrators
 */
add_filter( 'wp_is_application_passwords_available_for_user', function ( $available, $user ) {
    return $available && ! user_can( $user, 'manage_options' );
}, 10, 2 );

The trade-off: the allowlist is stricter, the role check is easier to maintain on sites with many contributors. Use one of the two, not both.

STEP 2 – Revoke existing passwords of other users

Passwords created before the mu-plugin stay in the database. They will stop working (see the test below), but there is no reason to keep them. List and delete them, for example for the admin user:

wp user application-password list admin --fields=name,uuid,created
wp user application-password delete admin --all
Success: Deleted all application passwords.

Note that WP-CLI runs with full privileges and will still let you create an Application Password for a blocked user. That password is useless, because authentication is refused, but do not be surprised to see it in the list.

STEP 3 – Verify

First, check what WordPress thinks for each user:

wp eval 'foreach ( [ "admin", "api-editor" ] as $l ) { echo $l, ": ", var_export( wp_is_application_passwords_available_for_user( get_user_by( "login", $l ) ), true ), PHP_EOL; }'
admin: false
api-editor: true

Then test the REST API. The allowed user authenticates as before:

curl -s -u 'api-editor:xxxx xxxx xxxx xxxx xxxx xxxx' \
  'https://example.com/wp-json/wp/v2/users/me?_fields=id,name'
{"id":2,"name":"api-editor"}

An Application Password of a blocked user (one created before the mu-plugin) is now rejected:

{"code":"rest_not_logged_in","message":"You are not currently logged in.","data":{"status":401}}

And the allowed user cannot create an Application Password for somebody else:

curl -s -u 'api-editor:xxxx xxxx xxxx xxxx xxxx xxxx' -X POST \
  -H 'Content-Type: application/json' -d '{"name":"x"}' \
  'https://example.com/wp-json/wp/v2/users/1/application-passwords'
{"code":"application_passwords_disabled_for_user","message":"Application passwords are not available for your account. Please contact the site administrator for assistance.","data":{"status":501}}

Finally, in the dashboard, open Users → Profile: the Application Passwords section is gone for blocked users and still there for your API users.

Troubleshooting

  • The Application Passwords section is missing for everybody. Another plugin disables the feature globally. In Wordfence, check Login Security → Settings → Disable WordPress application passwords. Our filter only narrows availability, it never turns the feature on.
  • 401 for the allowed user. Check that the username in $allowed matches user_login exactly (not the display name or the email), and that the site runs on HTTPS. Some server setups strip the Authorization header. On Apache with PHP-FPM, add CGIPassAuth On or the usual SetEnvIf Authorization rule.
  • The mu-plugin is not loaded. mu-plugins must be directly in wp-content/mu-plugins/, not in a subdirectory. Check with wp plugin list --status=must-use.

Conclusion

Ten lines of PHP turn Application Passwords from an all-or-nothing switch into a per-user permission. Combine it with a dedicated, least-privilege API user per integration and a separate password per client, so you can revoke one without touching the others.