andersonpg
Forum Replies Created
Viewing 1 replies (of 1 total)
-
Forum: Plugins
In reply to: [The Events Calendar] Limit time zone in dropdown menu?Thanks! That pointed me in the right direction. If anyone else is interested, here is the code I used via a snippets plugin to limit the time zones:
<?php
add_filter( 'tribe_events_timezone_choice', 'limit_timezone' );
function limit_timezone( $timezone_selector_html ) {
$retain = [
'Honolulu', // UTC-10
'Anchorage', // UTC-9
'Los Angeles', // UTC-8
'Phoenix', // UTC-7
'Denver', // UTC-7
'Chicago', // UTC-6
'New York', // UTC-5
];
$html = '';
$lines = explode( "\n", $timezone_selector_html );
$i = 0;
while ( $i < count( $lines ) ) {
$line = $lines[$i];
if ( 0 === strpos( $line, '<optgroup ' ) ) {
// Look ahead to check if the optgroup is empty
$j = $i + 1;
$optgroup_empty = true;
while ( $j < count( $lines ) && 0!== strpos( $lines[$j], '</optgroup>' ) ) {
if ( 0 === strpos( $lines[$j], '<option ' ) ) {
foreach ( $retain as $acceptable_timezone ) {
if ( false!== strpos( $lines[$j], ">$acceptable_timezone<" ) ) {
$optgroup_empty = false;
break 2;
}
}
}
$j++;
}
if (! $optgroup_empty ) {
$html.= "$line\n";
}
$i = $j;
} elseif ( 0 === strpos( $line, '<option ' ) ) {
// Check if this option is in the $retain list
foreach ( $retain as $acceptable_timezone ) {
if ( false!== strpos( $line, ">$acceptable_timezone<" ) ) {
$html.= "$line\n";
break;
}
}
$i++;
} else {
$html.= "$line\n";
$i++;
}
}
return $html;
}
?>
Viewing 1 replies (of 1 total)