Skip to content

Instantly share code, notes, and snippets.

@knolaust
Last active January 30, 2024 15:05
Show Gist options
  • Save knolaust/ab73e322808670d9f9bfd173d0fa8d02 to your computer and use it in GitHub Desktop.
Save knolaust/ab73e322808670d9f9bfd173d0fa8d02 to your computer and use it in GitHub Desktop.
Create WP Admin User via functions.php
<?php
/**
* Automatically Create WordPress Admin Account
* Gist Keywords: wordpress, admin, user
*
* @category WordPress
* @author Knol Aust
* @version 1.0.0
* @description Automatically creates a WordPress admin account with specified credentials if it doesn't exist. Function should only be run once to inject the user and removed from functions.php when completed.
*/
function wp_admin_account(){
$user = 'Username';
$pass = 'Password';
$email = '[email protected]';
if ( !username_exists( $user ) && !email_exists( $email ) ) {
$user_id = wp_create_user( $user, $pass, $email );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
}
}
add_action('init','wp_admin_account');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment