Completed
Push — fusion-sync/danroundhill/r2061... ( 6c7cf7...0f1caf )
by Jeremy
213:37 queued 206:26
created

Jetpack_Cxn_Tests::increase_timeout()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Collection of tests to run on the Jetpack connection locally.
4
 *
5
 * @package Jetpack
6
 */
7
8
use Automattic\Jetpack\Connection\Client;
9
use Automattic\Jetpack\Status;
10
use Automattic\Jetpack\Connection\Utils as Connection_Utils;
11
use Automattic\Jetpack\Sync\Modules;
12
use Automattic\Jetpack\Sync\Settings as Sync_Settings;
13
use Automattic\Jetpack\Sync\Health as Sync_Health;
14
use Automattic\Jetpack\Sync\Sender as Sync_Sender;
15
use Automattic\Jetpack\Redirect;
16
17
/**
18
 * Class Jetpack_Cxn_Tests contains all of the actual tests.
19
 */
20
class Jetpack_Cxn_Tests extends Jetpack_Cxn_Test_Base {
21
22
	/**
23
	 * Jetpack_Cxn_Tests constructor.
24
	 */
25
	public function __construct() {
26
		parent::__construct();
27
28
		$methods = get_class_methods( 'Jetpack_Cxn_Tests' );
29
30
		foreach ( $methods as $method ) {
31
			if ( false === strpos( $method, 'test__' ) ) {
32
				continue;
33
			}
34
			$this->add_test( array( $this, $method ), $method, 'direct' );
35
		}
36
37
		/**
38
		 * Fires after loading default Jetpack Connection tests.
39
		 *
40
		 * @since 7.1.0
41
		 * @since 8.3.0 Passes the Jetpack_Cxn_Tests instance.
42
		 */
43
		do_action( 'jetpack_connection_tests_loaded', $this );
44
45
		/**
46
		 * Determines if the WP.com testing suite should be included.
47
		 *
48
		 * @since 7.1.0
49
		 * @since 8.1.0 Default false.
50
		 *
51
		 * @param bool $run_test To run the WP.com testing suite. Default false.
52
		 */
53
		if ( apply_filters( 'jetpack_debugger_run_self_test', false ) ) {
54
			/**
55
			 * Intentionally added last as it checks for an existing failure state before attempting.
56
			 * Generally, any failed location condition would result in the WP.com check to fail too, so
57
			 * we will skip it to avoid confusing error messages.
58
			 *
59
			 * Note: This really should be an 'async' test.
60
			 */
61
			$this->add_test( array( $this, 'last__wpcom_self_test' ), 'test__wpcom_self_test', 'direct' );
62
		}
63
	}
64
65
	/**
66
	 * Helper function to look up the expected master user and return the local WP_User.
67
	 *
68
	 * @return WP_User Jetpack's expected master user.
69
	 */
70
	protected function helper_retrieve_local_master_user() {
71
		$master_user = Jetpack_Options::get_option( 'master_user' );
72
		return new WP_User( $master_user );
73
	}
74
75
	/**
76
	 * Is Jetpack even connected and supposed to be talking to WP.com?
77
	 */
78
	protected function helper_is_jetpack_connected() {
79
		return ( Jetpack::is_active() && ! ( new Status() )->is_development_mode() );
80
	}
81
82
	/**
83
	 * Returns a support url based on development mode.
84
	 */
85
	protected function helper_get_support_url() {
86
		return Jetpack::is_development_version()
87
			? Redirect::get_url( 'jetpack-contact-support-beta-group' )
88
			: Redirect::get_url( 'jetpack-contact-support' );
89
	}
90
91
	/**
92
	 * Gets translated support text.
93
	 */
94
	protected function helper_get_support_text() {
95
		return __( 'Please contact Jetpack support.', 'jetpack' );
96
	}
97
98
	/**
99
	 * Gets translated text to enable outbound requests.
100
	 *
101
	 * @param string $protocol Either 'HTTP' or 'HTTPS'.
102
	 *
103
	 * @return string The translated text.
104
	 */
105
	protected function helper_enable_outbound_requests( $protocol ) {
106
		return sprintf(
107
			/* translators: %1$s - request protocol, either http or https */
108
			__(
109
				'Your server did not successfully connect to the Jetpack server using %1$s
110
				Please ask your hosting provider to confirm your server can make outbound requests to jetpack.com.',
111
				'jetpack'
112
			),
113
			$protocol
114
		);
115
	}
116
117
	/**
118
	 * Returns 30 for use with a filter.
119
	 *
120
	 * To allow time for WP.com to run upstream testing, this function exists to increase the http_request_timeout value
121
	 * to 30.
122
	 *
123
	 * @return int 30
124
	 */
125
	public static function increase_timeout() {
126
		return 30; // seconds.
127
	}
128
129
	/**
130
	 * Test if Jetpack is connected.
131
	 */
132
	protected function test__check_if_connected() {
133
		$name = __FUNCTION__;
134
		if ( $this->helper_is_jetpack_connected() ) {
135
			$result = self::passing_test(
136
				array(
137
					'name'             => $name,
138
					'label'            => __( 'Your site is connected to Jetpack', 'jetpack' ),
139
					'long_description' => sprintf(
140
						'<p>%1$s</p>' .
141
						'<p><span class="dashicons pass"><span class="screen-reader-text">%2$s</span></span> %3$s</p>',
142
						__( 'A healthy connection ensures Jetpack essential services are provided to your WordPress site, such as Stats and Site Security.', 'jetpack' ),
143
						/* translators: Screen reader text indicating a test has passed */
144
						__( 'Passed', 'jetpack' ),
145
						__( 'Your site is connected to Jetpack.', 'jetpack' )
146
					),
147
				)
148
			);
149
		} elseif ( ( new Status() )->is_development_mode() ) {
150
			$result = self::skipped_test(
151
				array(
152
					'name'              => $name,
153
					'short_description' => __( 'Jetpack is in Development Mode:', 'jetpack' ) . ' ' . Jetpack::development_mode_trigger_text(),
154
				)
155
			);
156
		} else {
157
			$result = self::failing_test(
158
				array(
159
					'name'             => $name,
160
					'label'            => __( 'Your site is not connected to Jetpack', 'jetpack' ),
161
					'action'           => admin_url( 'admin.php?page=jetpack#/dashboard' ),
162
					'action_label'     => __( 'Reconnect your site now', 'jetpack' ),
163
					'long_description' => sprintf(
164
						'<p>%1$s</p>' .
165
						'<p><span class="dashicons fail"><span class="screen-reader-text">%2$s</span></span> %3$s<strong> %4$s</strong></p>',
166
						__( 'A healthy connection ensures Jetpack essential services are provided to your WordPress site, such as Stats and Site Security.', 'jetpack' ),
167
						/* translators: screen reader text indicating a test failed */
168
						__( 'Error', 'jetpack' ),
169
						__( 'Your site is not connected to Jetpack.', 'jetpack' ),
170
						__( 'We recommend reconnecting Jetpack.', 'jetpack' )
171
					),
172
				)
173
			);
174
		}
175
176
		return $result;
177
	}
178
179
	/**
180
	 * Test that the master user still exists on this site.
181
	 *
182
	 * @return array Test results.
183
	 */
184
	protected function test__master_user_exists_on_site() {
185
		$name = __FUNCTION__;
186 View Code Duplication
		if ( ! $this->helper_is_jetpack_connected() ) {
187
			return self::skipped_test(
188
				array(
189
					'name'              => $name,
190
					'short_description' => __( 'Jetpack is not connected. No master user to check.', 'jetpack' ),
191
				)
192
			);
193
		}
194
		$local_user = $this->helper_retrieve_local_master_user();
195
196
		if ( $local_user->exists() ) {
197
			$result = self::passing_test( array( 'name' => $name ) );
198 View Code Duplication
		} else {
199
			$result = self::failing_test(
200
				array(
201
					'name'              => $name,
202
					'short_description' => __( 'The user who setup the Jetpack connection no longer exists on this site.', 'jetpack' ),
203
					'action_label'      => __( 'Please disconnect and reconnect Jetpack.', 'jetpack' ),
204
					'action'            => Redirect::get_url( 'jetpack-support-reconnecting-reinstalling-jetpack' ),
205
				)
206
			);
207
		}
208
209
		return $result;
210
	}
211
212
	/**
213
	 * Test that the master user has the manage options capability (e.g. is an admin).
214
	 *
215
	 * Generic calls from WP.com execute on Jetpack as the master user. If it isn't an admin, random things will fail.
216
	 *
217
	 * @return array Test results.
218
	 */
219
	protected function test__master_user_can_manage_options() {
220
		$name = __FUNCTION__;
221 View Code Duplication
		if ( ! $this->helper_is_jetpack_connected() ) {
222
			return self::skipped_test(
223
				array(
224
					'name'              => $name,
225
					'short_description' => __( 'Jetpack is not connected.', 'jetpack' ),
226
				)
227
			);
228
		}
229
		$master_user = $this->helper_retrieve_local_master_user();
230
231
		if ( user_can( $master_user, 'manage_options' ) ) {
232
			$result = self::passing_test( array( 'name' => $name ) );
233 View Code Duplication
		} else {
234
			$result = self::failing_test(
235
				array(
236
					'name'              => $name,
237
					/* translators: a WordPress username */
238
					'short_description' => sprintf( __( 'The user (%s) who setup the Jetpack connection is not an administrator.', 'jetpack' ), $master_user->user_login ),
239
					'action_label'      => __( 'Either upgrade the user or disconnect and reconnect Jetpack.', 'jetpack' ),
240
					'action'            => Redirect::get_url( 'jetpack-support-reconnecting-reinstalling-jetpack' ),
241
				)
242
			);
243
		}
244
245
		return $result;
246
	}
247
248
	/**
249
	 * Test that the PHP's XML library is installed.
250
	 *
251
	 * While it should be installed by default, increasingly in PHP 7, some OSes require an additional php-xml package.
252
	 *
253
	 * @return array Test results.
254
	 */
255
	protected function test__xml_parser_available() {
256
		$name = __FUNCTION__;
257
		if ( function_exists( 'xml_parser_create' ) ) {
258
			$result = self::passing_test( array( 'name' => $name ) );
259
		} else {
260
			$result = self::failing_test(
261
				array(
262
					'name'              => $name,
263
					'label'             => __( 'PHP XML manipulation libraries are not available.', 'jetpack' ),
264
					'short_description' => __( 'Please ask your hosting provider to refer to our server requirements and enable PHP\'s XML module.', 'jetpack' ),
265
					'action_label'      => __( 'View our server requirements', 'jetpack' ),
266
					'action'            => Redirect::get_url( 'jetpack-support-server-requirements' ),
267
				)
268
			);
269
		}
270
		return $result;
271
	}
272
273
	/**
274
	 * Test that the server is able to send an outbound http communication.
275
	 *
276
	 * @return array Test results.
277
	 */
278 View Code Duplication
	protected function test__outbound_http() {
279
		$name    = __FUNCTION__;
280
		$request = wp_remote_get( preg_replace( '/^https:/', 'http:', JETPACK__API_BASE ) . 'test/1/' );
281
		$code    = wp_remote_retrieve_response_code( $request );
282
283
		if ( 200 === intval( $code ) ) {
284
			$result = self::passing_test( array( 'name' => $name ) );
285
		} else {
286
			$result = self::failing_test(
287
				array(
288
					'name'              => $name,
289
					'short_description' => $this->helper_enable_outbound_requests( 'HTTP' ),
290
				)
291
			);
292
		}
293
294
		return $result;
295
	}
296
297
	/**
298
	 * Test that the server is able to send an outbound https communication.
299
	 *
300
	 * @return array Test results.
301
	 */
302 View Code Duplication
	protected function test__outbound_https() {
303
		$name    = __FUNCTION__;
304
		$request = wp_remote_get( preg_replace( '/^http:/', 'https:', JETPACK__API_BASE ) . 'test/1/' );
305
		$code    = wp_remote_retrieve_response_code( $request );
306
307
		if ( 200 === intval( $code ) ) {
308
			$result = self::passing_test( array( 'name' => $name ) );
309
		} else {
310
			$result = self::failing_test(
311
				array(
312
					'name'              => $name,
313
					'short_description' => $this->helper_enable_outbound_requests( 'HTTPS' ),
314
				)
315
			);
316
		}
317
318
		return $result;
319
	}
320
321
	/**
322
	 * Check for an IDC.
323
	 *
324
	 * @return array Test results.
325
	 */
326
	protected function test__identity_crisis() {
327
		$name = __FUNCTION__;
328 View Code Duplication
		if ( ! $this->helper_is_jetpack_connected() ) {
329
			return self::skipped_test(
330
				array(
331
					'name'              => $name,
332
					'short_description' => __( 'Jetpack is not connected.', 'jetpack' ),
333
				)
334
			);
335
		}
336
		$identity_crisis = Jetpack::check_identity_crisis();
337
338
		if ( ! $identity_crisis ) {
339
			$result = self::passing_test( array( 'name' => $name ) );
340
		} else {
341
			$result = self::failing_test(
342
				array(
343
					'name'              => $name,
344
					'short_description' => sprintf(
345
						/* translators: Two URLs. The first is the locally-recorded value, the second is the value as recorded on WP.com. */
346
						__( 'Your url is set as `%1$s`, but your WordPress.com connection lists it as `%2$s`!', 'jetpack' ),
347
						$identity_crisis['home'],
348
						$identity_crisis['wpcom_home']
349
					),
350
					'action_label'      => $this->helper_get_support_text(),
351
					'action'            => $this->helper_get_support_url(),
352
				)
353
			);
354
		}
355
		return $result;
356
	}
357
358
	/**
359
	 * Tests connection status against wp.com's test-connection endpoint.
360
	 *
361
	 * @todo: Compare with the wpcom_self_test. We only need one of these.
362
	 *
363
	 * @return array Test results.
364
	 */
365
	protected function test__wpcom_connection_test() {
366
		$name = __FUNCTION__;
367
368
		$status = new Status();
369 View Code Duplication
		if ( ! Jetpack::is_active() || $status->is_development_mode() || $status->is_staging_site() || ! $this->pass ) {
370
			return self::skipped_test( array( 'name' => $name ) );
371
		}
372
373
		add_filter( 'http_request_timeout', array( 'Jetpack_Cxn_Tests', 'increase_timeout' ) );
374
		$response = Client::wpcom_json_api_request_as_blog(
375
			sprintf( '/jetpack-blogs/%d/test-connection', Jetpack_Options::get_option( 'id' ) ),
376
			Client::WPCOM_JSON_API_VERSION
377
		);
378
		remove_filter( 'http_request_timeout', array( 'Jetpack_Cxn_Tests', 'increase_timeout' ) );
379
380 View Code Duplication
		if ( is_wp_error( $response ) ) {
381
			return self::failing_test(
382
				array(
383
					'name'              => $name,
384
					/* translators: %1$s is the error code, %2$s is the error message */
385
					'short_description' => sprintf( __( 'Connection test failed (#%1$s: %2$s)', 'jetpack' ), $response->get_error_code(), $response->get_error_message() ),
0 ignored issues
show
Bug introduced by
The method get_error_code() does not seem to exist on object<WP_Error>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method get_error_message() does not seem to exist on object<WP_Error>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
386
					'action_label'      => $this->helper_get_support_text(),
387
					'action'            => $this->helper_get_support_url(),
388
				)
389
			);
390
		}
391
392
		$body = wp_remote_retrieve_body( $response );
393 View Code Duplication
		if ( ! $body ) {
394
			return self::failing_test(
395
				array(
396
					'name'              => $name,
397
					'short_description' => __( 'Connection test failed (empty response body)', 'jetpack' ) . wp_remote_retrieve_response_code( $response ),
398
					'action_label'      => $this->helper_get_support_text(),
399
					'action'            => $this->helper_get_support_url(),
400
				)
401
			);
402
		}
403
404 View Code Duplication
		if ( 404 === wp_remote_retrieve_response_code( $response ) ) {
405
			return self::skipped_test(
406
				array(
407
					'name'              => $name,
408
					'short_description' => __( 'The WordPress.com API returned a 404 error.', 'jetpack' ),
409
				)
410
			);
411
		}
412
413
		$result       = json_decode( $body );
414
		$is_connected = (bool) $result->connected;
415
		$message      = $result->message . ': ' . wp_remote_retrieve_response_code( $response );
416
417
		if ( $is_connected ) {
418
			return self::passing_test( array( 'name' => $name ) );
419
		} else {
420
			return self::failing_test(
421
				array(
422
					'name'              => $name,
423
					'short_description' => $message,
424
					'action_label'      => $this->helper_get_support_text(),
425
					'action'            => $this->helper_get_support_url(),
426
				)
427
			);
428
		}
429
	}
430
431
	/**
432
	 * Tests the port number to ensure it is an expected value.
433
	 *
434
	 * We expect that sites on be on one of:
435
	 * port 80,
436
	 * port 443 (https sites only),
437
	 * the value of JETPACK_SIGNATURE__HTTP_PORT,
438
	 * unless the site is intentionally on a different port (e.g. example.com:8080 is the site's URL).
439
	 *
440
	 * If the value isn't one of those and the site's URL doesn't include a port, then the signature verification will fail.
441
	 *
442
	 * This happens most commonly on sites with reverse proxies, so the edge (e.g. Varnish) is running on 80/443, but nginx
443
	 * or Apache is responding internally on a different port (e.g. 81).
444
	 *
445
	 * @return array Test results
446
	 */
447
	protected function test__server_port_value() {
448
		$name = __FUNCTION__;
449
		if ( ! isset( $_SERVER['HTTP_X_FORWARDED_PORT'] ) && ! isset( $_SERVER['SERVER_PORT'] ) ) {
450
			return self::skipped_test(
451
				array(
452
					'name'              => $name,
453
					'short_description' => __( 'The server port values are not defined. This is most common when running PHP via a CLI.', 'jetpack' ),
454
				)
455
			);
456
		}
457
		$site_port   = wp_parse_url( home_url(), PHP_URL_PORT );
0 ignored issues
show
Unused Code introduced by
The call to wp_parse_url() has too many arguments starting with PHP_URL_PORT.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
458
		$server_port = isset( $_SERVER['HTTP_X_FORWARDED_PORT'] ) ? (int) $_SERVER['HTTP_X_FORWARDED_PORT'] : (int) $_SERVER['SERVER_PORT'];
459
		$http_ports  = array( 80 );
460
		$https_ports = array( 80, 443 );
461
462
		if ( defined( 'JETPACK_SIGNATURE__HTTP_PORT' ) ) {
463
			$http_ports[] = JETPACK_SIGNATURE__HTTP_PORT;
464
		}
465
466
		if ( defined( 'JETPACK_SIGNATURE__HTTPS_PORT' ) ) {
467
			$https_ports[] = JETPACK_SIGNATURE__HTTPS_PORT;
468
		}
469
470
		if ( $site_port ) {
471
			return self::skipped_test( array( 'name' => $name ) ); // Not currently testing for this situation.
472
		}
473
474
		if ( is_ssl() && in_array( $server_port, $https_ports, true ) ) {
475
			return self::passing_test( array( 'name' => $name ) );
476
		} elseif ( in_array( $server_port, $http_ports, true ) ) {
477
			return self::passing_test( array( 'name' => $name ) );
478
		} else {
479
			if ( is_ssl() ) {
480
				$needed_constant = 'JETPACK_SIGNATURE__HTTPS_PORT';
481
			} else {
482
				$needed_constant = 'JETPACK_SIGNATURE__HTTP_PORT';
483
			}
484
			return self::failing_test(
485
				array(
486
					'name'              => $name,
487
					'short_description' => sprintf(
488
						/* translators: %1$s - a PHP code snippet */
489
						__(
490
							'The server port value is unexpected.
491
						Try adding the following to your wp-config.php file: %1$s',
492
							'jetpack'
493
						),
494
						"define( '$needed_constant', $server_port )"
495
					),
496
				)
497
			);
498
		}
499
	}
500
501
	/**
502
	 * Sync Health Tests.
503
	 *
504
	 * Disabled: Results in a failing test (recommended)
505
	 * In Progress: Results in failing test (recommended)
506
	 * Delayed: Results in failing test (recommended)
507
	 * Error: Results in failing test (critical)
508
	 */
509
	protected function test__sync_health() {
510
511
		$name = __FUNCTION__;
512
513
		if ( ! $this->helper_is_jetpack_connected() ) {
514
			// If the site is not connected, there is no point in testing Sync health.
515
			return self::skipped_test(
516
				array(
517
					'name'                => $name,
518
					'show_in_site_health' => false,
519
				)
520
			);
521
		}
522
523
		// Sync is enabled.
524
		if ( Sync_Settings::is_sync_enabled() ) {
525
526
			// Get Full Sync Progress.
527
			$full_sync_module = Modules::get_module( 'full-sync' );
528
			$progress_percent = $full_sync_module ? $full_sync_module->get_sync_progress_percentage() : null;
529
530
			// Full Sync in Progress.
531
			if ( $progress_percent ) {
532
533
				return self::failing_test(
534
					array(
535
						'name'              => $name,
536
						'label'             => __( 'Jetpack is performing a sync of your site', 'jetpack' ),
537
						'severity'          => 'recommended',
538
						'short_description' => __( 'Jetpack is performing a sync of your site', 'jetpack' ),
539
						'long_description'  => sprintf(
540
							'<p>%1$s</p>' .
541
							'<p><span class="dashicons dashicons-update"><span class="screen-reader-text">%2$s</span></span> %3$s</p>' .
542
							'<div class="jetpack-sync-progress-ui"><div class="jetpack-sync-progress-label"></div><div class="jetpack-sync-progress-bar"></div></div>',
543
							__( 'The information synced by Jetpack ensures that Jetpack Search, Related Posts and other features are aligned with your site’s current content.', 'jetpack' ),
544
							/* translators: screen reader text indicating data is updating. */
545
							__( 'Updating', 'jetpack' ),
546
							__( 'Jetpack is currently performing a full sync of your site data.', 'jetpack' )
547
						),
548
					)
549
				);
550
551
			} elseif ( Sync_Health::get_status() === Sync_Health::STATUS_OUT_OF_SYNC ) {
552
				/*
553
				 * Sync has experienced Data Loss.
554
				 */
555
556
				$description  = '<p>';
557
				$description .= esc_html__( 'The information synced by Jetpack ensures that Jetpack Search, Related Posts and other features are aligned with your site’s current content.', 'jetpack' );
558
				$description .= '</p>';
559
				$description .= '<p>';
560
				$description .= sprintf(
561
					'<span class="dashicons fail"><span class="screen-reader-text">%1$s</span></span> ',
562
					esc_html__( 'Error', 'jetpack' )
563
				);
564
				$description .= wp_kses(
565
					__( 'Jetpack has detected an error while syncing your site. <strong>We recommend <a id="full_sync_request_link" href="#">a full sync</a> to align Jetpack with your site data.</strong>', 'jetpack' ),
566
					array(
567
						'a'      => array(
568
							'id'   => array(),
569
							'href' => array(),
570
						),
571
						'strong' => array(),
572
					)
573
				);
574
				$description .= '</p>';
575
576
				return self::failing_test(
577
					array(
578
						'name'              => $name,
579
						'label'             => __( 'Jetpack has detected an error syncing your site.', 'jetpack' ),
580
						'severity'          => 'critical',
581
						'action'            => Redirect::get_url( 'jetpack-contact-support' ),
582
						'action_label'      => __( 'Contact Jetpack Support', 'jetpack' ),
583
						'short_description' => __( 'Jetpack has detected an error syncing your site.', 'jetpack' ),
584
						'long_description'  => $description,
585
					)
586
				);
587
588
			} else {
589
				// Get the Sync Queue.
590
				$sender     = Sync_Sender::get_instance();
591
				$sync_queue = $sender->get_sync_queue();
592
593
				// lag exceeds 5 minutes.
594
				if ( $sync_queue->lag() > 5 * MINUTE_IN_SECONDS ) {
595
596
					$description  = '<p>';
597
					$description .= esc_html__( 'The information synced by Jetpack ensures that Jetpack Search, Related Posts and other features are aligned with your site’s current content.', 'jetpack' );
598
					$description .= '</p>';
599
					$description .= '<p>';
600
					$description .= sprintf(
601
						'<span class="dashicons dashicons-clock" style="color: orange;"><span class="screen-reader-text">%1$s</span></span> ',
602
						/* translators: name, used to describe a clock icon. */
603
						esc_html__( 'Clock', 'jetpack' )
604
					);
605
					$description .= wp_kses(
606
						sprintf(
607
							/* translators: placeholder is a number of minutes. */
608
							_n(
609
								'Jetpack has identified a delay while syncing individual content updates. Certain features might be slower than usual, but this is only temporary while sync catches up with recent changes to your site. <strong>We’re seeing a current delay of %1$d minute.</strong>',
610
								'Jetpack has identified a delay while syncing individual content updates. Certain features might be slower than usual, but this is only temporary while sync catches up with recent changes to your site. <strong>We’re seeing a current delay of %1$d minutes.</strong>',
611
								intval( $sync_queue->lag() / MINUTE_IN_SECONDS ),
612
								'jetpack'
613
							),
614
							number_format_i18n( $sync_queue->lag() / MINUTE_IN_SECONDS )
615
						),
616
						array( 'strong' => array() )
617
					);
618
					$description .= '</p>';
619
620
					return self::failing_test(
621
						array(
622
							'name'              => $name,
623
							'label'             => __( 'Jetpack is experiencing a delay syncing your site.', 'jetpack' ),
624
							'severity'          => 'recommended',
625
							'action'            => null,
626
							'action_label'      => null,
627
							'short_description' => __( 'Jetpack is experiencing a delay syncing your site.', 'jetpack' ),
628
							'long_description'  => $description,
629
						)
630
					);
631
632
				} else {
633
634
					// Sync is Healthy.
635
					return self::skipped_test( array( 'name' => $name ) );
636
637
				}
638
			}
639
		} else {
640
			/*
641
			 * Sync is disabled.
642
			 */
643
644
			$description  = '<p>';
645
			$description .= esc_html__( 'The information synced by Jetpack ensures that Jetpack Search, Related Posts and other features are aligned with your site’s current content.', 'jetpack' );
646
			$description .= '</p>';
647
			$description .= '<p>';
648
			$description .= __( 'Developers may enable / disable syncing using the Sync Settings API.', 'jetpack' );
649
			$description .= '</p>';
650
			$description .= '<p>';
651
			$description .= sprintf(
652
				'<span class="dashicons fail"><span class="screen-reader-text">%1$s</span></span> ',
653
				esc_html__( 'Error', 'jetpack' )
654
			);
655
			$description .= wp_kses(
656
				__( 'Jetpack Sync has been disabled on your site. Without it, certain Jetpack features will not work. <strong>We recommend enabling Sync.</strong>', 'jetpack' ),
657
				array( 'strong' => array() )
658
			);
659
			$description .= '</p>';
660
661
			return self::failing_test(
662
				array(
663
					'name'              => $name,
664
					'label'             => __( 'Jetpack Sync has been disabled on your site.', 'jetpack' ),
665
					'severity'          => 'recommended',
666
					'action'            => 'https://github.com/Automattic/jetpack/blob/master/packages/sync/src/class-settings.php',
667
					'action_label'      => __( 'See Github for more on Sync Settings', 'jetpack' ),
668
					'short_description' => __( 'Jetpack Sync has been disabled on your site.', 'jetpack' ),
669
					'long_description'  => $description,
670
				)
671
			);
672
673
		}
674
675
	}
676
677
	/**
678
	 * Calls to WP.com to run the connection diagnostic testing suite.
679
	 *
680
	 * Intentionally added last as it will be skipped if any local failed conditions exist.
681
	 *
682
	 * @since 7.1.0
683
	 * @since 7.9.0 Timeout waiting for a WP.com response no longer fails the test. Test is marked skipped instead.
684
	 *
685
	 * @return array Test results.
686
	 */
687
	protected function last__wpcom_self_test() {
688
		$name = 'test__wpcom_self_test';
689
690
		$status = new Status();
691 View Code Duplication
		if ( ! Jetpack::is_active() || $status->is_development_mode() || $status->is_staging_site() || ! $this->pass ) {
692
			return self::skipped_test( array( 'name' => $name ) );
693
		}
694
695
		$self_xml_rpc_url = site_url( 'xmlrpc.php' );
696
697
		$testsite_url = Connection_Utils::fix_url_for_bad_hosts( JETPACK__API_BASE . 'testsite/1/?url=' );
698
699
		add_filter( 'http_request_timeout', array( 'Jetpack_Cxn_Tests', 'increase_timeout' ) );
700
701
		$response = wp_remote_get( $testsite_url . $self_xml_rpc_url );
702
703
		remove_filter( 'http_request_timeout', array( 'Jetpack_Cxn_Tests', 'increase_timeout' ) );
704
705
		if ( 200 === wp_remote_retrieve_response_code( $response ) ) {
706
			return self::passing_test( array( 'name' => $name ) );
707
		} elseif ( is_wp_error( $response ) && false !== strpos( $response->get_error_message(), 'cURL error 28' ) ) { // Timeout.
708
			return self::skipped_test(
709
				array(
710
					'name'              => $name,
711
					'short_description' => __( 'The test timed out which may sometimes indicate a failure or may be a false failure.', 'jetpack' ),
712
				)
713
			);
714
		} else {
715
			return self::failing_test(
716
				array(
717
					'name'              => $name,
718
					'short_description' => sprintf(
719
						/* translators: %1$s - A debugging url */
720
						__( 'Jetpack.com detected an error on the WP.com Self Test. Visit the Jetpack Debug page for more info: %1$s, or contact support.', 'jetpack' ),
721
						Redirect::get_url( 'jetpack-support-debug', array( 'query' => 'url=' . rawurlencode( site_url() ) ) )
722
					),
723
					'action_label'      => $this->helper_get_support_text(),
724
					'action'            => $this->helper_get_support_url(),
725
				)
726
			);
727
		}
728
	}
729
}
730