Skip to content

Instantly share code, notes, and snippets.

@agkovalev
Last active February 23, 2022 03:39
Show Gist options
  • Save agkovalev/a796efad8bb52f77baa705f791ce9f65 to your computer and use it in GitHub Desktop.
Save agkovalev/a796efad8bb52f77baa705f791ce9f65 to your computer and use it in GitHub Desktop.
Wordpress Add Admin User
<?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