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:

$adminUser = wp_insert_user(
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_wp_error( $adminUser ) ) {
   if( is_multisite() ) {
     grant_super_admin( $adminUser );
    }
}

Qaisar Satti

Hi, I'm Qaisar Satti! I've been a developer for over 20 years, and now I love sharing what I've learned through tutorials and guides. Whether you're working with Magento, PrestaShop, or WooCommerce, my goal is to make your development journey a bit easier and more fun. When I'm not coding or writing, you can find me exploring new tech trends and hanging out with the amazing developer community. Thanks for stopping by, and happy coding!