Prevent updating a WordPress Plugin

add_filter( 'site_transient_update_plugins', 'my_filter_plugin_updates' );
function my_filter_plugin_updates( $value ) {
    unset( $value->response['wp-responsive-menu/wp-responsive-menu.php'] );
    return $value;
}Code language: PHP (php)

Another method for multiple plugin entries:

add_filter( 'http_request_args', 'wp_prevent_plugin_update_check', 10, 2 );
function wp_prevent_plugin_update_check( $r, $url ) {
    $parse_url =  parse_url( $url );
    $host      = isset( $parse_url['host'] ) ? $parse_url['host'] : '';
    $path      = isset( $parse_url['path'] ) ? $parse_url['path'] : '';

    if ( $host == 'api.wordpress.org' && $path == '/plugins/update-check/1.1/' )
    {
        $plugins = json_decode($r['body']['plugins'], true);
        $update_blocked_plugins  = array('plugin_folder/plugin_main_file.php');

        foreach ($update_blocked_plugins as $update_blocked_plugin)
        {
            if (array_key_exists($update_blocked_plugin, $plugins['plugins']))
            {
                unset($plugins['plugins'][$update_blocked_plugin]);
            }
        }

        $r['body']['plugins'] = json_encode( $plugins );
    }

    return $r;
}Code language: PHP (php)

Posted

in

,

by

Tags:

Comments

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.