Skip to main content

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.

Before you start

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}
ObjectClassExamples
eventEM_Eventem_event_save, em_event_validate, em_event_delete
eventsEM_Events (queries and lists)em_events_get, em_events_output, em_events_build_sql_conditions
location, locationsEM_Location, EM_Locationsem_location_save, em_locations_get_default_search
booking, bookingsEM_Booking, EM_Bookingsem_booking_save, em_booking_set_status, em_bookings_added
ticket, ticket_bookingEM_Ticket, EM_Ticket_Bookingem_ticket_is_available, em_ticket_booking_output_placeholder
category, tagEM_Category, EM_Tagem_category_output_placeholder
calendarEM_Calendarem_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() returns apply_filters( 'em_event_save', $result, $this ). The first argument is the result so far (often true or false for success) and the second is the object. Return the first argument, changed or not.
  • An action ending in _pre fires before the method does its work, for example em_event_save_pre and em_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:

StepFilterWhat the method does
1em_event_get_postReads the submitted form into the object.
2em_event_validateChecks the object. Add to $EM_Event->errors with $EM_Event->add_error() and return false to block the save.
3em_event_saveWrites 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:

FilterPurpose
em_{object}_output_placeholderChange the replacement for one placeholder, or add a placeholder of your own. Objects: event, location, booking, ticket_booking, category, tag.
em_{object}_output_show_conditionDecide whether a conditional placeholder block is shown, or add a condition of your own. Objects: event, location, booking, ticket_booking.
em_{object}_outputChange 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:

FilterPurpose
em_{objects}_get_default_searchAdd or change accepted search attributes and their defaults.
em_{objects}_build_sql_conditionsAdd or change the WHERE conditions, as an array of SQL fragments joined with AND. Available for events and locations.
em_{objects}_getChange the array of objects a query returns.
em_{objects}_outputChange 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:

Log every em_ hook fired on a request
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.

ActionArgumentsFires
events_manager_loadednoneOn 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_byWhen an event object has loaded.
em_location$EM_Location, $id, $search_byWhen a location object has loaded.
em_booking$EM_Booking, $booking_dataWhen a booking object has loaded.
em_event_save_pre$EM_EventBefore an event is written.
em_booking_add$EM_Event, $EM_Booking, $post_validationWhen 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, $mailAfter a new booking is saved for the first time.
em_bookings_added$EM_BookingAfter a booking made through an event's booking form has been saved.
em_booking_status_changed$EM_Booking, $argsAfter a booking's status has changed and before emails go out. $args holds status, email and ignore_spaces.
em_booking_deleted$EM_BookingAfter a booking is deleted.
em_booking_email_before_send, em_booking_email_after_send$EM_BookingAround the emails for a booking.
em_booking_form_after_user_details$EM_Event, $EM_BookingInside 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_EventAt the bottom of the front-end event submission form.
em_template_search_form_footer$argsInside the main search bar, before the submit button.
em_search_form_advanced_sections_footer$argsAt the end of the advanced search sections.
em_template_before_{template_name}, em_template_after_{template_name}$argsAround every template file.

Filters used most often​

FilterArgumentsUse it to
em_event_get_post$result, $EM_EventRead your own fields from a submitted event form.
em_event_validate$result, $EM_EventReject an event that fails your own checks.
em_event_save$result, $EM_EventStore your own data when an event is saved.
em_event_delete$result, $EM_EventClean up your data when an event is deleted.
em_location_save$result, $EM_LocationStore your own data with a location.
em_booking_get_post$result, $EM_BookingRead your own fields from the booking form.
em_booking_validate$result, $EM_BookingBlock a booking. Add a message with $EM_Booking->add_error() and return false.
em_booking_save$result, $EM_Booking, $updateAct when a booking is created or updated. $update is true for an existing booking.
em_booking_set_status$result, $EM_BookingAct on a status change before its emails are sent.
em_booking_delete$result, $EM_BookingClean up your data when a booking is deleted.
em_booking_get_price$price, $EM_BookingAdjust 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_checkChange who may edit an event.
em_event_get_permalink$url, $EM_EventChange the link to an event.
em_event_output_placeholder$replace, $EM_Event, $full_result, $target, $placeholder_attsAdd 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_placeholdersame shapeAdd or change location and booking placeholders.
em_event_output_show_condition$show, $condition, $full_match, $EM_EventAdd or change an event conditional placeholder. $condition is the name between the braces.
em_event_output$output, $EM_Event, $format, $targetChange an event's formatted output.
em_events_get_default_search$args, $array, $defaultsRegister a search attribute. $array is what the caller passed in.
em_events_build_sql_conditions$conditions, $argsAdd a WHERE condition to event queries.
em_events_get$events, $argsChange the events a query returns.
em_events_output$output, $events, $args, $events_countChange the HTML of an events list.
em_accepted_searches$accepted_searches, $argsAllow a request variable from the search form through to the query.
em_get_scopes$scopesAdd a scope to the search form's list. See Custom event scopes.
em_content_pre$content, $page_contentReplace what the events page shows. Return a non-empty string to take over.
em_content$contentChange the finished content of an Events Manager page.
em_content_page_title_pre$title, $original_titleReplace the title of an Events Manager page.
em_locate_template$located, $template_name, $load, $argsLoad a template from somewhere else.
em_rewrite_rules_array_events$rules, $events_slugAdd rewrite rules under the events page.
em_ms_globals$option_namesOn multisite, store more options network-wide.
em_get_currencies$currenciesAdd 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.

Limit each account to one booking per event
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​

Run code when a booking becomes Approved
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 #_EVENTYEAR to event formats
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 );