I created a feedback form that works by creating a post in the "Messages" custom post type and then uses the code below to send an e-mail to a dynamic recipient. It works just fine except that, periodically, it will randomly stop working altogether. It tends to happen when the theme (Astra) requires updating. This is a bit of a nuisance and I'm wondering if there is anything in my code that could be improved to prevent this from happening.
Example Form: lien caché
// modify recipient to parent of the message post
add_filter('cred_notification_recipients', 'modify_recipients', 10, 4);
function modify_recipients($recipients, $notification, $form_id, $post_id) {
// Check notification name matches target notification
if ( isset($notification['name']) && 'Dynamic E-Mail Recipient' == $notification['name'] ) {
// Add email recipient
$parent_id = toolset_get_related_post(
$post_id,
'position-message'
);
$emailemailangehorige = get_post_meta($parent_id, 'wpcf-position-e-mail', true);
$recipients[0] = array(
'to' => 'to',
'address' => $emailemailangehorige,
'name' => '',
'lastname' => '');
}
return $recipients;
}
// modify the from and reply-to information
add_filter('cred_mail_header', 'customise_cred_notifications', 10, 5);
function customise_cred_notifications( $headers, $formid, $postid, $notification_name, $notification_number ) {
if ($formid==68 && $notification_name=='Dynamic E-Mail Recipient') {
$sendername = get_post_meta($postid,'wpcf-message-name',true);
$senderemail = get_post_meta($postid,'wpcf-message-e-mail',true);
$myheaders = array('Reply-To: '.$senderemail);
return array_merge($headers, $myheaders);
}
return $headers;
}
Hi,
Thank you for contacting us and I'd be happy to assist.
Reading through the code that you've shared, I can't think of a reason it can conflict with the Avada theme's code or pending updates.
When it stops working, do you see any error or warning in the server's error logs? Do you have to do something, to make the code work again?
Next, time if this happens, I'll recommend turning on the WordPress debugging, and see if any error or warning is logged in the error log.
( ref: https://wordpress.org/support/article/debugging-in-wordpress/ )
Please let me know how it goes and if you have any further details.
regards,
Waqar
Replying to keep this ticket open. I found out this morning the e-mails are still not working (despite working when I first opened this ticket). I will have to investigate further, and will try putting into debug mode as you suggested.
- Aaron
Thanks for the update and I'll wait to hear back from you.