← All changes
|
jetpack_vendor/automattic/jetpack-status/src/class-host.php
+31
-110
13.7.2
→
16.3-beta
View file →
| @@ -78,8 +78,36 @@ | ||
| 78 | 78 | return $this->is_wpcom_simple() || $this->is_woa_site(); |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
| 82 | + * Determine if this is a P2 site. | |
| 83 | + * This covers both P2 and P2020 themes. | |
| 84 | + * | |
| 85 | + * @return bool | |
| 86 | + */ | |
| 87 | + public function is_p2_site() { | |
| 88 | + $site_id = $this->get_wpcom_site_id(); | |
| 89 | + if ( ! $site_id ) { | |
| 90 | + return false; | |
| 91 | + } | |
| 92 | + return str_contains( get_stylesheet(), 'pub/p2' ) || ( function_exists( '\WPForTeams\is_wpforteams_site' ) && \WPForTeams\is_wpforteams_site( $site_id ) ); | |
| 93 | + } | |
| 94 | + | |
| 95 | + /** | |
| 96 | + * Get the current site's WordPress.com ID. | |
| 97 | + * | |
| 98 | + * @return mixed The site's WordPress.com ID. | |
| 99 | + */ | |
| 100 | + public function get_wpcom_site_id() { | |
| 101 | + if ( $this->is_wpcom_simple() ) { | |
| 102 | + return get_current_blog_id(); | |
| 103 | + } elseif ( class_exists( 'Jetpack' ) && \Jetpack::is_connection_ready() ) { | |
| 104 | + return \Jetpack_Options::get_option( 'id' ); | |
| 105 | + } | |
| 106 | + return false; | |
| 107 | + } | |
| 108 | + | |
| 109 | + /** | |
| 82 | 110 | * Add all wordpress.com environments to the safe redirect allowed list. |
| 83 | 111 | * |
| 84 | 112 | * To be used with a filter of allowed domains for a redirect. |
| 85 | 113 | * |
| @@ -135,116 +163,16 @@ | ||
| 135 | 163 | return ''; |
| 136 | 164 | } |
| 137 | 165 | |
| 138 | 166 | /** |
| 139 | - * Returns an array of nameservers for the current site. | |
| 167 | + * Returns a guess of the hosting provider for the current site based on various checks. | |
| 140 | 168 | * |
| 141 | - * @param string $domain The domain of the site to check. | |
| 142 | - * @return array | |
| 143 | - */ | |
| 144 | - public function get_nameserver_dns_records( $domain ) { | |
| 145 | - if ( ! function_exists( 'dns_get_record' ) ) { | |
| 146 | - return array(); | |
| 147 | - } | |
| 148 | - | |
| 149 | - $dns_records = dns_get_record( $domain, DNS_NS ); // Fetches the DNS records of type NS (Name Server) | |
| 150 | - $nameservers = array(); | |
| 151 | - foreach ( $dns_records as $record ) { | |
| 152 | - if ( isset( $record['target'] ) ) { | |
| 153 | - $nameservers[] = $record['target']; // Adds the nameserver to the array | |
| 154 | - } | |
| 155 | - } | |
| 156 | - | |
| 157 | - return $nameservers; // Returns an array of nameserver names | |
| 158 | - } | |
| 159 | - | |
| 160 | - /** | |
| 161 | - * Given a DNS entry, will return a hosting provider if one can be determined. Otherwise, will return 'unknown'. | |
| 162 | - * Sourced from: fbhepr%2Skers%2Sjcpbz%2Sjc%2Qpbagrag%2Syvo%2Subfgvat%2Qcebivqre%2Sanzrfreiref.cuc-og | |
| 169 | + * @since 5.0.4 Added $guess parameter. | |
| 170 | + * @since 6.0.0 Removed $guess parameter. | |
| 163 | 171 | * |
| 164 | - * @param string $domain The domain of the site to check. | |
| 165 | - * @return string The hosting provider of 'unknown'. | |
| 166 | - */ | |
| 167 | - public function get_hosting_provider_by_nameserver( $domain ) { | |
| 168 | - $known_nameservers = array( | |
| 169 | - 'bluehost' => array( | |
| 170 | - '.bluehost.com', | |
| 171 | - ), | |
| 172 | - 'dreamhost' => array( | |
| 173 | - '.dreamhost.com', | |
| 174 | - ), | |
| 175 | - 'mediatemple' => array( | |
| 176 | - '.mediatemple.net', | |
| 177 | - ), | |
| 178 | - 'xserver' => array( | |
| 179 | - '.xserver.jp', | |
| 180 | - ), | |
| 181 | - 'namecheap' => array( | |
| 182 | - '.namecheaphosting.com', | |
| 183 | - ), | |
| 184 | - 'hostmonster' => array( | |
| 185 | - '.hostmonster.com', | |
| 186 | - ), | |
| 187 | - 'justhost' => array( | |
| 188 | - '.justhost.com', | |
| 189 | - ), | |
| 190 | - 'digitalocean' => array( | |
| 191 | - '.digitalocean.com', | |
| 192 | - ), | |
| 193 | - 'one' => array( | |
| 194 | - '.one.com', | |
| 195 | - ), | |
| 196 | - 'hostpapa' => array( | |
| 197 | - '.hostpapa.com', | |
| 198 | - ), | |
| 199 | - 'siteground' => array( | |
| 200 | - '.sgcloud.net', | |
| 201 | - '.sgedu.site', | |
| 202 | - '.sgsrv1.com', | |
| 203 | - '.sgvps.net', | |
| 204 | - '.siteground.biz', | |
| 205 | - '.siteground.net', | |
| 206 | - '.siteground.eu', | |
| 207 | - ), | |
| 208 | - 'inmotion' => array( | |
| 209 | - '.inmotionhosting.com', | |
| 210 | - ), | |
| 211 | - 'ionos' => array( | |
| 212 | - '.ui-dns.org', | |
| 213 | - '.ui-dns.de', | |
| 214 | - '.ui-dns.biz', | |
| 215 | - '.ui-dns.com', | |
| 216 | - ), | |
| 217 | - ); | |
| 218 | - | |
| 219 | - $dns_records = $this->get_nameserver_dns_records( $domain ); | |
| 220 | - $dns_records = array_map( 'strtolower', $dns_records ); | |
| 221 | - | |
| 222 | - foreach ( $known_nameservers as $host => $ns_patterns ) { | |
| 223 | - foreach ( $ns_patterns as $ns_pattern ) { | |
| 224 | - foreach ( $dns_records as $record ) { | |
| 225 | - if ( false !== strpos( $record, $ns_pattern ) ) { | |
| 226 | - return $host; | |
| 227 | - } | |
| 228 | - } | |
| 229 | - } | |
| 230 | - } | |
| 231 | - | |
| 232 | - return 'unknown'; | |
| 233 | - } | |
| 234 | - | |
| 235 | - /** | |
| 236 | - * Returns a guess of the hosting provider for the current site based on various checks. | |
| 237 | - * | |
| 238 | 172 | * @return string |
| 239 | 173 | */ |
| 240 | 174 | public function get_known_host_guess() { |
| 241 | - $host = Cache::get( 'host_guess' ); | |
| 242 | - | |
| 243 | - if ( null !== $host ) { | |
| 244 | - return $host; | |
| 245 | - } | |
| 246 | - | |
| 247 | 175 | // First, let's check if we can recognize provider manually: |
| 248 | 176 | switch ( true ) { |
| 249 | 177 | case $this->is_woa_site(): |
| 250 | 178 | $provider = 'woa'; |
| @@ -266,15 +194,8 @@ | ||
| 266 | 194 | $provider = 'unknown'; |
| 267 | 195 | break; |
| 268 | 196 | } |
| 269 | 197 | |
| 270 | - // Second, let's check if we can recognize provider by nameservers: | |
| 271 | - $domain = isset( $_SERVER['SERVER_NAME'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_NAME'] ) ) : ''; | |
| 272 | - if ( $provider === 'unknown' && ! empty( $domain ) ) { | |
| 273 | - $provider = $this->get_hosting_provider_by_nameserver( $domain ); | |
| 274 | - } | |
| 275 | - | |
| 276 | - Cache::set( 'host_guess', $provider ); | |
| 277 | 198 | return $provider; |
| 278 | 199 | } |
| 279 | 200 | |
| 280 | 201 | /** |