Created
December 13, 2020 00:07
-
-
Save MrJoshFisher/bfe394c828fa18323cc2ba38de97e593 to your computer and use it in GitHub Desktop.
[Add an Admin User with PHP] #WordPress
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 | |
function smartwp_create_admin_user(){ | |
$username = 'yourusername'; | |
$password = '2JyAEQJ9B9Jf5T8a'; | |
$email = 'change@me.com'; | |
//This will ensure it only tries to create the user once (based on email/username) | |
if ( !username_exists( $username ) && !email_exists( $email ) ) { | |
$userid = wp_create_user( $username, $password, $email ); | |
$user = new WP_User( $userid ); | |
$user->set_role( 'administrator' ); | |
} | |
} | |
add_action('init', 'smartwp_create_admin_user'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment