tribe_events_template_data( $event = null, $additional = null )
Returns json for javascript templating functions throughout the plugin.
Contents
Parameters
- $event
-
(Optional)
Default value: null
- $additional
-
(Optional)
Default value: null
Return
(string)
Source
File: src/functions/template-tags/general.php
function tribe_events_template_data( $event = null, array $additional = null ) { // Base JSON variable $json = array( 'i18n' => array(), ); if ( ! is_null( $event ) ) { $event = get_post( $event ); // Check if we are dealing with an Event if ( is_object( $event ) && $event instanceof WP_Post && tribe_is_event( $event->ID ) ) { $has_image = false; $image_src = ''; $image_tool_src = ''; /** * Fires before the $date_display is called * * @since 4.7.2 * * @param $event */ do_action( 'tribe_events_before_event_template_data_date_display', $event ); $date_display = strip_tags( tribe_events_event_schedule_details( $event ) ); /** * Fires after the $date_display is called * * @since 4.7.2 * * @param $event */ do_action( 'tribe_events_after_event_template_data_date_display', $event ); if ( function_exists( 'has_post_thumbnail' ) && has_post_thumbnail( $event->ID ) ) { $has_image = true; $image_src = tribe_event_featured_image( $event->ID, 'large', false, false ); $image_tool_src = tribe_event_featured_image( $event->ID, 'medium', false, false ); } $category_classes = tribe_events_event_classes( $event->ID, false ); $day = tribe_events_get_current_month_day(); $event_id = "{$event->ID}-{$day['date']}"; $json['eventId'] = $event_id; $json['title'] = wp_kses_post( apply_filters( 'the_title', $event->post_title, $event->ID ) ); $json['permalink'] = tribe_get_event_link( $event->ID ); $json['imageSrc'] = $image_src; $json['dateDisplay'] = $date_display; $json['imageTooltipSrc'] = $image_tool_src; $json['excerpt'] = ! post_password_required( $event ) ? tribe_events_get_the_excerpt( $event, null, true ) : ''; $json['categoryClasses'] = $category_classes; /** * Template overrides (of month/tooltip.php) set up in 3.9.3 or earlier may still expect * these vars and will break without them, so they are being kept temporarily for * backwards compatibility purposes. * * @todo consider removing in 4.0 */ $json['startTime'] = tribe_get_start_date( $event ); $json['endTime'] = tribe_get_end_date( $event ); } } /** * Internationalization Strings */ $json['i18n']['find_out_more'] = esc_attr__( 'Find out more »', 'the-events-calendar' ); $json['i18n']['for_date'] = sprintf( esc_attr__( '%s for', 'the-events-calendar' ), tribe_get_event_label_plural() ); if ( $additional ) { $json = array_merge( (array) $json, (array) $additional ); } $json = apply_filters( 'tribe_events_template_data_array', $json, $event, $additional ); $json = tribe_prepare_for_json_deep( $json ); return json_encode( $json ); }