Skip to content

Instantly share code, notes, and snippets.

@someguy9
Created March 17, 2020 12:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save someguy9/ce152dc8a11fbd0d90fd02427b460e4e to your computer and use it in GitHub Desktop.
Save someguy9/ce152dc8a11fbd0d90fd02427b460e4e to your computer and use it in GitHub Desktop.
Create an admin user in 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