wpdesk / wp-notice
Library for displaying Wordpress notices.
Requires
- php: >=7.0.8
- wpdesk/wp-builder: ^1.0|^2.0
Requires (Dev)
- 10up/wp_mock: *
- mockery/mockery: *
- squizlabs/php_codesniffer: ^3.0.2
- wimg/php-compatibility: ^8
- wp-coding-standards/wpcs: ^0.14.1
- wpdesk/wp-codeception: ^2.7
- dev-master
- 3.2.5
- 3.2.4
- 3.2.3
- 3.2.2
- 3.2.1
- 3.2.0
- 3.2.0-beta7
- 3.2.0-beta6
- 3.2.0-beta5
- 3.2.0-beta4
- 3.2.0-beta3
- 3.2.0-beta2
- 3.2.0-beta1
- 3.1.4
- 3.1.4-beta1
- 3.1.3
- 3.1.1
- 3.1
- 3.0
- 2.3
- 2.2.2
- 2.2.1
- 2.2
- 2.1.1
- 2.1
- 2.0.1
- 2.0
- 1.0.2
- 1.0.1
- 1.0
- dev-fix/duplicate
- dev-bugfix/get_current_screen_fail
- dev-feature/dismiss-nonce
- dev-replace-dodgy-path
- dev-bugfix/notice-not-show
- dev-devel
This package is auto-updated.
Last update: 2024-11-23 14:25:30 UTC
README
wp-notice
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.
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' );