x-wp / admin-notice-manager
Simplifies the process of working with admin notices in WordPress.
Requires
- php: >=8.0
- x-wp/helper-functions: ^1.16
- x-wp/helper-traits: ^1.16
Requires (Dev)
Suggests
- automattic/jetpack-autoloader: Allow for better interoperability with other plugins that use this package.
Replaces
This package is auto-updated.
Last update: 2024-11-01 13:10:09 UTC
README
Admin Notice Manager 🔔
Simplifies the process of creating, displaying and saving notices in WordPress admin.
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.
How to use
Installation
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.
Configuration and initialization
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.
Examples
Creating a notice
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();