Skip to content

Instantly share code, notes, and snippets.

@bordoni
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bordoni/420661affe489e08fd5e to your computer and use it in GitHub Desktop.
Save bordoni/420661affe489e08fd5e to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: The Events Calendar: Snippet 945349
* Plugin URI: https://gist.github.com/bordoni/420661affe489e08fd5e
* Description: Wendy requested a snippet to use new data on Month and Week tooltips
* Version: 0.1.0
* Author: Gustavo Bordoni
* Author URI: http://bordoni.me
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ){
die;
}
class TEC_Forum_945349 {
public static $ID = 945349;
public static $_instance = null;
public function __construct(){
add_filter( 'tribe_events_template_data_array', array( __CLASS__, 'template_data_array' ), 10, 3 );
add_filter( 'tribe_events_template_paths', array( __CLASS__, 'template_paths' ) );
add_filter( 'tribe_events_template', array( __CLASS__, 'template' ), 10, 2 );
}
public static function instance(){
if ( ! is_a( self::$_instance, __CLASS__ ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
public static function template_data_array( $json, $event, $additional ){
$json['venue'] = '';
$json['organizer'] = '';
$json['price'] = '';
$venue = tribe_get_venue_id( $event );
if ( $venue ){
$json['venue'] = $venue;
$json['venue_link'] = tribe_get_venue_link( $venue, false );
$json['venue_title'] = tribe_get_venue( $venue );
}
$organizer = tribe_get_organizer( $event );
if ( $organizer ){
$json['organizer'] = $organizer;
}
if ( function_exists( 'wootickets_init' ) && false === true ){
$tickets = TribeWooTickets::get_instance()->get_tickets_ids( $event );
if ( ! empty( $tickets ) ){
$min = PHP_INT_MAX;
$max = -1;
foreach ( $tickets as $ticket ) {
$ticket = TribeWooTickets::get_instance()->get_ticket( $event, $ticket );
$min = min( array( $min, $ticket->price ) );
$max = max( array( $max, $ticket->price ) );
}
if ( $min == $max ){
$json['price'] = wc_price( $min );
} else {
$json['price'] = 'from ' . wc_price( $min ) . ' to ' . wc_price( $max );
}
}
}
return $json;
}
public static function template_paths( $bases ){
return array( 'forum-' . self::$ID => plugin_dir_path( __FILE__ ) ) + $bases;
}
public static function template( $file, $template ){
if ( 'month/tooltip.php' !== $template || false === strpos( $file, plugin_dir_path( __FILE__ ) ) ) {
return $file;
}
return plugin_dir_path( __FILE__ ) . 'view-month-tooltip.php';
}
}
TEC_Forum_945349::instance();
<script type="text/html" id="tribe_tmpl_tooltip">
<div id="tribe-events-tooltip-[[=eventId]]" class="tribe-events-tooltip">
<h4 class="entry-title summary">[[=title]]</h4>
<div class="tribe-events-event-body">
<div class="duration">
<abbr class="tribe-events-abbr updated published dtstart">[[=dateDisplay]] </abbr>
</div>
[[ if(imageTooltipSrc.length) { ]]
<div class="tribe-events-event-thumb">
<img src="[[=imageTooltipSrc]]" alt="[[=title]]" />
</div>
[[ } ]]
[[ if(excerpt.length) { ]]
<p class="entry-summary description">[[=raw excerpt]]</p>
[[ } ]]
[[ if(venue) { ]]
<div class="entry-venue">Venuet: <a href="[[=venue_link]]">[[=venue_title]]</a></div>
[[ } ]]
[[ if(organizer) { ]]
<div class="entry-organizer">Organizer: [[=raw organizer]]</div>
[[ } ]]
[[ if(price) { ]]
<div class="entry-price">Price: [[=raw price]]</a></div>
[[ } ]]
<span class="tribe-events-arrow"></span>
</div>
</div>
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment