HostResolver.php
2.45 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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
namespace WP_Rocket\ThirdParty\Hostings;
/**
* Host Resolver.
*
* @since 3.6.3
*/
class HostResolver {
/**
* Name of the current host service.
*
* @var string
*/
private static $hostname = '';
/**
* Get the name of an identifiable hosting service.
*
* @since 3.6.3
*
* @param bool $ignore_cached_hostname (optional) Don't use cached hostname when true.
*
* @return string Name of the hosting service or '' if no service is recognized.
*/
public static function get_host_service( $ignore_cached_hostname = false ) {
if ( ! $ignore_cached_hostname && ! empty( self::$hostname ) ) {
return self::$hostname;
}
if ( isset( $_SERVER['cw_allowed_ip'] ) ) {
self::$hostname = 'cloudways';
return 'cloudways';
}
if ( rocket_get_constant( 'IS_PRESSABLE' ) ) {
self::$hostname = 'pressable';
return 'pressable';
}
if ( getenv( 'SPINUPWP_CACHE_PATH' ) ) {
self::$hostname = 'spinupwp';
return 'spinupwp';
}
if (
(
class_exists( 'WpeCommon' )
&&
function_exists( 'wpe_param' )
)
) {
self::$hostname = 'wpengine';
return 'wpengine';
}
if ( rocket_has_constant( 'O2SWITCH_VARNISH_PURGE_KEY' ) ) {
self::$hostname = 'o2switch';
return 'o2switch';
}
if ( rocket_get_constant( 'WPCOMSH_VERSION' ) ) {
self::$hostname = 'wordpresscom';
return 'wordpresscom';
}
if (
rocket_get_constant( '\Savvii\CacheFlusherPlugin::NAME_FLUSH_NOW' )
&&
rocket_get_constant( '\Savvii\CacheFlusherPlugin::NAME_DOMAINFLUSH_NOW' )
) {
return 'savvii';
}
if ( self::is_dreampress() ) {
return 'dreampress';
}
if ( isset( $_SERVER['HTTP_WPXCLOUD'] ) ) {
self::$hostname = 'wpxcloud';
return 'wpxcloud';
}
if ( isset( $_SERVER['X-LSCACHE'] ) ) {
self::$hostname = 'litespeed';
return 'litespeed';
}
if ( class_exists( '\WPaas\Plugin' ) ) {
self::$hostname = 'godaddy';
return 'godaddy';
}
if ( isset( $_SERVER['KINSTA_CACHE_ZONE'] ) ) {
self::$hostname = 'kinsta';
return 'kinsta';
}
return '';
}
/**
* Checks if the current host is DreamPress
*
* @since 3.7.2
*
* @return boolean
*/
private static function is_dreampress() {
if ( ! isset( $_SERVER['DH_USER'] ) ) {
return false;
}
if (
! rocket_get_constant( 'WP_ROCKET_IS_TESTING', false )
&&
'dp-' !== substr( gethostname(), 0, 3 )
) {
return false;
}
return 'wp_' === substr( sanitize_key( wp_unslash( $_SERVER['DH_USER'] ) ), 0, 3 );
}
}