• Resolved jwpalfa

    (@jwpalfa)


    I have copied the alo-easymail_attachments.php to wp-content/mu-plugins and edited out the comment line. I created a sample.pdf in /uploads. And it works – my sample.pdf is attached to the emailed newsletter. Wonderful πŸ™‚

    However, I am at a loss as to how to use this to send out a monthly newsletter with a different attachment each time. I could edit the file alo-easymail_attachments.php each time I want to send the email but that seems kind of unfriendly. Is there some way to specify the file name for the attachment when creating the newsletter post?

    Thanks,
    John

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author eventualo

    (@eventualo)

    Hi, you can create a new function to search in uploads an attachment with a name “month-based”: if the file exists, it will be attached in newsletter.
    The code is something like:

    
    function custom_easymail_newsletter_attachment_monthly ( $attachs, $newsletter ) {
    
    	$month_file = WP_CONTENT_DIR . '/uploads/neswletter_'.date( 'Y_m' ).'.pdf';
    
    	if ( @file_exists( $month_file ) ) {
    		return $month_file;
    	}
    	return array();
    }
    add_filter ( 'alo_easymail_newsletter_attachments',  'custom_easymail_newsletter_attachment_monthly', 10, 2 );
    

    So you have to prepare the files inside upload folder, one for each month: neswletter_2017_12.pdf, neswletter_2018_01.pdf
    I hope it can be a good starting point for you.

    • This reply was modified 8 years, 6 months ago by eventualo.
    Thread Starter jwpalfa

    (@jwpalfa)

    Alo

    Thanks very much for that suggestion. It will work fine as long as I have only one newsletter per month and I want to send it in the month to which it belongs.

    Of course you know that your users always want more πŸ™‚ What would it take to add a data field to the newsletters post page to specify an attachment file name? I can live with uploading it myself, having a fixed upload directory (/uploads ?) and being limited to a single attachment. Naturally removing those limitations could be future enhancements πŸ™‚

    Adding this ability would certainly be worth a cash donation!

    Thanks for considering this,
    John

    Plugin Author eventualo

    (@eventualo)

    Hi jwpalfa, maybe you can use the standard attachments.
    So you can add files to a newsletter using the standard “add media” button. Then, all attached pdf files will be attached inside newsletter.
    Please try the following code (I didn’t tested it but I think it could work):

    
    function custom_easymail_newsletter_get_attachments ( $attachs, $newsletter ) {
    
    	$get_attachments = get_attached_media( 'application/pdf', $newsletter->ID );
    
    	$attachs = array();
    	if ( $get_attachments ) {
    		foreach( $get_attachments as $attachment ) {
    			$attachs[] = get_attached_file( $attachment->ID );
    		}
    	}
    	return $attachs;
    }
    add_filter ( 'alo_easymail_newsletter_attachments',  'custom_easymail_newsletter_get_attachments', 10, 2 );
    

    Please let us know if it works.

    • This reply was modified 8 years, 6 months ago by eventualo.
    Thread Starter jwpalfa

    (@jwpalfa)

    Interesting behaviour!

    If I create a newsletter post and click the ‘Add Media’ button and then go through the upload a file process and insert it into the post, I get a nice attachment just as hoped. However, if I select an existing file from the media library to insert into the post, it does not appear in the email as an attachment. Why the difference?

    My other complaint is that the body of the post contains a link to the file in the media library – which is not a url that I really want to expose.

    Close but not quite there yet πŸ™‚

    Plugin Author eventualo

    (@eventualo)

    You have to upload the file and insert it in newsletter in order to attach (=link) it to the newsletter. It’s the reason why if you get an existing file but uploaded in another post or what ever, it will not recognized as an attachment.

    Once you uploaded a file using media button in newsletter and the link is added inside newsletter content, this file is attached to newsletter (you should see the relation also in Media list table, in relationship column): so at this point I think you can remove the link from content because the file is anyway attached. Let us know if I remember well and if it works.

    • This reply was modified 8 years, 6 months ago by eventualo.
    Thread Starter jwpalfa

    (@jwpalfa)

    Alo

    Your memory is very good! After attaching the file to the newsletter post the link generated in the body of the post may be deleted. The file is still delivered as an attachment to the email message.

    I think you should include your custom_easymail_newsletter_get_attachments function as suggested above in the examples on the easymail for developers page! And in the samples in the mu-plugins folder.

    Thank you so much for the coding suggestions.

    John

    • This reply was modified 8 years, 6 months ago by jwpalfa.
    Plugin Author eventualo

    (@eventualo)

    Good idea, I’ll add this sample in developers page and also inside mu-plugins folder in EasyMail.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Add an attachment’ is closed to new replies.