AfterMigrationNotice.php
2 years ago
BlackFridayNotice.php
2 months ago
ChangedTrackingNotice.php
3 years ago
DatabaseEngineNotice.php
1 year ago
DeprecatedFilterNotice.php
4 years ago
DisabledMailFunctionNotice.php
2 months ago
DisabledWPCronNotice.php
1 year ago
EmailWithInvalidSegmentNotice.php
3 years ago
HeadersAlreadySentNotice.php
2 months ago
InactiveSubscribersNotice.php
2 years ago
PHPVersionWarnings.php
2 months ago
PendingApprovalNotice.php
2 years ago
PermanentNotices.php
2 months ago
PremiumFeaturesAvailableNotice.php
2 years ago
SenderDomainAuthenticationNotices.php
5 months ago
SendingQueueBodyCleanupNotice.php
2 months ago
StuckPostNotificationNotice.php
2 months ago
UnauthorizedEmailInNewslettersNotice.php
5 months ago
UnauthorizedEmailNotice.php
5 months ago
WooCommerceVersionWarning.php
1 year ago
WordPressPlaygroundNotice.php
1 year ago
index.php
3 years ago
WooCommerceVersionWarning.php
77 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Util\Notices; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Config\Env; |
| 9 | use MailPoet\Util\Helpers; |
| 10 | use MailPoet\WP\Functions as WPFunctions; |
| 11 | use MailPoet\WP\Notice; |
| 12 | |
| 13 | class WooCommerceVersionWarning { |
| 14 | const OPTION_NAME = 'mailpoet-dismissed-woo-version-outdated-notice'; |
| 15 | const DISMISS_NOTICE_TIMEOUT_SECONDS = 2592000; // 30 days |
| 16 | |
| 17 | /** @var WPFunctions */ |
| 18 | private $wp; |
| 19 | |
| 20 | public function __construct( |
| 21 | WPFunctions $wp |
| 22 | ) { |
| 23 | $this->wp = $wp; |
| 24 | } |
| 25 | |
| 26 | public function init($shouldDisplay) { |
| 27 | if (!is_plugin_active('woocommerce/woocommerce.php')) { |
| 28 | return; |
| 29 | } |
| 30 | $woocommerceVersion = $this->getWoocommerceVersion(); |
| 31 | $requiredWooCommerceVersion = $this->getRequiredWooCommerceVersion(); |
| 32 | if ($shouldDisplay && $this->isOutdatedWooCommerceVersion($woocommerceVersion, $requiredWooCommerceVersion)) { |
| 33 | $this->display($requiredWooCommerceVersion); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | public function isOutdatedWooCommerceVersion($woocommerceVersion, $requiredWooCommerceVersion): bool { |
| 38 | return version_compare($woocommerceVersion, $requiredWooCommerceVersion, '<') && !$this->wp->getTransient($this->getTransientKey()); |
| 39 | } |
| 40 | |
| 41 | private function display($requiredWooCommerceVersion) { |
| 42 | // translators: %s is the PHP version |
| 43 | $errorString = __('MailPoet plugin requires WooCommerce version %s or newer. Please update your WooCommerce plugin version, or read our [link]instructions[/link] for additional options on how to resolve this issue.', 'mailpoet'); |
| 44 | $errorString = sprintf($errorString, $requiredWooCommerceVersion); |
| 45 | $error = Helpers::replaceLinkTags($errorString, 'https://kb.mailpoet.com/article/152-minimum-requirements-for-mailpoet-3#woocommerce-version', [ |
| 46 | 'target' => '_blank', |
| 47 | ]); |
| 48 | |
| 49 | $extraClasses = 'mailpoet-dismissible-notice is-dismissible'; |
| 50 | |
| 51 | Notice::displayWarning($error, $extraClasses, self::OPTION_NAME); |
| 52 | } |
| 53 | |
| 54 | public function disable() { |
| 55 | $this->wp->setTransient($this->getTransientKey(), true, self::DISMISS_NOTICE_TIMEOUT_SECONDS); |
| 56 | } |
| 57 | |
| 58 | private function getTransientKey() { |
| 59 | $woocommerceVersion = $this->getWoocommerceVersion(); |
| 60 | return self::OPTION_NAME . '_' . $this->getRequiredWooCommerceVersion() . '_' . $woocommerceVersion; |
| 61 | } |
| 62 | |
| 63 | private function getWoocommerceVersion(): string { |
| 64 | return $this->wp->getPluginData(WP_PLUGIN_DIR . '/woocommerce/woocommerce.php', false, false)['Version']; |
| 65 | } |
| 66 | |
| 67 | private function getRequiredWooCommerceVersion(): string { |
| 68 | $pluginData = $this->wp->getFileData( |
| 69 | Env::$file, |
| 70 | [ |
| 71 | 'RequiredWCVersion' => 'WC requires at least', |
| 72 | ] |
| 73 | ); |
| 74 | return $pluginData['RequiredWCVersion'] ?? '100.0.0'; |
| 75 | } |
| 76 | } |
| 77 |