Skip to content

Instantly share code, notes, and snippets.

@mrcave
Created May 17, 2024 15:44
Show Gist options
  • Save mrcave/265c5bcf9b7a751600380e9a189b9955 to your computer and use it in GitHub Desktop.
Save mrcave/265c5bcf9b7a751600380e9a189b9955 to your computer and use it in GitHub Desktop.
Block requests to WP Ultimo's licensing servers
<?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