Prevent WordPress plugin updates for a specific plugin

Prevent Wordpress plugin updates with PHP code

Today I had to adapt a plugin in a customer's blog so that it optically matches the website and also has a German edition. Now the problem was that the customer was always busy making his updates in the WordPress admin.

In itself a praiseworthy thing, but when he imports the update for this plugin, all my adjustments in the programming are overwritten and gone. Of course, that shouldn't happen. But I'm realistic enough to know that a hint here doesn't stop anyone from doing future updates. For this reason, a solution has to be found here that is best not to display the update in the WP-Admin in the first place.

The "Disable All WordPress Updates" plugin prevents all updates - even those of the WordPress core.

The "Disable All WordPress Updates" plugin prevents all updates - even those of the WordPress core.

Solution 1: prevent all WordPress updates with a plugin

The first way you can choose here is the plugin "Disable All WordPress Updates", which can be found in the WordPress repository. It is, so to speak, the" cannon "with which we would shoot the" sparrow ", because actually we only want to prevent the updates of a plugin.

The "Disable All WordPress Updates" plugin does not only prevent all plugin updates, but also all installed themes and those of WordPress itself. In the long run, of course, this is a high security risk that I did not want to do to the customer.

Solution 2: only deactivate updates for specific plug-ins

In my case, the customer should still be allowed to run all plugins, but the one plugin that I adapted would have to be excluded from the updates. If there is a major update of the plugin at some point, I would import it manually and make the adjustments again. This will become important at some point so that the plugin can cope with larger version jumps of WordPress.

To test the code, I chose the "Ad Inserter" plugin, which had just displayed an update on my WordPress blog.

To test the code, I chose the "Ad Inserter" plugin, which had just displayed an update on my WordPress blog.

No change in the functions.php

Since the customer is also working on the theme here and there and may soon choose another theme, my plan was to exclude the solutions that work with a script in functions.php. When changing the theme, the functions.php is not automatically adopted and it is foreseeable that something will go wrong here. My plan was to put a few lines of code in the customized plugin so that it would no longer ask for and display updates.

I finally found what I was looking for in this thread from Stackoverflow, from which I got the following lines of code:

// Deactivate Update Feature of this plugin add_filter ('site_transient_update_plugins', 'remove_update_notification'); function remove_update_notification ($ value) {unset ($ value-> response [plugin_basename (__ FILE__)]); return $ value; }

These lines of code are copied into the main file of the plugin, which can usually be found in the folder "wp-content / plugins /" according to this scheme:

name-of-plugins / name-of-plugins.php

To test the code, I tried the "Ad-Inserter" plug-in, which was just about to get an update. In the screenshot you can see where I installed the code.

Here you can see the lines of code that I copied into the upper area of ​​the plugin code.

Here you can see the lines of code that I copied into the upper area of ​​the plugin code.

After installing it, I called up the list of plugins in the WordPress admin and lo and behold: The plugin no longer reports an available update (although there is one). So the thing works very reliably - tested with me up to WordPress 5.4.1.

After the code has been inserted, the plugin no longer shows an available update in the WordPress admin.

After the code has been inserted, the plugin no longer shows an available update in the WordPress admin.

My conclusion

The nice thing about the solution is that you can specifically exclude updates for certain plugins and you don't have to choose the "nuclear solution", which prevents all updates. If you want to hide the updates of several plugins, you copy the same code into the main file of each of these plugins.

What I particularly like about the code is the fact that you can copy and paste it straight away. With other solutions, you have to enter the file path and the name of the PHP file in the code in order for it to work. Here it was read out with the "plugin_basename" function, which is very convenient.

-
Do you like my blog? Then I would be happy to receive a short review on Google. Easy leave something here for a moment - that would be great, thank you!

 

Effectively for free: iPhone 13 Mini and iPhone 13 deals with top conditions at Otelo - Advertisement

Leave a Comment

Your e-mail address will not be published. Required fields are marked with * .