Move dynamic segment hooks from Premium plugin
[MAILPOET-2382]
This commit is contained in:
committed by
Jack Kitterhing
parent
e5e85344da
commit
771f4b9d63
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace MailPoet\Config;
|
namespace MailPoet\Config;
|
||||||
|
|
||||||
|
use MailPoet\DynamicSegments\DynamicSegmentHooks;
|
||||||
use MailPoet\Mailer\WordPress\Replacer;
|
use MailPoet\Mailer\WordPress\Replacer;
|
||||||
use MailPoet\Mailer\WordPress\WordpressMailerReplacer;
|
use MailPoet\Mailer\WordPress\WordpressMailerReplacer;
|
||||||
use MailPoet\Newsletter\Scheduler\PostNotificationScheduler;
|
use MailPoet\Newsletter\Scheduler\PostNotificationScheduler;
|
||||||
@@ -54,6 +55,9 @@ class Hooks {
|
|||||||
/** @var WordpressMailerReplacer */
|
/** @var WordpressMailerReplacer */
|
||||||
private $wordpress_mailer_replacer;
|
private $wordpress_mailer_replacer;
|
||||||
|
|
||||||
|
/** @var DynamicSegmentHooks */
|
||||||
|
private $dynamic_segment_hooks;
|
||||||
|
|
||||||
function __construct(
|
function __construct(
|
||||||
Form $subscription_form,
|
Form $subscription_form,
|
||||||
Comment $subscription_comment,
|
Comment $subscription_comment,
|
||||||
@@ -66,7 +70,8 @@ class Hooks {
|
|||||||
WooCommerceSettings $woocommerce_settings,
|
WooCommerceSettings $woocommerce_settings,
|
||||||
WooCommercePurchases $woocommerce_purchases,
|
WooCommercePurchases $woocommerce_purchases,
|
||||||
PostNotificationScheduler $post_notification_scheduler,
|
PostNotificationScheduler $post_notification_scheduler,
|
||||||
WordpressMailerReplacer $wordpress_mailer_replacer
|
WordpressMailerReplacer $wordpress_mailer_replacer,
|
||||||
|
DynamicSegmentHooks $dynamic_segment_hooks
|
||||||
) {
|
) {
|
||||||
$this->subscription_form = $subscription_form;
|
$this->subscription_form = $subscription_form;
|
||||||
$this->subscription_comment = $subscription_comment;
|
$this->subscription_comment = $subscription_comment;
|
||||||
@@ -80,6 +85,7 @@ class Hooks {
|
|||||||
$this->woocommerce_purchases = $woocommerce_purchases;
|
$this->woocommerce_purchases = $woocommerce_purchases;
|
||||||
$this->post_notification_scheduler = $post_notification_scheduler;
|
$this->post_notification_scheduler = $post_notification_scheduler;
|
||||||
$this->wordpress_mailer_replacer = $wordpress_mailer_replacer;
|
$this->wordpress_mailer_replacer = $wordpress_mailer_replacer;
|
||||||
|
$this->dynamic_segment_hooks = $dynamic_segment_hooks;
|
||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
@@ -92,6 +98,7 @@ class Hooks {
|
|||||||
$this->setupWooCommerceSubscriptionEvents();
|
$this->setupWooCommerceSubscriptionEvents();
|
||||||
$this->setupPostNotifications();
|
$this->setupPostNotifications();
|
||||||
$this->setupWooCommerceSettings();
|
$this->setupWooCommerceSettings();
|
||||||
|
$this->dynamic_segment_hooks->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
function initEarlyHooks() {
|
function initEarlyHooks() {
|
||||||
|
@@ -115,6 +115,8 @@ class ContainerConfigurator implements IContainerConfigurator {
|
|||||||
->setFactory([new Reference(\MailPoet\Doctrine\EntityManagerFactory::class), 'createEntityManager'])
|
->setFactory([new Reference(\MailPoet\Doctrine\EntityManagerFactory::class), 'createEntityManager'])
|
||||||
->setPublic(true);
|
->setPublic(true);
|
||||||
$container->autowire(\MailPoet\Doctrine\EventListeners\TimestampListener::class);
|
$container->autowire(\MailPoet\Doctrine\EventListeners\TimestampListener::class);
|
||||||
|
// Dynamic segments
|
||||||
|
$container->autowire(\MailPoet\DynamicSegments\DynamicSegmentHooks::class);
|
||||||
// Cron
|
// Cron
|
||||||
$container->autowire(\MailPoet\Cron\Daemon::class)->setPublic(true);
|
$container->autowire(\MailPoet\Cron\Daemon::class)->setPublic(true);
|
||||||
$container->autowire(\MailPoet\Cron\DaemonHttpRunner::class)->setPublic(true);
|
$container->autowire(\MailPoet\Cron\DaemonHttpRunner::class)->setPublic(true);
|
||||||
|
86
lib/DynamicSegments/DynamicSegmentHooks.php
Normal file
86
lib/DynamicSegments/DynamicSegmentHooks.php
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace MailPoet\DynamicSegments;
|
||||||
|
|
||||||
|
use MailPoet\DynamicSegments\FreePluginConnectors\AddToNewslettersSegments;
|
||||||
|
use MailPoet\DynamicSegments\FreePluginConnectors\AddToSubscribersFilters;
|
||||||
|
use MailPoet\DynamicSegments\FreePluginConnectors\SendingNewslettersSubscribersFinder;
|
||||||
|
use MailPoet\DynamicSegments\FreePluginConnectors\SubscribersBulkActionHandler;
|
||||||
|
use MailPoet\DynamicSegments\FreePluginConnectors\SubscribersListingsHandlerFactory;
|
||||||
|
use MailPoet\DynamicSegments\Mappers\DBMapper;
|
||||||
|
use MailPoet\DynamicSegments\Persistence\Loading\Loader;
|
||||||
|
use MailPoet\DynamicSegments\Persistence\Loading\SingleSegmentLoader;
|
||||||
|
use MailPoet\DynamicSegments\Persistence\Loading\SubscribersCount;
|
||||||
|
use MailPoet\DynamicSegments\Persistence\Loading\SubscribersIds;
|
||||||
|
use MailPoet\WP\Functions as WPFunctions;
|
||||||
|
|
||||||
|
class DynamicSegmentHooks {
|
||||||
|
/** @var WPFunctions */
|
||||||
|
private $wp;
|
||||||
|
|
||||||
|
function __construct(WPFunctions $wp) {
|
||||||
|
$this->wp = $wp;
|
||||||
|
}
|
||||||
|
|
||||||
|
function init() {
|
||||||
|
$this->wp->addAction(
|
||||||
|
'mailpoet_segments_with_subscriber_count',
|
||||||
|
[$this, 'addSegmentsWithSubscribersCount']
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->wp->addAction(
|
||||||
|
'mailpoet_get_subscribers_in_segment_finders',
|
||||||
|
[$this, 'getSubscribersInSegmentsFinders']
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->wp->addAction(
|
||||||
|
'mailpoet_get_subscribers_listings_in_segment_handlers',
|
||||||
|
[$this, 'getSubscribersListingsInSegmentsHandlers']
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->wp->addAction(
|
||||||
|
'mailpoet_subscribers_listings_filters_segments',
|
||||||
|
[$this, 'addDynamicFiltersToSubscribersListingsFilters']
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->wp->addAction(
|
||||||
|
'mailpoet_subscribers_in_segment_apply_bulk_action_handlers',
|
||||||
|
[$this, 'applySubscriberBulkAction']
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->wp->addAction(
|
||||||
|
'mailpoet_get_segment_filters',
|
||||||
|
[$this, 'getSegmentFilters']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function addSegmentsWithSubscribersCount($initial_segments) {
|
||||||
|
$newsletters_add_segments = new AddToNewslettersSegments(new Loader(new DBMapper()), new SubscribersCount());
|
||||||
|
return $newsletters_add_segments->add($initial_segments);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSubscribersInSegmentsFinders(array $finders) {
|
||||||
|
$finders[] = new SendingNewslettersSubscribersFinder(new SingleSegmentLoader(new DBMapper()), new SubscribersIds());
|
||||||
|
return $finders;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSubscribersListingsInSegmentsHandlers(array $handlers) {
|
||||||
|
$handlers[] = new SubscribersListingsHandlerFactory();
|
||||||
|
return $handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
function addDynamicFiltersToSubscribersListingsFilters($segment_filters) {
|
||||||
|
$newsletters_add_segments = new AddToSubscribersFilters(new Loader(new DBMapper()), new SubscribersCount());
|
||||||
|
return $newsletters_add_segments->add($segment_filters);
|
||||||
|
}
|
||||||
|
|
||||||
|
function applySubscriberBulkAction(array $handlers) {
|
||||||
|
$handlers[] = new SubscribersBulkActionHandler();
|
||||||
|
return $handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSegmentFilters($segment_id) {
|
||||||
|
$single_segment_loader = new SingleSegmentLoader(new DBMapper());
|
||||||
|
return $single_segment_loader->load($segment_id)->getFilters();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user