Disable updating of WordPress plugin or theme

There could be multiple reasons for disabling updates of plugin or a theme. For example, in time constraint, you have reached for desperate measures and edited the source of a third party plugin or theme. Now, that is the practice that is bad on so many levels, but sometimes you just have to deliver in time, no matter what.

Anyway, you have done the unimaginable and edited the code of the third party plug-in or theme. And, of course, you don’t have time to make up with another solution later, and any update to that theme or plugin would overwrite your changes. It would be pretty neat if you could somehow disable updates of that part of your website.

Another situation when it would be suitable to do something like this is when you create custom plugin and/or there for the client and don’t want to send additional requests to WordPress servers.

Mark Jaquith provides an efficient piece of code to prevent this, both for plugins and themes in his post: Excluding your plugin or theme from update checks

I just added a few lines to this code which are used to check if HTTPS protocol is used.

Use this code for a theme (put in functions.php):

function my_hidden_theme_12345( $r, $url ) {
  
  $update_url = $http_url = 'http://api.wordpress.org/themes/update-check/1.1/';
	if ( $ssl = wp_http_supports( array( 'ssl' ) ) )
		$update_url = set_url_scheme( $update_url, 'https' );
  
    if ( 0 !== strpos( $url, $update_url ) )
        return $r; // Not a theme update request. Bail immediately.
 
    $themes = unserialize( $r['body']['themes'] );
    unset( $themes[ get_option( 'template' ) ] );
    unset( $themes[ get_option( 'stylesheet' ) ] );
    $r['body']['themes'] = serialize( $themes );
    return $r;
}
 
add_filter( 'http_request_args', 'my_hidden_theme_12345', 5, 2 );

And this code for plugins:

function my_hidden_plugin_12345( $r, $url ) {
    $update_url = $http_url = 'http://api.wordpress.org/themes/update-check/1.1/';
	if ( $ssl = wp_http_supports( array( 'ssl' ) ) )
		$update_url = set_url_scheme( $update_url, 'https' );

    if ( 0 !== strpos( $url, $update_url ) )
        return $r; // Not a plugin update request. Bail immediately.
  
    $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', 'my_hidden_plugin_12345', 5, 2 );

Recent Posts

Sonata Admin: modify validation groups in an admin extension

SonataAdminBundle has a powerful extensions feature which allows you to add or change features of…

4 years ago

Grandfather’s advices

I used to spend a lot of time with my grandparents in my childhood. My…

5 years ago

World. World never stops changing.

If anything is certain in this world, it is that things always change. And there…

5 years ago

How to be successful

This is the most important advice on how to be successful! Read it carefully!

8 years ago

I wanted to change WordPress URL, you won’t believe what happened afterwards

WordPress has a nasty habit of storing absolute URLs in the database. That means that…

9 years ago

Let’s Encrypt – providing free automated SSL certificates

In August 2014 Google announced that their search engine will value HTTPS as a ranking…

9 years ago