[Solved] Hooking aditional actions to 'save draft/queue newsletter'
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.
Tagged:
Comments
@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 andHistory
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?
@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.
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.
@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.
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?
Nevermind first half of comment, I have made a mistake there (forgot that you have to pass function name like this
if it's inside of a class)
Managed to finish my task thanks for the help.
@Liudas
Thank you for the feedback.
I'm glad to hear that you managed with the task.