Skip to content

Instantly share code, notes, and snippets.

@damiencarbery
Created September 8, 2025 10:29
Show Gist options
  • Save damiencarbery/a3753707a4f570f3a59b8d68d1fea069 to your computer and use it in GitHub Desktop.
Save damiencarbery/a3753707a4f570f3a59b8d68d1fea069 to your computer and use it in GitHub Desktop.
Events Manager - custom placeholder demos - Demonstration of static and dynamic custom placeholder tags for Events Manager. https://www.damiencarbery.com/2025/09/events-manager-custom-placeholders/
<?php
/*
* Plugin Name: Events Manager - custom placeholder demos
* Description: Demonstration of static and dynamic custom placeholder tags for Events Manager.
* Plugin URI: https://www.damiencarbery.com/2025/09/events-manager-custom-placeholders/
* Author: Damien Carbery
* Author URI: https://www.damiencarbery.com
* Requires Plugins: events-manager
* Version: 0.1.20250908
*/
defined( 'ABSPATH' ) || exit;
// {closing_soon} placeholder.
add_action( 'em_event_output_show_condition', 'dcwd_show_closing_soon_placeholder', 10, 4 );
function dcwd_show_closing_soon_placeholder( $show, $condition, $full_match, $event ){
if ( 'closing_soon' == $condition ) {
$full_day = 86400; // 86,400 seconds = 24 hours.
// Check that bookings are open and it has a booking closing time set.
if ( $event->get_bookings()->is_open() && $event->get_bookings()->has_open_time() ) {
if ( $event->rsvp_end()->getTimestamp() - time() < $full_day ) {
return true;
}
}
}
return $show;
}
// {tickets_remaining} placeholder.
add_action( 'em_event_output_show_condition', 'dcwd_show_tickets_remaining_placeholder', 10, 4 );
function dcwd_show_tickets_remaining_placeholder( $show, $condition, $full_match, $event ){
if ( 'tickets_remaining' == $condition ) {
if ( $event->event_rsvp && $event->get_bookings()->get_available_spaces() > 0 ) {
$avail_spaces = $event->get_bookings()->get_available_spaces();
//$event->get_spaces() - $event->get_booked_spaces();
$spaces = $event->get_spaces();
//error_log( sprintf( 'Avail: %d, spaces: %d; Percent: %d; %s', $avail_spaces, $spaces, intval( $avail_spaces * 100 / $spaces ), $event->event_name ) );
$avail_spaces_percent = intval( $avail_spaces * 100 / $spaces );
if ( $avail_spaces_percent <= 20 ) {
return true;
}
}
}
return $show;
}
// {ticket_count} placeholder - show it.
add_action( 'em_event_output_show_condition', 'dcwd_show_ticket_count_placeholder', 1, 4 );
function dcwd_show_ticket_count_placeholder( $show, $condition, $full_match, $event ){
if ( 'ticket_count' == $condition ) { return true; }
return $show;
}
// {ticket_count} placeholder - process it.
add_filter('em_event_output_condition', 'dcwd_process_ticket_count_placeholder', 10, 4 );
function dcwd_process_ticket_count_placeholder( $replacement, $condition, $conditionals_key, $event) {
if ( 'ticket_count' == $condition ) {
// Check that bookings are open and it's not booked out.
if ( $event->event_rsvp && $event->get_bookings()->is_open() && $event->get_bookings()->get_available_spaces() > 0 ) {
return sprintf( $replacement, $event->get_bookings()->get_available_spaces() );
}
return '';
}
return $replacement;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment