Skip to content

Instantly share code, notes, and snippets.

@codearachnid
Created April 12, 2012 22: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 codearachnid/2371627 to your computer and use it in GitHub Desktop.
Save codearachnid/2371627 to your computer and use it in GitHub Desktop.
Tri.be Event Calendar getMonthOptions bugfix
<?php
/**
* The issue is in lib/tribe-view-helpers.class.php and exists in the getMonthOptions function.
* The date that is passed in by default "2012-04-01-01" has an extra '-01' appended to it.
* I am unsure where this is getting added to the date, but adding str_replace( '01-01', '01', $date )
* to remove those extra characters fixes the output.
*/
/**
* Builds a set of options for displaying a month chooser
* @param string the current date to select (optional)
* @return string a set of HTML options with all months (current month selected)
*/
public static function getMonthOptions($date = "") {
$tribe_ecp = TribeEvents::instance();
$months = $tribe_ecp->monthNames();
$options = '';
if (empty($date)) {
$month = ( date_i18n('j') == date_i18n('t') ) ? date('F', time() + 86400) : date_i18n('F');
} else {
// get rid of extra -01
$date = str_replace( '01-01', '01', $date );
$month = date('F', strtotime($date));
}
$monthIndex = 1;
foreach ($months as $englishMonth => $monthText) {
if ($monthIndex < 10) {
$monthIndex = "0" . $monthIndex; // need a leading zero in the month
}
if ($month == $englishMonth) {
$selected = 'selected="selected"';
} else {
$selected = '';
}
$options .= "<option value='$monthIndex' $selected>$monthText</option>\n";
$monthIndex++;
}
return $options;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment