diff --git a/mailpoet/lib/AdminPages/PageRenderer.php b/mailpoet/lib/AdminPages/PageRenderer.php index 1bbefac6f5..452f9463dc 100644 --- a/mailpoet/lib/AdminPages/PageRenderer.php +++ b/mailpoet/lib/AdminPages/PageRenderer.php @@ -136,7 +136,10 @@ class PageRenderer { if ($this->subscribersFeature->isSubscribersCountEnoughForCache($subscriberCount)) { $subscribersCacheCreatedAt = $this->transientCache->getOldestCreatedAt(TransientCache::SUBSCRIBERS_STATISTICS_COUNT_KEY) ?: Carbon::now(); } - + // Automations are hidden when the subscription is part of a bundle and AutomateWoo is active + $showAutomations = !($this->wp->isPluginActive('automatewoo/automatewoo.php') && + $this->servicesChecker->isBundledSubscription()); + $hideAutomations = !$this->wp->applyFilters('mailpoet_show_automations', $showAutomations); $defaults = [ 'current_page' => sanitize_text_field(wp_unslash($_GET['page'] ?? '')), 'site_name' => $this->wp->wpSpecialcharsDecode($this->wp->getOption('blogname'), ENT_QUOTES), @@ -177,7 +180,7 @@ class PageRenderer { 'mss_key_pending_approval' => $this->servicesChecker->isMailPoetAPIKeyPendingApproval(), 'mss_active' => $this->bridge->isMailpoetSendingServiceEnabled(), 'plugin_partial_key' => $this->servicesChecker->generatePartialApiKey(), - 'mailpoet_hide_automations' => $this->servicesChecker->isBundledSubscription() && $this->wp->isPluginActive('automatewoo/automatewoo.php'), + 'mailpoet_hide_automations' => $hideAutomations, 'subscriber_count' => $subscriberCount, 'subscribers_counts_cache_created_at' => $subscribersCacheCreatedAt->format('Y-m-d\TH:i:sO'), 'subscribers_limit' => $this->subscribersFeature->getSubscribersLimit(), diff --git a/mailpoet/lib/Config/Menu.php b/mailpoet/lib/Config/Menu.php index b0b9d435ea..8a94267029 100644 --- a/mailpoet/lib/Config/Menu.php +++ b/mailpoet/lib/Config/Menu.php @@ -507,7 +507,11 @@ class Menu { private function registerAutomationMenu() { $parentSlug = self::MAIN_PAGE_SLUG; // Automations menu is hidden when the subscription is part of a bundle and AutomateWoo is active but pages can be accessed directly - if ($this->wp->isPluginActive('automatewoo/automatewoo.php') && $this->servicesChecker->isBundledSubscription()) { + $showAutomations = !($this->wp->isPluginActive('automatewoo/automatewoo.php') && + $this->servicesChecker->isBundledSubscription()); + if ( + !$this->wp->applyFilters('mailpoet_show_automations', $showAutomations) + ) { $parentSlug = ''; } diff --git a/mailpoet/tests/integration/Config/MenuTest.php b/mailpoet/tests/integration/Config/MenuTest.php index dd543f9363..bf9873e1d4 100644 --- a/mailpoet/tests/integration/Config/MenuTest.php +++ b/mailpoet/tests/integration/Config/MenuTest.php @@ -98,4 +98,43 @@ class MenuTest extends \MailPoetTest { $menu->setup(); } + + public function testItShowsAutomationIfFilterIsTrue() { + $checker = Stub::make( + new ServicesChecker(), + [ + 'isPremiumKeyValid' => true, + 'isBundledSubscription' => true, + ], + $this + ); + + $wpMock = $this->createMock(WPFunctions::class); + $wpMock->method('isPluginActive')->willReturn(true); + $wpMock->method('applyFilters')->willReturn(true); + + $accessControlMock = $this->createMock(AccessControl::class); + $accessControlMock->method('validatePermission')->willReturn(true); + + $wpMock->expects($this->any())->method('addSubmenuPage')->withConsecutive( + [$this->anything(), $this->anything(), $this->anything(), $this->anything(), $this->anything(), $this->anything()], + [$this->anything(), $this->anything(), $this->anything(), $this->anything(), $this->anything(), $this->anything()], + [$this->anything(), $this->anything(), $this->anything(), $this->anything(), $this->anything(), $this->anything()], + [$this->anything(), $this->anything(), $this->anything(), $this->anything(), $this->anything(), $this->anything()], + [$this->anything(), $this->anything(), $this->anything(), $this->anything(), $this->anything(), $this->anything()], + [Menu::MAIN_PAGE_SLUG, $this->anything(), $this->anything(), $this->anything(), Menu::AUTOMATIONS_PAGE_SLUG, $this->anything()] + )->willReturn(true); + + $menu = new Menu( + $accessControlMock, + $wpMock, + $checker, + $this->diContainer, + $this->diContainer->get(Router::class), + $this->diContainer->get(CustomFonts::class) + ); + + $menu->setup(); + + } }