
For whatever reason, you’ve found yourself locked out of your own site. Without a user attached to your email address, you can’t even use the Forgot Password feature to get in. But, you own the site, so surely there must be some way to get in.
Good news, there is! Better news, it’s easy!
In this post, I’ll show you how to quickly gain access to your WordPress admin area by having access to either the files or the database.
If You Have Access to the Files
This requires knowing the site’s current theme and editing the functions.php file. Simply add the following to the bottom of that file:
add_action( 'wp_loaded', function() { if( ! username_exists('myadmin') ) { $wp_userdata = array( 'user_login' => 'myadmin', 'user_pass' => 'test1234!@#$', 'role' => 'administrator', ); wp_insert_user( $wp_userdata ); } });
Once you’re in go ahead and remove this code since it will be running for every page load unnecessarily.
If You Have Access to the Database
Or, with phpMyAdmin access, you can run these SQL statements…
INSERT INTO `wp_users` (`user_login`, `user_pass`, `user_nicename`, `user_email`, `user_status`) VALUES ('myadmin', MD5('test1234!@#$'), 'myadmin', 'dev@domain.com', '0'); INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, (Select max(id) FROM wp_users), 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}'); INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, (Select max(id) FROM wp_users), 'wp_user_level', '10');
Login to Your New Admin Account
Whichever method you chose, you should now be able to login using username: myadmin and password: test1234!@#$ (at least if you used this code without changing it).
Now, time to reset your password to something more secure.

Blogger, expert WordPress developer, and developer of the awesome bbPress Voting plugin which is a must-have plugin for any bbPress forum.
Download bbPress Voting for free on the WordPress Plugin Directory.