/** * Generate the corresponding HTML for a field. * * @param array $args * * @return string */ protected function _render($args) { $args = wp_parse_args($args, array('numeric' => false, 'checked' => null)); if (!is_array($args['checked'])) { $args['checked'] = array(); } $opts = ''; foreach ($args['choices'] as $value => $title) { $single_input = FormField::_checkbox(array('name' => $args['name'] . '[]', 'type' => 'checkbox', 'value' => $value, 'checked' => in_array($value, $args['checked']), 'desc' => $title, 'desc_pos' => 'after')); $opts .= str_replace(FormBuilder::TOKEN, $single_input, $args['wrap_each']); } return FormField::add_desc($opts, $args['desc'], $args['desc_pos']); }
/** * Generate the corresponding HTML for a field. * * @param array $args * * @return string */ protected function _render_specific($args) { if (array('foo') === $args['selected']) { // radio buttons should always have one option selected $args['selected'] = key($args['choices']); } $opts = ''; foreach ($args['choices'] as $value => $title) { $value = (string) $value; $single_input = FormField::_checkbox(array('name' => $args['name'], 'type' => 'radio', 'value' => $value, 'checked' => $value == $args['selected'], 'desc' => $title, 'desc_pos' => 'after')); $opts .= str_replace(FormBuilder::TOKEN, $single_input, $args['wrap_each']); } return FormField::add_desc($opts, $args['desc'], $args['desc_pos']); }