Created
December 23, 2015 14:44
-
-
Save EvanHerman/71e2ff6be016a3530e24 to your computer and use it in GitHub Desktop.
Programatically create an admin user (WordPress)
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 | |
add_action('init', 'prefix_add_user'); | |
function prefix_add_user() { | |
$username = 'username123'; | |
$password = 'azerty321'; | |
$email = '[email protected]'; | |
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