-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathblock-http-requests.php
More file actions
45 lines (41 loc) · 1.21 KB
/
block-http-requests.php
File metadata and controls
45 lines (41 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
/**
* Plugin Name: Block HTTP Requests to a list of URLs
* Description: This plugin blocks HTTP requests to specific URLs, such as the WP Ultimo update server.
* Version: 0.1.0
* Author: Jordan
* Author URI: https://managingwp.io/
* Type: snippet
* Status: Complete
**/
// Define the list of URL patterns to block
$blocked_urls = [
'https://versions.nextpress.co/updates/',
'https://api.wpultimo.com/',
'https://licensing.example.com/',
// Add more URLs to block as needed
];
add_filter('pre_http_request', function($pre, $r, $url) use ($blocked_urls) {
$is_blocked = false;
// Check if the URL matches any of the blocked patterns
foreach ($blocked_urls as $blocked_pattern) {
if (strpos($url, $blocked_pattern) === 0) {
$is_blocked = true;
break;
}
}
if (!$is_blocked) {
//error_log("Good API: $url");
return $pre;
} else {
// Block the request
error_log("Blocked API: $url");
return [
'headers' => [],
'body' => '',
'response' => ['code' => 201, 'message' => 'OK'],
'cookies' => [],
'filename' => null,
];
}
}, 10, 3);