Skip to content

Instantly share code, notes, and snippets.

@MrJoshFisher
Created December 13, 2020 00:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MrJoshFisher/bfe394c828fa18323cc2ba38de97e593 to your computer and use it in GitHub Desktop.
Save MrJoshFisher/bfe394c828fa18323cc2ba38de97e593 to your computer and use it in GitHub Desktop.
[Add an Admin User with PHP] #WordPress
<?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