PopulatorData
2 months ago
AccessControl.php
2 years ago
Activator.php
2 months ago
AssetsLoader.php
2 weeks ago
Capabilities.php
2 months ago
Changelog.php
2 months ago
DeactivationPoll.php
3 years ago
DeferredAdminNotices.php
2 months ago
Env.php
6 months ago
Hooks.php
1 month ago
HooksWooCommerce.php
1 month ago
Initializer.php
1 month ago
Installer.php
10 months ago
Localizer.php
3 years ago
Menu.php
1 month ago
PersonalDataErasers.php
1 month ago
PersonalDataExporters.php
1 month ago
PluginActivatedHook.php
3 years ago
Populator.php
2 weeks ago
PrivacyPolicy.php
1 month ago
Renderer.php
1 year ago
RendererFactory.php
3 years ago
RequirementsChecker.php
2 months ago
Router.php
2 months ago
ServicesChecker.php
3 years ago
Shortcodes.php
1 month ago
SilentUpgraderSkin.php
3 years ago
SubscriberChangesNotifier.php
2 months ago
TranslationUpdater.php
3 months ago
TwigEnvironment.php
1 year ago
TwigFileSystemCache.php
3 years ago
Updater.php
4 days ago
index.php
3 years ago
DeferredAdminNotices.php
52 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\Config; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\WP\Functions as WPFunctions; |
| 9 | use MailPoet\WP\Notice; |
| 10 | |
| 11 | class DeferredAdminNotices { |
| 12 | |
| 13 | const OPTIONS_KEY_NAME = 'mailpoet_deferred_admin_notices'; |
| 14 | |
| 15 | /** |
| 16 | * @param string $message |
| 17 | */ |
| 18 | public function addNetworkAdminNotice($message) { |
| 19 | $notices = WPFunctions::get()->getOption(DeferredAdminNotices::OPTIONS_KEY_NAME, []); |
| 20 | $notices = is_array($notices) ? $notices : []; |
| 21 | $notices[] = [ |
| 22 | "message" => $message, |
| 23 | "networkAdmin" => true,// if we'll need to display the notice to anyone else |
| 24 | ]; |
| 25 | WPFunctions::get()->updateOption(DeferredAdminNotices::OPTIONS_KEY_NAME, $notices); |
| 26 | } |
| 27 | |
| 28 | public function printAndClean() { |
| 29 | $notices = WPFunctions::get()->getOption(DeferredAdminNotices::OPTIONS_KEY_NAME, []); |
| 30 | |
| 31 | if (!is_array($notices)) { |
| 32 | if (!empty($notices)) { |
| 33 | WPFunctions::get()->deleteOption(DeferredAdminNotices::OPTIONS_KEY_NAME); |
| 34 | } |
| 35 | return; |
| 36 | } |
| 37 | |
| 38 | foreach ($notices as $notice) { |
| 39 | if (!is_array($notice) || empty($notice["message"])) { |
| 40 | continue; |
| 41 | } |
| 42 | |
| 43 | $notice = new Notice(Notice::TYPE_WARNING, $notice["message"]); |
| 44 | WPFunctions::get()->addAction('network_admin_notices', [$notice, 'displayWPNotice']); |
| 45 | } |
| 46 | |
| 47 | if (!empty($notices)) { |
| 48 | WPFunctions::get()->deleteOption(DeferredAdminNotices::OPTIONS_KEY_NAME); |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 |