/** * An ajax callback function that creates a new custom field with default settings. **/ public function create_custom_field_ajax() { $label = $_POST['label']; $meta_key = $_POST['meta_key']; $defaults = $this->form_manager->get_defaults(); if (!($label && $meta_key)) { $response = array('success' => false, 'error' => __('You missed a required item.', 'wpfepp-plugin')); die(json_encode($response)); } if ($meta_key != sanitize_key($meta_key)) { $response = array('success' => false, 'error' => __('The meta key is invalid.', 'wpfepp-plugin')); die(json_encode($response)); } $field_settings = array_merge(array('widget_label' => $label, 'label' => $label), $defaults['custom_field']); ob_start(); $this->display_item($meta_key, $field_settings); $widget_html = ob_get_clean(); $response = array('success' => true, 'widget_html' => $widget_html); die(json_encode($response)); }