WordPress Admin User Audit: Find Hidden Administrators With WP-CLI and SQL, Check Application Passwords and Sessions, and Set a Least-Privilege Role Plan

By Information Security Asia · Updated November 30, 2026 · 6 min read

WordPress Admin User Audit: Find Hidden Administrators With WP-CLI and SQL, Check Application Passwords and Sessions, and Set a Least-Privilege Role Plan

Short answer: To audit WordPress admin users, list administrators from the command line with wp user list --role=administrator and compare the result with the Users screen, because malware can hide accounts from the dashboard. Then query the database directly for every user whose capabilities include administrator, which catches accounts that WP-CLI and the dashboard might both miss if a plugin is filtering queries. For each admin, confirm the person, their email and when they were created; review and revoke application passwords and active sessions; and check custom roles that may carry admin-level capabilities. Finally, downgrade anyone who doesn’t need full control to Editor or a narrower role, and record the result so the next audit takes ten minutes.

Why admin accounts deserve a regular audit

An administrator in WordPress can install plugins, edit theme files and create other users. That makes admin accounts the most valuable foothold on a site. Attackers who get in through a vulnerable plugin very often create an extra administrator so they can return after the original hole is patched. Separately, ordinary sites accumulate admins over time: former developers, agencies, temporary contractors and staff who left. Each forgotten account with a weak or reused password is a risk. A quarterly audit, plus one immediately after any suspected compromise, keeps this under control.

WordPress Admin User Audit: Find Hidden Administrators With WP-CLI and SQL, Check Application Passwords and Sessions, and Set a Least-Privilege Role Plan

Step 1: list administrators three ways

Start with the dashboard: Users > All Users, filtered by Administrator. Note the count shown next to Administrator at the top. Then list them with WP-CLI from the site root:

wp user list --role=administrator --fields=ID,user_login,user_email,user_registered,display_name
wp user list --format=count --role=administrator

Finally, query the database directly. Replace the wp_ prefix if your site uses a different one:

wp db query "SELECT u.ID, u.user_login, u.user_email, u.user_registered FROM wp_users u JOIN wp_usermeta m ON m.user_id = u.ID WHERE m.meta_key = 'wp_capabilities' AND m.meta_value LIKE '%administrator%';"

All three lists should match. If the database shows an admin the dashboard doesn’t, something is filtering the user list, which is a classic malware technique. Search plugins, mu-plugins and the theme’s functions.php for code using hooks such as pre_user_query or views_users that excludes a particular user, and remove both the code and the hidden account.

On multisite networks, also run wp super-admin list, because super admins control the whole network and are stored separately.

Step 2: check each administrator

Check Why it matters How
Is this a real, current person? Orphaned accounts are easy targets Confirm with the team or client
Email domain and address Attackers use throwaway or lookalike addresses Look for misspellings and free mail on business sites
Registration date New admins near a suspected incident are suspect user_registered field
Generic usernames Names like admin, support or wpadmin attract attacks Rename by creating a new account and deleting the old
Two-factor authentication Stops password-only takeovers Your 2FA plugin’s user list
Last login Unused accounts can usually go Security or activity log plugin, if installed

When deleting a user, WordPress asks what to do with their content. Attribute it to an existing user so posts aren’t lost. With WP-CLI, wp user delete 123 --reassign=1 does the same.

Step 3: review application passwords

Application passwords, introduced in WordPress 5.6, let apps and scripts authenticate to the REST API without the user’s main password. They’re useful, but they also make a quiet backdoor: an attacker who creates one can keep API access even after the account’s password changes. Check each admin:

wp user application-password list 1 --fields=uuid,name,created,last_used,last_ip

Revoke any you don’t recognize with wp user application-password delete 1 <uuid>, or from the user’s profile page in the dashboard. If your site doesn’t use application passwords at all, you can disable the feature with the wp_is_application_passwords_available filter.

Step 4: end active sessions

Changing a password doesn’t automatically log out every existing session in all cases, and stolen session cookies can keep an attacker signed in. List and destroy sessions:

WordPress Admin User Audit: Find Hidden Administrators With WP-CLI and SQL, Check Application Passwords and Sessions, and Set a Least-Privilege Role Plan
wp user session list 1
wp user session destroy 1 --all

After a confirmed compromise, rotating the authentication keys and salts in wp-config.php logs out everyone at once; see our guide to WordPress salts and security keys for when that’s the right move.

Step 5: inspect roles and capabilities

An account doesn’t need the Administrator role to be dangerous. A custom role, or an Editor role modified by a plugin, can carry capabilities such as install_plugins, edit_plugins, edit_users or promote_users. List roles and look for powerful capabilities outside the Administrator role:

wp role list
wp cap list editor
wp cap list shop_manager

Also check the site’s default role for new users, which should normally be Subscriber, and whether open registration is turned on:

wp option get default_role
wp option get users_can_register

A default role of administrator is almost never intentional and is a strong sign of compromise.

Step 6: apply least privilege

Most people who log in to WordPress don’t need to be administrators. Writers need Author or Contributor; content managers need Editor; store staff on WooCommerce usually need Shop Manager. Keep administrator for one or two people who handle plugins, updates and users, and make sure each of them uses a unique password and two-factor authentication. Our guide to WordPress two-factor authentication covers enforcing it for admins. Developers who need occasional access can get a temporary admin account that you delete when the job is done, rather than a permanent one.

Step 7: record the audit and set a schedule

Keep a short record: the list of admins, who approved each, and the date. Next quarter, compare against it; anything new needs an explanation. If you found a hidden admin or an unknown application password, treat the site as compromised and work through our WordPress malware removal checklist, since the account was probably created through another backdoor that still exists. For quick signs of compromise beyond users, see our guide to where attackers hide backdoors.

Frequently asked questions

How many administrators should a WordPress site have?

As few as practical, typically one or two. Everyone else should have the lowest role that lets them do their job.

Can a hidden admin account exist without showing in the Users screen?

Yes. Malicious code can filter the user list so an account doesn’t appear. Querying the database directly is the reliable check.

Does deleting a malicious admin account fix the hack?

No. The account is a symptom. Find and remove the code or vulnerability used to create it, or the attacker will add another.

Should I rename the admin username?

WordPress doesn’t let you change usernames in the dashboard. Create a new administrator with a non-obvious name, log in with it, then delete the old account and reassign its content.

Sources

Keep reading