diff --git a/lib/API/MP/v1/API.php b/lib/API/MP/v1/API.php index b726ffd727..7fa70ef0cb 100644 --- a/lib/API/MP/v1/API.php +++ b/lib/API/MP/v1/API.php @@ -1,7 +1,35 @@ 'email', + 'name' => __('Email', 'mailpoet') + ), + array( + 'id' => 'first_name', + 'name' => __('First name', 'mailpoet') + ), + array( + 'id' => 'last_name', + 'name' => __('Last name', 'mailpoet') + ) + ); + + $custom_fields = CustomField::selectMany(array('id', 'name'))->findMany(); + foreach($custom_fields as $custom_field) { + $data[] = array( + 'id' => 'cf_' . $custom_field->id, + 'name' => $custom_field->name + ); + } + + return $data; + } } \ No newline at end of file diff --git a/lib/Models/CustomField.php b/lib/Models/CustomField.php index b84d80e018..91acc36c26 100644 --- a/lib/Models/CustomField.php +++ b/lib/Models/CustomField.php @@ -7,6 +7,12 @@ if(!defined('ABSPATH')) exit; class CustomField extends Model { public static $_table = MP_CUSTOM_FIELDS_TABLE; + const TYPE_DATE = 'date'; + const TYPE_TEXT = 'text'; + const TYPE_TEXTAREA = 'textarea'; + const TYPE_RADIO = 'radio'; + const TYPE_CHECKBOX = 'checkbox'; + const TYPE_SELECT = 'select'; function __construct() { parent::__construct(); @@ -43,7 +49,7 @@ class CustomField extends Model { function formatValue($value = null) { // format custom field data depending on type - if(is_array($value) && $this->type === 'date' ) { + if(is_array($value) && $this->type === self::TYPE_DATE) { $custom_field_data = $this->asArray(); $date_format = $custom_field_data['params']['date_format']; $date_type = (isset($custom_field_data['params']['date_type']) diff --git a/tests/unit/Models/CustomFieldTest.php b/tests/unit/Models/CustomFieldTest.php index d9eb649520..7e8387949f 100644 --- a/tests/unit/Models/CustomFieldTest.php +++ b/tests/unit/Models/CustomFieldTest.php @@ -8,7 +8,7 @@ class CustomFieldTest extends MailPoetTest { function _before() { $this->data = array( 'name' => 'City', - 'type' => 'text', + 'type' => CustomField::TYPE_TEXT, 'params' => array( 'label' => 'What is your city?' )