Created
May 17, 2024 15:44
-
-
Save mrcave/265c5bcf9b7a751600380e9a189b9955 to your computer and use it in GitHub Desktop.
Block requests to WP Ultimo's licensing servers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// WP Ultimo's licensing servers have gone offline and are causing | |
// customer networks to have long load times or error out completely. | |
// Blocking the requests to Ultimo's servers resolves this issue. | |
// | |
// H/T Calvin Alkan for suggesting http request filtering as a possible solution | |
add_filter('pre_http_request', 'block_ultimo_http_requests', 10, 3); | |
function block_ultimo_http_requests($preempt, $parsed_args, $url) { | |
// Define the domains to block | |
$blocked_domains = [ | |
'wpultimo.com', | |
'nextpress.co', | |
'nextpress.us' | |
]; | |
// Parse the URL to get the host | |
$parsed_url = wp_parse_url($url, PHP_URL_HOST); | |
// Check if the host contains any of the blocked domains | |
foreach ($blocked_domains as $domain) { | |
// Check if the blocked domain string is present in the parsed URL's host | |
// Note that a more robust regex would be preferrable to simple strpos check | |
if (strpos($parsed_url, $domain) !== false) { | |
// Block the request by returning a WP_Error | |
return new WP_Error('blocked_url', 'Blocked URL: ' . $url); | |
} | |
} | |
return $preempt; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment