Skip to content

Instantly share code, notes, and snippets.

@andrasguseo
Last active February 9, 2017 00:05
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 andrasguseo/d252c9e0c85c96e5a2bcfe36b0d09031 to your computer and use it in GitHub Desktop.
Save andrasguseo/d252c9e0c85c96e5a2bcfe36b0d09031 to your computer and use it in GitHub Desktop.
A Snippet for List View Multi Day Events Start Time - The Events Calendar
<?php
/*
Plugin Name: A Snippet for List View Multi Day Events Start Time - The Events Calendar
Plugin URI: http://theeventscalendar.com
Description: This plugin changes the List View Start Times for Multiple Day Events.
A long term that starts in the past shows up in the current month rather than appearing in its own month.
For example if an exhibition runs for a year from 1 April 2016 – 1 April 2017, it would currently mean
that the calendar would have a April 2016 section at the top which just looks like you have out of date info.
With this plugin the starting date of the event would always be the actual day.
Usage: Best is to save this code in a separate file ad put it in your wp-content/plugins folder, then
activate it on the Plugins page in your WordPress dashboard.
Author: brianjessee, aguseo
Version: 1.1
Author URI: http://theeventscalendar.com
*/
/**
* Example if an Event runs from May 1st to June 31st when visiting the list view on June 10th
* it looks like the first event is in May, but it is currently June. This snippet changes it
* so it displays JUne 10th as the start date in the list view.
*/
if ( ! function_exists( 'tribe_get_start_date' ) ) {
/**
* Start Date
*
* Returns the event start date and time
*
* @category Events
*
* @param int $event (optional)
* @param bool $display_time If true shows date and time, if false only shows date
* @param string $date_format Allows date and time formating using standard php syntax (http://php.net/manual/en/function.date.php)
* @param string $timezone Timezone in which to present the date/time (or default behaviour if not set)
*
* @return string|null Date
*/
function tribe_get_start_date( $event = null, $display_time = true, $date_format = '', $timezone = null ) {
if ( is_null( $event ) ) {
global $post;
$event = $post;
}
if ( is_numeric( $event ) ) {
$event = get_post( $event );
}
if ( ! is_object( $event ) ) {
return '';
}
if ( Tribe__Date_Utils::is_all_day( get_post_meta( $event->ID, '_EventAllDay', true ) ) ) {
$display_time = false;
}
// @todo move timezones to Common
if ( class_exists( 'Tribe__Events__Timezones' ) ) {
$start_date = Tribe__Events__Timezones::event_start_timestamp( $event->ID, $timezone );
} else {
return null;
}
if ( tribe_is_list_view() && ! tribe_is_past() ) {
//echo $start_date . ' start <br>';
$blogtime = current_time( 'timestamp' );
//echo strtotime( $cc_blogtime ) . ' mysql <br>';
if ( $start_date < $blogtime ) {
//echo $start_date . 'less <br>';
$start_date = $blogtime;
//echo $start_date . 'new <br>';
}
}
return tribe_format_date( $start_date, $display_time, $date_format );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment