Skip to content

Instantly share code, notes, and snippets.

@webdados
Last active October 11, 2024 12:08
Show Gist options
  • Save webdados/0eabe2246e6113f164e825a6b1431754 to your computer and use it in GitHub Desktop.
Save webdados/0eabe2246e6113f164e825a6b1431754 to your computer and use it in GitHub Desktop.
Remove 3rd party plugin from WordPress.org updates checks
<?php
/**
* Remove this plugin from the wp.org update requests by shortcircuiting the HTTP request
* This function should be placed on the plugin main file and namespaced accordingly
* Unfortunately, this will only work if the plugin is active
*
* @param array $parsed_args An array of HTTP request arguments.
* @param string $url The request URL.
*/
function namespace_this_remove_plugin_from_wporg_updates( $parsed_args, $url ) {
$plugin_basename = plugin_basename( __FILE__ );
if ( strpos( $url, 'api.wordpress.org/plugins/update-check' ) === false ) {
// Not a plugin update request. Bail immediately.
return $parsed_args;
} elseif ( isset( $parsed_args['body']['plugins'] ) ) {
$plugins = json_decode( $parsed_args['body']['plugins'] );
if ( isset( $plugins->plugins->$plugin_basename ) ) {
// Remove our plugin
unset( $plugins->plugins->$plugin_basename );
// No need to check if isset because this code would not run if the plugin isn't active
unset( $plugins->active[ array_search( $plugin_basename, $plugins->active ) ] );
// Rebuild arguments
$parsed_args['body']['plugins'] = wp_json_encode( $plugins );
}
}
return $parsed_args;
}
add_filter( 'http_request_args', array( $this, 'namespace_this_remove_plugin_from_wporg_updates' ), 5, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment