PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 2.7.5
Jetpack – WP Security, Backup, Speed, & Growth v2.7.5
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 / class.jetpack-debugger.php

class.jetpack-debugger.php in Jetpack – WP Security, Backup, Speed, & Growth 2.7.5, at class.jetpack-debugger.php

369 lines 14.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Jetpack_Debugger {
4
5 private static function is_jetpack_support_open() {
6 try {
7 $response = wp_remote_request( "http://jetpack.me/is-support-open" );
8 $body = wp_remote_retrieve_body( $response );
9 $json = json_decode( $body );
10 return ( ( bool )$json->is_support_open );
11 }
12 catch ( Exception $e ) {
13 return true;
14 }
15 }
16
17 public static function jetpack_increase_timeout($time) {
18 $time = 20; //seconds
19 return $time;
20 }
21
22 public static function jetpack_debug_display_handler() {
23 if ( ! current_user_can( 'manage_options' ) )
24 wp_die( esc_html__('You do not have sufficient permissions to access this page.', 'jetpack' ) );
25
26 global $current_user;
27 get_currentuserinfo();
28
29 $user_id = get_current_user_id();
30 $user_tokens = Jetpack_Options::get_option( 'user_tokens' );
31 if ( is_array( $user_tokens ) && array_key_exists( $user_id, $user_tokens ) ) {
32 $user_token = $user_tokens[$user_id];
33 } else {
34 $user_token = '[this user has no token]';
35 }
36 unset( $user_tokens );
37
38 $debug_info = "\r\n";
39 foreach ( array(
40 'CLIENT_ID' => 'id',
41 'BLOG_TOKEN' => 'blog_token',
42 'MASTER_USER' => 'master_user',
43 'CERT' => 'fallback_no_verify_ssl_certs',
44 'TIME_DIFF' => 'time_diff',
45 'VERSION' => 'version',
46 'OLD_VERSION' => 'old_version',
47 'PUBLIC' => 'public',
48 ) as $label => $option_name ) {
49 $debug_info .= "\r\n" . esc_html( $label . ": " . Jetpack_Options::get_option( $option_name ) );
50 }
51
52 $debug_info .= "\r\n" . esc_html( "USER_ID: " . $user_id );
53 $debug_info .= "\r\n" . esc_html( "USER_TOKEN: " . $user_token );
54 $debug_info .= "\r\n" . esc_html( "PHP_VERSION: " . PHP_VERSION );
55 $debug_info .= "\r\n" . esc_html( "WORDPRESS_VERSION: " . $GLOBALS['wp_version'] );
56 $debug_info .= "\r\n" . esc_html( "JETPACK__VERSION: " . JETPACK__VERSION );
57 $debug_info .= "\r\n" . esc_html( "JETPACK__PLUGIN_DIR: " . JETPACK__PLUGIN_DIR );
58 $debug_info .= "\r\n" . esc_html( "SITE_URL: " . site_url() );
59 $debug_info .= "\r\n" . esc_html( "HOME_URL: " . home_url() );
60
61 $debug_info .= "\r\n\r\nTEST RESULTS:\r\n\r\n";
62 $debug_raw_info = '';
63
64
65 $tests = array();
66
67 $tests['HTTP']['result'] = wp_remote_get( preg_replace( '/^https:/', 'http:', JETPACK__API_BASE ) . 'test/1/' );
68 $tests['HTTP']['fail_message'] = esc_html__( 'Your site isn’t reaching the Jetpack servers.', 'jetpack' );
69
70 $tests['HTTPS']['result'] = wp_remote_get( preg_replace( '/^http:/', 'https:', JETPACK__API_BASE ) . 'test/1/' );
71 $tests['HTTPS']['fail_message'] = esc_html__( 'Your site isn’t securely reaching the Jetpack servers.', 'jetpack' );
72
73 $identity_crisis_message = '';
74 if ( $identity_crisis = Jetpack::check_identity_crisis( true ) ) {
75 foreach( $identity_crisis as $key => $value ) {
76 $identity_crisis_message .= sprintf( __( 'Your `%1$s` option is set up as `%2$s`, but your WordPress.com connection lists it as `%3$s`!', 'jetpack' ), $key, (string) get_option( $key ), $value ) . "\r\n";
77 }
78 $identity_crisis = new WP_Error( 'identity-crisis', $identity_crisis_message, $identity_crisis );
79 } else {
80 $identity_crisis = 'PASS';
81 }
82 $tests['IDENTITY_CRISIS']['result'] = $identity_crisis;
83 $tests['IDENTITY_CRISIS']['fail_message'] = esc_html__( 'Something has gotten mixed up in your Jetpack Connection!', 'jetpack' );
84
85 $self_xml_rpc_url = home_url( 'xmlrpc.php' );
86
87 $args = array();
88 $testsite_url = Jetpack::fix_url_for_bad_hosts( JETPACK__API_BASE . 'testsite/1/?url=' );
89
90 add_filter( 'http_request_timeout', array( 'Jetpack_Debugger', 'jetpack_increase_timeout' ) );
91
92 $tests['SELF']['result'] = wp_remote_get( $testsite_url . $self_xml_rpc_url );
93 $tests['SELF']['fail_message'] = esc_html__( 'It looks like your site can not communicate properly with Jetpack.', 'jetpack' );
94
95 remove_filter( 'http_request_timeout', array( 'Jetpack_Debugger', 'jetpack_increase_timeout' ) );
96
97 ?>
98 <div class="wrap">
99 <h2><?php esc_html_e( 'Jetpack Debugging Center', 'jetpack' ); ?></h2>
100 <h3><?php _e( "Testing your site's compatibily with Jetpack...", 'jetpack' ); ?></h3>
101 <div class="jetpack-debug-test-container">
102 <?php
103 ob_start();
104 foreach ( $tests as $test_name => $test_info ) :
105 if ( 'PASS' !== $test_info['result'] && ( is_wp_error( $test_info['result'] ) ||
106 false == ( $response_code = wp_remote_retrieve_response_code( $test_info['result'] ) ) ||
107 '200' != $response_code ) ) {
108 $debug_info .= $test_name . ": FAIL\r\n";
109 ?>
110 <div class="jetpack-test-error">
111 <p>
112 <a class="jetpack-test-heading" href="#"><?php echo $test_info['fail_message']; ?>
113 <span class="noticon noticon-collapse"></span>
114 </a>
115 </p>
116 <pre class="jetpack-test-details"><?php echo esc_html( $test_name ); ?>:
117 <?php echo esc_html( is_wp_error( $test_info['result'] ) ? $test_info['result']->get_error_message() : print_r( $test_info['result'], 1 ) ); ?></pre>
118 </div><?php
119 } else {
120 $debug_info .= $test_name . ": PASS\r\n";
121 }
122 $debug_raw_info .= "\r\n\r\n" . $test_name . "\r\n" . esc_html( is_wp_error( $test_info['result'] ) ? $test_info['result']->get_error_message() : print_r( $test_info['result'], 1 ) );
123 ?>
124 <?php endforeach;
125 $html = ob_get_clean();
126
127 if ( '' == trim( $html ) ) {
128 echo '<div class="jetpack-tests-succed">' . esc_html__( 'Your Jetpack setup looks a-okay!', 'jetpack' ) . '</div>';
129 }
130 else {
131 echo '<h3>' . esc_html__( 'There seems to be a problem with your site’s ability to communicate with Jetpack!', 'jetpack' ) . '</h3>';
132 echo $html;
133 }
134 $debug_info .= "\r\n\r\nRAW TEST RESULTS:" . $debug_raw_info ."\r\n";
135 ?>
136 </div>
137 <div class="entry-content">
138 <h3><?php esc_html_e( 'Trouble with Jetpack?', 'jetpack' ); ?></h3>
139 <h4><?php esc_html_e( 'It may be caused by one of these issues, which you can diagnose yourself:', 'jetpack' ); ?></h4>
140 <ol>
141 <li><b><em><?php esc_html_e( 'A known issue.', 'jetpack' ); ?></em></b> <?php echo sprintf( __( '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">Jetpack support pages</a> or <a href="%4$s">Jetpack support forum</a> to see if others have experienced and solved the problem.)', 'jetpack' ), 'http://jetpack.me/support/getting-started-with-jetpack/known-issues/', 'http://jetpack.me/support/getting-started-with-jetpack/known-issues/', 'http://jetpack.me/support/', 'http://wordpress.org/support/plugin/jetpack' ); ?></li>
142 <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>
143 <li><b><em><?php esc_html_e( 'A theme conflict.', 'jetpack' ); ?></em></b> <?php esc_html_e( "If your problem isn't known or caused by a plugin, try activating Twenty Twelve (the default WordPress theme). If this solves the problem, something in your theme is probably broken – let the theme's author know.", 'jetpack' ); ?></li>
144 <li><b><em><?php esc_html_e( 'A problem with your XMLRPC file.', 'jetpack' ); ?></em></b> <?php echo sprintf( __( 'Load your <a href="%s">XMLRPC file</a>. It should say “XML-RPC server accepts POST requests only.” on a line by itself.', 'jetpack' ), site_url( 'xmlrpc.php' ) ); ?>
145 <ul>
146 <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>
147 <li>- <?php esc_html_e( "If you get a 404 message, contact your web host. Their security may block XMLRPC.", 'jetpack' ); ?></li>
148 </ul>
149 </li>
150 </ol>
151 <?php if ( self::is_jetpack_support_open() ): ?>
152 <p class="jetpack-show-contact-form"><?php _e( 'If none of these help you find a solution, <a href="#">click here to contact Jetpack support</a>. Tell us as much as you can about the issue and what steps you\'ve tried to resolve it, and one of our Happiness Engineers will be in touch to help.', 'jetpack' ); ?>
153 </p>
154 <?php endif; ?>
155 </div>
156 <div id="contact-message" style="display:none">
157 <?php if ( self::is_jetpack_support_open() ): ?>
158 <form id="contactme" method="post" action="http://jetpack.me/contact-support/">
159 <input type="hidden" name="action" value="submit">
160 <input type="hidden" name="jetpack" value="needs-service">
161
162 <input type="hidden" name="contact_form" id="contact_form" value="1">
163 <input type="hidden" name="blog_url" id="blog_url" value="<?php echo esc_attr( site_url() ); ?>">
164 <input type="hidden" name="subject" id="subject" value="from: <?php echo esc_attr( site_url() ); ?> Jetpack contact form">
165 <div class="formbox">
166 <label for="message" class="h"><?php esc_html_e( 'Please describe the problem you are having.', 'jetpack' ); ?></label>
167 <textarea name="message" cols="40" rows="7" id="did"></textarea>
168 </div>
169
170 <div id="name_div" class="formbox">
171 <label class="h" for="your_name"><?php esc_html_e( 'Name', 'jetpack' ); ?></label>
172 <span class="errormsg"><?php esc_html_e( 'Let us know your name.', 'jetpack' ); ?></span>
173 <input name="your_name" type="text" id="your_name" value="<?php esc_html_e( $current_user->display_name , 'jetpack'); ?>" size="40">
174 </div>
175
176 <div id="email_div" class="formbox">
177 <label class="h" for="your_email"><?php esc_html_e( 'E-mail', 'jetpack' ); ?></label>
178 <span class="errormsg"><?php esc_html_e( 'Use a valid email address.', 'jetpack' ); ?></span>
179 <input name="your_email" type="text" id="your_email" value="<?php esc_html_e( $current_user->user_email , 'jetpack'); ?>" size="40">
180 </div>
181
182 <div id="toggle_debug_info" class="formbox">
183 <p><?php _e( 'The test results and some other useful debug information will be sent to the support team. Please feel free to <a href="#">review/modify</a> this information.', 'jetpack' ); ?></p>
184 </div>
185
186 <div id="debug_info_div" class="formbox" style="display:none">
187 <label class="h" for="debug_info"><?php esc_html_e( 'Debug Info', 'jetpack' ); ?></label>
188 <textarea name="debug_info" cols="40" rows="7" id="debug_info"><?php echo esc_attr( $debug_info ); ?></textarea>
189 </div>
190
191 <div style="clear: both;"></div>
192
193 <div id="blog_div" class="formbox">
194 <div id="submit_div" class="contact-support">
195 <input type="submit" name="submit" value="Contact Support">
196 </div>
197 </div>
198 <div style="clear: both;"></div>
199 </form>
200 <?php endif; ?>
201 </div>
202 </div>
203 <?php
204 }
205
206 public static function jetpack_debug_admin_head() {
207 ?>
208 <style type="text/css">
209
210 .jetpack-debug-test-container {
211 margin-top: 20px;
212 margin-bottom: 30px;
213 }
214
215 .jetpack-tests-succed {
216 font-size: large;
217 color: #8BAB3E;
218 }
219
220 .jetpack-test-details {
221 margin: 4px 6px;
222 padding: 10px;
223 overflow: auto;
224 display: none;
225 }
226
227 .jetpack-test-error {
228 margin-bottom: 10px;
229 background: #FFEBE8;
230 border: solid 1px #C00;
231 border-radius: 3px;
232 }
233
234 .jetpack-test-error p {
235 margin: 0;
236 padding: 0;
237 }
238
239 .jetpack-test-error a.jetpack-test-heading {
240 padding: 4px 6px;
241 display: block;
242 text-decoration: none;
243 color: inherit;
244 }
245
246 .jetpack-test-error .noticon {
247 float: right;
248 }
249
250 form#contactme {
251 border: 1px solid #dfdfdf;
252 background: #eaf3fa;
253 padding: 20px;
254 margin: 10px;
255 background-color: #eaf3fa;
256 border-radius: 5px;
257 font-size: 15px;
258 font-family: "Open Sans", "Helvetica Neue", sans-serif;
259 }
260
261 form#contactme label.h {
262 color: #444;
263 display: block;
264 font-weight: bold;
265 margin: 0 0 7px 10px;
266 text-shadow: 1px 1px 0 #fff;
267 }
268
269 .formbox {
270 margin: 0 0 25px 0;
271 }
272
273 .formbox input[type="text"], .formbox input[type="email"], .formbox input[type="url"], .formbox textarea {
274 border: 1px solid #e5e5e5;
275 border-radius: 11px;
276 box-shadow: inset 0 1px 1px rgba(0,0,0,0.1);
277 color: #666;
278 font-size: 14px;
279 padding: 10px;
280 width: 97%;
281 }
282 .formbox .contact-support input[type="submit"] {
283 float: right;
284 margin: 0 !important;
285 border-radius: 20px !important;
286 cursor: pointer;
287 font-size: 13pt !important;
288 height: auto !important;
289 margin: 0 0 2em 10px !important;
290 padding: 8px 16px !important;
291 background-color: #ddd;
292 border: 1px solid rgba(0,0,0,0.05);
293 border-top-color: rgba(255,255,255,0.1);
294 border-bottom-color: rgba(0,0,0,0.15);
295 color: #333;
296 font-weight: 400;
297 display: inline-block;
298 text-align: center;
299 text-decoration: none;
300 }
301
302 .formbox span.errormsg {
303 margin: 0 0 10px 10px;
304 color: #d00;
305 display: none;
306 }
307
308 .formbox.error span.errormsg {
309 display: block;
310 }
311
312 #contact-message ul {
313 margin: 0 0 20px 10px;
314 }
315
316 #contact-message li {
317 margin: 0 0 10px 10px;
318 list-style: disc;
319 display: list-item;
320 }
321
322 </style>
323 <script type="text/javascript">
324 jQuery( document ).ready( function($) {
325
326 $('#debug_info').prepend('jQuery version: ' + jQuery.fn.jquery + "\r\n");
327
328 $( '.jetpack-test-error .jetpack-test-heading' ).on( 'click', function() {
329 $( this ).parents( '.jetpack-test-error' ).find( '.jetpack-test-details' ).slideToggle();
330 return false;
331 } );
332
333 $( '.jetpack-show-contact-form a' ).on( 'click', function() {
334 $('#contact-message').slideToggle();
335 return false;
336 } );
337
338 $( '#toggle_debug_info a' ).on( 'click', function() {
339 $('#debug_info_div').slideToggle();
340 return false;
341 } );
342
343 $('form#contactme').on("submit", function(e){
344 var form = $(this);
345 var message = form.find('#did');
346 var name = form.find('#your_name');
347 var email = form.find('#your_email')
348 var validation_error = false;
349 if( !name.val() ) {
350 name.parents('.formbox').addClass('error');
351 validation_error = true;
352 }
353 if( !email.val() ) {
354 email.parents('.formbox').addClass('error');
355 validation_error = true;
356 }
357 if ( validation_error ) {
358 return false;
359 }
360 message.val(message.val() + "\r\n\r\n----------------------------------------------\r\n\r\nDEBUG INFO:\r\n" + $('#debug_info').val() );
361 return true;
362 });
363
364 } );
365 </script>
366 <?php
367 }
368 }
369