WordPress 用戶的個人資料更新時發送郵件通知

有些朋友希望在用戶的個人資料更新時,發送郵件通知用戶,那麼,你可以將下面的代碼添加到主題的 functions.php 文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
/**
* WordPress 用戶的個人資料更新時發送郵件通知
* 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->user_email;
        $subject = "個人資料已更新: ".$site_url."";
        $message = "您好 " .$user_info->display_name . "\n您的個人資料已更新!\n\n感謝您訪問\n ".$site_url."";
        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( $user_id ) {
$site_url = get_bloginfo(‘wpurl’);
$user_info = get_userdata( $user_id );
$to = $user_info->user_email;
$subject = "個人資料已更新: ".$site_url."";
$message = "您好 " .$user_info->display_name . "\n您的個人資料已更新!\n\n感謝您訪問\n ".$site_url."";
wp_mail( $to, $subject, $message);
}
add_action( ‘profile_update’, ‘user_profile_update’, 10, 2);

如果你希望用戶的個人資料更新時,發送郵件通知管理員,可以使用下面的代碼:

1
2
3
4
5
6
7
8
9
10
11
12
13
/**
* 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->display_name." 的個人資料已更新";
        $message = "您好,管理員。用戶 " .$user_info->display_name . " 的個人資料已更新!\n\n訪問\n ".$site_url."";
        wp_mail( $to, $subject, $message);
}
add_action( 'profile_update', 'user_profile_update_email_admin', 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->display_name." 的個人資料已更新";
$message = "您好,管理員。用戶 " .$user_info->display_name . " 的個人資料已更新!\n\n訪問\n ".$site_url."";
wp_mail( $to, $subject, $message);
}
add_action( ‘profile_update’, ‘user_profile_update_email_admin’, 10, 2);

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *