Skip to content

Instantly share code, notes, and snippets.

@waqashassan98
Created December 7, 2018 09:48
Show Gist options
  • Save waqashassan98/1335e73aa10fd8ec5a06c70efb804f05 to your computer and use it in GitHub Desktop.
Save waqashassan98/1335e73aa10fd8ec5a06c70efb804f05 to your computer and use it in GitHub Desktop.
Create a wordpress admin user from functions.php
function wpb_admin_account(){
$user = 'admin_user';
$pass = 'admin_pass';
$email = 'youemail@xyz.com';
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','wpb_admin_account');
@waqashassan98
Copy link
Author

Make sure to remove the code from functions.php after the user has been created

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment