How to Exclude WordPress Plugins From Updates

More often then we would like to admit, we are unwilling or unable to submit our WordPress plugins back to the repository for everyone to use.  But how do you exclude your plugin from WordPress updates?  As usual, the answer is with filters.  Check out the code below to see how.

1
2
3
4
5
6
7
8
9
10
11
function exclude_my_plugin( $r, $url ) {
      if ( 0 !== strpos( $url, 'http://api.wordpress.org/plugins/update-check' ) )
          return $r;
      $plugins = unserialize( $r['body']['plugins'] );
      unset( $plugins->plugins[ plugin_basename( __FILE__ ) ] );
      unset( $plugins->active[ array_search( plugin_basename( __FILE__ ), $plugins->active ) ] );
      $r['body']['plugins'] = serialize( $plugins );
      return $r;
}
 
add_filter( 'http_request_args', 'exclude_my_plugin', 5, 2);

Attribute:  This code is originally from a lead WordPress Developer, Mark Jaquith (thanks Mark!)

But how does this exclude your plugin from the update?  First, it takes the HTTP Request args and unserializes the [‘body’][‘plugins’] part of it.  From there, it’s as simple as unsetting your plugin from the array, then re-serializing the request args.  Also the first part checks to see if this is actually and update check.  If it’s not, you exit the function.

Author: Jack Slingerland

I’m a software engineer working and living in Raleigh, NC. I work in Python, Django, Node.js, React+Flux, AngularJS, and PHP. I like to work out with Kettlebells, run, and spend my free time with my wife, cat, and dog.

2 thoughts on “How to Exclude WordPress Plugins From Updates”

Comments are closed.