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