Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
[Add an Admin User with PHP] #WordPress
//Create an admin user
function smartwp_create_admin_user(){
$username = 'yourusername';
$password = '2JyAEQJ9B9Jf5T8a';
$email = '';
//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