Skip to content

Instantly share code, notes, and snippets.

@rqreyes
Created May 17, 2016 16:43
Show Gist options
  • Save rqreyes/670022f3d85b021b31102e1420c37e6d to your computer and use it in GitHub Desktop.
Save rqreyes/670022f3d85b021b31102e1420c37e6d to your computer and use it in GitHub Desktop.
create a WP admin user
<?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