Completed
Push — update/check-for-idc ( 7e08b0...c9c554 )
by
unknown
24:34 queued 12:07
created

class.jetpack-debugger.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
class Jetpack_Debugger {
4
5
	private static function is_jetpack_support_open() {
6
		try {
7
			$url = add_query_arg( 'ver', JETPACK__VERSION, 'https://jetpack.com/is-support-open/' );
8
			$response = wp_remote_request( esc_url_raw( $url ) );
9
			if ( is_wp_error( $response ) ) {
10
				return false;
11
			}
12
			$body = wp_remote_retrieve_body( $response );
13
			$json = json_decode( $body );
14
			return ( ( bool ) $json->is_support_open );
15
		}
16
		catch ( Exception $e ) {
17
			return true;
18
		}
19
	}
20
21
	static function seconds_to_time( $seconds ) {
22
		$units = array(
23
			"week"   => 7*24*3600,
24
			"day"    =>   24*3600,
25
			"hour"   =>      3600,
26
			"minute" =>        60,
27
			"second" =>         1,
28
		);
29
		// specifically handle zero
30
		if ( $seconds == 0 ) return "0 seconds";
31
		$human_readable = "";
32
		foreach ( $units as $name => $divisor ) {
33
			if ( $quot = intval( $seconds / $divisor) ) {
34
				$human_readable .= "$quot $name";
35
				$human_readable .= ( abs( $quot ) > 1 ? "s" : "" ) . ", ";
36
				$seconds -= $quot * $divisor;
37
			}
38
		}
39
		return substr( $human_readable, 0, -2 );
40
	}
41
42
	public static function jetpack_increase_timeout() {
43
		return 30; // seconds
44
	}
45
46
	public static function jetpack_debug_display_handler() {
47
		if ( ! current_user_can( 'manage_options' ) )
48
			wp_die( esc_html__('You do not have sufficient permissions to access this page.', 'jetpack' ) );
49
50
		$current_user = wp_get_current_user();
51
52
		$user_id = get_current_user_id();
53
		$user_tokens = Jetpack_Options::get_option( 'user_tokens' );
54
		if ( is_array( $user_tokens ) && array_key_exists( $user_id, $user_tokens ) ) {
55
			$user_token = $user_tokens[$user_id];
56
		} else {
57
			$user_token = '[this user has no token]';
58
		}
59
		unset( $user_tokens );
60
61
		$debug_info = "\r\n";
62
		foreach ( array(
63
			'CLIENT_ID'   => 'id',
64
			'BLOG_TOKEN'  => 'blog_token',
65
			'MASTER_USER' => 'master_user',
66
			'CERT'        => 'fallback_no_verify_ssl_certs',
67
			'TIME_DIFF'   => 'time_diff',
68
			'VERSION'     => 'version',
69
			'OLD_VERSION' => 'old_version',
70
			'PUBLIC'      => 'public',
71
		) as $label => $option_name ) {
72
			$debug_info .= "\r\n" . esc_html( $label . ": " . Jetpack_Options::get_option( $option_name ) );
73
		}
74
75
		$debug_info .= "\r\n" . esc_html( "USER_ID: " . $user_id );
76
		$debug_info .= "\r\n" . esc_html( "USER_TOKEN: " . $user_token );
77
		$debug_info .= "\r\n" . esc_html( "PHP_VERSION: " . PHP_VERSION );
78
		$debug_info .= "\r\n" . esc_html( "WORDPRESS_VERSION: " . $GLOBALS['wp_version'] );
79
		$debug_info .= "\r\n" . esc_html( "JETPACK__VERSION: " . JETPACK__VERSION );
80
		$debug_info .= "\r\n" . esc_html( "JETPACK__PLUGIN_DIR: " . JETPACK__PLUGIN_DIR );
81
		$debug_info .= "\r\n" . esc_html( "SITE_URL: " . site_url() );
82
		$debug_info .= "\r\n" . esc_html( "HOME_URL: " . home_url() );
83
84
		$debug_info .= "\r\n";
85
		require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-modules.php';
86
		$sync_module = Jetpack_Sync_Modules::get_module( 'full-sync' );
87
		$sync_statuses = $sync_module->get_status();
88
		$human_readable_sync_status = array();
89
		foreach( $sync_statuses  as $sync_status => $sync_status_value ) {
90
			$human_readable_sync_status[ $sync_status ] =
91
				in_array( $sync_status, array( 'started', 'queue_finished', 'send_started', 'finished' ) )
92
				? date( 'r', $sync_status_value ) : $sync_status_value ;
93
		}
94
95
		$debug_info .= "\r\n". sprintf( esc_html__( 'Jetpack Sync Full Status: `%1$s`', 'jetpack' ), print_r( $human_readable_sync_status, 1 ) );
96
97
		require_once JETPACK__PLUGIN_DIR. 'sync/class.jetpack-sync-sender.php';
98
99
		$queue = Jetpack_Sync_Sender::get_instance()->get_sync_queue();
100
101
		$debug_info .= "\r\n". sprintf( esc_html__( 'Sync Queue size: %1$s', 'jetpack' ), $queue->size() );
102
		$debug_info .= "\r\n". sprintf( esc_html__( 'Sync Queue lag: %1$s', 'jetpack' ), self::seconds_to_time( $queue->lag() ) );
103
104
		$full_sync_queue = Jetpack_Sync_Sender::get_instance()->get_full_sync_queue();
105
106
		$debug_info .= "\r\n". sprintf( esc_html__( 'Full Sync Queue size: %1$s', 'jetpack' ), $full_sync_queue->size() );
107
		$debug_info .= "\r\n". sprintf( esc_html__( 'Full Sync Queue lag: %1$s', 'jetpack' ), self::seconds_to_time( $full_sync_queue->lag() ) );
108
109
		$debug_info .= "\r\n";
110
111
		foreach ( array (
112
					  'HTTP_HOST',
113
					  'SERVER_PORT',
114
					  'HTTPS',
115
					  'GD_PHP_HANDLER',
116
					  'HTTP_AKAMAI_ORIGIN_HOP',
117
					  'HTTP_CF_CONNECTING_IP',
118
					  'HTTP_CLIENT_IP',
119
					  'HTTP_FASTLY_CLIENT_IP',
120
					  'HTTP_FORWARDED',
121
					  'HTTP_FORWARDED_FOR',
122
					  'HTTP_INCAP_CLIENT_IP',
123
					  'HTTP_TRUE_CLIENT_IP',
124
					  'HTTP_X_CLIENTIP',
125
					  'HTTP_X_CLUSTER_CLIENT_IP',
126
					  'HTTP_X_FORWARDED',
127
					  'HTTP_X_FORWARDED_FOR',
128
					  'HTTP_X_IP_TRAIL',
129
					  'HTTP_X_REAL_IP',
130
					  'HTTP_X_VARNISH',
131
					  'REMOTE_ADDR'
132
				  ) as $header ) {
133
			if ( isset( $_SERVER[ $header ] ) ) {
134
				$debug_info .= "\r\n" . esc_html( $header . ": " . $_SERVER[ $header ] );
135
			}
136
		}
137
138
		$debug_info .= "\r\n" . esc_html( "PROTECT_TRUSTED_HEADER: " . json_encode( get_site_option( 'trusted_ip_header' ) ) );
139
140
		$debug_info .= "\r\n\r\nTEST RESULTS:\r\n\r\n";
141
		$debug_raw_info = '';
142
143
144
		$tests = array();
145
146
		$tests['HTTP']['result'] = wp_remote_get( preg_replace( '/^https:/', 'http:', JETPACK__API_BASE ) . 'test/1/' );
147
		$tests['HTTP']['fail_message'] = esc_html__( 'Your site isn’t reaching the Jetpack servers.', 'jetpack' );
148
149
		$tests['HTTPS']['result'] = wp_remote_get( preg_replace( '/^http:/', 'https:', JETPACK__API_BASE ) . 'test/1/' );
150
		$tests['HTTPS']['fail_message'] = esc_html__( 'Your site isn’t securely reaching the Jetpack servers.', 'jetpack' );
151
152
		$identity_crisis_message = '';
153
		if ( $identity_crisis = Jetpack::check_identity_crisis() ) {
154
			foreach( $identity_crisis as $key => $value ) {
0 ignored issues
show
The expression $identity_crisis of type array|boolean is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
155
				$identity_crisis_message .= sprintf( __( 'Your `%1$s` option is set up as `%2$s`, but your WordPress.com connection lists it as `%3$s`!', 'jetpack' ), $key, (string) Jetpack::normalize_url_protocol_agnostic( get_option( $key ) ), $value ) . "\r\n";
156
			}
157
			$identity_crisis = new WP_Error( 'identity-crisis', $identity_crisis_message, $identity_crisis );
158
		} else {
159
			$identity_crisis = 'PASS';
160
		}
161
		$tests['IDENTITY_CRISIS']['result'] = $identity_crisis;
162
		$tests['IDENTITY_CRISIS']['fail_message'] = esc_html__( 'Something has gotten mixed up in your Jetpack Connection!', 'jetpack' );
163
164
		$self_xml_rpc_url = home_url( 'xmlrpc.php' );
165
166
		$testsite_url = Jetpack::fix_url_for_bad_hosts( JETPACK__API_BASE . 'testsite/1/?url=' );
167
168
		add_filter( 'http_request_timeout', array( 'Jetpack_Debugger', 'jetpack_increase_timeout' ) );
169
170
		$tests['SELF']['result'] = wp_remote_get( $testsite_url . $self_xml_rpc_url );
171
		if ( is_wp_error( $tests['SELF']['result'] ) && 0 == strpos( $tests['SELF']['result']->get_error_message(), 'Operation timed out' ) ){
172
			$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' );
173
		} else {
174
			$tests['SELF']['fail_message'] = esc_html__( 'It looks like your site can not communicate properly with Jetpack.', 'jetpack' );
175
		}
176
177
		remove_filter( 'http_request_timeout', array( 'Jetpack_Debugger', 'jetpack_increase_timeout' ) );
178
179
		?>
180
		<div class="wrap">
181
			<h2><?php esc_html_e( 'Jetpack Debugging Center', 'jetpack' ); ?></h2>
182
			<h3><?php _e( "Testing your site's compatibility with Jetpack...", 'jetpack' ); ?></h3>
183
			<div class="jetpack-debug-test-container">
184
			<?php
185
			ob_start();
186
			foreach ( $tests as $test_name => $test_info ) :
187
				if ( 'PASS' !== $test_info['result'] && ( is_wp_error( $test_info['result'] ) ||
188
					false == ( $response_code = wp_remote_retrieve_response_code( $test_info['result'] ) )  ||
189
					'200' != $response_code ) ) {
190
					$debug_info .= $test_name . ": FAIL\r\n";
191
					?>
192
					<div class="jetpack-test-error">
193
						<p>
194
							<a class="jetpack-test-heading" href="#"><?php echo $test_info['fail_message']; ?>
195
							<span class="noticon noticon-collapse"></span>
196
							</a>
197
						</p>
198
						<pre class="jetpack-test-details"><?php echo esc_html( $test_name ); ?>:
199
	<?php echo esc_html( is_wp_error( $test_info['result'] ) ? $test_info['result']->get_error_message() : print_r( $test_info['result'], 1 ) ); ?></pre>
200
					</div><?php
201
				} else {
202
					$debug_info .= $test_name . ": PASS\r\n";
203
				}
204
				$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 ) );
205
				?>
206
			<?php endforeach;
207
			$html = ob_get_clean();
208
209
			if ( '' == trim( $html ) ) {
210
				echo '<div class="jetpack-tests-succed">' . esc_html__( 'Your Jetpack setup looks a-okay!', 'jetpack' ) . '</div>';
211
			}
212
			else {
213
				echo '<h3>' . esc_html__( 'There seems to be a problem with your site’s ability to communicate with Jetpack!', 'jetpack' ) . '</h3>';
214
				echo $html;
215
			}
216
			$debug_info .= "\r\n\r\nRAW TEST RESULTS:" . $debug_raw_info ."\r\n";
217
			?>
218
			</div>
219
			<div class="entry-content">
220
				<h3><?php esc_html_e( 'Trouble with Jetpack?', 'jetpack' ); ?></h3>
221
				<h4><?php esc_html_e( 'It may be caused by one of these issues, which you can diagnose yourself:', 'jetpack' ); ?></h4>
222
				<ol>
223
					<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>
224
					<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>
225
					<li>
226
						<b><em><?php esc_html_e( 'A theme conflict.', 'jetpack' ); ?></em></b>
227
						<?php
228
							$default_theme = wp_get_theme( WP_DEFAULT_THEME );
229
230
							if ( $default_theme->exists() ) {
231
								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' ) ) );
232
							} else {
233
								esc_html_e( "If your problem isn't known or caused by a plugin, try activating the default WordPress theme.", 'jetpack' );
234
							}
235
						?>
236
						<?php esc_html_e( "If this solves the problem, something in your theme is probably broken – let the theme's author know.", 'jetpack' ); ?>
237
					</li>
238
					<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' ) ); ?>
239
						<ul>
240
							<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>
241
							<li>- <?php esc_html_e( "If you get a 404 message, contact your web host. Their security may block XMLRPC.", 'jetpack' ); ?></li>
242
						</ul>
243
					</li>
244
				</ol>
245
				<?php if ( self::is_jetpack_support_open() ): ?>
246
				<p class="jetpack-show-contact-form"><?php echo sprintf( __( 'If none of these help you find a solution, <a href="%s">click here to contact Jetpack support</a>. Tell us as much as you can about the issue and what steps you\'ve tried to resolve it, and one of our Happiness Engineers will be in touch to help.', 'jetpack' ), Jetpack::admin_url( array( 'page' => 'jetpack-debugger', 'contact' => true ) ) ); ?>
247
				</p>
248
				<?php endif; ?>
249
				<?php if ( Jetpack::is_active() ) : ?>
250
					<hr />
251
					<div id="connected-user-details">
252
						<p><?php printf( __( 'The primary connection is owned by <strong>%s</strong>\'s WordPress.com account.', 'jetpack' ), esc_html( Jetpack::get_master_user_email() ) ); ?></p>
253
					</div>
254
				<?php endif; ?>
255
			</div>
256
			<div id="contact-message" <?php if( ! isset( $_GET['contact'] ) ) {?>  style="display:none" <?php } ?>>
257
			<?php if ( self::is_jetpack_support_open() ): ?>
258
				<form id="contactme" method="post" action="https://jetpack.com/contact-support/">
259
					<input type="hidden" name="action" value="submit">
260
					<input type="hidden" name="jetpack" value="needs-service">
261
262
					<input type="hidden" name="contact_form" id="contact_form" value="1">
263
					<input type="hidden" name="blog_url" id="blog_url" value="<?php echo esc_attr( site_url() ); ?>">
264
					<?php
265
						$subject_line = sprintf(
266
							/* translators: %s is the URL of the site */
267
							_x( 'from: %s Jetpack contact form', 'Support request email subject line', 'jetpack' ),
268
							esc_attr( site_url() )
269
						);
270
271
						if ( Jetpack::is_development_version() ) {
272
							$subject_line = 'BETA ' . $subject_line;
273
						}
274
275
						$subject_line_input = printf(
276
							'<input type="hidden" name="subject" id="subject" value="%s"">',
277
							$subject_line
278
						);
279
					?>
280
					<div class="formbox">
281
						<label for="message" class="h"><?php esc_html_e( 'Please describe the problem you are having.', 'jetpack' ); ?></label>
282
						<textarea name="message" cols="40" rows="7" id="did"></textarea>
283
					</div>
284
285
					<div id="name_div" class="formbox">
286
						<label class="h" for="your_name"><?php esc_html_e( 'Name', 'jetpack' ); ?></label>
287
			  			<span class="errormsg"><?php esc_html_e( 'Let us know your name.', 'jetpack' ); ?></span>
288
						<input name="your_name" type="text" id="your_name" value="<?php esc_html_e( $current_user->display_name, 'jetpack'); ?>" size="40">
289
					</div>
290
291
					<div id="email_div" class="formbox">
292
						<label class="h" for="your_email"><?php esc_html_e( 'E-mail', 'jetpack' ); ?></label>
293
			  			<span class="errormsg"><?php esc_html_e( 'Use a valid email address.', 'jetpack' ); ?></span>
294
						<input name="your_email" type="text" id="your_email" value="<?php esc_html_e( $current_user->user_email, 'jetpack'); ?>" size="40">
295
					</div>
296
297
					<div id="toggle_debug_form_info" class="formbox">
298
						<p><?php _e( 'The test results and some other useful debug information will be sent to the support team. Please feel free to <a href="#">review/modify</a> this information.', 'jetpack' ); ?></p>
299
					</div>
300
301
					<div id="debug_info_form_div" class="formbox" style="display:none">
302
						<label class="h" for="debug_info"><?php esc_html_e( 'Debug Info', 'jetpack' ); ?></label>
303
			  			<textarea name="debug_info" cols="40" rows="7" id="debug_form_info"><?php echo esc_attr( $debug_info ); ?></textarea>
304
					</div>
305
306
					<div style="clear: both;"></div>
307
308
					<div id="blog_div" class="formbox">
309
						<div id="submit_div" class="contact-support">
310
						<input type="submit" name="submit" value="<?php esc_html_e( 'Submit &#187;', 'jetpack' ); ?>">
311
						</div>
312
					</div>
313
					<div style="clear: both;"></div>
314
				</form>
315
			<?php endif; ?>
316
		</div> <!-- contact-message, hidden by default. -->
317
		<div id="toggle_debug_info"><a href="#"><?php _e( 'View Advanced Debug Results', 'jetpack' ); ?></a></div>
318
			<div id="debug_info_div" style="display:none">
319
			<h4><?php esc_html_e( 'Debug Info', 'jetpack' ); ?></h4>
320
			<div id="debug_info"><pre><?php echo esc_html( $debug_info ) ; ?></pre></div>
321
		</div>
322
		</div>
323
	<?php
324
	}
325
326
	public static function jetpack_debug_admin_head() {
327
		?>
328
		<style type="text/css">
329
330
			.jetpack-debug-test-container {
331
				margin-top: 20px;
332
				margin-bottom: 30px;
333
			}
334
335
			.jetpack-tests-succed {
336
				font-size: large;
337
				color: #8BAB3E;
338
			}
339
340
			.jetpack-test-details {
341
				margin: 4px 6px;
342
				padding: 10px;
343
				overflow: auto;
344
				display: none;
345
			}
346
347
			.jetpack-test-error {
348
				margin-bottom: 10px;
349
				background: #FFEBE8;
350
				border: solid 1px #C00;
351
				border-radius: 3px;
352
			}
353
354
			.jetpack-test-error p {
355
				margin: 0;
356
				padding: 0;
357
			}
358
359
			.jetpack-test-error a.jetpack-test-heading {
360
				padding: 4px 6px;
361
				display: block;
362
				text-decoration: none;
363
				color: inherit;
364
			}
365
366
			.jetpack-test-error .noticon {
367
				float: right;
368
			}
369
370
			form#contactme {
371
				border: 1px solid #dfdfdf;
372
				background: #eaf3fa;
373
				padding: 20px;
374
				margin: 10px;
375
				background-color: #eaf3fa;
376
				border-radius: 5px;
377
				font-size: 15px;
378
			}
379
380
			form#contactme label.h {
381
				color: #444;
382
				display: block;
383
				font-weight: bold;
384
				margin: 0 0 7px 10px;
385
				text-shadow: 1px 1px 0 #fff;
386
			}
387
388
			.formbox {
389
				margin: 0 0 25px 0;
390
			}
391
392
			.formbox input[type="text"], .formbox input[type="email"], .formbox input[type="url"], .formbox textarea, #debug_info_div {
393
				border: 1px solid #e5e5e5;
394
				border-radius: 11px;
395
				box-shadow: inset 0 1px 1px rgba(0,0,0,0.1);
396
				color: #666;
397
				font-size: 14px;
398
				padding: 10px;
399
				width: 97%;
400
			}
401
			#debug_info_div {
402
				border-radius: 0;
403
				margin-top: 16px;
404
				background: #FFF;
405
				padding: 16px;
406
			}
407
			.formbox .contact-support input[type="submit"] {
408
				float: right;
409
				margin: 0 !important;
410
				border-radius: 20px !important;
411
				cursor: pointer;
412
				font-size: 13pt !important;
413
				height: auto !important;
414
				margin: 0 0 2em 10px !important;
415
				padding: 8px 16px !important;
416
				background-color: #ddd;
417
				border: 1px solid rgba(0,0,0,0.05);
418
				border-top-color: rgba(255,255,255,0.1);
419
				border-bottom-color: rgba(0,0,0,0.15);
420
				color: #333;
421
				font-weight: 400;
422
				display: inline-block;
423
				text-align: center;
424
				text-decoration: none;
425
			}
426
427
			.formbox span.errormsg {
428
				margin: 0 0 10px 10px;
429
				color: #d00;
430
				display: none;
431
			}
432
433
			.formbox.error span.errormsg {
434
				display: block;
435
			}
436
437
			#contact-message ul {
438
				margin: 0 0 20px 10px;
439
			}
440
441
			#contact-message li {
442
				margin: 0 0 10px 10px;
443
				list-style: disc;
444
				display: list-item;
445
			}
446
447
			#debug_info_div, #toggle_debug_info, #debug_info_div p {
448
				font-size: 12px;
449
			}
450
451
		</style>
452
		<script type="text/javascript">
453
		jQuery( document ).ready( function($) {
454
455
			$( '#debug_info' ).prepend( 'jQuery version: ' + jQuery.fn.jquery + "\r\n" );
456
			$( '#debug_form_info' ).prepend( 'jQuery version: ' + jQuery.fn.jquery + "\r\n" );
457
458
			$( '.jetpack-test-error .jetpack-test-heading' ).on( 'click', function() {
459
				$( this ).parents( '.jetpack-test-error' ).find( '.jetpack-test-details' ).slideToggle();
460
				return false;
461
			} );
462
463
			$( '.jetpack-show-contact-form a' ).on( 'click', function() {
464
				$( '#contact-message' ).slideToggle();
465
				return false;
466
			} );
467
468
			$( '#toggle_debug_info a' ).on( 'click', function() {
469
				$( '#debug_info_div' ).slideToggle();
470
				return false;
471
			} );
472
473
			$( '#toggle_debug_form_info a' ).on( 'click', function() {
474
				$( '#debug_info_form_div' ).slideToggle();
475
				return false;
476
			} );
477
478
			$( 'form#contactme' ).on( "submit", function(e){
479
				var form = $( this );
480
				var message = form.find( '#did' );
481
				var name = form.find( '#your_name' );
482
				var email = form.find( '#your_email' )
483
				var validation_error = false;
484
				if( !name.val() ) {
485
					name.parents( '.formbox' ).addClass( 'error' );
486
					validation_error = true;
487
				}
488
				if( !email.val() ) {
489
					email.parents( '.formbox' ).addClass( 'error' );
490
					validation_error = true;
491
				}
492
				if ( validation_error ) {
493
					return false;
494
				}
495
				message.val( message.val() + "\r\n\r\n----------------------------------------------\r\n\r\nDEBUG INFO:\r\n" + $('#debug_form_info').val()  );
496
				return true;
497
	    	});
498
499
		} );
500
		</script>
501
		<?php
502
	}
503
}
504