Friday, 30 September 2011

How to prevent update checks for installed plug-ins in wordpress?

Plug-in is the one which is used to add some additional functionality to the blog. We have many free plug-in in the repository to extend the functionality.

If we get any plug-in, for our requirement we can use it directly or else we will customize the plug-in according to our requirements.

Each time the wordpress will check for the updates in the repository by using the function wp_update_plugins( ) in wp_includes/update.php. If there is any new version available we will get a notification at wordpress plugin dashboard.

If anyone clicks on update the plug-in will be updated to latest version, then the changes what we done will be lost and again we have to update the customizations. There is no hook to avoid this problem.

I faced this problem for one of my website. Each time, when the notification comes for the plug-in my client will update it.

To avoid this problem I added the following code to the plug-in for which I want to exclude from update check.

add_filter( 'http_request_args', 'prevent_update_check', 10, 2 );
function  prevent_update_check( $r, $url ) {
    if ( 0 === strpos( $url, '' ) ) {
        $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;

No comments:

Post a Comment