Completed
Push — add/sync-health-tests ( f3209b )
by
unknown
15:35
created

Jetpack_Cxn_Tests::test__outbound_https()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18

Duplication

Lines 18
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 18
loc 18
rs 9.6666
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\Settings as Sync_Settings;
12
use Automattic\Jetpack\Sync\Health as Sync_Health;
13
use Automattic\Jetpack\Sync\Sender as Sync_Sender;
14
15
/**
16
 * Class Jetpack_Cxn_Tests contains all of the actual tests.
17
 */
18
class Jetpack_Cxn_Tests extends Jetpack_Cxn_Test_Base {
19
20
	/**
21
	 * Jetpack_Cxn_Tests constructor.
22
	 */
23
	public function __construct() {
24
		parent::__construct();
25
26
		$methods = get_class_methods( 'Jetpack_Cxn_Tests' );
27
28
		foreach ( $methods as $method ) {
29
			if ( false === strpos( $method, 'test__' ) ) {
30
				continue;
31
			}
32
			$this->add_test( array( $this, $method ), $method, 'direct' );
33
		}
34
35
		/**
36
		 * Fires after loading default Jetpack Connection tests.
37
		 *
38
		 * @since 7.1.0
39
		 * @since 8.3.0 Passes the Jetpack_Cxn_Tests instance.
40
		 */
41
		do_action( 'jetpack_connection_tests_loaded', $this );
42
43
		/**
44
		 * Determines if the WP.com testing suite should be included.
45
		 *
46
		 * @since 7.1.0
47
		 * @since 8.1.0 Default false.
48
		 *
49
		 * @param bool $run_test To run the WP.com testing suite. Default false.
50
		 */
51
		if ( apply_filters( 'jetpack_debugger_run_self_test', false ) ) {
52
			/**
53
			 * Intentionally added last as it checks for an existing failure state before attempting.
54
			 * Generally, any failed location condition would result in the WP.com check to fail too, so
55
			 * we will skip it to avoid confusing error messages.
56
			 *
57
			 * Note: This really should be an 'async' test.
58
			 */
59
			$this->add_test( array( $this, 'last__wpcom_self_test' ), 'test__wpcom_self_test', 'direct' );
60
		}
61
	}
62
63
	/**
64
	 * Helper function to look up the expected master user and return the local WP_User.
65
	 *
66
	 * @return WP_User Jetpack's expected master user.
67
	 */
68
	protected function helper_retrieve_local_master_user() {
69
		$master_user = Jetpack_Options::get_option( 'master_user' );
70
		return new WP_User( $master_user );
71
	}
72
73
	/**
74
	 * Is Jetpack even connected and supposed to be talking to WP.com?
75
	 */
76
	protected function helper_is_jetpack_connected() {
77
		return ( Jetpack::is_active() && ! ( new Status() )->is_development_mode() );
78
	}
79
80
	/**
81
	 * Returns a support url based on development mode.
82
	 */
83
	protected function helper_get_support_url() {
84
		return Jetpack::is_development_version()
85
			? 'https://jetpack.com/contact-support/beta-group/'
86
			: 'https://jetpack.com/contact-support/';
87
	}
88
89
	/**
90
	 * Gets translated support text.
91
	 */
92
	protected function helper_get_support_text() {
93
		return __( 'Please contact Jetpack support.', 'jetpack' );
94
	}
95
96
	/**
97
	 * Gets translated text to enable outbound requests.
98
	 *
99
	 * @param string $protocol Either 'HTTP' or 'HTTPS'.
100
	 *
101
	 * @return string The translated text.
102
	 */
103
	protected function helper_enable_outbound_requests( $protocol ) {
104
		return sprintf(
105
			/* translators: %1$s - request protocol, either http or https */
106
			__(
107
				'Your server did not successfully connect to the Jetpack server using %1$s
108
				Please ask your hosting provider to confirm your server can make outbound requests to jetpack.com.',
109
				'jetpack'
110
			),
111
			$protocol
112
		);
113
	}
114
115
	/**
116
	 * Returns 30 for use with a filter.
117
	 *
118
	 * To allow time for WP.com to run upstream testing, this function exists to increase the http_request_timeout value
119
	 * to 30.
120
	 *
121
	 * @return int 30
122
	 */
123
	public static function increase_timeout() {
124
		return 30; // seconds.
125
	}
126
127
	/**
128
	 * Test if Jetpack is connected.
129
	 */
130
	protected function test__check_if_connected() {
131
		$name = __FUNCTION__;
132
		if ( $this->helper_is_jetpack_connected() ) {
133
			$result = self::passing_test(
134
				array(
135
					'name'             => $name,
136
					'label'            => __( 'Your site is connected to Jetpack', 'jetpack' ),
137
					'long_description' => sprintf(
138
						'<p>%1$s</p>' .
139
						'<p><span class="dashicons pass"><span class="screen-reader-text">%2$s</span></span> %3$s</p>',
140
						__( 'A healthy connection ensures Jetpack essential services are provided to your WordPress site, such as Stats and Site Security.', 'jetpack' ),
141
						/* translators: Screen reader text indicating a test has passed */
142
						__( 'Passed', 'jetpack' ),
143
						__( 'Your site is connected to Jetpack.', 'jetpack' )
144
					),
145
				)
146
			);
147
		} elseif ( ( new Status() )->is_development_mode() ) {
148
			$result = self::skipped_test(
149
				array(
150
					'name'              => $name,
151
					'short_description' => __( 'Jetpack is in Development Mode:', 'jetpack' ) . ' ' . Jetpack::development_mode_trigger_text(),
152
				)
153
			);
154
		} else {
155
			$result = self::failing_test(
156
				array(
157
					'name'             => $name,
158
					'label'            => __( 'Your site is not connected to Jetpack', 'jetpack' ),
159
					'action'           => admin_url( 'admin.php?page=jetpack#/dashboard' ),
160
					'action_label'     => __( 'Reconnect your site now', 'jetpack' ),
161
					'long_description' => sprintf(
162
						'<p>%1$s</p>' .
163
						'<p><span class="dashicons fail"><span class="screen-reader-text">%2$s</span></span> %3$s<strong> %4$s</strong></p>',
164
						__( 'A healthy connection ensures Jetpack essential services are provided to your WordPress site, such as Stats and Site Security.', 'jetpack' ),
165
						/* translators: screen reader text indicating a test failed */
166
						__( 'Error', 'jetpack' ),
167
						__( 'Your site is not connected to Jetpack.', 'jetpack' ),
168
						__( 'We recommend reconnecting Jetpack.', 'jetpack' )
169
					),
170
				)
171
			);
172
		}
173
174
		return $result;
175
	}
176
177
	/**
178
	 * Test that the master user still exists on this site.
179
	 *
180
	 * @return array Test results.
181
	 */
182
	protected function test__master_user_exists_on_site() {
183
		$name = __FUNCTION__;
184 View Code Duplication
		if ( ! $this->helper_is_jetpack_connected() ) {
185
			return self::skipped_test(
186
				array(
187
					'name'              => $name,
188
					'short_description' => __( 'Jetpack is not connected. No master user to check.', 'jetpack' ),
189
				)
190
			);
191
		}
192
		$local_user = $this->helper_retrieve_local_master_user();
193
194
		if ( $local_user->exists() ) {
195
			$result = self::passing_test( array( 'name' => $name ) );
196 View Code Duplication
		} else {
197
			$result = self::failing_test(
198
				array(
199
					'name'              => $name,
200
					'short_description' => __( 'The user who setup the Jetpack connection no longer exists on this site.', 'jetpack' ),
201
					'action_label'      => __( 'Please disconnect and reconnect Jetpack.', 'jetpack' ),
202
					'action'            => 'https://jetpack.com/support/reconnecting-reinstalling-jetpack/',
203
				)
204
			);
205
		}
206
207
		return $result;
208
	}
209
210
	/**
211
	 * Test that the master user has the manage options capability (e.g. is an admin).
212
	 *
213
	 * Generic calls from WP.com execute on Jetpack as the master user. If it isn't an admin, random things will fail.
214
	 *
215
	 * @return array Test results.
216
	 */
217
	protected function test__master_user_can_manage_options() {
218
		$name = __FUNCTION__;
219 View Code Duplication
		if ( ! $this->helper_is_jetpack_connected() ) {
220
			return self::skipped_test(
221
				array(
222
					'name'              => $name,
223
					'short_description' => __( 'Jetpack is not connected.', 'jetpack' ),
224
				)
225
			);
226
		}
227
		$master_user = $this->helper_retrieve_local_master_user();
228
229
		if ( user_can( $master_user, 'manage_options' ) ) {
230
			$result = self::passing_test( array( 'name' => $name ) );
231 View Code Duplication
		} else {
232
			$result = self::failing_test(
233
				array(
234
					'name'              => $name,
235
					/* translators: a WordPress username */
236
					'short_description' => sprintf( __( 'The user (%s) who setup the Jetpack connection is not an administrator.', 'jetpack' ), $master_user->user_login ),
237
					'action_label'      => __( 'Either upgrade the user or disconnect and reconnect Jetpack.', 'jetpack' ),
238
					'action'            => 'https://jetpack.com/support/reconnecting-reinstalling-jetpack/',
239
				)
240
			);
241
		}
242
243
		return $result;
244
	}
245
246
	/**
247
	 * Test that the PHP's XML library is installed.
248
	 *
249
	 * While it should be installed by default, increasingly in PHP 7, some OSes require an additional php-xml package.
250
	 *
251
	 * @return array Test results.
252
	 */
253
	protected function test__xml_parser_available() {
254
		$name = __FUNCTION__;
255
		if ( function_exists( 'xml_parser_create' ) ) {
256
			$result = self::passing_test( array( 'name' => $name ) );
257
		} else {
258
			$result = self::failing_test(
259
				array(
260
					'name'              => $name,
261
					'label'             => __( 'PHP XML manipulation libraries are not available.', 'jetpack' ),
262
					'short_description' => __( 'Please ask your hosting provider to refer to our server requirements and enable PHP\'s XML module.', 'jetpack' ),
263
					'action_label'      => __( 'View our server requirements', 'jetpack' ),
264
					'action'            => 'https://jetpack.com/support/server-requirements/',
265
				)
266
			);
267
		}
268
		return $result;
269
	}
270
271
	/**
272
	 * Test that the server is able to send an outbound http communication.
273
	 *
274
	 * @return array Test results.
275
	 */
276 View Code Duplication
	protected function test__outbound_http() {
277
		$name    = __FUNCTION__;
278
		$request = wp_remote_get( preg_replace( '/^https:/', 'http:', JETPACK__API_BASE ) . 'test/1/' );
279
		$code    = wp_remote_retrieve_response_code( $request );
280
281
		if ( 200 === intval( $code ) ) {
282
			$result = self::passing_test( array( 'name' => $name ) );
283
		} else {
284
			$result = self::failing_test(
285
				array(
286
					'name'              => $name,
287
					'short_description' => $this->helper_enable_outbound_requests( 'HTTP' ),
288
				)
289
			);
290
		}
291
292
		return $result;
293
	}
294
295
	/**
296
	 * Test that the server is able to send an outbound https communication.
297
	 *
298
	 * @return array Test results.
299
	 */
300 View Code Duplication
	protected function test__outbound_https() {
301
		$name    = __FUNCTION__;
302
		$request = wp_remote_get( preg_replace( '/^http:/', 'https:', JETPACK__API_BASE ) . 'test/1/' );
303
		$code    = wp_remote_retrieve_response_code( $request );
304
305
		if ( 200 === intval( $code ) ) {
306
			$result = self::passing_test( array( 'name' => $name ) );
307
		} else {
308
			$result = self::failing_test(
309
				array(
310
					'name'              => $name,
311
					'short_description' => $this->helper_enable_outbound_requests( 'HTTPS' ),
312
				)
313
			);
314
		}
315
316
		return $result;
317
	}
318
319
	/**
320
	 * Check for an IDC.
321
	 *
322
	 * @return array Test results.
323
	 */
324
	protected function test__identity_crisis() {
325
		$name = __FUNCTION__;
326 View Code Duplication
		if ( ! $this->helper_is_jetpack_connected() ) {
327
			return self::skipped_test(
328
				array(
329
					'name'              => $name,
330
					'short_description' => __( 'Jetpack is not connected.', 'jetpack' ),
331
				)
332
			);
333
		}
334
		$identity_crisis = Jetpack::check_identity_crisis();
335
336
		if ( ! $identity_crisis ) {
337
			$result = self::passing_test( array( 'name' => $name ) );
338
		} else {
339
			$result = self::failing_test(
340
				array(
341
					'name'              => $name,
342
					'short_description' => sprintf(
343
						/* translators: Two URLs. The first is the locally-recorded value, the second is the value as recorded on WP.com. */
344
						__( 'Your url is set as `%1$s`, but your WordPress.com connection lists it as `%2$s`!', 'jetpack' ),
345
						$identity_crisis['home'],
346
						$identity_crisis['wpcom_home']
347
					),
348
					'action_label'      => $this->helper_get_support_text(),
349
					'action'            => $this->helper_get_support_url(),
350
				)
351
			);
352
		}
353
		return $result;
354
	}
355
356
	/**
357
	 * Tests connection status against wp.com's test-connection endpoint.
358
	 *
359
	 * @todo: Compare with the wpcom_self_test. We only need one of these.
360
	 *
361
	 * @return array Test results.
362
	 */
363
	protected function test__wpcom_connection_test() {
364
		$name = __FUNCTION__;
365
366
		$status = new Status();
367 View Code Duplication
		if ( ! Jetpack::is_active() || $status->is_development_mode() || $status->is_staging_site() || ! $this->pass ) {
368
			return self::skipped_test( array( 'name' => $name ) );
369
		}
370
371
		add_filter( 'http_request_timeout', array( 'Jetpack_Cxn_Tests', 'increase_timeout' ) );
372
		$response = Client::wpcom_json_api_request_as_blog(
373
			sprintf( '/jetpack-blogs/%d/test-connection', Jetpack_Options::get_option( 'id' ) ),
374
			Client::WPCOM_JSON_API_VERSION
375
		);
376
		remove_filter( 'http_request_timeout', array( 'Jetpack_Cxn_Tests', 'increase_timeout' ) );
377
378 View Code Duplication
		if ( is_wp_error( $response ) ) {
379
			return self::failing_test(
380
				array(
381
					'name'              => $name,
382
					/* translators: %1$s is the error code, %2$s is the error message */
383
					'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...
384
					'action_label'      => $this->helper_get_support_text(),
385
					'action'            => $this->helper_get_support_url(),
386
				)
387
			);
388
		}
389
390
		$body = wp_remote_retrieve_body( $response );
391 View Code Duplication
		if ( ! $body ) {
392
			return self::failing_test(
393
				array(
394
					'name'              => $name,
395
					'short_description' => __( 'Connection test failed (empty response body)', 'jetpack' ) . wp_remote_retrieve_response_code( $response ),
396
					'action_label'      => $this->helper_get_support_text(),
397
					'action'            => $this->helper_get_support_url(),
398
				)
399
			);
400
		}
401
402 View Code Duplication
		if ( 404 === wp_remote_retrieve_response_code( $response ) ) {
403
			return self::skipped_test(
404
				array(
405
					'name'              => $name,
406
					'short_description' => __( 'The WordPress.com API returned a 404 error.', 'jetpack' ),
407
				)
408
			);
409
		}
410
411
		$result       = json_decode( $body );
412
		$is_connected = (bool) $result->connected;
413
		$message      = $result->message . ': ' . wp_remote_retrieve_response_code( $response );
414
415
		if ( $is_connected ) {
416
			return self::passing_test( array( 'name' => $name ) );
417
		} else {
418
			return self::failing_test(
419
				array(
420
					'name'              => $name,
421
					'short_description' => $message,
422
					'action_label'      => $this->helper_get_support_text(),
423
					'action'            => $this->helper_get_support_url(),
424
				)
425
			);
426
		}
427
	}
428
429
	/**
430
	 * Tests the port number to ensure it is an expected value.
431
	 *
432
	 * We expect that sites on be on one of:
433
	 * port 80,
434
	 * port 443 (https sites only),
435
	 * the value of JETPACK_SIGNATURE__HTTP_PORT,
436
	 * unless the site is intentionally on a different port (e.g. example.com:8080 is the site's URL).
437
	 *
438
	 * If the value isn't one of those and the site's URL doesn't include a port, then the signature verification will fail.
439
	 *
440
	 * This happens most commonly on sites with reverse proxies, so the edge (e.g. Varnish) is running on 80/443, but nginx
441
	 * or Apache is responding internally on a different port (e.g. 81).
442
	 *
443
	 * @return array Test results
444
	 */
445
	protected function test__server_port_value() {
446
		$name = __FUNCTION__;
447
		if ( ! isset( $_SERVER['HTTP_X_FORWARDED_PORT'] ) && ! isset( $_SERVER['SERVER_PORT'] ) ) {
448
			return self::skipped_test(
449
				array(
450
					'name'              => $name,
451
					'short_description' => __( 'The server port values are not defined. This is most common when running PHP via a CLI.', 'jetpack' ),
452
				)
453
			);
454
		}
455
		$site_port   = wp_parse_url( home_url(), PHP_URL_PORT );
456
		$server_port = isset( $_SERVER['HTTP_X_FORWARDED_PORT'] ) ? (int) $_SERVER['HTTP_X_FORWARDED_PORT'] : (int) $_SERVER['SERVER_PORT'];
457
		$http_ports  = array( 80 );
458
		$https_ports = array( 80, 443 );
459
460
		if ( defined( 'JETPACK_SIGNATURE__HTTP_PORT' ) ) {
461
			$http_ports[] = JETPACK_SIGNATURE__HTTP_PORT;
462
		}
463
464
		if ( defined( 'JETPACK_SIGNATURE__HTTPS_PORT' ) ) {
465
			$https_ports[] = JETPACK_SIGNATURE__HTTPS_PORT;
466
		}
467
468
		if ( $site_port ) {
469
			return self::skipped_test( array( 'name' => $name ) ); // Not currently testing for this situation.
470
		}
471
472
		if ( is_ssl() && in_array( $server_port, $https_ports, true ) ) {
473
			return self::passing_test( array( 'name' => $name ) );
474
		} elseif ( in_array( $server_port, $http_ports, true ) ) {
475
			return self::passing_test( array( 'name' => $name ) );
476
		} else {
477
			if ( is_ssl() ) {
478
				$needed_constant = 'JETPACK_SIGNATURE__HTTPS_PORT';
479
			} else {
480
				$needed_constant = 'JETPACK_SIGNATURE__HTTP_PORT';
481
			}
482
			return self::failing_test(
483
				array(
484
					'name'              => $name,
485
					'short_description' => sprintf(
486
						/* translators: %1$s - a PHP code snippet */
487
						__(
488
							'The server port value is unexpected.
489
						Try adding the following to your wp-config.php file: %1$s',
490
							'jetpack'
491
						),
492
						"define( '$needed_constant', $server_port )"
493
					),
494
				)
495
			);
496
		}
497
	}
498
499
	/**
500
	 * If Sync is enabled, this test will be skipped. If Sync is disabled, the test will fail.
501
	 * Eventually, we'll make this test more robust with additional states. Here is the plan for possible Sync states,
502
	 * including states that are planned but not yet implemented.
503
	 *
504
	 * Enabled: Skips test
505
	 * Disabled: Results in a failing test
506
	 * Healthy: @todo
507
	 * In Progress: @todo
508
	 * Delayed: @todo
509
	 * Error: @todo
510
	 */
511
	protected function test__sync_health() {
512
513
		$name = __FUNCTION__;
514
515
		if ( ! $this->helper_is_jetpack_connected() ) {
516
			// If the site is not connected, there is no point in testing Sync health.
517
			return self::skipped_test(
518
				array(
519
					'name'                => $name,
520
					'show_in_site_health' => false,
521
				)
522
			);
523
		}
524
525
		// Sync is enabled.
526
		if ( Sync_Settings::is_sync_enabled() ) {
527
528
			// Sync has experienced Data Loss.
529
			if ( Sync_Health::get_status() === Sync_Health::STATUS_OUT_OF_SYNC ) {
530
531
				return self::failing_test(
532
					array(
533
						'name'              => $name,
534
						'label'             => __( 'Jetpack has detected an error syncing your site.', 'jetpack' ),
535
						'severity'          => 'critical',
536
						'action'            => 'https://jetpack.com/contact-support/',
537
						'action_label'      => __( 'Contact Jetpack Support', 'jetpack' ),
538
						'short_description' => __( 'Jetpack has detected an error syncing your site.', 'jetpack' ),
539
						'long_description'  => sprintf(
540
							'<p>%1$s</p><p><span class="dashicons fail"><span class="screen-reader-text">%2$s</span></span> %3$s<strong> %4$s</strong></p>',
541
							__( 'The information synced by Jetpack ensures that Jetpack Search, Related Posts and other features are aligned with your site’s current content.', 'jetpack' ),
542
							__( 'Error', 'jetpack' ),
543
							__( 'Jetpack has detected an error while syncing your site', 'jetpack' ), /* translators: screen reader text indicating a test failed */
544
							__( 'We recommend a full sync to align Jetpack with your site data.', 'jetpack' )
545
						),
546
					)
547
				);
548
549
			} else {
550
551
				// Get the Sync Queue.
552
				$sender     = Sync_Sender::get_instance();
553
				$sync_queue = $sender->get_sync_queue();
554
555
				// lag exceeds 5 minutes.
556
				if ( $sync_queue->lag() > 5 * MINUTE_IN_SECONDS ) {
557
558
					return self::failing_test(
559
						array(
560
							'name'              => $name,
561
							'label'             => __( 'Jetpack is experiencing a delay syncing your site.', 'jetpack' ),
562
							'severity'          => 'recommended',
563
							'action'            => null,
564
							'action_label'      => null,
565
							'short_description' => __( 'Jetpack is experiencing a delay syncing your site.', 'jetpack' ),
566
							'long_description'  => sprintf(
567
								'<p>%1$s</p><p><span class="dashicons dashicons-clock" style="color: orange;"><span class="screen-reader-text">%2$s</span></span> %3$s <strong>%4$s %5$d %6$s</strong></p>',
568
								__( 'The information synced by Jetpack ensures that Jetpack Search, Related Posts and other features are aligned with your site’s current content.', 'jetpack' ),
569
								__( 'Clock', 'jetpack' ),
570
								__( '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.', 'jetpack' ), /* translators: screen reader text indicating a test failed */
571
								__( 'We’re seeing a current delay of', 'jetpack' ),
572
								intval( $sync_queue->lag() / MINUTE_IN_SECONDS ),
573
								__( 'minutes.', 'jetpack' )
574
							),
575
						)
576
					);
577
578
				} else {
579
580
					// Sync is Healthy.
581
					return self::skipped_test( array( 'name' => $name ) );
582
583
				}
584
			}
585
		} else {
586
587
			// Sync is disabled.
588
			return self::failing_test(
589
				array(
590
					'name'              => $name,
591
					'label'             => __( 'Jetpack Sync has been disabled on your site.', 'jetpack' ),
592
					'severity'          => 'recommended',
593
					'action'            => 'https://github.com/Automattic/jetpack/blob/master/packages/sync/src/class-settings.php',
594
					'action_label'      => __( 'See Github for more on Sync Settings', 'jetpack' ),
595
					'short_description' => __( 'Jetpack Sync has been disabled on your site.', 'jetpack' ),
596
					'long_description'  => sprintf(
597
						'<p>%1$s</p><p>%2$s</p><p><span class="dashicons fail"><span class="screen-reader-text">%3$s</span></span> %4$s<strong> %5$s</strong></p>',
598
						__( 'The information synced by Jetpack ensures that Jetpack Search, Related Posts and other features are aligned with your site’s current content.', 'jetpack' ),
599
						__( 'Developers may enable / disable syncing using the Sync Settings API.', 'jetpack' ), /* translators: screen reader text indicating a test failed */
600
						__( 'Error', 'jetpack' ),
601
						__( 'Jetpack Sync has been disabled on your site. Without it, certain Jetpack features will not work.', 'jetpack' ),
602
						__( 'We recommend enabling Sync.', 'jetpack' )
603
					),
604
				)
605
			);
606
607
		}
608
609
	}
610
611
	/**
612
	 * Calls to WP.com to run the connection diagnostic testing suite.
613
	 *
614
	 * Intentionally added last as it will be skipped if any local failed conditions exist.
615
	 *
616
	 * @since 7.1.0
617
	 * @since 7.9.0 Timeout waiting for a WP.com response no longer fails the test. Test is marked skipped instead.
618
	 *
619
	 * @return array Test results.
620
	 */
621
	protected function last__wpcom_self_test() {
622
		$name = 'test__wpcom_self_test';
623
624
		$status = new Status();
625 View Code Duplication
		if ( ! Jetpack::is_active() || $status->is_development_mode() || $status->is_staging_site() || ! $this->pass ) {
626
			return self::skipped_test( array( 'name' => $name ) );
627
		}
628
629
		$self_xml_rpc_url = site_url( 'xmlrpc.php' );
630
631
		$testsite_url = Connection_Utils::fix_url_for_bad_hosts( JETPACK__API_BASE . 'testsite/1/?url=' );
632
633
		add_filter( 'http_request_timeout', array( 'Jetpack_Cxn_Tests', 'increase_timeout' ) );
634
635
		$response = wp_remote_get( $testsite_url . $self_xml_rpc_url );
636
637
		remove_filter( 'http_request_timeout', array( 'Jetpack_Cxn_Tests', 'increase_timeout' ) );
638
639
		if ( 200 === wp_remote_retrieve_response_code( $response ) ) {
640
			return self::passing_test( array( 'name' => $name ) );
641
		} elseif ( is_wp_error( $response ) && false !== strpos( $response->get_error_message(), 'cURL error 28' ) ) { // Timeout.
642
			return self::skipped_test(
643
				array(
644
					'name'              => $name,
645
					'short_description' => __( 'The test timed out which may sometimes indicate a failure or may be a false failure.', 'jetpack' ),
646
				)
647
			);
648
		} else {
649
			return self::failing_test(
650
				array(
651
					'name'              => $name,
652
					'short_description' => sprintf(
653
						/* translators: %1$s - A debugging url */
654
						__( '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' ),
655
						esc_url( add_query_arg( 'url', rawurlencode( site_url() ), 'https://jetpack.com/support/debug/' ) )
656
					),
657
					'action_label'      => $this->helper_get_support_text(),
658
					'action'            => $this->helper_get_support_url(),
659
				)
660
			);
661
		}
662
	}
663
}
664