I have two notifications with different content set up through a cred form in admin to go to a set email address.
I am attempting to develop a conditional based use case and the starting point is simply adding a second 'to' email to the second notification (num_notification 1). However, I'm finding that the second 'to' email address is adding to both notifications, and also if I change $formid to a different form, it still sends it from form 316.
Is the above code correct?
On a side note, while I'm creating a support ticket - is it possible to disable a notification through this hook? eg in functions.php have a conditional parameter that triggers disabling notification 1 for form 316 from sending entirely?
Checking the source code it seems that the last update to CRED which added notification names also altered the cred_mail_header filter, but the documentation has not been updated (I'm adding an internal ticket for that now).
There is an additional argument for the notification name, and the notification number is now the 5th argument, which is why your code will not work, because your $num_notification is actually the notification name.
Here is an updated template for using the cred_mail_header filter with 5 arguments which you can modify to add your code to:
/**
* Customise CRED notifications
*/
function customise_cred_notifications( $headers, $formid, $postid, $notification_name, $notification_number ) {
// your code here
return $headers;
}
add_filter('cred_mail_header', 'customise_cred_notifications', 10, 5);
As for your last question, I can't find any hook that would specifically allow you to do that.
The only way I could think of trying to do something like that would be to manipulate the form settings in the database for CRED notifications (they are stored in the wp_postmeta table with a key of _cred_notification against the form post) using the cred_before_save_data hook. I don't know if it would work, and you should certainly only try it if you feel comfortable recreating the settings object which is stored as a serialised string.
Thanks, I've used your code but now get the error (twice, as below, for some reason):
Warning: Missing argument 5 for add_my_header() in /home/codeflex/public_html/subs/fbi/wp-content/themes/Family-Business-Institute/functions.php on line 596
Warning: Missing argument 5 for add_my_header() in /home/codeflex/public_html/subs/fbi/wp-content/themes/Family-Business-Institute/functions.php on line 596
I no longer get the error, but the added 'to' email sends to both notifications, instead of just the second (1) so I dont think I have the format correct.
1. is the name of the filter you are hooking into
2. is the name of the function you are adding to it
3. is the priority level (default is 10, higher numbers run later if there are multiple filters attached)
4. is the number of arguments that will be passed to your function
There are 5 arguments available with the cred_mail_header filter, but you are only passing 4 of the arguments. You need to change 4 to 5 to pass all the arguments, including the notification number.
You can add a conditional check so that your code only runs for a particular notification number, e.g.
/**
* Customise CRED notifications
*/
function customise_cred_notifications( $headers, $formid, $postid, $notification_name, $notification_number ) {
if ( $notification_number == 1 ) {
// code just for notification 1
$myheaders = array(); // add headers
$headers = array_merge( $headers, $myheaders );
} else {
// optionally add code for any other notification
// which similarly adjusts $headers
}
return $headers;
}
add_filter('cred_mail_header', 'customise_cred_notifications', 10, 5);
This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.