Home › Forums › Calendar Products › Events Calendar PRO › Event Counter
- This topic has 6 replies, 2 voices, and was last updated 9 years, 9 months ago by matthewdenton.
-
AuthorPosts
-
June 25, 2014 at 3:12 pm #251089cnhParticipant
Is it possible to execute a function right after submitting an event? I want to increase a counter when a user will submit an event.
Thanks.
June 26, 2014 at 11:19 am #253231matthewdentonMemberHi!
Thanks for reaching out to us and I would be more than happy to help you with your question.
We have tried to make The Events Calendar as extensible as possible. For this purpose we have several action hooks built into the event life-cycle including ‘tribe_events_event_save‘.
You can add actions on this hook to execute your own functions when a new event has been created.
The WordPress Codex has documentation on how to use action hooks that may be of use to you.
http://codex.wordpress.org/Function_Reference/do_actionOur documentation page also contains additional information on hooks and filters.
Please let me know if this answers your question.
June 30, 2014 at 5:15 pm #262944cnhParticipantI’ve tried with hook with my custom function but my function is not executing when an event is submitted. I’ve added the following codes in the functions.php file:
function my_func(){
update_usermeta( 33, ‘previous_member_level’, ‘test’ );
}do_action(‘tribe_events_event_save’,’my_func’);
Let me know if you need more details. Thanks
July 1, 2014 at 6:44 am #264357matthewdentonMemberHi!
Looking at the link I sent earlier I may have caused you some slight confusion, my apologies.
The do_action function is where you execute any functions defined to the action hook. We use this in our code base to create the hooks.
To add a function for execution based on the action you want to use add_action. I’ve updated the sample you provided as below, please let me know if it works for you.
function my_func(){ update_usermeta( 33, ‘previous_member_level’, ‘test’ ); } add_action(‘tribe_events_event_save’,'my_func’);
– Matthew
July 4, 2014 at 6:34 am #278219cnhParticipantThanks. It is almost working. But this action also executes when an event is updated. Is there any action exists like ‘tribe_events_event_submit’ or ‘tribe_events_event_create’ which will execute only when an event is first created not updated?
Thanks.
July 7, 2014 at 6:59 am #299549matthewdentonMemberHi!
I did another review of the code base and unfortunately there is no explicit hook for when an Event is “created”. We have hooks for explicit creation of Venue and Organizer but not for an Event. I’m going to add this to our tracker as it seems like an oversight.
Until the team has a chance to look into why we don’t have a created hook separately from save you could potentially use the modified time stamp of the event to see if it is the original save.
function my_func( $eventId ) {
$event = get_post( $eventId );
if ($event->post_date != $event->post_modified) return;
// Place your code here
}
}Please let me know if the above works for you and I’ll follow-up on my end to see about getting a distinct hook created.
Thank you,
– Matthew
July 21, 2014 at 7:26 am #470862matthewdentonMemberHi, I wanted to quickly follow-up with you to see if you are all set. Please let me know if you do have additional questions I can assist with or if I should go ahead and close this thread.
Thank you,
– Matthew
-
AuthorPosts
- The topic ‘Event Counter’ is closed to new replies.