Add public keyword to methods
[MAILPOET-2413]
This commit is contained in:
@ -42,7 +42,7 @@ class API {
|
||||
const CURRENT_VERSION = 'v1';
|
||||
|
||||
|
||||
function __construct(
|
||||
public function __construct(
|
||||
ContainerInterface $container,
|
||||
AccessControl $access_control,
|
||||
SettingsController $settings,
|
||||
@ -60,7 +60,7 @@ class API {
|
||||
}
|
||||
}
|
||||
|
||||
function init() {
|
||||
public function init() {
|
||||
// admin security token and API version
|
||||
WPFunctions::get()->addAction(
|
||||
'admin_head',
|
||||
@ -80,7 +80,7 @@ class API {
|
||||
);
|
||||
}
|
||||
|
||||
function setupAjax() {
|
||||
public function setupAjax() {
|
||||
$this->wp->doAction('mailpoet_api_setup', [$this]);
|
||||
|
||||
if (isset($_POST['api_version'])) {
|
||||
@ -105,7 +105,7 @@ class API {
|
||||
$response->send();
|
||||
}
|
||||
|
||||
function setRequestData($data, $request_type) {
|
||||
public function setRequestData($data, $request_type) {
|
||||
$this->_request_api_version = !empty($data['api_version']) ? $data['api_version'] : false;
|
||||
|
||||
$this->_request_endpoint = isset($data['endpoint'])
|
||||
@ -162,7 +162,7 @@ class API {
|
||||
}
|
||||
}
|
||||
|
||||
function processRoute() {
|
||||
public function processRoute() {
|
||||
try {
|
||||
if (empty($this->_request_endpoint_class) ||
|
||||
!$this->container->has($this->_request_endpoint_class)
|
||||
@ -203,18 +203,18 @@ class API {
|
||||
}
|
||||
}
|
||||
|
||||
function validatePermissions($request_method, $permissions) {
|
||||
public function validatePermissions($request_method, $permissions) {
|
||||
// validate method permission if defined, otherwise validate global permission
|
||||
return(!empty($permissions['methods'][$request_method])) ?
|
||||
$this->access_control->validatePermission($permissions['methods'][$request_method]) :
|
||||
$this->access_control->validatePermission($permissions['global']);
|
||||
}
|
||||
|
||||
function checkToken() {
|
||||
public function checkToken() {
|
||||
return WPFunctions::get()->wpVerifyNonce($this->_request_token, 'mailpoet_token');
|
||||
}
|
||||
|
||||
function setTokenAndAPIVersion() {
|
||||
public function setTokenAndAPIVersion() {
|
||||
$global = '<script type="text/javascript">';
|
||||
$global .= 'var mailpoet_token = "%s";';
|
||||
$global .= 'var mailpoet_api_version = "%s";';
|
||||
@ -226,24 +226,24 @@ class API {
|
||||
);
|
||||
}
|
||||
|
||||
function addEndpointNamespace($namespace, $version) {
|
||||
public function addEndpointNamespace($namespace, $version) {
|
||||
if (!empty($this->_endpoint_namespaces[$version][$namespace])) return;
|
||||
$this->_endpoint_namespaces[$version][] = $namespace;
|
||||
}
|
||||
|
||||
function getEndpointNamespaces() {
|
||||
public function getEndpointNamespaces() {
|
||||
return $this->_endpoint_namespaces;
|
||||
}
|
||||
|
||||
function getRequestedEndpointClass() {
|
||||
public function getRequestedEndpointClass() {
|
||||
return $this->_request_endpoint_class;
|
||||
}
|
||||
|
||||
function getRequestedAPIVersion() {
|
||||
public function getRequestedAPIVersion() {
|
||||
return $this->_request_api_version;
|
||||
}
|
||||
|
||||
function createErrorResponse($error_type, $error_message, $response_status) {
|
||||
public function createErrorResponse($error_type, $error_message, $response_status) {
|
||||
$error_response = new ErrorResponse(
|
||||
[
|
||||
$error_type => $error_message,
|
||||
|
@ -16,13 +16,13 @@ abstract class Endpoint {
|
||||
|
||||
protected static $get_methods = [];
|
||||
|
||||
function successResponse(
|
||||
public function successResponse(
|
||||
$data = [], $meta = [], $status = Response::STATUS_OK
|
||||
) {
|
||||
return new SuccessResponse($data, $meta, $status);
|
||||
}
|
||||
|
||||
function errorResponse(
|
||||
public function errorResponse(
|
||||
$errors = [], $meta = [], $status = Response::STATUS_NOT_FOUND
|
||||
) {
|
||||
if (empty($errors)) {
|
||||
@ -33,7 +33,7 @@ abstract class Endpoint {
|
||||
return new ErrorResponse($errors, $meta, $status);
|
||||
}
|
||||
|
||||
function badRequest($errors = [], $meta = []) {
|
||||
public function badRequest($errors = [], $meta = []) {
|
||||
if (empty($errors)) {
|
||||
$errors = [
|
||||
Error::BAD_REQUEST => WPFunctions::get()->__('Invalid request parameters', 'mailpoet'),
|
||||
|
@ -7,16 +7,16 @@ use MailPoet\WP\Functions as WPFunctions;
|
||||
class ErrorResponse extends Response {
|
||||
public $errors;
|
||||
|
||||
function __construct($errors = [], $meta = [], $status = self::STATUS_NOT_FOUND) {
|
||||
public function __construct($errors = [], $meta = [], $status = self::STATUS_NOT_FOUND) {
|
||||
parent::__construct($status, $meta);
|
||||
$this->errors = $this->formatErrors($errors);
|
||||
}
|
||||
|
||||
function getData() {
|
||||
public function getData() {
|
||||
return (empty($this->errors)) ? null : ['errors' => $this->errors];
|
||||
}
|
||||
|
||||
function formatErrors($errors = []) {
|
||||
public function formatErrors($errors = []) {
|
||||
return array_map(function($error, $message) {
|
||||
// sanitize SQL error
|
||||
if (preg_match('/^SQLSTATE/i', $message)) {
|
||||
|
@ -16,12 +16,12 @@ abstract class Response {
|
||||
public $status;
|
||||
public $meta;
|
||||
|
||||
function __construct($status, $meta = []) {
|
||||
public function __construct($status, $meta = []) {
|
||||
$this->status = $status;
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
function send() {
|
||||
public function send() {
|
||||
WPFunctions::get()->statusHeader($this->status);
|
||||
|
||||
$data = $this->getData();
|
||||
@ -41,5 +41,5 @@ abstract class Response {
|
||||
die();
|
||||
}
|
||||
|
||||
abstract function getData();
|
||||
public abstract function getData();
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ class CustomFieldsResponseBuilder {
|
||||
* @param CustomFieldEntity[] $custom_fields
|
||||
* @return array
|
||||
*/
|
||||
function buildBatch(array $custom_fields) {
|
||||
public function buildBatch(array $custom_fields) {
|
||||
return array_map([$this, 'build'], $custom_fields);
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@ class CustomFieldsResponseBuilder {
|
||||
* @param CustomFieldEntity $custom_field
|
||||
* @return array
|
||||
*/
|
||||
function build(CustomFieldEntity $custom_field) {
|
||||
public function build(CustomFieldEntity $custom_field) {
|
||||
return [
|
||||
'id' => $custom_field->getId(),
|
||||
'name' => $custom_field->getName(),
|
||||
|
@ -9,7 +9,7 @@ use MailPoet\Entities\SendingQueueEntity;
|
||||
class NewslettersResponseBuilder {
|
||||
const DATE_FORMAT = 'Y-m-d H:i:s';
|
||||
|
||||
function build(NewsletterEntity $newsletter) {
|
||||
public function build(NewsletterEntity $newsletter) {
|
||||
return [
|
||||
'id' => (string)$newsletter->getId(), // (string) for BC
|
||||
'hash' => $newsletter->getHash(),
|
||||
|
@ -5,12 +5,12 @@ namespace MailPoet\API\JSON;
|
||||
class SuccessResponse extends Response {
|
||||
public $data;
|
||||
|
||||
function __construct($data = [], $meta = [], $status = self::STATUS_OK) {
|
||||
public function __construct($data = [], $meta = [], $status = self::STATUS_OK) {
|
||||
parent::__construct($status, $meta);
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
function getData() {
|
||||
public function getData() {
|
||||
if ($this->data === null) return null;
|
||||
|
||||
return [
|
||||
|
@ -15,11 +15,11 @@ class Analytics extends APIEndpoint {
|
||||
'global' => AccessControl::NO_ACCESS_RESTRICTION,
|
||||
];
|
||||
|
||||
function __construct(Reporter $reporter) {
|
||||
public function __construct(Reporter $reporter) {
|
||||
$this->reporter = $reporter;
|
||||
}
|
||||
|
||||
function getTrackingData() {
|
||||
public function getTrackingData() {
|
||||
return $this->successResponse($this->reporter->getTrackingData());
|
||||
}
|
||||
}
|
||||
|
@ -15,12 +15,12 @@ class AutomatedLatestContent extends APIEndpoint {
|
||||
'global' => AccessControl::PERMISSION_MANAGE_EMAILS,
|
||||
];
|
||||
|
||||
function __construct(\MailPoet\Newsletter\AutomatedLatestContent $alc, WPFunctions $wp) {
|
||||
public function __construct(\MailPoet\Newsletter\AutomatedLatestContent $alc, WPFunctions $wp) {
|
||||
$this->ALC = $alc;
|
||||
$this->wp = $wp;
|
||||
}
|
||||
|
||||
function getPostTypes() {
|
||||
public function getPostTypes() {
|
||||
$post_types = array_map(function($post_type) {
|
||||
return [
|
||||
'name' => $post_type->name,
|
||||
@ -32,7 +32,7 @@ class AutomatedLatestContent extends APIEndpoint {
|
||||
);
|
||||
}
|
||||
|
||||
function getTaxonomies($data = []) {
|
||||
public function getTaxonomies($data = []) {
|
||||
$post_type = (isset($data['postType'])) ? $data['postType'] : 'post';
|
||||
$all_taxonomies = WPFunctions::get()->getObjectTaxonomies($post_type, 'objects');
|
||||
$taxonomies_with_label = array_filter($all_taxonomies, function($taxonomy) {
|
||||
@ -41,7 +41,7 @@ class AutomatedLatestContent extends APIEndpoint {
|
||||
return $this->successResponse($taxonomies_with_label);
|
||||
}
|
||||
|
||||
function getTerms($data = []) {
|
||||
public function getTerms($data = []) {
|
||||
$taxonomies = (isset($data['taxonomies'])) ? $data['taxonomies'] : [];
|
||||
$search = (isset($data['search'])) ? $data['search'] : '';
|
||||
$limit = (isset($data['limit'])) ? (int)$data['limit'] : 100;
|
||||
@ -62,20 +62,20 @@ class AutomatedLatestContent extends APIEndpoint {
|
||||
return $this->successResponse(array_values($terms));
|
||||
}
|
||||
|
||||
function getPosts($data = []) {
|
||||
public function getPosts($data = []) {
|
||||
return $this->successResponse(
|
||||
$this->ALC->getPosts($data)
|
||||
);
|
||||
}
|
||||
|
||||
function getTransformedPosts($data = []) {
|
||||
public function getTransformedPosts($data = []) {
|
||||
$posts = $this->ALC->getPosts($data);
|
||||
return $this->successResponse(
|
||||
$this->ALC->transformPosts($data, $posts)
|
||||
);
|
||||
}
|
||||
|
||||
function getBulkTransformedPosts($data = []) {
|
||||
public function getBulkTransformedPosts($data = []) {
|
||||
$used_posts = [];
|
||||
$rendered_posts = [];
|
||||
|
||||
|
@ -14,11 +14,11 @@ class AutomaticEmails extends APIEndpoint {
|
||||
|
||||
private $wp;
|
||||
|
||||
function __construct() {
|
||||
public function __construct() {
|
||||
$this->wp = new WPFunctions;
|
||||
}
|
||||
|
||||
function getEventOptions($data) {
|
||||
public function getEventOptions($data) {
|
||||
$query = (!empty($data['query'])) ? $data['query'] : null;
|
||||
$filter = (!empty($data['filter'])) ? $data['filter'] : null;
|
||||
$email_slug = (!empty($data['email_slug'])) ? $data['email_slug'] : null;
|
||||
@ -45,7 +45,7 @@ class AutomaticEmails extends APIEndpoint {
|
||||
);
|
||||
}
|
||||
|
||||
function getEventShortcodes($data) {
|
||||
public function getEventShortcodes($data) {
|
||||
$email_slug = (!empty($data['email_slug'])) ? $data['email_slug'] : null;
|
||||
$event_slug = (!empty($data['event_slug'])) ? $data['event_slug'] : null;
|
||||
|
||||
|
@ -31,12 +31,12 @@ class CustomFields extends APIEndpoint {
|
||||
$this->custom_fields_response_builder = $custom_fields_response_builder;
|
||||
}
|
||||
|
||||
function getAll() {
|
||||
public function getAll() {
|
||||
$collection = $this->custom_fields_repository->findBy([], ['created_at' => 'asc']);
|
||||
return $this->successResponse($this->custom_fields_response_builder->buildBatch($collection));
|
||||
}
|
||||
|
||||
function delete($data = []) {
|
||||
public function delete($data = []) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : null);
|
||||
$custom_field = $this->custom_fields_repository->findOneById($id);
|
||||
if ($custom_field instanceof CustomFieldEntity) {
|
||||
@ -51,7 +51,7 @@ class CustomFields extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function save($data = []) {
|
||||
public function save($data = []) {
|
||||
try {
|
||||
$custom_field = $this->custom_fields_repository->createOrUpdate($data);
|
||||
$custom_field = $this->custom_fields_repository->findOneById($custom_field->getId());
|
||||
@ -62,7 +62,7 @@ class CustomFields extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function get($data = []) {
|
||||
public function get($data = []) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : null);
|
||||
$custom_field = $this->custom_fields_repository->findOneById($id);
|
||||
if ($custom_field instanceof CustomFieldEntity) {
|
||||
|
@ -51,7 +51,7 @@ class DynamicSegments extends APIEndpoint {
|
||||
$this->subscribers_counts_loader = $subscribers_counts_loader ?: new SubscribersCount();
|
||||
}
|
||||
|
||||
function get($data = []) {
|
||||
public function get($data = []) {
|
||||
if (isset($data['id'])) {
|
||||
$id = (int)$data['id'];
|
||||
} else {
|
||||
@ -77,7 +77,7 @@ class DynamicSegments extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function save($data) {
|
||||
public function save($data) {
|
||||
try {
|
||||
$dynamic_segment = $this->mapper->mapDataToDB($data);
|
||||
$this->saver->save($dynamic_segment);
|
||||
@ -117,7 +117,7 @@ class DynamicSegments extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function trash($data = []) {
|
||||
public function trash($data = []) {
|
||||
if (isset($data['id'])) {
|
||||
$id = (int)$data['id'];
|
||||
} else {
|
||||
@ -140,7 +140,7 @@ class DynamicSegments extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function restore($data = []) {
|
||||
public function restore($data = []) {
|
||||
if (isset($data['id'])) {
|
||||
$id = (int)$data['id'];
|
||||
} else {
|
||||
@ -163,7 +163,7 @@ class DynamicSegments extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function delete($data = []) {
|
||||
public function delete($data = []) {
|
||||
if (isset($data['id'])) {
|
||||
$id = (int)$data['id'];
|
||||
} else {
|
||||
@ -183,7 +183,7 @@ class DynamicSegments extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function listing($data = []) {
|
||||
public function listing($data = []) {
|
||||
$listing_data = $this->listing_handler->get('\MailPoet\Models\DynamicSegment', $data);
|
||||
|
||||
$data = [];
|
||||
@ -206,7 +206,7 @@ class DynamicSegments extends APIEndpoint {
|
||||
|
||||
}
|
||||
|
||||
function bulkAction($data = []) {
|
||||
public function bulkAction($data = []) {
|
||||
try {
|
||||
$meta = $this->bulk_action->apply('\MailPoet\Models\DynamicSegment', $data);
|
||||
return $this->successResponse(null, $meta);
|
||||
|
@ -20,17 +20,17 @@ class FeatureFlags extends APIEndpoint {
|
||||
/** @var FeatureFlagsController */
|
||||
private $feature_flags_controller;
|
||||
|
||||
function __construct(FeaturesController $features_controller, FeatureFlagsController $feature_flags) {
|
||||
public function __construct(FeaturesController $features_controller, FeatureFlagsController $feature_flags) {
|
||||
$this->features_controller = $features_controller;
|
||||
$this->feature_flags_controller = $feature_flags;
|
||||
}
|
||||
|
||||
function getAll() {
|
||||
public function getAll() {
|
||||
$feature_flags = $this->feature_flags_controller->getAll();
|
||||
return $this->successResponse($feature_flags);
|
||||
}
|
||||
|
||||
function set(array $flags) {
|
||||
public function set(array $flags) {
|
||||
foreach ($flags as $name => $value) {
|
||||
if (!$this->features_controller->exists($name)) {
|
||||
return $this->badRequest([
|
||||
|
@ -31,7 +31,7 @@ class Forms extends APIEndpoint {
|
||||
'global' => AccessControl::PERMISSION_MANAGE_FORMS,
|
||||
];
|
||||
|
||||
function __construct(
|
||||
public function __construct(
|
||||
Listing\BulkActionController $bulk_action,
|
||||
Listing\Handler $listing_handler,
|
||||
FeaturesController $features_controller,
|
||||
@ -43,7 +43,7 @@ class Forms extends APIEndpoint {
|
||||
$this->form_styles_utils = $form_styles_utils;
|
||||
}
|
||||
|
||||
function get($data = []) {
|
||||
public function get($data = []) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$form = Form::findOne($id);
|
||||
if ($form instanceof Form) {
|
||||
@ -54,7 +54,7 @@ class Forms extends APIEndpoint {
|
||||
]);
|
||||
}
|
||||
|
||||
function listing($data = []) {
|
||||
public function listing($data = []) {
|
||||
$listing_data = $this->listing_handler->get('\MailPoet\Models\Form', $data);
|
||||
|
||||
$data = [];
|
||||
@ -79,7 +79,7 @@ class Forms extends APIEndpoint {
|
||||
]);
|
||||
}
|
||||
|
||||
function create() {
|
||||
public function create() {
|
||||
$form_name = WPFunctions::get()->__('New form', 'mailpoet');
|
||||
if ($this->features_controller->isSupported(FeaturesController::NEW_FORM_EDITOR)) {
|
||||
$form_name = '';
|
||||
@ -123,7 +123,7 @@ class Forms extends APIEndpoint {
|
||||
return $this->save($form_data);
|
||||
}
|
||||
|
||||
function save($data = []) {
|
||||
public function save($data = []) {
|
||||
$form = Form::createOrUpdate($data);
|
||||
$errors = $form->getErrors();
|
||||
|
||||
@ -135,7 +135,7 @@ class Forms extends APIEndpoint {
|
||||
return $this->badRequest($errors);
|
||||
}
|
||||
|
||||
function previewEditor($data = []) {
|
||||
public function previewEditor($data = []) {
|
||||
// html
|
||||
$html = FormRenderer::renderHTML($data);
|
||||
|
||||
@ -151,7 +151,7 @@ class Forms extends APIEndpoint {
|
||||
]);
|
||||
}
|
||||
|
||||
function exportsEditor($data = []) {
|
||||
public function exportsEditor($data = []) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$form = Form::findOne($id);
|
||||
if ($form instanceof Form) {
|
||||
@ -163,7 +163,7 @@ class Forms extends APIEndpoint {
|
||||
]);
|
||||
}
|
||||
|
||||
function saveEditor($data = []) {
|
||||
public function saveEditor($data = []) {
|
||||
$form_id = (isset($data['id']) ? (int)$data['id'] : 0);
|
||||
$name = (isset($data['name']) ? $data['name'] : WPFunctions::get()->__('New form', 'mailpoet'));
|
||||
$body = (isset($data['body']) ? $data['body'] : []);
|
||||
@ -232,7 +232,7 @@ class Forms extends APIEndpoint {
|
||||
);
|
||||
}
|
||||
|
||||
function restore($data = []) {
|
||||
public function restore($data = []) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$form = Form::findOne($id);
|
||||
if ($form instanceof Form) {
|
||||
@ -250,7 +250,7 @@ class Forms extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function trash($data = []) {
|
||||
public function trash($data = []) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$form = Form::findOne($id);
|
||||
if ($form instanceof Form) {
|
||||
@ -268,7 +268,7 @@ class Forms extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function delete($data = []) {
|
||||
public function delete($data = []) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$form = Form::findOne($id);
|
||||
if ($form instanceof Form) {
|
||||
@ -282,7 +282,7 @@ class Forms extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function duplicate($data = []) {
|
||||
public function duplicate($data = []) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$form = Form::findOne($id);
|
||||
|
||||
@ -311,7 +311,7 @@ class Forms extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function bulkAction($data = []) {
|
||||
public function bulkAction($data = []) {
|
||||
try {
|
||||
$meta = $this->bulk_action->apply('\MailPoet\Models\Form', $data);
|
||||
return $this->successResponse(null, $meta);
|
||||
|
@ -15,7 +15,7 @@ class ImportExport extends APIEndpoint {
|
||||
'global' => AccessControl::PERMISSION_MANAGE_SUBSCRIBERS,
|
||||
];
|
||||
|
||||
function getMailChimpLists($data) {
|
||||
public function getMailChimpLists($data) {
|
||||
try {
|
||||
$mailChimp = new MailChimp($data['api_key']);
|
||||
$lists = $mailChimp->getLists();
|
||||
@ -27,7 +27,7 @@ class ImportExport extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function getMailChimpSubscribers($data) {
|
||||
public function getMailChimpSubscribers($data) {
|
||||
try {
|
||||
$mailChimp = new MailChimp($data['api_key']);
|
||||
$subscribers = $mailChimp->getSubscribers($data['lists']);
|
||||
@ -39,7 +39,7 @@ class ImportExport extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function addSegment($data) {
|
||||
public function addSegment($data) {
|
||||
$segment = Segment::createOrUpdate($data);
|
||||
$errors = $segment->getErrors();
|
||||
|
||||
@ -52,7 +52,7 @@ class ImportExport extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function processImport($data) {
|
||||
public function processImport($data) {
|
||||
try {
|
||||
$import = new \MailPoet\Subscribers\ImportExport\Import\Import(
|
||||
json_decode($data, true)
|
||||
@ -66,7 +66,7 @@ class ImportExport extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function processExport($data) {
|
||||
public function processExport($data) {
|
||||
try {
|
||||
$export = new \MailPoet\Subscribers\ImportExport\Export\Export(
|
||||
json_decode($data, true)
|
||||
@ -80,7 +80,7 @@ class ImportExport extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function setupWooCommerceInitialImport() {
|
||||
public function setupWooCommerceInitialImport() {
|
||||
try {
|
||||
$task = ScheduledTask::where('type', WooCommerceSync::TASK_TYPE)
|
||||
->whereRaw('status = ? OR status IS NULL', [ScheduledTask::STATUS_SCHEDULED])
|
||||
|
@ -30,14 +30,14 @@ class Mailer extends APIEndpoint {
|
||||
'global' => AccessControl::PERMISSION_MANAGE_EMAILS,
|
||||
];
|
||||
|
||||
function __construct(AuthorizedEmailsController $authorized_emails_controller, SettingsController $settings, Bridge $bridge, MetaInfo $mailerMetaInfo) {
|
||||
public function __construct(AuthorizedEmailsController $authorized_emails_controller, SettingsController $settings, Bridge $bridge, MetaInfo $mailerMetaInfo) {
|
||||
$this->authorized_emails_controller = $authorized_emails_controller;
|
||||
$this->settings = $settings;
|
||||
$this->bridge = $bridge;
|
||||
$this->mailerMetaInfo = $mailerMetaInfo;
|
||||
}
|
||||
|
||||
function send($data = []) {
|
||||
public function send($data = []) {
|
||||
try {
|
||||
$mailer = new \MailPoet\Mailer\Mailer();
|
||||
$mailer->init(
|
||||
@ -67,7 +67,7 @@ class Mailer extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function resumeSending() {
|
||||
public function resumeSending() {
|
||||
if ($this->settings->get(AuthorizedEmailsController::AUTHORIZED_EMAIL_ADDRESSES_ERROR_SETTING)) {
|
||||
$this->authorized_emails_controller->checkAuthorizedEmailAddresses();
|
||||
}
|
||||
@ -75,7 +75,7 @@ class Mailer extends APIEndpoint {
|
||||
return $this->successResponse(null);
|
||||
}
|
||||
|
||||
function getAuthorizedEmailAddresses() {
|
||||
public function getAuthorizedEmailAddresses() {
|
||||
$authorized_emails = $this->bridge->getAuthorizedEmailAddresses();
|
||||
return $this->successResponse($authorized_emails);
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ class NewsletterLinks extends APIEndpoint {
|
||||
'global' => AccessControl::PERMISSION_MANAGE_SEGMENTS,
|
||||
];
|
||||
|
||||
function get($data = []) {
|
||||
public function get($data = []) {
|
||||
$links = NewsletterLink::select(['id', 'url'])->where('newsletter_id', $data['newsletterId'])->findArray();
|
||||
return $this->successResponse($links);
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ class NewsletterTemplates extends APIEndpoint {
|
||||
'getAll',
|
||||
];
|
||||
|
||||
function get($data = []) {
|
||||
public function get($data = []) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$template = NewsletterTemplate::findOne($id);
|
||||
if ($template instanceof NewsletterTemplate) {
|
||||
@ -31,7 +31,7 @@ class NewsletterTemplates extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function getAll() {
|
||||
public function getAll() {
|
||||
$collection = NewsletterTemplate
|
||||
::selectExpr('id, categories, thumbnail, name, description, readonly')
|
||||
->orderByAsc('readonly')
|
||||
@ -45,7 +45,7 @@ class NewsletterTemplates extends APIEndpoint {
|
||||
return $this->successResponse($templates);
|
||||
}
|
||||
|
||||
function save($data = []) {
|
||||
public function save($data = []) {
|
||||
ignore_user_abort(true);
|
||||
if (!empty($data['newsletter_id'])) {
|
||||
$template = NewsletterTemplate::whereEqual('newsletter_id', $data['newsletter_id'])->findOne();
|
||||
@ -70,7 +70,7 @@ class NewsletterTemplates extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function delete($data = []) {
|
||||
public function delete($data = []) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$template = NewsletterTemplate::findOne($id);
|
||||
if ($template instanceof NewsletterTemplate) {
|
||||
|
@ -80,7 +80,7 @@ class Newsletters extends APIEndpoint {
|
||||
/** @var SubscribersFeature */
|
||||
private $subscribers_feature;
|
||||
|
||||
function __construct(
|
||||
public function __construct(
|
||||
Listing\BulkActionController $bulk_action,
|
||||
Listing\Handler $listing_handler,
|
||||
WPFunctions $wp,
|
||||
@ -112,7 +112,7 @@ class Newsletters extends APIEndpoint {
|
||||
$this->subscribers_feature = $subscribers_feature;
|
||||
}
|
||||
|
||||
function get($data = []) {
|
||||
public function get($data = []) {
|
||||
$newsletter = isset($data['id'])
|
||||
? $this->newsletters_repository->findOneById((int)$data['id'])
|
||||
: null;
|
||||
@ -137,7 +137,7 @@ class Newsletters extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function getWithStats($data = []) {
|
||||
public function getWithStats($data = []) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$newsletter = Newsletter::findOne($id);
|
||||
if ($newsletter instanceof Newsletter) {
|
||||
@ -164,7 +164,7 @@ class Newsletters extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function save($data = []) {
|
||||
public function save($data = []) {
|
||||
$data = $this->wp->applyFilters('mailpoet_api_newsletters_save_before', $data);
|
||||
|
||||
$segments = [];
|
||||
@ -286,7 +286,7 @@ class Newsletters extends APIEndpoint {
|
||||
return $this->successResponse($newsletter->asArray(), ['preview_url' => $preview_url]);
|
||||
}
|
||||
|
||||
function setStatus($data = []) {
|
||||
public function setStatus($data = []) {
|
||||
$status = (isset($data['status']) ? $data['status'] : null);
|
||||
|
||||
if (!$status) {
|
||||
@ -339,7 +339,7 @@ class Newsletters extends APIEndpoint {
|
||||
);
|
||||
}
|
||||
|
||||
function restore($data = []) {
|
||||
public function restore($data = []) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$newsletter = Newsletter::findOne($id);
|
||||
if ($newsletter instanceof Newsletter) {
|
||||
@ -359,7 +359,7 @@ class Newsletters extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function trash($data = []) {
|
||||
public function trash($data = []) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$newsletter = Newsletter::findOne($id);
|
||||
if ($newsletter instanceof Newsletter) {
|
||||
@ -378,7 +378,7 @@ class Newsletters extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function delete($data = []) {
|
||||
public function delete($data = []) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$newsletter = Newsletter::findOne($id);
|
||||
if ($newsletter instanceof Newsletter) {
|
||||
@ -391,7 +391,7 @@ class Newsletters extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function duplicate($data = []) {
|
||||
public function duplicate($data = []) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$newsletter = Newsletter::findOne($id);
|
||||
|
||||
@ -420,7 +420,7 @@ class Newsletters extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function showPreview($data = []) {
|
||||
public function showPreview($data = []) {
|
||||
if (empty($data['body'])) {
|
||||
return $this->badRequest([
|
||||
APIError::BAD_REQUEST => __('Newsletter data is missing.', 'mailpoet'),
|
||||
@ -456,7 +456,7 @@ class Newsletters extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function sendPreview($data = []) {
|
||||
public function sendPreview($data = []) {
|
||||
if (empty($data['subscriber'])) {
|
||||
return $this->badRequest([
|
||||
APIError::BAD_REQUEST => __('Please specify receiver information.', 'mailpoet'),
|
||||
@ -527,7 +527,7 @@ class Newsletters extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function listing($data = []) {
|
||||
public function listing($data = []) {
|
||||
$listing_data = $this->listing_handler->get('\MailPoet\Models\Newsletter', $data);
|
||||
|
||||
$data = [];
|
||||
@ -585,7 +585,7 @@ class Newsletters extends APIEndpoint {
|
||||
]);
|
||||
}
|
||||
|
||||
function bulkAction($data = []) {
|
||||
public function bulkAction($data = []) {
|
||||
try {
|
||||
$meta = $this->bulk_action->apply('\MailPoet\Models\Newsletter', $data);
|
||||
return $this->successResponse(null, $meta);
|
||||
@ -596,7 +596,7 @@ class Newsletters extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function create($data = []) {
|
||||
public function create($data = []) {
|
||||
$options = [];
|
||||
if (isset($data['options'])) {
|
||||
$options = $data['options'];
|
||||
|
@ -25,7 +25,7 @@ class Segments extends APIEndpoint {
|
||||
/** @var WooCommerce */
|
||||
private $woo_commerce_sync;
|
||||
|
||||
function __construct(
|
||||
public function __construct(
|
||||
Listing\BulkActionController $bulk_action,
|
||||
Listing\Handler $listing_handler,
|
||||
WooCommerce $woo_commerce
|
||||
@ -35,7 +35,7 @@ class Segments extends APIEndpoint {
|
||||
$this->woo_commerce_sync = $woo_commerce;
|
||||
}
|
||||
|
||||
function get($data = []) {
|
||||
public function get($data = []) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$segment = Segment::findOne($id);
|
||||
if ($segment instanceof Segment) {
|
||||
@ -47,7 +47,7 @@ class Segments extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function listing($data = []) {
|
||||
public function listing($data = []) {
|
||||
$listing_data = $this->listing_handler->get('\MailPoet\Models\Segment', $data);
|
||||
|
||||
$data = [];
|
||||
@ -69,7 +69,7 @@ class Segments extends APIEndpoint {
|
||||
]);
|
||||
}
|
||||
|
||||
function save($data = []) {
|
||||
public function save($data = []) {
|
||||
$segment = Segment::createOrUpdate($data);
|
||||
$errors = $segment->getErrors();
|
||||
|
||||
@ -84,7 +84,7 @@ class Segments extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function restore($data = []) {
|
||||
public function restore($data = []) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$segment = Segment::findOne($id);
|
||||
if ($segment instanceof Segment) {
|
||||
@ -102,7 +102,7 @@ class Segments extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function trash($data = []) {
|
||||
public function trash($data = []) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$segment = Segment::findOne($id);
|
||||
if ($segment instanceof Segment) {
|
||||
@ -120,7 +120,7 @@ class Segments extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function delete($data = []) {
|
||||
public function delete($data = []) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$segment = Segment::findOne($id);
|
||||
if ($segment instanceof Segment) {
|
||||
@ -133,7 +133,7 @@ class Segments extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function duplicate($data = []) {
|
||||
public function duplicate($data = []) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$segment = Segment::findOne($id);
|
||||
|
||||
@ -161,7 +161,7 @@ class Segments extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function synchronize($data) {
|
||||
public function synchronize($data) {
|
||||
try {
|
||||
if ($data['type'] === Segment::TYPE_WC_USERS) {
|
||||
$this->woo_commerce_sync->synchronizeCustomers();
|
||||
@ -177,7 +177,7 @@ class Segments extends APIEndpoint {
|
||||
return $this->successResponse(null);
|
||||
}
|
||||
|
||||
function bulkAction($data = []) {
|
||||
public function bulkAction($data = []) {
|
||||
try {
|
||||
$meta = $this->bulk_action->apply('\MailPoet\Models\Segment', $data);
|
||||
return $this->successResponse(null, $meta);
|
||||
|
@ -23,11 +23,11 @@ class SendingQueue extends APIEndpoint {
|
||||
/** @var SubscribersFeature */
|
||||
private $subscribers_feature;
|
||||
|
||||
function __construct(SubscribersFeature $subscribers_feature) {
|
||||
public function __construct(SubscribersFeature $subscribers_feature) {
|
||||
$this->subscribers_feature = $subscribers_feature;
|
||||
}
|
||||
|
||||
function add($data = []) {
|
||||
public function add($data = []) {
|
||||
if ($this->subscribers_feature->check()) {
|
||||
return $this->errorResponse([
|
||||
APIError::FORBIDDEN => __('Subscribers limit reached.', 'mailpoet'),
|
||||
@ -117,7 +117,7 @@ class SendingQueue extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function pause($data = []) {
|
||||
public function pause($data = []) {
|
||||
$newsletter_id = (isset($data['newsletter_id'])
|
||||
? (int)$data['newsletter_id']
|
||||
: false
|
||||
@ -144,7 +144,7 @@ class SendingQueue extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function resume($data = []) {
|
||||
public function resume($data = []) {
|
||||
if ($this->subscribers_feature->check()) {
|
||||
return $this->errorResponse([
|
||||
APIError::FORBIDDEN => __('Subscribers limit reached.', 'mailpoet'),
|
||||
|
@ -31,7 +31,7 @@ class SendingTaskSubscribers extends APIEndpoint {
|
||||
/** @var WPFunctions */
|
||||
private $wp;
|
||||
|
||||
function __construct(
|
||||
public function __construct(
|
||||
Listing\Handler $listing_handler,
|
||||
SettingsController $settings,
|
||||
CronHelper $cron_helper,
|
||||
@ -43,7 +43,7 @@ class SendingTaskSubscribers extends APIEndpoint {
|
||||
$this->wp = $wp;
|
||||
}
|
||||
|
||||
function listing($data = []) {
|
||||
public function listing($data = []) {
|
||||
$newsletter_id = !empty($data['params']['id']) ? (int)$data['params']['id'] : false;
|
||||
$tasks_ids = SendingQueueModel::select('task_id')
|
||||
->where('newsletter_id', $newsletter_id)
|
||||
@ -72,7 +72,7 @@ class SendingTaskSubscribers extends APIEndpoint {
|
||||
]);
|
||||
}
|
||||
|
||||
function resend($data = []) {
|
||||
public function resend($data = []) {
|
||||
$task_id = !empty($data['taskId']) ? (int)$data['taskId'] : false;
|
||||
$subscriber_id = !empty($data['subscriberId']) ? (int)$data['subscriberId'] : false;
|
||||
$task_subscriber = ScheduledTaskSubscriber::where('task_id', $task_id)
|
||||
|
@ -33,7 +33,7 @@ class Services extends APIEndpoint {
|
||||
'global' => AccessControl::PERMISSION_MANAGE_SETTINGS,
|
||||
];
|
||||
|
||||
function __construct(Bridge $bridge, SettingsController $settings, AnalyticsHelper $analytics, SPFCheck $spf_check) {
|
||||
public function __construct(Bridge $bridge, SettingsController $settings, AnalyticsHelper $analytics, SPFCheck $spf_check) {
|
||||
$this->bridge = $bridge;
|
||||
$this->settings = $settings;
|
||||
$this->analytics = $analytics;
|
||||
@ -41,7 +41,7 @@ class Services extends APIEndpoint {
|
||||
$this->date_time = new DateTime();
|
||||
}
|
||||
|
||||
function checkSPFRecord($data = []) {
|
||||
public function checkSPFRecord($data = []) {
|
||||
$sender_address = $this->settings->get('sender.address');
|
||||
$domain_name = mb_substr($sender_address, mb_strpos($sender_address, '@') + 1);
|
||||
|
||||
@ -57,7 +57,7 @@ class Services extends APIEndpoint {
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
function checkMSSKey($data = []) {
|
||||
public function checkMSSKey($data = []) {
|
||||
$key = isset($data['key']) ? trim($data['key']) : null;
|
||||
|
||||
if (!$key) {
|
||||
@ -119,7 +119,7 @@ class Services extends APIEndpoint {
|
||||
return $this->errorResponse([APIError::BAD_REQUEST => $error]);
|
||||
}
|
||||
|
||||
function checkPremiumKey($data = []) {
|
||||
public function checkPremiumKey($data = []) {
|
||||
$key = isset($data['key']) ? trim($data['key']) : null;
|
||||
|
||||
if (!$key) {
|
||||
|
@ -47,11 +47,11 @@ class Settings extends APIEndpoint {
|
||||
$this->wc_transactional_emails = $wc_transactional_emails;
|
||||
}
|
||||
|
||||
function get() {
|
||||
public function get() {
|
||||
return $this->successResponse($this->settings->getAll());
|
||||
}
|
||||
|
||||
function set($settings = []) {
|
||||
public function set($settings = []) {
|
||||
if (empty($settings)) {
|
||||
return $this->badRequest(
|
||||
[
|
||||
|
@ -18,12 +18,12 @@ class Setup extends APIEndpoint {
|
||||
/** @var Activator */
|
||||
private $activator;
|
||||
|
||||
function __construct(WPFunctions $wp, Activator $activator) {
|
||||
public function __construct(WPFunctions $wp, Activator $activator) {
|
||||
$this->wp = $wp;
|
||||
$this->activator = $activator;
|
||||
}
|
||||
|
||||
function reset() {
|
||||
public function reset() {
|
||||
try {
|
||||
$this->activator->deactivate();
|
||||
$this->activator->activate();
|
||||
|
@ -94,7 +94,7 @@ class Subscribers extends APIEndpoint {
|
||||
$this->subscription_url_factory = $subscription_url_factory;
|
||||
}
|
||||
|
||||
function get($data = []) {
|
||||
public function get($data = []) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$subscriber = Subscriber::findOne($id);
|
||||
if ($subscriber === false) {
|
||||
@ -111,7 +111,7 @@ class Subscribers extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function listing($data = []) {
|
||||
public function listing($data = []) {
|
||||
|
||||
if (!isset($data['filter']['segment'])) {
|
||||
$listing_data = $this->listing_handler->get('\MailPoet\Models\Subscriber', $data);
|
||||
@ -159,7 +159,7 @@ class Subscribers extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function subscribe($data = []) {
|
||||
public function subscribe($data = []) {
|
||||
$form_id = (isset($data['form_id']) ? (int)$data['form_id'] : false);
|
||||
$form = Form::findOne($form_id);
|
||||
unset($data['form_id']);
|
||||
@ -336,7 +336,7 @@ class Subscribers extends APIEndpoint {
|
||||
return true;
|
||||
}
|
||||
|
||||
function save($data = []) {
|
||||
public function save($data = []) {
|
||||
if (empty($data['segments'])) {
|
||||
$data['segments'] = [];
|
||||
}
|
||||
@ -400,7 +400,7 @@ class Subscribers extends APIEndpoint {
|
||||
return array_diff($data['segments'], $old_segment_ids);
|
||||
}
|
||||
|
||||
function restore($data = []) {
|
||||
public function restore($data = []) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$subscriber = Subscriber::findOne($id);
|
||||
if ($subscriber instanceof Subscriber) {
|
||||
@ -418,7 +418,7 @@ class Subscribers extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function trash($data = []) {
|
||||
public function trash($data = []) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$subscriber = Subscriber::findOne($id);
|
||||
if ($subscriber instanceof Subscriber) {
|
||||
@ -436,7 +436,7 @@ class Subscribers extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function delete($data = []) {
|
||||
public function delete($data = []) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$subscriber = Subscriber::findOne($id);
|
||||
if ($subscriber instanceof Subscriber) {
|
||||
@ -449,7 +449,7 @@ class Subscribers extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function sendConfirmationEmail($data = []) {
|
||||
public function sendConfirmationEmail($data = []) {
|
||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
||||
$subscriber = Subscriber::findOne($id);
|
||||
if ($subscriber instanceof Subscriber) {
|
||||
@ -464,7 +464,7 @@ class Subscribers extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function bulkAction($data = []) {
|
||||
public function bulkAction($data = []) {
|
||||
try {
|
||||
if (!isset($data['listing']['filter']['segment'])) {
|
||||
return $this->successResponse(
|
||||
|
@ -17,11 +17,11 @@ class UserFlags extends APIEndpoint {
|
||||
'global' => AccessControl::ALL_ROLES_ACCESS,
|
||||
];
|
||||
|
||||
function __construct(UserFlagsController $user_flags) {
|
||||
public function __construct(UserFlagsController $user_flags) {
|
||||
$this->user_flags = $user_flags;
|
||||
}
|
||||
|
||||
function set(array $flags = []) {
|
||||
public function set(array $flags = []) {
|
||||
if (empty($flags)) {
|
||||
return $this->badRequest(
|
||||
[
|
||||
|
@ -18,11 +18,11 @@ class WoocommerceSettings extends APIEndpoint {
|
||||
/** @var WPFunctions */
|
||||
private $wp;
|
||||
|
||||
function __construct(WPFunctions $wp) {
|
||||
public function __construct(WPFunctions $wp) {
|
||||
$this->wp = $wp;
|
||||
}
|
||||
|
||||
function set($data = []) {
|
||||
public function set($data = []) {
|
||||
foreach ($data as $option => $value) {
|
||||
if (in_array($option, $this->allowed_settings)) {
|
||||
$this->wp->updateOption($option, $value);
|
||||
|
Reference in New Issue
Block a user