Disabling updates for a specific WordPress plugin can be done by utilizing the site_transient_update_plugins
filter. The idea is to intercept the information about available plugin updates and remove the specific plugin from the update list.
Here’s an example of how you can disable updates for particular WordPress plugins:
function disable_plugin_updates( $value ) { // List of plugins to be excluded from updates $plugins_not_updatable = [ 'plugin-folder/plugin-file.php', 'another-plugin-folder/another-plugin-file.php' ]; if ( isset( $value->response ) && is_array( $value->response ) ) { foreach ( $plugins_not_updatable as $plugin ) { if ( isset( $value->response[ $plugin ] ) ) { unset( $value->response[ $plugin ] ); } } } return $value; } add_filter( 'site_transient_update_plugins', 'disable_plugin_updates' );
Let’s break down the code step by step:
function disable_plugin_updates( $value ) { // List of plugins to be excluded from updates $plugins_not_updatable = [ 'plugin-folder/plugin-file.php', 'another-plugin-folder/another-plugin-file.php' ];
- The function
disable_plugin_updates
is defined, and it takes one parameter,$value
. This parameter represents the data about available plugin updates. - An array called
$plugins_not_updatable
is created, containing the file paths of the plugins you want to exclude from updates. Each element in the array is a string composed of the plugin folder and main file (e.g., ‘plugin-folder/plugin-file.php’).if ( isset( $value->response ) && is_array( $value->response ) ) {
- The code checks if the
$value
object has a property named ‘response’ and if the ‘response’ property is an array. This is done to ensure that the update information is available and in the expected format.
- The code checks if the
-
foreach ( $plugins_not_updatable as $plugin ) { if ( isset( $value->response[ $plugin ] ) ) { unset( $value->response[ $plugin ] ); } }
- If the conditions are met, the code enters a loop that iterates over each plugin in the
$plugins_not_updatable
array.
- If the conditions are met, the code enters a loop that iterates over each plugin in the
For each plugin, it checks if there is an entry for that plugin in the ‘response’ property of the $value
object. If such an entry exists, it is removed using unset()
. This essentially excludes the plugin from the list of available updates.
return $value; } add_filter( 'site_transient_update_plugins', 'disable_plugin_updates' );
- Finally, the modified
$value
object is returned. This is necessary for the changes to take effect. - The
add_filter
function is used to hook thedisable_plugin_updates
function into thesite_transient_update_plugins
filter. This ensures that the function is called when WordPress checks for plugin updates.
In summary, this code intercepts the information about available plugin updates, checks if the updates correspond to specific plugins in the exclusion list, and removes them from the update list. This way, you can prevent certain plugins from being updated automatically by WordPress.
Make sure to replace the plugin file paths in the $plugins_not_updatable
array with the actual paths of the plugins you want to exclude.
Insert this code into your theme’s functions.php
file or preferably in a custom plugin file. Keep in mind that manually disabling updates for plugins means you will be responsible for ensuring the security and compatibility of those plugins. If a plugin has a security update, it’s generally recommended to update it to the latest version to maintain the security of your WordPress site.