Completed
Push — fix/visibility-condition-issue... ( eee6fd...a71c15 )
by
unknown
11:07
created

Jetpack_Debugger::what_jetpack_plan()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
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 jetpack_debug_display_handler() {
53
		if ( ! current_user_can( 'manage_options' ) )
54
			wp_die( esc_html__('You do not have sufficient permissions to access this page.', 'jetpack' ) );
55
56
		$current_user = wp_get_current_user();
57
58
		$user_id = get_current_user_id();
59
		$user_tokens = Jetpack_Options::get_option( 'user_tokens' );
60
		if ( is_array( $user_tokens ) && array_key_exists( $user_id, $user_tokens ) ) {
61
			$user_token = $user_tokens[$user_id];
62
		} else {
63
			$user_token = '[this user has no token]';
64
		}
65
		unset( $user_tokens );
66
67
		$debug_info = "\r\n";
68
		foreach ( array(
69
			'CLIENT_ID'   => 'id',
70
			'BLOG_TOKEN'  => 'blog_token',
71
			'MASTER_USER' => 'master_user',
72
			'CERT'        => 'fallback_no_verify_ssl_certs',
73
			'TIME_DIFF'   => 'time_diff',
74
			'VERSION'     => 'version',
75
			'OLD_VERSION' => 'old_version',
76
			'PUBLIC'      => 'public',
77
		) as $label => $option_name ) {
78
			$debug_info .= "\r\n" . esc_html( $label . ": " . Jetpack_Options::get_option( $option_name ) );
79
		}
80
81
		$debug_info .= "\r\n" . esc_html( "USER_ID: " . $user_id );
82
		$debug_info .= "\r\n" . esc_html( "USER_TOKEN: " . $user_token );
83
		$debug_info .= "\r\n" . esc_html( "PHP_VERSION: " . PHP_VERSION );
84
		$debug_info .= "\r\n" . esc_html( "WORDPRESS_VERSION: " . $GLOBALS['wp_version'] );
85
		$debug_info .= "\r\n" . esc_html( "JETPACK__VERSION: " . JETPACK__VERSION );
86
		$debug_info .= "\r\n" . esc_html( "JETPACK__PLUGIN_DIR: " . JETPACK__PLUGIN_DIR );
87
		$debug_info .= "\r\n" . esc_html( "SITE_URL: " . site_url() );
88
		$debug_info .= "\r\n" . esc_html( "HOME_URL: " . home_url() );
89
		$debug_info .= "\r\n" . esc_html( "PLAN: " . self::what_jetpack_plan() );
90
91
		$debug_info .= "\r\n";
92
		require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-modules.php';
93
		$sync_module = Jetpack_Sync_Modules::get_module( 'full-sync' );
94
		$sync_statuses = $sync_module->get_status();
95
		$human_readable_sync_status = array();
96
		foreach( $sync_statuses  as $sync_status => $sync_status_value ) {
97
			$human_readable_sync_status[ $sync_status ] =
98
				in_array( $sync_status, array( 'started', 'queue_finished', 'send_started', 'finished' ) )
99
				? date( 'r', $sync_status_value ) : $sync_status_value ;
100
		}
101
102
		$debug_info .= "\r\n". sprintf( esc_html__( 'Jetpack Sync Full Status: `%1$s`', 'jetpack' ), print_r( $human_readable_sync_status, 1 ) );
103
104
		require_once JETPACK__PLUGIN_DIR. 'sync/class.jetpack-sync-sender.php';
105
106
		$queue = Jetpack_Sync_Sender::get_instance()->get_sync_queue();
107
108
		$debug_info .= "\r\n". sprintf( esc_html__( 'Sync Queue size: %1$s', 'jetpack' ), $queue->size() );
109
		$debug_info .= "\r\n". sprintf( esc_html__( 'Sync Queue lag: %1$s', 'jetpack' ), self::seconds_to_time( $queue->lag() ) );
110
111
		$full_sync_queue = Jetpack_Sync_Sender::get_instance()->get_full_sync_queue();
112
113
		$debug_info .= "\r\n". sprintf( esc_html__( 'Full Sync Queue size: %1$s', 'jetpack' ), $full_sync_queue->size() );
114
		$debug_info .= "\r\n". sprintf( esc_html__( 'Full Sync Queue lag: %1$s', 'jetpack' ), self::seconds_to_time( $full_sync_queue->lag() ) );
115
116
		$debug_info .= "\r\n";
117
118
		foreach ( array (
119
					  'HTTP_HOST',
120
					  'SERVER_PORT',
121
					  'HTTPS',
122
					  'GD_PHP_HANDLER',
123
					  'HTTP_AKAMAI_ORIGIN_HOP',
124
					  'HTTP_CF_CONNECTING_IP',
125
					  'HTTP_CLIENT_IP',
126
					  'HTTP_FASTLY_CLIENT_IP',
127
					  'HTTP_FORWARDED',
128
					  'HTTP_FORWARDED_FOR',
129
					  'HTTP_INCAP_CLIENT_IP',
130
					  'HTTP_TRUE_CLIENT_IP',
131
					  'HTTP_X_CLIENTIP',
132
					  'HTTP_X_CLUSTER_CLIENT_IP',
133
					  'HTTP_X_FORWARDED',
134
					  'HTTP_X_FORWARDED_FOR',
135
					  'HTTP_X_IP_TRAIL',
136
					  'HTTP_X_REAL_IP',
137
					  'HTTP_X_VARNISH',
138
					  'REMOTE_ADDR'
139
				  ) as $header ) {
140
			if ( isset( $_SERVER[ $header ] ) ) {
141
				$debug_info .= "\r\n" . esc_html( $header . ": " . $_SERVER[ $header ] );
142
			}
143
		}
144
145
		$debug_info .= "\r\n" . esc_html( "PROTECT_TRUSTED_HEADER: " . json_encode( get_site_option( 'trusted_ip_header' ) ) );
146
147
		$debug_info .= "\r\n\r\nTEST RESULTS:\r\n\r\n";
148
		$debug_raw_info = '';
149
150
151
		$tests = array();
152
153
		$tests['HTTP']['result'] = wp_remote_get( preg_replace( '/^https:/', 'http:', JETPACK__API_BASE ) . 'test/1/' );
154
		$tests['HTTP']['fail_message'] = esc_html__( 'Your site isn’t reaching the Jetpack servers.', 'jetpack' );
155
156
		$tests['HTTPS']['result'] = wp_remote_get( preg_replace( '/^http:/', 'https:', JETPACK__API_BASE ) . 'test/1/' );
157
		$tests['HTTPS']['fail_message'] = esc_html__( 'Your site isn’t securely reaching the Jetpack servers.', 'jetpack' );
158
159
		$identity_crisis_message = '';
160
		if ( $identity_crisis = Jetpack::check_identity_crisis() ) {
161
			$identity_crisis_message .= sprintf(
162
				__( 'Your url is set as `%1$s`, but your WordPress.com connection lists it as `%2$s`!', 'jetpack' ),
163
				$identity_crisis['home'],
164
				$identity_crisis['wpcom_home']
165
			);
166
			$identity_crisis = new WP_Error( 'identity-crisis', $identity_crisis_message, $identity_crisis );
167
		} else {
168
			$identity_crisis = 'PASS';
169
		}
170
		$tests['IDENTITY_CRISIS']['result'] = $identity_crisis;
171
		$tests['IDENTITY_CRISIS']['fail_message'] = esc_html__( 'Something has gotten mixed up in your Jetpack Connection!', 'jetpack' );
172
173
		$self_xml_rpc_url = site_url( 'xmlrpc.php' );
174
175
		$testsite_url = Jetpack::fix_url_for_bad_hosts( JETPACK__API_BASE . 'testsite/1/?url=' );
176
177
		add_filter( 'http_request_timeout', array( 'Jetpack_Debugger', 'jetpack_increase_timeout' ) );
178
179
		$tests['SELF']['result'] = wp_remote_get( $testsite_url . $self_xml_rpc_url );
180
		if ( is_wp_error( $tests['SELF']['result'] ) && 0 == strpos( $tests['SELF']['result']->get_error_message(), 'Operation timed out' ) ){
181
			$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' );
182
		} else {
183
			$tests['SELF']['fail_message'] = esc_html__( 'It looks like your site can not communicate properly with Jetpack.', 'jetpack' );
184
		}
185
186
		remove_filter( 'http_request_timeout', array( 'Jetpack_Debugger', 'jetpack_increase_timeout' ) );
187
188
		?>
189
		<div class="wrap">
190
			<h2><?php esc_html_e( 'Jetpack Debugging Center', 'jetpack' ); ?></h2>
191
			<h3><?php _e( "Testing your site's compatibility with Jetpack...", 'jetpack' ); ?></h3>
192
			<div class="jetpack-debug-test-container">
193
			<?php
194
			ob_start();
195
			foreach ( $tests as $test_name => $test_info ) :
196
				if ( 'PASS' !== $test_info['result'] && ( is_wp_error( $test_info['result'] ) ||
197
					false == ( $response_code = wp_remote_retrieve_response_code( $test_info['result'] ) )  ||
198
					'200' != $response_code ) ) {
0 ignored issues
show
Bug introduced by
The variable $response_code does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
199
					$debug_info .= $test_name . ": FAIL\r\n";
200
					?>
201
					<div class="jetpack-test-error">
202
						<p>
203
							<a class="jetpack-test-heading" href="#"><?php echo $test_info['fail_message']; ?>
204
							<span class="noticon noticon-collapse"></span>
205
							</a>
206
						</p>
207
						<pre class="jetpack-test-details"><?php echo esc_html( $test_name ); ?>:
208
	<?php echo esc_html( is_wp_error( $test_info['result'] ) ? $test_info['result']->get_error_message() : print_r( $test_info['result'], 1 ) ); ?></pre>
209
					</div><?php
210
				} else {
211
					$debug_info .= $test_name . ": PASS\r\n";
212
				}
213
				$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 ) );
214
				?>
215
			<?php endforeach;
216
			$html = ob_get_clean();
217
218
			if ( '' == trim( $html ) ) {
219
				echo '<div class="jetpack-tests-succed">' . esc_html__( 'Your Jetpack setup looks a-okay!', 'jetpack' ) . '</div>';
220
			}
221
			else {
222
				echo '<h3>' . esc_html__( 'There seems to be a problem with your site’s ability to communicate with Jetpack!', 'jetpack' ) . '</h3>';
223
				echo $html;
224
			}
225
			$debug_info .= "\r\n\r\nRAW TEST RESULTS:" . $debug_raw_info ."\r\n";
226
			?>
227
			</div>
228
			<div class="entry-content">
229
				<h3><?php esc_html_e( 'Trouble with Jetpack?', 'jetpack' ); ?></h3>
230
				<h4><?php esc_html_e( 'It may be caused by one of these issues, which you can diagnose yourself:', 'jetpack' ); ?></h4>
231
				<ol>
232
					<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>
233
					<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>
234
					<li>
235
						<b><em><?php esc_html_e( 'A theme conflict.', 'jetpack' ); ?></em></b>
236
						<?php
237
							$default_theme = wp_get_theme( WP_DEFAULT_THEME );
238
239
							if ( $default_theme->exists() ) {
240
								/* translators: %s is the name of a theme */
241
								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' ) ) );
242
							} else {
243
								esc_html_e( "If your problem isn't known or caused by a plugin, try activating the default WordPress theme.", 'jetpack' );
244
							}
245
						?>
246
						<?php esc_html_e( "If this solves the problem, something in your theme is probably broken – let the theme's author know.", 'jetpack' ); ?>
247
					</li>
248
					<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' ) ); ?>
249
						<ul>
250
							<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>
251
							<li>- <?php esc_html_e( "If you get a 404 message, contact your web host. Their security may block XMLRPC.", 'jetpack' ); ?></li>
252
						</ul>
253
					</li>
254
				</ol>
255
				<?php if ( self::is_jetpack_support_open() ): ?>
256
				<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 ) ) ); ?>
257
				</p>
258
				<?php endif; ?>
259
				<hr />
260
				<?php if ( Jetpack::is_active() ) : ?>
261
					<div id="connected-user-details">
262
						<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>
263
					</div>
264
				<?php else : ?>
265
					<div id="dev-mode-details">
266
						<p><?php printf(
267
							__( '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' ),
268
							'https://jetpack.com/support/development-mode/'
269
						); ?></p>
270
					</div>
271
				<?php endif; ?>
272
			</div>
273
			<div id="contact-message" <?php if( ! isset( $_GET['contact'] ) ) {?>  style="display:none" <?php } ?>>
274
			<?php if ( self::is_jetpack_support_open() ): ?>
275
				<form id="contactme" method="post" action="https://jetpack.com/contact-support/">
276
					<input type="hidden" name="action" value="submit">
277
					<input type="hidden" name="jetpack" value="needs-service">
278
279
					<input type="hidden" name="contact_form" id="contact_form" value="1">
280
					<input type="hidden" name="blog_url" id="blog_url" value="<?php echo esc_attr( site_url() ); ?>">
