dev-master
9999999-devDisplay admin notices in WordPress after a page redirect or reload.
GPL-2.0+
by Micah Wood
1.0
1.0.0.0Display admin notices in WordPress after a page redirect or reload.
GPL-2.0+
by Micah Wood
Wallogit.com
2017 © Pedro Peláez
Display admin notices in WordPress after a page redirect or reload.
Handles the display of admin notices in WordPress after a page redirect or reload., (*1)
When creating a new instance of TransientAdminNotices, you will need to provide a transient name. This is used as either the cache key, when caching is enabled, or the database option name, if caching isn't an option. If you're notice is user-specific, be sure to scope your transient name to the user., (*2)
Ensure that you instantiate the class on the admin_init hook. This ensures that the class can automatically setup a hook to render your notices on the admin_notices hook and that it only runs in the WordPress admin. Note that you must create an instance, even if you are not adding new notices, in order for notices from a previous page load to display., (*3)
All notices added to your instance require a key, the message you want to display, and the notice type. The key can be any string you want and can be used to later get or remove that specific notice from the queue., (*4)
These notice types are the types provided by WordPress, but can be passed in to the add() method to customize how your notices will display., (*5)
success - Displays with a green bar info - Displays with a blue bar (default)warning - Displays with an orange barerror - Displays with a red bar<?php
use wpscholar\WordPress\TransientAdminNotices;
add_action( 'admin_init', function() {
$transient_name = md5( 'my_plugin' . get_current_user_id() );
$notices = new TransientAdminNotices( $transient_name );
if( ! $user_has_account ) {
$notices->add( 'msg1', 'Looks like you have not created an account yet!', 'warning' );
}
} );
Display admin notices in WordPress after a page redirect or reload.
GPL-2.0+
Display admin notices in WordPress after a page redirect or reload.
GPL-2.0+