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