Last active
September 28, 2019 06:40
-
-
Save meetawahab/a3655632fdbbf814dbe8050b54f0096d to your computer and use it in GitHub Desktop.
Create a new admin user in WordPress through code. You just need to change the variables and drop the file in the mu-plugins directory or add the following code in active theme's functions.php, then reload the homepage in WordPress. The new user will be created. Remove the file/code after that.
This file contains 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', 'aw610_create_user' ); | |
function aw610_create_user() { | |
$username = 'admin'; | |
$password = 'password'; | |
$email_address = 'email@domain.com'; | |
if ( ! username_exists( $username ) ) { | |
$user_id = wp_create_user( $username, $password, $email_address ); | |
$user = new WP_User( $user_id ); | |
$user->set_role( 'administrator' ); | |
// To send an email to the new user. | |
wp_new_user_notification( $user_id, $password ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment