| Conditions | 32 |
| Paths | > 20000 |
| Total Lines | 293 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 64 | public static function jetpack_debug_display_handler() { |
||
| 65 | if ( ! current_user_can( 'manage_options' ) ) { |
||
| 66 | wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'jetpack' ) ); |
||
| 67 | } |
||
| 68 | |||
| 69 | $current_user = wp_get_current_user(); |
||
|
|
|||
| 70 | |||
| 71 | $user_id = get_current_user_id(); |
||
| 72 | $user_tokens = Jetpack_Options::get_option( 'user_tokens' ); |
||
| 73 | if ( is_array( $user_tokens ) && array_key_exists( $user_id, $user_tokens ) ) { |
||
| 74 | $user_token = $user_tokens[ $user_id ]; |
||
| 75 | } else { |
||
| 76 | $user_token = '[this user has no token]'; |
||
| 77 | } |
||
| 78 | unset( $user_tokens ); |
||
| 79 | |||
| 80 | $debug_info = "\r\n"; |
||
| 81 | foreach ( array( |
||
| 82 | 'CLIENT_ID' => 'id', |
||
| 83 | 'BLOG_TOKEN' => 'blog_token', |
||
| 84 | 'MASTER_USER' => 'master_user', |
||
| 85 | 'CERT' => 'fallback_no_verify_ssl_certs', |
||
| 86 | 'TIME_DIFF' => 'time_diff', |
||
| 87 | 'VERSION' => 'version', |
||
| 88 | 'OLD_VERSION' => 'old_version', |
||
| 89 | 'PUBLIC' => 'public', |
||
| 90 | ) as $label => $option_name ) { |
||
| 91 | $debug_info .= "\r\n" . esc_html( $label . ': ' . Jetpack_Options::get_option( $option_name ) ); |
||
| 92 | } |
||
| 93 | |||
| 94 | $debug_info .= "\r\n" . esc_html( 'USER_ID: ' . $user_id ); |
||
| 95 | $debug_info .= "\r\n" . esc_html( 'USER_TOKEN: ' . $user_token ); |
||
| 96 | $debug_info .= "\r\n" . esc_html( 'PHP_VERSION: ' . PHP_VERSION ); |
||
| 97 | $debug_info .= "\r\n" . esc_html( 'WORDPRESS_VERSION: ' . $GLOBALS['wp_version'] ); |
||
| 98 | $debug_info .= "\r\n" . esc_html( 'JETPACK__VERSION: ' . JETPACK__VERSION ); |
||
| 99 | $debug_info .= "\r\n" . esc_html( 'JETPACK__PLUGIN_DIR: ' . JETPACK__PLUGIN_DIR ); |
||
| 100 | $debug_info .= "\r\n" . esc_html( 'SITE_URL: ' . site_url() ); |
||
| 101 | $debug_info .= "\r\n" . esc_html( 'HOME_URL: ' . home_url() ); |
||
| 102 | $debug_info .= "\r\n" . esc_html( 'PLAN: ' . self::what_jetpack_plan() ); |
||
| 103 | |||
| 104 | $debug_info .= "\r\n"; |
||
| 105 | |||
| 106 | $debug_info .= "\r\n" . '-- SYNC Status -- '; |
||
| 107 | require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-modules.php'; |
||
| 108 | $sync_module = Jetpack_Sync_Modules::get_module( 'full-sync' ); |
||
| 109 | if ( $sync_module ) { |
||
| 110 | $sync_statuses = $sync_module->get_status(); |
||
| 111 | $human_readable_sync_status = array(); |
||
| 112 | foreach ( $sync_statuses as $sync_status => $sync_status_value ) { |
||
| 113 | $human_readable_sync_status[ $sync_status ] = |
||
| 114 | in_array( $sync_status, array( 'started', 'queue_finished', 'send_started', 'finished' ) ) |
||
| 115 | ? date( 'r', $sync_status_value ) : $sync_status_value; |
||
| 116 | } |
||
| 117 | $debug_info .= "\r\n" . sprintf( esc_html__( 'Jetpack Sync Full Status: `%1$s`', 'jetpack' ), print_r( $human_readable_sync_status, 1 ) ); |
||
| 118 | } |
||
| 119 | |||
| 120 | require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-sender.php'; |
||
| 121 | |||
| 122 | $queue = Jetpack_Sync_Sender::get_instance()->get_sync_queue(); |
||
| 123 | |||
| 124 | $debug_info .= "\r\n" . sprintf( esc_html__( 'Sync Queue size: %1$s', 'jetpack' ), $queue->size() ); |
||
| 125 | $debug_info .= "\r\n" . sprintf( esc_html__( 'Sync Queue lag: %1$s', 'jetpack' ), self::seconds_to_time( $queue->lag() ) ); |
||
| 126 | |||
| 127 | $full_sync_queue = Jetpack_Sync_Sender::get_instance()->get_full_sync_queue(); |
||
| 128 | |||
| 129 | $debug_info .= "\r\n" . sprintf( esc_html__( 'Full Sync Queue size: %1$s', 'jetpack' ), $full_sync_queue->size() ); |
||
| 130 | $debug_info .= "\r\n" . sprintf( esc_html__( 'Full Sync Queue lag: %1$s', 'jetpack' ), self::seconds_to_time( $full_sync_queue->lag() ) ); |
||
| 131 | |||
| 132 | require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-functions.php'; |
||
| 133 | $idc_urls = array( |
||
| 134 | 'home' => Jetpack_Sync_Functions::home_url(), |
||
| 135 | 'siteurl' => Jetpack_Sync_Functions::site_url(), |
||
| 136 | 'WP_HOME' => Jetpack_Constants::is_defined( 'WP_HOME' ) ? Jetpack_Constants::get_constant( 'WP_HOME' ) : '', |
||
| 137 | 'WP_SITEURL' => Jetpack_Constants::is_defined( 'WP_SITEURL' ) ? Jetpack_Constants::get_constant( 'WP_SITEURL' ) : '', |
||
| 138 | ); |
||
| 139 | $debug_info .= "\r\n" . esc_html( sprintf( 'Sync IDC URLs: %s', json_encode( $idc_urls ) ) ); |
||
| 140 | $debug_info .= "\r\n" . esc_html( sprintf( 'Sync error IDC option: %s', json_encode( Jetpack_Options::get_option( 'sync_error_idc' ) ) ) ); |
||
| 141 | $debug_info .= "\r\n" . esc_html( sprintf( 'Sync IDC Optin: %s', (string) Jetpack::sync_idc_optin() ) ); |
||
| 142 | |||
| 143 | $debug_info .= "\r\n"; |
||
| 144 | |||
| 145 | foreach ( array( |
||
| 146 | 'HTTP_HOST', |
||
| 147 | 'SERVER_PORT', |
||
| 148 | 'HTTPS', |
||
| 149 | 'GD_PHP_HANDLER', |
||
| 150 | 'HTTP_AKAMAI_ORIGIN_HOP', |
||
| 151 | 'HTTP_CF_CONNECTING_IP', |
||
| 152 | 'HTTP_CLIENT_IP', |
||
| 153 | 'HTTP_FASTLY_CLIENT_IP', |
||
| 154 | 'HTTP_FORWARDED', |
||
| 155 | 'HTTP_FORWARDED_FOR', |
||
| 156 | 'HTTP_INCAP_CLIENT_IP', |
||
| 157 | 'HTTP_TRUE_CLIENT_IP', |
||
| 158 | 'HTTP_X_CLIENTIP', |
||
| 159 | 'HTTP_X_CLUSTER_CLIENT_IP', |
||
| 160 | 'HTTP_X_FORWARDED', |
||
| 161 | 'HTTP_X_FORWARDED_FOR', |
||
| 162 | 'HTTP_X_IP_TRAIL', |
||
| 163 | 'HTTP_X_REAL_IP', |
||
| 164 | 'HTTP_X_VARNISH', |
||
| 165 | 'REMOTE_ADDR', |
||
| 166 | ) as $header ) { |
||
| 167 | if ( isset( $_SERVER[ $header ] ) ) { |
||
| 168 | $debug_info .= "\r\n" . esc_html( $header . ': ' . $_SERVER[ $header ] ); |
||
| 169 | } |
||
| 170 | } |
||
| 171 | |||
| 172 | $debug_info .= "\r\n" . esc_html( 'PROTECT_TRUSTED_HEADER: ' . json_encode( get_site_option( 'trusted_ip_header' ) ) ); |
||
| 173 | |||
| 174 | $debug_info .= "\r\n\r\nTEST RESULTS:\r\n\r\n"; |
||
| 175 | $debug_raw_info = ''; |
||
| 176 | |||
| 177 | $tests = array(); |
||
| 178 | |||
| 179 | $tests['HTTP']['result'] = wp_remote_get( preg_replace( '/^https:/', 'http:', JETPACK__API_BASE ) . 'test/1/' ); |
||
| 180 | $tests['HTTP']['fail_message'] = esc_html__( 'Your site isn’t reaching the Jetpack servers.', 'jetpack' ); |
||
| 181 | |||
| 182 | $tests['HTTPS']['result'] = wp_remote_get( preg_replace( '/^http:/', 'https:', JETPACK__API_BASE ) . 'test/1/' ); |
||
| 183 | $tests['HTTPS']['fail_message'] = esc_html__( 'Your site isn’t securely reaching the Jetpack servers.', 'jetpack' ); |
||
| 184 | |||
| 185 | $identity_crisis_message = ''; |
||
| 186 | if ( $identity_crisis = Jetpack::check_identity_crisis() ) { |
||
| 187 | $identity_crisis_message .= sprintf( |
||
| 188 | __( 'Your url is set as `%1$s`, but your WordPress.com connection lists it as `%2$s`!', 'jetpack' ), |
||
| 189 | $identity_crisis['home'], |
||
| 190 | $identity_crisis['wpcom_home'] |
||
| 191 | ); |
||
| 192 | $identity_crisis = new WP_Error( 'identity-crisis', $identity_crisis_message, $identity_crisis ); |
||
| 193 | } else { |
||
| 194 | $identity_crisis = 'PASS'; |
||
| 195 | } |
||
| 196 | $tests['IDENTITY_CRISIS']['result'] = $identity_crisis; |
||
| 197 | $tests['IDENTITY_CRISIS']['fail_message'] = esc_html__( 'Something has gotten mixed up in your Jetpack Connection!', 'jetpack' ); |
||
| 198 | |||
| 199 | $tests['SELF']['result'] = self::run_self_test(); |
||
| 200 | |||
| 201 | if ( is_wp_error( $tests['SELF']['result'] ) && 0 == strpos( $tests['SELF']['result']->get_error_message(), 'Operation timed out' ) ) { |
||
| 202 | $tests['SELF']['fail_message'] = esc_html__( 'Your site did not get a response from our debugging service in the expected timeframe. If you are not experiencing other issues, this could be due to a slow connection between your site and our server.', 'jetpack' ); |
||
| 203 | } else { |
||
| 204 | $tests['SELF']['fail_message'] = esc_html__( 'It looks like your site can not communicate properly with Jetpack.', 'jetpack' ); |
||
| 205 | } |
||
| 206 | |||
| 207 | ?> |
||
| 208 | <div class="wrap"> |
||
| 209 | <h2><?php esc_html_e( 'Debugging Center', 'jetpack' ); ?></h2> |
||
| 210 | <?php if ( isset( $can_disconnect ) && $can_disconnect ) : ?> |
||
| 211 | <div id="message" class="updated notice notice-success is-dismissible"><p><?php esc_html_e( 'This site was successfully disconnected.', 'jetpack' ); ?> <a href="<?php echo esc_url( Jetpack::admin_url() ); ?>"><?php esc_html_e( 'Go to connection screen.', 'jetpack' ); ?></a></p> |
||
| 212 | <button type="button" class="notice-dismiss"><span class="screen-reader-text"><?php esc_html_e( 'Dismiss this notice.', 'jetpack' ); ?></span></button></div> |
||
| 213 | <?php else : ?> |
||
| 214 | <h3><?php _e( "Testing your site's compatibility with Jetpack...", 'jetpack' ); ?></h3> |
||
| 215 | <div class="jetpack-debug-test-container"> |
||
| 216 | <?php |
||
| 217 | ob_start(); |
||
| 218 | foreach ( $tests as $test_name => $test_info ) : |
||
| 219 | if ( 'PASS' !== $test_info['result'] && ( is_wp_error( $test_info['result'] ) || |
||
| 220 | false == ( $response_code = wp_remote_retrieve_response_code( $test_info['result'] ) ) || |
||
| 221 | '200' != $response_code ) ) { |
||
| 222 | $debug_info .= $test_name . ": FAIL\r\n"; |
||
| 223 | ?> |
||
| 224 | <div class="jetpack-test-error"> |
||
| 225 | <p> |
||
| 226 | <a class="jetpack-test-heading" href="#"><?php echo $test_info['fail_message']; ?> |
||
| 227 | <span class="noticon noticon-collapse"></span> |
||
| 228 | </a> |
||
| 229 | </p> |
||
| 230 | <pre class="jetpack-test-details"><?php echo esc_html( $test_name ); ?>: |
||
| 231 | <?php echo esc_html( is_wp_error( $test_info['result'] ) ? $test_info['result']->get_error_message() : print_r( $test_info['result'], 1 ) ); ?></pre> |
||
| 232 | </div> |
||
| 233 | <?php |
||
| 234 | } else { |
||
| 235 | $debug_info .= $test_name . ": PASS\r\n"; |
||
| 236 | } |
||
| 237 | $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 ) ); |
||
| 238 | ?> |
||
| 239 | <?php |
||
| 240 | endforeach; |
||
| 241 | $html = ob_get_clean(); |
||
| 242 | |||
| 243 | if ( '' == trim( $html ) ) { |
||
| 244 | echo '<div class="jetpack-tests-succed">' . esc_html__( 'Your Jetpack setup looks a-okay!', 'jetpack' ) . '</div>'; |
||
| 245 | } else { |
||
| 246 | echo '<h3>' . esc_html__( 'There seems to be a problem with your site’s ability to communicate with Jetpack!', 'jetpack' ) . '</h3>'; |
||
| 247 | echo $html; |
||
| 248 | } |
||
| 249 | $debug_info .= "\r\n\r\nRAW TEST RESULTS:" . $debug_raw_info . "\r\n"; |
||
| 250 | ?> |
||
| 251 | </div> |
||
| 252 | <?php endif; ?> |
||
| 253 | |||
| 254 | <div class="entry-content"> |
||
| 255 | <h3><?php esc_html_e( 'Trouble with Jetpack?', 'jetpack' ); ?></h3> |
||
| 256 | <h4><?php esc_html_e( 'It may be caused by one of these issues, which you can diagnose yourself:', 'jetpack' ); ?></h4> |
||
| 257 | <ol> |
||
| 258 | <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" 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' ), 'http://jetpack.com/support/getting-started-with-jetpack/known-issues/', 'http://jetpack.com/support/getting-started-with-jetpack/known-issues/', 'http://jetpack.com/support/', 'https://wordpress.org/support/plugin/jetpack' ); ?></li> |
||
| 259 | <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> |
||
| 260 | <li> |
||
| 261 | <b><em><?php esc_html_e( 'A theme conflict.', 'jetpack' ); ?></em></b> |
||
| 262 | <?php |
||
| 263 | $default_theme = wp_get_theme( WP_DEFAULT_THEME ); |
||
| 264 | |||
| 265 | if ( $default_theme->exists() ) { |
||
| 266 | /* translators: %s is the name of a theme */ |
||
| 267 | 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' ) ) ); |
||
| 268 | } else { |
||
| 269 | esc_html_e( "If your problem isn't known or caused by a plugin, try activating the default WordPress theme.", 'jetpack' ); |
||
| 270 | } |
||
| 271 | ?> |
||
| 272 | <?php esc_html_e( "If this solves the problem, something in your theme is probably broken – let the theme's author know.", 'jetpack' ); ?> |
||
| 273 | </li> |
||
| 274 | <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' ) ); ?> |
||
| 275 | <ul> |
||
| 276 | <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> |
||
| 277 | <li>- <?php esc_html_e( 'If you get a 404 message, contact your web host. Their security may block XMLRPC.', 'jetpack' ); ?></li> |
||
| 278 | </ul> |
||
| 279 | </li> |
||
| 280 | <?php if ( current_user_can( 'jetpack_disconnect' ) && Jetpack::is_active() ) : ?> |
||
| 281 | <li> |
||
| 282 | <strong><em><?php esc_html_e( 'A connection problem with WordPress.com.', 'jetpack' ); ?></em></strong> |
||
| 283 | <?php |
||
| 284 | echo wp_kses( |
||
| 285 | sprintf( |
||
| 286 | __( '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' ), |
||
| 287 | wp_nonce_url( |
||
| 288 | Jetpack::admin_url( |
||
| 289 | array( |
||
| 290 | 'page' => 'jetpack-debugger', |
||
| 291 | 'disconnect' => true, |
||
| 292 | ) |
||
| 293 | ), |
||
| 294 | 'jp_disconnect', |
||
| 295 | 'nonce' |
||
| 296 | ) |
||
| 297 | ), |
||
| 298 | array( |
||
| 299 | 'a' => array( |
||
| 300 | 'href' => array(), |
||
| 301 | 'class' => array(), |
||
| 302 | ), |
||
| 303 | ) |
||
| 304 | ); |
||
| 305 | ?> |
||
| 306 | </li> |
||
| 307 | <?php endif; ?> |
||
| 308 | </ol> |
||
| 309 | <hr /> |
||
| 310 | <?php if ( Jetpack::is_active() ) : ?> |
||
| 311 | <div id="connected-user-details"> |
||
| 312 | <h3><?php esc_html_e( 'More details about your Jetpack settings', 'jetpack' ); ?></h3> |
||
| 313 | <p> |
||
| 314 | <?php |
||
| 315 | printf( |
||
| 316 | /* translators: %s is an e-mail address */ |
||
| 317 | __( 'The primary connection is owned by <strong>%s</strong>\'s WordPress.com account.', 'jetpack' ), |
||
| 318 | esc_html( Jetpack::get_master_user_email() ) |
||
| 319 | ); |
||
| 320 | ?> |
||
| 321 | </p> |
||
| 322 | </div> |
||
| 323 | <?php else : ?> |
||
| 324 | <div id="dev-mode-details"> |
||
| 325 | <p> |
||
| 326 | <?php |
||
| 327 | printf( |
||
| 328 | __( 'Would you like to use Jetpack on your local development site? You can do so thanks to <a href="%s">Jetpack\'s development mode</a>.', 'jetpack' ), |
||
| 329 | 'https://jetpack.com/support/development-mode/' |
||
| 330 | ); |
||
| 331 | ?> |
||
| 332 | </p> |
||
| 333 | </div> |
||
| 334 | <?php endif; ?> |
||
| 335 | <?php |
||
| 336 | if ( |
||
| 337 | current_user_can( 'jetpack_manage_modules' ) |
||
| 338 | && ( Jetpack::is_development_mode() || Jetpack::is_active() ) |
||
| 339 | ) { |
||
| 340 | printf( |
||
| 341 | '<p><a href="%1$s">%2$s</a></p>', |
||
| 342 | Jetpack::admin_url( 'page=jetpack_modules' ), |
||
| 343 | esc_html__( 'Access the full list of Jetpack modules available on your site.', 'jetpack' ) |
||
| 344 | ); |
||
| 345 | } |
||
| 346 | ?> |
||
| 347 | </div> |
||
| 348 | <hr /> |
||
| 349 | <div id="toggle_debug_info"><?php _e( 'Advanced Debug Results', 'jetpack' ); ?></div> |
||
| 350 | <div id="debug_info_div"> |
||
| 351 | <h4><?php esc_html_e( 'Debug Info', 'jetpack' ); ?></h4> |
||
| 352 | <div id="debug_info"><pre><?php echo esc_html( $debug_info ); ?></pre></div> |
||
| 353 | </div> |
||
| 354 | </div> |
||
| 355 | <?php |
||
| 356 | } |
||
| 357 | |||
| 478 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.