Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send email password when creating a new user by API in Wordpress?

Tags:

wordpress

api

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?

like image 618
Mert Nuhoglu Avatar asked Nov 22 '12 09:11

Mert Nuhoglu


People also ask

How do I create a welcome email in WordPress?

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.”


1 Answers

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.

like image 151
Christian Avatar answered Oct 11 '22 09:10

Christian