Ability to include attachments to emails in Customer Area Notifications

    • First Reef Studio
      Participant
      # 3 years, 1 month ago

      I 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_id

      notifications-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 checked
          if(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
    • # 3 years, 1 month ago

      Hi,

      Yes, we could perfectly do that indeed.

      I will add this so that you get the same filter in the next addon update.

      Regards,

    • # 3 years, 1 month ago

      Actually 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);
    • # 3 years, 1 month ago

      You 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
      # 3 years, 1 month ago

      Hi 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

    • Thomas
      Keymaster
      # 3 years, 1 month ago

      Hi,

      We don’t know when we’ll release the next version, yet. Consider applying Vincent’s changes to our plugin files so you won’t need to do anything more when the update will come out.

      Regards.

      Want to help WP Customer Area? It only takes few seconds!
      Rate & review the plugin on WordPress.org 🙂

Viewing 5 reply threads

The topic ‘Ability to include attachments to emails in Customer Area Notifications’ is closed to new replies.