Jetpack_Debugger

The Jetpack by WordPress.com Jetpack Debugger class.

Defined (1)

The class is defined in the following location(s).

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