| @@ -1,0 +1,125 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * WP Site Health debugging functions. | |
| 4 | + * | |
| 5 | + * @deprecated 15.9 Site Health integration is now handled by the connection package. | |
| 6 | + * @package automattic/jetpack | |
| 7 | + */ | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * Test runner for Core's Site Health module. | |
| 11 | + * | |
| 12 | + * @since 7.3.0 | |
| 13 | + * @deprecated 15.9 Use Automattic\Jetpack\Connection\Site_Health instead. | |
| 14 | + */ | |
| 15 | +function jetpack_debugger_ajax_local_testing_suite() { | |
| 16 | + _deprecated_function( __FUNCTION__, 'jetpack-15.9' ); | |
| 17 | + check_ajax_referer( 'health-check-site-status' ); | |
| 18 | + if ( ! current_user_can( 'jetpack_manage_modules' ) ) { | |
| 19 | + // @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- It takes null, but its phpdoc only says int. | |
| 20 | + wp_send_json_error( null, null, JSON_UNESCAPED_SLASHES ); | |
| 21 | + } | |
| 22 | + $tests = new Automattic\Jetpack\Connection\Connection_Health_Tests(); | |
| 23 | + // @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- It takes null, but its phpdoc only says int. | |
| 24 | + wp_send_json_success( $tests->output_results_for_core_async_site_health(), null, JSON_UNESCAPED_SLASHES ); | |
| 25 | +} | |
| 26 | +/** | |
| 27 | + * Adds the Jetpack Local Testing Suite to the Core Site Health system. | |
| 28 | + * | |
| 29 | + * @since 7.3.0 | |
| 30 | + * @deprecated 15.9 Use Automattic\Jetpack\Connection\Site_Health instead. | |
| 31 | + * | |
| 32 | + * @param array $core_tests Array of tests from Core's Site Health. | |
| 33 | + * | |
| 34 | + * @return array $core_tests Array of tests for Core's Site Health. | |
| 35 | + */ | |
| 36 | +function jetpack_debugger_site_status_tests( $core_tests ) { | |
| 37 | + _deprecated_function( __FUNCTION__, 'jetpack-15.9' ); | |
| 38 | + $cxn_tests = new Automattic\Jetpack\Connection\Connection_Health_Tests(); | |
| 39 | + $tests = $cxn_tests->list_tests( 'direct' ); | |
| 40 | + foreach ( $tests as $test ) { | |
| 41 | + | |
| 42 | + $core_tests['direct'][ $test['name'] ] = array( | |
| 43 | + 'label' => __( 'Jetpack: ', 'jetpack' ) . $test['name'], | |
| 44 | + /** | |
| 45 | + * Callable for Core's Site Health system to execute. | |
| 46 | + * | |
| 47 | + * @var array $test A Jetpack Testing Suite test array. | |
| 48 | + * @var Automattic\Jetpack\Connection\Connection_Health_Tests $cxn_tests An instance of the connection test suite. | |
| 49 | + * | |
| 50 | + * @return array { | |
| 51 | + * A results array to match the format expected by WordPress Core. | |
| 52 | + * | |
| 53 | + * @type string $label Name for the test. | |
| 54 | + * @type string $status 'critical', 'recommended', or 'good'. | |
| 55 | + * @type array $badge Array for Site Health status. Keys label and color. | |
| 56 | + * @type string $description Description of the test result. | |
| 57 | + * @type string $action HTML to a link to resolve issue. | |
| 58 | + * @type string $test Unique test identifier. | |
| 59 | + * } | |
| 60 | + */ | |
| 61 | + 'test' => function () use ( $test, $cxn_tests ) { | |
| 62 | + $results = $cxn_tests->run_test( $test['name'] ); | |
| 63 | + if ( is_wp_error( $results ) ) { | |
| 64 | + return; | |
| 65 | + } | |
| 66 | + | |
| 67 | + $label = $results['label'] ? | |
| 68 | + $results['label'] : | |
| 69 | + ucwords( | |
| 70 | + str_replace( | |
| 71 | + '_', | |
| 72 | + ' ', | |
| 73 | + str_replace( 'test__', '', $test['name'] ) | |
| 74 | + ) | |
| 75 | + ); | |
| 76 | + if ( $results['long_description'] ) { | |
| 77 | + $description = $results['long_description']; | |
| 78 | + } elseif ( $results['short_description'] ) { | |
| 79 | + $description = sprintf( | |
| 80 | + '<p>%s</p>', | |
| 81 | + $results['short_description'] | |
| 82 | + ); | |
| 83 | + } else { | |
| 84 | + $description = sprintf( | |
| 85 | + '<p>%s</p>', | |
| 86 | + __( 'This test successfully passed!', 'jetpack' ) | |
| 87 | + ); | |
| 88 | + } | |
| 89 | + | |
| 90 | + $return = array( | |
| 91 | + 'label' => $label, | |
| 92 | + 'status' => 'good', | |
| 93 | + 'badge' => array( | |
| 94 | + 'label' => __( 'Jetpack', 'jetpack' ), | |
| 95 | + 'color' => 'green', | |
| 96 | + ), | |
| 97 | + 'description' => $description, | |
| 98 | + 'actions' => '', | |
| 99 | + 'test' => 'jetpack_' . $test['name'], | |
| 100 | + ); | |
| 101 | + | |
| 102 | + if ( false === $results['pass'] ) { | |
| 103 | + $return['status'] = $results['severity']; | |
| 104 | + if ( ! empty( $results['action'] ) ) { | |
| 105 | + $return['actions'] = sprintf( | |
| 106 | + '<a 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>', | |
| 107 | + esc_url( $results['action'] ), | |
| 108 | + $results['action_label'], | |
| 109 | + /* translators: accessibility text */ | |
| 110 | + __( '(opens in a new tab)', 'jetpack' ) | |
| 111 | + ); | |
| 112 | + } | |
| 113 | + } | |
| 114 | + | |
| 115 | + return $return; | |
| 116 | + }, | |
| 117 | + ); | |
| 118 | + } | |
| 119 | + $core_tests['async']['jetpack_test_suite'] = array( | |
| 120 | + 'label' => __( 'Jetpack Tests', 'jetpack' ), | |
| 121 | + 'test' => 'jetpack_local_testing_suite', | |
| 122 | + ); | |
| 123 | + | |
| 124 | + return $core_tests; | |
| 125 | +} | |