Hello,
I wonder if the "cred recipients" hook could allow to delete all cred notification recipients and replace them by ones defined threw a function ?
Please see https://toolset.com/forums/topic/cred-api-headers-in-notifications-sent-only-if-from-is-set/ for further information.
Thank you.
Dear Roman,
I assume we are talking about the CRED filter hook "cred_notification_recipients", which is locate in CRED plugin file \cred-frontend-editor\application\controllers\notification_manager.php, line 1109~1110:
// add custom recipients by 3rd-party
$recipients = apply_filters('cred_notification_recipients', $recipients, $notification, $form_id, $post_id);
Yes, it is possible to do what you are going to achieve:
delete all cred notification recipients and replace them by ones defined threw a function
But it needs some custom PHP codes, here is an example:
add_filter('cred_notification_recipients', 'my_cred_notification_recipients_func', 999, 4);
function my_cred_notification_recipients_func($recipients, $notification, $form_id, $post_id){
if($form_id == 123){ //replace it with your CRED form ID
$recipients[] = array(); //delete all cred notification recipient
$my_email = 'abc@abc.com'; //your specific email address.
$recipients[] = array('to'=>'', 'name'=>'', 'lastname'=>'', 'address'=>$my_email );
}
return $recipients;
}
It is only an example, you will need to customize the PHP codes to what you want.
Hello and thank you.
I've just tried it and it does not work. The hook adds its own emails without deleting the emails set in backend.
I just tested the PHP codes, it works fine, but I am not sure how do you setup your CRED form, could you take a screenshot for how do you setup your CRED form, especially the email notification settings, I need to duplicate same problem and debug it in my localhost, thanks
Here it is.
The yellow email should be replaced by the CRED recipients. Instead, the CRED recepients hook adds its recipients, without deleted the yellow one.
Thank you.
There is a error in my codes, please try to modify it as below and test again:
add_filter('cred_notification_recipients', 'my_cred_notification_recipients_func', 999, 4);
function my_cred_notification_recipients_func($recipients, $notification, $form_id, $post_id){
if($form_id == 123){ //replace it with your CRED form ID
$recipients = array(); //delete all cred notification recipient
$my_email = 'abc@abc.com'; //your specific email address.
$recipients[] = array('to'=>'', 'name'=>'', 'lastname'=>'', 'address'=>$my_email );
}
return $recipients;
}
Thank you, it works great now without the [] !