Created
March 16, 2021 12:13
-
-
Save cinghaman/856ffd44065e1348ee3487e5a1b2f21e to your computer and use it in GitHub Desktop.
WordPress Add Admin Through PHP
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
function wp_add_admin() { | |
$user = 'some_user_name'; | |
$pass = 'some_pass_word'; // password in plain text | |
$email = 'email_id'; | |
if ( ! username_exists( $user ) && ! email_exists( $email ) ) { | |
$user_id = wp_create_user( $user, $pass, $email ); | |
$user = new WP_User( $user_id ); | |
$user->set_role( 'administrator' ); | |
} | |
} | |
add_action( 'init', 'wp_add_admin' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment