Created
August 1, 2023 22:10
-
-
Save alexwcoleman/e8d0e4ececf5de133f60e5e4f75ebfd5 to your computer and use it in GitHub Desktop.
Add WP User via PHP
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 mu-plugins/ directory in your site’s wp-content/ directory. | |
// Create a new file in the wp-content/mu-plugins/ directory you created and name it anything you want. Something like create-admin-user.php would work nicely. | |
// Copy this code snippet and paste it into the file you just created: | |
add_action( 'init', function () { | |
$username = 'admin'; | |
$password = 'password'; | |
$email_address = '[email protected]'; | |
if ( ! username_exists( $username ) ) { | |
$user_id = wp_create_user( $username, $password, $email_address ); | |
$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