An helper library to create persistent and dismissible WordPress admin notices.
Composer is required.
composer require alessandrotesoro/wp-noticesImport the library and assign it your own namespace:
use TDP\WP_Notice as MYNOTICES;Create a wrapper function:
function mynotices() {
return MYNOTICES::instance();
}Create a global notice for all users:
mynotices()->register_notice( 'my_notice', 'warning', 'This is the message' ) );Or create a notice for the currently logged in user only:
mynotices()->register_notice( 'my_notice', 'warning', 'This is the message', array( 'scope' => 'user' ) ) );| Parameter | Type | Options | Defaults | Description |
|---|---|---|---|---|
| id | string | Required ID to identify the notice | ||
| type | string | success, warning, error, info | Determine the type of notice | |
| message | string | The message you wish to display within WordPress | ||
| args | array | scope (global, user), dismissible (true/false), cap, class | scope = global, dismissible = true | Additional settings available for the notice |