dev-master
9999999-devManage WordPress Admin Notices easily
MIT
The Requires
- php >=5.3.2
- composer/installers >=v1.2.0
by Pablo Pacheco
wordpress admin notice notices
Wallogit.com
2017 © Pedro Peláez
Manage WordPress Admin Notices easily
An easy and convenient way to create WordPress admin notices that can be closed persistently. Besides that it has some cool features: * Keep your notices hidden only for the user who closed it. * Display your notice on specific situations, like when some plugin gets updated or activated or on specific admin screen ids or on $_GET / $_POST requests, * Create your own special cases where/when your notice should be displayed, (*1)
add_action( 'admin_notices', function () {
$notices_manager = \ThanksToIT\WPAN\get_notices_manager();
$notices_manager->create_notice( array(
'id' => 'my-notice',
'content' => '<p>My Notice</p>',
) );
} );
Note: By default, this library will make notices persist, meaning they will not be displayed again after user close them, unless they expire, (*2)
In order to make it work perfectly, you need to initialize it like this:, (*3)
add_action( 'wp_ajax_' . 'tttwpan_dismiss_persist', array( 'ThanksToIT\WPAN\Notices_Manager', 'ajax_dismiss' ) ); add_action( 'activated_plugin', array( 'ThanksToIT\WPAN\Notices_Manager', 'set_activated_plugin' ) ); add_action( 'upgrader_process_complete', array( 'ThanksToIT\WPAN\Notices_Manager', 'set_upgrader_process' ), 10, 2 );
And it's important to make these calls before any other hook on your plugin/theme. But don't worry, this library will be loaded only when it's necessary, as it's being called on the proper hooks, (*4)
'notice-info', 'notice-warning', 'notice-success', 'notice-error', 'notice-info'. Default value is 'notice-info'.true.MONTH_IN_SECONDS.'screen_id' => array( 'plugins' ).'activated_plugin' => array('akismet/akismet.php').'updated_plugin' => array('akismet/akismet.php').'key' and 'value' parameters. Example:
'request' => array( array( 'key' => 'show_notice', 'value' => '1' ), ).array( 'activated_plugin', 'updated_plugin' ),add_action( 'admin_notices', function () {
$notices_manager = \ThanksToIT\WPAN\get_notices_manager();
$notices_manager->create_notice( array(
'id' => '1-week-notice',
'content' => '<p>1 week notice</p>',
'dismissal_expiration' => WEEK_IN_SECONDS,
) );
} );
add_action( 'admin_notices', function () {
$notices_manager = \ThanksToIT\WPAN\get_notices_manager();
$notices_manager->create_notice( array(
'id' => 'plugins-page-notice',
'content' => '<p>plugins page notice</p>',
'display_on' => array(
'screen_id' => array( 'plugins' ),
)
) );
} );
add_action( 'admin_notices', function () {
$notices_manager = \ThanksToIT\WPAN\get_notices_manager();
$notices_manager->create_notice( array(
'id' => 'akismet-notice',
'content' => '<p>Akismet notice</p>',
'display_on' => array(
'activated_plugin' => array('akismet/akismet.php')
)
) );
} );
To install this package, edit your composer.json file:, (*5)
{
"require": {
"thanks-to-it/wp-admin-notices": "dev-master"
}
}
Now run:, (*6)
$ composer install, (*7)
Manage WordPress Admin Notices easily
MIT
wordpress admin notice notices