Blocks
10 months ago
Coupons
1 month ago
Endpoints
2 months ago
Patterns
1 month ago
PersonalizationTags
4 days ago
ProductCollection
1 month ago
Templates
2 months ago
AutomationEmailContextProvider.php
2 months ago
AutomationEmailPreviewOrderProvider.php
2 months ago
BlockEmailContentDetector.php
2 months ago
Cli.php
2 weeks ago
DependencyNotice.php
11 months ago
EditorPageRenderer.php
1 week ago
EmailApiController.php
1 week ago
EmailEditor.php
2 months ago
EmailEditorPreviewEmail.php
9 months ago
Logger.php
10 months ago
MailPoetCssInliner.php
8 months ago
MailpoetCssInlinerFactory.php
1 year ago
PersonalizationTagManager.php
5 days ago
index.php
2 years ago
DependencyNotice.php
57 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\EmailEditor\Integrations\MailPoet; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use Automattic\WooCommerce\EmailEditor\Email_Editor_Container; |
| 9 | use Automattic\WooCommerce\EmailEditor\Engine\Dependency_Check; |
| 10 | use MailPoet\Config\AccessControl; |
| 11 | use MailPoet\WP\Functions as WPFunctions; |
| 12 | |
| 13 | class DependencyNotice { |
| 14 | private const EMAIL_EDITOR_DEPENDENCY_NOTICE = 'email_editor_dependencies_not_met'; |
| 15 | private WPFunctions $wp; |
| 16 | private Dependency_Check $dependencyCheck; |
| 17 | |
| 18 | public function __construct( |
| 19 | WPFunctions $wp |
| 20 | ) { |
| 21 | $this->wp = $wp; |
| 22 | $this->dependencyCheck = Email_Editor_Container::container()->get(Dependency_Check::class); |
| 23 | } |
| 24 | |
| 25 | public function checkDependenciesAndEventuallyShowNotice(): bool { |
| 26 | if ($this->dependencyCheck->are_dependencies_met()) { |
| 27 | $this->wp->deleteTransient(self::EMAIL_EDITOR_DEPENDENCY_NOTICE); |
| 28 | return false; |
| 29 | } |
| 30 | // For admins, we redirect to newsletters page and show notice there, for other users we display a notice immediately |
| 31 | if ($this->wp->currentUserCan(AccessControl::PERMISSION_MANAGE_EMAILS)) { |
| 32 | $this->wp->setTransient(self::EMAIL_EDITOR_DEPENDENCY_NOTICE, true); |
| 33 | $this->wp->wpSafeRedirect($this->wp->adminUrl('admin.php?page=mailpoet-newsletters')); |
| 34 | return true; |
| 35 | } else { |
| 36 | $this->displayMessage(); |
| 37 | return true; |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | public function displayMessageIfNeeded(): void { |
| 42 | if ($this->wp->getTransient(self::EMAIL_EDITOR_DEPENDENCY_NOTICE)) { |
| 43 | $this->displayMessage(); |
| 44 | } |
| 45 | $this->wp->deleteTransient(self::EMAIL_EDITOR_DEPENDENCY_NOTICE); |
| 46 | } |
| 47 | |
| 48 | private function displayMessage(): void { |
| 49 | $dependencyErrorMessage = sprintf( |
| 50 | // translators: %1$s: WordPress version e.g. 6.7 |
| 51 | __('This email was created using the new editor, which requires WordPress version %1$s or higher. Please update your setup to continue editing or previewing this email.', 'mailpoet'), |
| 52 | Dependency_Check::MIN_WP_VERSION, |
| 53 | ); |
| 54 | echo '<div class="notice notice-warning is-dismissible"><p>' . esc_html($dependencyErrorMessage) . '</p></div>'; |
| 55 | } |
| 56 | } |
| 57 |