function show_field_select_ajax($field, $meta) { if (!is_array($meta)) { $meta = (array) $meta; } $meta_value = html_addslashes(empty($meta) ? '' : $meta[0]); $field['with'] = !empty($field['with']) && in_array($field['with'], ["post_type", "taxonomy"]) ? $field['with'] : "post_type"; $this->show_field_begin($field, $meta); echo "<input type='hidden' value=\"{$meta_value}\" name='{$field['id']}' class='input-xlarge select2_ajax' data-relation='{$field['relation']}' data-with='{$field['with']}' data-placeholder='Select an Option..'" . ($field['multiple'] ? " data-multiple='true' style='height:auto'" : "data-multiple='false'") . " /> "; $this->show_field_end($field, $meta); }
public static function render_field($field = null, $key = 0, $val = '', $id_section = '') { if (!$field) { return; } if (!empty($id_section)) { $field['id'] = $id_section . '_' . $field['id']; } if (empty($val)) { $val = is_callable($field['value']) ? call_user_func($field['value']) : $field['value']; } if ($field['type'] == 'hidden') { echo '<input type="hidden" value="' . $val . '" id="' . $field['id'] . '_' . $key . '" name="' . $field['id'] . '_' . $key . '"/> '; return; } echo '<div class="row-field">'; echo '<label for="' . $field['id'] . '_' . $key . '">' . $field['name'] . '</label>'; switch ($field['type']) { case 'select': echo '<select class="select2" id="' . $field['id'] . '_' . $key . '" name="' . $field['id'] . '_' . $key . ($field['multiple'] ? '[]" multiple="multiple" style="height:auto"' : '"') . '>'; foreach ($field['options'] as $k => $value) { echo '<option value="' . $k . '" ' . selected(in_array($k, (array) $val), true, false) . '>' . $value . '</option>'; } echo '</select>'; break; case 'text': echo '<input type="text" id="' . $field['id'] . '_' . $key . '" name="' . $field['id'] . '_' . $key . '" value="' . stripslashes($val) . '">'; break; case 'textarea': echo '<div class="wrap-editor">'; echo '<textarea rows="5" id="' . $field['id'] . '_' . $key . '" name="' . $field['id'] . '_' . $key . '">' . stripslashes($val) . '</textarea>'; echo '</div>'; break; case 'wysiwyg': echo '<div class="wrap-editor">'; wp_editor(stripslashes($val), $field['id'] . '_' . $key); echo '</div>'; break; case 'media': $background = stripslashes($val); echo '<div class="wrap-media"><div class="remove_background" data-remove-background>x</div><div class="background" data-section-background style="background-image:url(' . $background . ');">'; echo '<input type="hidden" name="' . $field['id'] . '_' . $key . '" id="' . $field['id'] . '_' . $key . '" value="' . $background . '" />'; echo '</div></div>'; break; case 'select_ajax': echo '<input type="hidden" value="' . html_addslashes($val) . '" id="' . $field['id'] . '_' . $key . '" name="' . $field['id'] . '_' . $key . '" class="input-xlarge select2_ajax" data-relation="' . ($field['relation'] ? $field['relation'] : 'page') . '" data-placeholder="Select an Option.."' . ($field['multiple'] ? ' data-multiple="true" style="height:auto"' : ' data-multiple="false"') . ' /> '; break; default: return null; break; } echo '</div>'; }