Created
September 17, 2020 23:36
-
-
Save jasonrush/1105ce4e7329d0ee5f39bd8be42b223e to your computer and use it in GitHub Desktop.
Create WordPress Administrator account
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Get a list of possible prefixes */ | |
SELECT TRIM( TRAILING "usermeta" FROM TABLE_NAME) as PrefixesFound FROM information_schema.TABLES WHERE TABLE_NAME LIKE "%usermeta%"; | |
/* | |
This will autodetect the first table prefix. | |
NOTE: ONLY USE IF THERE IS ONLY ONE PREFIX FOUND | |
*/ | |
SET @TablePrefix = (SELECT TRIM( TRAILING "usermeta" FROM TABLE_NAME) as PrefixesFound FROM information_schema.TABLES WHERE TABLE_NAME LIKE "%usermeta%" LIMIT 1); | |
SELECT @TablePrefix; | |
/* Otherwise manually set the prefix */ | |
SET @TablePrefix = 'wp_'; | |
/* Additional configuration settings */ | |
SET @NewUsername = 'jrush'; | |
SET @NewName = 'Jason Rush'; | |
SET @NewEmail = '[email protected]'; | |
SET @NewPassword = 'T3mporary!'; | |
/* End configuration */ | |
SET @UsersTable = CONCAT(@TablePrefix, "users"); | |
SET @UsermetaTable = CONCAT(@TablePrefix, "usermeta"); | |
/* Verify if the user already exists */ | |
SELECT * FROM @UsersTable WHERE username = @NewUsername; | |
/* Create the user account */ | |
INSERT INTO @UsersTable (`user_login`, `user_pass`, `user_nicename`, `user_email`, | |
`user_status`) | |
VALUES (@NewUsername, MD5(@NewPassword), @NewName, @NewEmail, '0'); | |
/* Set the "administrator" capability */ | |
INSERT INTO @UsermetaTable (`umeta_id`, `user_id`, `meta_key`, `meta_value`) | |
VALUES (NULL, (SELECT id FROM @UsersTable WHERE username = @NewUsername), | |
CONCAT( @TablePrefix, 'capabilities'), 'a:1:{s:13:"administrator";s:1:"1";}'); | |
/* And set the user level to 10 (aka admin) */ | |
INSERT INTO @UsermetaTable (`umeta_id`, `user_id`, `meta_key`, `meta_value`) | |
VALUES (NULL, (SELECT id FROM @UsersTable WHERE username = @NewUsername), CONCAT( @TablePrefix, 'wp_user_level'), '10'); | |
/* Display the info for the user */ | |
SELECT id,`user_login`,`user_email` FROM @UsersTable WHERE username = @NewUsername; | |
/* Display the metadata for the user */ | |
SELECT * FROM @UsermetaTable WHERE `user_id` = (SELECT id FROM @UsersTable WHERE username = @NewUsername); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment