php - Block plugin update possibilities (but not by hiding notifications)

admin2025-04-18  0

Is it possible to block specific plugins from updating, manually too? I don't want to block this by hiding the notification, changing the plugin version or anything like this. I'd like the notification to show, show the new version number, but when hitting the update manually it should block/disallow this - preferably displaying some sort of (cusomized) notification in the plugin section (eg. "Update for this plugin is not possible").

Is it possible to block specific plugins from updating, manually too? I don't want to block this by hiding the notification, changing the plugin version or anything like this. I'd like the notification to show, show the new version number, but when hitting the update manually it should block/disallow this - preferably displaying some sort of (cusomized) notification in the plugin section (eg. "Update for this plugin is not possible").

Share Improve this question asked Nov 26, 2019 at 12:24 Chris OsiakChris Osiak 117 bronze badges 3
  • if it's a free plugin of wordpress, you juste have to rename the directory name of the plugin. – Kaperto Commented Nov 26, 2019 at 12:38
  • I was more looking into commercial plugins. – Chris Osiak Commented Nov 26, 2019 at 15:26
  • there is a lot of different way to update a commercial plugin then you have to read the code of the plugin to find how to stop the update. – Kaperto Commented Nov 26, 2019 at 18:01
Add a comment  | 

2 Answers 2

Reset to default 0

Try this:

add_filter( 'http_request_args', 'dm_prevent_update_check', 10, 2 );
function dm_prevent_update_check( $r, $url ) {
    if ( 0 === strpos( $url, 'http://api.wordpress/plugins/update-check/' ) ) {
        $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;
}

Credits: https://stackoverflow/questions/17897044/wordpress-how-to-disable-plugin-update

Assuming you are still planning on updating plugins yourself but don't want other users to be able to do it, according to wp-admin/update.php you can revoke the 'update_plugins' permission from a user to prevent this. They will get a wp_die message 'Sorry, you are not allowed to update plugins for this site.'

For permissions management you can use User Role Editor or similar.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1744965370a277167.html

最新回复(0)