Нет описания

DeferredAdminNotices.php 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace MailPoet\Config;
  3. if (!defined('ABSPATH')) exit;
  4. use MailPoet\WP\Functions as WPFunctions;
  5. use MailPoet\WP\Notice;
  6. class DeferredAdminNotices {
  7. const OPTIONS_KEY_NAME = 'mailpoet_deferred_admin_notices';
  8. /**
  9. * @param string $message
  10. */
  11. public function addNetworkAdminNotice($message) {
  12. $notices = WPFunctions::get()->getOption(DeferredAdminNotices::OPTIONS_KEY_NAME, []);
  13. $notices[] = [
  14. "message" => $message,
  15. "networkAdmin" => true,// if we'll need to display the notice to anyone else
  16. ];
  17. WPFunctions::get()->updateOption(DeferredAdminNotices::OPTIONS_KEY_NAME, $notices);
  18. }
  19. public function printAndClean() {
  20. $notices = WPFunctions::get()->getOption(DeferredAdminNotices::OPTIONS_KEY_NAME, []);
  21. foreach ($notices as $notice) {
  22. $notice = new Notice(Notice::TYPE_WARNING, $notice["message"]);
  23. WPFunctions::get()->addAction('network_admin_notices', [$notice, 'displayWPNotice']);
  24. }
  25. if (!empty($notices)) {
  26. WPFunctions::get()->deleteOption(DeferredAdminNotices::OPTIONS_KEY_NAME);
  27. }
  28. }
  29. }