Create a WordPress admin user via FTP when you are locked out
Recover a locked WordPress site by temporarily adding a known-safe admin account through FTP or file manager, then remove the code immediately.
Topics Backups & recovery Login & access
Security advisorywp2shell: WordPress core vulnerability. Updated August 4, 2026.
Read the advisoryRecover a locked WordPress site by temporarily adding a known-safe admin account through FTP or file manager, then remove the code immediately.
Topics Backups & recovery Login & access
Locked out of wp-admin but you still have FTP, SFTP, or hosting file manager access? You can temporarily bootstrap a new administrator from the active theme’s functions.php, log in, then delete the code.
This is emergency recovery for a site you own or are authorized to fix. It is not a permanent “backdoor.”
Related: login security, hacked site recovery.
wp-content/themes/ for the one in use, or look in the database option template / stylesheet if you can).admin.If you would rather not edit PHP, some hosts and tools offer emergency login resets. The steps below work on almost any install with file access.
wp-content/themes/your-active-theme/.functions.php first.functions.php and paste the following at the end of the file:<?php
/**
* TEMPORARY emergency admin. Remove this entire block after you log in.
*/
function sn_emergency_create_admin() {
$username = 'recover_admin'; // change me
$password = 'replace-with-a-long-unique-password'; // change me
$email = 'you@example.com'; // change me
if ( username_exists( $username ) || email_exists( $email ) ) {
return;
}
$user_id = wp_create_user( $username, $password, $email );
if ( is_wp_error( $user_id ) ) {
return;
}
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
}
add_action( 'init', 'sn_emergency_create_admin' );
init runs./wp-login.php with the new credentials.functions.php immediately and save again.Leaving this code in place recreates or re-checks the account on every request. That is a security problem, not a feature.
Losing access to one admin account does not delete that user’s posts. Content stays in the database. Create a recovery admin, then fix or reassign the original account.
For a different emergency pattern (one-time URL trigger), see emergency access recovery. Prefer removing any recovery code the moment you regain control.
Found this useful? Share it.