1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* WP Site Health functionality temporarily stored in this file until all of Jetpack is PHP 5.3+ |
4
|
|
|
* |
5
|
|
|
* @package Jetpack. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Test runner for Core's Site Health module. |
10
|
|
|
* |
11
|
|
|
* @since 7.3.0 |
12
|
|
|
*/ |
13
|
|
|
function jetpack_debugger_ajax_local_testing_suite() { |
14
|
|
|
check_ajax_referer( 'health-check-site-status' ); |
15
|
|
|
if ( ! current_user_can( 'jetpack_manage_modules' ) ) { |
16
|
|
|
wp_send_json_error(); |
17
|
|
|
} |
18
|
|
|
$tests = new Jetpack_Cxn_Tests(); |
19
|
|
|
wp_send_json_success( $tests->output_results_for_core_async_site_health() ); |
20
|
|
|
} |
21
|
|
|
/** |
22
|
|
|
* Adds the Jetpack Local Testing Suite to the Core Site Health system. |
23
|
|
|
* |
24
|
|
|
* @since 7.3.0 |
25
|
|
|
* |
26
|
|
|
* @param array $core_tests Array of tests from Core's Site Health. |
27
|
|
|
* |
28
|
|
|
* @return array $core_tests Array of tests for Core's Site Health. |
29
|
|
|
*/ |
30
|
|
|
function jetpack_debugger_site_status_tests( $core_tests ) { |
31
|
|
|
$cxn_tests = new Jetpack_Cxn_Tests(); |
32
|
|
|
$tests = $cxn_tests->list_tests( 'direct' ); |
33
|
|
|
foreach ( $tests as $test ) { |
34
|
|
|
$core_tests['direct'][ $test['name'] ] = array( |
35
|
|
|
'label' => __( 'Jetpack: ', 'jetpack' ) . $test['name'], |
36
|
|
|
'test' => function() use ( $test, $cxn_tests ) { // phpcs:ignore PHPCompatibility.FunctionDeclarations.NewClosure.Found |
37
|
|
|
$results = $cxn_tests->run_test( $test['name'] ); |
38
|
|
|
// Test names are, by default, `test__some_string_of_text`. Let's convert to "Some String Of Text" for humans. |
39
|
|
|
$label = ucwords( |
40
|
|
|
str_replace( |
41
|
|
|
'_', |
42
|
|
|
' ', |
43
|
|
|
str_replace( 'test__', '', $test['name'] ) |
44
|
|
|
) |
45
|
|
|
); |
46
|
|
|
$return = array( |
47
|
|
|
'label' => $label, |
48
|
|
|
'status' => 'good', |
49
|
|
|
'badge' => array( |
50
|
|
|
'label' => __( 'Jetpack', 'jetpack' ), |
51
|
|
|
'color' => 'green', |
52
|
|
|
), |
53
|
|
|
'description' => sprintf( |
54
|
|
|
'<p>%s</p>', |
55
|
|
|
__( 'This test successfully passed!', 'jetpack' ) |
56
|
|
|
), |
57
|
|
|
'actions' => '', |
58
|
|
|
'test' => 'jetpack_' . $test['name'], |
59
|
|
|
); |
60
|
|
|
if ( is_wp_error( $results ) ) { |
61
|
|
|
return; |
62
|
|
|
} |
63
|
|
|
if ( false === $results['pass'] ) { |
64
|
|
|
$return['label'] = $results['message']; |
65
|
|
|
$return['status'] = $results['severity']; |
66
|
|
|
$return['description'] = sprintf( |
67
|
|
|
'<p>%s</p>', |
68
|
|
|
$results['resolution'] |
69
|
|
|
); |
70
|
|
View Code Duplication |
if ( ! empty( $results['action'] ) ) { |
71
|
|
|
$return['actions'] = sprintf( |
72
|
|
|
'<a class="button button-primary" href="%1$s" target="_blank" rel="noopener noreferrer">%2$s <span class="screen-reader-text">%3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>', |
73
|
|
|
esc_url( $results['action'] ), |
74
|
|
|
__( 'Resolve', 'jetpack' ), |
75
|
|
|
/* translators: accessibility text */ |
76
|
|
|
__( '(opens in a new tab)', 'jetpack' ) |
77
|
|
|
); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return $return; |
82
|
|
|
}, |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
$core_tests['async']['jetpack_test_suite'] = array( |
86
|
|
|
'label' => __( 'Jetpack Tests', 'jetpack' ), |
87
|
|
|
'test' => 'jetpack_local_testing_suite', |
88
|
|
|
); |
89
|
|
|
|
90
|
|
|
return $core_tests; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
|