Skip to content

Instantly share code, notes, and snippets.

@NigelRodgers
Created December 13, 2021 08:32
Show Gist options
  • Save NigelRodgers/c8c554433be5d842d957ba0d1e1cd6b0 to your computer and use it in GitHub Desktop.
Save NigelRodgers/c8c554433be5d842d957ba0d1e1cd6b0 to your computer and use it in GitHub Desktop.
Script to create a WordPress Admin User
<?php
add_action( 'init', 'create_new_admin_user_account' );
function create_new_admin_user_account() {
$username = '';
$password = '';
$email = '';
if ( ! username_exists( $username ) && !email_exists($email) ) {
$user_id = wp_create_user( $username, $password, $email );
$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