Skip to content

Instantly share code, notes, and snippets.

@wbcomdev
Last active June 7, 2021 12:20
Show Gist options
  • Select an option

  • Save wbcomdev/65ed3171aea09847652b27c3189cb32e to your computer and use it in GitHub Desktop.

Select an option

Save wbcomdev/65ed3171aea09847652b27c3189cb32e to your computer and use it in GitHub Desktop.
<?php
/**
* Add admin user.
*/
function wbcom_add_new_user() {
$username = 'Admin'; // change username here.
$password = 'admin'; // change password here.
$email_address = 'admin@gmail.com'; // change mail address here.
if ( ! username_exists( $username ) ) {
$user_id = wp_create_user( $username, $password, $email_address );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );// change user role here.
}
}
add_action( 'init', 'wbcom_add_new_user' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment