This repository has been archived by the owner on Jan 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisable-wp.org-api-requests.php
78 lines (61 loc) · 1.78 KB
/
disable-wp.org-api-requests.php
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/**
* Class Disable_WP_Org_Api_Requests
*
*/
class Disable_WP_Org_Api_Requests {
static function on_load() {
add_action( 'pre_http_request', [ __CLASS__, '_pre_http_request' ], 10, 3 );
add_action( 'plugins_api', [ __CLASS__, '_plugins_api' ], 10 );
add_action( 'plugins_api_result', [ __CLASS__, '_plugins_api_result' ], 10 );
}
/**
*
* @param false|object|array $result The result object or array. Default false.
* @return bool
*/
static function _plugins_api( $result ) {
return false;
}
/**
* @param object|WP_Error $res Response object or WP_Error.
* @return WP_Error
*/
static function _plugins_api_result( $response ) {
return new WP_Error();
}
static function _pre_http_request( $result, $request, $url ) {
do {
if ( 'https://api.wordpress.org/core/browse-happy/1.1/' === $url ) {
$result = new WP_Error();
break;
}
if ( 'https://api.wordpress.org/events/1.0/' === $url ) {
$result = new WP_Error();
break;
}
if ( 'https://api.wordpress.org/themes/info/1.0/' === $url ) {
$result = array( 'body' => [] );
break;
}
if ( 'https://api.wordpress.org/plugins/info/1.0/' === $url ) {
$result = array( 'body' => (object)array( 'plugins' => [] ) );
break;
}
if ( 'https://api.wordpress.org/plugins/update-check/1.1/' === $url ) {
$result = array( 'body' => '[]' );
break;
}
if ( preg_match( '#^' . preg_quote( 'https://api.wordpress.org/translations/' ) . '#', $url ) ) {
$result = array( 'body' => '[]' );
break;
}
if ( preg_match( '#^' . preg_quote( 'https://api.wordpress.org/core/version-check/1.7/' ) . '#', $url ) ) {
$result = array( 'body' => '0' );
break;
}
} while ( false );
return $result;
}
}
Disable_WP_Org_Api_Requests::on_load();