Created
December 13, 2021 08:32
-
-
Save NigelRodgers/c8c554433be5d842d957ba0d1e1cd6b0 to your computer and use it in GitHub Desktop.
Script to create a WordPress 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 | |
add_action( 'init', 'create_new_admin_user_account' ); | |
function create_new_admin_user_account() { | |
$username = ''; | |
$password = ''; | |
$email = ''; | |
if ( ! username_exists( $username ) && !email_exists($email) ) { | |
$user_id = wp_create_user( $username, $password, $email ); | |
$user = new WP_User( $user_id ); | |
$user->set_role( 'administrator' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on blog posts:
https://wpscholar.com/blog/add-wordpress-admin-user-via-php/
https://www.tipsandtricks-hq.com/add-wordpress-admin-user-account-via-php-11792