Earlier today, Jason Gegere asked me how to prevent WordPress from checking for updates on a plugin. This may be helpful if you are running a custom version of a plugin from the repository and you don’t want to accidently update the plugin and lose the customizations, or if you are running a private plugin and don’t want WordPress to check for updates from the plugin repository. WordPress doesn’t know if your plugin is in the WordPress plugins repository and it will request the update check on all installed plugins.
WordPress checks for updates using wp_update_plugins() in wp-includes/update.php but there are no hooks in this function which could be used to exclude your plugin from the update check. However, you can hook into http_request_args and remove your plugin from the query arguments passed in the http request. You can add the following code to your plugin to prevent WordPress from checking for updates for your plugin:
add_filter( 'http_request_args', 'dm_prevent_update_check', 10, 2 );
function dm_prevent_update_check( $r, $url ) {
if ( 0 === strpos( $url, 'http://api.wordpress.org/plugins/update-check/' ) ) {
$my_plugin = plugin_basename( __FILE__ );
$plugins = unserialize( $r['body']['plugins'] );
unset( $plugins->plugins[$my_plugin] );
unset( $plugins->active[array_search( $my_plugin, $plugins->active )] );
$r['body']['plugins'] = serialize( $plugins );
}
return $r;
}
Let me be specific. To correctly use this function. Would this example be correct for the commonly used “Art Direction” plugin?
add_filter( ‘http_request_args’, ‘dm_prevent_update_check’, 10, ‘http://wordpress.org/extend/plugins/art-direction’ );
What does the variable $r = 10 specify.
No, that’s not correct.
add_filter()takes in four parameters and you can read more about it in the codex here. The two arguments,$rand$url, come from thewp_remote_post()inwp_includes/updates.php. You’ll just need to paste the code as-is in your plugin.Hi, thanks for your script. Love it. Word of WARNING to others: make sure you change the function name if you use this on more than one plugin. Yeah, I’ve been hacking plugins – I know it’s not ideal but for some reason no one does exactly what the client needs!
So my little mistake of using the same function name in two plugins got me thinking. Is there a way to this to the next level and create a plugin that disables other plugins? It seems like if you can disable all updates including core update notification one should be able to write one would list all plugins (installed or not) and selectively control update notification for each?
Very nice, I’m a huge fan of WordPress and it’s great to see new really useful plugins getting released. Going to download and check it out, looks exactly like what I was looking for for weeks. So, thanks alot!
Just one question regarding the code above:
does the plugin need to be activated to actually work?
In a short test with an outdated plugin (which was not active at that moment) on my WordPress MU the code had no further effect.
However, thanks for all your exceptionally insightful posts
Yes, the plugin needs to be activated for the code to work.
Doesn’t work in WordPress 3.0? Or am I doing something wrong…?
Works with 3.0. You may be doing something wrong.
Hi Pete – this function is great and works in MultiSite 3.1 network provided that the plugin php file exists in the root plugin folder – i.e., in the wp-contents/plugins/ but if in a folder further south, e.g., wp-contents/plugins/my-custom-plugin-dir/ then it does not work and the auto check for updates still continues to run …
e.g., i hacked the CIMY User Manager plugin for my own import needs and the plugin typically gets installed in a folder called “cimy-user-manager” which is then subset of the plugins folder … hacked plugin runs fine yet when i put your function in the main php file (ie., cimy_user_manager.php) then the auto check for updates continues thus your function does not work while in that sub folder … if i move cimy_user_manager.php to the root plugins folder, then your function does work (meaning it stops looking to be updated) …
thus i’m not sure if your $my_plugin variable needs to be prepended with the plugin directory or ..??..
regardless, muchisimo gracias for sharing as it certainly helped me for now and only share as fyi in case this sub-folder thing might be issue for others ..??..
cordially, chuck scott
thanks! You just saved me a ton of work from having to go re-add code everytime my client updated the darn plugin herself lol
It doesn’t seem to be doing anything…
I just pasted the code at the bottom of my plugin file, and *even* putting a var_dump() in the function doesn’t output a single extra character. Seems the filter function is never called. What gives?
Oops, my bad. I didn’t realize WP only checks once every 12 hours, unless something has changed. Good to know, since it’s only hidden deeply in the source code and not mentioned on the plugins overview.