admin管理员组文章数量:1426216
currently using this plugin / and there is a section where if you want to send a user an email when he/she registers (using wordpress as a headless CMS)
add_action('wp_rest_user_user_register', 'user_registered');
function user_registered($user) {
// Do Something
}
already set up WP Mail SMTP plugin so it overrides the wp_mail function
the question is: how can I get the email of the registered user to send him/her an email using the wp_mail function ?
currently using this plugin https://wordpress/plugins/wp-rest-user/ and there is a section where if you want to send a user an email when he/she registers (using wordpress as a headless CMS)
add_action('wp_rest_user_user_register', 'user_registered');
function user_registered($user) {
// Do Something
}
already set up WP Mail SMTP plugin so it overrides the wp_mail function
the question is: how can I get the email of the registered user to send him/her an email using the wp_mail function ?
Share Improve this question asked May 22, 2019 at 16:09 technolaajitechnolaaji 1034 bronze badges 2 |1 Answer
Reset to default 0You don't know the type of content that might be passed for the $user
parameter, so let's test it out.
You will want to expand on these conditions and responses. This is just an example of the tests you probably want to make.
function user_registered( $user ) {
// Check to make sure it's not an error.
if ( is_wp_error( $user ) ) {
return;
}
// This is how WordPress checks to make sure the user exists.
// This could also apply to many other objects, though.
if ( ! isset( $user->ID ) ) {
return;
}
// This checks to make sure you're getting the expected user object fields.
if ( ! isset( $user->user_email ) ) {
// If you have a correct ID, you can still retrieve the user's fields.
$user = get_user_by( 'ID', $user->ID );
// If the user doesn't exist, stop where you are.
if ( ! $user ) {
return false;
}
}
$headers = array(
'Content-Type: text/html; charset=UTF-8',
'From: WordPress Website <[email protected]>',
);
wp_mail( $user->user_email, 'Subject of email', 'Email body', $headers );
}
本文标签: pluginsSend email when a user registers Rest api
版权声明:本文标题:plugins - Send email when a user registers Rest api 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745469467a2659684.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
$user
is you're getting passed? If it is an object of theWP_User
class, it should be trivial to get their mail address. – kero Commented May 22, 2019 at 16:11