Completed
Push — add/stats-banner-traffic-tab ( 6add1c )
by
unknown
83:43 queued 74:26
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
	private static function what_jetpack_plan() {
22
		$plan = Jetpack::get_active_plan();
23
		$plan = ! empty( $plan['class'] ) ? $plan['class'] : 'undefined';
24
		return 'JetpackPlan' . $plan;
25
	}
26
27
	static function seconds_to_time( $seconds ) {
28
		$units = array(
29
			"week"   => 7*24*3600,
30
			"day"    =>   24*3600,
31
			"hour"   =>      3600,
32
			"minute" =>        60,
33
			"second" =>         1,
34
		);
35
		// specifically handle zero
36
		if ( $seconds == 0 ) return "0 seconds";
37
		$human_readable = "";
38
		foreach ( $units as $name => $divisor ) {
39
			if ( $quot = intval( $seconds / $divisor) ) {
40
				$human_readable .= "$quot $name";
41
				$human_readable .= ( abs( $quot ) > 1 ? "s" : "" ) . ", ";
42
				$seconds -= $quot * $divisor;
43
			}
44
		}
45
		return substr( $human_readable, 0, -2 );
46
	}
47
48
	public static function jetpack_increase_timeout() {
49
		return 30; // seconds
50
	}
51
52
	public static function disconnect_and_redirect() {
53
		$can_disconnect = isset( $_GET['disconnect'] ) && $_GET['disconnect'] && isset( $_GET['nonce'] ) && wp_verify_nonce( $_GET['nonce'], 'jp_disconnect' );
54
		if ( $can_disconnect ) {
55
			if ( Jetpack::is_active() ) {
56
				Jetpack::disconnect();
57
				wp_redirect( Jetpack::admin_url() );
58
			}
59
		}
60
	}
