Last active
February 23, 2022 03:39
-
-
Save agkovalev/a796efad8bb52f77baa705f791ce9f65 to your computer and use it in GitHub Desktop.
Wordpress Add Admin User
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 | |
/* | |
* Create an admin user silently | |
*/ | |
add_action('init', 'agk_add_admin_user'); | |
function agk_add_admin_user() { | |
$username = 'username123'; | |
$password = 'pasword123'; | |
$email = 'drew@example.com'; | |
if (username_exists($username) == null && email_exists($email) == false) { | |
// 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