Adds method to return subscriber fields
This commit is contained in:
@ -1,7 +1,35 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\API\MP\v1;
|
namespace MailPoet\API\MP\v1;
|
||||||
|
|
||||||
|
use MailPoet\Models\CustomField;
|
||||||
|
|
||||||
if(!defined('ABSPATH')) exit;
|
if(!defined('ABSPATH')) exit;
|
||||||
|
|
||||||
class API {
|
class API {
|
||||||
|
function getSubscriberFields() {
|
||||||
|
$data = array(
|
||||||
|
array(
|
||||||
|
'id' => '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;
|
||||||
|
}
|
||||||
}
|
}
|
@ -7,6 +7,12 @@ if(!defined('ABSPATH')) exit;
|
|||||||
|
|
||||||
class CustomField extends Model {
|
class CustomField extends Model {
|
||||||
public static $_table = MP_CUSTOM_FIELDS_TABLE;
|
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() {
|
function __construct() {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
@ -43,7 +49,7 @@ class CustomField extends Model {
|
|||||||
|
|
||||||
function formatValue($value = null) {
|
function formatValue($value = null) {
|
||||||
// format custom field data depending on type
|
// 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();
|
$custom_field_data = $this->asArray();
|
||||||
$date_format = $custom_field_data['params']['date_format'];
|
$date_format = $custom_field_data['params']['date_format'];
|
||||||
$date_type = (isset($custom_field_data['params']['date_type'])
|
$date_type = (isset($custom_field_data['params']['date_type'])
|
||||||
|
@ -8,7 +8,7 @@ class CustomFieldTest extends MailPoetTest {
|
|||||||
function _before() {
|
function _before() {
|
||||||
$this->data = array(
|
$this->data = array(
|
||||||
'name' => 'City',
|
'name' => 'City',
|
||||||
'type' => 'text',
|
'type' => CustomField::TYPE_TEXT,
|
||||||
'params' => array(
|
'params' => array(
|
||||||
'label' => 'What is your city?'
|
'label' => 'What is your city?'
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user