Няма описание

class-jetpack-debugger.php 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. <?php
  2. /**
  3. * Jetpack Debugger functionality allowing for self-service diagnostic information via the legacy jetpack debugger.
  4. *
  5. * @package automattic/jetpack
  6. */
  7. use Automattic\Jetpack\Redirect;
  8. use Automattic\Jetpack\Status;
  9. /**
  10. * Class Jetpack_Debugger
  11. *
  12. * A namespacing class for functionality related to the legacy in-plugin diagnostic tooling.
  13. */
  14. class Jetpack_Debugger {
  15. /**
  16. * Returns 30 for use with a filter.
  17. *
  18. * To allow time for WP.com to run upstream testing, this function exists to increase the http_request_timeout value
  19. * to 30.
  20. *
  21. * @deprecated 8.0.0
  22. *
  23. * @return int 30
  24. */
  25. public static function jetpack_increase_timeout() {
  26. _deprecated_function( __METHOD__, 'jetpack-8.0', 'Jetpack_Cxn_Tests::increase_timeout' );
  27. return 30; // seconds.
  28. }
  29. /**
  30. * Disconnect Jetpack and redirect user to connection flow.
  31. *
  32. * Used in class.jetpack-admin.php.
  33. */
  34. public static function disconnect_and_redirect() {
  35. if ( ! ( isset( $_GET['nonce'] ) && wp_verify_nonce( $_GET['nonce'], 'jp_disconnect' ) ) ) {
  36. return;
  37. }
  38. if ( isset( $_GET['disconnect'] ) && $_GET['disconnect'] ) {
  39. if ( Jetpack::is_connection_ready() ) {
  40. Jetpack::disconnect();
  41. wp_safe_redirect( Jetpack::admin_url() );
  42. exit;
  43. }
  44. }
  45. }
  46. /**
  47. * Handles output to the browser for the in-plugin debugger.
  48. */
  49. public static function jetpack_debug_display_handler() {
  50. if ( ! current_user_can( 'manage_options' ) ) {
  51. wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'jetpack' ) );
  52. }
  53. $support_url = Jetpack::is_development_version()
  54. ? Redirect::get_url( 'jetpack-contact-support-beta-group' )
  55. : Redirect::get_url( 'jetpack-contact-support' );
  56. $cxntests = new Jetpack_Cxn_Tests();
  57. ?>
  58. <div class="wrap">
  59. <h2><?php esc_html_e( 'Debugging Center', 'jetpack' ); ?></h2>
  60. <h3><?php esc_html_e( "Testing your site's compatibility with Jetpack...", 'jetpack' ); ?></h3>
  61. <div class="jetpack-debug-test-container">
  62. <?php
  63. if ( $cxntests->pass() ) {
  64. echo '<div class="jetpack-tests-succeed">' . esc_html__( 'Your Jetpack setup looks a-okay!', 'jetpack' ) . '</div>';
  65. } else {
  66. $failures = $cxntests->list_fails();
  67. foreach ( $failures as $fail ) {
  68. $action_link = $fail['action'];
  69. $action_label = $fail['action_label'];
  70. $action = ( $action_link ) ? '<a href="' . $action_link . '">' . $action_label . '</a>' : $action_label;
  71. echo '<div class="jetpack-test-error">';
  72. echo '<p><a class="jetpack-test-heading" href="#">' . esc_html( $fail['short_description'] );
  73. echo '<span class="noticon noticon-collapse"></span></a></p>';
  74. echo '<p class="jetpack-test-details">' . wp_kses(
  75. $action,
  76. array(
  77. 'a' => array(
  78. 'href' => array(),
  79. 'target' => array(),
  80. 'rel' => array(),
  81. ),
  82. )
  83. ) . '</p>';
  84. echo '</div>';
  85. }
  86. }
  87. ?>
  88. </div>
  89. <div class="entry-content">
  90. <h3><?php esc_html_e( 'Trouble with Jetpack?', 'jetpack' ); ?></h3>
  91. <h4><?php esc_html_e( 'It may be caused by one of these issues, which you can diagnose yourself:', 'jetpack' ); ?></h4>
  92. <ol>
  93. <li><b><em>
  94. <?php
  95. esc_html_e( 'A known issue.', 'jetpack' );
  96. ?>
  97. </em></b>
  98. <?php
  99. echo sprintf(
  100. wp_kses(
  101. /* translators: URLs to Jetpack support pages. */
  102. __( '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' ),
  103. array(
  104. 'a' => array(
  105. 'href' => array(),
  106. 'target' => array(),
  107. ),
  108. )
  109. ),
  110. esc_url( Redirect::get_url( 'jetpack-contact-support-known-issues' ) ),
  111. esc_url( Redirect::get_url( 'jetpack-contact-support-known-issues' ) ),
  112. esc_url( Redirect::get_url( 'jetpack-support' ) ),
  113. esc_url( Redirect::get_url( 'wporg-support-plugin-jetpack' ) )
  114. );
  115. ?>
  116. </li>
  117. <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>
  118. <li>
  119. <b><em><?php esc_html_e( 'A theme conflict.', 'jetpack' ); ?></em></b>
  120. <?php
  121. $default_theme = wp_get_theme( WP_DEFAULT_THEME );
  122. if ( $default_theme->exists() ) {
  123. /* translators: %s is the name of a theme */
  124. 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' ) ) );
  125. } else {
  126. esc_html_e( "If your problem isn't known or caused by a plugin, try activating the default WordPress theme.", 'jetpack' );
  127. }
  128. ?>
  129. <?php esc_html_e( "If this solves the problem, something in your theme is probably broken – let the theme's author know.", 'jetpack' ); ?>
  130. </li>
  131. <li><b><em><?php esc_html_e( 'A problem with your XMLRPC file.', 'jetpack' ); ?></em></b>
  132. <?php
  133. echo sprintf(
  134. wp_kses(
  135. /* translators: The URL to the site's xmlrpc.php file. */
  136. __( 'Load your <a href="%s">XMLRPC file</a>. It should say “XML-RPC server accepts POST requests only.” on a line by itself.', 'jetpack' ),
  137. array( 'a' => array( 'href' => array() ) )
  138. ),
  139. esc_attr( site_url( 'xmlrpc.php' ) )
  140. );
  141. ?>
  142. <ul>
  143. <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>
  144. <li>- <?php esc_html_e( 'If you get a 404 message, contact your web host. Their security may block XMLRPC.', 'jetpack' ); ?></li>
  145. </ul>
  146. </li>
  147. <?php if ( current_user_can( 'jetpack_disconnect' ) && Jetpack::is_connection_ready() ) : ?>
  148. <li>
  149. <strong><em><?php esc_html_e( 'A connection problem with WordPress.com.', 'jetpack' ); ?></em></strong>
  150. <?php
  151. echo sprintf(
  152. wp_kses(
  153. /* translators: URL to disconnect and reconnect Jetpack. */
  154. __( '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' ),
  155. array(
  156. 'a' => array(
  157. 'href' => array(),
  158. 'class' => array(),
  159. ),
  160. )
  161. ),
  162. esc_attr(
  163. wp_nonce_url(
  164. Jetpack::admin_url(
  165. array(
  166. 'page' => 'jetpack-debugger',
  167. 'disconnect' => true,
  168. )
  169. ),
  170. 'jp_disconnect',
  171. 'nonce'
  172. )
  173. )
  174. );
  175. ?>
  176. </li>
  177. <?php endif; ?>
  178. </ol>
  179. <h4><?php esc_html_e( 'Still having trouble?', 'jetpack' ); ?></h4>
  180. <p><b><em><?php esc_html_e( 'Ask us for help!', 'jetpack' ); ?></em></b>
  181. <?php
  182. /**
  183. * Offload to new WordPress debug data.
  184. */
  185. echo sprintf(
  186. wp_kses(
  187. /* translators: URL for Jetpack support. URL for WordPress's Site Health */
  188. __( '<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' ),
  189. array( 'a' => array( 'href' => array() ) )
  190. ),
  191. esc_url( $support_url ),
  192. esc_url( admin_url() . 'site-health.php?tab=debug' )
  193. );
  194. ?>
  195. </p>
  196. <hr />
  197. <?php if ( Jetpack::is_connection_ready() ) : ?>
  198. <div id="connected-user-details">
  199. <h3><?php esc_html_e( 'More details about your Jetpack settings', 'jetpack' ); ?></h3>
  200. <p>
  201. <?php
  202. printf(
  203. wp_kses(
  204. /* translators: %s is an e-mail address */
  205. __( 'The primary connection is owned by <strong>%s</strong>\'s WordPress.com account.', 'jetpack' ),
  206. array( 'strong' => array() )
  207. ),
  208. esc_html( Jetpack::get_master_user_email() )
  209. );
  210. ?>
  211. </p>
  212. </div>
  213. <?php else : ?>
  214. <div id="dev-mode-details">
  215. <p>
  216. <?php
  217. printf(
  218. wp_kses(
  219. /* translators: Link to a Jetpack support page. */
  220. __( 'Would you like to use Jetpack on your local development site? You can do so thanks to <a href="%s">Jetpack\'s offline mode</a>.', 'jetpack' ),
  221. array( 'a' => array( 'href' => array() ) )
  222. ),
  223. esc_url( Redirect::get_url( 'jetpack-support-development-mode' ) )
  224. );
  225. ?>
  226. </p>
  227. </div>
  228. <?php endif; ?>
  229. <?php
  230. if (
  231. current_user_can( 'jetpack_manage_modules' )
  232. && ( ( new Status() )->is_offline_mode() || Jetpack::is_connection_ready() )
  233. ) {
  234. printf(
  235. wp_kses(
  236. '<p><a href="%1$s">%2$s</a></p>',
  237. array(
  238. 'a' => array( 'href' => array() ),
  239. 'p' => array(),
  240. )
  241. ),
  242. esc_attr( Jetpack::admin_url( 'page=jetpack_modules' ) ),
  243. esc_html__( 'Access the full list of Jetpack modules available on your site.', 'jetpack' )
  244. );
  245. }
  246. ?>
  247. </div>
  248. </div>
  249. <?php
  250. }
  251. /**
  252. * Outputs html needed within the <head> for the in-plugin debugger page.
  253. */
  254. public static function jetpack_debug_admin_head() {
  255. Jetpack_Admin_Page::load_wrapper_styles();
  256. ?>
  257. <style type="text/css">
  258. .jetpack-debug-test-container {
  259. margin-top: 20px;
  260. margin-bottom: 30px;
  261. }
  262. .jetpack-tests-succeed {
  263. font-size: large;
  264. color: #8BAB3E;
  265. }
  266. .jetpack-test-details {
  267. margin: 4px 6px;
  268. padding: 10px;
  269. overflow: auto;
  270. display: none;
  271. }
  272. .jetpack-test-error {
  273. margin-bottom: 10px;
  274. background: #FFEBE8;
  275. border: solid 1px #C00;
  276. border-radius: 3px;
  277. }
  278. .jetpack-test-error p {
  279. margin: 0;
  280. padding: 0;
  281. }
  282. p.jetpack-test-details {
  283. margin: 4px 6px;
  284. padding: 10px;
  285. }
  286. .jetpack-test-error a.jetpack-test-heading {
  287. padding: 4px 6px;
  288. display: block;
  289. text-decoration: none;
  290. color: inherit;
  291. }
  292. .jetpack-test-error .noticon {
  293. float: right;
  294. }
  295. .formbox {
  296. margin: 0 0 25px 0;
  297. }
  298. .formbox input[type="text"], .formbox input[type="email"], .formbox input[type="url"], .formbox textarea, #debug_info_div {
  299. border: 1px solid #dcdcde;
  300. border-radius: 11px;
  301. box-shadow: inset 0 1px 1px rgba(0,0,0,0.1);
  302. color: #646970;
  303. font-size: 14px;
  304. padding: 10px;
  305. width: 97%;
  306. }
  307. #debug_info_div {
  308. border-radius: 0;
  309. margin-top: 16px;
  310. background: #FFF;
  311. padding: 16px;
  312. }
  313. .formbox .contact-support input[type="submit"] {
  314. float: right;
  315. margin: 0 !important;
  316. border-radius: 20px !important;
  317. cursor: pointer;
  318. font-size: 13pt !important;
  319. height: auto !important;
  320. margin: 0 0 2em 10px !important;
  321. padding: 8px 16px !important;
  322. background-color: #dcdcde;
  323. border: 1px solid rgba(0,0,0,0.05);
  324. border-top-color: rgba(255,255,255,0.1);
  325. border-bottom-color: rgba(0,0,0,0.15);
  326. color: #333;
  327. font-weight: 400;
  328. display: inline-block;
  329. text-align: center;
  330. text-decoration: none;
  331. }
  332. .formbox span.errormsg {
  333. margin: 0 0 10px 10px;
  334. color: #d00;
  335. display: none;
  336. }
  337. .formbox.error span.errormsg {
  338. display: block;
  339. }
  340. #debug_info_div, #toggle_debug_info, #debug_info_div p {
  341. font-size: 12px;
  342. }
  343. #category_div ul li {
  344. list-style-type: none;
  345. }
  346. </style>
  347. <script type="text/javascript">
  348. jQuery( document ).ready( function($) {
  349. $( '#debug_info' ).prepend( 'jQuery version: ' + jQuery.fn.jquery + "\r\n" );
  350. $( '#debug_form_info' ).prepend( 'jQuery version: ' + jQuery.fn.jquery + "\r\n" );
  351. $( '.jetpack-test-error .jetpack-test-heading' ).on( 'click', function() {
  352. $( this ).parents( '.jetpack-test-error' ).find( '.jetpack-test-details' ).slideToggle();
  353. return false;
  354. } );
  355. } );
  356. </script>
  357. <?php
  358. }
  359. }