Events Made Easy › Forums › How do I … › Send mail on event PUBLISHING
Tagged: mail, publishing
- This topic has 6 replies, 3 voices, and was last updated 3 years, 10 months ago by Anonymous.
-
AuthorPosts
-
Fri 6 Nov 2020 at 19:59 #61869AnonymousInactive
Hey Franky….
Using the code found in documentation at https://www.e-dynamics.be/wordpress/category/documentation/12-hooks-and-filters/
add_action('eme_insert_event_action','eme_mail_event'); function eme_mail_event ($event) { $contact = eme_get_event_contact ($event); $contact_email = $contact->user_email; $contact_name = $contact->display_name; $subject_format="This is the new event called ' #_EVENTNAME '"; $body_format="This is the new event called ' #_EVENTNAME '"; $subject=eme_replace_placeholders($subject_format, $event, "text"); $body=eme_replace_placeholders($body_format, $event, "text"); $blogusers = get_users(); foreach ( $blogusers as $user ) { eme_send_mail($subject,$body, $user->user_email, $user->display_name, $contact_email, $contact_name); } }
I am able to get the system to send mail the second I press SAVE. Unfortunately, some events are still drafts or are private and I don’t want them sending until they publish to the public at large.
Any way to add a filter or hook to only send once published or, barring that, only send events that are in a certain category automatically?
Thanks
Fri 6 Nov 2020 at 22:46 #61871FrankyKeymasterAdd this condition to your code:
if ($event ['event_status'] == EME_EVENT_STATUS_PUBLIC)
Mon 15 Feb 2021 at 20:15 #62060AnonymousInactiveHi Franky.
I’m successfully using code similar to the user above – to notify my site’s users when a new private event is created. I do not want users to be notified when a draft event is created.
The problem I’m facing is that, when a draft event’s status is changed to private (or public), I need to send an email to my users (telling them that a ‘new’ event was published).
Do you think this would be possible – e.g. using ’eme_update_event_action’, but only running the function when event_status is changed to public or private? Any tips?
Many thanks! Matt.
Mon 15 Feb 2021 at 20:31 #62061FrankyKeymasterYou can use the filter eme_event_preupdate_filter if you’d want for that. Just return the same $event on the end (no modif needed), and get the original event using eme_get_event:
add_filter('eme_event_preupdate_filter','my_pre_filter'); function my_pre_filter($event) { $orig_event=eme_get_event($event['event_id']); ... return $event; }
Using that code you have the original event ($orig_event) and the new one ($event), so you can compare the status for the 2 and do what is needed if wanted.
Fri 19 Feb 2021 at 13:03 #62080AnonymousInactiveUnfortunately I’m having trouble with eme_event_preupdate_filter.
Here’s my code:
add_filter('eme_event_preupdate_filter','draft_to_private_filter'); function draft_to_private_filter($event) { $orig_event=eme_get_event($event['event_id']); print_r($orig_event); print_r($event); if ($orig_event ['event_status'] == EME_EVENT_STATUS_DRAFT) { if ($event ['event_status'] == EME_EVENT_STATUS_PRIVATE) { eme_send_mail('subject','event was draft and is now private', 'myemail@mail.com', 'test user', 'myadmin@mail.com', 'contact name'); } } return $event; }
I’m using print_r to view the arrays for testing purposes. For the (updated) $event array, ‘event_status’ always shows the correct, updated, value (‘1’, ‘2’, or ‘5’, depending on what it was changed to). For $orig_event array, the ‘event_status’ is always ‘2’. Looking at the rest of the two arrays, I can see that other values (such as ‘event_notes’) are behaving as expected, showing the original value in the $event array, and the updated value in the $orig_event array.
I’m not having any issues with eme_send_mail.
Any ideas? Many thanks!
Fri 19 Feb 2021 at 18:59 #62081FrankyKeymasterReason was that event_id was not given for the new event (in your php logs this would show and also your print_r of the original event would show a lot of info missing). Try this small change:
https://plugins.trac.wordpress.org/changeset/2477870/Sat 20 Feb 2021 at 11:24 #62082AnonymousInactiveQuick test seems to show that everything is now working as expected with that changeset 🙂
Big thanks!
-
AuthorPosts
- The forum ‘How do I …’ is closed to new topics and replies.