Hooks and Filters
Events Manager fires WordPress actions and filters at almost every point where it loads, saves, validates, queries or prints something. Version 7.5 contains close to 300 distinct actions and 700 filters, so this page does not list them all. It explains the naming patterns, which let you predict most hook names, shows how to find a hook in the source, and gives the signatures of the ones used most.
You should be comfortable with add_action() and add_filter(). Put your code in a small plugin or a must-use plugin, as described in Where to add PHP. The examples need PHP 7.4 or later, the minimum Events Manager itself requires.
How hooks are named
Most hooks follow one pattern: em_, then the object, then the method that fires it.
em_{object}_{method}
| Object | Class | Examples |
|---|---|---|
event | EM_Event | em_event_save, em_event_validate, em_event_delete |
events | EM_Events (queries and lists) | em_events_get, em_events_output, em_events_build_sql_conditions |
location, locations | EM_Location, EM_Locations | em_location_save, em_locations_get_default_search |
booking, bookings | EM_Booking, EM_Bookings | em_booking_save, em_booking_set_status, em_bookings_added |
ticket, ticket_booking | EM_Ticket, EM_Ticket_Booking | em_ticket_is_available, em_ticket_booking_output_placeholder |
category, tag | EM_Category, EM_Tag | em_category_output_placeholder |
calendar | EM_Calendar | em_calendar_get, em_calendar_get_default_search |
A few conventions apply across all of them:
- A method usually ends by passing its return value through a filter with the method's name.
EM_Event::save()returnsapply_filters( 'em_event_save', $result, $this ). The first argument is the result so far (oftentrueorfalsefor success) and the second is the object. Return the first argument, changed or not. - An action ending in
_prefires before the method does its work, for exampleem_event_save_preandem_booking_validate_pre. Use it to change the object before it is saved or checked. - An action named after the object alone (
em_event,em_location,em_booking) fires when that object has finished loading. Use it to attach your own data. - Actions in the past tense report something that has happened:
em_booking_added,em_booking_deleted,em_booking_status_changed.
Save and validate families
Saving an event from a form runs three methods in order, and each has its own filter:
| Step | Filter | What the method does |
|---|---|---|
| 1 | em_event_get_post | Reads the submitted form into the object. |
| 2 | em_event_validate | Checks the object. Add to $EM_Event->errors with $EM_Event->add_error() and return false to block the save. |
| 3 | em_event_save | Writes the event. Fires after the event and its meta are stored. |
Locations (em_location_get_post, em_location_validate, em_location_save) and bookings (em_booking_get_post, em_booking_validate, em_booking_save) follow the same sequence.
em_event_save fires in more situations than a form submission: quick edit, the REST API, imports, front-end submissions, and once for each recurrence when a recurring event is saved. Don't assume your form fields are in $_POST when it runs. Check for your own nonce first, as the Save event data tutorial does.
Output and placeholder families
Every object that supports placeholders has three filters with the same shape:
| Filter | Purpose |
|---|---|
em_{object}_output_placeholder | Change the replacement for one placeholder, or add a placeholder of your own. Objects: event, location, booking, ticket_booking, category, tag. |
em_{object}_output_show_condition | Decide whether a conditional placeholder block is shown, or add a condition of your own. Objects: event, location, booking, ticket_booking. |
em_{object}_output | Change the finished string after all placeholders are replaced. Objects: event, location, booking. |
Search and query families
Each query class (EM_Events, EM_Locations, EM_Bookings, EM_Calendar) cleans its arguments, builds SQL and returns results through filters:
| Filter | Purpose |
|---|---|
em_{objects}_get_default_search | Add or change accepted search attributes and their defaults. |
em_{objects}_build_sql_conditions | Add or change the WHERE conditions, as an array of SQL fragments joined with AND. Available for events and locations. |
em_{objects}_get | Change the array of objects a query returns. |
em_{objects}_output | Change the HTML of a finished list. |
Template hooks
Every template file fires em_template_before_{template_name} and em_template_after_{template_name}, where the name is the template's path such as templates/events-list.php. Templates also contain actions of their own at useful points, for example em_booking_form_after_user_details in the booking form and em_template_search_form_footer in the search form.
Find the hook you need
The source is the reference. To find what fires around the code you want to change, search the plugin folder:
cd wp-content/plugins/events-manager
# every hook fired by the booking class
grep -n "apply_filters\|do_action" classes/em-booking.php
# where one hook is fired, with its arguments
grep -rn "'em_event_output_placeholder'" --include=*.php .
The line that fires the hook shows the arguments in order. Pass the number of arguments you need as the fourth parameter of add_filter() or add_action(), or your callback receives only the first.
To see which hooks run during one request, log them. This writes every Events Manager hook to the debug log, and should be removed when you are done:
add_action( 'all', function ( $hook ) {
if ( str_starts_with( $hook, 'em_' ) && defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) {
error_log( $hook );
}
} );
str_starts_with() needs PHP 8.0 or WordPress 5.9 or later.
Events Manager Pro and the add-ons follow the same patterns, and Pro adds hooks with an em_ or emp_ prefix.
Actions used most often
All of these are in Events Manager 7.5.
| Action | Arguments | Fires |
|---|---|---|
events_manager_loaded | none | On init at priority 1, when the plugin's classes and constants are ready. A safe point to register anything that depends on Events Manager. |
em_event | $EM_Event, $id, $search_by | When an event object has loaded. |
em_location | $EM_Location, $id, $search_by | When a location object has loaded. |
em_booking | $EM_Booking, $booking_data | When a booking object has loaded. |
em_event_save_pre | $EM_Event | Before an event is written. |
em_booking_add | $EM_Event, $EM_Booking, $post_validation | When a booking form is submitted, after validation and before the booking is saved. $post_validation is false if validation failed. |
em_booking_added | $EM_Booking, $mail | After a new booking is saved for the first time. |
em_bookings_added | $EM_Booking | After a booking made through an event's booking form has been saved. |
em_booking_status_changed | $EM_Booking, $args | After a booking's status has changed and before emails go out. $args holds status, email and ignore_spaces. |
em_booking_deleted | $EM_Booking | After a booking is deleted. |
em_booking_email_before_send, em_booking_email_after_send | $EM_Booking | Around the emails for a booking. |
em_booking_form_after_user_details | $EM_Event, $EM_Booking | Inside the booking form, after the registration fields. The form template has an action before and after each of its sections. |
em_front_event_form_footer | $EM_Event | At the bottom of the front-end event submission form. |
em_template_search_form_footer | $args | Inside the main search bar, before the submit button. |
em_search_form_advanced_sections_footer | $args | At the end of the advanced search sections. |
em_template_before_{template_name}, em_template_after_{template_name} | $args | Around every template file. |
Filters used most often
| Filter | Arguments | Use it to |
|---|---|---|
em_event_get_post | $result, $EM_Event | Read your own fields from a submitted event form. |
em_event_validate | $result, $EM_Event | Reject an event that fails your own checks. |
em_event_save | $result, $EM_Event | Store your own data when an event is saved. |
em_event_delete | $result, $EM_Event | Clean up your data when an event is deleted. |
em_location_save | $result, $EM_Location | Store your own data with a location. |
em_booking_get_post | $result, $EM_Booking | Read your own fields from the booking form. |
em_booking_validate | $result, $EM_Booking | Block a booking. Add a message with $EM_Booking->add_error() and return false. |
em_booking_save | $result, $EM_Booking, $update | Act when a booking is created or updated. $update is true for an existing booking. |
em_booking_set_status | $result, $EM_Booking | Act on a status change before its emails are sent. |
em_booking_delete | $result, $EM_Booking | Clean up your data when a booking is deleted. |
em_booking_get_price | $price, $EM_Booking | Adjust a booking's total price. |
em_ticket_is_available | $available, $EM_Ticket, ... | Make a ticket available or unavailable by your own rules. |
em_event_can_manage | $can_manage, $EM_Event, $owner_capability, $admin_capability, $user_to_check | Change who may edit an event. |
em_event_get_permalink | $url, $EM_Event | Change the link to an event. |
em_event_output_placeholder | $replace, $EM_Event, $full_result, $target, $placeholder_atts | Add or change an event placeholder. $full_result is the placeholder as written, such as #_EVENTNAME. $target is the output type: html, email, rss, ical, map or raw. |
em_location_output_placeholder, em_booking_output_placeholder | same shape | Add or change location and booking placeholders. |
em_event_output_show_condition | $show, $condition, $full_match, $EM_Event | Add or change an event conditional placeholder. $condition is the name between the braces. |
em_event_output | $output, $EM_Event, $format, $target | Change an event's formatted output. |
em_events_get_default_search | $args, $array, $defaults | Register a search attribute. $array is what the caller passed in. |
em_events_build_sql_conditions | $conditions, $args | Add a WHERE condition to event queries. |
em_events_get | $events, $args | Change the events a query returns. |
em_events_output | $output, $events, $args, $events_count | Change the HTML of an events list. |
em_accepted_searches | $accepted_searches, $args | Allow a request variable from the search form through to the query. |
em_get_scopes | $scopes | Add a scope to the search form's list. See Custom event scopes. |
em_content_pre | $content, $page_content | Replace what the events page shows. Return a non-empty string to take over. |
em_content | $content | Change the finished content of an Events Manager page. |
em_content_page_title_pre | $title, $original_title | Replace the title of an Events Manager page. |
em_locate_template | $located, $template_name, $load, $args | Load a template from somewhere else. |
em_rewrite_rules_array_events | $rules, $events_slug | Add rewrite rules under the events page. |
em_ms_globals | $option_names | On multisite, store more options network-wide. |
em_get_currencies | $currencies | Add or rename a currency. |
Examples
Block a booking
Validation filters receive the result so far. Add an error and return false to stop the booking and show the visitor your message.
add_filter( 'em_booking_validate', function ( $result, $EM_Booking ) {
if ( ! $result || ! is_user_logged_in() || $EM_Booking->booking_id ) {
return $result;
}
$existing = $EM_Booking->get_event()->get_bookings()->has_booking( get_current_user_id() );
if ( $existing ) {
$EM_Booking->add_error( __( 'You have already booked this event.', 'my-plugin' ) );
return false;
}
return $result;
}, 10, 2 );
Events Manager already does this when Allow double bookings? is off in Events then Settings then Bookings then General Options. The example shows the shape of a validation filter.
React when a booking is confirmed
add_action( 'em_booking_status_changed', function ( $EM_Booking, $args ) {
if ( (int) $EM_Booking->booking_status === 1 ) {
// 1 is Approved. Send the booking to your CRM, for example.
do_action( 'my_plugin_booking_confirmed', $EM_Booking->booking_id, $EM_Booking->get_person()->user_email );
}
}, 10, 2 );
Add a placeholder
add_filter( 'em_event_output_placeholder', function ( $replace, $EM_Event, $full_result ) {
if ( $full_result === '#_EVENTYEAR' ) {
$replace = esc_html( $EM_Event->start()->format( 'Y' ) );
}
return $replace;
}, 10, 3 );