name = 'radio'; $this->label = __("Radio Button",'acf'); $this->category = 'choice'; $this->defaults = array( 'layout' => 'vertical', 'choices' => array(), 'default_value' => '', 'other_choice' => 0, 'save_other_choice' => 0, 'allow_null' => 0, 'return_format' => 'value' ); } /* * render_field() * * Create the HTML interface for your field * * @param $field (array) the $field being rendered * * @type action * @since 3.6 * @date 23/01/13 * * @param $field (array) the $field being edited * @return n/a */ function render_field( $field ) { // vars $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']; // Determine selected value. $value = (string) $field['value']; // 1. Selected choice. if( isset( $field['choices'][ $value ] ) ) { $checked = (string) $value; // 2. Custom choice. } elseif( $field['other_choice'] && $value !== '' ) { $checked = 'other'; // 3. Empty choice. } elseif( $field['allow_null'] ) { $checked = ''; // 4. Default to first choice. } else { $checked = (string) key( $field['choices'] ); } // other choice $other_input = false; if( $field['other_choice'] ) { // Define other input attrs. $other_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( $other_input['disabled'] ); $other_input['value'] = $field['value']; } // Ensure an 'other' choice is defined. if( !isset( $field['choices']['other'] ) ) { $field['choices']['other'] = ''; } } // Bail early if no choices. if( empty( $field['choices'] ) ) { return; } // Hiden input. $e .= acf_get_hidden_input( array('name' => $field['name']) ); // Open