[Solved] Hooking aditional actions to 'save draft/queue newsletter'

edited January 2016 in Newsletter plugin

Hello i have to add some extra attachments via ajax to a newsletter in 'create newsletter' window. I managed to insert them into the window itself, using rather hidden 'newsletters_page_newsletters-create' hook. Now i want to save/send these extra attachments just can't figure out what hook should i attach my function to. Also it would be nice to know what function deals with the default attachments and what it is hooked to.



Summary: what are the hooks for save draft/queue newsletters/save attachments.

Comments

  • 8 Comments sorted by
  • Vote Up1Vote Down

    @Liudas

    Great, thank you for confirming.

    There is no hook for adding additional attachments at the moment.

    We've added it to the core here like this: https://goo.gl/Jt3U4V. So it will be in the next release.

    For now, please add this newsletters_send_attachments to the core of your Newsletter plugin.

    There is a filter at the time that the history/draft email gets saved though.

    The filter hook is newsletters_db_data_before_validate with $data as first parameter and History string as second.

    Here is a sample of how you can use it: https://gist.github.com/tribulant/f126e91427898a766462

    So you can catch your $_FILES at this time and add it to the attachments Array.

    Let me know if that helps?

  • Vote Up0Vote Down

    @Liudas

    Thank you for your post.

    Are you referring to email attachments on the newsletter specifically?

    Did you add a box to the Create Newsletter page to specify more attachments?

    I look forward to your response with more details.

  • Vote Up0Vote Down

    Yes I am referring to email attachments on newsletter.

    And yes I added a custom metabox to the Create Newsletter page. At the moment there are only images which should be attached displayed in metabox with ability to remove unwanted images. I need to attach those images to email.

    (The thing I need to do is create a template which you can select from a dropdown menu in create newsletter page, choosing  template would add some text to mail, add subject, and images as attachments)

    Most of stuff I need to do is done all I need to do is upon saving/sending newsletter to save those images as attachments.

    Best regards, Liudas.

  • Vote Up0Vote Down

    @Liudas

    Same as the code above, you can hook to that new newsletters_send_attachments as well.

    The hook just isn't publicly released yet so you need to add it as shown in the screenshot.

    It will be in the next release of the plugin.

  • Vote Up0Vote Down

    I am rather new to wordpress and so far haven't used many filters so i might have done something wrong.

    I tried to add the add_attachments functiuon as it was suggested (added it to functions.php of my theme), but then the draft doesn't get saved at all(removing/commenting that code lets it be saved again).

    Another thing is I have the file data in ajax, that is called on create newsletter page. How can i save my file data to the $_FILES variable so it would be visible inside add_attachments function?

  • Vote Up0Vote Down

    Nevermind first half of comment, I have made a mistake there (forgot that you have to pass function name like this


    array($this, 'add_attachmentss')

    if it's inside of a class)

  • Vote Up0Vote Down

    Managed to finish my task thanks for the help.

  • Vote Up0Vote Down

    @Liudas

    Thank you for the feedback.

    I'm glad to hear that you managed with the task.

Sign In or Register to comment.