Inserting yourself as admin into WordPress
Posted on February 28, 2013
On quite a few occasions I’ve had clients send me a complete backup of their site during the discovery period. Usually this is because they don’t have a Release Candidate / Quality Assurance / Staging / Development version(s) of their site where changes can be made, and approved, without affecting the live site.
Without standing on my soapbox too long – if your website lacks a staging site, version control for custom code, or backups – you should address them immediately.
In this case, I was glad the client had at least one backup (the one that was provided to me) which I could turn into a local WordPress installation to begin development. Since the client didn’t provide a WordPress Admin user and password, I just decided to insert myself into WordPress.
Use this script to insert a WordPress Admin user, using phpMyAdmin, the MySQL command line interface, MySQL Workbench, or whatever SQL tool you normally use:
SET @user_login := 'justin_foell';
SET @user_pass := 'Q9xiHgzZ';
SET @user_email := '[email protected]';
INSERT INTO `wp_users`
(`user_login`, `user_pass`, `user_email`, `user_registered`)
VALUES
(@user_login, MD5(@user_pass), @user_email, now());
SELECT @user_id := LAST_INSERT_ID();
INSERT INTO `wp_usermeta`
(`user_id`, `meta_key`, `meta_value`)
VALUES
(@user_id, 'wp_capabilities', 'a:1:{s:13:"administrator";b:1;}');
INSERT INTO `wp_usermeta`
(`user_id`, `meta_key`, `meta_value`)
VALUES
(@user_id, 'wp_user_level', '10');
Replace the set values at the top for @user_login, @user_pass and @user_email with your own settings. Also, if your WordPress installation uses tables that start with a prefix other than ‘wp_’, you’ll want to replace that in the table names as well.
I wish I knew more!!!
Cool! I didn't realize you could use SET up top to set all those values. I've been using Dash and CodeBox to manage snippets which does tag based insertion, but way easier and cleaner the way you've got it. FYI, I've also had trouble with users created this way no being able to use the VisualEditor. I tracked it down to the rich_editor flag not being set so I added another INSERT
Note: That's untested and adapted from my significantly different snippet/syntax but I think it all correct.JB, you can omit the `umeta_id` and NULL value for that column in your statement. MySQL will fill it with an auto-increment value of its own. An excellent addition!
Also, if you want to add yourself as a Super Admin to a network site, you can do the following, but be careful! From phpMyAdmin select the following value:
Make sure the option "Full Texts" is on in your phpMyAdmin results page. Then in a PHP script or command line, add yourself to the site_admins array - replacing my example serialized data an username with your own: Update the site_admins value in the sitemeta table with the new value, 'a:2:{i:0;s:5:"admin";i:1;s:12:"justin_foell";}' in my particular case.