Disable WordPress Plugins update indicator for inactive plugins
I have to really tip my hat to the guys that work hard on the core WordPress code at Automatic. In the last 12 months they taken the system to new heights with a complete redo of the admin interface. Adding many features to extend the core so that developers like myself can extend things even further.
Take for example the nice little number displayed on the Plugins menu item when some of your installed plugins are out of date. What a nice little feature. There is also an update display on the actual Plugins page the little yellow-ish box below a plugin row to indicate there is an update and the user needs to take action. From a usability stand point I think this sort of forward thinking is the reason I keep hacking in WordPress instead of other CMS-type systems like Drupal, Joomla, eZ Publish, etc.
But I do have a major annoyance with this ‘feature’. Like many other WordPress users I have man plugins installed. At any given time I will have a third of the plugins disabled maybe because I was testing things or maybe I deactivated the plugin but didn’t want to uninstall it. My annoyance is that the plugin update indicators work on all plugins even those you don’t have active. Not good. Worse on the client sites I support I really don’t want the client to need to worry about updating inactive plugins.
Sure I know there are at least half a dozen plugins that will completely turn off the plugin and WordPress core update nag indicators. But I really don’t want that. I just don’t want to see update nag on those plugins I’m not currently using.
So I did some research on this lazy Sunday afternoon and figured out how to hide the update indicator on those inactive plugins. The code below will hide these inactive plugin from the update counter. When the plugin is re-activated the plugin update indicator will once again show in the sidebar menu and on the plugins listing.
The Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | function update_active_plugins($value = '') { /* The $value array passed in contains the list of plugins with time marks when the last time the groups was checked for version match The $value->reponse node contains an array of the items that are out of date. This response node is use by the 'Plugins' menu for example to indicate there are updates. Also on the actual plugins listing to provide the yellow box below a given plugin to indicate action is needed by the user. */ if ((isset($value->response)) && (count($value->response))) { // Get the list cut current active plugins $active_plugins = get_option('active_plugins'); if ($active_plugins) { // Here we start to compare the $value->response // items checking each against the active plugins list. foreach($value->response as $plugin_idx => $plugin_item) { // If the response item is not an active plugin then remove it. // This will prevent WordPress from indicating the plugin needs update actions. if (!in_array($plugin_idx, $active_plugins)) unset($value->response[$plugin_idx]); } } else { // If no active plugins then ignore the inactive out of date ones. foreach($value->response as $plugin_idx => $plugin_item) { unset($value->response); } } } return $value; } add_filter('transient_update_plugins', 'update_active_plugins'); // Hook for 2.8.x //add_filter( 'option_update_plugins', 'update_active_plugins'); // Hook for 2.7.x |
A note on the ‘add_filter’ lines just above. Seems there are two different hooks depending your the WordPress version. If you are running version 2.8.x or newer you should be safe to use the first add_filter line. If however you are still using 2.7.x then comment out the first add_filter an use the second one.
Installation
I really don’t plan to turn this into an official plugin for WordPress. So the simplest method of installation is to add it to your theme’s functions.php file.
Media Tags 2.2 plugin for WordPress Released
Filed Under: Tags: media-tags, plugin, WordPress
Over this past week I added quite a few features to the famous Media Tags plugin for WordPress. The list below details many of these new features
- Added a new tab to the Media Upload popup box. Anyone familiar with WordPress Post or Page entry is familiar with the popup provided to upload images and other media files. In this popup if you wanted to search for items using the handy Media Tags it was not possible. Now the user is provided with a new Tab labelled ‘Media Tags’. When the tab is clicked the user is presented with a listing of all Media Tags used on the site. Along with the Media Tag name there is a use could in the far right of the listing. This count if greater than zero is a link and will filter the Media Library (another Tab) listing for items from that Media Tags group.
Below is a screenshot of the new popup tab.
- More control over the permalink prefix. The Media Tags plugin works with the WordPress Permalink rewrite system to provide ‘pretty’ URLs for the archive. For example if you have some media loaded and tagged on your site for say ‘Texas’. The you can display these items in an archive type listing by using the URL http://www.mysite.com/media-tags/texas/ This format should be familiar to most users of WordPress since Categories and Tags or handled in much the same way. This feature was added in Media Tags version 2.0 and has received much acclaim from the users. The problem is the prefix ‘/media-tags/’ was hard-coded into the plugin. I have a few users request a way to alter this prefix. Other than suggesting they edit the config file for the plugin there was not a good solution.
So I starting thinking I would just build my own admin page where the user can set this permalink prefix. But I hated having to build a new admin page just for the one setting. Well over the weekend I found the solution of solutions. Why not just add my own field to the WordPress Settings -> Permalink page. This turned out to be quite easy using the new Settings API introduced into WordPress 2.7.
Below is a screenshot of the new Media Tags Permalink option. The new field just below the standard Category and Tags fields.
-
Playing nice with other plugins. I’ve used the Google Sitemap XML plugin for quite some time and generally install it by default onto any client site I’ve worked on. This is one of those plus plus plugins that can only help your site. Recently I had to figure out a way to include non-WordPress pages into the XML sitemap output. This is actually very easy to do as the plugin authors have provide a nice hook to allow this.
So my next enhancement to the Media-Tags plugin was to include the Media Tag archives into the Google Sitemaps XML output. This feature is quite powerful since it just adds juice to Google content harvesting. Not wanting to hard-coded this feature into the plugin I ended up building that admin interface I mentioned in the previous point. There is only one option on the page (more to come soon). A simple Yes/No box to include/exclude the Media Tags archive from the Sitemap XML output. I assume most people will wan this but also know there is always the possibility some may now.
Below is a screenshot of the new Media-Tag admin interface. Look for this under the standard WordPress Settings section.
- Along with the above mentioned new features I also cleaned up some code related issues. Most of these are under the covers cosmetic items and not related to any screen changes.
Media Tags Future Enhancements
Still on my list of features to add in some upcoming release is Media-Tags Cloud. This is still one of the most requested options for the sidebar. Still working on that code. Trying to follow some of the code written for the built-in WordPress Tags. pretty ugly stuff. Has to be a better way.
Other than the Media Tags Cloud I don’t have any big changes planned for the plugin. Then again the three features mentioned in this post were not planned at all. Just something that hit me on Friday that I started working toward.
So if there is a feature you just think would make the Media-Tags plugin rock for your blog please consider leaving a comment below.
Donations
If you enjoy using the Media Tags plugin or any of my other WordPress plugins, please consider making a donation to show your support. Anything is appreciated. Thanks.
The correct method of adding JavaScript to a WordPress theme
Filed Under: Tags: Codex, function, init, WordPress
A quick note to all the WordPress developments out there. If you are adding a standard JS library like jQuery or Prototype, chances are WordPress already includes a version as part of the core files. So no need to download your own copy and place in somewhere in the themes folder.
Many theme developer who rely on JS for different effects simple place the link into the template header.php. Something like this:
1 2 | <script type='text/javascript' src='http://localhost/wp-content/themes/mytheme/js/jquery/jquery.js'></script> |
While this does accomplish the goal of loading the JS library it also increases the chances of a second instance of the library also being loaded. Thus bloating your site.
A better option in my opinion is to add a little code to the themes functions.php file. The theme file functions.php is standard in most WordPress themes and is considered the best place to place common code that is needed by the theme. The functions.php file is automatically loaded by WordPress.
1 2 3 4 | function my_functions_init() { wp_enqueue_script('jquery'); } add_action( 'init', 'my_functions_init' ); |
Note we are hooking into the WordPress ‘init’ logic. We must setup the JS loading early. Some time later WordPress will load the theme. If the theme header used the theme function ‘wp_head()’ then our JS library will automatically be included. The ‘wp_head()’ function allows plugin author to insert needed JS and CSS files dynamically. Using this hook we are doing the same thing for our theme. No more hard coding the JS file link.
So how is this really “Better”?
The biggest benefit is we are preventing multiple copied of the same JS library from being loaded by WordPress or plugins. If we did hard code the JS link for jQuery and we also installed some plugin like cforms which used the jQuery library then it will load it’s own copy. By using the ‘wp_enqueue_script()’ function we are letting WordPress know we need jQuery loaded. When the plugin is loaded it will also tell WordPress is needs to load jQuery. As a result WordPress can track what JS files need to be inserted via the ‘wp_header()’ function.
For more information on the ‘wp_enqueue_script()’ function check the WordPress Codex
http://codex.wordpress.org/Function_Reference/wp_enqueue_script
Media Tags 2.0 released
Filed Under: Tags: media-tags, plugins, WordPress
Today I would like to finally release to the wild the totally rewritten Media-Tags plugin version 2.0. The Media-Tags plugin 2.0 has been completely rewritten to use to WordPress Taxonomy system for storing related media-tag information. As a benefit to this rewrite the user now has a new Media Tags management interface located under the Media section. Via this Media Tags management interface users can better manage the media tags used on the site. Deleting, renaming and adding new media tags is now quite simple. The Media Tags for the attachment are still display both under Media and the media popup on the editor screen as before. (more…)
Media Tags 2.0 Beta
Filed Under: Tags: development, media-tags, WordPress
Today I’d like to release the first public beta of the Media Tags plugin. This is an exciting change and almost complete rewrite to the core plugin code.
For anyone downloading this beta please be aware this is a beta version and subject to change in the near future. Also since this is a beta it is recommended NOT to use this on a production system. User beware! If you do download the plugin and test if please using the comment form below to mention any issue you have with the new plugin. I can only test thing to a certain level with my own client sites.
This new beta has been tested on WordPress versions 2.7.1 and 2.8 only! At this time I’ve not tested the new Media-Tags Management interface on any lower version of WordPress.







