Adds method to return subscriber fields

This commit is contained in:
Vlad
2017-05-10 20:49:14 -04:00
parent cedd94550f
commit 5e34bbf9d5
3 changed files with 36 additions and 2 deletions

View File

@ -1,7 +1,35 @@
<?php
namespace MailPoet\API\MP\v1;
use MailPoet\Models\CustomField;
if(!defined('ABSPATH')) exit;
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;
}
}