XHanch Studio Log in | Register | Cart

Forum

[How to] Create Wor...
 
Notifications
Clear all

[How to] Create WordPress user account programmatically

1 Posts
1 Users
0 Likes
15.7 K Views
XHanch
(@xhanch-alt)
Posts: 2105
Member Admin
Topic starter
 

You can easily create a WordPress account programmatically by utilizing WordPress wp_create_user function.

The wp_create_user function allows you to insert a new user into the WordPress database by parsing 3 (three) parameters through to the function itself. It uses the $wpdb class to escape the variable values, preparing it for insertion into the database.

See the following PHP codes to learn how to use it.

$user_id = username_exists($user_name);
if (!$user_id) {
    //Generate a random password
    $random_password = wp_generate_password(12, false);
    //Create the account
    $user_id = wp_create_user($user_name, $random_password, $user_email);
}else{
    //Username already exists
    //Do or display something
}
 
Posted : 17/04/2011 12:57 am
Share:

× Close Menu