Created
November 13, 2018 17:55
-
-
Save junaidtk/2ec588cca4a488ee48f83295bc362ea1 to your computer and use it in GitHub Desktop.
How to add new admin user through the code snipppets
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
We can add new admin user by using below code. it will be helpfull if we forget the admin details of the website. | |
add_action('init', 'add_new_admin_user'); | |
function add_new_admin_user() { | |
$username = 'testuser'; | |
$email = '[email protected]'; | |
$password = 'password'; | |
$user_id = username_exists( $username ); | |
if ( !$user_id && email_exists($email) == false ) { | |
$user_id = wp_create_user( $username, $password, $email ); | |
if( !is_wp_error($user_id) ) { | |
$user = get_user_by( 'id', $user_id ); | |
$user->set_role( 'administrator' ); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment