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

By Aleksandar Jakovljević

My name is Aleksandar Jakovljević and I am a web developer from Belgrade, Serbia. I was born in Smederevo, in 1980. I started focusing on web development since late 2003. I am mostly focused on open source web technologies. I specialised in PHP, focusing on Symfony framework, with skills in Drupal and WordPress, too. I worked more than 7 years for art_net studio and 10 years for Computer Rock (former Spoiled Milk). Now I am working on developing industry leading subscription management system as a part of Plenigo team since August 2021. I love the web and everything related to it. The possibility to publish your ideas quickly and make them available to the entire world is what made me decide to pursue a career in web development.

Follow on: Twitter | GitHub | LinkedIn | Facebook | Instagram

Hire me on Upwork

Leave a comment

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


The reCAPTCHA verification period has expired. Please reload the page.