wp admin notices
1.0.0
An easy and convenient way to create WordPress admin notices that can be closed persistently. Besides that it has some cool features:
add_action( 'admin_notices', function () {
$notices_manager = ThanksToITWPANget_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
In order to make it work perfectly, you need to initialize it like this:
add_action( 'wp_ajax_' . 'tttwpan_dismiss_persist', array( 'ThanksToITWPANNotices_Manager', 'ajax_dismiss' ) );
add_action( 'activated_plugin', array( 'ThanksToITWPANNotices_Manager', 'set_activated_plugin' ) );
add_action( 'upgrader_process_complete', array( 'ThanksToITWPANNotices_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
'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 = ThanksToITWPANget_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 = ThanksToITWPANget_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 = ThanksToITWPANget_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:
{
"require": {
"thanks-to-it/wp-admin-notices": "dev-master"
}
}
Now run:
$ composer install