WordPress Library to display notices in admin area.
wp-notice is a simple library for WordPress plugins allowing to display notices in admin area.
This library can display simple notices such as error, warning, success, info and dismissible ones as well. It can also handle dismiss functionality with AJAX requests.
Requirements
PHP 5.5 or later.
Installation via Composer
In order to install the bindings via Composer run the following command:
composer require wpdesk/wp-notice
Next, use the Composer's autoload to use them:
require_once 'vendor/autoload.php';
Manual installation
If you prefer not to use the Composer you can also download the latest library release. Once it is done, simply include the init.php file to use the Notices.
require_once('/path/to/wp-desk/wp-notice/init.php');
Getting Started
Notices usage example
$notice = wpdesk_wp_notice('Notice text goes here');
// Is equivalent to:
$notice = WPDeskWpNotice('Notice text goes here');
// Is equivalent to:
$notice = \WPDesk\Notice\Factory::notice('Notice text goes here');
// Is equivalent to:
$notice = new \WPDesk\Notice\Notice('Notice text goes here');
Please mind that the Notice must be used before WordPress admin_notices
action. You can find WordPress admin actions order listed here.
Permanently dismissible notices
AJAX handler
In order to use permanently dismissible notices the AJAX handler needs to be created first and the hooks initialized:
wpdesk_init_wp_notice_ajax_handler();
// Is equivalent to:
( new \WPDesk\Notice\AjaxHandler() )->hooks();
Displaying the permanently dismissible notices
Use the following code for the permanently dismissible notice to be displayed:
wpdesk_permanent_dismissible_wp_notice( 'Notice text goes here', 'notice-name' );
// Is equivalent to
$notice = new \WPDesk\Notice\PermanentDismissibleNotice( 'Notice text goes here', 'notice-name' );