61
62
	public static function jetpack_debug_display_handler() {
63
		if ( ! current_user_can( 'manage_options' ) )
64
			wp_die( esc_html__('You do not have sufficient permissions to access this page.', 'jetpack' ) );
65
66
		$current_user = wp_get_current_user();
67
68
		$user_id = get_current_user_id();
69
		$user_tokens = Jetpack_Options::get_option( 'user_tokens' );
70
		if ( is_array( $user_tokens ) && array_key_exists( $user_id, $user_tokens ) ) {
71
			$user_token = $user_tokens[$user_id];
72
		} else {
73
			$user_token = '[this user has no token]';
74
		}
75
		unset( $user_tokens );
76
77
		$debug_info = "\r\n";
78
		foreach ( array(
79
			'CLIENT_ID'   => 'id',
80
			'BLOG_TOKEN'  => 'blog_token',
81
			'MASTER_USER' => 'master_user',
82
			'CERT'        => 'fallback_no_verify_ssl_certs',
83
			'TIME_DIFF'   => 'time_diff',
84
			'VERSION'     => 'version',
85
			'OLD_VERSION' => 'old_version',
86
			'PUBLIC'      => 'public',
87
		) as $label => $option_name ) {
88
			$debug_info .= "\r\n" . esc_html( $label . ": " . Jetpack_Options::get_option( $option_name ) );
89
		}
90
91
		$debug_info .= "\r\n" . esc_html( "USER_ID: " . $user_id );
92
		$debug_info .= "\r\n" . esc_html( "USER_TOKEN: " . $user_token );
93
		$debug_info .= "\r\n" . esc_html( "PHP_VERSION: " . PHP_VERSION );
94
		$debug_info .= "\r\n" . esc_html( "WORDPRESS_VERSION: " . $GLOBALS['wp_version'] );
95
		$debug_info .= "\r\n" . esc_html( "JETPACK__VERSION: " . JETPACK__VERSION );
96
		$debug_info .= "\r\n" . esc_html( "JETPACK__PLUGIN_DIR: " . JETPACK__PLUGIN_DIR );
97
		$debug_info .= "\r\n" . esc_html( "SITE_URL: " . site_url() );
98
		$debug_info .= "\r\n" . esc_html( "HOME_URL: " . home_url() );
99
		$debug_info .= "\r\n" . esc_html( "PLAN: " . self::what_jetpack_plan() );
100
101
		$debug_info .= "\r\n";
102
		require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-modules.php';
103
		$sync_module = Jetpack_Sync_Modules::get_module( 'full-sync' );
104
		$sync_statuses = $sync_module->get_status();
105
		$human_readable_sync_status = array();
106
		foreach( $sync_statuses  as $sync_status => $sync_status_value ) {
107
			$human_readable_sync_status[ $sync_status ] =
108
				in_array( $sync_status, array( 'started', 'queue_finished', 'send_started', 'finished' ) )
109
				? date( 'r', $sync_status_value ) : $sync_status_value ;
110
		}
111
112
		$debug_info .= "\r\n". sprintf( esc_html__( 'Jetpack Sync Full Status: `%1$s`', 'jetpack' ), print_r( $human_readable_sync_status, 1 ) );
113
114
		require_once JETPACK__PLUGIN_DIR. 'sync/class.jetpack-sync-sender.php';
115
116
		$queue = Jetpack_Sync_Sender::get_instance()->get_sync_queue();
117
118
		$debug_info .= "\r\n". sprintf( esc_html__( 'Sync Queue size: %1$s', 'jetpack' ), $queue->size() );
119
		$debug_info .= "\r\n". sprintf( esc_html__( 'Sync Queue lag: %1$s', 'jetpack' ), self::seconds_to_time( $queue->lag() ) );
120
121
		$full_sync_queue = Jetpack_Sync_Sender::get_instance()->get_full_sync_queue();
122
123
		$debug_info .= "\r\n". sprintf( esc_html__( 'Full Sync Queue size: %1$s', 'jetpack' ), $full_sync_queue->size() );
124
		$debug_info .= "\r\n". sprintf( esc_html__( 'Full Sync Queue lag: %1$s', 'jetpack' ), self::seconds_to_time( $full_sync_queue->lag() ) );
125
126
		$debug_info .= "\r\n";
127
128
		foreach ( array (
129
					  'HTTP_HOST',
130
					  'SERVER_PORT',
131
					  'HTTPS',
132
					  'GD_PHP_HANDLER',
133
					  'HTTP_AKAMAI_ORIGIN_HOP',
134
					  'HTTP_CF_CONNECTING_IP',
135
					  'HTTP_CLIENT_IP',
136
					  'HTTP_FASTLY_CLIENT_IP',
137
					  'HTTP_FORWARDED',
138
					  'HTTP_FORWARDED_FOR',
139
					  'HTTP_INCAP_CLIENT_IP',
140
					  'HTTP_TRUE_CLIENT_IP',
141
					  'HTTP_X_CLIENTIP',
142
					  'HTTP_X_CLUSTER_CLIENT_IP',
143
					  'HTTP_X_FORWARDED',
144
					  'HTTP_X_FORWARDED_FOR',
145
					  'HTTP_X_IP_TRAIL',
146
					  'HTTP_X_REAL_IP',
147
					  'HTTP_X_VARNISH',
148
					  'REMOTE_ADDR'
149
				  ) as $header ) {
150
			if ( isset( $_SERVER[ $header ] ) ) {
151
				$debug_info .= "\r\n" . esc_html( $header . ": " . $_SERVER[ $header ] );
152
			}
153
		}
154
155
		$debug_info .= "\r\n" . esc_html( "PROTECT_TRUSTED_HEADER: " . json_encode( get_site_option( 'trusted_ip_header' ) ) );
156
157
		$debug_info .= "\r\n\r\nTEST RESULTS:\r\n\r\n";
158
		$debug_raw_info = '';
159
160
161
		$tests = array();
162
163
		$tests['HTTP']['result'] = wp_remote_get( preg_replace( '/^https:/', 'http:', JETPACK__API_BASE ) . 'test/1/' );
164
		$tests['HTTP']['fail_message'] = esc_html__( 'Your site isn’t reaching the Jetpack servers.', 'jetpack' );
165
166
		$tests['HTTPS']['result'] = wp_remote_get( preg_replace( '/^http:/', 'https:', JETPACK__API_BASE ) . 'test/1/' );
167
		$tests['HTTPS']['fail_message'] = esc_html__( 'Your site isn’t securely reaching the Jetpack servers.', 'jetpack' );
168
169
		$identity_crisis_message = '';
170
		if ( $identity_crisis = Jetpack::check_identity_crisis() ) {
171
			$identity_crisis_message .= sprintf(
172
				__( 'Your url is set as `%1$s`, but your WordPress.com connection lists it as `%2$s`!', 'jetpack' ),
173
				$identity_crisis['home'],
174
				$identity_crisis['wpcom_home']
175
			);
176
			$identity_crisis = new WP_Error( 'identity-crisis', $identity_crisis_message, $identity_crisis );
177
		} else {
178
			$identity_crisis = 'PASS';
179
		}
180
		$tests['IDENTITY_CRISIS']['result'] = $identity_crisis;
181
		$tests['IDENTITY_CRISIS']['fail_message'] = esc_html__( 'Something has gotten mixed up in your Jetpack Connection!', 'jetpack' );
182
183
		$self_xml_rpc_url = site_url( 'xmlrpc.php' );
184
185
		$testsite_url = Jetpack::fix_url_for_bad_hosts( JETPACK__API_BASE . 'testsite/1/?url=' );
186
187
		add_filter( 'http_request_timeout', array( 'Jetpack_Debugger', 'jetpack_increase_timeout' ) );
188
189
		$tests['SELF']['result'] = wp_remote_get( $testsite_url . $self_xml_rpc_url );
190
		if ( is_wp_error( $tests['SELF']['result'] ) && 0 == strpos( $tests['SELF']['result']->get_error_message(), 'Operation timed out' ) ){
191
			$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' );
192
		} else {
193
			$tests['SELF']['fail_message'] = esc_html__( 'It looks like your site can not communicate properly with Jetpack.', 'jetpack' );
194
		}
195
196
		remove_filter( 'http_request_timeout', array( 'Jetpack_Debugger', 'jetpack_increase_timeout' ) );
197
198
		?>
199
		<div class="wrap">
200
			<h2><?php esc_html_e( 'Jetpack Debugging Center', 'jetpack' ); ?></h2>
201
			<?php if ( $can_disconnect ) : ?>
0 ignored issues
show
The variable $can_disconnect does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
202
				<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>
203
					<button type="button" class="notice-dismiss"><span class="screen-reader-text"><?php esc_html_e( 'Dismiss this notice.', 'jetpack' ); ?></span></button></div>
204
			<?php else: ?>
205
				<h3><?php _e( "Testing your site's compatibility with Jetpack...", 'jetpack' ); ?></h3>
206
				<div class="jetpack-debug-test-container">
207
					<?php
208
					ob_start();
209
					foreach ( $tests as $test_name => $test_info ) :
210
						if ( 'PASS' !== $test_info['result'] && ( is_wp_error( $test_info['result'] ) ||
211
								false == ( $response_code = wp_remote_retrieve_response_code( $test_info['result'] ) )  ||
212
								'200' != $response_code ) ) {
213
							$debug_info .= $test_name . ": FAIL\r\n";
214
							?>
215
							<div class="jetpack-test-error">
216
							<p>
217
								<a class="jetpack-test-heading" href="#"><?php echo $test_info['fail_message']; ?>
218
									<span class="noticon noticon-collapse"></span>
219
								</a>
220
							</p>
221
						<pre class="jetpack-test-details"><?php echo esc_html( $test_name ); ?>:
222
							<?php echo esc_html( is_wp_error( $test_info['result'] ) ? $test_info['result']->get_error_message() : print_r( $test_info['result'], 1 ) ); ?></pre>
223
							</div><?php
224
						} else {
225
							$debug_info .= $test_name . ": PASS\r\n";
226
						}
227
						$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 ) );
