This class CreateUser  is use to create user programmatically.

File need to include:

Following file contain the class, you can include in your theme or plugin or application to use of class.

classes/class-create-user.php

Example file:

Following file is contain example code of usages of class.

functions/functions-create-user.php

Code sample:

$args = array(
    'username'    => 'demo_post', // Optional
    'password' 	  => '', // Optional
    'email'       => 'hasan@gmail50.com', // Required
    'user_meta' => array(
        'nickname'=>'Dummy nickname',
        'first_name'=>'My first_name',
        'last_name'=>'My last_name',
        'description'=>'My description',
        'wp_user_level'=> 3,
    ),
);

$CreateUser = new CreateUser();
$userId = $CreateUser->create_user($args);

var_dump($userId);

 

Arguments:

Argument Type Example
username String Any String for Username, If empty it will auto generate from email username
password String  Any string for password, if empty it will auto generated.
email String  (Required)Any string for email.
user_meta Array  Array of meta field key and value, value can be string, integer or array.