Brak opisu

BlackFridayNotice.php 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace MailPoet\Util\Notices;
  3. if (!defined('ABSPATH')) exit;
  4. use MailPoet\Models\Subscriber;
  5. use MailPoet\WP\Functions as WPFunctions;
  6. use MailPoet\WP\Notice as WPNotice;
  7. class BlackFridayNotice {
  8. const OPTION_NAME = 'dismissed-black-friday-notice';
  9. const DISMISS_NOTICE_TIMEOUT_SECONDS = 2592000; // 30 days
  10. public function init($shouldDisplay) {
  11. $shouldDisplay = $shouldDisplay
  12. && (time() <= strtotime('2020-12-06 12:00:00'))
  13. && (time() >= strtotime('2020-11-23 12:00:00'))
  14. && !get_transient(self::OPTION_NAME);
  15. if ($shouldDisplay) {
  16. $this->display();
  17. }
  18. }
  19. private function display() {
  20. $subscribers = Subscriber
  21. ::whereNull('deleted_at')
  22. ->count();
  23. $header = '<h3 class="mailpoet-h3">' . __('MailPoet Black Friday: 33% discount on all our plans!', 'mailpoet') . '</h3>';
  24. $body = '<h5 class="mailpoet-h5">' . __('Signup to a yearly plan today and get 4 months for free.', 'mailpoet') . '</h5>';
  25. $link = "<p><a href='https://account.mailpoet.com/?s=$subscribers' class='mailpoet-button button-primary' target='_blank'>"
  26. . __('Buy Now', 'mailpoet')
  27. . '</a></p>';
  28. $extraClasses = 'mailpoet-dismissible-notice is-dismissible';
  29. WPNotice::displaySuccess($header . $body . $link, $extraClasses, self::OPTION_NAME, false);
  30. }
  31. public function disable() {
  32. WPFunctions::get()->setTransient(self::OPTION_NAME, true, self::DISMISS_NOTICE_TIMEOUT_SECONDS);
  33. }
  34. }