Skip to content

Commit 8c78623

Browse files
committed
Release 1.4.5
Added block-http-requests.php
1 parent 89682aa commit 8c78623

File tree

5 files changed

+62
-1
lines changed

5 files changed

+62
-1
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
# Changelog
2+
## mend
3+
4+
5+
## Release 1.4.5
6+
* Added block-http-requests.php
7+
8+
29
## Release 1.4.4
310
* Added disable-wp-rocket-preload.php
411

README-snippets.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
| Title | Version | Type | Status | Description |
4444
| ----- | ------- | ---- | ------ | ----------- |
45+
| [Block HTTP Requests to a list of URLs](./core/block-http-requests.php) | 0.1.0 | * Type: snippet | :white_check_mark: | This plugin blocks HTTP requests to specific URLs, such as the WP Ultimo update server. |
4546
| [enable-core-updates-version-control.php](./core/enable-core-updates-version-control.php) | 1.0.0 | Plugin | :white_check_mark: | Filters whether the automatic updater should consider a filesystem location to be potentially managed by a version control system. |
4647

4748
## [debug](debug)

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ The status field is used to indicate the current status of the snippet. This is
5656

5757
| Title | Version | Type | Status | Description |
5858
| ----- | ------- | ---- | ------ | ----------- |
59+
| [Block HTTP Requests to a list of URLs](./core/block-http-requests.php) | 0.1.0 | * Type: snippet | :white_check_mark: | This plugin blocks HTTP requests to specific URLs, such as the WP Ultimo update server. |
5960
| [enable-core-updates-version-control.php](./core/enable-core-updates-version-control.php) | 1.0.0 | Plugin | :white_check_mark: | Filters whether the automatic updater should consider a filesystem location to be potentially managed by a version control system. |
6061

6162
## [debug](debug)
@@ -142,6 +143,13 @@ The status field is used to indicate the current status of the snippet. This is
142143
| [Failover Status Monitor](./wp-failover/wp-failover.php) | 1.0.0 | Plugin | :white_check_mark: | Monitors failover status and provides notifications. |
143144

144145
# Changelog
146+
## mend
147+
148+
149+
## Release 1.4.5
150+
* Added block-http-requests.php
151+
152+
145153
## Release 1.4.4
146154
* Added disable-wp-rocket-preload.php
147155

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.4.4
1+
1.4.5

core/block-http-requests.php

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

0 commit comments

Comments
 (0)