PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 7.4.3
Jetpack – WP Security, Backup, Speed, & Growth v7.4.3
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
441 lines 14.1 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 via the legacy jetpack debugger.
4 *
5 * @package jetpack
6 */
7
8 /** Ensure the Jetpack_Debug_Data class is available. It should be via the library loaded, but defense is good. */
9 require_once 'class-jetpack-debug-data.php';
10
11 /**
12 * Class Jetpack_Debugger
13 *
14 * A namespacing class for functionality related to the legacy in-plugin diagnostic tooling.
15 */
16 class Jetpack_Debugger {
17
18 /**
19 * Determine the active plan and normalize it for the debugger results.
20 *
21 * @return string The plan slug prepended with "JetpackPlan"
22 */
23 private static function what_jetpack_plan() {
24 // Specifically not deprecating this function since it modifies the output of the Jetpack_Debug_Data::what_jetpack_plan return.
25 return 'JetpackPlan' . Jetpack_Debug_Data::what_jetpack_plan();
26 }
27
28 /**
29 * Convert seconds to human readable time.
30 *
31 * A dedication function instead of using Core functionality to allow for output in seconds.
32 *
33 * @deprecated 7.3.0
34 *
35 * @param int $seconds Number of seconds to convert to human time.
36 *
37 * @return string Human readable time.
38 */
39 public static function seconds_to_time( $seconds ) {
40 _deprecated_function( 'Jetpack_Debugger::seconds_to_time', 'Jetpack 7.3.0', 'Jeptack_Debug_Data::seconds_to_time' );
41 return Jetpack_Debug_Data::seconds_to_time( $seconds );
42 }
43
44 /**
45 * Returns 30 for use with a filter.
46 *
47 * To allow time for WP.com to run upstream testing, this function exists to increase the http_request_timeout value
48 * to 30.
49 *
50 * @return int 30
51 */
52 public static function jetpack_increase_timeout() {
53 return 30; // seconds.
54 }
55
56 /**
57 * Disconnect Jetpack and redirect user to connection flow.
58 */
59 public static function disconnect_and_redirect() {
60 if ( ! ( isset( $_GET['nonce'] ) && wp_verify_nonce( $_GET['nonce'], 'jp_disconnect' ) ) ) {
61 return;
62 }
63
64 if ( isset( $_GET['disconnect'] ) && $_GET['disconnect'] ) {
65 if ( Jetpack::is_active() ) {
66 Jetpack::disconnect();
67 wp_safe_redirect( Jetpack::admin_url() );
68 exit;
69 }
70 }
71 }
72
73 /**
74 * Handles output to the browser for the in-plugin debugger.
75 */
76 public static function jetpack_debug_display_handler() {
77 global $wp_version;
78 if ( ! current_user_can( 'manage_options' ) ) {
79 wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'jetpack' ) );
80 }
81
82 $data = Jetpack_Debug_Data::debug_data();
83 $debug_info = '';
84 foreach ( $data as $datum ) {
85 $debug_info .= $datum['label'] . ': ' . $datum['value'] . "\r\n";
86 }
87
88 $debug_info .= "\r\n" . esc_html( 'PHP_VERSION: ' . PHP_VERSION );
89 $debug_info .= "\r\n" . esc_html( 'WORDPRESS_VERSION: ' . $GLOBALS['wp_version'] );
90 $debug_info .= "\r\n" . esc_html( 'SITE_URL: ' . site_url() );
91 $debug_info .= "\r\n" . esc_html( 'HOME_URL: ' . home_url() );
92
93 $debug_info .= "\r\n\r\nTEST RESULTS:\r\n\r\n";
94
95 $cxntests = new Jetpack_Cxn_Tests();
96 ?>
97 <div class="wrap">
98 <h2><?php esc_html_e( 'Debugging Center', 'jetpack' ); ?></h2>
99 <h3><?php esc_html_e( "Testing your site's compatibility with Jetpack...", 'jetpack' ); ?></h3>
100 <div class="jetpack-debug-test-container">
101 <?php
102 if ( $cxntests->pass() ) {
103 echo '<div class="jetpack-tests-succeed">' . esc_html__( 'Your Jetpack setup looks a-okay!', 'jetpack' ) . '</div>';
104 $debug_info .= "All tests passed.\r\n";
105 $debug_info .= print_r( $cxntests->raw_results(), true ); //phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r
106 } else {
107 $failures = $cxntests->list_fails();
108 foreach ( $failures as $fail ) {
109 echo '<div class="jetpack-test-error">';
110 echo '<p><a class="jetpack-test-heading" href="#">' . esc_html( $fail['message'] );
111 echo '<span class="noticon noticon-collapse"></span></a></p>';
112 echo '<p class="jetpack-test-details">' . esc_html( $fail['resolution'] ) . '</p>';
113 echo '</div>';
114
115 $debug_info .= "FAILED TESTS!\r\n";
116 $debug_info .= $fail['name'] . ': ' . $fail['message'] . "\r\n";
117 $debug_info .= print_r( $cxntests->raw_results(), true ); //phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r
118 }
119 }
120 ?>
121 </div>
122 <div class="entry-content">
123 <h3><?php esc_html_e( 'Trouble with Jetpack?', 'jetpack' ); ?></h3>
124 <h4><?php esc_html_e( 'It may be caused by one of these issues, which you can diagnose yourself:', 'jetpack' ); ?></h4>
125 <ol>
126 <li><b><em>
127 <?php
128 esc_html_e( 'A known issue.', 'jetpack' );
129 ?>
130 </em></b>
131 <?php
132 echo sprintf(
133 wp_kses(
134 /* translators: URLs to Jetpack support pages. */
135 __( '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' ),
136 array(
137 'a' => array(
138 'href' => array(),
139 'target' => array(),
140 ),
141 )
142 ),
143 'http://jetpack.com/support/getting-started-with-jetpack/known-issues/',
144 'http://jetpack.com/support/getting-started-with-jetpack/known-issues/',
145 'http://jetpack.com/support/',
146 'https://wordpress.org/support/plugin/jetpack'
147 );
148 ?>
149 </li>
150 <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>
151 <li>
152 <b><em><?php esc_html_e( 'A theme conflict.', 'jetpack' ); ?></em></b>
153 <?php
154 $default_theme = wp_get_theme( WP_DEFAULT_THEME );
155
156 if ( $default_theme->exists() ) {
157 /* translators: %s is the name of a theme */
158 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' ) ) );
159 } else {
160 esc_html_e( "If your problem isn't known or caused by a plugin, try activating the default WordPress theme.", 'jetpack' );
161 }
162 ?>
163 <?php esc_html_e( "If this solves the problem, something in your theme is probably broken – let the theme's author know.", 'jetpack' ); ?>
164 </li>
165 <li><b><em><?php esc_html_e( 'A problem with your XMLRPC file.', 'jetpack' ); ?></em></b>
166 <?php
167 echo sprintf(
168 wp_kses(
169 /* translators: The URL to the site's xmlrpc.php file. */
170 __( 'Load your <a href="%s">XMLRPC file</a>. It should say “XML-RPC server accepts POST requests only.” on a line by itself.', 'jetpack' ),
171 array( 'a' => array( 'href' => array() ) )
172 ),
173 esc_attr( site_url( 'xmlrpc.php' ) )
174 );
175 ?>
176 <ul>
177 <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>
178 <li>- <?php esc_html_e( 'If you get a 404 message, contact your web host. Their security may block XMLRPC.', 'jetpack' ); ?></li>
179 </ul>
180 </li>
181 <?php if ( current_user_can( 'jetpack_disconnect' ) && Jetpack::is_active() ) : ?>
182 <li>
183 <strong><em><?php esc_html_e( 'A connection problem with WordPress.com.', 'jetpack' ); ?></em></strong>
184 <?php
185 echo sprintf(
186 wp_kses(
187 /* translators: URL to disconnect and reconnect Jetpack. */
188 __( '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' ),
189 array(
190 'a' => array(
191 'href' => array(),
192 'class' => array(),
193 ),
194 )
195 ),
196 esc_attr(
197 wp_nonce_url(
198 Jetpack::admin_url(
199 array(
200 'page' => 'jetpack-debugger',
201 'disconnect' => true,
202 )
203 ),
204 'jp_disconnect',
205 'nonce'
206 )
207 )
208 );
209 ?>
210 </li>
211 <?php endif; ?>
212 </ol>
213 <h4><?php esc_html_e( 'Still having trouble?', 'jetpack' ); ?></h4>
214 <p><b><em><?php esc_html_e( 'Ask us for help!', 'jetpack' ); ?></em></b>
215 <?php
216 /**
217 * Offload to new WordPress debug data in WP 5.2+
218 *
219 * @todo remove fallback when 5.2 is the minimum supported.
220 */
221 if ( version_compare( $wp_version, '5.2-alpha', '>=' ) ) {
222 echo sprintf(
223 wp_kses(
224 /* translators: URL for Jetpack support. URL for WordPress's Site Health */
225 __( '<a href="%1$s">Contact our Happiness team</a>. When you do, please include the <a href="%2$s">full debug information from your site</a>.', 'jetpack' ),
226 array( 'a' => array( 'href' => array() ) )
227 ),
228 'https://jetpack.com/contact-support/',
229 esc_url( admin_url() . 'site-health.php?tab=debug' )
230 );
231 $hide_debug = true;
232 } else { // Versions before 5.2, fallback.
233 echo sprintf(
234 wp_kses(
235 /* translators: URL for Jetpack support. */
236 __( '<a href="%s">Contact our Happiness team</a>. When you do, please include the full debug information below.', 'jetpack' ),
237 array( 'a' => array( 'href' => array() ) )
238 ),
239 'https://jetpack.com/contact-support/'
240 );
241 $hide_debug = false;
242 }
243 ?>
244 </p>
245 <hr />
246 <?php if ( Jetpack::is_active() ) : ?>
247 <div id="connected-user-details">
248 <h3><?php esc_html_e( 'More details about your Jetpack settings', 'jetpack' ); ?></h3>
249 <p>
250 <?php
251 printf(
252 wp_kses(
253 /* translators: %s is an e-mail address */
254 __( 'The primary connection is owned by <strong>%s</strong>\'s WordPress.com account.', 'jetpack' ),
255 array( 'strong' => array() )
256 ),
257 esc_html( Jetpack::get_master_user_email() )
258 );
259 ?>
260 </p>
261 </div>
262 <?php else : ?>
263 <div id="dev-mode-details">
264 <p>
265 <?php
266 printf(
267 wp_kses(
268 /* translators: Link to a Jetpack support page. */
269 __( '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' ),
270 array( 'a' => array( 'href' => array() ) )
271 ),
272 'https://jetpack.com/support/development-mode/'
273 );
274 ?>
275 </p>
276 </div>
277 <?php endif; ?>
278 <?php
279 if (
280 current_user_can( 'jetpack_manage_modules' )
281 && ( Jetpack::is_development_mode() || Jetpack::is_active() )
282 ) {
283 printf(
284 wp_kses(
285 '<p><a href="%1$s">%2$s</a></p>',
286 array(
287 'a' => array( 'href' => array() ),
288 'p' => array(),
289 )
290 ),
291 esc_attr( Jetpack::admin_url( 'page=jetpack_modules' ) ),
292 esc_html__( 'Access the full list of Jetpack modules available on your site.', 'jetpack' )
293 );
294 }
295 ?>
296 </div>
297 <hr />
298 <?php
299 if ( ! $hide_debug ) {
300 ?>
301 <div id="toggle_debug_info"><?php esc_html_e( 'Advanced Debug Results', 'jetpack' ); ?></div>
302 <div id="debug_info_div">
303 <h4><?php esc_html_e( 'Debug Info', 'jetpack' ); ?></h4>
304 <div id="debug_info"><pre><?php echo esc_html( $debug_info ); ?></pre></div>
305 </div>
306 <?php
307 }
308 ?>
309 </div>
310 <?php
311 }
312
313 /**
314 * Outputs html needed within the <head> for the in-plugin debugger page.
315 */
316 public static function jetpack_debug_admin_head() {
317
318 Jetpack_Admin_Page::load_wrapper_styles();
319 ?>
320 <style type="text/css">
321
322 .jetpack-debug-test-container {
323 margin-top: 20px;
324 margin-bottom: 30px;
325 }
326
327 .jetpack-tests-succeed {
328 font-size: large;
329 color: #8BAB3E;
330 }
331
332 .jetpack-test-details {
333 margin: 4px 6px;
334 padding: 10px;
335 overflow: auto;
336 display: none;
337 }
338
339 .jetpack-test-error {
340 margin-bottom: 10px;
341 background: #FFEBE8;
342 border: solid 1px #C00;
343 border-radius: 3px;
344 }
345
346 .jetpack-test-error p {
347 margin: 0;
348 padding: 0;
349 }
350
351 p.jetpack-test-details {
352 margin: 4px 6px;
353 padding: 10px;
354 }
355
356 .jetpack-test-error a.jetpack-test-heading {
357 padding: 4px 6px;
358 display: block;
359 text-decoration: none;
360 color: inherit;
361 }
362
363 .jetpack-test-error .noticon {
364 float: right;
365 }
366
367 .formbox {
368 margin: 0 0 25px 0;
369 }
370
371 .formbox input[type="text"], .formbox input[type="email"], .formbox input[type="url"], .formbox textarea, #debug_info_div {
372 border: 1px solid #e5e5e5;
373 border-radius: 11px;
374 box-shadow: inset 0 1px 1px rgba(0,0,0,0.1);
375 color: #666;
376 font-size: 14px;
377 padding: 10px;
378 width: 97%;
379 }
380 #debug_info_div {
381 border-radius: 0;
382 margin-top: 16px;
383 background: #FFF;
384 padding: 16px;
385 }
386 .formbox .contact-support input[type="submit"] {
387 float: right;
388 margin: 0 !important;
389 border-radius: 20px !important;
390 cursor: pointer;
391 font-size: 13pt !important;
392 height: auto !important;
393 margin: 0 0 2em 10px !important;
394 padding: 8px 16px !important;
395 background-color: #ddd;
396 border: 1px solid rgba(0,0,0,0.05);
397 border-top-color: rgba(255,255,255,0.1);
398 border-bottom-color: rgba(0,0,0,0.15);
399 color: #333;
400 font-weight: 400;
401 display: inline-block;
402 text-align: center;
403 text-decoration: none;
404 }
405
406 .formbox span.errormsg {
407 margin: 0 0 10px 10px;
408 color: #d00;
409 display: none;
410 }
411
412 .formbox.error span.errormsg {
413 display: block;
414 }
415
416 #debug_info_div, #toggle_debug_info, #debug_info_div p {
417 font-size: 12px;
418 }
419
420 #category_div ul li {
421 list-style-type: none;
422 }
423
424 </style>
425 <script type="text/javascript">
426 jQuery( document ).ready( function($) {
427
428 $( '#debug_info' ).prepend( 'jQuery version: ' + jQuery.fn.jquery + "\r\n" );
429 $( '#debug_form_info' ).prepend( 'jQuery version: ' + jQuery.fn.jquery + "\r\n" );
430
431 $( '.jetpack-test-error .jetpack-test-heading' ).on( 'click', function() {
432 $( this ).parents( '.jetpack-test-error' ).find( '.jetpack-test-details' ).slideToggle();
433 return false;
434 } );
435
436 } );
437 </script>
438 <?php
439 }
440 }
441