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.
Authorized emergency recovery when you have file access but no admin login: a temporary one-time URL hook, then remove the code immediately.
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.
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 = '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_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.
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.