暫無描述

PHPVersionWarnings.php 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace MailPoet\Util\Notices;
  3. if (!defined('ABSPATH')) exit;
  4. use MailPoet\Util\Helpers;
  5. use MailPoet\WP\Functions as WPFunctions;
  6. use MailPoet\WP\Notice;
  7. class PHPVersionWarnings {
  8. const DISMISS_NOTICE_TIMEOUT_SECONDS = 2592000; // 30 days
  9. const OPTION_NAME = 'dismissed-php-version-outdated-notice';
  10. public function init($phpVersion, $shouldDisplay) {
  11. if ($shouldDisplay && $this->isOutdatedPHPVersion($phpVersion)) {
  12. return $this->display($phpVersion);
  13. }
  14. }
  15. public function isOutdatedPHPVersion($phpVersion) {
  16. return version_compare($phpVersion, '7.2', '<') && !get_transient(self::OPTION_NAME);
  17. }
  18. public function display($phpVersion) {
  19. $errorString = __('Your website is running on PHP %s which MailPoet does not officially support. Read our [link]simple PHP upgrade guide.[/link]', 'mailpoet');
  20. $errorString = sprintf($errorString, $phpVersion);
  21. $error = Helpers::replaceLinkTags($errorString, 'https://kb.mailpoet.com/article/251-upgrading-the-websites-php-version', [
  22. 'target' => '_blank',
  23. 'data-beacon-article' => '5ad5f8982c7d3a0e93676666',
  24. ]);
  25. $extraClasses = 'mailpoet-dismissible-notice is-dismissible';
  26. return Notice::displayWarning($error, $extraClasses, self::OPTION_NAME);
  27. }
  28. public function disable() {
  29. WPFunctions::get()->setTransient(self::OPTION_NAME, true, self::DISMISS_NOTICE_TIMEOUT_SECONDS);
  30. }
  31. }