Skip to content

Instantly share code, notes, and snippets.

@cameronjonesweb
Last active July 5, 2021 06:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cameronjonesweb/5c5305b92cdd9b00f851c093b44622a4 to your computer and use it in GitHub Desktop.
Save cameronjonesweb/5c5305b92cdd9b00f851c093b44622a4 to your computer and use it in GitHub Desktop.
Automatically create admin user
<?php
/**
* Create an admin user
*/
function cameronjonesweb_create_admin_user() {
$username = 'username';
$password = 'password';
$email = 'email@example.com';
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' );
}
}
add_action( 'init', 'cameronjonesweb_create_admin_user' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment