A WordPress plugin demonstrating how the class Typewheel_Notice operates.
This plugin demonstrates a simple way to implement delayed and dismissible admin notices in WordPress. This implementation of notices is most notably unique in that it…
- allows any number of unique notices to be added to a plugin.
- allows dismissal forever or allows for a user to request a reminder in one week or one month.
- allows the notice to display on any number of admin pages (including those added by other plugins having only a
?page=
parameter in the URL). - allows defining a capability per notice which controls the users to whom a notice is shown.
- implements dismissals on a per user basis.
- includes a
show_typewheel_notices
filter that can completely disable notices on a site. - allows full styling of the notice.
- allows for both a plugin activation notice and delayed notices.
- Add the
typewheel-notice/
folder to your root directory. - Include the code from
plugin.php
in your root file. - Search & replace all instances of
your_prefix_
in the root file. (prefix should be unique to project) - In the
register_deactivation_hook
, replacetypewheel-notice-demo.php
with the name of your root file. - Customize your notices.
All of the following arguments can be customized in each notice array
$prefix . '-unique-notice-id' => array()
(This array id will be used to track dismissals and must be unique for each notice. Do not modify the $prefix)
'trigger' => {true|false}
(This flags whether or not the notice should be shown)
'time' => time() +/- {int}
(when should the notice be made active? replace {int} with number of seconds before/after activation)
'dismiss' => array({week,month})
(whether to include an option to dismiss for one week or one month)
'type' => {success|error|warning|info}
(optional) (whether to include WP notice styling)
'icon' => {dashicon-slug}
(optional) (prepends a dashicon to the notice)
'content' => ''
(required) (string with content of notice)
'style' => array() or ''
(optional) (array of CSS parameters/values)
'location' => array()
(required) (array of pages on which to show the notice)
'capability' => ''
(optional) (to whom should the notice be shown? defaults to read
.)