PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.2-a.5
Jetpack – WP Security, Backup, Speed, & Growth v16.2-a.5
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 14.4.2 All 500 releases
jetpack / _inc / lib / debugger / class-jetpack-debugger.php
class-jetpack-debugger.php
368 lines 12.5 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 automattic/jetpack
6 */
7
8 use Automattic\Jetpack\Redirect;
9 use Automattic\Jetpack\Status;
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 * Disconnect Jetpack and redirect user to connection flow.
19 *
20 * Used in class.jetpack-admin.php.
21 */
22 public static function disconnect_and_redirect() {
23 if ( ! ( isset( $_GET['nonce'] ) && wp_verify_nonce( $_GET['nonce'], 'jp_disconnect' ) ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
24 return;
25 }
26
27 if ( ! empty( $_GET['disconnect'] ) ) {
28 if ( Jetpack::is_connection_ready() ) {
29 Jetpack::disconnect();
30 wp_safe_redirect( Jetpack::admin_url() );
31 exit( 0 );
32 }
33 }
34 }
35
36 /**
37 * Handles output to the browser for the in-plugin debugger.
38 */
39 public static function jetpack_debug_display_handler() {
40 if ( ! current_user_can( 'manage_options' ) ) {
41 wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'jetpack' ) );
42 }
43
44 $support_url = Jetpack::is_development_version()
45 ? Redirect::get_url( 'jetpack-contact-support-beta-group' )
46 : Redirect::get_url( 'jetpack-contact-support' );
47
48 $cxntests = new Automattic\Jetpack\Connection\Connection_Health_Tests();
49 ?>
50 <div class="wrap">
51 <div class="jp-static-block">
52 <h2><?php esc_html_e( 'Debugging Center', 'jetpack' ); ?></h2>
53
54 <div class="jp-static-block-body">
55 <h3><?php esc_html_e( "Testing your site's compatibility with Jetpack...", 'jetpack' ); ?></h3>
56 <div class="jetpack-debug-test-container">
57 <?php
58 if ( $cxntests->pass() ) {
59 echo '<div class="jetpack-tests-succeed">' . esc_html__( 'Your Jetpack setup looks a-okay!', 'jetpack' ) . '</div>';
60 } else {
61 $failures = $cxntests->list_fails();
62 foreach ( $failures as $fail ) {
63 ?>
64 <div class="notice notice-error inline">
65 <div class="notice-icon-wrapper">
66 <svg xmlns="http://www.w3.org/2000/svg" viewBox="-2 -2 24 24" width="24" height="24" class="y_IPyP1wIAOhyNaqvXJq" aria-hidden="true" focusable="false"><path d="M10 2c4.42 0 8 3.58 8 8s-3.58 8-8 8-8-3.58-8-8 3.58-8 8-8zm1.13 9.38l.35-6.46H8.52l.35 6.46h2.26zm-.09 3.36c.24-.23.37-.55.37-.96 0-.42-.12-.74-.36-.97s-.59-.35-1.06-.35-.82.12-1.07.35-.37.55-.37.97c0 .41.13.73.38.96.26.23.61.34 1.06.34s.8-.11 1.05-.34z"></path></svg>
67 </div>
68
69 <div class="notice-main-content">
70 <div class="notice-title"><?php echo esc_html( $fail['short_description'] ); ?></div>
71
72 <div class="notice-action-bar">
73 <div>
74 <a href="<?php echo esc_attr( $fail['action'] ); ?>" aria-disabled="false" class="components-button is-primary"><span><?php echo esc_html( $fail['action_label'] ); ?></span></a>
75 </div>
76 </div>
77 </div>
78 </div>
79 <?php
80 }
81 }
82 ?>
83 </div>
84
85 <div class="entry-content">
86 <h4><?php esc_html_e( 'Trouble with Jetpack?', 'jetpack' ); ?></h4>
87 <p><?php esc_html_e( 'It may be caused by one of these issues, which you can diagnose yourself:', 'jetpack' ); ?></p>
88 <ol>
89 <li><?php esc_html_e( 'A known issue.', 'jetpack' ); ?>
90 <?php
91 printf(
92 wp_kses(
93 /* translators: URLs to Jetpack support pages. */
94 __( 'Some themes and plugins have <a href="%1$s" target="_blank" rel="noopener noreferrer">known conflicts</a> with Jetpack – check the list. (You can also browse the <a href="%2$s" target="_blank" rel="noopener noreferrer">Jetpack support pages</a> or <a href="%3$s" target="_blank" rel="noopener noreferrer">Jetpack support forum</a> to see if others have experienced and solved the problem.)', 'jetpack' ),
95 array(
96 'a' => array(
97 'href' => array(),
98 'target' => array(),
99 'rel' => array(),
100 ),
101 )
102 ),
103 esc_url( Redirect::get_url( 'jetpack-contact-support-known-issues' ) ),
104 esc_url( Redirect::get_url( 'jetpack-support' ) ),
105 esc_url( Redirect::get_url( 'wporg-support-plugin-jetpack' ) )
106 );
107 ?>
108 </li>
109 <li>
110 <?php esc_html_e( 'An incompatible plugin.', 'jetpack' ); ?>
111 <?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' ); ?>
112 </li>
113 <li>
114 <?php esc_html_e( 'A theme conflict.', 'jetpack' ); ?>
115 <?php
116 $default_theme = wp_get_theme( WP_DEFAULT_THEME );
117
118 if ( $default_theme->exists() ) {
119 /* translators: %s is the name of a theme */
120 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' ) ) );
121 } else {
122 esc_html_e( "If your problem isn't known or caused by a plugin, try activating the default WordPress theme.", 'jetpack' );
123 }
124 ?>
125 <?php esc_html_e( "If this solves the problem, something in your theme is probably broken – let the theme's author know.", 'jetpack' ); ?>
126 </li>
127 <li>
128 <?php esc_html_e( 'A problem with your XML-RPC file.', 'jetpack' ); ?>
129 <?php
130 printf(
131 wp_kses(
132 /* translators: The URL to the site's xmlrpc.php file. */
133 __( 'Load your <a href="%s">XML-RPC file</a>. It should say “XML-RPC server accepts POST requests only.” on a line by itself.', 'jetpack' ),
134 array( 'a' => array( 'href' => array() ) )
135 ),
136 esc_attr( site_url( 'xmlrpc.php' ) )
137 );
138 ?>
139 <ul>
140 <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>
141 <li><?php esc_html_e( 'If you get a 404 message, contact your web host. Their security may block the XML-RPC file.', 'jetpack' ); ?></li>
142 </ul>
143 </li>
144
145 <?php if ( current_user_can( 'jetpack_disconnect' ) && Jetpack::is_connection_ready() ) : ?>
146 <li>
147 <?php esc_html_e( 'A connection problem with WordPress.com.', 'jetpack' ); ?>
148 <?php
149 printf(
150 wp_kses(
151 /* translators: URL to disconnect and reconnect Jetpack. */
152 __( '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' ),
153 array(
154 'a' => array(
155 'href' => array(),
156 'class' => array(),
157 ),
158 )
159 ),
160 esc_attr(
161 wp_nonce_url(
162 Jetpack::admin_url(
163 array(
164 'page' => 'jetpack-debugger',
165 'disconnect' => true,
166 )
167 ),
168 'jp_disconnect',
169 'nonce'
170 )
171 )
172 );
173 ?>
174 </li>
175 <?php endif; ?>
176 </ol>
177
178 <h4><?php esc_html_e( 'Still having trouble?', 'jetpack' ); ?></h4>
179 <p>
180 <?php esc_html_e( 'Ask us for help!', 'jetpack' ); ?>
181
182 <?php
183 /**
184 * Offload to new WordPress debug data.
185 */
186 printf(
187 wp_kses(
188 /* translators: URL for Jetpack support. URL for WordPress's Site Health */
189 __( '<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' ),
190 array( 'a' => array( 'href' => array() ) )
191 ),
192 esc_url( $support_url ),
193 esc_url( admin_url() . 'site-health.php?tab=debug' )
194 );
195 ?>
196 </p>
197 </div>
198 </div>
199 </div>
200
201 <div class="jp-static-block">
202 <h2><?php esc_html_e( 'More details about your Jetpack settings', 'jetpack' ); ?></h2>
203
204 <div class="jp-static-block-body">
205 <?php if ( Jetpack::is_connection_ready() ) : ?>
206 <div id="connected-user-details">
207 <p>
208 <?php
209 printf(
210 wp_kses(
211 /* translators: %s is an e-mail address */
212 __( 'The primary connection is owned by <strong>%s</strong>\'s WordPress.com account.', 'jetpack' ),
213 array( 'strong' => array() )
214 ),
215 esc_html( Jetpack::get_master_user_email() )
216 );
217 ?>
218 </p>
219 </div>
220 <?php else : ?>
221 <div id="dev-mode-details">
222 <p>
223 <?php
224 printf(
225 wp_kses(
226 /* translators: Link to a Jetpack support page. */
227 __( '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' ),
228 array( 'a' => array( 'href' => array() ) )
229 ),
230 esc_url( Redirect::get_url( 'jetpack-support-development-mode' ) )
231 );
232 ?>
233 </p>
234 </div>
235 <?php endif; ?>
236
237 <?php
238 if (
239 current_user_can( 'jetpack_manage_modules' )
240 && ( ( new Status() )->is_offline_mode() || Jetpack::is_connection_ready() )
241 ) {
242 printf(
243 wp_kses(
244 '<p><a href="%1$s">%2$s</a></p>',
245 array(
246 'a' => array( 'href' => array() ),
247 'p' => array(),
248 )
249 ),
250 esc_attr( Jetpack::admin_url( 'page=jetpack_modules' ) ),
251 esc_html__( 'Access the full list of Jetpack modules available on your site.', 'jetpack' )
252 );
253 }
254 ?>
255 </div>
256 </div>
257 </div>
258 <?php
259 }
260
261 /**
262 * Outputs html needed within the <head> for the in-plugin debugger page.
263 */
264 public static function jetpack_debug_admin_head() {
265
266 $min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
267 wp_enqueue_style( 'jetpack-admin', plugins_url( "css/jetpack-admin{$min}.css", JETPACK__PLUGIN_FILE ), array( 'genericons', 'jetpack-connection' ), JETPACK__VERSION . '-20121016' );
268 wp_style_add_data( 'jetpack-admin', 'rtl', 'replace' );
269 wp_style_add_data( 'jetpack-admin', 'suffix', $min );
270
271 Jetpack_Admin_Page::load_wrapper_styles();
272 ?>
273 <style type="text/css">
274
275 .jetpack-debug-test-container {
276 margin: 8px 0;
277 }
278
279 #connected-user-details p strong {
280 word-break: break-all;
281 }
282
283 .jetpack-tests-succeed {
284 font-size: large;
285 color: #069E08;
286 }
287
288 .jetpack-test-details {
289 margin: 4px 6px;
290 padding: 10px;
291 overflow: auto;
292 display: none;
293 }
294
295 .formbox {
296 margin: 0 0 25px 0;
297 }
298
299 .formbox input[type="text"], .formbox input[type="email"], .formbox input[type="url"], .formbox textarea, #debug_info_div {
300 border: 1px solid var(--wpds-color-stroke-surface-neutral-weak, #e4e4e4);
301 border-radius: var(--wpds-border-radius-md, 4px);
302 color: #646970;
303 font-size: 14px;
304 padding: 10px;
305 width: 97%;
306 }
307 #debug_info_div {
308 border-radius: var(--wpds-border-radius-lg, 8px);
309 margin-top: 16px;
310 background: var(--wpds-color-background-surface-neutral-strong, #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
333 .formbox span.errormsg {
334 margin: 0 0 10px 10px;
335 color: #d00;
336 display: none;
337 }
338
339 .formbox.error span.errormsg {
340 display: block;
341 }
342
343 #debug_info_div, #toggle_debug_info, #debug_info_div p {
344 font-size: 12px;
345 }
346
347 #category_div ul li {
348 list-style-type: none;
349 }
350
351 </style>
352 <script type="text/javascript">
353 jQuery( document ).ready( function($) {
354
355 $( '#debug_info' ).prepend( 'jQuery version: ' + jQuery.fn.jquery + "\r\n" );
356 $( '#debug_form_info' ).prepend( 'jQuery version: ' + jQuery.fn.jquery + "\r\n" );
357
358 $( '.jetpack-test-error .jetpack-test-heading' ).on( 'click', function() {
359 $( this ).parents( '.jetpack-test-error' ).find( '.jetpack-test-details' ).slideToggle();
360 return false;
361 } );
362
363 } );
364 </script>
365 <?php
366 }
367 }
368