Is there a hook for when an event is created

Home Forums Calendar Products Events Calendar PRO Is there a hook for when an event is created

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1190493

    I 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 );
    }

    #1191011
    Geoff
    Member

    Hi 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:

    wp_insert_post()

    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!
    Geoff

    #1191015
    Geoff
    Member

    Hi Kindra,

    I also wanted to add in here that using the save_post action ought to accomplish what you’re looking for. 🙂

    Cheers,
    Geoff

    #1194000

    Thanks 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!

    #1194234
    Geoff
    Member

    Hi 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,
    Geoff

    #1194726

    Thank you for all of your help. I used the functions you mentioned and got it working!

    #1195289
    Geoff
    Member

    YES! 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

Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘Is there a hook for when an event is created’ is closed to new replies.