Skip to content

Instantly share code, notes, and snippets.

@EvanHerman
Created December 23, 2015 14:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EvanHerman/71e2ff6be016a3530e24 to your computer and use it in GitHub Desktop.
Save EvanHerman/71e2ff6be016a3530e24 to your computer and use it in GitHub Desktop.
Programatically create an admin user (WordPress)
<?php
add_action('init', 'prefix_add_user');
function prefix_add_user() {
$username = 'username123';
$password = 'azerty321';
$email = 'example@example.com';
if (username_exists($username) == null && email_exists($email) == false) {
$user_id = wp_create_user( $username, $password, $email );
$user = get_user_by( 'id', $user_id );
$user->remove_role( 'subscriber' );
$user->add_role( 'administrator' );
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment