Home › Forums › Calendar Products › Events Calendar PRO › Is there a hook for when an event is created
- This topic has 7 replies, 3 voices, and was last updated 9 years, 5 months ago by
Susanne Thiede Barnet.
-
AuthorPosts
-
November 10, 2016 at 11:22 am #1190493
Susanne Thiede Barnet
ParticipantI see that there is a hook for when community events are created (tribe_community_event_created), but is there one for when a normal event is published?
I am basically trying to send an email out each time an event is published, something like this:
add_action( 'tribe_event_created', 'notify_organizer' );function notify_organizer ( $event_id ) {
$email = '[email protected]';
$link = tribe_get_event_link( $event_id, true );$subject = 'New event published';
$message = 'A new event was just created. Would you like to review? ' . $link;wp_mail( $email, $subject, $message );
}November 11, 2016 at 8:41 am #1191011Geoff
MemberHi Kindra,
Great question!
You ought to be able to hook into the same WordPress action used for creating default posts, but specify the tribe-events custom post type to limit it directly to event posts:
We have the tribe_create_event action for you to hook into, but I do not think it is the exact thing you are looking for and targeting the default WordPress post action would be more effective.
Cheers!
GeoffNovember 11, 2016 at 8:46 am #1191015Geoff
MemberHi Kindra,
I also wanted to add in here that using the save_post action ought to accomplish what you’re looking for. 🙂
Cheers,
GeoffNovember 17, 2016 at 9:32 am #1194000Susanne Thiede Barnet
ParticipantThanks for the quick response! Now that I’ve got the function sending an email every time an event is published, a few new questions arose.
Currently when I publish a recurring event the function fires for each event in the recurrence. Is there a way to only trigger the function after the last event in a recurring group is published?
Also is there a way to grab the link to the ‘all’ page for the event that is created? eg events/test-event/all/?
I see that there are tribe_is_recurring_event and tribe_display_current_events_slug functions that could be helpful in accomplishing this, however it doesn’t appear that you can pass them an ID.
Thanks!
November 17, 2016 at 5:16 pm #1194234Geoff
MemberHi Kindra,
Nice work so far!
I think the closest function for you to specify the first recurring event in a series is tribe_get_upcoming_recurring_event_id_from_url(). That will return the ID for the first recurrence in the series, so I wonder if that would accomplish what you’d need to isolate one event from the others in the series when hooking into save_post.
I believe the tribe_all_occurrences_link() function is what you’re looking for to produce the /all URL for recurring events. That is linked directly to Events Calendar PRO, which contains the recurring events feature and appears to be used for similar stuff in the core code.
I hope this helps! I’ll certainly do my best if you have any other questions!
Cheers,
GeoffNovember 18, 2016 at 2:29 pm #1194726Susanne Thiede Barnet
ParticipantThank you for all of your help. I used the functions you mentioned and got it working!
November 21, 2016 at 7:00 am #1195289Geoff
MemberYES! That is awesome, Kindra! Serious props to you for making it work — that is not an easy customization and you nailed it. 🙂
Thanks so much for following up to let me know it went well and I hope you had a great weekend as well.
Cheers!
Geoff -
AuthorPosts
- The topic ‘Is there a hook for when an event is created’ is closed to new replies.
