landbryo
7/19/2019 - 4:01 PM

Create New User

Function to create a new user without dashboard access.

add_action( 'init', function () {
  
  $username = 'admin';
	$password = 'password';
	$email_address = 'administrator@domain.com';
	$role = 'administrator';
	
	if ( ! username_exists( $username ) ) {
		$user_id = wp_create_user( $username, $password, $email_address );
		$user = new WP_User( $user_id );
		$user->set_role( $role );
	}
	
} );