281
					<?php
282
						$subject_line = sprintf(
283
							/* translators: %s is the URL of the site */
284
							_x( 'from: %s Jetpack contact form', 'Support request email subject line', 'jetpack' ),
285
							esc_attr( site_url() )
286
						);
287
288
						if ( Jetpack::is_development_version() ) {
289
							$subject_line = 'BETA ' . $subject_line;
290
						}
291
292
						$subject_line_input = printf(
0 ignored issues
show
Unused Code introduced by
$subject_line_input is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
293
							'<input type="hidden" name="subject" id="subject" value="%s"">',
294
							$subject_line
295
						);
296
					?>
297
					<div class="formbox">
298
						<label for="message" class="h"><?php esc_html_e( 'Please describe the problem you are having.', 'jetpack' ); ?></label>
299
						<textarea name="message" cols="40" rows="7" id="did"></textarea>
300
					</div>
301
302
					<div id="name_div" class="formbox">
303
						<label class="h" for="your_name"><?php esc_html_e( 'Name', 'jetpack' ); ?></label>
304
			  			<span class="errormsg"><?php esc_html_e( 'Let us know your name.', 'jetpack' ); ?></span>
305
						<input name="your_name" type="text" id="your_name" value="<?php esc_html_e( $current_user->display_name, 'jetpack'); ?>" size="40">
306
					</div>
307
308
					<div id="email_div" class="formbox">
309
						<label class="h" for="your_email"><?php esc_html_e( 'Email', 'jetpack' ); ?></label>
310
			  			<span class="errormsg"><?php esc_html_e( 'Use a valid email address.', 'jetpack' ); ?></span>
311
						<input name="your_email" type="text" id="your_email" value="<?php esc_html_e( $current_user->user_email, 'jetpack'); ?>" size="40">
312
					</div>
313
314
					<div id="toggle_debug_form_info" class="formbox">
315
						<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>
316
					</div>
317
318
					<div id="debug_info_form_div" class="formbox" style="display:none">
319
						<label class="h" for="debug_info"><?php esc_html_e( 'Debug Info', 'jetpack' ); ?></label>
320
			  			<textarea name="debug_info" cols="40" rows="7" id="debug_form_info"><?php echo esc_attr( $debug_info ); ?></textarea>
321
					</div>
322
323
					<div style="clear: both;"></div>
324
325
					<div id="blog_div" class="formbox">
326
						<div id="submit_div" class="contact-support">
327
						<input type="submit" name="submit" value="<?php esc_html_e( 'Submit &#187;', 'jetpack' ); ?>">
328
						</div>
329
					</div>
330
					<div style="clear: both;"></div>
331
				</form>
332
			<?php endif; ?>
333
		</div> <!-- contact-message, hidden by default. -->
334
		<div id="toggle_debug_info"><a href="#"><?php _e( 'View Advanced Debug Results', 'jetpack' ); ?></a></div>
335
			<div id="debug_info_div" style="display:none">
336
			<h4><?php esc_html_e( 'Debug Info', 'jetpack' ); ?></h4>
337
			<div id="debug_info"><pre><?php echo esc_html( $debug_info ) ; ?></pre></div>
338
		</div>
339
		</div>
340
	<?php
341
	}
342
343
	public static function jetpack_debug_admin_head() {
344
		?>
345
		<style type="text/css">
346
347
			.jetpack-debug-test-container {
348
				margin-top: 20px;
349
				margin-bottom: 30px;
350
			}
351
352
			.jetpack-tests-succed {
353
				font-size: large;
354
				color: #8BAB3E;
355
			}
356
357
			.jetpack-test-details {
358
				margin: 4px 6px;
359
				padding: 10px;
360
				overflow: auto;
361
				display: none;
362
			}
363
364
			.jetpack-test-error {
365
				margin-bottom: 10px;
366
				background: #FFEBE8;
367
				border: solid 1px #C00;
368
				border-radius: 3px;
369
			}
370
371
			.jetpack-test-error p {
372
				margin: 0;
373
				padding: 0;
374
			}
375
376
			.jetpack-test-error a.jetpack-test-heading {
377
				padding: 4px 6px;
378
				display: block;
379
				text-decoration: none;
380
				color: inherit;
381
			}
382
383
			.jetpack-test-error .noticon {
384
				float: right;
385
			}
386
387
			form#contactme {
388
				border: 1px solid #dfdfdf;
389
				background: #eaf3fa;
390
				padding: 20px;
391
				margin: 10px;
392
				background-color: #eaf3fa;
393
				border-radius: 5px;
394
				font-size: 15px;
395
			}
