WordPress 用户的个人资料更新时发送邮件通知

有些朋友希望在用户的个人资料更新时,发送邮件通知用户,那么,你可以将下面的代码添加到主题的 functions.php 文件:

/**
* WordPress 用户的<a href="https://www.wpdaxue.com/tag/%e4%b8%aa%e4%ba%ba%e8%b5%84%e6%96%99" title="查看与【个人资料】相关的文章" target="_blank" rel="noopener">个人资料</a>更新时发送邮件通知
* https://www.wpdaxue.com/send-email-notification-when-profile-updates.html
*/
function user_profile_update( $user_id ) {
        $site_url = get_bloginfo('wpurl');
        $user_info = get_userdata( $user_id );
        $to = $user_info-&gt;user_email;
        $subject = &quot;个人资料已更新: &quot;.$site_url.&quot;&quot;;
        $message = &quot;您好 &quot; .$user_info-&gt;display_name . &quot;\n您的个人资料已更新!\n\n感谢您访问\n &quot;.$site_url.&quot;&quot;;
        wp_mail( $to, $subject, $message);
}
add_action( 'profile_update', 'user_profile_update', 10, 2);

如果你希望用户的个人资料更新时,发送邮件通知管理员,可以使用下面的代码:

/**
* WordPress 用户的个人资料更新时发送邮件通知
* https://www.wpdaxue.com/send-email-notification-when-profile-updates.html
*/
function user_profile_update_email_admin( $user_id ) {
        $site_url = get_bloginfo('wpurl');
        $user_info = get_userdata( $user_id );
        $to = get_option( 'admin_email' );
        $subject = $user_info-&gt;display_name.&quot; 的个人资料已更新&quot;;
        $message = &quot;您好,管理员。用户 &quot; .$user_info-&gt;display_name . &quot; 的个人资料已更新!\n\n访问\n &quot;.$site_url.&quot;&quot;;
        wp_mail( $to, $subject, $message);
}
add_action( 'profile_update', 'user_profile_update_email_admin', 10, 2);

来源:

https://www.wpdaxue.com/send-email-notification-when-profile-updates.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_33159.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?