Skip to content
Snippets Groups Projects
Grzegorz Rola's avatar
Grzegorz Rola authored
Feature/readme

See merge request !22
19b51baa

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

WordPress Library to display notices in admin area.

wp-notice is a simple library for WordPress plugins to display notices in admin area.

This library can display simple notices (error, warning, success, info) and dismissible notices. It also handles dismiss functionality with AJAX requests.

Requirements

PHP 5.5 or later.

Installation with composer

You can install the bindings via Composer. Run the following command:

composer require wpdesk/wp-notice

To use the bindings, use Composer's autoload:

require_once 'vendor/autoload.php';

Manual installation

If you do not wish to use Composer, you can download the latest release. Then, to use the Notices, include the init.php file.

require_once('/path/to/wp-desk/wp-notice/init.php');

Getting Started

Simple usage looks like

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

Notice must be used before WordPress action admin_notices. WordPress admin actions order is listed here.

Permanent dismissible notices

AJAX handler

To use permanent dismissible notices AJAX handler must be created and hooks initialized:

wpdesk_init_wp_notice_ajax_handler();

// Is equivalent to:
( new \WPDesk\Notice\AjaxHandler() )->hooks();

Displaying

To display permanent dismissible notice:

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

AJAX handler

To use permanent dismissible notices AJAX handler must be created and hooks initialized:

wpdesk_init_wp_notice_ajax_handler();

// Is equivalent to:
( new \WPDesk\Notice\AjaxHandler() )->hooks();

Displaying

To display permanent dismissible notice:

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