Because we'll be sharing a lot of code outside of the WordPress plugin ecosystem, we needed a way to communicate updates to plugins (or shortcodes) when required. While we can 'force' our clients to use a global plugin that accomplishes what we've just described (and a lot more), it's not appropriate for the average user that might use a plugin of ours and then rarely check back in. With a view to making the simple plugins we share more scalable, we've decided to use a WordPress hook function with each plugin that will render an update message (and link) via a WordPress admin notice whenever it's required. It's made possible via the funky little API we're using with our download manager.
Admin Notices
Admin notices are rendered in your WP administration dashboard as messages at the top of your page. While they're often used by plugin developers for success, failure, and other messages, they can be used for any purpose. If you have a multi-author website they're an effective way of broadcasting a message (although dashboard custom meta boxes are likely more effective).
Example: If you want to display a generic admin notice to all your authors as they visit their dashboard (as pictured above), use the following.
Copy and paste the WordPress function into your theme's functions.php
file or, if you sensibly have one installed, your custom functions plugin.
To render the notice only between a certain timeframe, use the from
and to
arguments. Different styles can be applied by using $notice="1"
(notice-info), $notice="2"
(notice-warning), or $notice="3"
(notice-error).
The admin notice will render on every single administration page. To display on only the front dashboard page, use the following action (uses the load-(page) hook):
Plugin Update Notices Shortcode
The following code will be of value to those of our clients that use our new download manager. For plugins distributed company-wide (without our oversight), the admin notice is an effective means of providing update notifications. For the purpose of the example, we'll use the function packaged with an upcoming post on pastebin shortcode.
With each plugin we package up, the $atts
array and function name is altered. We'll cache version data for up to a month. When the version returned via our API differs from that of the plugin, we'll display the notice in the administration dashboard.
Download
The downloadable code includes only the first function (labeled as shortcode).
Title: Display WordPress Admin Notices
Description: Display WordPress Admin (Plugin Upgrade) Notices. We use this feature for upgrade notifications.
Download • Version 0.1, 704.0B, zip, Category: WordPress Shortcodes