Skip to content

Instantly share code, notes, and snippets.

@fovoc
Forked from wpscholar/create-admin-user.php
Last active October 20, 2017 14:12
Show Gist options
  • Save fovoc/149846e367511aa914c60d9479b24e05 to your computer and use it in GitHub Desktop.
Save fovoc/149846e367511aa914c60d9479b24e05 to your computer and use it in GitHub Desktop.
Create a new admin user in WordPress via code. Drop this file in the mu-plugins directory and update the variables, then load a page in WordPress to create the user. Remove the file when done.
<?php
add_action( 'init', function () {
$username = 'admin';
$password = 'password';
$email_address = 'webmaster@mydomain.com';
if ( ! username_exists( $username ) ) {
$user_id = wp_create_user( $username, $password, $email_address );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
grant_super_admin( $user_id );
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment