PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 7.1
Jetpack – WP Security, Backup, Speed, & Growth v7.1
16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / _inc / lib / debugger / class-jetpack-debugger.php
class-jetpack-debugger.php
531 lines 17.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Jetpack Debugger functionality allowing for self-service diagnostic information.
4 *
5 * @package jetpack
6 */
7
8 /**
9 * Class Jetpack_Debugger
10 *
11 * A namespacing class for functionality related to the in-plugin diagnostic tooling.
12 */
13 class Jetpack_Debugger {
14
15 /**
16 * Determine the active plan and normalize it for the debugger results.
17 *
18 * @return string The plan slug prepended with "JetpackPlan"
19 */
20 private static function what_jetpack_plan() {
21 $plan = Jetpack::get_active_plan();
22 $plan = ! empty( $plan['class'] ) ? $plan['class'] : 'undefined';
23 return 'JetpackPlan' . $plan;
24 }
25
26 /**
27 * Convert seconds to human readable time.
28 *
29 * A dedication function instead of using Core functionality to allow for output in seconds.
30 *
31 * @param int $seconds Number of seconds to convert to human time.
32 *
33 * @return string Human readable time.
34 */
35 public static function seconds_to_time( $seconds ) {
36 $seconds = intval( $seconds );
37 $units = array(
38 'week' => WEEK_IN_SECONDS,
39 'day' => DAY_IN_SECONDS,
40 'hour' => HOUR_IN_SECONDS,
41 'minute' => MINUTE_IN_SECONDS,
42 'second' => 1,
43 );
44 // specifically handle zero.
45 if ( 0 === $seconds ) {
46 return '0 seconds';
47 }
48 $human_readable = '';
49 foreach ( $units as $name => $divisor ) {
50 $quot = intval( $seconds / $divisor );
51 if ( $quot ) {
52 $human_readable .= "$quot $name";
53 $human_readable .= ( abs( $quot ) > 1 ? 's' : '' ) . ', ';
54 $seconds -= $quot * $divisor;
55 }
56 }
57 return substr( $human_readable, 0, -2 );
58 }
59
60 /**
61 * Returns 30 for use with a filter.
62 *
63 * To allow time for WP.com to run upstream testing, this function exists to increase the http_request_timeout value
64 * to 30.
65 *
66 * @return int 30
67 */
68 public static function jetpack_increase_timeout() {
69 return 30; // seconds.
70 }
71
72 /**
73 * Disconnect Jetpack and redirect user to connection flow.
74 */
75 public static function disconnect_and_redirect() {
76 if ( ! ( isset( $_GET['nonce'] ) && wp_verify_nonce( $_GET['nonce'], 'jp_disconnect' ) ) ) {
77 return;
78 }
79
80 if ( isset( $_GET['disconnect'] ) && $_GET['disconnect'] ) {
81 if ( Jetpack::is_active() ) {
82 Jetpack::disconnect();
83 wp_safe_redirect( Jetpack::admin_url() );
84 exit;
85 }
86 }
87 }
88
89 /**
90 * Handles output to the browser for the in-plugin debugger.
91 */
92 public static function jetpack_debug_display_handler() {
93 if ( ! current_user_can( 'manage_options' ) ) {
94 wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'jetpack' ) );
95 }
96
97 $user_id = get_current_user_id();
98 $user_tokens = Jetpack_Options::get_option( 'user_tokens' );
99 if ( is_array( $user_tokens ) && array_key_exists( $user_id, $user_tokens ) ) {
100 $user_token = $user_tokens[ $user_id ];
101 } else {
102 $user_token = '[this user has no token]';
103 }
104 unset( $user_tokens );
105
106 $debug_info = "\r\n";
107 foreach ( array(
108 'CLIENT_ID' => 'id',
109 'BLOG_TOKEN' => 'blog_token',
110 'MASTER_USER' => 'master_user',
111 'CERT' => 'fallback_no_verify_ssl_certs',
112 'TIME_DIFF' => 'time_diff',
113 'VERSION' => 'version',
114 'OLD_VERSION' => 'old_version',
115 'PUBLIC' => 'public',
116 ) as $label => $option_name ) {
117 $debug_info .= "\r\n" . esc_html( $label . ': ' . Jetpack_Options::get_option( $option_name ) );
118 }
119
120 $debug_info .= "\r\n" . esc_html( 'USER_ID: ' . $user_id );
121 $debug_info .= "\r\n" . esc_html( 'USER_TOKEN: ' . $user_token );
122 $debug_info .= "\r\n" . esc_html( 'PHP_VERSION: ' . PHP_VERSION );
123 $debug_info .= "\r\n" . esc_html( 'WORDPRESS_VERSION: ' . $GLOBALS['wp_version'] );
124 $debug_info .= "\r\n" . esc_html( 'JETPACK__VERSION: ' . JETPACK__VERSION );
125 $debug_info .= "\r\n" . esc_html( 'JETPACK__PLUGIN_DIR: ' . JETPACK__PLUGIN_DIR );
126 $debug_info .= "\r\n" . esc_html( 'SITE_URL: ' . site_url() );
127 $debug_info .= "\r\n" . esc_html( 'HOME_URL: ' . home_url() );
128 $debug_info .= "\r\n" . esc_html( 'PLAN: ' . self::what_jetpack_plan() );
129
130 $debug_info .= "\r\n";
131
132 $debug_info .= "\r\n" . '-- SYNC Status -- ';
133 require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-modules.php';
134 $sync_module = Jetpack_Sync_Modules::get_module( 'full-sync' );
135 if ( $sync_module ) {
136 $sync_statuses = $sync_module->get_status();
137 $human_readable_sync_status = array();
138 foreach ( $sync_statuses as $sync_status => $sync_status_value ) {
139 $human_readable_sync_status[ $sync_status ] =
140 in_array( $sync_status, array( 'started', 'queue_finished', 'send_started', 'finished' ), true )
141 ? date( 'r', $sync_status_value ) : $sync_status_value;
142 }
143 /* translators: A string reporting status. Example: "started" */
144 $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
145 }
146
147 require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-sender.php';
148
149 $queue = Jetpack_Sync_Sender::get_instance()->get_sync_queue();
150
151 /* translators: The number of items waiting to be synced. */
152 $debug_info .= "\r\n" . sprintf( esc_html__( 'Sync Queue size: %1$s', 'jetpack' ), $queue->size() );
153 /* translators: Human-readable time since the oldest item in the sync queue. */
154 $debug_info .= "\r\n" . sprintf( esc_html__( 'Sync Queue lag: %1$s', 'jetpack' ), self::seconds_to_time( $queue->lag() ) );
155
156 $full_sync_queue = Jetpack_Sync_Sender::get_instance()->get_full_sync_queue();
157
158 /* translators: The number of items waiting to be synced. */
159 $debug_info .= "\r\n" . sprintf( esc_html__( 'Full Sync Queue size: %1$s', 'jetpack' ), $full_sync_queue->size() );
160 /* translators: Human-readable time since the oldest item in the sync queue. */
161 $debug_info .= "\r\n" . sprintf( esc_html__( 'Full Sync Queue lag: %1$s', 'jetpack' ), self::seconds_to_time( $full_sync_queue->lag() ) );
162
163 require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-functions.php';
164 $idc_urls = array(
165 'home' => Jetpack_Sync_Functions::home_url(),
166 'siteurl' => Jetpack_Sync_Functions::site_url(),
167 'WP_HOME' => Jetpack_Constants::is_defined( 'WP_HOME' ) ? Jetpack_Constants::get_constant( 'WP_HOME' ) : '',
168 'WP_SITEURL' => Jetpack_Constants::is_defined( 'WP_SITEURL' ) ? Jetpack_Constants::get_constant( 'WP_SITEURL' ) : '',
169 );
170 /* translators: List of URLs. */
171 $debug_info .= "\r\n" . esc_html( sprintf( 'Sync IDC URLs: %s', wp_json_encode( $idc_urls ) ) );
172 /* translators: String of a current option. */
173 $debug_info .= "\r\n" . esc_html( sprintf( 'Sync error IDC option: %s', wp_json_encode( Jetpack_Options::get_option( 'sync_error_idc' ) ) ) );
174 /* translators: String of a current option. */
175 $debug_info .= "\r\n" . esc_html( sprintf( 'Sync IDC Optin: %s', (string) Jetpack::sync_idc_optin() ) );
176
177 $debug_info .= "\r\n";
178
179 foreach ( array(
180 'HTTP_HOST',
181 'SERVER_PORT',
182 'HTTPS',
183 'GD_PHP_HANDLER',
184 'HTTP_AKAMAI_ORIGIN_HOP',
185 'HTTP_CF_CONNECTING_IP',
186 'HTTP_CLIENT_IP',
187 'HTTP_FASTLY_CLIENT_IP',
188 'HTTP_FORWARDED',
189 'HTTP_FORWARDED_FOR',
190 'HTTP_INCAP_CLIENT_IP',
191 'HTTP_TRUE_CLIENT_IP',
192 'HTTP_X_CLIENTIP',
193 'HTTP_X_CLUSTER_CLIENT_IP',
194 'HTTP_X_FORWARDED',
195 'HTTP_X_FORWARDED_FOR',
196 'HTTP_X_IP_TRAIL',
197 'HTTP_X_REAL_IP',
198 'HTTP_X_VARNISH',
199 'REMOTE_ADDR',
200 ) as $header ) {
201 if ( isset( $_SERVER[ $header ] ) ) {
202 $debug_info .= "\r\n" . esc_html( $header . ': ' . $_SERVER[ $header ] );
203 }
204 }
205
206 $debug_info .= "\r\n" . esc_html( 'PROTECT_TRUSTED_HEADER: ' . wp_json_encode( get_site_option( 'trusted_ip_header' ) ) );
207
208 $debug_info .= "\r\n\r\nTEST RESULTS:\r\n\r\n";
209
210 $cxntests = new Jetpack_Cxn_Tests();
211 ?>
212 <div class="wrap">
213 <h2><?php esc_html_e( 'Debugging Center', 'jetpack' ); ?></h2>
214 <h3><?php esc_html_e( "Testing your site's compatibility with Jetpack...", 'jetpack' ); ?></h3>
215 <div class="jetpack-debug-test-container">
216 <?php
217 if ( $cxntests->pass() ) {
218 echo '<div class="jetpack-tests-succeed">' . esc_html__( 'Your Jetpack setup looks a-okay!', 'jetpack' ) . '</div>';
219 $debug_info .= "All tests passed.\r\n";
220 $debug_info .= print_r( $cxntests->raw_results(), true ); //phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r
221 } else {
222 $failures = $cxntests->list_fails();
223 foreach ( $failures as $fail ) {
224 echo '<div class="jetpack-test-error">';
225 echo '<p><a class="jetpack-test-heading" href="#">' . esc_html( $fail['message'] );
226 echo '<span class="noticon noticon-collapse"></span></a></p>';
227 echo '<p class="jetpack-test-details">' . esc_html( $fail['resolution'] ) . '</p>';
228 echo '</div>';
229
230 $debug_info .= "FAILED TESTS!\r\n";
231 $debug_info .= $fail['name'] . ': ' . $fail['message'] . "\r\n";
232 $debug_info .= print_r( $cxntests->raw_results(), true ); //phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r
233 }
234 }
235 ?>
236 </div>
237 <div class="entry-content">
238 <h3><?php esc_html_e( 'Trouble with Jetpack?', 'jetpack' ); ?></h3>
239 <h4><?php esc_html_e( 'It may be caused by one of these issues, which you can diagnose yourself:', 'jetpack' ); ?></h4>
240 <ol>
241 <li><b><em>
242 <?php
243 esc_html_e( 'A known issue.', 'jetpack' );
244 ?>
245 </em></b>
246 <?php
247 echo sprintf(
248 wp_kses(
249 /* translators: URLs to Jetpack support pages. */
250 __( 'Some themes and plugins have <a href="%1$s" target="_blank">known conflicts</a> with Jetpack – check the <a href="%2$s" target="_blank">list</a>. (You can also browse the <a href="%3$s" target="_blank">Jetpack support pages</a> or <a href="%4$s" target="_blank">Jetpack support forum</a> to see if others have experienced and solved the problem.)', 'jetpack' ),
251 array(
252 'a' => array(
253 'href' => array(),
254 'target' => array(),
255 ),
256 )
257 ),
258 'http://jetpack.com/support/getting-started-with-jetpack/known-issues/',
259 'http://jetpack.com/support/getting-started-with-jetpack/known-issues/',
260 'http://jetpack.com/support/',
261 'https://wordpress.org/support/plugin/jetpack'
262 );
263 ?>
264 </li>
265 <li><b><em><?php esc_html_e( 'An incompatible plugin.', 'jetpack' ); ?></em></b> <?php esc_html_e( "Find out by disabling all plugins except Jetpack. If the problem persists, it's not a plugin issue. If the problem is solved, turn your plugins on one by one until the problem pops up again – there's the culprit! Let us know, and we'll try to help.", 'jetpack' ); ?></li>
266 <li>
267 <b><em><?php esc_html_e( 'A theme conflict.', 'jetpack' ); ?></em></b>
268 <?php
269 $default_theme = wp_get_theme( WP_DEFAULT_THEME );
270
271 if ( $default_theme->exists() ) {
272 /* translators: %s is the name of a theme */
273 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' ) ) );
274 } else {
275 esc_html_e( "If your problem isn't known or caused by a plugin, try activating the default WordPress theme.", 'jetpack' );
276 }
277 ?>
278 <?php esc_html_e( "If this solves the problem, something in your theme is probably broken – let the theme's author know.", 'jetpack' ); ?>
279 </li>
280 <li><b><em><?php esc_html_e( 'A problem with your XMLRPC file.', 'jetpack' ); ?></em></b>
281 <?php
282 echo sprintf(
283 wp_kses(
284 /* translators: The URL to the site's xmlrpc.php file. */
285 __( 'Load your <a href="%s">XMLRPC file</a>. It should say “XML-RPC server accepts POST requests only.” on a line by itself.', 'jetpack' ),
286 array( 'a' => array( 'href' => array() ) )
287 ),
288 esc_attr( site_url( 'xmlrpc.php' ) )
289 );
290 ?>
291 <ul>
292 <li>- <?php esc_html_e( "If it's not by itself, a theme or plugin is displaying extra characters. Try steps 2 and 3.", 'jetpack' ); ?></li>
293 <li>- <?php esc_html_e( 'If you get a 404 message, contact your web host. Their security may block XMLRPC.', 'jetpack' ); ?></li>
294 </ul>
295 </li>
296 <?php if ( current_user_can( 'jetpack_disconnect' ) && Jetpack::is_active() ) : ?>
297 <li>
298 <strong><em><?php esc_html_e( 'A connection problem with WordPress.com.', 'jetpack' ); ?></em></strong>
299 <?php
300 echo sprintf(
301 wp_kses(
302 /* translators: URL to disconnect and reconnect Jetpack. */
303 __( 'Jetpack works by connecting to WordPress.com for a lot of features. Sometimes, when the connection gets messed up, you need to disconnect and reconnect to get things working properly. <a href="%s">Disconnect from WordPress.com</a>', 'jetpack' ),
304 array(
305 'a' => array(
306 'href' => array(),
307 'class' => array(),
308 ),
309 )
310 ),
311 esc_attr(
312 wp_nonce_url(
313 Jetpack::admin_url(
314 array(
315 'page' => 'jetpack-debugger',
316 'disconnect' => true,
317 )
318 ),
319 'jp_disconnect',
320 'nonce'
321 )
322 )
323 );
324 ?>
325 </li>
326 <?php endif; ?>
327 </ol>
328 <h4><?php esc_html_e( 'Still having trouble?', 'jetpack' ); ?></h4>
329 <p><b><em><?php esc_html_e( 'Ask us for help!', 'jetpack' ); ?></em></b>
330 <?php
331 echo sprintf(
332 wp_kses(
333 /* translators: URL for Jetpack support. */
334 __( '<a href="%s">Contact our Happiness team</a>. When you do, please include the full debug information below.', 'jetpack' ),
335 array( 'a' => array( 'href' => array() ) )
336 ),
337 'https://jetpack.com/contact-support/'
338 );
339 ?>
340 </p>
341 <hr />
342 <?php if ( Jetpack::is_active() ) : ?>
343 <div id="connected-user-details">
344 <h3><?php esc_html_e( 'More details about your Jetpack settings', 'jetpack' ); ?></h3>
345 <p>
346 <?php
347 printf(
348 wp_kses(
349 /* translators: %s is an e-mail address */
350 __( 'The primary connection is owned by <strong>%s</strong>\'s WordPress.com account.', 'jetpack' ),
351 array( 'strong' => array() )
352 ),
353 esc_html( Jetpack::get_master_user_email() )
354 );
355 ?>
356 </p>
357 </div>
358 <?php else : ?>
359 <div id="dev-mode-details">
360 <p>
361 <?php
362 printf(
363 wp_kses(
364 /* translators: Link to a Jetpack support page. */
365 __( 'Would you like to use Jetpack on your local development site? You can do so thanks to <a href="%s">Jetpack\'s development mode</a>.', 'jetpack' ),
366 array( 'a' => array( 'href' => array() ) )
367 ),
368 'https://jetpack.com/support/development-mode/'
369 );
370 ?>
371 </p>
372 </div>
373 <?php endif; ?>
374 <?php
375 if (
376 current_user_can( 'jetpack_manage_modules' )
377 && ( Jetpack::is_development_mode() || Jetpack::is_active() )
378 ) {
379 printf(
380 wp_kses(
381 '<p><a href="%1$s">%2$s</a></p>',
382 array(
383 'a' => array( 'href' => array() ),
384 'p' => array(),
385 )
386 ),
387 esc_attr( Jetpack::admin_url( 'page=jetpack_modules' ) ),
388 esc_html__( 'Access the full list of Jetpack modules available on your site.', 'jetpack' )
389 );
390 }
391 ?>
392 </div>
393 <hr />
394 <div id="toggle_debug_info"><?php esc_html_e( 'Advanced Debug Results', 'jetpack' ); ?></div>
395 <div id="debug_info_div">
396 <h4><?php esc_html_e( 'Debug Info', 'jetpack' ); ?></h4>
397 <div id="debug_info"><pre><?php echo esc_html( $debug_info ); ?></pre></div>
398 </div>
399 </div>
400 <?php
401 }
402
403 /**
404 * Outputs html needed within the <head> for the in-plugin debugger page.
405 */
406 public static function jetpack_debug_admin_head() {
407
408 Jetpack_Admin_Page::load_wrapper_styles();
409 ?>
410 <style type="text/css">
411
412 .jetpack-debug-test-container {
413 margin-top: 20px;
414 margin-bottom: 30px;
415 }
416
417 .jetpack-tests-succeed {
418 font-size: large;
419 color: #8BAB3E;
420 }
421
422 .jetpack-test-details {
423 margin: 4px 6px;
424 padding: 10px;
425 overflow: auto;
426 display: none;
427 }
428
429 .jetpack-test-error {
430 margin-bottom: 10px;
431 background: #FFEBE8;
432 border: solid 1px #C00;
433 border-radius: 3px;
434 }
435
436 .jetpack-test-error p {
437 margin: 0;
438 padding: 0;
439 }
440
441 p.jetpack-test-details {
442 margin: 4px 6px;
443 padding: 10px;
444 }
445
446 .jetpack-test-error a.jetpack-test-heading {
447 padding: 4px 6px;
448 display: block;
449 text-decoration: none;
450 color: inherit;
451 }
452
453 .jetpack-test-error .noticon {
454 float: right;
455 }
456
457 .formbox {
458 margin: 0 0 25px 0;
459 }
460
461 .formbox input[type="text"], .formbox input[type="email"], .formbox input[type="url"], .formbox textarea, #debug_info_div {
462 border: 1px solid #e5e5e5;
463 border-radius: 11px;
464 box-shadow: inset 0 1px 1px rgba(0,0,0,0.1);
465 color: #666;
466 font-size: 14px;
467 padding: 10px;
468 width: 97%;
469 }
470 #debug_info_div {
471 border-radius: 0;
472 margin-top: 16px;
473 background: #FFF;
474 padding: 16px;
475 }
476 .formbox .contact-support input[type="submit"] {
477 float: right;
478 margin: 0 !important;
479 border-radius: 20px !important;
480 cursor: pointer;
481 font-size: 13pt !important;
482 height: auto !important;
483 margin: 0 0 2em 10px !important;
484 padding: 8px 16px !important;
485 background-color: #ddd;
486 border: 1px solid rgba(0,0,0,0.05);
487 border-top-color: rgba(255,255,255,0.1);
488 border-bottom-color: rgba(0,0,0,0.15);
489 color: #333;
490 font-weight: 400;
491 display: inline-block;
492 text-align: center;
493 text-decoration: none;
494 }
495
496 .formbox span.errormsg {
497 margin: 0 0 10px 10px;
498 color: #d00;
499 display: none;
500 }
501
502 .formbox.error span.errormsg {
503 display: block;
504 }
505
506 #debug_info_div, #toggle_debug_info, #debug_info_div p {
507 font-size: 12px;
508 }
509
510 #category_div ul li {
511 list-style-type: none;
512 }
513
514 </style>
515 <script type="text/javascript">
516 jQuery( document ).ready( function($) {
517
518 $( '#debug_info' ).prepend( 'jQuery version: ' + jQuery.fn.jquery + "\r\n" );
519 $( '#debug_form_info' ).prepend( 'jQuery version: ' + jQuery.fn.jquery + "\r\n" );
520
521 $( '.jetpack-test-error .jetpack-test-heading' ).on( 'click', function() {
522 $( this ).parents( '.jetpack-test-error' ).find( '.jetpack-test-details' ).slideToggle();
523 return false;
524 } );
525
526 } );
527 </script>
528 <?php
529 }
530 }
531