Move WPHooks methods to WPFunctions
This commit is contained in:
@ -6,7 +6,7 @@ use MailPoetVendor\Psr\Container\ContainerInterface;
|
||||
use MailPoet\Models\Setting;
|
||||
use MailPoet\Util\Helpers;
|
||||
use MailPoet\Util\Security;
|
||||
use MailPoet\WP\Hooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
@ -26,10 +26,17 @@ class API {
|
||||
|
||||
/** @var AccessControl */
|
||||
private $access_control;
|
||||
|
||||
/** @var WPFunctions */
|
||||
private $wp;
|
||||
|
||||
const CURRENT_VERSION = 'v1';
|
||||
|
||||
function __construct(ContainerInterface $container, AccessControl $access_control) {
|
||||
function __construct(ContainerInterface $container, AccessControl $access_control, WPFunctions $wp = null) {
|
||||
if($wp === null) {
|
||||
$wp = new WPFunctions;
|
||||
}
|
||||
$this->wp = $wp;
|
||||
$this->container = $container;
|
||||
$this->access_control = $access_control;
|
||||
foreach($this->_available_api_versions as $available_api_version) {
|
||||
@ -61,7 +68,7 @@ class API {
|
||||
}
|
||||
|
||||
function setupAjax() {
|
||||
Hooks::doAction('mailpoet_api_setup', array($this));
|
||||
$this->wp->doAction('mailpoet_api_setup', array($this));
|
||||
$this->setRequestData($_POST);
|
||||
|
||||
$ignoreToken = (
|
||||
|
@ -4,7 +4,7 @@ namespace MailPoet\API\JSON\v1;
|
||||
|
||||
use MailPoet\API\JSON\Endpoint as APIEndpoint;
|
||||
use MailPoet\Config\AccessControl;
|
||||
use MailPoet\WP\Hooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
use MailPoet\WP\Posts as WPPosts;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
@ -12,12 +12,14 @@ if(!defined('ABSPATH')) exit;
|
||||
class AutomatedLatestContent extends APIEndpoint {
|
||||
/** @var \MailPoet\Newsletter\AutomatedLatestContent */
|
||||
public $ALC;
|
||||
private $wp;
|
||||
public $permissions = array(
|
||||
'global' => AccessControl::PERMISSION_MANAGE_EMAILS
|
||||
);
|
||||
|
||||
function __construct(\MailPoet\Newsletter\AutomatedLatestContent $alc) {
|
||||
function __construct(\MailPoet\Newsletter\AutomatedLatestContent $alc, WPFunctions $wp) {
|
||||
$this->ALC = $alc;
|
||||
$this->wp = $wp;
|
||||
}
|
||||
|
||||
function getPostTypes() {
|
||||
@ -56,7 +58,7 @@ class AutomatedLatestContent extends APIEndpoint {
|
||||
'order' => 'ASC'
|
||||
);
|
||||
|
||||
$args = Hooks::applyFilters('mailpoet_search_terms_args', $args);
|
||||
$args = $this->wp->applyFilters('mailpoet_search_terms_args', $args);
|
||||
$terms = WPPosts::getTerms($args);
|
||||
|
||||
return $this->successResponse(array_values($terms));
|
||||
|
@ -20,7 +20,6 @@ use MailPoet\Models\Subscriber;
|
||||
use MailPoet\Newsletter\Renderer\Renderer;
|
||||
use MailPoet\Newsletter\Scheduler\Scheduler;
|
||||
use MailPoet\Newsletter\Url as NewsletterUrl;
|
||||
use MailPoet\WP\Hooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
@ -63,13 +62,13 @@ class Newsletters extends APIEndpoint {
|
||||
->withOptions()
|
||||
->withSendingQueue()
|
||||
->asArray();
|
||||
$newsletter = Hooks::applyFilters('mailpoet_api_newsletters_get_after', $newsletter);
|
||||
$newsletter = $this->wp->applyFilters('mailpoet_api_newsletters_get_after', $newsletter);
|
||||
return $this->successResponse($newsletter);
|
||||
}
|
||||
}
|
||||
|
||||
function save($data = array()) {
|
||||
$data = Hooks::applyFilters('mailpoet_api_newsletters_save_before', $data);
|
||||
$data = $this->wp->applyFilters('mailpoet_api_newsletters_save_before', $data);
|
||||
|
||||
$segments = array();
|
||||
if(isset($data['segments'])) {
|
||||
@ -161,7 +160,7 @@ class Newsletters extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
Hooks::doAction('mailpoet_api_newsletters_save_after', $newsletter);
|
||||
$this->wp->doAction('mailpoet_api_newsletters_save_after', $newsletter);
|
||||
|
||||
$preview_url = NewsletterUrl::getViewInBrowserUrl(
|
||||
NewsletterUrl::TYPE_LISTING_EDITOR,
|
||||
@ -281,7 +280,7 @@ class Newsletters extends APIEndpoint {
|
||||
if(!empty($errors)) {
|
||||
return $this->errorResponse($errors);
|
||||
} else {
|
||||
Hooks::doAction('mailpoet_api_newsletters_duplicate_after', $newsletter, $duplicate);
|
||||
$this->wp->doAction('mailpoet_api_newsletters_duplicate_after', $newsletter, $duplicate);
|
||||
return $this->successResponse(
|
||||
Newsletter::findOne($duplicate->id)->asArray(),
|
||||
array('count' => 1)
|
||||
@ -438,7 +437,7 @@ class Newsletters extends APIEndpoint {
|
||||
$queue
|
||||
);
|
||||
|
||||
$data[] = Hooks::applyFilters('mailpoet_api_newsletters_listing_item', $newsletter->asArray());
|
||||
$data[] = $this->wp->applyFilters('mailpoet_api_newsletters_listing_item', $newsletter->asArray());
|
||||
}
|
||||
|
||||
return $this->successResponse($data, array(
|
||||
|
@ -3,25 +3,31 @@
|
||||
namespace MailPoet\API\JSON\v1;
|
||||
|
||||
use MailPoet\API\JSON\Endpoint as APIEndpoint;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
use MailPoet\Config\AccessControl;
|
||||
use MailPoet\Config\Activator;
|
||||
use MailPoet\WP\Hooks;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class Setup extends APIEndpoint {
|
||||
private $wp;
|
||||
public $permissions = array(
|
||||
'global' => AccessControl::PERMISSION_MANAGE_SETTINGS
|
||||
);
|
||||
|
||||
function __construct(WPFunctions $wp) {
|
||||
$this->wp = $wp;
|
||||
}
|
||||
|
||||
function reset() {
|
||||
try {
|
||||
$activator = new Activator();
|
||||
$activator->deactivate();
|
||||
$activator->activate();
|
||||
Hooks::doAction('mailpoet_setup_reset');
|
||||
$this->wp->doAction('mailpoet_setup_reset');
|
||||
return $this->successResponse();
|
||||
} catch(\Exception $e) {
|
||||
dd($e->getMessage());
|
||||
return $this->errorResponse(array(
|
||||
$e->getCode() => $e->getMessage()
|
||||
));
|
||||
|
@ -17,7 +17,7 @@ use MailPoet\Segments\SubscribersListings;
|
||||
use MailPoet\Subscribers\RequiredCustomFieldValidator;
|
||||
use MailPoet\Subscribers\Source;
|
||||
use MailPoet\Subscription\Throttling as SubscriptionThrottling;
|
||||
use MailPoet\WP\Hooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
@ -41,16 +41,20 @@ class Subscribers extends APIEndpoint {
|
||||
/** @var Listing\Handler */
|
||||
private $listing_handler;
|
||||
|
||||
private $wp;
|
||||
|
||||
public function __construct(
|
||||
Listing\BulkActionController $bulk_action_controller,
|
||||
SubscribersListings $subscribers_listings,
|
||||
RequiredCustomFieldValidator $required_custom_field_validator,
|
||||
Listing\Handler $listing_handler
|
||||
Listing\Handler $listing_handler,
|
||||
WPFunctions $wp
|
||||
) {
|
||||
$this->bulk_action_controller = $bulk_action_controller;
|
||||
$this->subscribers_listings = $subscribers_listings;
|
||||
$this->required_custom_field_validator = $required_custom_field_validator;
|
||||
$this->listing_handler = $listing_handler;
|
||||
$this->wp = $wp;
|
||||
}
|
||||
|
||||
function get($data = array()) {
|
||||
@ -85,7 +89,7 @@ class Subscribers extends APIEndpoint {
|
||||
->asArray();
|
||||
}
|
||||
|
||||
$listing_data['filters']['segment'] = Hooks::applyFilters(
|
||||
$listing_data['filters']['segment'] = $this->wp->applyFilters(
|
||||
'mailpoet_subscribers_listings_filters_segments',
|
||||
$listing_data['filters']['segment']
|
||||
);
|
||||
|
Reference in New Issue
Block a user