Skip to content

Commit

Permalink
Merge pull request #3 from dinc5150/master
Browse files Browse the repository at this point in the history
Update V5 to have default value setting
  • Loading branch information
DocWatson authored Aug 2, 2016
2 parents dedc0f6 + 834ae91 commit b541ff7
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion acf-timezone_picker-v5.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,40 @@ function __construct() {
}


/*
* render_field_settings()
*
* Create extra settings for your field. These are visible when editing a field
*
* @type action
* @since 3.6
* @date 23/01/13
*
* @param $field (array) the $field being edited
* @return n/a
*/

function render_field_settings( $field ) {

/*
* acf_render_field_setting
*
* This function will create a setting for your field. Simply pass the $field parameter and an array of field settings.
* The array of settings does not require a `value` or `prefix`; These settings are found from the $field array.
*
* More than one setting can be added by copy/paste the above code.
* Please note that you must also have a matching $defaults value for the field name (font_size)
*/

acf_render_field_setting( $field, array(
'label' => __('Default Timezone','acf-FIELD_NAME'),
'instructions' => __('e.g. Country/City (Australia/Sydney)','acf-FIELD_NAME'),
'type' => 'text',
'name' => 'default_time_zone',
));
}


/*
* render_field()
*
Expand All @@ -77,14 +111,18 @@ function render_field( $field ) {
*/
$utc = new DateTimeZone('UTC');
$dt = new DateTime('now', $utc);
$fieldValue = trim($field['value']);
if(!$fieldValue && $field['default_time_zone']){
$fieldValue = trim($field['default_time_zone']);
}
?>
<select name="<?php echo esc_attr($field['name']) ?>">
<?php
foreach (\DateTimeZone::listIdentifiers() as $tz) {
$current_tz = new \DateTimeZone($tz);
$transition = $current_tz->getTransitions($dt->getTimestamp(), $dt->getTimestamp());
$abbr = $transition[0]['abbr'];
$is_selected = trim($field['value']) === trim($tz) ? ' selected="selected"' : '';
$is_selected = $fieldValue === trim($tz) ? ' selected="selected"' : '';
?>
<option value="<?php echo $tz; ?>"<?php echo $is_selected;?>><?php echo $tz . ' (' . $abbr . ')'; ?></option>
<?php } ?>
Expand Down

0 comments on commit b541ff7

Please sign in to comment.