I have a plugin that I know I never want to update. I am aware that this is NOT best practice, but in this case it must be done. Is there any way to stop WordPress from prompting me to auto-update a particular plugin (but still alert as normal for all other plugins).
8 Answers
you place this in your theme's functions.php
// Disable update notification for individual plugins - see my example of plugin block-spam-by-math-reloaded as to how to use this function
function filter_plugin_updates( $value ) {
unset( $value->response['plugin-folder-name/plugin-file-name.php'] );
return $value;
}
add_filter( 'site_transient_update_plugins', 'filter_plugin_updates' );
-
I don't understand why there's a Google +1 button code in your answer... Probably a left over... Commented Jun 29, 2012 at 19:38
-
-
3This solution throws a warning while enabling or disabling any other plugin.
Warning: Attempt to modify property of non-object in /home/XXXXXX/public_html/wp-content/themes/XXXXXXX/custom-functions.php on line 15
– gurungCommented Jan 11, 2014 at 3:58 -
T31os's answer was right: Increase the version number inside the plugin's main file.. eg. 99.9 ... and also make that same change inside the readme file for good measure(though i don't think that's actually required).. – t31os
While Tara's answer works well, it requires the programmer to enter the path to the main plugin file and it is only functional while that particular theme is enabled. An alternative solution might look like this:
add_filter('site_transient_update_plugins', 'remove_update_notification_1234');
function remove_update_notification_1234($value) {
unset($value->response[ plugin_basename(__FILE__) ]);
return $value;
}
one-line version:
add_filter('site_transient_update_plugins', function ($value) { unset($value->response[ plugin_basename(__FILE__) ]);return $value; });
Place this code at the top of the main .php
file of the plugin you wish to disable. If you plan on using this more than once in your site, change the _1234
in the filter and function name to a different set of random numbers to avoid duplicate function names.
Chances are that if you are disabling updates for a particular plugin, it's because you're editing it for some reason... so adding a few extra lines to that plugin should be viable.
-
1This is the best answer in my opinion, especially if you are disabling updates because you're editing the plugin yourself. Thanks emc.– NathanCommented May 11, 2018 at 15:55
I was getting PHP Warnings like 'gurung' mentioned above when I installed or updated other plugins when I was using this code. I saw the PHP Warnings in WP 4.3.1.
I found some other posts on stackexchange about the issue and I've come up with a function that loops through your array of plugin references and first checks to see if there's a reference to that plugin already (to avoid the PHP warning on non-objects if there isn't one) and if there is an object it will unset it just like the original code.
I haven't done unit tests but was getting PHP warnings on every update/install of plugins and now I don't see them.
function filter_plugin_updates( $value ) {
// Add references to plugins you want to disable update notices for in the $plugins array
$plugins = array(
'k-elements/setup.php'
);
foreach( $plugins as $plugin ) {
if ( isset( $value->response[$plugin] ) ) {
unset( $value->response[$plugin] );
}
}
return $value;
}
add_filter( 'site_transient_update_plugins', 'filter_plugin_updates' );
Or you just rename it so it is 'not' the same plugin.
You need to rename not just the folder but also in the readme and plugin header.
I inherited a site with npc's implementation of tara's code snip, which threw errors per gurung's comment. Drove me nuts. I was hesitant to edit code in a plugin, until I realized that the snipper is custom anyway.
To eliminate the errors, change this:
unset($value->response[ plugin_basename(__FILE__) ]);
to this:
if($value) {
unset($value->response[ plugin_basename(__FILE__) ]);
}
It may be obvious to some, but the key is that it is already custom so you can edit it, and it probably won't be overwritten by updates because the whole point is to keep you from updating the plugin.
You can prevent updates simply by renaming the plugin folder (or, in the case of a single-file plugin, renaming that PHP file). This is by far the simplest solution. In addition, this approach makes the fact that you altered the code transparent to future devs, including "future you".
A Higher version in the main plugin file is best, but only when adding a special hack. It calls a null/undefined number and will then remain in that version. Example:
Version:
This will ensure that in 2100 it won't be updated after 9.9.9 or something like that. It is a simple approach for abandoned plugins that will at sometime be replaced.
99.9
...and also make that same change inside the readme file for good measure(though i don't think that's actually required)..1.10.1
?