PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-beta
Jetpack – WP Security, Backup, Speed, & Growth v16.3-beta
16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 All 507 releases
← All changes | jetpack_vendor/automattic/jetpack-status/src/class-status.php +141 -73 12.5.2 → 16.3-beta View file →
@@ -17,20 +17,8 @@
17 17 * Used to retrieve information about the current status of Jetpack and the site overall.
18 18 */
19 19 class Status {
20 20 /**
21 - * Is Jetpack in development (offline) mode?
22 - *
23 - * @deprecated 1.3.0 Use Status->is_offline_mode().
24 - *
25 - * @return bool Whether Jetpack's offline mode is active.
26 - */
27 - public function is_development_mode() {
28 - _deprecated_function( __FUNCTION__, '1.3.0', 'Automattic\Jetpack\Status->is_offline_mode' );
29 - return $this->is_offline_mode();
30 - }
31 -
32 - /**
33 21 * Is Jetpack in offline mode?
34 22 *
35 23 * This was formerly called "Development Mode", but sites "in development" aren't always offline/localhost.
36 24 *
@@ -56,25 +44,10 @@
56 44
57 45 /**
58 46 * Filters Jetpack's offline mode.
59 47 *
60 - * @see https://jetpack.com/support/development-mode/
61 - * @todo Update documentation ^^.
48 + * @see https://jetpack.com/support/offline-mode/
62 49 *
63 - * @since 1.1.1
64 - * @since-jetpack 2.2.1
65 - * @deprecated 1.3.0
66 - *
67 - * @param bool $offline_mode Is Jetpack's offline mode active.
68 - */
69 - $offline_mode = (bool) apply_filters_deprecated( 'jetpack_development_mode', array( $offline_mode ), '1.3.0', 'jetpack_offline_mode' );
70 -
71 - /**
72 - * Filters Jetpack's offline mode.
73 - *
74 - * @see https://jetpack.com/support/development-mode/
75 - * @todo Update documentation ^^.
76 - *
77 50 * @since 1.3.0
78 51 *
79 52 * @param bool $offline_mode Is Jetpack's offline mode active.
80 53 */
@@ -79,28 +52,30 @@
79 52 * @param bool $offline_mode Is Jetpack's offline mode active.
80 53 */
81 54 $offline_mode = (bool) apply_filters( 'jetpack_offline_mode', $offline_mode );
82 55
56 + if ( ! $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 + }
71 + }
72 +
83 73 Cache::set( 'is_offline_mode', $offline_mode );
84 74 return $offline_mode;
85 75 }
86 76
87 77 /**
88 - * Is Jetpack in "No User test mode"?
89 - *
90 - * This will make Jetpack act as if there were no connected users, but only a site connection (aka blog token)
91 - *
92 - * @since 1.6.0
93 - * @deprecated 1.7.5 Since this version, Jetpack connection is considered active after registration, making no_user_testing_mode obsolete.
94 - *
95 - * @return bool Whether Jetpack's No User Testing Mode is active.
96 - */
97 - public function is_no_user_testing_mode() {
98 - _deprecated_function( __METHOD__, '1.7.5' );
99 - return true;
100 - }
101 -
102 - /**
103 78 * Whether this is a system with a multiple networks.
104 79 * Implemented since there is no core is_multi_network function.
105 80 * Right now there is no way to tell which network is the dominant network on the system.
106 81 *
@@ -163,33 +138,64 @@
163 138 if ( null !== $cached ) {
164 139 return $cached;
165 140 }
166 141
167 - $site_url = site_url();
142 + $site_url = trim( (string) site_url() );
168 143
169 - // Check for localhost and sites using an IP only first.
170 - $is_local = $site_url && false === strpos( $site_url, '.' );
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 + }
171 165
172 - // @todo Remove function_exists when the package has a documented minimum WP version.
173 - // Use Core's environment check, if available. Added in 5.5.0 / 5.5.1 (for `local` return value).
174 - if ( function_exists( 'wp_get_environment_type' ) && 'local' === wp_get_environment_type() ) {
166 + /*
167 + * Check for localhost and sites using an IP only first. No dot means it can't be a
168 + * public domain. Dotless IPv6 literals land here too, routable ones included:
169 + * WordPress.com won't register an IPv6 site URL, so offline mode is where they belong.
170 + * An IPv4-mapped literal like [::ffff:127.0.0.1] keeps its dots and reads as remote.
171 + */
172 + $is_local = '' !== $host && false === strpos( $host, '.' );
173 +
174 + // Use Core's environment check, if available.
175 + if ( 'local' === wp_get_environment_type() ) {
175 176 $is_local = true;
176 177 }
177 178
178 - // Then check for usual usual domains used by local dev tools.
179 + // Then check for usual domains used by local dev tools.
179 180 $known_local = array(
180 181 '#\.local$#i',
181 - '#\.localhost$#i',
182 + '#(^|\.)localhost$#i', // localhost and any subdomain of it.
182 183 '#\.test$#i',
183 - '#\.docksal$#i', // Docksal.
184 + '#\.docksal$#i', // Docksal.
184 185 '#\.docksal\.site$#i', // Docksal.
185 186 '#\.dev\.cc$#i', // ServerPress.
186 187 '#\.lndo\.site$#i', // Lando.
188 + '#\.ddev\.site$#i', // DDEV.
189 + // The whole 127.0.0.0/8 range is loopback; each octet is capped at 255.
190 + '#^127\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){2}$#',
191 + '#^0\.0\.0\.0$#', // All-interfaces bind, common under Docker and `wp server`.
192 + '#^playground\.wordpress\.net$#i', // WordPress Playground, which runs entirely in the browser.
187 193 );
188 194
189 - if ( ! $is_local ) {
190 - foreach ( $known_local as $url ) {
191 - if ( preg_match( $url, $site_url ) ) {
195 + if ( ! $is_local && '' !== $host ) {
196 + foreach ( $known_local as $pattern ) {
197 + if ( preg_match( $pattern, $host ) ) {
192 198 $is_local = true;
193 199 break;
194 200 }
195 201 }
@@ -210,36 +216,39 @@
210 216
211 217 /**
212 218 * If is a staging site.
213 219 *
214 - * @todo Add IDC detection to a package.
220 + * @deprecated since 3.3.0
215 221 *
216 222 * @return bool
217 223 */
218 224 public function is_staging_site() {
225 + _deprecated_function( __FUNCTION__, '3.3.0', 'in_safe_mode' );
219 226 $cached = Cache::get( 'is_staging_site' );
220 227 if ( null !== $cached ) {
221 228 return $cached;
222 229 }
223 230
224 - // @todo Remove function_exists when the package has a documented minimum WP version.
225 - // Core's wp_get_environment_type allows for a few specific options. We should default to bowing out gracefully for anything other than production or local.
226 - $is_staging = function_exists( 'wp_get_environment_type' ) && ! in_array( wp_get_environment_type(), array( 'production', 'local' ), true );
231 + /*
232 + * Core's wp_get_environment_type allows for a few specific options.
233 + * We should default to bowing out gracefully for anything other than production or local.
234 + */
235 + $is_staging = ! in_array( wp_get_environment_type(), array( 'production', 'local' ), true );
227 236
228 237 $known_staging = array(
229 238 'urls' => array(
230 - '#\.staging\.wpengine\.com$#i', // WP Engine. This is their legacy staging URL structure. Their new platform does not have a common URL. https://github.com/Automattic/jetpack/issues/21504
231 - '#\.staging\.kinsta\.com$#i', // Kinsta.com.
232 - '#\.kinsta\.cloud$#i', // Kinsta.com.
233 - '#\.stage\.site$#i', // DreamPress.
234 - '#\.newspackstaging\.com$#i', // Newspack.
235 - '#\.pantheonsite\.io$#i', // Pantheon.
236 - '#\.flywheelsites\.com$#i', // Flywheel.
237 - '#\.flywheelstaging\.com$#i', // Flywheel.
238 - '#\.cloudwaysapps\.com$#i', // Cloudways.
239 - '#\.azurewebsites\.net$#i', // Azure.
240 - '#\.wpserveur\.net$#i', // WPServeur.
241 - '#\-liquidwebsites\.com$#i', // Liquidweb.
239 + '#\.staging\.wpengine\.com$#i', // WP Engine. This is their legacy staging URL structure. Their new platform does not have a common URL. https://github.com/Automattic/jetpack/issues/21504
240 + '#\.staging\.kinsta\.com$#i', // Kinsta.com.
241 + '#\.kinsta\.cloud$#i', // Kinsta.com.
242 + '#\.stage\.site$#i', // DreamPress.
243 + '#\.newspackstaging\.com$#i', // Newspack.
244 + '#^(?!live-)([a-zA-Z0-9-]+)\.pantheonsite\.io$#i', // Pantheon.
245 + '#\.flywheelsites\.com$#i', // Flywheel.
246 + '#\.flywheelstaging\.com$#i', // Flywheel.
247 + '#\.cloudwaysapps\.com$#i', // Cloudways.
248 + '#\.azurewebsites\.net$#i', // Azure.
249 + '#\.wpserveur\.net$#i', // WPServeur.
250 + '#\-liquidwebsites\.com$#i', // Liquidweb.
242 251 ),
243 252 'constants' => array(
244 253 'IS_WPE_SNAPSHOT', // WP Engine. This is used on their legacy staging environment. Their new platform does not have a constant. https://github.com/Automattic/jetpack/issues/21504
245 254 'KINSTA_DEV_ENV', // Kinsta.com.
@@ -299,13 +308,73 @@
299 308 return $is_staging;
300 309 }
301 310
302 311 /**
312 + * If the site is in safe mode.
313 + *
314 + * @since 3.3.0
315 + *
316 + * @return bool
317 + */
318 + public function in_safe_mode() {
319 + $cached = Cache::get( 'in_safe_mode' );
320 + if ( null !== $cached ) {
321 + return $cached;
322 + }
323 + $in_safe_mode = false;
324 + if ( method_exists( 'Automattic\\Jetpack\\Identity_Crisis', 'validate_sync_error_idc_option' ) && \Automattic\Jetpack\Identity_Crisis::validate_sync_error_idc_option() ) {
325 + $in_safe_mode = true;
326 + }
327 + /**
328 + * Filters in_safe_mode check.
329 + *
330 + * @since 3.3.0
331 + *
332 + * @param bool $in_safe_mode If the current site is in safe mode.
333 + */
334 + $in_safe_mode = apply_filters( 'jetpack_is_in_safe_mode', $in_safe_mode );
335 +
336 + Cache::set( 'in_safe_mode', $in_safe_mode );
337 + return $in_safe_mode;
338 + }
339 +
340 + /**
341 + * If the site is a development/staging site.
342 + * This is a new version of is_staging_site added to separate safe mode from the legacy staging mode.
343 + * This method checks for core WP_ENVIRONMENT_TYPE setting
344 + * Using the jetpack_is_development_site filter.
345 + *
346 + * @since 3.3.0
347 + *
348 + * @return bool
349 + */
350 + public static function is_development_site() {
351 + $cached = Cache::get( 'is_development_site' );
352 + if ( null !== $cached ) {
353 + return $cached;
354 + }
355 + $is_dev_site = ! in_array( wp_get_environment_type(), array( 'production', 'local' ), true );
356 + /**
357 + * Filters is_development_site check.
358 + *
359 + * @since 3.3.0
360 + *
361 + * @param bool $is_dev_site If the current site is a staging or dev site.
362 + */
363 + $is_dev_site = apply_filters( 'jetpack_is_development_site', $is_dev_site );
364 +
365 + Cache::set( 'is_development_site', $is_dev_site );
366 + return $is_dev_site;
367 + }
368 +
369 + /**
303 370 * Whether the site is currently onboarding or not.
304 371 * A site is considered as being onboarded if it currently has an onboarding token.
305 372 *
306 373 * @since-jetpack 5.8
307 374 *
375 + * @deprecated since 4.0.0
376 + *
308 377 * @access public
309 378 * @static
310 379 *
311 380 * @return bool True if the site is currently onboarding, false otherwise
@@ -352,9 +421,9 @@
352 421 */
353 422 public function is_coming_soon() {
354 423 $ret = Cache::get( 'is_coming_soon' );
355 424 if ( null === $ret ) {
356 - $is_coming_soon = (bool) ( function_exists( 'site_is_coming_soon' ) && \site_is_coming_soon() )
425 + $is_coming_soon = ( function_exists( 'site_is_coming_soon' ) && \site_is_coming_soon() )
357 426 || get_option( 'wpcom_public_coming_soon' );
358 427
359 428 /**
360 429 * Filters the is_coming_soon check.
@@ -408,6 +477,5 @@
408 477 $url = str_replace( '/', '::', $url );
409 478
410 479 return rtrim( $url, ':' );
411 480 }
412 -
413 481 }