Created
May 17, 2016 16:43
-
-
Save rqreyes/670022f3d85b021b31102e1420c37e6d to your computer and use it in GitHub Desktop.
create a WP admin user
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 | |
// Create Admin User | |
$wp_password = 'PASSWORD'; #enter your desired password here, if you don't line 16 makes sure nothing bad happens like setting you actual password to 'PASSWORD' | |
$wp_username = 'USERNAME'; | |
$wp_email = 'EMAIL'; | |
if ( $wp_password === 'PASSWORD' ) | |
die; | |
require_once('wp-blog-header.php'); | |
if ( !username_exists($wp_username) && !email_exists($wp_email) ) { | |
$user_id = wp_create_user( $wp_username, $wp_password, $wp_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