Created
April 27, 2020 22:13
-
-
Save taricco/684ce6c11175fc976791f16b0ebd8f0a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // ADD NEW ADMIN USER TO WORDPRESS | |
| // ---------------------------------- | |
| // Put this file in your Wordpress root directory and run it from your browser. | |
| // Delete it when you're done. | |
| require_once 'wp-blog-header.php'; | |
| require_once 'wp-includes/registration.php'; | |
| // CONFIG | |
| $newusername = 'your_username'; | |
| $newpassword = 'your_password'; | |
| $newemail = 'your_email'; | |
| // Make sure you set CONFIG variables | |
| if ($newpassword != 'your_password' && $newemail != 'your_email' && $newusername != 'your_username') { | |
| // Check that user doesn't already exist | |
| if (!username_exists($newusername) && !email_exists($newemail)) { | |
| // Create user and set role to administrator | |
| $user_id = wp_create_user($newusername, $newpassword, $newemail); | |
| if (is_int($user_id)) { | |
| $wp_user_object = new WP_User($user_id); | |
| $wp_user_object->set_role('administrator'); | |
| echo 'Successfully created new admin user. Now delete this file!'; | |
| } else { | |
| echo 'Error with wp_insert_user. No users were created.'; | |
| } | |
| } else { | |
| echo 'This user or email already exists. Nothing was done.'; | |
| } | |
| } else { | |
| echo "Whoops, looks like you didn't set a password, username, or email before running the script. Set these variables and try again."; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment