Created
April 13, 2020 18:59
-
-
Save digisavvy/d98bb5a966a44fd07cca4a8edcff46dd 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
| <?php | |
| /** | |
| * Script to create administrator user in WordPress | |
| * | |
| * @package none | |
| * @link https://9seeds.com/creating-a-wordpress-user-when-you-dont-have-an-existing-admin-login-to-use/ | |
| */ | |
| $dgs_password = 'fGNAj8ZDirz'; | |
| $dgs_username = 'digisavvy'; | |
| $dgs_email = 'accounts@digisavvy.com'; | |
| if ( 'PASSWORD' === $dgs_password ) { | |
| die; | |
| } | |
| require_once 'wp-blog-header.php'; | |
| if ( ! username_exists( $dgs_username ) && ! email_exists( $dgs_email ) ) { | |
| $user_id = wp_create_user( $dgs_username, $dgs_password, $dgs_email ); | |
| if ( is_int( $user_id ) ) { | |
| $wp_user_object = new WP_User( $user_id ); | |
| $wp_user_object->set_role( 'administrator' ); | |
| echo 'Success!'; | |
| } else { | |
| echo 'Error with wp_insert_user. No users were created.'; | |
| } | |
| } else { | |
| echo 'This user or email already exists. Nothing was done.'; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment