Add filter to remove restriction on Woo Express

[MAILPOET-5573]
This commit is contained in:
Brezo Cordero
2023-09-21 20:42:53 -05:00
committed by Aschepikov
parent 748995d9d5
commit c12438db08
3 changed files with 49 additions and 3 deletions

View File

@@ -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(),

View File

@@ -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 = '';
}

View File

@@ -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();
}
}