Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Long events in widget calendar causing dates to be modified #159

Closed
stephenharris opened this issue Nov 1, 2013 · 1 comment
Closed
Labels

Comments

@stephenharris
Copy link
Owner

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.

@stephenharris
Copy link
Owner Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant