Emergency WordPress admin recovery with a one-time URL hook
Authorized emergency recovery when you have file access but no admin login: a temporary one-time URL hook, then remove the code immediately. Plus how to spot
Authorized emergency recovery when you have file access but no admin login: a temporary one-time URL hook, then remove the code immediately. Plus how to spot
If you own the site (or are hired to recover it) and every administrator login is gone, but you still have FTP, SFTP, or file manager access, you can temporarily create a new admin with a secret URL, log in, then delete the code.
Do not leave this in place “for later.” Do not install it on client sites as a hidden permanent entry. Attackers look for exactly this pattern. A forgotten recovery hook is a backdoor.
Prefer the simpler flow when you can: create an admin via functions.php and remove it after one login. Use the URL hook below only when you want the account created on an explicit visit.
Use it only when all of these are true:
Do not use it when:
Typical recovery cases: a previous developer vanished with the only admin credentials, or malware deleted or locked every administrator account. If the lockout came from a hack, continue with hacked site steps after you get in.
functions.php.<?php
/**
* TEMPORARY authorized recovery hook. Delete after you log in once.
* Visit: https://example.com/?sn_recover=your-long-secret
*/
function sn_emergency_url_admin() {
if ( ! isset( $_GET['sn_recover'] ) ) {
return;
}
// Change both values before upload.
if ( 'your-long-secret' !== $_GET['sn_recover'] ) {
return;
}
$username = 'recover_admin'; // change me
$password = 'replace-with-a-long-unique-password'; // change me
$email = '[email protected]'; // 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_url_admin' );
https://yoursite.com/?sn_recover=your-long-secret./wp-login.php with the new credentials.functions.php and save.Change sn_recover, the secret string, username, password, and email before you deploy anything. Never edit WordPress core files for this.
“Indoxploit-style” usually means commodity PHP webshell / backdoor kits aimed at WordPress, not a custom APT. They typically arrive through outdated themes and plugins, weak or reused admin passwords, or poor hosting isolation. Automated bots spray known weaknesses; once inside, attackers drop PHP that restores admin access after you think you cleaned up.
What it often looks like when you are responding:
wp-content/uploads/, old theme folders, or oddly named files next to legitimate assetseval, base64_decode, remote includes) in functions.php, mu-plugins, or drop-insHow to respond:
wp-config.phpFull procedure: WordPress malware removal. Locked out with only file access? Use the temporary hook above, then clean. Do not leave any recovery code behind.
favicon.ico and friends)Attackers sometimes hide executable PHP behind familiar filenames so it blends into backups and casual file lists. Classic cues during cleanup:
favicon.ico (or similarly “normal” asset name) that is actually PHP, has a huge unexpected size, or lives outside the usual theme/media pathsuploads/ (uploads should rarely need executable PHP).htaccess that auto-prepends or rewrites requests to odd filesTreat these as detection and cleanup targets, not recipes. If anything looks wrong:
Keep access boring: unique passwords, 2FA, few administrators, and offsite backups. Recovery hooks are last-resort tools, not day-to-day workflow.
Found this useful? Share it.
Only when you own the site or have written authorization to recover it. Unauthorized access is illegal. This is an emergency recovery technique for locked-out authorized operators, not a hidden permanent entry.
No. Remove the code immediately after one successful login. A forgotten hook is a backdoor attackers search for.
Treat it as compromise. Remove the code, audit users, scan for malware, rotate credentials, and follow hacked-site cleanup steps.