Helper class to display admin notices.
composer require shazzad/wp-admin-notice
Initialize the service provider.
\Shazzad\WpAdminNotice\Provider::setup();
Call the function do_action
with appropriate parameter to add a notice.
This code must be placed before wp admin area start rendering content on screen.
Use admin_notices
, all_admin_notices
or network_admin_notices
action hook to add notice.
do_action(
'swpan_notice',
array(
'success' => __('You setting is stored successfully.'),
'id' => 'plugin-setting',
)
);
do_action(
'swpan_notice',
array(
'error' => __('Sorry, we could not save your settings.'),
)
);
Use user notice when you perform some action and redirect the user to a page. The notice will be stored for until it is displayed to the user. Add a third parameter to the action hook to add a user notice.
do_action(
'swpan_notice',
array(
'message' => __('You setting is stored successfully.'),
'type' => 'success',
'id' => 'my-notice-id',
),
'user'
);
do_action(
'swpan_notice',
array(
'message' => __('Sorry, we could not save your settings.'),
'type' => 'error',
'id' => 'my-notice-id',
),
'user'
);
- WordPress: 6.0.1
- PHP: 7.4
- Tested: 6.2.2