Skip to content

Instantly share code, notes, and snippets.

@micc83
Created July 2, 2013 14:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micc83/5909638 to your computer and use it in GitHub Desktop.
Save micc83/5909638 to your computer and use it in GitHub Desktop.
Create a new admin user in WordPress
<?php
// 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 = 'user';
$newpassword = 'pass';
$newemail = 'email@email.email';
if ( !username_exists( $newusername ) && !email_exists( $newemail ) ) {
$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.';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment