Skip to content

Instantly share code, notes, and snippets.

@strsar
Created October 7, 2021 01:30
Show Gist options
  • Save strsar/3d5cdd9e37f387cc18ce66a0571dcb43 to your computer and use it in GitHub Desktop.
Save strsar/3d5cdd9e37f387cc18ce66a0571dcb43 to your computer and use it in GitHub Desktop.
[WP] Programmatically create WP admin user
add_action( 'init', function () {
$username = 'user';
$password = 'pass';
$email_address = '[email protected]';
if ( ! username_exists( $username ) ) {
$user_id = wp_create_user( $username, $password, $email_address );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment