1. Go to this page and download the library: Download typisttech/wp-admin-notices library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
typisttech / wp-admin-notices example snippets
use TypistTech\WPAdminNotices\Factory;
use TypistTech\WPAdminNotices\Notice;
use TypistTech\WPAdminNotices\StickyNotice;
$store = Factory::build('my_unique_demo_option', 'my_unique_demo_action');
add_action('admin_init', function () use ($store) {
$notice = new Notice('example-notice-1', 'my notice message');
$store->add($notice);
}
);
add_action('post_updated', function ($post_id) use ($store) {
$notices[] = new Notice(
'example-notice-2',
"<p><strong>WPAdminNotices</strong>: Post ID: $post_id has been updated.</p>",
Notice::SUCCESS
);
$notices[] = new StickyNotice(
'example-notice-3',
'<p><strong>WPAdminNotices</strong>: StickyNotice persists in database until user clicks to dismiss it.</p>'
);
$store->add(...$notices);
}
);
$notice = new Notice('example-notice', '<strong>Hello</strong> World!', Notice::SUCCESS);
$stickyNotice = new StickyNotice('example-sticky-notice', 'I wont go away until users click on me.', StickyNotice::WARNING);
$store = new Store('my_unique_option_key');
$store->add($notice1, $notice2);
// To update a notice, re-add with the same handle.
$oldNotice = new Notice('i-am-unique', "Chaos isn't a pit.");
$store->add($oldNotice);
$newNotice = new Notice('i-am-unique', 'Chaos is a ladder.');
$store->add($newNotice);
$store->delete('i-am-unique');
$store = new Store('my_unique_option_key');
$notifier = new Notifier('my_unique_action', $store);
add_action('admin_notices', [$notifier, 'renderNotices']);
add_action("wp_ajax_my_unique_action", [$notifier, 'dismissNotice']);
add_action('admin_footer', [$notifier, 'renderScript']);