Library for displaying Wordpress notices.

3.2.0 2022-06-06 16:36 UTC


pipeline status coverage report Latest Stable Version Total Downloads Latest Unstable Version License


A simple, yet very useful library for WordPress plugins allowing to display the different kind of notices in the admin area. It can be easily used to:

  • Display the simple error, warning, success and info notices,
  • Display the permanently dismissible notices,
  • Handle the dismiss functionality with AJAX requests.


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.


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:


// 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' );

Project documentation

PHPDoc: https://wpdesk.gitlab.io/wp-notice/index.html