October 7, 2015

Creating a WordPress user when you don’t have an existing admin login

Tech TalkComments are off for this post.

You Are Here:Creating a WordPress user when you don’t have an existing admin login

A long time ago I found a post on how to insert yourself into WordPress as an admin that has been very popular.

Just to be clear, this won’t help you hack a WordPress site. You have to have some kind of server level access to make use of any of these, but in our work we often have scenarios where we only have access to a server.

There are 3 quick ways to create a WordPress user from outside the WordPress dashboard.

Creating a WordPress user with WP CLI USER CREATE

My new favorite way is using WP CLI.  These require that WP CLI is installed on the server, but recently WP Engine started rolling out WP-CLI Support to Select Partners for Beta Testing.  It’s not just a WP Engine thing though, a few other hosts provide WP CLI support via shell access and if you’re running on your own server you can install it.  You’re not likely to be able to install this yourself on shared hosting.
Assuming you have access to WP CLI it’s as easy as SSH’ing into your server, or using the WP Engine portal, and typing

wp create user name unique@email.com --role=administrator

You can specific a password with –user_pass=”Password!” or let it create a random password for you!



Create a WordPress user via MySQL

If you don’t have SSH access and WP CLI already installed the next quickest way is to insert a user via MySQL. Most hosts include PHPMyAdmin so you can just jump into there, select the database you want to insert a user in, paste this code into the SQL page, edit the values and click Go.

SET @user_login := 'justin_foell';
SET @user_pass := 'Q9xiHgzZ';
SET @user_email := 'justin@9seeds.com';
INSERT INTO `wp_users` 
(`user_login`, `user_pass`, `user_email`, `user_registered`) 
(@user_login, MD5(@user_pass), @user_email, now());
SELECT @user_id := LAST_INSERT_ID();
INSERT INTO `wp_usermeta` 
(`user_id`, `meta_key`, `meta_value`) 
(@user_id, 'wp_capabilities', 'a:1:{s:13:"administrator";b:1;}');
INSERT INTO `wp_usermeta` 
(`user_id`, `meta_key`, `meta_value`) 
(@user_id, 'wp_user_level', '10');



Create a WordPress user via FTP

This used to be my favorite way because often all I had was FTP access, but these days I use the first two a lot more often.  Still it’s easy, especially if running running MySQL commands scares you.

Here you simple FTP to root directory of the site you need access to and create a new empty PHP file.  Often I just “duplicate” an existing file and clear it out, that’s fine too.

Open of the file and insert this code, then change the user/pass/email values and finally visit the file in web browser.  You should delete the file after it runs, or at least give it very unique name.

Thats it!  3 ways to create a WordPress user when you don’t have dashboard access.

About the author: