Created
February 26, 2020 15:54
-
-
Save Pebblo/ddea6d317b20fa2e9f69c17792658399 to your computer and use it in GitHub Desktop.
This snippet fixes the 'Month/Year' dropdown on Event Espresso -> Events when our site is set not to use a year i the date format.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter('FHEE__Events_Admin_Page__get_events__where', 'tw_ee_fix_month_year_dropdown_with_no_year', 10, 2); | |
function tw_ee_fix_month_year_dropdown_with_no_year( $where, $req_data ) { | |
// If month_range is empty, we have nothing to do here. | |
if(empty($req_data['month_range'])) { | |
return $where; | |
} | |
if (isset($req_data['month_range'])) { | |
$pieces = explode(' ', $req_data['month_range'], 3); | |
// simulate the FIRST day of the month, that fixes issues for months like February | |
// where PHP doesn't know what to assume for date. | |
// @see https://events.codebasehq.com/projects/event-espresso/tickets/10437 | |
$month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : ''; | |
$year_r = ! empty($pieces[1]) ? $pieces[1] : ''; | |
} | |
$DateTime = new DateTime( | |
$year_r . '-' . $month_r . '-01 00:00:00', | |
new DateTimeZone('UTC') | |
); | |
$start = $DateTime->getTimestamp(); | |
// set the datetime to be the end of the month | |
$DateTime->setDate( | |
$year_r, | |
$month_r, | |
$DateTime->format('t') | |
)->setTime(23, 59, 59); | |
$end = $DateTime->getTimestamp(); | |
$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); | |
return $where; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment