It often happens to have WordPress inactive plugins in your list but you will not need them for a long time or not need them anymore and forget to delete them. If you know you do no need update notifications for some of the disabled plugins or for all, then you can use the following code to hide the updates.
This is also useful if you want to keep using an older version of a plugin until, some day, you will update it to the latest version. This way, the plugins page and the link in the Dashboard’s sidebar will show you the number of available updates based on your preferences.
Place this code into functions.php (located in your active’s theme folder):
[php]
function bit_hide_plugins_updates( $value ) {
// View it only in the Dashboard
if( ! is_admin()) {
return;
}
$plugins_list = array();
//$plugins_list[] = ‘akismet/akismet.php’;
//$plugins_list[] = ‘plugin-name/plugin-file-here.php’;
// Check if $value is an object and $value->response is not empty
if ( isset( $value ) && is_object( $value ) && ! empty( $value->response ) ) {
// No Custom List? Disable Updates for all inactive ones
if(empty($plugins_list)) {
foreach( $value->response as $plugin => $plugin_info ) {
$plugin_path = isset($plugin_info->plugin) ? $plugin_info->plugin : $plugin;
if( ! is_plugin_active($plugin_path) ) {
unset($value->response[$plugin_path]);
}
}
// Disable updates for specified inactive plugins
} else {
foreach( $plugins_list as $plugin_path ) {
if( ! is_plugin_active($plugin_path) ) {
unset($value->response[$plugin_path]);
}
}
}
}
return $value;
}
add_filter( ‘site_transient_update_plugins’, ‘bit_hide_plugins_updates’, 10000 );
[/php]
How it works?
By using the filter ‘site_transient_update_plugins’, the inactive plugins are being removed from the list that is shown when you access the plugins page or view the number of updates within the “Plugins” link in the Dashboard. Note that I’ve added 10000 (can be updates to a lower or bigger values depending on the situation) argument for the $priority argument. This is to trigger the filter late after other plugins already done their filtering.
If we are viewing the Dashboard then the function checks if there is any list of inactive plugins for which you want to disable the updates. If it’s not ($plugins_list is empty – line 7) it will go through all plugins, otherwise it will only check the list you specified (see lines 8 and 9).
What if I want to disable updates for active plugins as well?
Just comment out the code that verifies if the plugin is not active like in the following example:
[php]//if( ! is_plugin_active($plugin_path) ) {
unset($value->response[$plugin_path]);
//}[/php]
If you want to disable updates JUST for active plugins, then you just have to remove the exclamation mark from the IF clause like this:
[php]if( is_plugin_active($plugin_path) ) {
unset($value->response[$plugin_path]);
}[/php]