Created
August 3, 2017 15:01
-
-
Save hostedpixel/b8fee97550c65de36606c141e2dd1f62 to your computer and use it in GitHub Desktop.
WordPress Create new admin
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
/* | |
* Create an admin user silently | |
*/ | |
add_action('init', 'add_user'); | |
function add_user() { | |
$username = 'username123'; | |
$password = 'pasword123'; | |
$email = '[email protected]'; | |
// Create the new user | |
$user_id = wp_create_user( $username, $password, $email ); | |
// Get current user object | |
$user = get_user_by( 'id', $user_id ); | |
// Remove role | |
$user->remove_role( 'subscriber' ); | |
// Add role | |
$user->add_role( 'administrator' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment