示例#1
0
function acf_hidden_input($atts)
{
    echo acf_get_hidden_input($atts);
}
示例#2
0
 function render_field($field)
 {
     // vars
     $i = 0;
     $e = '';
     $ul = array('class' => 'acf-radio-list', 'data-allow_null' => $field['allow_null'], 'data-other_choice' => $field['other_choice']);
     // append to class
     $ul['class'] .= ' ' . ($field['layout'] == 'horizontal' ? 'acf-hl' : 'acf-bl');
     $ul['class'] .= ' ' . $field['class'];
     // select value
     $checked = '';
     $value = strval($field['value']);
     // selected choice
     if (isset($field['choices'][$value])) {
         $checked = $value;
         // custom choice
     } elseif ($field['other_choice'] && $value !== '') {
         $checked = 'other';
         // allow null
     } elseif ($field['allow_null']) {
         // do nothing
         // select first input by default
     } else {
         $checked = key($field['choices']);
     }
     // ensure $checked is a string (could be an int)
     $checked = strval($checked);
     // other choice
     if ($field['other_choice']) {
         // vars
         $input = array('type' => 'text', 'name' => $field['name'], 'value' => '', 'disabled' => 'disabled', 'class' => 'acf-disabled');
         // select other choice if value is not a valid choice
         if ($checked === 'other') {
             unset($input['disabled']);
             $input['value'] = $field['value'];
         }
         // append other choice
         $field['choices']['other'] = '</label><input type="text" ' . acf_esc_attr($input) . ' /><label>';
     }
     // bail early if no choices
     if (empty($field['choices'])) {
         return;
     }
     // hiden input
     $e .= acf_get_hidden_input(array('name' => $field['name']));
     // open
     $e .= '<ul ' . acf_esc_attr($ul) . '>';
     // foreach choices
     foreach ($field['choices'] as $value => $label) {
         // ensure value is a string
         $value = strval($value);
         $class = '';
         // increase counter
         $i++;
         // vars
         $atts = array('type' => 'radio', 'id' => $field['id'], 'name' => $field['name'], 'value' => $value);
         // checked
         if ($value === $checked) {
             $atts['checked'] = 'checked';
             $class = ' class="selected"';
         }
         // deisabled
         if (isset($field['disabled']) && acf_in_array($value, $field['disabled'])) {
             $atts['disabled'] = 'disabled';
         }
         // id (use crounter for each input)
         if ($i > 1) {
             $atts['id'] .= '-' . $value;
         }
         // append
         $e .= '<li><label' . $class . '><input ' . acf_esc_attr($atts) . '/>' . $label . '</label></li>';
     }
     // close
     $e .= '</ul>';
     // return
     echo $e;
 }