Create a WordPress Admin with Code

A few times I’ve gotten into a situation where I have access to WordPress files (via SFTP or other means) but I’m otherwise locked out of the site (my user hasn’t been created or was accidentally deleted). In those cases, the quickest option is generally just to create a new admin user with code.

If I know which theme is active, I’ll generally just drop this code into the bottom of functions.php for that theme, refresh the site once or twice in the browser, and then delete the code (important: make sure to delete it!)

https://gist.github.com/wpscholar/86c236469f3610400f8a

If you don’t know which theme is active, you can also create a new directory called “mu-plugins” inside wp-content, and paste this code into a file called create-admin-user.php as WP Scholar recommends.

About Devin

I am a developer based in Austin, Texas. I run a little theme shop called DevPress and help manage a WooCommerce shop with Universal Yums. Find me on twitter @devinsays.

Leave a Reply