Prevent Update Checks for a WordPress Plugin

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;
}

Related posts:

  1. New Plugin Release: WP Plugin Installer
  2. How to Tweak the WordPress Generator Meta Tag
  3. How to Create a WordPress Dashboard Widget
This entry was posted in Plugin Development, WordPress and tagged , , , . Bookmark the permalink.

7 Responses to Prevent Update Checks for a WordPress Plugin

  1. Jason Gegere says:

    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.

    • Pete Mall says:

      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, $r and $url, come from the wp_remote_post() in wp_includes/updates.php. You’ll just need to paste the code as-is in your plugin.

  2. Hanna Jones says:

    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!

  3. Arne Seemann says:

    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 :)

  4. Peter Verkooijen says:

    Doesn’t work in WordPress 3.0? Or am I doing something wrong…?

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>