如何创建通过API在Word preSS新用户时发送电子邮件密码? [英] How to send email password when creating a new user by API in Wordpress?
问题描述
有可能通过API来创建一个新的用户使用以下行:
It is possible to create a new user by API with the following line:
$user_id = wp_insert_user( $user_data );
我不知道如何发送新创建的用户,它包含了密码的电子邮件?有没有在Word preSS API完成这项任务的,或者我应该创建和自己发送电子邮件?任何功能
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?
推荐答案
我假设你正在生成的密码,并将其添加到 $ USER_DATA
数组?
I assume you are generating the password and adding it to the $user_data
array?
如果没有,你可以用它来生成密码 -
If not, you can use this to generate a password -
$this->password = wp_generate_password(6, false);
$user_data['user_pass'] = $this->password;
虽然有可能是挂钩到通用WP发送密码的电子邮件的方式,我只是用我自己的。这样一来,我可以自定义的内容,使它看起来像从我的网站的其他电子邮件。
And while there probably is a way of hooking in to the generic WP send password email, I just use my own. That way, I can customise the content, and make it look like other emails from my site.
请注意,我已经设置了登记类,因此,如果你没有,你将需要删除的实例 $这个 - 方式>
Note that I have set up a Class for registration, so if you have not, you will need to remove instances of $this->
.
function prepare_email(){
$confirmation_to = $_REQUEST['email_address'];
$confirmation_subject = 'Confirmation - Registration to My Site';
$confirmation_message = 'Hi '.$_REQUEST['first_name'].',<br /></br />Thank you for registering with My Site. Your account has been set up and you can log in using the following details -<br /><br />'
.'<strong>Username:</strong> '.$_REQUEST['username']
.'<br /><strong>Password:</strong> '.$this->password
.'<br /><br />Once you have logged in, please ensure that you visit the Site Admin and change you password so that you don\'t forget it in the future.';
$headers = 'MIME-Version: 1.0'."\r\n";
$headers.= 'Content-type: text/html; charset=iso-8859-1'."\r\n";
$confirmation_headers = $headers.'From: My Site <no-reply@mysite.com>'."\r\n";
$this->form_for_email = compact('confirmation_to', 'confirmation_subject', 'confirmation_message', 'confirmation_headers');
}
这篇关于如何创建通过API在Word preSS新用户时发送电子邮件密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!