Filter
uncanny-automator
uap_option_all_em_events
Filters the list of all EM events data before it's saved to options.
add_filter( 'uap_option_all_em_events', $callback, 10, 1 );
Description
Filters the options array used to display all Events Manager events in Ultimate Affiliate Pro. Developers can modify this array to customize the data passed to the frontend for event selection, influencing which events are available for affiliate tracking or selection. This hook fires before the options are returned.
Usage
add_filter( 'uap_option_all_em_events', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter is used to specify the label for the events option in the Events Manager integration.
Return Value
The filtered value.
Examples
/**
* Example of how to filter the 'uap_option_all_em_events' hook.
* This example demonstrates how to add a custom event to the list
* of available Events Manager events.
*
* @param array $option The array of options passed to the filter.
* @return array The modified array of options.
*/
add_filter( 'uap_option_all_em_events', function( $option ) {
// Check if the 'options' key exists and is an array before proceeding.
if ( !isset( $option['options'] ) || !is_array( $option['options'] ) ) {
// If not, return the original $option to avoid errors.
return $option;
}
// Define our custom event.
$custom_event = array(
'id' => 'custom_event_id', // A unique identifier for the custom event.
'name' => esc_html__( 'My Custom Event', 'your-text-domain' ), // The display name for the custom event.
);
// Add our custom event to the existing 'options' array.
$option['options'][] = $custom_event;
// Return the modified $option array with the custom event included.
return $option;
}, 10, 1 );
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/integrations/events-manager/helpers/events-manager-helpers.php:110
public function all_em_events( $label = null, $option_code = 'EMALLEVENTS', $args = array() ) {
if ( ! $label ) {
$label = esc_attr_x( 'Event', 'Events Manager', 'uncanny-automator' );
}
$token = key_exists( 'token', $args ) ? $args['token'] : false;
$is_ajax = key_exists( 'is_ajax', $args ) ? $args['is_ajax'] : false;
$target_field = key_exists( 'target_field', $args ) ? $args['target_field'] : '';
$end_point = key_exists( 'endpoint', $args ) ? $args['endpoint'] : '';
$any_option = key_exists( 'any_option', $args ) ? $args['any_option'] : false;
$relevant_tokens = key_exists( 'relevant_tokens', $args ) ? $args['relevant_tokens'] : '';
$options = array();
if ( isset( $any_option ) && true == $any_option ) {
$options['-1'] = esc_attr_x( 'Any event', 'Events Manager', 'uncanny-automator' );
}
$default_tokens = array();
global $wpdb;
$all_events = $wpdb->get_results(
$wpdb->prepare(
"SELECT event_id,event_name FROM {$wpdb->prefix}em_events WHERE event_status = %d ORDER BY event_name",
1
)
);
foreach ( $all_events as $event ) {
$title = $event->event_name;
if ( empty( $title ) ) {
// translators: 1: Event ID
$title = sprintf( esc_attr_x( 'ID: %s (no title)', 'Events Manager', 'uncanny-automator' ), $event->event_id );
}
$options[ $event->event_id ] = $title;
}
if ( ! empty( $relevant_tokens ) ) {
$default_tokens = array_merge( $default_tokens, $relevant_tokens );
}
$option = array(
'option_code' => $option_code,
'label' => $label,
'input_type' => 'select',
'required' => true,
'supports_tokens' => $token,
'is_ajax' => $is_ajax,
'fill_values_in' => $target_field,
'endpoint' => $end_point,
'options' => $options,
'relevant_tokens' => $default_tokens,
);
return apply_filters( 'uap_option_all_em_events', $option );
}