asArray(); }, $collection); wp_send_json($custom_fields); } function delete($id) { $custom_field = CustomField::findOne($id); if($custom_field === false or !$custom_field->id()) { wp_send_json(array( 'result' => false )); } else { $custom_field->delete(); wp_send_json(array( 'result' => true, 'field' => $custom_field->asArray() )); } } function save($data = array()) { $custom_field = CustomField::createOrUpdate($data); if($custom_field === false) { $result = array( 'result' => false, 'errors' => array( __('The custom field could not be created.') ) ); } else { $errors = $custom_field->getValidationErrors(); if(!empty($errors)) { $result = array( 'result' => false, 'errors' => $errors ); } else { $result = array( 'result' => true, 'field' => $custom_field->asArray() ); } } wp_send_json($result); } function get($id) { $custom_field = CustomField::findOne($id); if($custom_field === false) { wp_send_json(false); } else { $custom_field = $custom_field->asArray(); wp_send_json($custom_field); } } }