Skip Navigation

[Resolved] Cancel and replace cred notification recepients

This support ticket is created 7 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 6 replies, has 2 voices.

Last updated by romanB-3 7 years, 3 months ago.

Assisted by: Luo Yang.

Author
Posts
#560718

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.

#561042

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.

#561180

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.

#561789

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

#561859
cred.PNG

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.

#561871

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;
}
#561909

Thank you, it works great now without the [] !