This commit fixes a problem in the logic used to decide whether or not the HelpScout chat should be available on the MailPoet admin pages. Before, we were displaying the chat for plans that include premium support and access to MSS. But we also have plans, like the Blogger plan, that include premium support, and should see the chat, but don't include access to MSS. Those plans were not seeing the chat. This was happening because the code was checking just for `mailpoet_api_key_state.data.support_tier == 'premium'`. The mailpoet_api_key_state setting is added to the database based on the response from the bridge.mailpoet.com/me endpoint. This endpoint returns a 403 error for plans that don't include the sending service. In this commit, to fix this problem, the code now checks for both `mailpoet_api_key_state.data.support_tier == 'premium'` and `premium_key_state.data.support_tier == 'premium'`. The former setting is added to the database based on the response of the bridge.mailpoet.com/premium endpoint. This endpoint works for plans that have access to MailPoet Premium, but don't have access to MSS. We need to check for both settings as we also have some plans that include the sending service, but don't include MailPoet Premium. [MAILPOET-3438]
77 lines
2.5 KiB
PHP
77 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace MailPoet\AdminPages;
|
|
|
|
use MailPoet\Config\Renderer;
|
|
use MailPoet\Entities\SegmentEntity;
|
|
use MailPoet\Features\FeaturesController;
|
|
use MailPoet\Referrals\ReferralDetector;
|
|
use MailPoet\Segments\SegmentsRepository;
|
|
use MailPoet\Settings\SettingsController;
|
|
use MailPoet\Settings\UserFlagsController;
|
|
use MailPoet\Tracy\DIPanel\DIPanel;
|
|
use MailPoet\WP\Notice as WPNotice;
|
|
use Tracy\Debugger;
|
|
|
|
class PageRenderer {
|
|
/** @var Renderer */
|
|
private $renderer;
|
|
|
|
/** @var FeaturesController */
|
|
private $featuresController;
|
|
|
|
/** @var SettingsController */
|
|
private $settings;
|
|
|
|
/** @var UserFlagsController */
|
|
private $userFlags;
|
|
|
|
/** @var SegmentsRepository */
|
|
private $segmentRepository;
|
|
|
|
public function __construct(
|
|
Renderer $renderer,
|
|
FeaturesController $featuresController,
|
|
SettingsController $settings,
|
|
UserFlagsController $userFlags,
|
|
SegmentsRepository $segmentRepository
|
|
) {
|
|
$this->renderer = $renderer;
|
|
$this->featuresController = $featuresController;
|
|
$this->settings = $settings;
|
|
$this->userFlags = $userFlags;
|
|
$this->segmentRepository = $segmentRepository;
|
|
}
|
|
|
|
/**
|
|
* Set common data for template and display template
|
|
* @param string $template
|
|
* @param array $data
|
|
*/
|
|
public function displayPage($template, array $data = []) {
|
|
$lastAnnouncementDate = $this->settings->get('last_announcement_date');
|
|
$lastAnnouncementSeen = $this->userFlags->get('last_announcement_seen');
|
|
$wpSegment = $this->segmentRepository->getWPUsersSegment();
|
|
$wpSegmentState = ($wpSegment instanceof SegmentEntity) && $wpSegment->getDeletedAt() === null ?
|
|
SegmentEntity::SEGMENT_ENABLED : SegmentEntity::SEGMENT_DISABLED;
|
|
$defaults = [
|
|
'feature_flags' => $this->featuresController->getAllFlags(),
|
|
'referral_id' => $this->settings->get(ReferralDetector::REFERRAL_SETTING_NAME),
|
|
'mailpoet_api_key_state' => $this->settings->get('mta.mailpoet_api_key_state'),
|
|
'premium_key_state' => $this->settings->get('premium.premium_key_state'),
|
|
'last_announcement_seen' => $lastAnnouncementSeen,
|
|
'feature_announcement_has_news' => (empty($lastAnnouncementSeen) || $lastAnnouncementSeen < $lastAnnouncementDate),
|
|
'wp_segment_state' => $wpSegmentState,
|
|
];
|
|
try {
|
|
if (class_exists(Debugger::class)) {
|
|
DIPanel::init();
|
|
}
|
|
echo $this->renderer->render($template, $data + $defaults);
|
|
} catch (\Exception $e) {
|
|
$notice = new WPNotice(WPNotice::TYPE_ERROR, $e->getMessage());
|
|
$notice->displayWPNotice();
|
|
}
|
|
}
|
|
}
|