Conditions | 31 |
Paths | > 20000 |
Total Lines | 308 |
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 //phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
||
112 | public static function jetpack_debug_display_handler() { |
||
113 | if ( ! current_user_can( 'manage_options' ) ) { |
||
114 | wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'jetpack' ) ); |
||
115 | } |
||
116 | |||
117 | $user_id = get_current_user_id(); |
||
118 | $user_tokens = Jetpack_Options::get_option( 'user_tokens' ); |
||
119 | if ( is_array( $user_tokens ) && array_key_exists( $user_id, $user_tokens ) ) { |
||
120 | $user_token = $user_tokens[ $user_id ]; |
||
121 | } else { |
||
122 | $user_token = '[this user has no token]'; |
||
123 | } |
||
124 | unset( $user_tokens ); |
||
125 | |||
126 | $debug_info = "\r\n"; |
||
127 | foreach ( array( |
||
128 | 'CLIENT_ID' => 'id', |
||
129 | 'BLOG_TOKEN' => 'blog_token', |
||
130 | 'MASTER_USER' => 'master_user', |
||
131 | 'CERT' => 'fallback_no_verify_ssl_certs', |
||
132 | 'TIME_DIFF' => 'time_diff', |
||
133 | 'VERSION' => 'version', |
||
134 | 'OLD_VERSION' => 'old_version', |
||
135 | 'PUBLIC' => 'public', |
||
136 | ) as $label => $option_name ) { |
||
137 | $debug_info .= "\r\n" . esc_html( $label . ': ' . Jetpack_Options::get_option( $option_name ) ); |
||
138 | } |
||
139 | |||
140 | $debug_info .= "\r\n" . esc_html( 'USER_ID: ' . $user_id ); |
||
141 | $debug_info .= "\r\n" . esc_html( 'USER_TOKEN: ' . $user_token ); |
||
142 | $debug_info .= "\r\n" . esc_html( 'PHP_VERSION: ' . PHP_VERSION ); |
||
143 | $debug_info .= "\r\n" . esc_html( 'WORDPRESS_VERSION: ' . $GLOBALS['wp_version'] ); |
||
144 | $debug_info .= "\r\n" . esc_html( 'JETPACK__VERSION: ' . JETPACK__VERSION ); |
||
145 | $debug_info .= "\r\n" . esc_html( 'JETPACK__PLUGIN_DIR: ' . JETPACK__PLUGIN_DIR ); |
||
146 | $debug_info .= "\r\n" . esc_html( 'SITE_URL: ' . site_url() ); |
||
147 | $debug_info .= "\r\n" . esc_html( 'HOME_URL: ' . home_url() ); |
||
148 | $debug_info .= "\r\n" . esc_html( 'PLAN: ' . self::what_jetpack_plan() ); |
||
149 | |||
150 | $debug_info .= "\r\n"; |
||
151 | |||
152 | $debug_info .= "\r\n" . '-- SYNC Status -- '; |
||
153 | require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-modules.php'; |
||
154 | $sync_module = Jetpack_Sync_Modules::get_module( 'full-sync' ); |
||
155 | if ( $sync_module ) { |
||
156 | $sync_statuses = $sync_module->get_status(); |
||
157 | $human_readable_sync_status = array(); |
||
158 | foreach ( $sync_statuses as $sync_status => $sync_status_value ) { |
||
159 | $human_readable_sync_status[ $sync_status ] = |
||
160 | in_array( $sync_status, array( 'started', 'queue_finished', 'send_started', 'finished' ), true ) |
||
161 | ? date( 'r', $sync_status_value ) : $sync_status_value; |
||
162 | } |
||
163 | /* translators: A string reporting status. Example: "started" */ |
||
164 | $debug_info .= "\r\n" . sprintf( esc_html__( 'Jetpack Sync Full Status: `%1$s`', 'jetpack' ), print_r( $human_readable_sync_status, 1 ) ); //phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r |
||
165 | } |
||
166 | |||
167 | require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-sender.php'; |
||
168 | |||
169 | $queue = Jetpack_Sync_Sender::get_instance()->get_sync_queue(); |
||
170 | |||
171 | /* translators: The number of items waiting to be synced. */ |
||
172 | $debug_info .= "\r\n" . sprintf( esc_html__( 'Sync Queue size: %1$s', 'jetpack' ), $queue->size() ); |
||
173 | /* translators: Human-readable time since the oldest item in the sync queue. */ |
||
174 | $debug_info .= "\r\n" . sprintf( esc_html__( 'Sync Queue lag: %1$s', 'jetpack' ), self::seconds_to_time( $queue->lag() ) ); |
||
175 | |||
176 | $full_sync_queue = Jetpack_Sync_Sender::get_instance()->get_full_sync_queue(); |
||
177 | |||
178 | /* translators: The number of items waiting to be synced. */ |
||
179 | $debug_info .= "\r\n" . sprintf( esc_html__( 'Full Sync Queue size: %1$s', 'jetpack' ), $full_sync_queue->size() ); |
||
180 | /* translators: Human-readable time since the oldest item in the sync queue. */ |
||
181 | $debug_info .= "\r\n" . sprintf( esc_html__( 'Full Sync Queue lag: %1$s', 'jetpack' ), self::seconds_to_time( $full_sync_queue->lag() ) ); |
||
182 | |||
183 | require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-functions.php'; |
||
184 | $idc_urls = array( |
||
185 | 'home' => Jetpack_Sync_Functions::home_url(), |
||
186 | 'siteurl' => Jetpack_Sync_Functions::site_url(), |
||
187 | 'WP_HOME' => Jetpack_Constants::is_defined( 'WP_HOME' ) ? Jetpack_Constants::get_constant( 'WP_HOME' ) : '', |
||
188 | 'WP_SITEURL' => Jetpack_Constants::is_defined( 'WP_SITEURL' ) ? Jetpack_Constants::get_constant( 'WP_SITEURL' ) : '', |
||
189 | ); |
||
190 | /* translators: List of URLs. */ |
||
191 | $debug_info .= "\r\n" . esc_html( sprintf( 'Sync IDC URLs: %s', wp_json_encode( $idc_urls ) ) ); |
||
192 | /* translators: String of a current option. */ |
||
193 | $debug_info .= "\r\n" . esc_html( sprintf( 'Sync error IDC option: %s', wp_json_encode( Jetpack_Options::get_option( 'sync_error_idc' ) ) ) ); |
||
194 | /* translators: String of a current option. */ |
||
195 | $debug_info .= "\r\n" . esc_html( sprintf( 'Sync IDC Optin: %s', (string) Jetpack::sync_idc_optin() ) ); |
||
196 | |||
197 | $debug_info .= "\r\n"; |
||
198 | |||
199 | foreach ( array( |
||
200 | 'HTTP_HOST', |
||
201 | 'SERVER_PORT', |
||
202 | 'HTTPS', |
||
203 | 'GD_PHP_HANDLER', |
||
204 | 'HTTP_AKAMAI_ORIGIN_HOP', |
||
205 | 'HTTP_CF_CONNECTING_IP', |
||
206 | 'HTTP_CLIENT_IP', |
||
207 | 'HTTP_FASTLY_CLIENT_IP', |
||
208 | 'HTTP_FORWARDED', |
||
209 | 'HTTP_FORWARDED_FOR', |
||
210 | 'HTTP_INCAP_CLIENT_IP', |
||
211 | 'HTTP_TRUE_CLIENT_IP', |
||
212 | 'HTTP_X_CLIENTIP', |
||
213 | 'HTTP_X_CLUSTER_CLIENT_IP', |
||
214 | 'HTTP_X_FORWARDED', |
||
215 | 'HTTP_X_FORWARDED_FOR', |
||
216 | 'HTTP_X_IP_TRAIL', |
||
217 | 'HTTP_X_REAL_IP', |
||
218 | 'HTTP_X_VARNISH', |
||
219 | 'REMOTE_ADDR', |
||
220 | ) as $header ) { |
||
221 | if ( isset( $_SERVER[ $header ] ) ) { |
||
222 | $debug_info .= "\r\n" . esc_html( $header . ': ' . $_SERVER[ $header ] ); |
||
223 | } |
||
224 | } |
||
225 | |||
226 | $debug_info .= "\r\n" . esc_html( 'PROTECT_TRUSTED_HEADER: ' . wp_json_encode( get_site_option( 'trusted_ip_header' ) ) ); |
||
227 | |||
228 | $debug_info .= "\r\n\r\nTEST RESULTS:\r\n\r\n"; |
||
229 | $debug_raw_info = ''; |
||
230 | |||
231 | $tests = array(); |
||
232 | |||
233 | $tests['XML']['result'] = ( function_exists( 'xml_parser_create' ) ) ? 'PASS' : false; |
||
234 | /* translators: Link to Jetpack Hosting support page. */ |
||
235 | $tests['XML']['fail_message'] = esc_html__( 'Jetpack can not load necessary XML manipulation libraries. Please ask your hosting provider to refer to our server requirements at https://jetpack.com/support/server-requirements/ .', 'jetpack' ); |
||
236 | |||
237 | $tests['HTTP']['result'] = wp_remote_get( preg_replace( '/^https:/', 'http:', JETPACK__API_BASE ) . 'test/1/' ); |
||
238 | $tests['HTTP']['fail_message'] = esc_html__( 'Your site isn’t reaching the Jetpack servers.', 'jetpack' ); |
||
239 | |||
240 | $tests['HTTPS']['result'] = wp_remote_get( preg_replace( '/^http:/', 'https:', JETPACK__API_BASE ) . 'test/1/' ); |
||
241 | $tests['HTTPS']['fail_message'] = esc_html__( 'Your site isn’t securely reaching the Jetpack servers.', 'jetpack' ); |
||
242 | |||
243 | $identity_crisis_message = ''; |
||
244 | $identity_crisis = Jetpack::check_identity_crisis(); |
||
245 | if ( $identity_crisis ) { |
||
246 | $identity_crisis_message .= sprintf( |
||
247 | /* translators: Two URLs. The first is the locally-recorded value, the second is the value as recorded on WP.com. */ |
||
248 | __( 'Your url is set as `%1$s`, but your WordPress.com connection lists it as `%2$s`!', 'jetpack' ), |
||
249 | $identity_crisis['home'], |
||
250 | $identity_crisis['wpcom_home'] |
||
251 | ); |
||
252 | $identity_crisis = new WP_Error( 'identity-crisis', $identity_crisis_message, $identity_crisis ); |
||
253 | } else { |
||
254 | $identity_crisis = 'PASS'; |
||
255 | } |
||
256 | $tests['IDENTITY_CRISIS']['result'] = $identity_crisis; |
||
257 | $tests['IDENTITY_CRISIS']['fail_message'] = esc_html__( 'Something has gotten mixed up in your Jetpack Connection!', 'jetpack' ); |
||
258 | |||
259 | $tests['SELF']['result'] = self::run_self_test(); |
||
260 | |||
261 | if ( is_wp_error( $tests['SELF']['result'] ) && 0 == strpos( $tests['SELF']['result']->get_error_message(), 'Operation timed out' ) ) { |
||
262 | $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' ); |
||
263 | } else { |
||
264 | $tests['SELF']['fail_message'] = esc_html__( 'It looks like your site can not communicate properly with Jetpack.', 'jetpack' ); |
||
265 | } |
||
266 | |||
267 | ?> |
||
268 | <div class="wrap"> |
||
269 | <h2><?php esc_html_e( 'Debugging Center', 'jetpack' ); ?></h2> |
||
270 | <h3><?php esc_html_e( "Testing your site's compatibility with Jetpack...", 'jetpack' ); ?></h3> |
||
271 | <div class="jetpack-debug-test-container"> |
||
272 | <?php |
||
273 | ob_start(); |
||
274 | foreach ( $tests as $test_name => $test_info ) : |
||
275 | $response_code = wp_remote_retrieve_response_code( $test_info['result'] ); |
||
276 | if ( 'PASS' !== $test_info['result'] && ( is_wp_error( $test_info['result'] ) || |
||
277 | false === ( $response_code ) || |
||
278 | 200 !== intval( $response_code ) ) ) { |
||
279 | $debug_info .= $test_name . ": FAIL\r\n"; |
||
280 | ?> |
||
281 | <div class="jetpack-test-error"> |
||
282 | <p> |
||
283 | <a class="jetpack-test-heading" href="#"><?php echo esc_html( $test_info['fail_message'] ); ?> |
||
284 | <span class="noticon noticon-collapse"></span> |
||
285 | </a> |
||
286 | </p> |
||
287 | <pre class="jetpack-test-details"><?php echo esc_html( $test_name ); ?>: |
||
288 | <?php echo esc_html( is_wp_error( $test_info['result'] ) ? $test_info['result']->get_error_message() : print_r( $test_info['result'], 1 ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r ?></pre> |
||
289 | </div> |
||
290 | <?php |
||
291 | } else { |
||
292 | $debug_info .= $test_name . ": PASS\r\n"; |
||
293 | } |
||
294 | $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 ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r |
||
295 | ?> |
||
296 | <?php |
||
297 | endforeach; |
||
298 | $html = ob_get_clean(); |
||
299 | |||
300 | if ( '' === trim( $html ) ) { |
||
301 | echo '<div class="jetpack-tests-succed">' . esc_html__( 'Your Jetpack setup looks a-okay!', 'jetpack' ) . '</div>'; |
||
302 | } else { |
||
303 | echo '<h3>' . esc_html__( 'There seems to be a problem with your site’s ability to communicate with Jetpack!', 'jetpack' ) . '</h3>'; |
||
304 | echo $html; |
||
305 | } |
||
306 | $debug_info .= "\r\n\r\nRAW TEST RESULTS:" . $debug_raw_info . "\r\n"; |
||
307 | ?> |
||
308 | </div> |
||
309 | |||
310 | <div class="entry-content"> |
||
311 | <h3><?php esc_html_e( 'Trouble with Jetpack?', 'jetpack' ); ?></h3> |
||
312 | <h4><?php esc_html_e( 'It may be caused by one of these issues, which you can diagnose yourself:', 'jetpack' ); ?></h4> |
||
313 | <ol> |
||
314 | <?php /* translators: URLs to Jetpack support pages. */ ?> |
||
315 | <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> |
||
316 | <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> |
||
317 | <li> |
||
318 | <b><em><?php esc_html_e( 'A theme conflict.', 'jetpack' ); ?></em></b> |
||
319 | <?php |
||
320 | $default_theme = wp_get_theme( WP_DEFAULT_THEME ); |
||
321 | |||
322 | if ( $default_theme->exists() ) { |
||
323 | /* translators: %s is the name of a theme */ |
||
324 | 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' ) ) ); |
||
325 | } else { |
||
326 | esc_html_e( "If your problem isn't known or caused by a plugin, try activating the default WordPress theme.", 'jetpack' ); |
||
327 | } |
||
328 | ?> |
||
329 | <?php esc_html_e( "If this solves the problem, something in your theme is probably broken – let the theme's author know.", 'jetpack' ); ?> |
||
330 | </li> |
||
331 | <?php /* translators: The URL to the site's xmlrpc.php file. */ ?> |
||
332 | <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' ) ); ?> |
||
333 | <ul> |
||
334 | <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> |
||
335 | <li>- <?php esc_html_e( 'If you get a 404 message, contact your web host. Their security may block XMLRPC.', 'jetpack' ); ?></li> |
||
336 | </ul> |
||
337 | </li> |
||
338 | <?php if ( current_user_can( 'jetpack_disconnect' ) && Jetpack::is_active() ) : ?> |
||
339 | <li> |
||
340 | <strong><em><?php esc_html_e( 'A connection problem with WordPress.com.', 'jetpack' ); ?></em></strong> |
||
341 | <?php |
||
342 | echo wp_kses( |
||
343 | sprintf( |
||
344 | /* translators: URL to disconnect and reconnect Jetpack. */ |
||
345 | __( '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' ), |
||
346 | wp_nonce_url( |
||
347 | Jetpack::admin_url( |
||
348 | array( |
||
349 | 'page' => 'jetpack-debugger', |
||
350 | 'disconnect' => true, |
||
351 | ) |
||
352 | ), |
||
353 | 'jp_disconnect', |
||
354 | 'nonce' |
||
355 | ) |
||
356 | ), |
||
357 | array( |
||
358 | 'a' => array( |
||
359 | 'href' => array(), |
||
360 | 'class' => array(), |
||
361 | ), |
||
362 | ) |
||
363 | ); |
||
364 | ?> |
||
365 | </li> |
||
366 | <?php endif; ?> |
||
367 | </ol> |
||
368 | <h4><?php esc_html_e( 'Still having trouble?', 'jetpack' ); ?></h4> |
||
369 | <?php /* translators: URL for Jetpack support. */ ?> |
||
370 | <p><b><em><?php esc_html_e( 'Ask us for help!', 'jetpack' ); ?></em></b> <?php echo sprintf( __( '<a href="%s">Contact our Happiness team</a>. When you do, please include the full debug information below.', 'jetpack' ), 'https://jetpack.com/contact-support/' ); ?></p> |
||
371 | <hr /> |
||
372 | <?php if ( Jetpack::is_active() ) : ?> |
||
373 | <div id="connected-user-details"> |
||
374 | <h3><?php esc_html_e( 'More details about your Jetpack settings', 'jetpack' ); ?></h3> |
||
375 | <p> |
||
376 | <?php |
||
377 | printf( |
||
378 | /* translators: %s is an e-mail address */ |
||
379 | __( 'The primary connection is owned by <strong>%s</strong>\'s WordPress.com account.', 'jetpack' ), |
||
380 | esc_html( Jetpack::get_master_user_email() ) |
||
381 | ); |
||
382 | ?> |
||
383 | </p> |
||
384 | </div> |
||
385 | <?php else : ?> |
||
386 | <div id="dev-mode-details"> |
||
387 | <p> |
||
388 | <?php |
||
389 | printf( |
||
390 | /* translators: Link to a Jetpack support page. */ |
||
391 | __( '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' ), |
||
392 | 'https://jetpack.com/support/development-mode/' |
||
393 | ); |
||
394 | ?> |
||
395 | </p> |
||
396 | </div> |
||
397 | <?php endif; ?> |
||
398 | <?php |
||
399 | if ( |
||
400 | current_user_can( 'jetpack_manage_modules' ) |
||
401 | && ( Jetpack::is_development_mode() || Jetpack::is_active() ) |
||
402 | ) { |
||
403 | printf( |
||
404 | '<p><a href="%1$s">%2$s</a></p>', |
||
405 | Jetpack::admin_url( 'page=jetpack_modules' ), |
||
406 | esc_html__( 'Access the full list of Jetpack modules available on your site.', 'jetpack' ) |
||
407 | ); |
||
408 | } |
||
409 | ?> |
||
410 | </div> |
||
411 | <hr /> |
||
412 | <div id="toggle_debug_info"><?php esc_html_e( 'Advanced Debug Results', 'jetpack' ); ?></div> |
||
413 | <div id="debug_info_div"> |
||
414 | <h4><?php esc_html_e( 'Debug Info', 'jetpack' ); ?></h4> |
||
415 | <div id="debug_info"><pre><?php echo esc_html( $debug_info ); ?></pre></div> |
||
416 | </div> |
||
417 | </div> |
||
418 | <?php |
||
419 | } |
||
420 | |||
544 |