← All changes
|
jetpack_vendor/automattic/jetpack-status/src/class-status.php
+46
-11
3.3.6
→
3.3.8
View file →
| @@ -53,9 +53,22 @@ | ||
| 53 | 53 | */ |
| 54 | 54 | $offline_mode = (bool) apply_filters( 'jetpack_offline_mode', $offline_mode ); |
| 55 | 55 | |
| 56 | 56 | if ( ! $offline_mode ) { |
| 57 | - $offline_mode = (bool) get_option( 'jetpack_offline_mode' ); | |
| 57 | + // Sentinel default so an absent option isn't confused with a stored null/false. | |
| 58 | + $sentinel = new \stdClass(); | |
| 59 | + $option = get_option( 'jetpack_offline_mode', $sentinel ); | |
| 60 | + | |
| 61 | + if ( $sentinel === $option ) { | |
| 62 | + // Seed an autoloaded default to stop per-request reads, but only where it helps | |
| 63 | + // (no persistent object cache) and writes are safe (keep front-end reads read-only). | |
| 64 | + if ( ! wp_using_ext_object_cache() && ( is_admin() || wp_doing_cron() || ( defined( 'WP_CLI' ) && WP_CLI ) ) ) { | |
| 65 | + add_option( 'jetpack_offline_mode', false, '', true ); | |
| 66 | + } | |
| 67 | + } else { | |
| 68 | + // A default_option filter could return a non-scalar; only a scalar is a real value. | |
| 69 | + $offline_mode = is_scalar( $option ) ? (bool) $option : false; | |
| 70 | + } | |
| 58 | 71 | } |
| 59 | 72 | |
| 60 | 73 | Cache::set( 'is_offline_mode', $offline_mode ); |
| 61 | 74 | return $offline_mode; |
| @@ -125,13 +138,34 @@ | ||
| 125 | 138 | if ( null !== $cached ) { |
| 126 | 139 | return $cached; |
| 127 | 140 | } |
| 128 | 141 | |
| 129 | - $site_url = site_url(); | |
| 142 | + $site_url = trim( (string) site_url() ); | |
| 130 | 143 | |
| 144 | + /* | |
| 145 | + * Every check below cares about the host, not the rest of the URL. Matching the host | |
| 146 | + * alone means a port, a subdirectory install, or a trailing slash can't defeat them, | |
| 147 | + * and a known local domain sitting in the path can't trigger them by accident. | |
| 148 | + */ | |
| 149 | + $host = wp_parse_url( $site_url, PHP_URL_HOST ); | |
| 150 | + if ( ( ! is_string( $host ) || '' === $host ) && ! preg_match( '#^[a-z][a-z0-9+.\-]*:#i', $site_url ) ) { | |
| 151 | + /* | |
| 152 | + * No scheme, so site_url() isn't absolute. Read the value as a bare host. | |
| 153 | + * A value that does carry a scheme but still won't parse is malformed, and | |
| 154 | + * guessing at it would read "https:/example.com" as the host "https". | |
| 155 | + */ | |
| 156 | + $host = wp_parse_url( '//' . ltrim( $site_url, '/' ), PHP_URL_HOST ); | |
| 157 | + } | |
| 158 | + if ( ! is_string( $host ) ) { | |
| 159 | + /* | |
| 160 | + * Nothing host-shaped to test. Treat the site as remote rather than matching the | |
| 161 | + * raw URL: a false "local" silently drops a live site into offline mode. | |
| 162 | + */ | |
| 163 | + $host = ''; | |
| 164 | + } | |
| 165 | + | |
| 131 | 166 | // Check for localhost and sites using an IP only first. |
| 132 | - // Note: str_contains() is not used here, as wp-includes/compat.php is not loaded in this file. | |
| 133 | - $is_local = $site_url && false === strpos( $site_url, '.' ); | |
| 167 | + $is_local = '' !== $host && false === strpos( $host, '.' ); | |
| 134 | 168 | |
| 135 | 169 | // Use Core's environment check, if available. |
| 136 | 170 | if ( 'local' === wp_get_environment_type() ) { |
| 137 | 171 | $is_local = true; |
| @@ -136,24 +170,25 @@ | ||
| 136 | 170 | if ( 'local' === wp_get_environment_type() ) { |
| 137 | 171 | $is_local = true; |
| 138 | 172 | } |
| 139 | 173 | |
| 140 | - // Then check for usual usual domains used by local dev tools. | |
| 174 | + // Then check for usual domains used by local dev tools. | |
| 141 | 175 | $known_local = array( |
| 142 | 176 | '#\.local$#i', |
| 143 | - '#\.localhost$#i', | |
| 177 | + '#(^|\.)localhost$#i', // localhost and any subdomain of it. | |
| 144 | 178 | '#\.test$#i', |
| 145 | - '#\.docksal$#i', // Docksal. | |
| 179 | + '#\.docksal$#i', // Docksal. | |
| 146 | 180 | '#\.docksal\.site$#i', // Docksal. |
| 147 | 181 | '#\.dev\.cc$#i', // ServerPress. |
| 148 | 182 | '#\.lndo\.site$#i', // Lando. |
| 149 | 183 | '#\.ddev\.site$#i', // DDEV. |
| 150 | - '#^https?://127\.0\.0\.1$#', | |
| 184 | + '#^127\.0\.0\.1$#', | |
| 185 | + '#^playground\.wordpress\.net$#i', // WordPress Playground, which runs entirely in the browser. | |
| 151 | 186 | ); |
| 152 | 187 | |
| 153 | - if ( ! $is_local ) { | |
| 154 | - foreach ( $known_local as $url ) { | |
| 155 | - if ( preg_match( $url, $site_url ) ) { | |
| 188 | + if ( ! $is_local && '' !== $host ) { | |
| 189 | + foreach ( $known_local as $pattern ) { | |
| 190 | + if ( preg_match( $pattern, $host ) ) { | |
| 156 | 191 | $is_local = true; |
| 157 | 192 | break; |
| 158 | 193 | } |
| 159 | 194 | } |