228
						?>
229
					<?php endforeach;
230
					$html = ob_get_clean();
231
232
					if ( '' == trim( $html ) ) {
233
						echo '<div class="jetpack-tests-succed">' . esc_html__( 'Your Jetpack setup looks a-okay!', 'jetpack' ) . '</div>';
234
					} else {
235
						echo '<h3>' . esc_html__( 'There seems to be a problem with your site’s ability to communicate with Jetpack!', 'jetpack' ) . '</h3>';
236
						echo $html;
237
					}
238
					$debug_info .= "\r\n\r\nRAW TEST RESULTS:" . $debug_raw_info ."\r\n";
239
					?>
240
				</div>
241
			<?php endif; ?>
242
243
			<div class="entry-content">
244
				<h3><?php esc_html_e( 'Trouble with Jetpack?', 'jetpack' ); ?></h3>
245
				<h4><?php esc_html_e( 'It may be caused by one of these issues, which you can diagnose yourself:', 'jetpack' ); ?></h4>
246
				<ol>
247
					<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>
248
					<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>
249
					<li>
250
						<b><em><?php esc_html_e( 'A theme conflict.', 'jetpack' ); ?></em></b>
251
						<?php
252
							$default_theme = wp_get_theme( WP_DEFAULT_THEME );
253
254
							if ( $default_theme->exists() ) {
255
								/* translators: %s is the name of a theme */
256
								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' ) ) );
257
							} else {
258
								esc_html_e( "If your problem isn't known or caused by a plugin, try activating the default WordPress theme.", 'jetpack' );
259
							}
