Skip to content

Instantly share code, notes, and snippets.

@rxnlabs
Last active May 21, 2020 14:55
Show Gist options
  • Save rxnlabs/567284862c536228e64e to your computer and use it in GitHub Desktop.
Save rxnlabs/567284862c536228e64e to your computer and use it in GitHub Desktop.
WP - WordPress add new admin user to MySQL table using raw SQL queries. Use in case you don't have access to WordPress dashboard since you may not be a user yet.
# MariaDB is throwing an error when attempting to use variables. You will have to hardcode the database tables
SET @username = 'YOUR_USER_NAME';
SET @password = 'YOUR_PASSWORD';
SET @nicename = 'YOUR_NICENAME';
SET @email_address = 'YOUR_EMAIL_ADDRESS';
SET @fullname = 'YOUR_FULL_NAME';
SET @wpdb_prefix = 'wp_';
SET @wpdb_users_table = CONCAT(@wpdb_prefix,'', 'users');
SET @wpdb_usermeta_table = CONCAT(@wpdb_prefix,'', 'usermeta');
INSERT INTO @wpdb_users_table (`user_login`, `user_pass`, `user_nicename`, `user_email`, `user_url`, `user_registered`, `user_activation_key`, `user_status`, `display_name`) VALUES (@username, MD5(@password), @nicename, @email_address, '', NOW(), '', '0', @fullname);
SET @user_id = LAST_INSERT_ID();
INSERT INTO @wpdb_usermeta_table (`user_id`, `meta_key`, `meta_value`) VALUES (@user_id, 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');
INSERT INTO @wpdb_usermeta_table (`user_id`, `meta_key`, `meta_value`) VALUES (@user_id, 'wp_user_level', '10');
INSERT INTO @wpdb_usermeta_table (`user_id`, `meta_key`, `meta_value`) VALUES (@user_id, 'rich_editing', 'true');
INSERT INTO @wpdb_usermeta_table (`user_id`, `meta_key`, `meta_value`) VALUES (@user_id, 'show_admin_bar_front', 'true');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment