Ability to include attachments to emails in Customer Area Notifications
-
-
First Reef Studio
Participant# il y a 1 année et 3 moisI have made some really basic changes to the notifications-maler-helper.class.php file that allows me to add attachments to emails, however I’d like this to possible be made a part of the actual plugin so I don’t have to re-implement this every time I perform an update.
The changes are as follows:
notifications-mailer-helper.class.php, line 114:
$this->send_email($from_name, $from_address, $to_name, $to_address, $email_subject, $email_body, $email_format, $post_id); // ADDED $post_idnotifications-mailer-helper.class.php line 156:
/* Create an empty attachments array that can be modified via external plugins */
$mail_attachments = Array(); // Create an empty attachments array
$mail_attachments = apply_filters(‘cuar/notifications/attachments’, $mail_attachments, $this->plugin, $post_id, $to_name, $to_address, $subject, $body, $headers);@wp_mail($to, $subject, $body, $headers, $mail_attachments); // ADDED $mail_attachments
What this then allows me to do, in functions.php is create the following filter to attach relevant files:
add_filter(‘cuar/notifications/attachments’, ‘attachFilesToEmail’, 10, 8);function attachFilesToEmail($mail_attachments, $plugin, $post_id, $to_name, $to_address, $subject, $body, $headers){// Check that the send attachment checkbox was checkedif(isset($_POST[‘cuar_no_send_new_private_post_attachment’])){$pf_addon = $plugin->get_addon(‘private-files’);$po_addon = $plugin->get_addon(‘post-owner’);$att = $pf_addon->get_attached_files($post_id);foreach ($att as $attachment) {$file_path = $po_addon->get_private_file_path($attachment[‘file’], $post_id, false);array_push($mail_attachments, $file_path);}}return$mail_attachments;}If you could please confirm whether or not this will be adopted in a future release, that would be appreciated -
Vincent Mimoun-Prat
Maître des clés# il y a 1 année et 3 moisHi,
Yes, we could perfectly do that indeed.
I will add this so that you get the same filter in the next addon update.
Regards,
-
Vincent Mimoun-Prat
Maître des clés# il y a 1 année et 3 moisActually I have done it slightly differently. Here is what I have modified:
// customer-area-notifications/src/php/helpers/notifications-mailer-helper.class.php // LINE 113 // Gather attachments $attachments = apply_filters( 'cuar/notifications/attachments', [], $recipient_id, $notification_id, $post_id, $notif_settings, $extra ); // Send the email $this->send_email( $from_name, $from_address, $to_name, $to_address, $email_subject, $email_body, $email_format, $attachments ); // LINE 145 public function send_email($from_name, $from_address, $to_name, $to_address, $subject, $body, $format, $attachments) // LINE 170 @wp_mail($to, $subject, $body, $headers, $attachments);
-
Vincent Mimoun-Prat
Maître des clés# il y a 1 année et 3 moisYou can write the code I have given and adapt your own hook in order to be compatible with the next release.
-
First Reef Studio
Participant# il y a 1 année et 3 moisHi Vincent,
Thank you for the update, when the next release comes out I will be sure to adapt my code to suit the changes you have made
Thanks
-
The topic ‘Ability to include attachments to emails in Customer Area Notifications’ is closed to new replies.