Hi, here is an example of a plugin hook that will send a different email to a specific user. You need to adjust it to your needs and put it at the end of functions.php file of your theme:
if (!function_exists('wfu_before_email_notification_handler')) {
function wfu_before_email_notification_handler($changable_data, $additional_data) {
$user = wp_get_current_user();
if ( 0 == $user->ID ) $user_login = "guest";
else $user_login = $user->user_login;
$notifyrecipients = "[email protected]";
$notifysubject = "New File Uploaded";
$notifymessage = "Hello\n\nCustomer $user_login has sent you some files\n\nRegards";
$notifyheaders = "";
$notify_sent = wp_mail($notifyrecipients, $notifysubject, $notifymessage, $notifyheaders);
return $changable_data;
}
add_filter('wfu_before_email_notification', 'wfu_before_email_notification_handler', 10, 2);
}
Regards
Nickolas
Thread Starter
Marcus
(@omako)
That’s exactly what i was looking for. Thank you very much.
Kind Regards
Marcus
Hi Nickolas-
I can’t get the notification setting to work using two different email addresses. I’ve tried editing in the block setting and in the plugin setting but when I put two email addresses in neither one receives an email. So what is the correct format to include two or more recipient email addresses?
Hi, you just separate them with comma
Regards
Nickolas
Thread Starter
Marcus
(@omako)
Nickolas, just one thing, how can I add %userdataX% to this hook? Best Marcus
Hi which hook do you mean?
Nickolas
Thread Starter
Marcus
(@omako)
oh, within the function wfu_before_email_notification_handler you declared a variable $notifymessage for the email body. is is possible to give out additional %userdateXXX% like notifications in the string? Marcus
Hi, the following script will allow %userdataXXX% variable in second email subject and body, as well as some other variables:
if (!function_exists('wfu_before_email_notification_handler')) {
function wfu_before_email_notification_handler($changable_data, $additional_data) {
global $blog_id;
$user = wp_get_current_user();
if ( 0 == $user->ID ) {
$user_login = "guest";
$user_email = "";
}
else {
$user_login = $user->user_login;
$user_email = $user->user_email;
}
$notifyrecipients = "[email protected]";
$notifysubject = "New File Uploaded";
$notifymessage = "Hello\n\nCustomer $user_login has sent you some files\n\nRegards";
$notifyheaders = "";
$search = array ('/%username%/', '/%useremail%/', '/%filename%/', '/%filepath%/', '/%blogid%/');
$replace = array ($user_login, ( $user_email == "" ? "no email" : $user_email ), $changable_data["filename"], $changable_data["filepath"], $blog_id);
foreach ( $changable_data["user_data"] as $userdata_key => $userdata_field ) {
$ind = 1 + $userdata_key;
array_push($search, '/%userdata'.$ind.'%/');
array_push($replace, $userdata_field["value"]);
}
$notifysubject = preg_replace($search, $replace, $notifysubject);
$notifymessage = preg_replace($search, $replace, $notifymessage);
$notify_sent = wp_mail($notifyrecipients, $notifysubject, $notifymessage, $notifyheaders);
return $changable_data;
}
add_filter('wfu_before_email_notification', 'wfu_before_email_notification_handler', 10, 2);
}
Regards
Nickolas