260
						?>
261
						<?php esc_html_e( "If this solves the problem, something in your theme is probably broken – let the theme's author know.", 'jetpack' ); ?>
262
					</li>
263
					<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' ) ); ?>
264
						<ul>
265
							<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>
266
							<li>- <?php esc_html_e( "If you get a 404 message, contact your web host. Their security may block XMLRPC.", 'jetpack' ); ?></li>
267
						</ul>
268
					</li>
269
					<?php if ( current_user_can( 'jetpack_disconnect' ) && Jetpack::is_active() ) : ?>
270
						<li>
271
							<strong><em><?php esc_html_e( 'A connection problem with WordPress.com.', 'jetpack' ); ?></em></strong>
272
							<?php
273
							echo wp_kses(
274
								sprintf(
275
									__( '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' ),
276
									wp_nonce_url(
277
										Jetpack::admin_url( array( 'page' => 'jetpack-debugger', 'disconnect' => true ) ),
278
										'jp_disconnect',
279
										'nonce'
280
									)
281
								),
282
								array( 'a' => array( 'href'  => array(), 'class' => array() ) )
283
							);
284
							?>
285
						</li>
286
					<?php endif; ?>
287
				</ol>
288
				<?php if ( self::is_jetpack_support_open() ): ?>
289
				<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 ) ) ); ?>
290
				</p>
291
				<?php endif; ?>
292
				<hr />
293
				<?php if ( Jetpack::is_active() ) : ?>
294
					<div id="connected-user-details">
295
						<p><?php printf( /* translators: %s is an e-mail address */ __( 'The primary connection is owned by <strong>%s</strong>\'s WordPress.com account.', 'jetpack' ), esc_html( Jetpack::get_master_user_email() ) ); ?></p>
296
					</div>
297
				<?php else : ?>
298
					<div id="dev-mode-details">
299
						<p><?php printf(
300
							__( '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' ),
301
							'https://jetpack.com/support/development-mode/'
302
						); ?></p>
303
					</div>
304
				<?php endif; ?>
305
			</div>
306
			<div id="contact-message" <?php if( ! isset( $_GET['contact'] ) ) {?>  style="display:none" <?php } ?>>
307
			<?php if ( self::is_jetpack_support_open() ): ?>
308
				<form id="contactme" method="post" action="https://jetpack.com/contact-support/">
309
					<input type="hidden" name="action" value="submit">
310
					<input type="hidden" name="jetpack" value="needs-service">
311
312
					<input type="hidden" name="contact_form" id="contact_form" value="1">
313
					<input type="hidden" name="blog_url" id="blog_url" value="<?php echo esc_attr( site_url() ); ?>">
314
					<?php
315
						$subject_line = sprintf(
316
							/* translators: %s is the URL of the site */
317
							_x( 'from: %s Jetpack contact form', 'Support request email subject line', 'jetpack' ),
318
							esc_attr( site_url() )
319
						);
320
321
						if ( Jetpack::is_development_version() ) {
322
							$subject_line = 'BETA ' . $subject_line;
323
						}