396
397
			form#contactme label.h {
398
				color: #444;
399
				display: block;
400
				font-weight: bold;
401
				margin: 0 0 7px 10px;
402
				text-shadow: 1px 1px 0 #fff;
403
			}
404
405
			.formbox {
406
				margin: 0 0 25px 0;
407
			}
408
409
			.formbox input[type="text"], .formbox input[type="email"], .formbox input[type="url"], .formbox textarea, #debug_info_div {
410
				border: 1px solid #e5e5e5;
411
				border-radius: 11px;
412
				box-shadow: inset 0 1px 1px rgba(0,0,0,0.1);
413
				color: #666;
414
				font-size: 14px;
415
				padding: 10px;
416
				width: 97%;
417
			}
418
			#debug_info_div {
419
				border-radius: 0;
420
				margin-top: 16px;
421
				background: #FFF;
422
				padding: 16px;
423
			}
424
			.formbox .contact-support input[type="submit"] {
425
				float: right;
426
				margin: 0 !important;
427
				border-radius: 20px !important;
428
				cursor: pointer;
429
				font-size: 13pt !important;
430
				height: auto !important;
431
				margin: 0 0 2em 10px !important;
432
				padding: 8px 16px !important;
433
				background-color: #ddd;
434
				border: 1px solid rgba(0,0,0,0.05);
435
				border-top-color: rgba(255,255,255,0.1);
436
				border-bottom-color: rgba(0,0,0,0.15);
437
				color: #333;
438
				font-weight: 400;
439
				display: inline-block;
440
				text-align: center;
441
				text-decoration: none;
442
			}
443
444
			.formbox span.errormsg {
445
				margin: 0 0 10px 10px;
446
				color: #d00;
447
				display: none;
448
			}
449
450
			.formbox.error span.errormsg {
451
				display: block;
452
			}
453
454
			#contact-message ul {
455
				margin: 0 0 20px 10px;
456
			}
457
458
			#contact-message li {
459
				margin: 0 0 10px 10px;
460
				list-style: disc;
461
				display: list-item;
462
			}
463
464
			#debug_info_div, #toggle_debug_info, #debug_info_div p {
465
				font-size: 12px;
466
			}
467
468
		</style>
469
		<script type="text/javascript">
470
		jQuery( document ).ready( function($) {
471
472
			$( '#debug_info' ).prepend( 'jQuery version: ' + jQuery.fn.jquery + "\r\n" );
473
			$( '#debug_form_info' ).prepend( 'jQuery version: ' + jQuery.fn.jquery + "\r\n" );
474
475
			$( '.jetpack-test-error .jetpack-test-heading' ).on( 'click', function() {
476
				$( this ).parents( '.jetpack-test-error' ).find( '.jetpack-test-details' ).slideToggle();
477
				return false;
478
			} );
479
480
			$( '.jetpack-show-contact-form a' ).on( 'click', function() {
481
				$( '#contact-message' ).slideToggle();
482
				return false;
483
			} );
484
485
			$( '#toggle_debug_info a' ).on( 'click', function() {
486
				$( '#debug_info_div' ).slideToggle();
487
				return false;
488
			} );
489
490
			$( '#toggle_debug_form_info a' ).on( 'click', function() {
491
				$( '#debug_info_form_div' ).slideToggle();
492
				return false;
493
			} );
494
495
			$( 'form#contactme' ).on( "submit", function(e){
496
				var form = $( this );
497
				var message = form.find( '#did' );
498
				var name = form.find( '#your_name' );
499
				var email = form.find( '#your_email' )
500
				var validation_error = false;
501
				if( !name.val() ) {
502
					name.parents( '.formbox' ).addClass( 'error' );
503
					validation_error = true;
504
				}
505
				if( !email.val() ) {
506
					email.parents( '.formbox' ).addClass( 'error' );
507
					validation_error = true;
508
				}
509
				if ( validation_error ) {
510
					return false;
511
				}
512
				message.val( message.val() + "\r\n\r\n----------------------------------------------\r\n\r\nDEBUG INFO:\r\n" + $('#debug_form_info').val()  );
513
				return true;
514
	    	});
515
516
		} );
517
		</script>
518
		<?php
519
	}
520
}
521