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']
|
||||
);
|
||||
|
@ -4,7 +4,7 @@ namespace MailPoet\Analytics;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use MailPoet\Models\Setting;
|
||||
use MailPoet\WP\Hooks as WPHooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
@ -16,15 +16,17 @@ class Analytics {
|
||||
|
||||
/** @var Reporter */
|
||||
private $reporter;
|
||||
private $wp;
|
||||
|
||||
public function __construct(Reporter $reporter) {
|
||||
$this->reporter = $reporter;
|
||||
$this->wp = new WPFunctions;
|
||||
}
|
||||
|
||||
/** @return array */
|
||||
function generateAnalytics() {
|
||||
if($this->shouldSend()) {
|
||||
$data = WPHooks::applyFilters(self::ANALYTICS_FILTER, $this->reporter->getData());
|
||||
$data = $this->wp->applyFilters(self::ANALYTICS_FILTER, $this->reporter->getData());
|
||||
$this->recordDataSent();
|
||||
return $data;
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace MailPoet\Config;
|
||||
|
||||
use MailPoet\WP\Hooks as WPHooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
@ -24,40 +24,41 @@ class AccessControl {
|
||||
}
|
||||
|
||||
static function getDefaultPermissions() {
|
||||
$wp = new WPFunctions;
|
||||
return array(
|
||||
self::PERMISSION_ACCESS_PLUGIN_ADMIN => WPHooks::applyFilters(
|
||||
self::PERMISSION_ACCESS_PLUGIN_ADMIN => $wp->applyFilters(
|
||||
'mailpoet_permission_access_plugin_admin',
|
||||
array(
|
||||
'administrator',
|
||||
'editor'
|
||||
)
|
||||
),
|
||||
self::PERMISSION_MANAGE_SETTINGS => WPHooks::applyFilters(
|
||||
self::PERMISSION_MANAGE_SETTINGS => $wp->applyFilters(
|
||||
'mailpoet_permission_manage_settings',
|
||||
array(
|
||||
'administrator'
|
||||
)
|
||||
),
|
||||
self::PERMISSION_MANAGE_EMAILS => WPHooks::applyFilters(
|
||||
self::PERMISSION_MANAGE_EMAILS => $wp->applyFilters(
|
||||
'mailpoet_permission_manage_emails',
|
||||
array(
|
||||
'administrator',
|
||||
'editor'
|
||||
)
|
||||
),
|
||||
self::PERMISSION_MANAGE_SUBSCRIBERS => WPHooks::applyFilters(
|
||||
self::PERMISSION_MANAGE_SUBSCRIBERS => $wp->applyFilters(
|
||||
'mailpoet_permission_manage_subscribers',
|
||||
array(
|
||||
'administrator'
|
||||
)
|
||||
),
|
||||
self::PERMISSION_MANAGE_FORMS => WPHooks::applyFilters(
|
||||
self::PERMISSION_MANAGE_FORMS => $wp->applyFilters(
|
||||
'mailpoet_permission_manage_forms',
|
||||
array(
|
||||
'administrator'
|
||||
)
|
||||
),
|
||||
self::PERMISSION_MANAGE_SEGMENTS => WPHooks::applyFilters(
|
||||
self::PERMISSION_MANAGE_SEGMENTS => $wp->applyFilters(
|
||||
'mailpoet_permission_manage_segments',
|
||||
array(
|
||||
'administrator'
|
||||
|
@ -2,17 +2,22 @@
|
||||
|
||||
namespace MailPoet\Config;
|
||||
|
||||
use MailPoet\WP\Hooks as WPHooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class Capabilities {
|
||||
const MEMBERS_CAP_GROUP_NAME = 'mailpoet';
|
||||
|
||||
private $renderer = null;
|
||||
private $wp;
|
||||
|
||||
function __construct($renderer = null) {
|
||||
function __construct($renderer = null, WPFunctions $wp = null) {
|
||||
if($renderer !== null) {
|
||||
$this->renderer = $renderer;
|
||||
}
|
||||
if($wp == null) {
|
||||
$wp = new WPFunctions;
|
||||
}
|
||||
$this->wp = $wp;
|
||||
}
|
||||
|
||||
function init() {
|
||||
@ -48,9 +53,9 @@ class Capabilities {
|
||||
}
|
||||
|
||||
function setupMembersCapabilities() {
|
||||
WPHooks::addAction('admin_enqueue_scripts', array($this, 'enqueueMembersStyles'));
|
||||
WPHooks::addAction('members_register_cap_groups', array($this, 'registerMembersCapGroup'));
|
||||
WPHooks::addAction('members_register_caps', array($this, 'registerMembersCapabilities'));
|
||||
$this->wp->addAction('admin_enqueue_scripts', array($this, 'enqueueMembersStyles'));
|
||||
$this->wp->addAction('members_register_cap_groups', array($this, 'registerMembersCapGroup'));
|
||||
$this->wp->addAction('members_register_caps', array($this, 'registerMembersCapabilities'));
|
||||
}
|
||||
|
||||
function enqueueMembersStyles() {
|
||||
|
@ -4,9 +4,15 @@ namespace MailPoet\Config;
|
||||
|
||||
use MailPoet\Models\Setting;
|
||||
use MailPoet\Util\Url;
|
||||
use MailPoet\WP\Hooks as WPHooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class Changelog {
|
||||
private $wp;
|
||||
|
||||
function __construct() {
|
||||
$this->wp = new WPFunctions;
|
||||
}
|
||||
|
||||
function init() {
|
||||
$doing_ajax = (bool)(defined('DOING_AJAX') && DOING_AJAX);
|
||||
|
||||
@ -45,7 +51,7 @@ class Changelog {
|
||||
// Migration from MP2
|
||||
$redirect_url = admin_url('admin.php?page=mailpoet-migration');
|
||||
} else {
|
||||
$skip_wizard = WPHooks::applyFilters('mailpoet_skip_welcome_wizard', false);
|
||||
$skip_wizard = $this->wp->applyFilters('mailpoet_skip_welcome_wizard', false);
|
||||
$redirect_url = $skip_wizard ? null : admin_url('admin.php?page=mailpoet-welcome-wizard');
|
||||
|
||||
// ensure there was no MP2 migration (migration resets $version so it must be checked)
|
||||
|
@ -7,9 +7,15 @@ use MailPoet\Models\Subscriber;
|
||||
use MailPoet\Models\SubscriberSegment;
|
||||
use MailPoet\Newsletter\Url as NewsletterUrl;
|
||||
use MailPoet\Subscription\Pages;
|
||||
use MailPoet\WP\Hooks as WPHooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class Shortcodes {
|
||||
private $wp;
|
||||
|
||||
function __construct() {
|
||||
$this->wp = new WPFunctions;
|
||||
}
|
||||
|
||||
function init() {
|
||||
// form widget shortcode
|
||||
add_shortcode('mailpoet_form', array($this, 'formWidget'));
|
||||
@ -27,10 +33,10 @@ class Shortcodes {
|
||||
$this, 'getArchive'
|
||||
));
|
||||
|
||||
WPHooks::addFilter('mailpoet_archive_date', array(
|
||||
$this->wp->addFilter('mailpoet_archive_date', array(
|
||||
$this, 'renderArchiveDate'
|
||||
), 2);
|
||||
WPHooks::addFilter('mailpoet_archive_subject', array(
|
||||
$this->wp->addFilter('mailpoet_archive_subject', array(
|
||||
$this, 'renderArchiveSubject'
|
||||
), 2, 3);
|
||||
|
||||
@ -86,12 +92,12 @@ class Shortcodes {
|
||||
$subscriber = Subscriber::getCurrentWPUser();
|
||||
|
||||
if(empty($newsletters)) {
|
||||
return WPHooks::applyFilters(
|
||||
return $this->wp->applyFilters(
|
||||
'mailpoet_archive_no_newsletters',
|
||||
__('Oops! There are no newsletters to display.', 'mailpoet')
|
||||
);
|
||||
} else {
|
||||
$title = WPHooks::applyFilters('mailpoet_archive_title', '');
|
||||
$title = $this->wp->applyFilters('mailpoet_archive_title', '');
|
||||
if(!empty($title)) {
|
||||
$html .= '<h3 class="mailpoet_archive_title">'.$title.'</h3>';
|
||||
}
|
||||
@ -100,10 +106,10 @@ class Shortcodes {
|
||||
$queue = $newsletter->queue()->findOne();
|
||||
$html .= '<li>'.
|
||||
'<span class="mailpoet_archive_date">'.
|
||||
WPHooks::applyFilters('mailpoet_archive_date', $newsletter).
|
||||
$this->wp->applyFilters('mailpoet_archive_date', $newsletter).
|
||||
'</span>
|
||||
<span class="mailpoet_archive_subject">'.
|
||||
WPHooks::applyFilters('mailpoet_archive_subject', $newsletter, $subscriber, $queue).
|
||||
$this->wp->applyFilters('mailpoet_archive_subject', $newsletter, $subscriber, $queue).
|
||||
'</span>
|
||||
</li>';
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ use MailPoet\Models\Setting;
|
||||
use MailPoet\Router\Endpoints\CronDaemon as CronDaemonEndpoint;
|
||||
use MailPoet\Router\Router;
|
||||
use MailPoet\Util\Security;
|
||||
use MailPoet\WP\Hooks as WPHooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
@ -130,7 +129,10 @@ class CronHelper {
|
||||
}
|
||||
|
||||
static function queryCronUrl($url, $wp = null) {
|
||||
$args = WPHooks::applyFilters(
|
||||
if(is_null($wp)) {
|
||||
$wp = new WPFunctions();
|
||||
}
|
||||
$args = $wp->applyFilters(
|
||||
'mailpoet_cron_request_args',
|
||||
array(
|
||||
'blocking' => true,
|
||||
@ -139,19 +141,19 @@ class CronHelper {
|
||||
'user-agent' => 'MailPoet Cron'
|
||||
)
|
||||
);
|
||||
if(is_null($wp)) {
|
||||
$wp = new WPFunctions();
|
||||
}
|
||||
return $wp->wpRemotePost($url, $args);
|
||||
}
|
||||
|
||||
static function getCronUrl($action, $data = false) {
|
||||
static function getCronUrl($action, $data = false, $wp = null) {
|
||||
if(is_null($wp)) {
|
||||
$wp = new WPFunctions();
|
||||
}
|
||||
$url = Router::buildRequest(
|
||||
CronDaemonEndpoint::ENDPOINT,
|
||||
$action,
|
||||
$data
|
||||
);
|
||||
$custom_cron_url = WPHooks::applyFilters('mailpoet_cron_request_url', $url);
|
||||
$custom_cron_url = $wp->applyFilters('mailpoet_cron_request_url', $url);
|
||||
return ($custom_cron_url === $url) ?
|
||||
str_replace(home_url(), self::getSiteUrl(), $url) :
|
||||
$custom_cron_url;
|
||||
|
@ -15,7 +15,7 @@ use MailPoet\Models\Subscriber as SubscriberModel;
|
||||
use MailPoet\Segments\SubscribersFinder;
|
||||
use MailPoet\Tasks\Sending as SendingTask;
|
||||
use MailPoet\Tasks\Subscribers\BatchIterator;
|
||||
use MailPoet\WP\Hooks as WPHooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
@ -39,7 +39,8 @@ class SendingQueue {
|
||||
$this->mailer_task = ($mailer_task) ? $mailer_task : new MailerTask();
|
||||
$this->newsletter_task = ($newsletter_task) ? $newsletter_task : new NewsletterTask();
|
||||
$this->timer = ($timer) ? $timer : microtime(true);
|
||||
$this->batch_size = WPHooks::applyFilters('mailpoet_cron_worker_sending_queue_batch_size', self::BATCH_SIZE);
|
||||
$wp = new WPFunctions;
|
||||
$this->batch_size = $wp->applyFilters('mailpoet_cron_worker_sending_queue_batch_size', self::BATCH_SIZE);
|
||||
}
|
||||
|
||||
function process() {
|
||||
|
@ -13,7 +13,7 @@ use MailPoet\Models\Setting;
|
||||
use MailPoet\Newsletter\Links\Links as NewsletterLinks;
|
||||
use MailPoet\Newsletter\Renderer\PostProcess\OpenTracking;
|
||||
use MailPoet\Util\Helpers;
|
||||
use MailPoet\WP\Hooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
@ -21,8 +21,14 @@ class Newsletter {
|
||||
public $tracking_enabled;
|
||||
public $tracking_image_inserted;
|
||||
|
||||
function __construct() {
|
||||
private $wp;
|
||||
|
||||
function __construct(WPFunctions $wp = null) {
|
||||
$this->tracking_enabled = (boolean)Setting::getValue('tracking.enabled');
|
||||
if($wp == null) {
|
||||
$wp = new WPFunctions;
|
||||
}
|
||||
$this->wp = $wp;
|
||||
}
|
||||
|
||||
function getNewsletterFromQueue($queue) {
|
||||
@ -66,7 +72,7 @@ class Newsletter {
|
||||
$this->tracking_image_inserted = OpenTracking::addTrackingImage();
|
||||
// render newsletter
|
||||
$rendered_newsletter = $newsletter->render();
|
||||
$rendered_newsletter = Hooks::applyFilters(
|
||||
$rendered_newsletter = $this->wp->applyFilters(
|
||||
'mailpoet_sending_newsletter_render_after',
|
||||
$rendered_newsletter,
|
||||
$newsletter
|
||||
@ -76,7 +82,7 @@ class Newsletter {
|
||||
} else {
|
||||
// render newsletter
|
||||
$rendered_newsletter = $newsletter->render();
|
||||
$rendered_newsletter = Hooks::applyFilters(
|
||||
$rendered_newsletter = $this->wp->applyFilters(
|
||||
'mailpoet_sending_newsletter_render_after',
|
||||
$rendered_newsletter,
|
||||
$newsletter
|
||||
|
@ -9,12 +9,13 @@ use MailPoet\Form\Renderer as FormRenderer;
|
||||
use MailPoet\Models\Form;
|
||||
use MailPoet\Models\Setting;
|
||||
use MailPoet\Util\Security;
|
||||
use MailPoet\WP\Hooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class Widget extends \WP_Widget {
|
||||
private $renderer;
|
||||
private $wp;
|
||||
|
||||
const RECAPTCHA_API_URL = 'https://www.google.com/recaptcha/api.js?onload=reCaptchaCallback&render=explicit';
|
||||
|
||||
@ -24,7 +25,7 @@ class Widget extends \WP_Widget {
|
||||
__('MailPoet 3 Form', 'mailpoet'),
|
||||
array('description' => __('Add a newsletter subscription form', 'mailpoet'))
|
||||
);
|
||||
|
||||
$this->wp = new WPFunctions;
|
||||
$this->renderer = new \MailPoet\Config\Renderer(!WP_DEBUG, !WP_DEBUG);
|
||||
if(!is_admin()) {
|
||||
$this->setupIframe();
|
||||
@ -255,7 +256,7 @@ EOL;
|
||||
$instance = $args;
|
||||
}
|
||||
|
||||
$title = Hooks::applyFilters(
|
||||
$title = $this->wp->applyFilters(
|
||||
'widget_title',
|
||||
!empty($instance['title']) ? $instance['title'] : '',
|
||||
$instance,
|
||||
@ -321,7 +322,7 @@ EOL;
|
||||
try {
|
||||
$output = $renderer->render('form/widget.html', $data);
|
||||
$output = do_shortcode($output);
|
||||
$output = Hooks::applyFilters('mailpoet_form_widget_post_process', $output);
|
||||
$output = $this->wp->applyFilters('mailpoet_form_widget_post_process', $output);
|
||||
} catch(\Exception $e) {
|
||||
$output = $e->getMessage();
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ namespace MailPoet\Mailer\Methods;
|
||||
|
||||
use MailPoet\Mailer\Mailer;
|
||||
use MailPoet\Mailer\Methods\ErrorMappers\SMTPMapper;
|
||||
use MailPoet\WP\Hooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
@ -24,9 +24,12 @@ class SMTP {
|
||||
/** @var SMTPMapper */
|
||||
private $error_mapper;
|
||||
|
||||
private $wp;
|
||||
|
||||
function __construct(
|
||||
$host, $port, $authentication, $login = null, $password = null, $encryption,
|
||||
$sender, $reply_to, $return_path, SMTPMapper $error_mapper) {
|
||||
$this->wp = new WPFunctions;
|
||||
$this->host = $host;
|
||||
$this->port = $port;
|
||||
$this->authentication = $authentication;
|
||||
@ -64,14 +67,14 @@ class SMTP {
|
||||
function buildMailer() {
|
||||
$transport = \Swift_SmtpTransport::newInstance(
|
||||
$this->host, $this->port, $this->encryption);
|
||||
$connection_timeout = Hooks::applyFilters('mailpoet_mailer_smtp_connection_timeout', self::SMTP_CONNECTION_TIMEOUT);
|
||||
$connection_timeout = $this->wp->applyFilters('mailpoet_mailer_smtp_connection_timeout', self::SMTP_CONNECTION_TIMEOUT);
|
||||
$transport->setTimeout($connection_timeout);
|
||||
if($this->authentication) {
|
||||
$transport
|
||||
->setUsername($this->login)
|
||||
->setPassword($this->password);
|
||||
}
|
||||
$transport = Hooks::applyFilters('mailpoet_mailer_smtp_transport_agent', $transport);
|
||||
$transport = $this->wp->applyFilters('mailpoet_mailer_smtp_transport_agent', $transport);
|
||||
return \Swift_Mailer::newInstance($transport);
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace MailPoet\Newsletter\Editor;
|
||||
|
||||
use MailPoet\WP\Hooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
@ -11,8 +11,10 @@ class PostContentManager {
|
||||
|
||||
public $max_excerpt_length = 60;
|
||||
|
||||
|
||||
function __construct() {
|
||||
$this->max_excerpt_length = Hooks::applyFilters('mailpoet_newsletter_post_excerpt_length', $this->max_excerpt_length);
|
||||
$wp = new WPFunctions;
|
||||
$this->max_excerpt_length = $wp->applyFilters('mailpoet_newsletter_post_excerpt_length', $this->max_excerpt_length);
|
||||
}
|
||||
|
||||
function getContent($post, $displayType) {
|
||||
|
@ -4,14 +4,16 @@ namespace MailPoet\Segments;
|
||||
|
||||
use MailPoet\Listing\Handler;
|
||||
use MailPoet\Models\Segment;
|
||||
use MailPoet\WP\Hooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class BulkAction {
|
||||
|
||||
private $data = null;
|
||||
private $wp;
|
||||
|
||||
function __construct($data) {
|
||||
$this->data = $data;
|
||||
$this->wp = new WPFunctions;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -42,7 +44,7 @@ class BulkAction {
|
||||
$bulk_action = new \MailPoet\Listing\BulkActionController(new Handler());
|
||||
return $bulk_action->apply('\MailPoet\Models\Subscriber', $this->data);
|
||||
} else {
|
||||
$handlers = Hooks::applyFilters('mailpoet_subscribers_in_segment_apply_bulk_action_handlers', array());
|
||||
$handlers = $this->wp->applyFilters('mailpoet_subscribers_in_segment_apply_bulk_action_handlers', array());
|
||||
foreach($handlers as $handler) {
|
||||
$meta = $handler->apply($segment, $this->data);
|
||||
if($meta) {
|
||||
|
@ -6,11 +6,17 @@ use MailPoet\Models\ScheduledTask;
|
||||
use MailPoet\Models\ScheduledTaskSubscriber;
|
||||
use MailPoet\Models\Segment;
|
||||
use MailPoet\Models\Subscriber;
|
||||
use MailPoet\WP\Hooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
use function MailPoet\Util\array_column;
|
||||
|
||||
class SubscribersFinder {
|
||||
|
||||
private $wp;
|
||||
|
||||
function __construct() {
|
||||
$this->wp = new WPFunctions;
|
||||
}
|
||||
|
||||
function findSubscribersInSegments($subscribers_to_process_ids, $newsletter_segments_ids) {
|
||||
$result = array();
|
||||
foreach($newsletter_segments_ids as $segment_id) {
|
||||
@ -25,7 +31,7 @@ class SubscribersFinder {
|
||||
$subscribers = Subscriber::findSubscribersInSegments($subscribers_to_process_ids, array($segment->id))->findMany();
|
||||
return Subscriber::extractSubscribersIds($subscribers);
|
||||
}
|
||||
$finders = Hooks::applyFilters('mailpoet_get_subscribers_in_segment_finders', array());
|
||||
$finders = $this->wp->applyFilters('mailpoet_get_subscribers_in_segment_finders', array());
|
||||
foreach($finders as $finder) {
|
||||
$subscribers = $finder->findSubscribersInSegment($segment, $subscribers_to_process_ids);
|
||||
if($subscribers) {
|
||||
@ -93,7 +99,7 @@ class SubscribersFinder {
|
||||
}
|
||||
|
||||
private function addSubscribersToTaskFromDynamicSegment(ScheduledTask $task, Segment $segment) {
|
||||
$finders = Hooks::applyFilters('mailpoet_get_subscribers_in_segment_finders', array());
|
||||
$finders = $this->wp->applyFilters('mailpoet_get_subscribers_in_segment_finders', array());
|
||||
$count = 0;
|
||||
foreach($finders as $finder) {
|
||||
$subscribers = $finder->getSubscriberIdsInSegment($segment);
|
||||
|
@ -4,15 +4,18 @@ namespace MailPoet\Segments;
|
||||
|
||||
use MailPoet\Listing\Handler;
|
||||
use MailPoet\Models\Segment;
|
||||
use MailPoet\WP\Hooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class SubscribersListings {
|
||||
|
||||
/** @var Handler */
|
||||
private $handler;
|
||||
|
||||
function __construct(Handler $handler) {
|
||||
private $wp;
|
||||
|
||||
function __construct(Handler $handler, WPFunctions $wp) {
|
||||
$this->handler = $handler;
|
||||
$this->wp = $wp;
|
||||
}
|
||||
|
||||
function getListingsInSegment($data) {
|
||||
@ -30,7 +33,7 @@ class SubscribersListings {
|
||||
) {
|
||||
return $listing_data = $this->handler->get('\MailPoet\Models\Subscriber', $data);
|
||||
}
|
||||
$handlers = Hooks::applyFilters('mailpoet_get_subscribers_listings_in_segment_handlers', array());
|
||||
$handlers = $this->wp->applyFilters('mailpoet_get_subscribers_listings_in_segment_handlers', array());
|
||||
foreach($handlers as $handler) {
|
||||
$listings = $handler->get($segment, $data);
|
||||
if($listings) {
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace MailPoet\Services\Bridge;
|
||||
|
||||
use MailPoet\WP\Hooks as WPHooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
@ -141,7 +140,7 @@ class API {
|
||||
|
||||
private function request($url, $body, $method = 'POST') {
|
||||
$params = array(
|
||||
'timeout' => WPHooks::applyFilters('mailpoet_bridge_api_request_timeout', self::REQUEST_TIMEOUT),
|
||||
'timeout' => $this->wp->applyFilters('mailpoet_bridge_api_request_timeout', self::REQUEST_TIMEOUT),
|
||||
'httpversion' => '1.0',
|
||||
'method' => $method,
|
||||
'headers' => array(
|
||||
|
@ -4,7 +4,7 @@ namespace MailPoet\Subscribers\ImportExport\Export;
|
||||
|
||||
use MailPoet\Models\Segment;
|
||||
use MailPoet\Models\Subscriber;
|
||||
use MailPoet\WP\Hooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
/**
|
||||
* Gets batches of subscribers from dynamic segments.
|
||||
@ -13,6 +13,16 @@ class DynamicSubscribersGetter extends SubscribersGetter {
|
||||
|
||||
protected $segment_index = 0;
|
||||
|
||||
private $wp;
|
||||
|
||||
function __construct($segments_ids, $batch_size, WPFunctions $wp = null) {
|
||||
parent::__construct($segments_ids, $batch_size);
|
||||
if($wp == null) {
|
||||
$wp = new WPFunctions;
|
||||
}
|
||||
$this->wp = $wp;
|
||||
}
|
||||
|
||||
public function reset() {
|
||||
parent::reset();
|
||||
$this->segment_index = 0;
|
||||
@ -21,7 +31,7 @@ class DynamicSubscribersGetter extends SubscribersGetter {
|
||||
protected function filter($subscribers) {
|
||||
$segment_id = $this->segments_ids[$this->segment_index];
|
||||
|
||||
$filters = Hooks::applyFilters(
|
||||
$filters = $this->wp->applyFilters(
|
||||
'mailpoet_get_segment_filters',
|
||||
$segment_id
|
||||
);
|
||||
|
@ -5,7 +5,7 @@ use MailPoet\Models\CustomField;
|
||||
use MailPoet\Models\Segment;
|
||||
use MailPoet\Premium\Models\DynamicSegment;
|
||||
use MailPoet\Util\Helpers;
|
||||
use MailPoet\WP\Hooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class ImportExportFactory {
|
||||
const IMPORT_ACTION = 'import';
|
||||
@ -13,8 +13,11 @@ class ImportExportFactory {
|
||||
|
||||
public $action;
|
||||
|
||||
private $wp;
|
||||
|
||||
function __construct($action = null) {
|
||||
$this->action = $action;
|
||||
$this->wp = new WPFunctions;
|
||||
}
|
||||
|
||||
function getSegments() {
|
||||
@ -22,7 +25,7 @@ class ImportExportFactory {
|
||||
$segments = Segment::getSegmentsForImport();
|
||||
} else {
|
||||
$segments = Segment::getSegmentsForExport();
|
||||
$segments = Hooks::applyFilters('mailpoet_segments_with_subscriber_count', $segments);
|
||||
$segments = $this->wp->applyFilters('mailpoet_segments_with_subscriber_count', $segments);
|
||||
$segments = array_values(array_filter($segments, function($segment) {
|
||||
return $segment['subscribers'] > 0;
|
||||
}));
|
||||
|
@ -3,15 +3,15 @@ namespace MailPoet\Subscription;
|
||||
|
||||
use MailPoet\Models\SubscriberIP;
|
||||
use MailPoet\Util\Helpers;
|
||||
use MailPoet\WP\Hooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class Throttling {
|
||||
static function throttle() {
|
||||
$subscription_limit_enabled = Hooks::applyFilters('mailpoet_subscription_limit_enabled', true);
|
||||
$wp = new WPFunctions;
|
||||
$subscription_limit_enabled = $wp->applyFilters('mailpoet_subscription_limit_enabled', true);
|
||||
|
||||
$subscription_limit_window = Hooks::applyFilters('mailpoet_subscription_limit_window', DAY_IN_SECONDS);
|
||||
$subscription_limit_base = Hooks::applyFilters('mailpoet_subscription_limit_base', MINUTE_IN_SECONDS);
|
||||
$subscription_limit_window = $wp->applyFilters('mailpoet_subscription_limit_window', DAY_IN_SECONDS);
|
||||
$subscription_limit_base = $wp->applyFilters('mailpoet_subscription_limit_base', MINUTE_IN_SECONDS);
|
||||
|
||||
$subscriber_ip = Helpers::getIP();
|
||||
$wp = new WPFunctions;
|
||||
|
@ -24,6 +24,34 @@ class Functions {
|
||||
return call_user_func_array('wp_remote_retrieve_response_message', func_get_args());
|
||||
}
|
||||
|
||||
function addFilter() {
|
||||
return call_user_func_array('add_filter', func_get_args());
|
||||
}
|
||||
|
||||
function applyFilters() {
|
||||
return call_user_func_array('apply_filters', func_get_args());
|
||||
}
|
||||
|
||||
function removeFilter() {
|
||||
return call_user_func_array('remove_filter', func_get_args());
|
||||
}
|
||||
|
||||
function addAction() {
|
||||
return call_user_func_array('add_action', func_get_args());
|
||||
}
|
||||
|
||||
function doAction() {
|
||||
return call_user_func_array('do_action', func_get_args());
|
||||
}
|
||||
|
||||
function removeAction() {
|
||||
return call_user_func_array('remove_action', func_get_args());
|
||||
}
|
||||
|
||||
function removeAllFilters() {
|
||||
return call_user_func_array('remove_all_filters', func_get_args());
|
||||
}
|
||||
|
||||
function currentTime() {
|
||||
return call_user_func_array('current_time', func_get_args());
|
||||
}
|
||||
|
@ -1,40 +0,0 @@
|
||||
<?php
|
||||
namespace MailPoet\WP;
|
||||
|
||||
class Hooks {
|
||||
static function addFilter() {
|
||||
return self::callWithFallback('add_filter', func_get_args());
|
||||
}
|
||||
|
||||
static function applyFilters() {
|
||||
return self::callWithFallback('apply_filters', func_get_args());
|
||||
}
|
||||
|
||||
static function removeFilter() {
|
||||
return self::callWithFallback('remove_filter', func_get_args());
|
||||
}
|
||||
|
||||
static function addAction() {
|
||||
return self::callWithFallback('add_action', func_get_args());
|
||||
}
|
||||
|
||||
static function doAction() {
|
||||
return self::callWithFallback('do_action', func_get_args());
|
||||
}
|
||||
|
||||
static function removeAction() {
|
||||
return self::callWithFallback('remove_action', func_get_args());
|
||||
}
|
||||
|
||||
static function removeAllFilters() {
|
||||
return self::callWithFallback('remove_all_filters', func_get_args());
|
||||
}
|
||||
|
||||
private static function callWithFallback($func, $args) {
|
||||
$local_func = __NAMESPACE__ . '\\' . $func;
|
||||
if(function_exists($local_func)) {
|
||||
return call_user_func_array($local_func, $args);
|
||||
}
|
||||
return call_user_func_array($func, $args);
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@ use MailPoet\Config\AccessControl;
|
||||
use MailPoet\DI\ContainerConfigurator;
|
||||
use MailPoetVendor\Symfony\Component\DependencyInjection\Container;
|
||||
use MailPoet\DI\ContainerFactory;
|
||||
use MailPoet\WP\Hooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
// required to be able to use wp_delete_user()
|
||||
require_once(ABSPATH . 'wp-admin/includes/user.php');
|
||||
@ -46,7 +46,7 @@ class APITest extends \MailPoetTest {
|
||||
|
||||
function testItCallsAPISetupAction() {
|
||||
$called = false;
|
||||
Hooks::addAction(
|
||||
(new WPFunctions)->addAction(
|
||||
'mailpoet_api_setup',
|
||||
function($api) use (&$called) {
|
||||
$called = true;
|
||||
@ -57,6 +57,7 @@ class APITest extends \MailPoetTest {
|
||||
$this->api,
|
||||
'setupAjax',
|
||||
array(
|
||||
'wp' => new WPFunctions,
|
||||
'processRoute' => Stub::makeEmpty(new SuccessResponse)
|
||||
)
|
||||
);
|
||||
@ -285,7 +286,6 @@ class APITest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
function _after() {
|
||||
WPHooksHelper::releaseAllHooks();
|
||||
wp_delete_user($this->wp_user_id);
|
||||
}
|
||||
}
|
||||
|
@ -3,10 +3,11 @@
|
||||
namespace MailPoet\Test\API\JSON\v1;
|
||||
|
||||
use MailPoet\API\JSON\v1\AutomatedLatestContent;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class AutomatedLatestContentTest extends \MailPoetTest {
|
||||
function testItGetsPostTypes() {
|
||||
$endpoint = new AutomatedLatestContent(new \MailPoet\Newsletter\AutomatedLatestContent());
|
||||
$endpoint = new AutomatedLatestContent(new \MailPoet\Newsletter\AutomatedLatestContent(), new WPFunctions);
|
||||
$response = $endpoint->getPostTypes();
|
||||
expect($response->data)->notEmpty();
|
||||
foreach($response->data as $post_type) {
|
||||
@ -17,7 +18,7 @@ class AutomatedLatestContentTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
function testItDoesNotGetPostTypesExludedFromSearch() {
|
||||
$endpoint = new AutomatedLatestContent(new \MailPoet\Newsletter\AutomatedLatestContent());
|
||||
$endpoint = new AutomatedLatestContent(new \MailPoet\Newsletter\AutomatedLatestContent(), new WPFunctions);
|
||||
$response = $endpoint ->getPostTypes();
|
||||
// WP's default post type 'revision' is excluded from search
|
||||
// https://codex.wordpress.org/Post_Types
|
||||
|
@ -7,6 +7,8 @@ use Codeception\Util\Fixtures;
|
||||
use Codeception\Util\Stub;
|
||||
use Helper\WordPressHooks as WPHooksHelper;
|
||||
use MailPoet\API\JSON\Response as APIResponse;
|
||||
use MailPoet\Listing\BulkActionController;
|
||||
use MailPoet\Listing\Handler;
|
||||
use MailPoet\API\JSON\v1\Newsletters;
|
||||
use MailPoet\DI\ContainerWrapper;
|
||||
use MailPoet\Models\Newsletter;
|
||||
@ -22,6 +24,7 @@ use MailPoet\Newsletter\Url;
|
||||
use MailPoet\Router\Router;
|
||||
use MailPoet\Subscription\Url as SubscriptionUrl;
|
||||
use MailPoet\Tasks\Sending as SendingTask;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class NewslettersTest extends \MailPoetTest {
|
||||
/** @var Newsletters */
|
||||
@ -98,8 +101,14 @@ class NewslettersTest extends \MailPoetTest {
|
||||
expect($response->errors[0]['message'])
|
||||
->equals('This newsletter does not exist.');
|
||||
|
||||
WPHooksHelper::interceptApplyFilters();
|
||||
|
||||
$wp = Stub::make(new WPFunctions, [
|
||||
'applyFilters' => asCallable([WPHooksHelper::class, 'applyFilters'])
|
||||
]);
|
||||
$this->endpoint = new Newsletters(
|
||||
ContainerWrapper::getInstance()->get(BulkActionController::class),
|
||||
ContainerWrapper::getInstance()->get(Handler::class),
|
||||
$wp
|
||||
);
|
||||
$response = $this->endpoint->get(array('id' => $this->newsletter->id));
|
||||
expect($response->status)->equals(APIResponse::STATUS_OK);
|
||||
expect($response->data)->equals(
|
||||
@ -128,9 +137,15 @@ class NewslettersTest extends \MailPoetTest {
|
||||
)
|
||||
);
|
||||
|
||||
WPHooksHelper::interceptApplyFilters();
|
||||
WPHooksHelper::interceptDoAction();
|
||||
|
||||
$wp = Stub::make(new WPFunctions, [
|
||||
'applyFilters' => asCallable([WPHooksHelper::class, 'applyFilters']),
|
||||
'doAction' => asCallable([WPHooksHelper::class, 'doAction'])
|
||||
]);
|
||||
$this->endpoint = new Newsletters(
|
||||
ContainerWrapper::getInstance()->get(BulkActionController::class),
|
||||
ContainerWrapper::getInstance()->get(Handler::class),
|
||||
$wp
|
||||
);
|
||||
|
||||
$response = $this->endpoint->save($valid_data);
|
||||
$saved_newsletter = Newsletter::filter('filterWithOptions', Newsletter::TYPE_STANDARD)
|
||||
@ -487,7 +502,14 @@ class NewslettersTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
function testItCanDuplicateANewsletter() {
|
||||
WPHooksHelper::interceptDoAction();
|
||||
$wp = Stub::make(new WPFunctions, [
|
||||
'doAction' => asCallable([WPHooksHelper::class, 'doAction'])
|
||||
]);
|
||||
$this->endpoint = new Newsletters(
|
||||
ContainerWrapper::getInstance()->get(BulkActionController::class),
|
||||
ContainerWrapper::getInstance()->get(Handler::class),
|
||||
$wp
|
||||
);
|
||||
|
||||
$response = $this->endpoint->duplicate(array('id' => $this->newsletter->id));
|
||||
expect($response->status)->equals(APIResponse::STATUS_OK);
|
||||
@ -846,7 +868,6 @@ class NewslettersTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
function _after() {
|
||||
WPHooksHelper::releaseAllHooks();
|
||||
\ORM::raw_execute('TRUNCATE ' . Newsletter::$_table);
|
||||
\ORM::raw_execute('TRUNCATE ' . NewsletterSegment::$_table);
|
||||
\ORM::raw_execute('TRUNCATE ' . NewsletterOptionField::$_table);
|
||||
|
@ -1,10 +1,12 @@
|
||||
<?php
|
||||
namespace MailPoet\Test\API\JSON\v1;
|
||||
|
||||
use Codeception\Stub;
|
||||
use MailPoet\Models\Setting;
|
||||
use MailPoet\API\JSON\v1\Setup;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
use Helper\WordPressHooks as WPHooksHelper;
|
||||
use MailPoet\API\JSON\Response as APIResponse;
|
||||
use MailPoet\API\JSON\v1\Setup;
|
||||
use MailPoet\Models\Setting;
|
||||
|
||||
class SetupTest extends \MailPoetTest {
|
||||
function _before() {
|
||||
@ -12,9 +14,11 @@ class SetupTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
function testItCanReinstall() {
|
||||
WPHooksHelper::interceptDoAction();
|
||||
$wp = Stub::make(new WPFunctions, [
|
||||
'doAction' => asCallable([WPHooksHelper::class, 'doAction'])
|
||||
]);
|
||||
|
||||
$router = new Setup();
|
||||
$router = new Setup($wp);
|
||||
$response = $router->reset();
|
||||
expect($response->status)->equals(APIResponse::STATUS_OK);
|
||||
|
||||
@ -26,7 +30,6 @@ class SetupTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
function _after() {
|
||||
WPHooksHelper::releaseAllHooks();
|
||||
Setting::deleteMany();
|
||||
}
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ class AnalyticsTest extends \MailPoetTest {
|
||||
$reporter = Stub::makeEmpty(
|
||||
'MailPoet\Analytics\Reporter',
|
||||
array(
|
||||
'getData' => Expected::once(function() use ($data){
|
||||
'getData' => Expected::once(function() use ($data) {
|
||||
return $data;
|
||||
}),
|
||||
),
|
||||
@ -80,7 +80,7 @@ class AnalyticsTest extends \MailPoetTest {
|
||||
|
||||
$analytics = new Analytics($reporter);
|
||||
|
||||
expect($analytics->generateAnalytics())->equals($data);
|
||||
expect($analytics->generateAnalytics())->equals(apply_filters(Analytics::ANALYTICS_FILTER, $data));
|
||||
}
|
||||
|
||||
function testGetDataIfEnabledAndSentLongTimeAgo() {
|
||||
@ -99,7 +99,7 @@ class AnalyticsTest extends \MailPoetTest {
|
||||
|
||||
$analytics = new Analytics($reporter);
|
||||
|
||||
expect($analytics->generateAnalytics())->equals($data);
|
||||
expect($analytics->generateAnalytics())->equals(apply_filters(Analytics::ANALYTICS_FILTER, $data));
|
||||
}
|
||||
|
||||
function testSetPublicId() {
|
||||
|
@ -7,7 +7,7 @@ use Codeception\Util\Stub;
|
||||
use Helper\WordPress as WPHelper;
|
||||
use Helper\WordPressHooks as WPHooksHelper;
|
||||
use MailPoet\Config\AccessControl;
|
||||
use MailPoet\WP\Hooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class AccessControlTest extends \MailPoetTest {
|
||||
function testItSetsDefaultPermissionsUponInitialization() {
|
||||
@ -38,37 +38,38 @@ class AccessControlTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
function testItAllowsSettingCustomPermissions() {
|
||||
Hooks::addFilter(
|
||||
$wp = new WPFunctions;
|
||||
$wp->addFilter(
|
||||
'mailpoet_permission_access_plugin_admin',
|
||||
function() {
|
||||
return array('custom_access_plugin_admin_role');
|
||||
}
|
||||
);
|
||||
Hooks::addFilter(
|
||||
$wp->addFilter(
|
||||
'mailpoet_permission_manage_settings',
|
||||
function() {
|
||||
return array('custom_manage_settings_role');
|
||||
}
|
||||
);
|
||||
Hooks::addFilter(
|
||||
$wp->addFilter(
|
||||
'mailpoet_permission_manage_emails',
|
||||
function() {
|
||||
return array('custom_manage_emails_role');
|
||||
}
|
||||
);
|
||||
Hooks::addFilter(
|
||||
$wp->addFilter(
|
||||
'mailpoet_permission_manage_subscribers',
|
||||
function() {
|
||||
return array('custom_manage_subscribers_role');
|
||||
}
|
||||
);
|
||||
Hooks::addFilter(
|
||||
$wp->addFilter(
|
||||
'mailpoet_permission_manage_forms',
|
||||
function() {
|
||||
return array('custom_manage_forms_role');
|
||||
}
|
||||
);
|
||||
Hooks::addFilter(
|
||||
$wp->addFilter(
|
||||
'mailpoet_permission_manage_segments',
|
||||
function() {
|
||||
return array('custom_manage_segments_role');
|
||||
|
@ -8,7 +8,7 @@ use Helper\WordPressHooks as WPHooksHelper;
|
||||
use MailPoet\Config\AccessControl;
|
||||
use MailPoet\Config\Capabilities;
|
||||
use MailPoet\Config\Renderer;
|
||||
use MailPoet\WP\Hooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class CapabilitiesTest extends \MailPoetTest {
|
||||
function _before() {
|
||||
@ -60,7 +60,8 @@ class CapabilitiesTest extends \MailPoetTest {
|
||||
$filter = function() {
|
||||
return array('nonexistent_role');
|
||||
};
|
||||
Hooks::addFilter('mailpoet_permission_access_plugin_admin', $filter);
|
||||
$wp = new WPFunctions;
|
||||
$wp->addFilter('mailpoet_permission_access_plugin_admin', $filter);
|
||||
$this->caps->setupWPCapabilities();
|
||||
|
||||
// role does not exist
|
||||
@ -72,7 +73,7 @@ class CapabilitiesTest extends \MailPoetTest {
|
||||
expect($editor_role->has_cap(AccessControl::PERMISSION_MANAGE_EMAILS))->true();
|
||||
|
||||
// Restore capabilities
|
||||
Hooks::removeFilter('mailpoet_permission_access_plugin_admin', $filter);
|
||||
$wp->removeFilter('mailpoet_permission_access_plugin_admin', $filter);
|
||||
$this->caps->setupWPCapabilities();
|
||||
|
||||
$editor_role = get_role('editor');
|
||||
@ -81,7 +82,10 @@ class CapabilitiesTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
function testItSetsUpMembersCapabilities() {
|
||||
WPHooksHelper::interceptAddAction();
|
||||
$wp = Stub::make(new WPFunctions, [
|
||||
'addAction' => asCallable([WPHooksHelper::class, 'addAction'])
|
||||
]);
|
||||
$this->caps = new Capabilities(new Renderer, $wp);
|
||||
|
||||
$this->caps->setupMembersCapabilities();
|
||||
|
||||
@ -113,7 +117,6 @@ class CapabilitiesTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
function _after() {
|
||||
WPHooksHelper::releaseAllHooks();
|
||||
Mock::clean();
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ use AspectMock\Test as Mock;
|
||||
use MailPoet\Cron\CronHelper;
|
||||
use MailPoet\Cron\DaemonHttpRunner;
|
||||
use MailPoet\Models\Setting;
|
||||
use MailPoet\WP\Hooks as WPHooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class CronHelperTest extends \MailPoetTest {
|
||||
@ -278,16 +277,16 @@ class CronHelperTest extends \MailPoetTest {
|
||||
return $request_args;
|
||||
};
|
||||
$wp_remote_get_args = [];
|
||||
$wp = Stub::make(new WPFunctions(), [
|
||||
$wp = Stub::make(new WPFunctions, [
|
||||
'wpRemotePost' => function() use (&$wp_remote_get_args) {
|
||||
return $wp_remote_get_args = func_get_args();
|
||||
}
|
||||
]);
|
||||
WPHooks::addFilter('mailpoet_cron_request_args', $filter);
|
||||
$wp->addFilter('mailpoet_cron_request_args', $filter);
|
||||
CronHelper::queryCronUrl('test', $wp);
|
||||
expect($wp_remote_get_args[1])->equals($request_args);
|
||||
|
||||
WPHooks::removeFilter('mailpoet_cron_request_args', $filter);
|
||||
$wp->removeFilter('mailpoet_cron_request_args', $filter);
|
||||
}
|
||||
|
||||
function testItReturnsErrorMessageAsPingResponseWhenCronUrlCannotBeAccessed() {
|
||||
|
@ -31,7 +31,7 @@ use MailPoet\Router\Endpoints\Track;
|
||||
use MailPoet\Router\Router;
|
||||
use MailPoet\Subscription\Url;
|
||||
use MailPoet\Tasks\Sending as SendingTask;
|
||||
use MailPoet\WP\Hooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class SendingQueueTest extends \MailPoetTest {
|
||||
/** @var SendingErrorHandler */
|
||||
@ -665,10 +665,11 @@ class SendingQueueTest extends \MailPoetTest {
|
||||
$filter = function() use ($custom_batch_size_value) {
|
||||
return $custom_batch_size_value;
|
||||
};
|
||||
Hooks::addFilter('mailpoet_cron_worker_sending_queue_batch_size', $filter);
|
||||
$wp = new WPFunctions;
|
||||
$wp->addFilter('mailpoet_cron_worker_sending_queue_batch_size', $filter);
|
||||
$sending_queue_worker = new SendingQueueWorker($this->sending_error_handler, $this->stats_notifications_worker);
|
||||
expect($sending_queue_worker->batch_size)->equals($custom_batch_size_value);
|
||||
Hooks::removeFilter('mailpoet_cron_worker_sending_queue_batch_size', $filter);
|
||||
$wp->removeFilter('mailpoet_cron_worker_sending_queue_batch_size', $filter);
|
||||
}
|
||||
|
||||
function _after() {
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace MailPoet\Test\Cron\Workers\SendingQueue\Tasks;
|
||||
|
||||
use Codeception\Stub;
|
||||
use AspectMock\Test as Mock;
|
||||
use Codeception\Util\Fixtures;
|
||||
use Helper\WordPressHooks as WPHooksHelper;
|
||||
@ -16,7 +17,7 @@ use MailPoet\Models\Setting;
|
||||
use MailPoet\Models\Subscriber;
|
||||
use MailPoet\Router\Router;
|
||||
use MailPoet\Tasks\Sending as SendingTask;
|
||||
use MailPoet\WP\Functions;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
@ -127,8 +128,10 @@ class NewsletterTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
function testItHashesLinksAndInsertsTrackingImageWhenTrackingIsEnabled() {
|
||||
WPHooksHelper::interceptApplyFilters();
|
||||
$newsletter_task = $this->newsletter_task;
|
||||
$wp = Stub::make(new WPFunctions, [
|
||||
'applyFilters' => asCallable([WPHooksHelper::class, 'applyFilters'])
|
||||
]);
|
||||
$newsletter_task = new NewsletterTask($wp);
|
||||
$newsletter_task->tracking_enabled = true;
|
||||
$newsletter_task->preProcessNewsletter($this->newsletter, $this->queue);
|
||||
$link = NewsletterLink::where('newsletter_id', $this->newsletter->id)
|
||||
@ -147,8 +150,10 @@ class NewsletterTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
function testItDoesNotHashLinksAndInsertTrackingCodeWhenTrackingIsDisabled() {
|
||||
WPHooksHelper::interceptApplyFilters();
|
||||
$newsletter_task = $this->newsletter_task;
|
||||
$wp = Stub::make(new WPFunctions, [
|
||||
'applyFilters' => asCallable([WPHooksHelper::class, 'applyFilters'])
|
||||
]);
|
||||
$newsletter_task = new NewsletterTask($wp);
|
||||
$newsletter_task->tracking_enabled = false;
|
||||
$newsletter_task->preProcessNewsletter($this->newsletter, $this->queue);
|
||||
$link = NewsletterLink::where('newsletter_id', $this->newsletter->id)
|
||||
@ -231,7 +236,7 @@ class NewsletterTest extends \MailPoetTest {
|
||||
$queue = $this->queue;
|
||||
$newsletter = $this->newsletter_task->preProcessNewsletter($newsletter, $queue);
|
||||
$queue = SendingTask::getByNewsletterId($newsletter->id);
|
||||
$wp = new Functions();
|
||||
$wp = new WPFunctions();
|
||||
expect($queue->newsletter_rendered_subject)
|
||||
->contains(date_i18n('dS', $wp->currentTime('timestamp')));
|
||||
}
|
||||
@ -375,7 +380,6 @@ class NewsletterTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
function _after() {
|
||||
WPHooksHelper::releaseAllHooks();
|
||||
\ORM::raw_execute('TRUNCATE ' . Setting::$_table);
|
||||
\ORM::raw_execute('TRUNCATE ' . Subscriber::$_table);
|
||||
\ORM::raw_execute('TRUNCATE ' . Newsletter::$_table);
|
||||
|
@ -5,7 +5,7 @@ namespace MailPoet\Test\Form;
|
||||
use MailPoet\Form\Widget;
|
||||
use MailPoet\Models\Form;
|
||||
use MailPoet\Util\pQuery\pQuery;
|
||||
use MailPoet\WP\Hooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class WidgetTest extends \MailPoetTest {
|
||||
function testItAllowsModifyingRenderedFormWidgetViaHook() {
|
||||
@ -34,7 +34,7 @@ class WidgetTest extends \MailPoetTest {
|
||||
expect($DOM->query('form')->attr('target'))->equals('_self');
|
||||
|
||||
// form target is modified to _top via hook
|
||||
Hooks::addFilter(
|
||||
(new WPFunctions)->addFilter(
|
||||
'mailpoet_form_widget_post_process',
|
||||
function($form) {
|
||||
$form = str_replace('target="_self"', 'target="_top"', $form);
|
||||
|
@ -5,7 +5,7 @@ use MailPoet\Helpscout\Beacon;
|
||||
use MailPoet\Models\Setting;
|
||||
use MailPoet\Models\Subscriber;
|
||||
use MailPoet\Services\Bridge;
|
||||
use MailPoet\WP\Hooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class BeaconTest extends \MailPoetTest {
|
||||
function _before() {
|
||||
@ -130,10 +130,11 @@ class BeaconTest extends \MailPoetTest {
|
||||
$filter = function($url) {
|
||||
return str_replace(home_url(), 'http://custom_url/', $url);
|
||||
};
|
||||
Hooks::addFilter('mailpoet_cron_request_url', $filter);
|
||||
$wp = new WPFunctions;
|
||||
$wp->addFilter('mailpoet_cron_request_url', $filter);
|
||||
$beacon_data = Beacon::getData();
|
||||
expect($beacon_data['Cron ping URL'])->regExp('!^http:\/\/custom_url\/!');
|
||||
Hooks::removeFilter('mailpoet_cron_request_url', $filter);
|
||||
$wp->removeFilter('mailpoet_cron_request_url', $filter);
|
||||
}
|
||||
|
||||
function testItReturnsPremiumVersion() {
|
||||
|
@ -5,7 +5,7 @@ use Helper\WordPressHooks as WPHooksHelper;
|
||||
use MailPoet\Mailer\Mailer;
|
||||
use MailPoet\Mailer\Methods\ErrorMappers\SMTPMapper;
|
||||
use MailPoet\Mailer\Methods\SMTP;
|
||||
use MailPoet\WP\Hooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class SMTPTest extends \MailPoetTest {
|
||||
function _before() {
|
||||
@ -134,7 +134,7 @@ class SMTPTest extends \MailPoetTest {
|
||||
function testItAppliesTransportFilter() {
|
||||
$mailer = $this->mailer->buildMailer();
|
||||
expect($mailer->getTransport()->getStreamOptions())->isEmpty();
|
||||
Hooks::addFilter(
|
||||
(new WPFunctions)->addFilter(
|
||||
'mailpoet_mailer_smtp_transport_agent',
|
||||
function($transport) {
|
||||
$transport->setStreamOptions(
|
||||
@ -162,7 +162,7 @@ class SMTPTest extends \MailPoetTest {
|
||||
function testItAppliesTimeoutFilter() {
|
||||
$mailer = $this->mailer->buildMailer();
|
||||
expect($mailer->getTransport()->getTimeout())->equals(\MailPoet\Mailer\Methods\SMTP::SMTP_CONNECTION_TIMEOUT);
|
||||
Hooks::addFilter(
|
||||
(new WPFunctions)->addFilter(
|
||||
'mailpoet_mailer_smtp_connection_timeout',
|
||||
function() {
|
||||
return 20;
|
||||
@ -182,6 +182,5 @@ class SMTPTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
function _after() {
|
||||
WPHooksHelper::releaseAllHooks();
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ namespace MailPoet\Test\Newsletter\Editor;
|
||||
|
||||
use Helper\WordPressHooks as WPHooksHelper;
|
||||
use MailPoet\Newsletter\Editor\PostContentManager;
|
||||
use MailPoet\WP\Hooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class PostContentManagerTest extends \MailPoetTest {
|
||||
|
||||
@ -138,7 +138,7 @@ class PostContentManagerTest extends \MailPoetTest {
|
||||
);
|
||||
$excerpt = $post_content_manager->getContent($post, 'excerpt');
|
||||
expect($excerpt)->equals('one two three four five six');
|
||||
Hooks::addFilter(
|
||||
(new WPFunctions)->addFilter(
|
||||
'mailpoet_newsletter_post_excerpt_length',
|
||||
function() {
|
||||
return 2;
|
||||
@ -170,6 +170,5 @@ class PostContentManagerTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
function _after() {
|
||||
WPHooksHelper::releaseAllHooks();
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@ use Codeception\Util\Stub;
|
||||
use MailPoet\Models\Segment;
|
||||
use MailPoet\Models\Subscriber;
|
||||
use MailPoet\Models\SubscriberSegment;
|
||||
use MailPoet\WP\Hooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
require_once('SubscribersBulkActionHandlerMock.php');
|
||||
|
||||
@ -90,7 +90,7 @@ class BulkActionTest extends \MailPoetTest {
|
||||
->will($this->returnValue('result'));
|
||||
|
||||
remove_all_filters('mailpoet_subscribers_in_segment_apply_bulk_action_handlers');
|
||||
Hooks::addFilter('mailpoet_subscribers_in_segment_apply_bulk_action_handlers', function () use ($mock) {
|
||||
(new WPFunctions)->addFilter('mailpoet_subscribers_in_segment_apply_bulk_action_handlers', function () use ($mock) {
|
||||
return array($mock);
|
||||
});
|
||||
|
||||
|
@ -11,7 +11,7 @@ use MailPoet\Models\Segment;
|
||||
use MailPoet\Models\Subscriber;
|
||||
use MailPoet\Models\SubscriberSegment;
|
||||
use MailPoet\Tasks\Sending as SendingTask;
|
||||
use MailPoet\WP\Hooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class SubscribersFinderTest extends \MailPoetTest {
|
||||
|
||||
@ -68,7 +68,7 @@ class SubscribersFinderTest extends \MailPoetTest {
|
||||
->will($this->returnValue(array($this->subscriber_3)));
|
||||
|
||||
remove_all_filters('mailpoet_get_subscribers_in_segment_finders');
|
||||
Hooks::addFilter('mailpoet_get_subscribers_in_segment_finders', function () use ($mock) {
|
||||
(new WPFunctions)->addFilter('mailpoet_get_subscribers_in_segment_finders', function () use ($mock) {
|
||||
return array($mock);
|
||||
});
|
||||
|
||||
@ -86,7 +86,7 @@ class SubscribersFinderTest extends \MailPoetTest {
|
||||
->will($this->returnValue(array($this->subscriber_3)));
|
||||
|
||||
remove_all_filters('mailpoet_get_subscribers_in_segment_finders');
|
||||
Hooks::addFilter('mailpoet_get_subscribers_in_segment_finders', function () use ($mock) {
|
||||
(new WPFunctions)->addFilter('mailpoet_get_subscribers_in_segment_finders', function () use ($mock) {
|
||||
return array($mock);
|
||||
});
|
||||
|
||||
@ -127,7 +127,7 @@ class SubscribersFinderTest extends \MailPoetTest {
|
||||
->will($this->returnValue(array(array('id' => $this->subscriber_1->id))));
|
||||
|
||||
remove_all_filters('mailpoet_get_subscribers_in_segment_finders');
|
||||
Hooks::addFilter('mailpoet_get_subscribers_in_segment_finders', function () use ($mock) {
|
||||
(new WPFunctions)->addFilter('mailpoet_get_subscribers_in_segment_finders', function () use ($mock) {
|
||||
return array($mock);
|
||||
});
|
||||
|
||||
@ -151,7 +151,7 @@ class SubscribersFinderTest extends \MailPoetTest {
|
||||
->method('getSubscriberIdsInSegment')
|
||||
->will($this->returnValue(array(array('id' => $this->subscriber_2->id))));
|
||||
remove_all_filters('mailpoet_get_subscribers_in_segment_finders');
|
||||
Hooks::addFilter('mailpoet_get_subscribers_in_segment_finders', function () use ($mock) {
|
||||
(new WPFunctions)->addFilter('mailpoet_get_subscribers_in_segment_finders', function () use ($mock) {
|
||||
return array($mock);
|
||||
});
|
||||
|
||||
|
@ -9,7 +9,7 @@ use MailPoet\DI\ContainerWrapper;
|
||||
use MailPoet\Models\Segment;
|
||||
use MailPoet\Models\Subscriber;
|
||||
use MailPoet\Models\SubscriberSegment;
|
||||
use MailPoet\WP\Hooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class SubscribersListingsTest extends \MailPoetTest {
|
||||
|
||||
@ -76,7 +76,7 @@ class SubscribersListingsTest extends \MailPoetTest {
|
||||
->will($this->returnValue('dynamic listings'));
|
||||
|
||||
remove_all_filters('mailpoet_get_subscribers_listings_in_segment_handlers');
|
||||
Hooks::addFilter('mailpoet_get_subscribers_listings_in_segment_handlers', function () use ($mock) {
|
||||
(new WPFunctions)->addFilter('mailpoet_get_subscribers_listings_in_segment_handlers', function () use ($mock) {
|
||||
return array($mock);
|
||||
});
|
||||
|
||||
|
@ -8,7 +8,6 @@ use MailPoet\Models\Setting;
|
||||
use MailPoet\Services\Bridge;
|
||||
use MailPoet\Services\Bridge\API;
|
||||
use MailPoet\Services\Bridge\BridgeTestMockAPI as MockAPI;
|
||||
use MailPoet\WP\Hooks as WPHooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
require_once('BridgeTestMockAPI.php');
|
||||
@ -273,10 +272,11 @@ class BridgeTest extends \MailPoetTest {
|
||||
$filter = function() use ($custom_request_value) {
|
||||
return $custom_request_value;
|
||||
};
|
||||
WPHooks::addFilter('mailpoet_bridge_api_request_timeout', $filter);
|
||||
$wp = new WPFunctions;
|
||||
$wp->addFilter('mailpoet_bridge_api_request_timeout', $filter);
|
||||
$api->sendMessages('test');
|
||||
expect($wp_remote_post_args[1]['timeout'])->equals($custom_request_value);
|
||||
WPHooks::removeFilter('mailpoet_bridge_api_request_timeout', $filter);
|
||||
$wp->removeFilter('mailpoet_bridge_api_request_timeout', $filter);
|
||||
}
|
||||
|
||||
private function setMailPoetSendingMethod() {
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace MailPoet\Test\Subscribers\ImportExport\Export;
|
||||
|
||||
use MailPoet\WP\Hooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
use MailPoet\Models\CustomField;
|
||||
use MailPoet\Models\Segment;
|
||||
use MailPoet\Models\Subscriber;
|
||||
@ -85,9 +85,9 @@ class DynamicSubscribersGetterTest extends \MailPoetTest {
|
||||
$entity->custom_field_id = 1;
|
||||
$entity->value = $this->subscribers_data[1][1];
|
||||
$entity->save();
|
||||
|
||||
Hooks::removeAllFilters('mailpoet_get_segment_filters');
|
||||
Hooks::addAction(
|
||||
$wp = new WPFunctions;
|
||||
$wp->removeAllFilters('mailpoet_get_segment_filters');
|
||||
$wp->addAction(
|
||||
'mailpoet_get_segment_filters',
|
||||
function($segment_id) {
|
||||
if($segment_id == 1) {
|
||||
|
@ -4,7 +4,7 @@ namespace MailPoet\Test\Subscription;
|
||||
use Carbon\Carbon;
|
||||
use MailPoet\Models\SubscriberIP;
|
||||
use MailPoet\Subscription\Throttling;
|
||||
use MailPoet\WP\Hooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class ThrottlingTest extends \MailPoetTest {
|
||||
function testItProgressivelyThrottlesSubscriptions() {
|
||||
@ -22,10 +22,11 @@ class ThrottlingTest extends \MailPoetTest {
|
||||
|
||||
function testItDoesNotThrottleIfDisabledByAHook() {
|
||||
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
||||
Hooks::addFilter('mailpoet_subscription_limit_enabled', '__return_false');
|
||||
$wp = new WPFunctions;
|
||||
$wp->addFilter('mailpoet_subscription_limit_enabled', '__return_false');
|
||||
expect(Throttling::throttle())->equals(false);
|
||||
expect(Throttling::throttle())->equals(false);
|
||||
Hooks::removeFilter('mailpoet_subscription_limit_enabled', '__return_false');
|
||||
$wp->removeFilter('mailpoet_subscription_limit_enabled', '__return_false');
|
||||
expect(Throttling::throttle())->greaterThan(0);
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@ namespace MailPoet\Test\Util;
|
||||
|
||||
use Helper\WordPressHooks as WPHooksHelper;
|
||||
use MailPoet\Util\ConflictResolver;
|
||||
use MailPoet\WP\Hooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class ConflictResolverTest extends \MailPoetTest {
|
||||
public $conflict_resolver;
|
||||
@ -47,7 +47,8 @@ class ConflictResolverTest extends \MailPoetTest {
|
||||
|
||||
function testItWhitelistsStyles() {
|
||||
wp_enqueue_style('select2', '/wp-content/some/offending/plugin/select2.css');
|
||||
Hooks::addFilter(
|
||||
$wp = new WPFunctions;
|
||||
$wp->addFilter(
|
||||
'mailpoet_conflict_resolver_whitelist_style',
|
||||
function($whitelisted_styles) {
|
||||
$whitelisted_styles[] = '^/wp-content/some/offending/plugin';
|
||||
@ -84,7 +85,8 @@ class ConflictResolverTest extends \MailPoetTest {
|
||||
|
||||
function testItWhitelistsScripts() {
|
||||
wp_enqueue_script('select2', '/wp-content/some/offending/plugin/select2.js');
|
||||
Hooks::addFilter(
|
||||
$wp = new WPFunctions;
|
||||
$wp->addFilter(
|
||||
'mailpoet_conflict_resolver_whitelist_script',
|
||||
function($whitelisted_scripts) {
|
||||
$whitelisted_scripts[] = '^/wp-content/some/offending/plugin';
|
||||
@ -100,6 +102,5 @@ class ConflictResolverTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
function _after() {
|
||||
WPHooksHelper::releaseAllHooks();
|
||||
}
|
||||
}
|
@ -9,6 +9,9 @@ class FunctionsTest extends \MailPoetTest {
|
||||
global $content_width;
|
||||
$this->_content_width = $content_width;
|
||||
$content_width = 150;
|
||||
$this->action = 'mailpoet_test_action';
|
||||
$this->filter = 'mailpoet_test_filter';
|
||||
$this->wp = new WPFunctions;
|
||||
}
|
||||
|
||||
function makeAttachment($upload, $parent_post_id = 0) {
|
||||
@ -50,13 +53,57 @@ class FunctionsTest extends \MailPoetTest {
|
||||
$id = $this->makeAttachment($upload);
|
||||
expect($id)->notEmpty();
|
||||
|
||||
$wp = new WPFunctions();
|
||||
$image = $wp->getImageInfo($id);
|
||||
$image = $this->wp->getImageInfo($id);
|
||||
expect($image[1])->equals(Env::NEWSLETTER_CONTENT_WIDTH);
|
||||
|
||||
wp_delete_attachment($id, $force_delete = true);
|
||||
}
|
||||
|
||||
|
||||
function testItCanProcessActions() {
|
||||
$test_value = array('abc', 'def');
|
||||
$test_value2 = new \stdClass;
|
||||
$called = false;
|
||||
|
||||
$callback = function ($value, $value2) use ($test_value, $test_value2, &$called) {
|
||||
$called = true;
|
||||
expect($value)->same($test_value);
|
||||
expect($value2)->same($test_value2);
|
||||
};
|
||||
|
||||
$this->wp->addAction($this->action, $callback, 10, 2);
|
||||
$this->wp->doAction($this->action, $test_value, $test_value2);
|
||||
|
||||
expect($called)->true();
|
||||
|
||||
$called = false;
|
||||
$this->wp->removeAction($this->action, $callback);
|
||||
$this->wp->doAction($this->action);
|
||||
expect($called)->false();
|
||||
}
|
||||
|
||||
function testItCanProcessFilters() {
|
||||
$test_value = array('abc', 'def');
|
||||
|
||||
$called = false;
|
||||
|
||||
$callback = function ($value) use ($test_value, &$called) {
|
||||
$called = true;
|
||||
return $test_value;
|
||||
};
|
||||
|
||||
$this->wp->addFilter($this->filter, $callback);
|
||||
$result = $this->wp->applyFilters($this->filter, $test_value);
|
||||
|
||||
expect($called)->true();
|
||||
expect($result)->equals($test_value);
|
||||
|
||||
$called = false;
|
||||
$this->wp->removeFilter($this->filter, $callback);
|
||||
$this->wp->applyFilters($this->filter, $test_value);
|
||||
expect($called)->false();
|
||||
}
|
||||
|
||||
function _after() {
|
||||
global $content_width;
|
||||
$content_width = $this->_content_width;
|
||||
|
@ -1,55 +0,0 @@
|
||||
<?php
|
||||
namespace MailPoet\Test\WP;
|
||||
|
||||
use MailPoet\WP\Hooks;
|
||||
|
||||
class HooksTest extends \MailPoetTest {
|
||||
function _before() {
|
||||
$this->action = 'mailpoet_test_action';
|
||||
$this->filter = 'mailpoet_test_filter';
|
||||
}
|
||||
|
||||
function testItCanProcessActions() {
|
||||
$test_value = array('abc', 'def');
|
||||
$test_value2 = new \stdClass;
|
||||
$called = false;
|
||||
|
||||
$callback = function ($value, $value2) use ($test_value, $test_value2, &$called) {
|
||||
$called = true;
|
||||
expect($value)->same($test_value);
|
||||
expect($value2)->same($test_value2);
|
||||
};
|
||||
|
||||
Hooks::addAction($this->action, $callback, 10, 2);
|
||||
Hooks::doAction($this->action, $test_value, $test_value2);
|
||||
|
||||
expect($called)->true();
|
||||
|
||||
$called = false;
|
||||
Hooks::removeAction($this->action, $callback);
|
||||
Hooks::doAction($this->action);
|
||||
expect($called)->false();
|
||||
}
|
||||
|
||||
function testItCanProcessFilters() {
|
||||
$test_value = array('abc', 'def');
|
||||
|
||||
$called = false;
|
||||
|
||||
$callback = function ($value) use ($test_value, &$called) {
|
||||
$called = true;
|
||||
return $test_value;
|
||||
};
|
||||
|
||||
Hooks::addFilter($this->filter, $callback);
|
||||
$result = Hooks::applyFilters($this->filter, $test_value);
|
||||
|
||||
expect($called)->true();
|
||||
expect($result)->equals($test_value);
|
||||
|
||||
$called = false;
|
||||
Hooks::removeFilter($this->filter, $callback);
|
||||
Hooks::applyFilters($this->filter, $test_value);
|
||||
expect($called)->false();
|
||||
}
|
||||
}
|
@ -145,4 +145,10 @@ abstract class MailPoetTest extends \Codeception\TestCase\Test {
|
||||
}
|
||||
}
|
||||
|
||||
function asCallable($fn) {
|
||||
return function() use(&$fn) {
|
||||
return call_user_func_array($fn, func_get_args());
|
||||
};
|
||||
}
|
||||
|
||||
include '_fixtures.php';
|
||||
|
Reference in New Issue
Block a user