WEEK_IN_SECONDS,
'day' => DAY_IN_SECONDS,
'hour' => HOUR_IN_SECONDS,
'minute' => MINUTE_IN_SECONDS,
'second' => 1,
);
// specifically handle zero.
if ( 0 === $seconds ) {
return '0 seconds';
}
$human_readable = '';
foreach ( $units as $name => $divisor ) {
$quot = intval( $seconds / $divisor );
if ( $quot ) {
$human_readable .= "$quot $name";
$human_readable .= ( abs( $quot ) > 1 ? 's' : '' ) . ', ';
$seconds -= $quot * $divisor;
}
}
return substr( $human_readable, 0, -2 );
}
/**
* 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 jetpack_increase_timeout() {
return 30; // seconds.
}
/**
* Disconnect Jetpack and redirect user to connection flow.
*/
public static function disconnect_and_redirect() {
if ( ! ( isset( $_GET['nonce'] ) && wp_verify_nonce( $_GET['nonce'], 'jp_disconnect' ) ) ) {
return;
}
if ( isset( $_GET['disconnect'] ) && $_GET['disconnect'] ) {
if ( Jetpack::is_active() ) {
Jetpack::disconnect();
wp_safe_redirect( Jetpack::admin_url() );
exit;
}
}
}
/**
* Calls to WP.com to run the connection diagnostic testing suite.
*
* @return array|WP_Error Standard WP_HTTP return array: 'headers', 'body', 'response', 'cookies', 'filename' on success.
*/
public static function run_self_test() {
$self_xml_rpc_url = site_url( 'xmlrpc.php' );
$testsite_url = Jetpack::fix_url_for_bad_hosts( JETPACK__API_BASE . 'testsite/1/?url=' );
add_filter( 'http_request_timeout', array( 'Jetpack_Debugger', 'jetpack_increase_timeout' ) );
$response = wp_remote_get( $testsite_url . $self_xml_rpc_url );
remove_filter( 'http_request_timeout', array( 'Jetpack_Debugger', 'jetpack_increase_timeout' ) );
return $response;
}
/**
* Handles output to the browser for the in-plugin debugger.
*/
public static function jetpack_debug_display_handler() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'jetpack' ) );
}
$user_id = get_current_user_id();
$user_tokens = Jetpack_Options::get_option( 'user_tokens' );
if ( is_array( $user_tokens ) && array_key_exists( $user_id, $user_tokens ) ) {
$user_token = $user_tokens[ $user_id ];
} else {
$user_token = '[this user has no token]';
}
unset( $user_tokens );
$debug_info = "\r\n";
foreach ( array(
'CLIENT_ID' => 'id',
'BLOG_TOKEN' => 'blog_token',
'MASTER_USER' => 'master_user',
'CERT' => 'fallback_no_verify_ssl_certs',
'TIME_DIFF' => 'time_diff',
'VERSION' => 'version',
'OLD_VERSION' => 'old_version',
'PUBLIC' => 'public',
) as $label => $option_name ) {
$debug_info .= "\r\n" . esc_html( $label . ': ' . Jetpack_Options::get_option( $option_name ) );
}
$debug_info .= "\r\n" . esc_html( 'USER_ID: ' . $user_id );
$debug_info .= "\r\n" . esc_html( 'USER_TOKEN: ' . $user_token );
$debug_info .= "\r\n" . esc_html( 'PHP_VERSION: ' . PHP_VERSION );
$debug_info .= "\r\n" . esc_html( 'WORDPRESS_VERSION: ' . $GLOBALS['wp_version'] );
$debug_info .= "\r\n" . esc_html( 'JETPACK__VERSION: ' . JETPACK__VERSION );
$debug_info .= "\r\n" . esc_html( 'JETPACK__PLUGIN_DIR: ' . JETPACK__PLUGIN_DIR );
$debug_info .= "\r\n" . esc_html( 'SITE_URL: ' . site_url() );
$debug_info .= "\r\n" . esc_html( 'HOME_URL: ' . home_url() );
$debug_info .= "\r\n" . esc_html( 'PLAN: ' . self::what_jetpack_plan() );
$debug_info .= "\r\n";
$debug_info .= "\r\n" . '-- SYNC Status -- ';
require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-modules.php';
$sync_module = Jetpack_Sync_Modules::get_module( 'full-sync' );
if ( $sync_module ) {
$sync_statuses = $sync_module->get_status();
$human_readable_sync_status = array();
foreach ( $sync_statuses as $sync_status => $sync_status_value ) {
$human_readable_sync_status[ $sync_status ] =
in_array( $sync_status, array( 'started', 'queue_finished', 'send_started', 'finished' ), true )
? date( 'r', $sync_status_value ) : $sync_status_value;
}
/* translators: A string reporting status. Example: "started" */
$debug_info .= "\r\n" . sprintf( esc_html__( 'Jetpack Sync Full Status: `%1$s`', 'jetpack' ), print_r( $human_readable_sync_status, 1 ) ); //phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r
}
require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-sender.php';
$queue = Jetpack_Sync_Sender::get_instance()->get_sync_queue();
/* translators: The number of items waiting to be synced. */
$debug_info .= "\r\n" . sprintf( esc_html__( 'Sync Queue size: %1$s', 'jetpack' ), $queue->size() );
/* translators: Human-readable time since the oldest item in the sync queue. */
$debug_info .= "\r\n" . sprintf( esc_html__( 'Sync Queue lag: %1$s', 'jetpack' ), self::seconds_to_time( $queue->lag() ) );
$full_sync_queue = Jetpack_Sync_Sender::get_instance()->get_full_sync_queue();
/* translators: The number of items waiting to be synced. */
$debug_info .= "\r\n" . sprintf( esc_html__( 'Full Sync Queue size: %1$s', 'jetpack' ), $full_sync_queue->size() );
/* translators: Human-readable time since the oldest item in the sync queue. */
$debug_info .= "\r\n" . sprintf( esc_html__( 'Full Sync Queue lag: %1$s', 'jetpack' ), self::seconds_to_time( $full_sync_queue->lag() ) );
require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-functions.php';
$idc_urls = array(
'home' => Jetpack_Sync_Functions::home_url(),
'siteurl' => Jetpack_Sync_Functions::site_url(),
'WP_HOME' => Jetpack_Constants::is_defined( 'WP_HOME' ) ? Jetpack_Constants::get_constant( 'WP_HOME' ) : '',
'WP_SITEURL' => Jetpack_Constants::is_defined( 'WP_SITEURL' ) ? Jetpack_Constants::get_constant( 'WP_SITEURL' ) : '',
);
/* translators: List of URLs. */
$debug_info .= "\r\n" . esc_html( sprintf( 'Sync IDC URLs: %s', wp_json_encode( $idc_urls ) ) );
/* translators: String of a current option. */
$debug_info .= "\r\n" . esc_html( sprintf( 'Sync error IDC option: %s', wp_json_encode( Jetpack_Options::get_option( 'sync_error_idc' ) ) ) );
/* translators: String of a current option. */
$debug_info .= "\r\n" . esc_html( sprintf( 'Sync IDC Optin: %s', (string) Jetpack::sync_idc_optin() ) );
$debug_info .= "\r\n";
foreach ( array(
'HTTP_HOST',
'SERVER_PORT',
'HTTPS',
'GD_PHP_HANDLER',
'HTTP_AKAMAI_ORIGIN_HOP',
'HTTP_CF_CONNECTING_IP',
'HTTP_CLIENT_IP',
'HTTP_FASTLY_CLIENT_IP',
'HTTP_FORWARDED',
'HTTP_FORWARDED_FOR',
'HTTP_INCAP_CLIENT_IP',
'HTTP_TRUE_CLIENT_IP',
'HTTP_X_CLIENTIP',
'HTTP_X_CLUSTER_CLIENT_IP',
'HTTP_X_FORWARDED',
'HTTP_X_FORWARDED_FOR',
'HTTP_X_IP_TRAIL',
'HTTP_X_REAL_IP',
'HTTP_X_VARNISH',
'REMOTE_ADDR',
) as $header ) {
if ( isset( $_SERVER[ $header ] ) ) {
$debug_info .= "\r\n" . esc_html( $header . ': ' . $_SERVER[ $header ] );
}
}
$debug_info .= "\r\n" . esc_html( 'PROTECT_TRUSTED_HEADER: ' . wp_json_encode( get_site_option( 'trusted_ip_header' ) ) );
$debug_info .= "\r\n\r\nTEST RESULTS:\r\n\r\n";
$debug_raw_info = '';
$tests = array();
$tests['XML']['result'] = ( function_exists( 'xml_parser_create' ) ) ? 'PASS' : false;
/* translators: Link to Jetpack Hosting support page. */
$tests['XML']['fail_message'] = esc_html__( 'Jetpack can not load necessary XML manipulation libraries. Please ask your hosting provider to refer to our server requirements at https://jetpack.com/support/server-requirements/ .', 'jetpack' );
$tests['HTTP']['result'] = wp_remote_get( preg_replace( '/^https:/', 'http:', JETPACK__API_BASE ) . 'test/1/' );
$tests['HTTP']['fail_message'] = esc_html__( 'Your site isn’t reaching the Jetpack servers.', 'jetpack' );
$tests['HTTPS']['result'] = wp_remote_get( preg_replace( '/^http:/', 'https:', JETPACK__API_BASE ) . 'test/1/' );
$tests['HTTPS']['fail_message'] = esc_html__( 'Your site isn’t securely reaching the Jetpack servers.', 'jetpack' );
$identity_crisis_message = '';
$identity_crisis = Jetpack::check_identity_crisis();
if ( $identity_crisis ) {
$identity_crisis_message .= sprintf(
/* translators: Two URLs. The first is the locally-recorded value, the second is the value as recorded on WP.com. */
__( 'Your url is set as `%1$s`, but your WordPress.com connection lists it as `%2$s`!', 'jetpack' ),
$identity_crisis['home'],
$identity_crisis['wpcom_home']
);
$identity_crisis = new WP_Error( 'identity-crisis', $identity_crisis_message, $identity_crisis );
} else {
$identity_crisis = 'PASS';
}
$tests['IDENTITY_CRISIS']['result'] = $identity_crisis;
$tests['IDENTITY_CRISIS']['fail_message'] = esc_html__( 'Something has gotten mixed up in your Jetpack Connection!', 'jetpack' );
$tests['SELF']['result'] = self::run_self_test();
if ( is_wp_error( $tests['SELF']['result'] ) && 0 == strpos( $tests['SELF']['result']->get_error_message(), 'Operation timed out' ) ) {
$tests['SELF']['fail_message'] = esc_html__( 'Your site did not get a response from our debugging service in the expected timeframe. If you are not experiencing other issues, this could be due to a slow connection between your site and our server.', 'jetpack' );
} else {
$tests['SELF']['fail_message'] = esc_html__( 'It looks like your site can not communicate properly with Jetpack.', 'jetpack' );
}
?>
$test_info ) :
$response_code = wp_remote_retrieve_response_code( $test_info['result'] );
if ( 'PASS' !== $test_info['result'] && ( is_wp_error( $test_info['result'] ) ||
false === ( $response_code ) ||
200 !== intval( $response_code ) ) ) {
$debug_info .= $test_name . ": FAIL\r\n";
?>
:
get_error_message() : print_r( $test_info['result'], 1 ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r ?>
get_error_message() : print_r( $test_info['result'], 1 ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r
?>
' . esc_html__( 'Your Jetpack setup looks a-okay!', 'jetpack' ) . '
';
} else {
echo '
' . esc_html__( 'There seems to be a problem with your site’s ability to communicate with Jetpack!', 'jetpack' ) . '
';
echo $html;
}
$debug_info .= "\r\n\r\nRAW TEST RESULTS:" . $debug_raw_info . "\r\n";
?>
- known conflicts with Jetpack – check the list. (You can also browse the Jetpack support pages or Jetpack support forum to see if others have experienced and solved the problem.)', 'jetpack' ), 'http://jetpack.com/support/getting-started-with-jetpack/known-issues/', 'http://jetpack.com/support/getting-started-with-jetpack/known-issues/', 'http://jetpack.com/support/', 'https://wordpress.org/support/plugin/jetpack' ); ?>
-
-
exists() ) {
/* translators: %s is the name of a theme */
echo esc_html( sprintf( __( "If your problem isn't known or caused by a plugin, try activating %s (the default WordPress theme).", 'jetpack' ), $default_theme->get( 'Name' ) ) );
} else {
esc_html_e( "If your problem isn't known or caused by a plugin, try activating the default WordPress theme.", 'jetpack' );
}
?>
- XMLRPC file. It should say “XML-RPC server accepts POST requests only.” on a line by itself.', 'jetpack' ), site_url( 'xmlrpc.php' ) ); ?>
-
Disconnect from WordPress.com', 'jetpack' ),
wp_nonce_url(
Jetpack::admin_url(
array(
'page' => 'jetpack-debugger',
'disconnect' => true,
)
),
'jp_disconnect',
'nonce'
)
),
array(
'a' => array(
'href' => array(),
'class' => array(),
),
)
);
?>
Contact our Happiness team. When you do, please include the full debug information below.', 'jetpack' ), 'https://jetpack.com/contact-support/' ); ?>
%s\'s WordPress.com account.', 'jetpack' ),
esc_html( Jetpack::get_master_user_email() )
);
?>
Jetpack\'s development mode.', 'jetpack' ),
'https://jetpack.com/support/development-mode/'
);
?>
%2$s',
Jetpack::admin_url( 'page=jetpack_modules' ),
esc_html__( 'Access the full list of Jetpack modules available on your site.', 'jetpack' )
);
}
?>
for the in-plugin debugger page.
*/
public static function jetpack_debug_admin_head() {
Jetpack_Admin_Page::load_wrapper_styles();
?>