/** * The actual rendering. * * @param array $args * * @return string */ protected function _render($args) { $args = wp_parse_args($args, array('value' => '', 'desc_pos' => 'after', 'extra' => array('class' => 'regular-text'))); $values = maybe_unserialize($args['value']); $opts = '<div class="ae_gallery_field" id="' . uniqid() . '">'; $opts .= '<script class="data-args">' . wp_json_encode($args) . '</script>'; $opts .= '<script class="data-value">' . wp_json_encode($values) . '</script>'; $opts .= '</div>'; 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($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']); }
/** * The actual rendering. * * @param array $args */ protected function _render($args) { $args = wp_parse_args($args, array('value' => '', 'desc_pos' => 'after', 'extra' => array('class' => 'regular-text'))); $values = maybe_unserialize($args['value']); $opts = ''; foreach ($values as $index => $group) { $group_id = 'group_' . $index; $opts .= '<div id="' . $group_id . '">'; if (is_array($group)) { foreach ($group as $key => $value) { $single_input = FormField::_input_gen(array('name' => $args['name'] . '[' . $index . '][' . $key . ']', 'type' => 'text', 'value' => $value, 'desc' => $key, 'desc_pos' => 'before')); $opts .= '<br>' . str_replace(FormBuilder::TOKEN, $single_input, $args['wrap_each']); } $opts .= '<button class="btnRemoveRule" data-id="' . $group_id . '">Remove</button></div>'; } } $opts .= '<button class="btnAddRule" data-count="' . count($values) . '">Add</button>'; return FormField::add_desc($opts, $args['desc'], $args['desc_pos']); }