324
325
						$subject_line_input = printf(
326
							'<input type="hidden" name="subject" id="subject" value="%s"">',
327
							$subject_line
328
						);
329
					?>
330
					<div class="formbox">
331
						<label for="message" class="h"><?php esc_html_e( 'Please describe the problem you are having.', 'jetpack' ); ?></label>
332
						<textarea name="message" cols="40" rows="7" id="did"></textarea>
333
					</div>
334
335
					<div id="name_div" class="formbox">
336
						<label class="h" for="your_name"><?php esc_html_e( 'Name', 'jetpack' ); ?></label>
337
			  			<span class="errormsg"><?php esc_html_e( 'Let us know your name.', 'jetpack' ); ?></span>
338
						<input name="your_name" type="text" id="your_name" value="<?php esc_html_e( $current_user->display_name, 'jetpack'); ?>" size="40">
339
					</div>
340
341
					<div id="email_div" class="formbox">
342
						<label class="h" for="your_email"><?php esc_html_e( 'Email', 'jetpack' ); ?></label>
343
			  			<span class="errormsg"><?php esc_html_e( 'Use a valid email address.', 'jetpack' ); ?></span>
344
						<input name="your_email" type="text" id="your_email" value="<?php esc_html_e( $current_user->user_email, 'jetpack'); ?>" size="40">
345
					</div>
346
347
					<div id="toggle_debug_form_info" class="formbox">
348
						<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>
349
					</div>
350
351
					<div id="debug_info_form_div" class="formbox" style="display:none">
352
						<label class="h" for="debug_info"><?php esc_html_e( 'Debug Info', 'jetpack' ); ?></label>
353
			  			<textarea name="debug_info" cols="40" rows="7" id="debug_form_info"><?php echo esc_attr( $debug_info ); ?></textarea>
354
					</div>
355
356
					<div style="clear: both;"></div>
357
358
					<div id="blog_div" class="formbox">
359
						<div id="submit_div" class="contact-support">
360
						<input type="submit" name="submit" value="<?php esc_html_e( 'Submit &#187;', 'jetpack' ); ?>">
361
						</div>
362
					</div>
363
					<div style="clear: both;"></div>
364
				</form>
365
			<?php endif; ?>
366
		</div> <!-- contact-message, hidden by default. -->
367
		<div id="toggle_debug_info"><a href="#"><?php _e( 'View Advanced Debug Results', 'jetpack' ); ?></a></div>
368
			<div id="debug_info_div" style="display:none">
369
			<h4><?php esc_html_e( 'Debug Info', 'jetpack' ); ?></h4>
370
			<div id="debug_info"><pre><?php echo esc_html( $debug_info ) ; ?></pre></div>
371
		</div>
372
		</div>
373
	<?php
374
	}
375
376
	public static function jetpack_debug_admin_head() {
377
		?>
378
		<style type="text/css">
379
380
			.jetpack-debug-test-container {
381
				margin-top: 20px;
382
				margin-bottom: 30px;
383
			}
384
385
			.jetpack-tests-succed {
386
				font-size: large;
387
				color: #8BAB3E;
388
			}
389
390
			.jetpack-test-details {
391
				margin: 4px 6px;
392
				padding: 10px;
393
				overflow: auto;
394
				display: none;
395
			}
396
397
			.jetpack-test-error {
398
				margin-bottom: 10px;
399
				background: #FFEBE8;
400
				border: solid 1px #C00;
401
				border-radius: 3px;
402
			}
403
404
			.jetpack-test-error p {
405
				margin: 0;
406
				padding: 0;
407
			}
408
409
			.jetpack-test-error a.jetpack-test-heading {
410
				padding: 4px 6px;
411
				display: block;
412
				text-decoration: none;
413
				color: inherit;
414
			}
415
416
			.jetpack-test-error .noticon {
417
				float: right;
418
			}
419
420
			form#contactme {
421
				border: 1px solid #dfdfdf;
422
				background: #eaf3fa;
423
				padding: 20px;
424
				margin: 10px;
425
				background-color: #eaf3fa;
426
				border-radius: 5px;
427
				font-size: 15px;
428
			}
429
430
			form#contactme label.h {
431
				color: #444;
432
				display: block;
433
				font-weight: bold;
434
				margin: 0 0 7px 10px;
435
				text-shadow: 1px 1px 0 #fff;
436
			}
437
438
			.formbox {
439
				margin: 0 0 25px 0;
440
			}
441
442
			.formbox input[type="text"], .formbox input[type="email"], .formbox input[type="url"], .formbox textarea, #debug_info_div {
443
				border: 1px solid #e5e5e5;
444
				border-radius: 11px;
445
				box-shadow: inset 0 1px 1px rgba(0,0,0,0.1);
446
				color: #666;
447
				font-size: 14px;
448
				padding: 10px;
449
				width: 97%;
450
			}
451
			#debug_info_div {
452
				border-radius: 0;
453
				margin-top: 16px;
454
				background: #FFF;
455
				padding: 16px;
456
			}
457
			.formbox .contact-support input[type="submit"] {
458
				float: right;
459
				margin: 0 !important;
460
				border-radius: 20px !important;
461
				cursor: pointer;
462
				font-size: 13pt !important;
463
				height: auto !important;
464
				margin: 0 0 2em 10px !important;
465
				padding: 8px 16px !important;
466
				background-color: #ddd;
467
				border: 1px solid rgba(0,0,0,0.05);
468
				border-top-color: rgba(255,255,255,0.1);
469
				border-bottom-color: rgba(0,0,0,0.15);
470
				color: #333;
471
				font-weight: 400;
472
				display: inline-block;
473
				text-align: center;
474
				text-decoration: none;
475
			}
476
477
			.formbox span.errormsg {
478
				margin: 0 0 10px 10px;
479
				color: #d00;
480
				display: none;
481
			}
482
483
			.formbox.error span.errormsg {
484
				display: block;
485
			}
486
487
			#contact-message ul {
488
				margin: 0 0 20px 10px;
489
			}
490
491
			#contact-message li {
492
				margin: 0 0 10px 10px;
493
				list-style: disc;
494
				display: list-item;
495
			}
496
497
			#debug_info_div, #toggle_debug_info, #debug_info_div p {
498
				font-size: 12px;
499
			}
500
501
		</style>
502
		<script type="text/javascript">
503
		jQuery( document ).ready( function($) {
504
505
			$( '#debug_info' ).prepend( 'jQuery version: ' + jQuery.fn.jquery + "\r\n" );
506
			$( '#debug_form_info' ).prepend( 'jQuery version: ' + jQuery.fn.jquery + "\r\n" );
507
508
			$( '.jetpack-test-error .jetpack-test-heading' ).on( 'click', function() {
509
				$( this ).parents( '.jetpack-test-error' ).find( '.jetpack-test-details' ).slideToggle();
510
				return false;
511
			} );
512
513
			$( '.jetpack-show-contact-form a' ).on( 'click', function() {
514
				$( '#contact-message' ).slideToggle();
515
				return false;
516
			} );
517
518
			$( '#toggle_debug_info a' ).on( 'click', function() {
519
				$( '#debug_info_div' ).slideToggle();
520
				return false;
521
			} );
522
523
			$( '#toggle_debug_form_info a' ).on( 'click', function() {
524
				$( '#debug_info_form_div' ).slideToggle();
525
				return false;
526
			} );
527
528
			$( 'form#contactme' ).on( "submit", function(e){
529
				var form = $( this );
530
				var message = form.find( '#did' );
531
				var name = form.find( '#your_name' );
532
				var email = form.find( '#your_email' )
533
				var validation_error = false;
534
				if( !name.val() ) {
535
					name.parents( '.formbox' ).addClass( 'error' );
536
					validation_error = true;
537
				}
538
				if( !email.val() ) {
539
					email.parents( '.formbox' ).addClass( 'error' );
540
					validation_error = true;
541
				}
542
				if ( validation_error ) {
543
					return false;
544
				}
545
				message.val( message.val() + "\r\n\r\n----------------------------------------------\r\n\r\nDEBUG INFO:\r\n" + $('#debug_form_info').val()  );
546
				return true;
547
	    	});
548
549
		} );
550
		</script>
551
		<?php
552
	}
553
}
554