stephenharris / Event-Organiser

WordPress plug-in, Event Organiser, development repository

Home Page:http://wordpress.org/extend/plugins/event-organiser/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Long events in widget calendar causing dates to be modified

stephenharris opened this issue · comments

As reported here: http://wordpress.org/support/topic/event-that-spans-more-than-one-day-gets-wrong-startdate

So I've identified a problem with the Event Calendar Widget. If you have enabled the option to show long events, the query from the Calendar Widget modifies the data start-date stored for the event in wp_cache.

Example: I have an event that spans 2013-10-29 to 2013-10-31. The first call to eo_get_the_occurrences_of(17091) does a database query and returns the correct date.

The next call to the same function with the same ID correctly returns the data from the cache, with the correct start_date (2013-10-29).

However, the third call (the second to the cache) returns 2013-11-01 as start-date, still for the same event with the same event id (17091).

In my template, the sidebar is called before the loop, so the Event Calendar Widget is the responsible function for these first eo_get_the_occurrences_of-queries.
If I disable the widget, the start-date never is modified and the loop displays the correct start-date. I have from my loop done several (repeatedly) calls to eo_get_the_occurrences_of to the same ID but the start-date stays the same, unmodified.

Given the code, this is entirely correct behaviour: http://php.net/manual/en/language.oop5.references.php E.g.:

function return_a_date(){

    static $date = false; 
    if( !$date )
        $date = new DateTime( '2013-11-01 01:47:00');

    return $date;
}

$mydate = return_a_date(); //Returns 2013-11-01
$mydate->modify('+1 day');
echo $mydate->format('Y-m-d'); //Prints 2013-11-02 as expected

$mydate2 = return_a_date();
echo $mydate2->format('Y-m-d'); //Prints 2013-11-02.

Solution is to clone the date and modify that.