Skip to content

Instantly share code, notes, and snippets.

@barryhughes
Created August 7, 2018 12:15
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 barryhughes/49b8ae0fce2f9f611e68f00bc880caa9 to your computer and use it in GitHub Desktop.
Save barryhughes/49b8ae0fce2f9f611e68f00bc880caa9 to your computer and use it in GitHub Desktop.
Alter the date presented within month view tooltips for multiday events.
<?php
/**
* Modifies the month view tooltip for multiday events.
*
* Instead of seeing "5 - 15 August", the tooltip for multiday event will show
* the date of the cell which contains it.
*
* For example, if a visitor hovers over the multiday event name within the cell
* for 11 August, the tooltip will now display "11 August" etc.
*/
class Month_View_Multiday_Event_Tooltip_Modifier {
private $current_day;
public function __construct() {
add_filter( 'tribe_events_get_current_month_day', [ $this, 'capture_day' ] );
add_filter( 'tribe_events_template_data_array', [ $this, 'replace_date' ], 10, 2 );
}
public function capture_day( $day ) {
$this->save_formatted_day( $day );
return $day;
}
private function save_formatted_day( $day ) {
if ( ! is_array( $day ) || empty( $day['date'] ) ) {
$this->current_day = '';
return;
}
$this->current_day = tribe_format_date( $day['date'] );
}
public function replace_date( $tooltip_data, $event = false ) {
if ( ! $event ) {
return $tooltip_data;
}
if ( tribe_event_is_multiday( $event->ID ) && ! empty( $this->current_day ) ) {
$tooltip_data['dateDisplay'] = $this->current_day;
}
return $tooltip_data;
}
}
new Month_View_Multiday_Event_Tooltip_Modifier;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment