Skip to content

Instantly share code, notes, and snippets.

@cinghaman
Created March 16, 2021 12:13
Show Gist options
  • Save cinghaman/856ffd44065e1348ee3487e5a1b2f21e to your computer and use it in GitHub Desktop.
Save cinghaman/856ffd44065e1348ee3487e5a1b2f21e to your computer and use it in GitHub Desktop.
WordPress Add Admin Through PHP
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