Displaying notices in WordPress admin is a common task for plugin and theme developers. This package provides an easy to use API for notice management.
You can install the package via composer:
composer require x-wp/admin-notice-manager
Tip
We recommend using the automattic/jetpack-autoloader
with this package to prevent autoloading issues.
Package will automatically initialize itself on admin_init
hook. Manager comes with batteries included - you will use the Notice class to create and display notices.
If you are certain that no invoice has the same id as the one you are creating, you can use the xwp_create_notice
function to create a notice.
<?php
xwp_create_notice(
array(
'id' => 'my-plugin-notice',
'type' => 'info',
'message' => 'This is an informational notice.',
'persistent' => true,
'dismissible' => true,
)
);
Alternatively you can use the xwp_get_notice
function to try retrieving a notice by its id - and create it if it doesn't exist.
<?php
xwp_get_notice('my-plugin-notice')
->set_props(
array(
'id' => 'my-plugin-notice',
'type' => 'info',
'message' => 'This is an informational notice.',
'persistent' => true,
'dismissible' => true,
)
)
->save();