Created
March 17, 2020 12:35
-
-
Save someguy9/ce152dc8a11fbd0d90fd02427b460e4e to your computer and use it in GitHub Desktop.
Create an admin user in 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