Skip to content

Instantly share code, notes, and snippets.

@Pebblo
Created February 26, 2020 15:54
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 Pebblo/ddea6d317b20fa2e9f69c17792658399 to your computer and use it in GitHub Desktop.
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.
<?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