It is possible to create a new user by API with the following line:
$user_id = wp_insert_user( $user_data );
I wonder how to send the newly created user an email that contains his password? Is there any function in Wordpress API that handles this job or should I create and send an email by myself?
Step 2: Create your WordPress welcome email Next, go to MailPoet > Emails and hit “Add New.” Choose “Welcome Email” from the available options. On the next page, you'll be asked when you want to send your welcome email and which list you want to send to. Select the options that suit your needs and click “Next.”
As David guessed (but didn't specify), there is some functionality inside Wordpress to do this: wp_new_user_notification($user_id, $user_pass)
.
So, rewriting the above code, it should look like this (code has been edited after parameter deprecation in 4.3.1):
$user_id = wp_insert_user( $user_data );
wp_new_user_notification( $user_id, null, 'both' );
Edit: Please also see @ale's comment below.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With