summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/_inc/lib/debugger/class-jetpack-cxn-tests.php')
-rw-r--r--plugins/jetpack/_inc/lib/debugger/class-jetpack-cxn-tests.php66
1 files changed, 56 insertions, 10 deletions
diff --git a/plugins/jetpack/_inc/lib/debugger/class-jetpack-cxn-tests.php b/plugins/jetpack/_inc/lib/debugger/class-jetpack-cxn-tests.php
index 274d032b..6e3cccd6 100644
--- a/plugins/jetpack/_inc/lib/debugger/class-jetpack-cxn-tests.php
+++ b/plugins/jetpack/_inc/lib/debugger/class-jetpack-cxn-tests.php
@@ -5,6 +5,10 @@
* @package Jetpack
*/
+use Automattic\Jetpack\Connection\Client;
+use Automattic\Jetpack\Status;
+use Automattic\Jetpack\Connection\Utils as Connection_Utils;
+
/**
* Class Jetpack_Cxn_Tests contains all of the actual tests.
*/
@@ -65,7 +69,19 @@ class Jetpack_Cxn_Tests extends Jetpack_Cxn_Test_Base {
* Is Jetpack even connected and supposed to be talking to WP.com?
*/
protected function helper_is_jetpack_connected() {
- return ( Jetpack::is_active() && ! Jetpack::is_development_mode() );
+ return ( Jetpack::is_active() && ! ( new Status() )->is_development_mode() );
+ }
+
+ /**
+ * Returns 30 for use with a filter.
+ *
+ * To allow time for WP.com to run upstream testing, this function exists to increase the http_request_timeout value
+ * to 30.
+ *
+ * @return int 30
+ */
+ public static function increase_timeout() {
+ return 30; // seconds.
}
/**
@@ -75,7 +91,7 @@ class Jetpack_Cxn_Tests extends Jetpack_Cxn_Test_Base {
$name = __FUNCTION__;
if ( $this->helper_is_jetpack_connected() ) {
$result = self::passing_test( $name );
- } elseif ( Jetpack::is_development_mode() ) {
+ } elseif ( ( new Status() )->is_development_mode() ) {
$result = self::skipped_test( $name, __( 'Jetpack is in Development Mode:', 'jetpack' ) . ' ' . Jetpack::development_mode_trigger_text(), __( 'Disable development mode.', 'jetpack' ) );
} else {
$result = self::failing_test( $name, __( 'Jetpack is not connected.', 'jetpack' ), 'cycle_connection' );
@@ -221,14 +237,16 @@ class Jetpack_Cxn_Tests extends Jetpack_Cxn_Test_Base {
protected function test__wpcom_connection_test() {
$name = __FUNCTION__;
- if ( ! Jetpack::is_active() || Jetpack::is_development_mode() || Jetpack::is_staging_site() || ! $this->pass ) {
+ if ( ! Jetpack::is_active() || ( new Status() )->is_development_mode() || Jetpack::is_staging_site() || ! $this->pass ) {
return self::skipped_test( $name );
}
- $response = Jetpack_Client::wpcom_json_api_request_as_blog(
+ add_filter( 'http_request_timeout', array( 'Jetpack_Cxn_Tests', 'increase_timeout' ) );
+ $response = Client::wpcom_json_api_request_as_blog(
sprintf( '/jetpack-blogs/%d/test-connection', Jetpack_Options::get_option( 'id' ) ),
- Jetpack_Client::WPCOM_JSON_API_VERSION
+ Client::WPCOM_JSON_API_VERSION
);
+ remove_filter( 'http_request_timeout', array( 'Jetpack_Cxn_Tests', 'increase_timeout' ) );
if ( is_wp_error( $response ) ) {
/* translators: %1$s is the error code, %2$s is the error message */
@@ -242,6 +260,10 @@ class Jetpack_Cxn_Tests extends Jetpack_Cxn_Test_Base {
return self::failing_test( $name, $message );
}
+ if ( 404 === wp_remote_retrieve_response_code( $response ) ) {
+ return self::skipped_test( $name, __( 'The WordPress.com API returned a 404 error.', 'jetpack' ) );
+ }
+
$result = json_decode( $body );
$is_connected = (bool) $result->connected;
$message = $result->message . ': ' . wp_remote_retrieve_response_code( $response );
@@ -313,28 +335,52 @@ class Jetpack_Cxn_Tests extends Jetpack_Cxn_Test_Base {
*
* Intentionally added last as it will be skipped if any local failed conditions exist.
*
+ * @since 7.1.0
+ * @since 7.9.0 Timeout waiting for a WP.com response no longer fails the test. Test is marked skipped instead.
+ *
* @return array Test results.
*/
protected function last__wpcom_self_test() {
$name = 'test__wpcom_self_test';
- if ( ! Jetpack::is_active() || Jetpack::is_development_mode() || Jetpack::is_staging_site() || ! $this->pass ) {
+
+ if ( ! Jetpack::is_active() || ( new Status() )->is_development_mode() || Jetpack::is_staging_site() || ! $this->pass ) {
return self::skipped_test( $name );
}
$self_xml_rpc_url = site_url( 'xmlrpc.php' );
- $testsite_url = Jetpack::fix_url_for_bad_hosts( JETPACK__API_BASE . 'testsite/1/?url=' );
+ $testsite_url = Connection_Utils::fix_url_for_bad_hosts( JETPACK__API_BASE . 'testsite/1/?url=' );
- add_filter( 'http_request_timeout', array( 'Jetpack_Debugger', 'jetpack_increase_timeout' ) );
+ add_filter( 'http_request_timeout', array( 'Jetpack_Cxn_Tests', 'increase_timeout' ) );
$response = wp_remote_get( $testsite_url . $self_xml_rpc_url );
- remove_filter( 'http_request_timeout', array( 'Jetpack_Debugger', 'jetpack_increase_timeout' ) );
+ remove_filter( 'http_request_timeout', array( 'Jetpack_Cxn_Tests', 'increase_timeout' ) );
+
+ $error_msg = wp_kses(
+ sprintf(
+ /* translators: Placeholder is a link to site's Jetpack debug page. */
+ __(
+ '<a target="_blank" rel="noopener noreferrer" href="%s">Visit the Jetpack.com debug page</a> for more information or <a target="_blank" rel="noopener noreferrer" href="https://jetpack.com/contact-support/">contact support</a>.',
+ 'jetpack'
+ ),
+ esc_url( add_query_arg( 'url', rawurlencode( site_url() ), 'https://jetpack.com/support/debug/' ) )
+ ),
+ array(
+ 'a' => array(
+ 'href' => array(),
+ 'target' => array(),
+ 'rel' => array(),
+ ),
+ )
+ );
if ( 200 === wp_remote_retrieve_response_code( $response ) ) {
return self::passing_test( $name );
+ } elseif ( is_wp_error( $response ) && false !== strpos( $response->get_error_message(), 'cURL error 28' ) ) { // Timeout.
+ return self::skipped_test( $name, __( 'The test timed out which may sometimes indicate a failure or may be a false failure.', 'jetpack' ) );
} else {
- return self::failing_test( $name, __( 'Jetpack.com detected an error.', 'jetpack' ), __( 'Visit the Jetpack.com debugging page for more information or contact support.', 'jetpack' ) ); // @todo direct links.
+ return self::failing_test( $name, __( 'Jetpack.com detected an error on the WPcom Self Test.', 'jetpack' ), $error_msg );
}
}
}