How to Create Admin User Programmatically:
In this tutorial, we are going to teach you how to create a WordPress or woocommerce admin user programmatically using either the wp_create_user() or wp_insert_user() functions. In this tutorial, we will show you the difference between them and look through some examples as well.
Difference Between wp_create_user() and wp_insert_user()
These functions will only allow you to provide a username, password, and email when creating a user. A user will be created with a default role, which is set in Settings > General.
You can change these values from settings.
More than that, wp_create_user() works on the base of wp_insert_user().
It is a complete way of creating a WordPress user programmatically. You can provide other useful data, such as first and last names, a display name, a user role, and so on.
Create an admin user programmatically
In this case, we will no longer use the wp_create_user() function. Here’s the code that you can use to create a WordPress admin.
Example:
array(
'user_login' => 'qaisar',
'user_pass' => 'qaisar@123',
'role' => 'administrator',
) );
Here is the way that you can make the user a super admin:
if( is_multisite() ) {
grant_super_admin( $adminUser );
}
}