Skip to content

Instantly share code, notes, and snippets.

@erfan-ilyas
Created October 6, 2022 14:39
Show Gist options
  • Save erfan-ilyas/49f56934cb94f5801e562f8c69f37130 to your computer and use it in GitHub Desktop.
Save erfan-ilyas/49f56934cb94f5801e562f8c69f37130 to your computer and use it in GitHub Desktop.
WP pre_http_request filter to disable selected premium plugins update check.
<?php
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
add_action( 'admin_init', function(){
add_filter( 'pre_http_request', 'july2122522_pre_http_request', 999, 3 );
function july2122522_pre_http_request( $preempt, $parsed_args, $url ){
// Split the URL into useful parts.
$url_data = parse_url( $url );
#1
$hostCheck = 'api.wordpress.org';
if( $url_data['host'] == $hostCheck ){
if( isset($url_data['path']) && $url_data['path'] == '/plugins/update-check/1.1/' ){
return new WP_Error( 'http_request_block', 'disabled '.$hostCheck.' using mu-plugin: filter-http-api.php' );
}
if( isset($url_data['path']) && $url_data['path'] == '/themes/update-check/1.1/' ){
return new WP_Error( 'http_request_block', 'disabled '.$hostCheck.' using mu-plugin: filter-http-api.php' );
}
if( isset($url_data['path']) && $url_data['path'] == '/core/version-check/1.7/' ){
return new WP_Error( 'http_request_block', 'disabled '.$hostCheck.' using mu-plugin: filter-http-api.php' );
}
if( isset($url_data['path']) && $url_data['path'] == '/core/browse-happy/1.1/' ){
return new WP_Error( 'http_request_block', 'disabled '.$hostCheck.' using mu-plugin: filter-http-api.php' );
}
if( isset($url_data['path']) && $url_data['path'] == '/core/serve-happy/1.0/' ){
return new WP_Error( 'http_request_block', 'disabled '.$hostCheck.' using mu-plugin: filter-http-api.php' );
}
if( isset($url_data['path']) && $url_data['path'] == '/translations/core/1.0/' ){
return new WP_Error( 'http_request_block', 'disabled '.$hostCheck.' using mu-plugin: filter-http-api.php' );
}
}
//following is custom for myperformance.app network
#2
$hostCheck = 'update.buddyboss.com';
if( $url_data['host'] == $hostCheck ){
if( isset($parsed_args['body']['action']) && $parsed_args['body']['action'] == 'update_check' ){
return new WP_Error( 'http_request_block', 'disabled '.$hostCheck.' using mu-plugin: filter-http-api.php' );
}
if( isset($parsed_args['body']['action']) && $parsed_args['body']['action'] == 'theme_update' ){
return new WP_Error( 'http_request_block', 'disabled '.$hostCheck.' using mu-plugin: filter-http-api.php' );
}
}
#3
$hostCheck = 'bitbucket.org';
if( $url_data['host'] == $hostCheck ){
if( isset($url_data['path']) && $url_data['path'] == '/learndash/learndash-add-ons/get/stable.zip' ){
return new WP_Error( 'http_request_block', 'disabled '.$hostCheck.' using mu-plugin: filter-http-api.php' );
}
}
#4
$hostCheck = 'support.learndash.com';
if( $url_data['host'] == $hostCheck ){
if( isset($parsed_args['body']['action']) && $parsed_args['body']['action'] == 'info' ){
return new WP_Error( 'http_request_block', 'disabled '.$hostCheck.' using mu-plugin: filter-http-api.php' );
}
}
#5
$hostCheck = 'api.github.com';
if( $url_data['host'] == $hostCheck ){
if( isset($url_data['path']) ){
if( strpos($url_data['path'], '/repos/buddyboss/buddyboss-platform/releases/tags/') !== false) {
return new WP_Error( 'http_request_block', 'disabled '.$hostCheck.' using mu-plugin: filter-http-api.php' );
}
}
}
#6
$hostCheck = 'api.wpdeveloper.com';
if( $url_data['host'] == $hostCheck ){
if( isset($parsed_args['body']['edd_action']) && $parsed_args['body']['edd_action'] == 'get_version' ){
return new WP_Error( 'http_request_block', 'disabled '.$hostCheck.' using mu-plugin: filter-http-api.php' );
}
if( isset($parsed_args['body']['edd_action']) && $parsed_args['body']['edd_action'] == 'check_license' ){
return new WP_Error( 'http_request_block', 'disabled '.$hostCheck.' using mu-plugin: filter-http-api.php' );
}
}
#7
$hostCheck = 'www.uncannyowl.com';
if( $url_data['host'] == $hostCheck ){
if( isset($parsed_args['body']['edd_action']) && $parsed_args['body']['edd_action'] == 'get_version' ){
return new WP_Error( 'http_request_block', 'disabled '.$hostCheck.' using mu-plugin: filter-http-api.php' );
}
}
$debugLog = array( 'url'=>$url_data );
if( isset($parsed_args['body']) ){
$debugLog['body'] = $parsed_args['body'];
}else{
$debugLog['body'] = 'body not found';
}
do_action( 'qm/debug', $debugLog );
return $preempt;
}
});
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment