Completed
Push — master ( 8a7e31...f76ead )
by Armando
12s
created
lib/class-api.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -563,7 +563,7 @@  discard block
 block discarded – undo
563 563
 	 *
564 564
 	 * @param string $url  The URL to request.
565 565
 	 * @param array  $args Arguments to be posted with the request.
566
-	 * @return object An object containing details about this request.
566
+	 * @return string An object containing details about this request.
567 567
 	 */
568 568
 	private function _request( $url, $args = array() ) {
569 569
 		// Prefix the full pod URL if necessary.
@@ -632,7 +632,7 @@  discard block
 block discarded – undo
632 632
 	 * @see WP_Error::__construct()
633 633
 	 * @since 1.6.0
634 634
 	 *
635
-	 * @param  string|int $code    Error code.
635
+	 * @param  string $code    Error code.
636 636
 	 * @param  string     $message Error message.
637 637
 	 * @param  mixed      $data    Error data.
638 638
 	 */
Please login to merge, or discard this patch.
Spacing   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
  */
20 20
 
21 21
 // Exit if accessed directly.
22
-defined( 'ABSPATH' ) || exit;
22
+defined('ABSPATH') || exit;
23 23
 
24 24
 /**
25 25
  * API class to talk to diaspora*.
@@ -128,15 +128,15 @@  discard block
 block discarded – undo
128 128
 	 * @param string $path Path to add to the pod url.
129 129
 	 * @return string Full pod url.
130 130
 	 */
131
-	public function get_pod_url( $path = '' ) {
132
-		$path = trim( $path, ' /' );
131
+	public function get_pod_url($path = '') {
132
+		$path = trim($path, ' /');
133 133
 
134 134
 		// Add a slash to the beginning?
135
-		if ( '' !== $path ) {
136
-			$path = '/' . $path;
135
+		if ('' !== $path) {
136
+			$path = '/'.$path;
137 137
 		}
138 138
 
139
-		return sprintf( 'http%s://%s%s', ( $this->_is_secure ) ? 's' : '', $this->_pod, $path );
139
+		return sprintf('http%s://%s%s', ($this->_is_secure) ? 's' : '', $this->_pod, $path);
140 140
 	}
141 141
 
142 142
 	/**
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 	 * @param string  $pod       The pod domain to connect to.
146 146
 	 * @param boolean $is_secure Is this a secure server? (Default: true).
147 147
 	 */
148
-	public function __construct( $pod, $is_secure = true ) {
148
+	public function __construct($pod, $is_secure = true) {
149 149
 		// Set class variables.
150 150
 		$this->_pod       = $pod;
151 151
 		$this->_is_secure = (bool) $is_secure;
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 	 * @param boolean $is_secure Is this a secure server? (Default: true).
160 160
 	 * @return boolean True if we could get the token, else false.
161 161
 	 */
162
-	public function init( $pod = null, $is_secure = true ) {
162
+	public function init($pod = null, $is_secure = true) {
163 163
 		// If we are changing pod, we need to fetch a new token.
164 164
 		$force_new_token = false;
165 165
 
@@ -168,21 +168,21 @@  discard block
 block discarded – undo
168 168
 		$this->_last_error = null;
169 169
 
170 170
 		// Change the pod we are connecting to?
171
-		if ( isset( $pod ) && ( $this->_pod !== $pod || $this->_is_secure !== $is_secure ) ) {
171
+		if (isset($pod) && ($this->_pod !== $pod || $this->_is_secure !== $is_secure)) {
172 172
 			$this->_pod       = $pod;
173 173
 			$this->_is_secure = (bool) $is_secure;
174 174
 			$force_new_token  = true;
175 175
 		}
176 176
 
177 177
 		// Get and save the token.
178
-		if ( null === $this->_fetch_token( $force_new_token ) ) {
179
-			$error = ( $this->has_last_error() ) ? ' ' . $this->get_last_error() : '';
180
-			$this->_error( 'wp2d_api_init_failed',
178
+		if (null === $this->_fetch_token($force_new_token)) {
179
+			$error = ($this->has_last_error()) ? ' '.$this->get_last_error() : '';
180
+			$this->_error('wp2d_api_init_failed',
181 181
 				sprintf(
182
-					_x( 'Failed to initialise connection to pod "%s".', 'Placeholder is the full pod URL.', 'wp-to-diaspora' ),
182
+					_x('Failed to initialise connection to pod "%s".', 'Placeholder is the full pod URL.', 'wp-to-diaspora'),
183 183
 					$this->get_pod_url()
184
-				) . $error,
185
-				array( 'help_tab' => 'troubleshooting' )
184
+				).$error,
185
+				array('help_tab' => 'troubleshooting')
186 186
 			);
187 187
 
188 188
 			return false;
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 	 * @return boolean If there is an API error around.
197 197
 	 */
198 198
 	public function has_last_error() {
199
-		return is_wp_error( $this->_last_error );
199
+		return is_wp_error($this->_last_error);
200 200
 	}
201 201
 
202 202
 	/**
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
 	 * @param boolean $clear If the error should be cleared after returning it.
206 206
 	 * @return WP_Error|null The last API error object or null.
207 207
 	 */
208
-	public function get_last_error_object( $clear = true ) {
208
+	public function get_last_error_object($clear = true) {
209 209
 		$last_error = $this->_last_error;
210 210
 		$clear && $this->_last_error = null;
211 211
 		return $last_error;
@@ -217,8 +217,8 @@  discard block
 block discarded – undo
217 217
 	 * @param boolean $clear If the error should be cleared after returning it.
218 218
 	 * @return string The last API error message.
219 219
 	 */
220
-	public function get_last_error( $clear = false ) {
221
-		$last_error = ( $this->has_last_error() ) ? $this->_last_error->get_error_message() : '';
220
+	public function get_last_error($clear = false) {
221
+		$last_error = ($this->has_last_error()) ? $this->_last_error->get_error_message() : '';
222 222
 		$clear && $this->_last_error = null;
223 223
 		return $last_error;
224 224
 	}
@@ -229,11 +229,11 @@  discard block
 block discarded – undo
229 229
 	 * @param boolean $force Force to fetch a new token.
230 230
 	 * @return string The fetched token.
231 231
 	 */
232
-	private function _fetch_token( $force = false ) {
233
-		if ( ! isset( $this->_token ) || (bool) $force ) {
232
+	private function _fetch_token($force = false) {
233
+		if ( ! isset($this->_token) || (bool) $force) {
234 234
 			// Go directly to the sign in page, as it would redirect to there anyway.
235 235
 			// Since _request function automatically saves the new token, just call it with no data.
236
-			$this->_request( '/users/sign_in' );
236
+			$this->_request('/users/sign_in');
237 237
 		}
238 238
 		return $this->_token;
239 239
 	}
@@ -244,8 +244,8 @@  discard block
 block discarded – undo
244 244
 	 * @return boolean Has the connection been initialised?
245 245
 	 */
246 246
 	private function _check_init() {
247
-		if ( is_null( $this->_token ) ) {
248
-			$this->_error( 'wp2d_api_connection_not_initialised', __( 'Connection not initialised.', 'wp-to-diaspora' ) );
247
+		if (is_null($this->_token)) {
248
+			$this->_error('wp2d_api_connection_not_initialised', __('Connection not initialised.', 'wp-to-diaspora'));
249 249
 			return false;
250 250
 		}
251 251
 		return true;
@@ -257,11 +257,11 @@  discard block
 block discarded – undo
257 257
 	 * @return boolean Are we logged in already?
258 258
 	 */
259 259
 	private function _check_login() {
260
-		if ( ! $this->_check_init() ) {
260
+		if ( ! $this->_check_init()) {
261 261
 			return false;
262 262
 		}
263
-		if ( ! $this->is_logged_in() ) {
264
-			$this->_error( 'wp2d_api_not_logged_in', __( 'Not logged in.', 'wp-to-diaspora' ) );
263
+		if ( ! $this->is_logged_in()) {
264
+			$this->_error('wp2d_api_not_logged_in', __('Not logged in.', 'wp-to-diaspora'));
265 265
 			return false;
266 266
 		}
267 267
 		return true;
@@ -284,17 +284,17 @@  discard block
 block discarded – undo
284 284
 	 * @param boolean $force    Force a new login even if we are already logged in.
285 285
 	 * @return boolean Did the login succeed?
286 286
 	 */
287
-	public function login( $username, $password, $force = false ) {
287
+	public function login($username, $password, $force = false) {
288 288
 		// Has the connection been initialised?
289
-		if ( ! $this->_check_init() ) {
289
+		if ( ! $this->_check_init()) {
290 290
 			$this->logout();
291 291
 			return false;
292 292
 		}
293 293
 
294 294
 		// Username and password both need to be set.
295
-		$username = ( isset( $username ) && '' !== $username ) ? $username : null;
296
-		$password = ( isset( $password ) && '' !== $password ) ? $password : null;
297
-		if ( ! isset( $username, $password ) ) {
295
+		$username = (isset($username) && '' !== $username) ? $username : null;
296
+		$password = (isset($password) && '' !== $password) ? $password : null;
297
+		if ( ! isset($username, $password)) {
298 298
 			$this->logout();
299 299
 			return false;
300 300
 		}
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
 		// If we are already logged in and not forcing a relogin, return.
303 303
 		if ( ! $force && $this->is_logged_in() &&
304 304
 			$username === $this->_username &&
305
-			$password === $this->_password ) {
305
+			$password === $this->_password) {
306 306
 			return true;
307 307
 		}
308 308
 
@@ -323,15 +323,15 @@  discard block
 block discarded – undo
323 323
 		);
324 324
 
325 325
 		// Try to sign in.
326
-		$this->_request( '/users/sign_in', $args );
326
+		$this->_request('/users/sign_in', $args);
327 327
 
328 328
 		// Can we load the bookmarklet to make sure we're logged in?
329
-		$response = $this->_request( '/bookmarklet' );
329
+		$response = $this->_request('/bookmarklet');
330 330
 
331 331
 		// If the request isn't successful, we are not logged in correctly.
332
-		if ( is_wp_error( $response ) || 200 !== $response->code ) {
332
+		if (is_wp_error($response) || 200 !== $response->code) {
333 333
 			// Login failed.
334
-			$this->_error( 'wp2d_api_login_failed', __( 'Login failed. Check your login details.', 'wp-to-diaspora' ), array( 'help_tab' => 'troubleshooting' ) );
334
+			$this->_error('wp2d_api_login_failed', __('Login failed. Check your login details.', 'wp-to-diaspora'), array('help_tab' => 'troubleshooting'));
335 335
 			$this->logout();
336 336
 			return false;
337 337
 		}
@@ -375,17 +375,17 @@  discard block
 block discarded – undo
375 375
 	 * @param array        $extra_data Any extra data to be added to the post call.
376 376
 	 * @return boolean|object Return the response data of the new diaspora* post if successfully posted, else false.
377 377
 	 */
378
-	public function post( $text, $aspects = 'public', $extra_data = array() ) {
378
+	public function post($text, $aspects = 'public', $extra_data = array()) {
379 379
 		// Are we logged in?
380
-		if ( ! $this->_check_login() ) {
380
+		if ( ! $this->_check_login()) {
381 381
 			return false;
382 382
 		}
383 383
 
384 384
 		// Put the aspects into a clean array.
385
-		$aspects = array_filter( WP2D_Helpers::str_to_arr( $aspects ) );
385
+		$aspects = array_filter(WP2D_Helpers::str_to_arr($aspects));
386 386
 
387 387
 		// If no aspects have been selected or the public one is also included, choose public only.
388
-		if ( empty( $aspects ) || in_array( 'public', $aspects ) ) {
388
+		if (empty($aspects) || in_array('public', $aspects)) {
389 389
 			$aspects = 'public';
390 390
 		}
391 391
 
@@ -399,14 +399,14 @@  discard block
 block discarded – undo
399 399
 		);
400 400
 
401 401
 		// Add any extra data to the post.
402
-		if ( ! empty( $extra_data ) ) {
402
+		if ( ! empty($extra_data)) {
403 403
 				$post_data += $extra_data;
404 404
 		}
405 405
 
406 406
 		// Check if we can use the new wp_json_encode function.
407
-		$post_data = ( function_exists( 'wp_json_encode' ) )
408
-			? wp_json_encode( $post_data )
409
-			: json_encode( $post_data );
407
+		$post_data = (function_exists('wp_json_encode'))
408
+			? wp_json_encode($post_data)
409
+			: json_encode($post_data);
410 410
 
411 411
 		$args = array(
412 412
 			'method'  => 'POST',
@@ -419,21 +419,21 @@  discard block
 block discarded – undo
419 419
 		);
420 420
 
421 421
 		// Submit the post.
422
-		$response = $this->_request( '/status_messages', $args );
422
+		$response = $this->_request('/status_messages', $args);
423 423
 
424
-		if ( is_wp_error( $response ) ) {
425
-			$this->_error( 'wp2d_api_post_failed', $response->get_error_message() );
424
+		if (is_wp_error($response)) {
425
+			$this->_error('wp2d_api_post_failed', $response->get_error_message());
426 426
 			return false;
427 427
 		}
428 428
 
429
-		$diaspost = json_decode( $response->body );
430
-		if ( 201 !== $response->code ) {
431
-			$this->_error( 'wp2d_api_post_failed', ( isset( $diaspost->error ) ) ? $diaspost->error : _x( 'Unknown error occurred.', 'When an unknown error occurred in the WP2D_API object.', 'wp-to-diaspora' ) );
429
+		$diaspost = json_decode($response->body);
430
+		if (201 !== $response->code) {
431
+			$this->_error('wp2d_api_post_failed', (isset($diaspost->error)) ? $diaspost->error : _x('Unknown error occurred.', 'When an unknown error occurred in the WP2D_API object.', 'wp-to-diaspora'));
432 432
 			return false;
433 433
 		}
434 434
 
435 435
 		// Add additional info to our diaspora post object.
436
-		$diaspost->permalink = $this->get_pod_url( '/posts/' . $diaspost->guid );
436
+		$diaspost->permalink = $this->get_pod_url('/posts/'.$diaspost->guid);
437 437
 
438 438
 		return $diaspost;
439 439
 	}
@@ -447,15 +447,15 @@  discard block
 block discarded – undo
447 447
 	 * @param string $id The ID of the post or comment to delete.
448 448
 	 * @return boolean If the deletion was successful.
449 449
 	 */
450
-	public function delete( $what, $id ) {
450
+	public function delete($what, $id) {
451 451
 		// Are we logged in?
452
-		if ( ! $this->_check_login() ) {
452
+		if ( ! $this->_check_login()) {
453 453
 			return false;
454 454
 		}
455 455
 
456 456
 		// For now, only deleting posts and comments is allowed.
457
-		if ( ! in_array( $what, array( 'post', 'comment' ) ) ) {
458
-			$this->_error( 'wp2d_api_delete_failed', __( 'You can only delete posts and comments.', 'wp-to-diaspora' ) );
457
+		if ( ! in_array($what, array('post', 'comment'))) {
458
+			$this->_error('wp2d_api_delete_failed', __('You can only delete posts and comments.', 'wp-to-diaspora'));
459 459
 			return false;
460 460
 		}
461 461
 
@@ -469,43 +469,43 @@  discard block
 block discarded – undo
469 469
 		);
470 470
 
471 471
 		// Try to delete the post or comment.
472
-		$response = $this->_request( '/' . $what . 's/' . $id, $args );
472
+		$response = $this->_request('/'.$what.'s/'.$id, $args);
473 473
 
474 474
 		$error_message = '';
475 475
 
476
-		if ( is_wp_error( $response ) ) {
476
+		if (is_wp_error($response)) {
477 477
 			$error_message = $response->get_error_message();
478 478
 		} else {
479
-			switch ( $response->code ) {
479
+			switch ($response->code) {
480 480
 				case 204:
481 481
 					return true;
482 482
 				case 404:
483
-					$error_message = ( 'post' === $what )
484
-						? __( 'The post you tried to delete does not exist.', 'wp-to-diaspora' )
485
-						: __( 'The comment you tried to delete does not exist.', 'wp-to-diaspora' );
483
+					$error_message = ('post' === $what)
484
+						? __('The post you tried to delete does not exist.', 'wp-to-diaspora')
485
+						: __('The comment you tried to delete does not exist.', 'wp-to-diaspora');
486 486
 					break;
487 487
 
488 488
 				// Due to diaspora* returning a proper 403 when trying to delete a foreign comment
489 489
 				// but returning a 500 when trying to delete a foreign post, this needs some special attention.
490 490
 				case 403:
491
-					if ( 'comment' === $what ) {
492
-						$error_message = __( 'The comment you tried to delete does not belong to you.', 'wp-to-diaspora' );
491
+					if ('comment' === $what) {
492
+						$error_message = __('The comment you tried to delete does not belong to you.', 'wp-to-diaspora');
493 493
 						break;
494 494
 					}
495 495
 					// Fall through...
496 496
 				case 500:
497
-					if ( 'post' === $what ) {
498
-						$error_message = __( 'The post you tried to delete does not belong to you.', 'wp-to-diaspora' );
497
+					if ('post' === $what) {
498
+						$error_message = __('The post you tried to delete does not belong to you.', 'wp-to-diaspora');
499 499
 						break;
500 500
 					}
501 501
 					// Fall through...
502 502
 				default:
503
-					$error_message = _x( 'Unknown error occurred.', 'When an unknown error occurred in the WP2D_API object.', 'wp-to-diaspora' );
503
+					$error_message = _x('Unknown error occurred.', 'When an unknown error occurred in the WP2D_API object.', 'wp-to-diaspora');
504 504
 					break;
505 505
 			}
506 506
 		}
507 507
 
508
-		$this->_error( 'wp2d_api_delete_' . $what . '_failed', $error_message );
508
+		$this->_error('wp2d_api_delete_'.$what.'_failed', $error_message);
509 509
 		return false;
510 510
 	}
511 511
 
@@ -515,9 +515,9 @@  discard block
 block discarded – undo
515 515
 	 * @param boolean $force Force to fetch new aspects.
516 516
 	 * @return array Array of aspect objects.
517 517
 	 */
518
-	public function get_aspects( $force = false ) {
519
-		$this->_aspects = $this->_get_aspects_services( 'aspects', $this->_aspects, $force );
520
-		return ( is_array( $this->_aspects ) ) ? $this->_aspects : false;
518
+	public function get_aspects($force = false) {
519
+		$this->_aspects = $this->_get_aspects_services('aspects', $this->_aspects, $force);
520
+		return (is_array($this->_aspects)) ? $this->_aspects : false;
521 521
 	}
522 522
 
523 523
 	/**
@@ -526,9 +526,9 @@  discard block
 block discarded – undo
526 526
 	 * @param boolean $force Force to fetch new connected services.
527 527
 	 * @return array Array of service objects.
528 528
 	 */
529
-	public function get_services( $force = false ) {
530
-		$this->_services = $this->_get_aspects_services( 'services', $this->_services, $force );
531
-		return ( is_array( $this->_services ) ) ? $this->_services : false;
529
+	public function get_services($force = false) {
530
+		$this->_services = $this->_get_aspects_services('services', $this->_services, $force);
531
+		return (is_array($this->_services)) ? $this->_services : false;
532 532
 	}
533 533
 
534 534
 	/**
@@ -539,48 +539,48 @@  discard block
 block discarded – undo
539 539
 	 * @param boolean $force Force to fetch new list.
540 540
 	 * @return boolean Was the list fetched successfully?
541 541
 	 */
542
-	private function _get_aspects_services( $type, $list, $force ) {
543
-		if ( ! $this->_check_login() ) {
542
+	private function _get_aspects_services($type, $list, $force) {
543
+		if ( ! $this->_check_login()) {
544 544
 			return false;
545 545
 		}
546 546
 
547 547
 		// Fetch the new list if the current list is empty or a reload is forced.
548
-		if ( empty( $list ) || (bool) $force ) {
549
-			$response = $this->_request( '/bookmarklet' );
548
+		if (empty($list) || (bool) $force) {
549
+			$response = $this->_request('/bookmarklet');
550 550
 
551
-			if ( is_wp_error( $response ) || 200 !== $response->code ) {
552
-				switch ( $type ) {
551
+			if (is_wp_error($response) || 200 !== $response->code) {
552
+				switch ($type) {
553 553
 					case 'aspects':
554
-						$this->_error( 'wp2d_api_getting_aspects_failed', __( 'Error loading aspects.', 'wp-to-diaspora' ) );
554
+						$this->_error('wp2d_api_getting_aspects_failed', __('Error loading aspects.', 'wp-to-diaspora'));
555 555
 						break;
556 556
 					case 'services':
557
-						$this->_error( 'wp2d_api_getting_services_failed', __( 'Error loading services.', 'wp-to-diaspora' ) );
557
+						$this->_error('wp2d_api_getting_services_failed', __('Error loading services.', 'wp-to-diaspora'));
558 558
 						break;
559 559
 					default:
560
-						$this->_error( 'wp2d_api_getting_aspects_services_failed', _x( 'Unknown error occurred.', 'When an unknown error occurred in the WP2D_API object.', 'wp-to-diaspora' ) );
560
+						$this->_error('wp2d_api_getting_aspects_services_failed', _x('Unknown error occurred.', 'When an unknown error occurred in the WP2D_API object.', 'wp-to-diaspora'));
561 561
 						break;
562 562
 				}
563 563
 				return false;
564 564
 			}
565 565
 
566 566
 			// Load the aspects or services.
567
-			if ( is_array( $raw_list = json_decode( $this->_parse_regex( $type, $response->body ) ) ) ) {
567
+			if (is_array($raw_list = json_decode($this->_parse_regex($type, $response->body)))) {
568 568
 				// In case this fetch is forced, empty the list.
569 569
 				$list = array();
570 570
 
571
-				switch ( $type ) {
571
+				switch ($type) {
572 572
 					case 'aspects':
573 573
 						// Add the 'public' aspect, as it's global and not user specific.
574
-						$list['public'] = __( 'Public', 'wp-to-diaspora' );
574
+						$list['public'] = __('Public', 'wp-to-diaspora');
575 575
 
576 576
 						// Add all user specific aspects.
577
-						foreach ( $raw_list as $aspect ) {
578
-							$list[ $aspect->id ] = $aspect->name;
577
+						foreach ($raw_list as $aspect) {
578
+							$list[$aspect->id] = $aspect->name;
579 579
 						}
580 580
 						break;
581 581
 					case 'services':
582
-						foreach ( $raw_list as $service ) {
583
-							$list[ $service ] = ucfirst( $service );
582
+						foreach ($raw_list as $service) {
583
+							$list[$service] = ucfirst($service);
584 584
 						}
585 585
 						break;
586 586
 				}
@@ -598,10 +598,10 @@  discard block
 block discarded – undo
598 598
 	 * @param array  $args Arguments to be posted with the request.
599 599
 	 * @return object An object containing details about this request.
600 600
 	 */
601
-	private function _request( $url, $args = array() ) {
601
+	private function _request($url, $args = array()) {
602 602
 		// Prefix the full pod URL if necessary.
603
-		if ( 0 === strpos( $url, '/' ) ) {
604
-			$url = $this->get_pod_url( $url );
603
+		if (0 === strpos($url, '/')) {
604
+			$url = $this->get_pod_url($url);
605 605
 		}
606 606
 
607 607
 		// Disable redirections so we can verify HTTP response codes.
@@ -614,44 +614,44 @@  discard block
 block discarded – undo
614 614
 
615 615
 		// If the certificate bundle has been downloaded manually, use that instead.
616 616
 		// NOTE: This should actually never be necessary, it's a fallback!
617
-		if ( file_exists( WP2D_DIR . '/cacert.pem' ) ) {
618
-			$defaults['sslcertificates'] = WP2D_DIR . '/cacert.pem';
617
+		if (file_exists(WP2D_DIR.'/cacert.pem')) {
618
+			$defaults['sslcertificates'] = WP2D_DIR.'/cacert.pem';
619 619
 		}
620 620
 
621 621
 		// Set the correct cookie.
622
-		if ( ! empty( $this->_cookies ) ) {
622
+		if ( ! empty($this->_cookies)) {
623 623
 			$defaults['cookies'] = $this->_cookies;
624 624
 		}
625 625
 
626
-		$args = wp_parse_args( $args, $defaults );
626
+		$args = wp_parse_args($args, $defaults);
627 627
 
628 628
 		// Get the response from the WP_HTTP request.
629
-		$response = wp_remote_request( $url, $args );
629
+		$response = wp_remote_request($url, $args);
630 630
 
631
-		if ( is_wp_error( $response ) ) {
631
+		if (is_wp_error($response)) {
632 632
 			$this->_last_error = $response;
633 633
 			return $response;
634 634
 		}
635 635
 
636 636
 		// Get the headers and the html response.
637
-		$headers = wp_remote_retrieve_headers( $response );
638
-		$body    = wp_remote_retrieve_body( $response );
637
+		$headers = wp_remote_retrieve_headers($response);
638
+		$body    = wp_remote_retrieve_body($response);
639 639
 
640 640
 		// Remember this request.
641 641
 		$this->_last_request = new stdClass();
642 642
 		$this->_last_request->response = $response;
643 643
 		$this->_last_request->headers  = $headers;
644 644
 		$this->_last_request->body     = $body;
645
-		$this->_last_request->message  = wp_remote_retrieve_response_message( $response );
646
-		$this->_last_request->code     = wp_remote_retrieve_response_code( $response );
645
+		$this->_last_request->message  = wp_remote_retrieve_response_message($response);
646
+		$this->_last_request->code     = wp_remote_retrieve_response_code($response);
647 647
 
648 648
 		// Save the new token.
649
-		if ( $token = $this->_parse_regex( 'token', $body ) ) {
649
+		if ($token = $this->_parse_regex('token', $body)) {
650 650
 			$this->_token = $token;
651 651
 		}
652 652
 
653 653
 		// Save the latest cookies.
654
-		if ( isset( $response['cookies'] ) ) {
654
+		if (isset($response['cookies'])) {
655 655
 			$this->_cookies = $response['cookies'];
656 656
 		}
657 657
 
@@ -669,13 +669,13 @@  discard block
 block discarded – undo
669 669
 	 * @param  string     $message Error message.
670 670
 	 * @param  mixed      $data    Error data.
671 671
 	 */
672
-	private function _error( $code, $message, $data = '' ) {
672
+	private function _error($code, $message, $data = '') {
673 673
 		// Always add the code and message of the last request.
674
-		$data = array_merge( array_filter( (array) $data ), array(
675
-			'code'    => ( isset( $this->_last_request->code ) ) ? $this->_last_request->code : null,
676
-			'message' => ( isset( $this->_last_request->message ) ) ? $this->_last_request->message : null,
677
-		) );
678
-		$this->_last_error = new WP_Error( $code, $message, $data );
674
+		$data = array_merge(array_filter((array) $data), array(
675
+			'code'    => (isset($this->_last_request->code)) ? $this->_last_request->code : null,
676
+			'message' => (isset($this->_last_request->message)) ? $this->_last_request->message : null,
677
+		));
678
+		$this->_last_error = new WP_Error($code, $message, $data);
679 679
 	}
680 680
 
681 681
 	/**
@@ -685,13 +685,13 @@  discard block
 block discarded – undo
685 685
 	 * @param string $content Text to parse the regex with.
686 686
 	 * @return string The found string, or an empty string.
687 687
 	 */
688
-	private function _parse_regex( $regex, $content ) {
688
+	private function _parse_regex($regex, $content) {
689 689
 		// Use a shorthand regex if available.
690
-		if ( array_key_exists( $regex, $this->_regexes ) ) {
691
-			$regex = $this->_regexes[ $regex ];
690
+		if (array_key_exists($regex, $this->_regexes)) {
691
+			$regex = $this->_regexes[$regex];
692 692
 		}
693 693
 
694
-		preg_match( $regex, $content, $matches );
695
-		return trim( array_pop( $matches ) );
694
+		preg_match($regex, $content, $matches);
695
+		return trim(array_pop($matches));
696 696
 	}
697 697
 }
Please login to merge, or discard this patch.
Indentation   +668 added lines, -668 removed lines patch added patch discarded remove patch
@@ -26,672 +26,672 @@
 block discarded – undo
26 26
  */
27 27
 class WP2D_API {
28 28
 
29
-	/**
30
-	 * The provider name to display when posting to diaspora*.
31
-	 *
32
-	 * @var string
33
-	 */
34
-	public $provider = 'WP to diaspora*';
35
-
36
-	/**
37
-	 * The last http request error that occurred.
38
-	 *
39
-	 * @var WP_Error
40
-	 */
41
-	private $_last_error;
42
-
43
-	/**
44
-	 * Security token to be used for making requests.
45
-	 *
46
-	 * @var string
47
-	 */
48
-	private $_token;
49
-
50
-	/**
51
-	 * Save the cookies for the requests.
52
-	 *
53
-	 * @var array
54
-	 */
55
-	private $_cookies;
56
-
57
-	/**
58
-	 * The last http request made to diaspora*.
59
-	 * Contains the response and request infos.
60
-	 *
61
-	 * @var object
62
-	 */
63
-	private $_last_request;
64
-
65
-	/**
66
-	 * Is this a secure server, use HTTPS instead of HTTP?
67
-	 *
68
-	 * @var boolean
69
-	 */
70
-	private $_is_secure;
71
-
72
-	/**
73
-	 * The pod domain to make the http requests to.
74
-	 *
75
-	 * @var string
76
-	 */
77
-	private $_pod;
78
-
79
-	/**
80
-	 * Username to use when logging in to diaspora*.
81
-	 *
82
-	 * @var string
83
-	 */
84
-	private $_username;
85
-
86
-	/**
87
-	 * Password to use when logging in to diaspora*.
88
-	 *
89
-	 * @var string
90
-	 */
91
-	private $_password;
92
-
93
-	/**
94
-	 * Remember the current login state.
95
-	 *
96
-	 * @var boolean
97
-	 */
98
-	private $_is_logged_in = false;
99
-
100
-	/**
101
-	 * The list of user's aspects, which get set after ever http request.
102
-	 *
103
-	 * @var array
104
-	 */
105
-	private $_aspects = array();
106
-
107
-	/**
108
-	 * The list of user's connected services, which get set after ever http request.
109
-	 *
110
-	 * @var array
111
-	 */
112
-	private $_services = array();
113
-
114
-	/**
115
-	 * List of regex expressions used to filter out details from http request responses.
116
-	 *
117
-	 * @var array
118
-	 */
119
-	private $_regexes = array(
120
-		'token'    => '/content="(.*?)" name="csrf-token"|name="csrf-token" content="(.*?)"/',
121
-		'aspects'  => '/"aspects"\:(\[.*?\])/',
122
-		'services' => '/"configured_services"\:(\[.*?\])/',
123
-	);
124
-
125
-	/**
126
-	 * The full pod url, with the used protocol.
127
-	 *
128
-	 * @param string $path Path to add to the pod url.
129
-	 * @return string Full pod url.
130
-	 */
131
-	public function get_pod_url( $path = '' ) {
132
-		$path = trim( $path, ' /' );
133
-
134
-		// Add a slash to the beginning?
135
-		if ( '' !== $path ) {
136
-			$path = '/' . $path;
137
-		}
138
-
139
-		return sprintf( 'http%s://%s%s', ( $this->_is_secure ) ? 's' : '', $this->_pod, $path );
140
-	}
141
-
142
-	/**
143
-	 * Constructor to initialise the connection to diaspora*.
144
-	 *
145
-	 * @param string  $pod       The pod domain to connect to.
146
-	 * @param boolean $is_secure Is this a secure server? (Default: true).
147
-	 */
148
-	public function __construct( $pod, $is_secure = true ) {
149
-		// Set class variables.
150
-		$this->_pod       = $pod;
151
-		$this->_is_secure = (bool) $is_secure;
152
-	}
153
-
154
-	/**
155
-	 * Initialise the connection to diaspora*. The pod and protocol can be changed by passing new parameters.
156
-	 * Check if we can connect to the pod to retrieve the token.
157
-	 *
158
-	 * @param string  $pod       Pod domain to connect to, if it should be changed.
159
-	 * @param boolean $is_secure Is this a secure server? (Default: true).
160
-	 * @return boolean True if we could get the token, else false.
161
-	 */
162
-	public function init( $pod = null, $is_secure = true ) {
163
-		// If we are changing pod, we need to fetch a new token.
164
-		$force_new_token = false;
165
-
166
-		// When initialising a connection, clear the last error.
167
-		// This is important when multiple init tries happen.
168
-		$this->_last_error = null;
169
-
170
-		// Change the pod we are connecting to?
171
-		if ( isset( $pod ) && ( $this->_pod !== $pod || $this->_is_secure !== $is_secure ) ) {
172
-			$this->_pod       = $pod;
173
-			$this->_is_secure = (bool) $is_secure;
174
-			$force_new_token  = true;
175
-		}
176
-
177
-		// Get and save the token.
178
-		if ( null === $this->_fetch_token( $force_new_token ) ) {
179
-			$error = ( $this->has_last_error() ) ? ' ' . $this->get_last_error() : '';
180
-			$this->_error( 'wp2d_api_init_failed',
181
-				sprintf(
182
-					_x( 'Failed to initialise connection to pod "%s".', 'Placeholder is the full pod URL.', 'wp-to-diaspora' ),
183
-					$this->get_pod_url()
184
-				) . $error,
185
-				array( 'help_tab' => 'troubleshooting' )
186
-			);
187
-
188
-			return false;
189
-		}
190
-		return true;
191
-	}
192
-
193
-	/**
194
-	 * Check if there is an API error around.
195
-	 *
196
-	 * @return boolean If there is an API error around.
197
-	 */
198
-	public function has_last_error() {
199
-		return is_wp_error( $this->_last_error );
200
-	}
201
-
202
-	/**
203
-	 * Get the last API error object.
204
-	 *
205
-	 * @param boolean $clear If the error should be cleared after returning it.
206
-	 * @return WP_Error|null The last API error object or null.
207
-	 */
208
-	public function get_last_error_object( $clear = true ) {
209
-		$last_error = $this->_last_error;
210
-		$clear && $this->_last_error = null;
211
-		return $last_error;
212
-	}
213
-
214
-	/**
215
-	 * Get the last API error message.
216
-	 *
217
-	 * @param boolean $clear If the error should be cleared after returning it.
218
-	 * @return string The last API error message.
219
-	 */
220
-	public function get_last_error( $clear = false ) {
221
-		$last_error = ( $this->has_last_error() ) ? $this->_last_error->get_error_message() : '';
222
-		$clear && $this->_last_error = null;
223
-		return $last_error;
224
-	}
225
-
226
-	/**
227
-	 * Fetch the secure token from Diaspora and save it for future use.
228
-	 *
229
-	 * @param boolean $force Force to fetch a new token.
230
-	 * @return string The fetched token.
231
-	 */
232
-	private function _fetch_token( $force = false ) {
233
-		if ( ! isset( $this->_token ) || (bool) $force ) {
234
-			// Go directly to the sign in page, as it would redirect to there anyway.
235
-			// Since _request function automatically saves the new token, just call it with no data.
236
-			$this->_request( '/users/sign_in' );
237
-		}
238
-		return $this->_token;
239
-	}
240
-
241
-	/**
242
-	 * Check if the API has been initialised. Otherwise set the last error.
243
-	 *
244
-	 * @return boolean Has the connection been initialised?
245
-	 */
246
-	private function _check_init() {
247
-		if ( is_null( $this->_token ) ) {
248
-			$this->_error( 'wp2d_api_connection_not_initialised', __( 'Connection not initialised.', 'wp-to-diaspora' ) );
249
-			return false;
250
-		}
251
-		return true;
252
-	}
253
-
254
-	/**
255
-	 * Check if we're logged in. Otherwise set the last error.
256
-	 *
257
-	 * @return boolean Are we logged in already?
258
-	 */
259
-	private function _check_login() {
260
-		if ( ! $this->_check_init() ) {
261
-			return false;
262
-		}
263
-		if ( ! $this->is_logged_in() ) {
264
-			$this->_error( 'wp2d_api_not_logged_in', __( 'Not logged in.', 'wp-to-diaspora' ) );
265
-			return false;
266
-		}
267
-		return true;
268
-	}
269
-
270
-	/**
271
-	 * Check if we are logged in.
272
-	 *
273
-	 * @return boolean Are we logged in already?
274
-	 */
275
-	public function is_logged_in() {
276
-		return $this->_is_logged_in;
277
-	}
278
-
279
-	/**
280
-	 * Log in to diaspora*.
281
-	 *
282
-	 * @param string  $username Username used for login.
283
-	 * @param string  $password Password used for login.
284
-	 * @param boolean $force    Force a new login even if we are already logged in.
285
-	 * @return boolean Did the login succeed?
286
-	 */
287
-	public function login( $username, $password, $force = false ) {
288
-		// Has the connection been initialised?
289
-		if ( ! $this->_check_init() ) {
290
-			$this->logout();
291
-			return false;
292
-		}
293
-
294
-		// Username and password both need to be set.
295
-		$username = ( isset( $username ) && '' !== $username ) ? $username : null;
296
-		$password = ( isset( $password ) && '' !== $password ) ? $password : null;
297
-		if ( ! isset( $username, $password ) ) {
298
-			$this->logout();
299
-			return false;
300
-		}
301
-
302
-		// If we are already logged in and not forcing a relogin, return.
303
-		if ( ! $force && $this->is_logged_in() &&
304
-			$username === $this->_username &&
305
-			$password === $this->_password ) {
306
-			return true;
307
-		}
308
-
309
-		// Set the newly passed username and password.
310
-		$this->_username = $username;
311
-		$this->_password = $password;
312
-
313
-		// Set up the login parameters.
314
-		$params = array(
315
-			'user[username]'     => $this->_username,
316
-			'user[password]'     => $this->_password,
317
-			'authenticity_token' => $this->_fetch_token(),
318
-		);
319
-
320
-		$args = array(
321
-			'method' => 'POST',
322
-			'body'   => $params,
323
-		);
324
-
325
-		// Try to sign in.
326
-		$this->_request( '/users/sign_in', $args );
327
-
328
-		// Can we load the bookmarklet to make sure we're logged in?
329
-		$response = $this->_request( '/bookmarklet' );
330
-
331
-		// If the request isn't successful, we are not logged in correctly.
332
-		if ( is_wp_error( $response ) || 200 !== $response->code ) {
333
-			// Login failed.
334
-			$this->_error( 'wp2d_api_login_failed', __( 'Login failed. Check your login details.', 'wp-to-diaspora' ), array( 'help_tab' => 'troubleshooting' ) );
335
-			$this->logout();
336
-			return false;
337
-		}
338
-
339
-		// Login succeeded.
340
-		$this->_is_logged_in = true;
341
-		return true;
342
-	}
343
-
344
-	/**
345
-	 * Perform a logout, resetting all login info.
346
-	 *
347
-	 * @since 1.6.0
348
-	 */
349
-	public function logout() {
350
-		$this->_is_logged_in = false;
351
-		$this->_username = null;
352
-		$this->_password = null;
353
-		$this->_aspects = array();
354
-		$this->_services = array();
355
-	}
356
-
357
-	/**
358
-	 * Perform a deinitialisation, resetting all class variables.
359
-	 *
360
-	 * @since 1.7.0
361
-	 */
362
-	public function deinit() {
363
-		$this->logout();
364
-		$this->_last_error = null;
365
-		$this->_token = null;
366
-		$this->_cookies = array();
367
-		$this->_last_request = null;
368
-	}
369
-
370
-	/**
371
-	 * Post to diaspora*.
372
-	 *
373
-	 * @param string       $text       The text to post.
374
-	 * @param array|string $aspects    The aspects to post to. Array or comma seperated ids.
375
-	 * @param array        $extra_data Any extra data to be added to the post call.
376
-	 * @return boolean|object Return the response data of the new diaspora* post if successfully posted, else false.
377
-	 */
378
-	public function post( $text, $aspects = 'public', $extra_data = array() ) {
379
-		// Are we logged in?
380
-		if ( ! $this->_check_login() ) {
381
-			return false;
382
-		}
383
-
384
-		// Put the aspects into a clean array.
385
-		$aspects = array_filter( WP2D_Helpers::str_to_arr( $aspects ) );
386
-
387
-		// If no aspects have been selected or the public one is also included, choose public only.
388
-		if ( empty( $aspects ) || in_array( 'public', $aspects ) ) {
389
-			$aspects = 'public';
390
-		}
391
-
392
-		// Prepare post data.
393
-		$post_data = array(
394
-			'aspect_ids'     => $aspects,
395
-			'status_message' => array(
396
-				'text' => $text,
397
-				'provider_display_name' => $this->provider,
398
-			),
399
-		);
400
-
401
-		// Add any extra data to the post.
402
-		if ( ! empty( $extra_data ) ) {
403
-				$post_data += $extra_data;
404
-		}
405
-
406
-		// Check if we can use the new wp_json_encode function.
407
-		$post_data = ( function_exists( 'wp_json_encode' ) )
408
-			? wp_json_encode( $post_data )
409
-			: json_encode( $post_data );
410
-
411
-		$args = array(
412
-			'method'  => 'POST',
413
-			'body'    => $post_data,
414
-			'headers' => array(
415
-				'Accept'       => 'application/json',
416
-				'Content-Type' => 'application/json',
417
-				'X-CSRF-Token' => $this->_fetch_token(),
418
-			),
419
-		);
420
-
421
-		// Submit the post.
422
-		$response = $this->_request( '/status_messages', $args );
423
-
424
-		if ( is_wp_error( $response ) ) {
425
-			$this->_error( 'wp2d_api_post_failed', $response->get_error_message() );
426
-			return false;
427
-		}
428
-
429
-		$diaspost = json_decode( $response->body );
430
-		if ( 201 !== $response->code ) {
431
-			$this->_error( 'wp2d_api_post_failed', ( isset( $diaspost->error ) ) ? $diaspost->error : _x( 'Unknown error occurred.', 'When an unknown error occurred in the WP2D_API object.', 'wp-to-diaspora' ) );
432
-			return false;
433
-		}
434
-
435
-		// Add additional info to our diaspora post object.
436
-		$diaspost->permalink = $this->get_pod_url( '/posts/' . $diaspost->guid );
437
-
438
-		return $diaspost;
439
-	}
440
-
441
-	/**
442
-	 * Delete a post or comment from diaspora*.
443
-	 *
444
-	 * @since 1.6.0
445
-	 *
446
-	 * @param string $what What to delete, 'post' or 'comment'.
447
-	 * @param string $id The ID of the post or comment to delete.
448
-	 * @return boolean If the deletion was successful.
449
-	 */
450
-	public function delete( $what, $id ) {
451
-		// Are we logged in?
452
-		if ( ! $this->_check_login() ) {
453
-			return false;
454
-		}
455
-
456
-		// For now, only deleting posts and comments is allowed.
457
-		if ( ! in_array( $what, array( 'post', 'comment' ) ) ) {
458
-			$this->_error( 'wp2d_api_delete_failed', __( 'You can only delete posts and comments.', 'wp-to-diaspora' ) );
459
-			return false;
460
-		}
461
-
462
-		$args = array(
463
-			'method'  => 'DELETE',
464
-			'headers' => array(
465
-				'Accept'       => 'application/json',
466
-				'Content-Type' => 'application/json',
467
-				'X-CSRF-Token' => $this->_fetch_token(),
468
-			),
469
-		);
470
-
471
-		// Try to delete the post or comment.
472
-		$response = $this->_request( '/' . $what . 's/' . $id, $args );
473
-
474
-		$error_message = '';
475
-
476
-		if ( is_wp_error( $response ) ) {
477
-			$error_message = $response->get_error_message();
478
-		} else {
479
-			switch ( $response->code ) {
480
-				case 204:
481
-					return true;
482
-				case 404:
483
-					$error_message = ( 'post' === $what )
484
-						? __( 'The post you tried to delete does not exist.', 'wp-to-diaspora' )
485
-						: __( 'The comment you tried to delete does not exist.', 'wp-to-diaspora' );
486
-					break;
487
-
488
-				// Due to diaspora* returning a proper 403 when trying to delete a foreign comment
489
-				// but returning a 500 when trying to delete a foreign post, this needs some special attention.
490
-				case 403:
491
-					if ( 'comment' === $what ) {
492
-						$error_message = __( 'The comment you tried to delete does not belong to you.', 'wp-to-diaspora' );
493
-						break;
494
-					}
495
-					// Fall through...
496
-				case 500:
497
-					if ( 'post' === $what ) {
498
-						$error_message = __( 'The post you tried to delete does not belong to you.', 'wp-to-diaspora' );
499
-						break;
500
-					}
501
-					// Fall through...
502
-				default:
503
-					$error_message = _x( 'Unknown error occurred.', 'When an unknown error occurred in the WP2D_API object.', 'wp-to-diaspora' );
504
-					break;
505
-			}
506
-		}
507
-
508
-		$this->_error( 'wp2d_api_delete_' . $what . '_failed', $error_message );
509
-		return false;
510
-	}
511
-
512
-	/**
513
-	 * Get the list of aspects.
514
-	 *
515
-	 * @param boolean $force Force to fetch new aspects.
516
-	 * @return array Array of aspect objects.
517
-	 */
518
-	public function get_aspects( $force = false ) {
519
-		$this->_aspects = $this->_get_aspects_services( 'aspects', $this->_aspects, $force );
520
-		return ( is_array( $this->_aspects ) ) ? $this->_aspects : false;
521
-	}
522
-
523
-	/**
524
-	 * Get the list of connected services.
525
-	 *
526
-	 * @param boolean $force Force to fetch new connected services.
527
-	 * @return array Array of service objects.
528
-	 */
529
-	public function get_services( $force = false ) {
530
-		$this->_services = $this->_get_aspects_services( 'services', $this->_services, $force );
531
-		return ( is_array( $this->_services ) ) ? $this->_services : false;
532
-	}
533
-
534
-	/**
535
-	 * Get the list of aspects or connected services.
536
-	 *
537
-	 * @param string  $type  Type of list to get.
538
-	 * @param array   $list  The current list of items.
539
-	 * @param boolean $force Force to fetch new list.
540
-	 * @return boolean Was the list fetched successfully?
541
-	 */
542
-	private function _get_aspects_services( $type, $list, $force ) {
543
-		if ( ! $this->_check_login() ) {
544
-			return false;
545
-		}
546
-
547
-		// Fetch the new list if the current list is empty or a reload is forced.
548
-		if ( empty( $list ) || (bool) $force ) {
549
-			$response = $this->_request( '/bookmarklet' );
550
-
551
-			if ( is_wp_error( $response ) || 200 !== $response->code ) {
552
-				switch ( $type ) {
553
-					case 'aspects':
554
-						$this->_error( 'wp2d_api_getting_aspects_failed', __( 'Error loading aspects.', 'wp-to-diaspora' ) );
555
-						break;
556
-					case 'services':
557
-						$this->_error( 'wp2d_api_getting_services_failed', __( 'Error loading services.', 'wp-to-diaspora' ) );
558
-						break;
559
-					default:
560
-						$this->_error( 'wp2d_api_getting_aspects_services_failed', _x( 'Unknown error occurred.', 'When an unknown error occurred in the WP2D_API object.', 'wp-to-diaspora' ) );
561
-						break;
562
-				}
563
-				return false;
564
-			}
565
-
566
-			// Load the aspects or services.
567
-			if ( is_array( $raw_list = json_decode( $this->_parse_regex( $type, $response->body ) ) ) ) {
568
-				// In case this fetch is forced, empty the list.
569
-				$list = array();
570
-
571
-				switch ( $type ) {
572
-					case 'aspects':
573
-						// Add the 'public' aspect, as it's global and not user specific.
574
-						$list['public'] = __( 'Public', 'wp-to-diaspora' );
575
-
576
-						// Add all user specific aspects.
577
-						foreach ( $raw_list as $aspect ) {
578
-							$list[ $aspect->id ] = $aspect->name;
579
-						}
580
-						break;
581
-					case 'services':
582
-						foreach ( $raw_list as $service ) {
583
-							$list[ $service ] = ucfirst( $service );
584
-						}
585
-						break;
586
-				}
587
-			}
588
-		}
589
-		return $list;
590
-	}
591
-
592
-	/**
593
-	 * Send an http(s) request via WP_HTTP API.
594
-	 *
595
-	 * @see WP_Http::request()
596
-	 *
597
-	 * @param string $url  The URL to request.
598
-	 * @param array  $args Arguments to be posted with the request.
599
-	 * @return object An object containing details about this request.
600
-	 */
601
-	private function _request( $url, $args = array() ) {
602
-		// Prefix the full pod URL if necessary.
603
-		if ( 0 === strpos( $url, '/' ) ) {
604
-			$url = $this->get_pod_url( $url );
605
-		}
606
-
607
-		// Disable redirections so we can verify HTTP response codes.
608
-		$defaults = array(
609
-			'redirection' => 0,
610
-			'sslverify'   => true,
611
-			'timeout'     => 60,
612
-			'method'      => 'GET',
613
-		);
614
-
615
-		// If the certificate bundle has been downloaded manually, use that instead.
616
-		// NOTE: This should actually never be necessary, it's a fallback!
617
-		if ( file_exists( WP2D_DIR . '/cacert.pem' ) ) {
618
-			$defaults['sslcertificates'] = WP2D_DIR . '/cacert.pem';
619
-		}
620
-
621
-		// Set the correct cookie.
622
-		if ( ! empty( $this->_cookies ) ) {
623
-			$defaults['cookies'] = $this->_cookies;
624
-		}
625
-
626
-		$args = wp_parse_args( $args, $defaults );
627
-
628
-		// Get the response from the WP_HTTP request.
629
-		$response = wp_remote_request( $url, $args );
630
-
631
-		if ( is_wp_error( $response ) ) {
632
-			$this->_last_error = $response;
633
-			return $response;
634
-		}
635
-
636
-		// Get the headers and the html response.
637
-		$headers = wp_remote_retrieve_headers( $response );
638
-		$body    = wp_remote_retrieve_body( $response );
639
-
640
-		// Remember this request.
641
-		$this->_last_request = new stdClass();
642
-		$this->_last_request->response = $response;
643
-		$this->_last_request->headers  = $headers;
644
-		$this->_last_request->body     = $body;
645
-		$this->_last_request->message  = wp_remote_retrieve_response_message( $response );
646
-		$this->_last_request->code     = wp_remote_retrieve_response_code( $response );
647
-
648
-		// Save the new token.
649
-		if ( $token = $this->_parse_regex( 'token', $body ) ) {
650
-			$this->_token = $token;
651
-		}
652
-
653
-		// Save the latest cookies.
654
-		if ( isset( $response['cookies'] ) ) {
655
-			$this->_cookies = $response['cookies'];
656
-		}
657
-
658
-		// Return the last request details.
659
-		return $this->_last_request;
660
-	}
661
-
662
-	/**
663
-	 * Helper method to set the last occurred error.
664
-	 *
665
-	 * @see WP_Error::__construct()
666
-	 * @since 1.6.0
667
-	 *
668
-	 * @param  string|int $code    Error code.
669
-	 * @param  string     $message Error message.
670
-	 * @param  mixed      $data    Error data.
671
-	 */
672
-	private function _error( $code, $message, $data = '' ) {
673
-		// Always add the code and message of the last request.
674
-		$data = array_merge( array_filter( (array) $data ), array(
675
-			'code'    => ( isset( $this->_last_request->code ) ) ? $this->_last_request->code : null,
676
-			'message' => ( isset( $this->_last_request->message ) ) ? $this->_last_request->message : null,
677
-		) );
678
-		$this->_last_error = new WP_Error( $code, $message, $data );
679
-	}
680
-
681
-	/**
682
-	 * Parse the regex and return the found string.
683
-	 *
684
-	 * @param string $regex   Shorthand of a saved regex or a custom regex.
685
-	 * @param string $content Text to parse the regex with.
686
-	 * @return string The found string, or an empty string.
687
-	 */
688
-	private function _parse_regex( $regex, $content ) {
689
-		// Use a shorthand regex if available.
690
-		if ( array_key_exists( $regex, $this->_regexes ) ) {
691
-			$regex = $this->_regexes[ $regex ];
692
-		}
693
-
694
-		preg_match( $regex, $content, $matches );
695
-		return trim( array_pop( $matches ) );
696
-	}
29
+  /**
30
+   * The provider name to display when posting to diaspora*.
31
+   *
32
+   * @var string
33
+   */
34
+  public $provider = 'WP to diaspora*';
35
+
36
+  /**
37
+   * The last http request error that occurred.
38
+   *
39
+   * @var WP_Error
40
+   */
41
+  private $_last_error;
42
+
43
+  /**
44
+   * Security token to be used for making requests.
45
+   *
46
+   * @var string
47
+   */
48
+  private $_token;
49
+
50
+  /**
51
+   * Save the cookies for the requests.
52
+   *
53
+   * @var array
54
+   */
55
+  private $_cookies;
56
+
57
+  /**
58
+   * The last http request made to diaspora*.
59
+   * Contains the response and request infos.
60
+   *
61
+   * @var object
62
+   */
63
+  private $_last_request;
64
+
65
+  /**
66
+   * Is this a secure server, use HTTPS instead of HTTP?
67
+   *
68
+   * @var boolean
69
+   */
70
+  private $_is_secure;
71
+
72
+  /**
73
+   * The pod domain to make the http requests to.
74
+   *
75
+   * @var string
76
+   */
77
+  private $_pod;
78
+
79
+  /**
80
+   * Username to use when logging in to diaspora*.
81
+   *
82
+   * @var string
83
+   */
84
+  private $_username;
85
+
86
+  /**
87
+   * Password to use when logging in to diaspora*.
88
+   *
89
+   * @var string
90
+   */
91
+  private $_password;
92
+
93
+  /**
94
+   * Remember the current login state.
95
+   *
96
+   * @var boolean
97
+   */
98
+  private $_is_logged_in = false;
99
+
100
+  /**
101
+   * The list of user's aspects, which get set after ever http request.
102
+   *
103
+   * @var array
104
+   */
105
+  private $_aspects = array();
106
+
107
+  /**
108
+   * The list of user's connected services, which get set after ever http request.
109
+   *
110
+   * @var array
111
+   */
112
+  private $_services = array();
113
+
114
+  /**
115
+   * List of regex expressions used to filter out details from http request responses.
116
+   *
117
+   * @var array
118
+   */
119
+  private $_regexes = array(
120
+    'token'    => '/content="(.*?)" name="csrf-token"|name="csrf-token" content="(.*?)"/',
121
+    'aspects'  => '/"aspects"\:(\[.*?\])/',
122
+    'services' => '/"configured_services"\:(\[.*?\])/',
123
+  );
124
+
125
+  /**
126
+   * The full pod url, with the used protocol.
127
+   *
128
+   * @param string $path Path to add to the pod url.
129
+   * @return string Full pod url.
130
+   */
131
+  public function get_pod_url( $path = '' ) {
132
+    $path = trim( $path, ' /' );
133
+
134
+    // Add a slash to the beginning?
135
+    if ( '' !== $path ) {
136
+      $path = '/' . $path;
137
+    }
138
+
139
+    return sprintf( 'http%s://%s%s', ( $this->_is_secure ) ? 's' : '', $this->_pod, $path );
140
+  }
141
+
142
+  /**
143
+   * Constructor to initialise the connection to diaspora*.
144
+   *
145
+   * @param string  $pod       The pod domain to connect to.
146
+   * @param boolean $is_secure Is this a secure server? (Default: true).
147
+   */
148
+  public function __construct( $pod, $is_secure = true ) {
149
+    // Set class variables.
150
+    $this->_pod       = $pod;
151
+    $this->_is_secure = (bool) $is_secure;
152
+  }
153
+
154
+  /**
155
+   * Initialise the connection to diaspora*. The pod and protocol can be changed by passing new parameters.
156
+   * Check if we can connect to the pod to retrieve the token.
157
+   *
158
+   * @param string  $pod       Pod domain to connect to, if it should be changed.
159
+   * @param boolean $is_secure Is this a secure server? (Default: true).
160
+   * @return boolean True if we could get the token, else false.
161
+   */
162
+  public function init( $pod = null, $is_secure = true ) {
163
+    // If we are changing pod, we need to fetch a new token.
164
+    $force_new_token = false;
165
+
166
+    // When initialising a connection, clear the last error.
167
+    // This is important when multiple init tries happen.
168
+    $this->_last_error = null;
169
+
170
+    // Change the pod we are connecting to?
171
+    if ( isset( $pod ) && ( $this->_pod !== $pod || $this->_is_secure !== $is_secure ) ) {
172
+      $this->_pod       = $pod;
173
+      $this->_is_secure = (bool) $is_secure;
174
+      $force_new_token  = true;
175
+    }
176
+
177
+    // Get and save the token.
178
+    if ( null === $this->_fetch_token( $force_new_token ) ) {
179
+      $error = ( $this->has_last_error() ) ? ' ' . $this->get_last_error() : '';
180
+      $this->_error( 'wp2d_api_init_failed',
181
+        sprintf(
182
+          _x( 'Failed to initialise connection to pod "%s".', 'Placeholder is the full pod URL.', 'wp-to-diaspora' ),
183
+          $this->get_pod_url()
184
+        ) . $error,
185
+        array( 'help_tab' => 'troubleshooting' )
186
+      );
187
+
188
+      return false;
189
+    }
190
+    return true;
191
+  }
192
+
193
+  /**
194
+   * Check if there is an API error around.
195
+   *
196
+   * @return boolean If there is an API error around.
197
+   */
198
+  public function has_last_error() {
199
+    return is_wp_error( $this->_last_error );
200
+  }
201
+
202
+  /**
203
+   * Get the last API error object.
204
+   *
205
+   * @param boolean $clear If the error should be cleared after returning it.
206
+   * @return WP_Error|null The last API error object or null.
207
+   */
208
+  public function get_last_error_object( $clear = true ) {
209
+    $last_error = $this->_last_error;
210
+    $clear && $this->_last_error = null;
211
+    return $last_error;
212
+  }
213
+
214
+  /**
215
+   * Get the last API error message.
216
+   *
217
+   * @param boolean $clear If the error should be cleared after returning it.
218
+   * @return string The last API error message.
219
+   */
220
+  public function get_last_error( $clear = false ) {
221
+    $last_error = ( $this->has_last_error() ) ? $this->_last_error->get_error_message() : '';
222
+    $clear && $this->_last_error = null;
223
+    return $last_error;
224
+  }
225
+
226
+  /**
227
+   * Fetch the secure token from Diaspora and save it for future use.
228
+   *
229
+   * @param boolean $force Force to fetch a new token.
230
+   * @return string The fetched token.
231
+   */
232
+  private function _fetch_token( $force = false ) {
233
+    if ( ! isset( $this->_token ) || (bool) $force ) {
234
+      // Go directly to the sign in page, as it would redirect to there anyway.
235
+      // Since _request function automatically saves the new token, just call it with no data.
236
+      $this->_request( '/users/sign_in' );
237
+    }
238
+    return $this->_token;
239
+  }
240
+
241
+  /**
242
+   * Check if the API has been initialised. Otherwise set the last error.
243
+   *
244
+   * @return boolean Has the connection been initialised?
245
+   */
246
+  private function _check_init() {
247
+    if ( is_null( $this->_token ) ) {
248
+      $this->_error( 'wp2d_api_connection_not_initialised', __( 'Connection not initialised.', 'wp-to-diaspora' ) );
249
+      return false;
250
+    }
251
+    return true;
252
+  }
253
+
254
+  /**
255
+   * Check if we're logged in. Otherwise set the last error.
256
+   *
257
+   * @return boolean Are we logged in already?
258
+   */
259
+  private function _check_login() {
260
+    if ( ! $this->_check_init() ) {
261
+      return false;
262
+    }
263
+    if ( ! $this->is_logged_in() ) {
264
+      $this->_error( 'wp2d_api_not_logged_in', __( 'Not logged in.', 'wp-to-diaspora' ) );
265
+      return false;
266
+    }
267
+    return true;
268
+  }
269
+
270
+  /**
271
+   * Check if we are logged in.
272
+   *
273
+   * @return boolean Are we logged in already?
274
+   */
275
+  public function is_logged_in() {
276
+    return $this->_is_logged_in;
277
+  }
278
+
279
+  /**
280
+   * Log in to diaspora*.
281
+   *
282
+   * @param string  $username Username used for login.
283
+   * @param string  $password Password used for login.
284
+   * @param boolean $force    Force a new login even if we are already logged in.
285
+   * @return boolean Did the login succeed?
286
+   */
287
+  public function login( $username, $password, $force = false ) {
288
+    // Has the connection been initialised?
289
+    if ( ! $this->_check_init() ) {
290
+      $this->logout();
291
+      return false;
292
+    }
293
+
294
+    // Username and password both need to be set.
295
+    $username = ( isset( $username ) && '' !== $username ) ? $username : null;
296
+    $password = ( isset( $password ) && '' !== $password ) ? $password : null;
297
+    if ( ! isset( $username, $password ) ) {
298
+      $this->logout();
299
+      return false;
300
+    }
301
+
302
+    // If we are already logged in and not forcing a relogin, return.
303
+    if ( ! $force && $this->is_logged_in() &&
304
+      $username === $this->_username &&
305
+      $password === $this->_password ) {
306
+      return true;
307
+    }
308
+
309
+    // Set the newly passed username and password.
310
+    $this->_username = $username;
311
+    $this->_password = $password;
312
+
313
+    // Set up the login parameters.
314
+    $params = array(
315
+      'user[username]'     => $this->_username,
316
+      'user[password]'     => $this->_password,
317
+      'authenticity_token' => $this->_fetch_token(),
318
+    );
319
+
320
+    $args = array(
321
+      'method' => 'POST',
322
+      'body'   => $params,
323
+    );
324
+
325
+    // Try to sign in.
326
+    $this->_request( '/users/sign_in', $args );
327
+
328
+    // Can we load the bookmarklet to make sure we're logged in?
329
+    $response = $this->_request( '/bookmarklet' );
330
+
331
+    // If the request isn't successful, we are not logged in correctly.
332
+    if ( is_wp_error( $response ) || 200 !== $response->code ) {
333
+      // Login failed.
334
+      $this->_error( 'wp2d_api_login_failed', __( 'Login failed. Check your login details.', 'wp-to-diaspora' ), array( 'help_tab' => 'troubleshooting' ) );
335
+      $this->logout();
336
+      return false;
337
+    }
338
+
339
+    // Login succeeded.
340
+    $this->_is_logged_in = true;
341
+    return true;
342
+  }
343
+
344
+  /**
345
+   * Perform a logout, resetting all login info.
346
+   *
347
+   * @since 1.6.0
348
+   */
349
+  public function logout() {
350
+    $this->_is_logged_in = false;
351
+    $this->_username = null;
352
+    $this->_password = null;
353
+    $this->_aspects = array();
354
+    $this->_services = array();
355
+  }
356
+
357
+  /**
358
+   * Perform a deinitialisation, resetting all class variables.
359
+   *
360
+   * @since 1.7.0
361
+   */
362
+  public function deinit() {
363
+    $this->logout();
364
+    $this->_last_error = null;
365
+    $this->_token = null;
366
+    $this->_cookies = array();
367
+    $this->_last_request = null;
368
+  }
369
+
370
+  /**
371
+   * Post to diaspora*.
372
+   *
373
+   * @param string       $text       The text to post.
374
+   * @param array|string $aspects    The aspects to post to. Array or comma seperated ids.
375
+   * @param array        $extra_data Any extra data to be added to the post call.
376
+   * @return boolean|object Return the response data of the new diaspora* post if successfully posted, else false.
377
+   */
378
+  public function post( $text, $aspects = 'public', $extra_data = array() ) {
379
+    // Are we logged in?
380
+    if ( ! $this->_check_login() ) {
381
+      return false;
382
+    }
383
+
384
+    // Put the aspects into a clean array.
385
+    $aspects = array_filter( WP2D_Helpers::str_to_arr( $aspects ) );
386
+
387
+    // If no aspects have been selected or the public one is also included, choose public only.
388
+    if ( empty( $aspects ) || in_array( 'public', $aspects ) ) {
389
+      $aspects = 'public';
390
+    }
391
+
392
+    // Prepare post data.
393
+    $post_data = array(
394
+      'aspect_ids'     => $aspects,
395
+      'status_message' => array(
396
+        'text' => $text,
397
+        'provider_display_name' => $this->provider,
398
+      ),
399
+    );
400
+
401
+    // Add any extra data to the post.
402
+    if ( ! empty( $extra_data ) ) {
403
+        $post_data += $extra_data;
404
+    }
405
+
406
+    // Check if we can use the new wp_json_encode function.
407
+    $post_data = ( function_exists( 'wp_json_encode' ) )
408
+      ? wp_json_encode( $post_data )
409
+      : json_encode( $post_data );
410
+
411
+    $args = array(
412
+      'method'  => 'POST',
413
+      'body'    => $post_data,
414
+      'headers' => array(
415
+        'Accept'       => 'application/json',
416
+        'Content-Type' => 'application/json',
417
+        'X-CSRF-Token' => $this->_fetch_token(),
418
+      ),
419
+    );
420
+
421
+    // Submit the post.
422
+    $response = $this->_request( '/status_messages', $args );
423
+
424
+    if ( is_wp_error( $response ) ) {
425
+      $this->_error( 'wp2d_api_post_failed', $response->get_error_message() );
426
+      return false;
427
+    }
428
+
429
+    $diaspost = json_decode( $response->body );
430
+    if ( 201 !== $response->code ) {
431
+      $this->_error( 'wp2d_api_post_failed', ( isset( $diaspost->error ) ) ? $diaspost->error : _x( 'Unknown error occurred.', 'When an unknown error occurred in the WP2D_API object.', 'wp-to-diaspora' ) );
432
+      return false;
433
+    }
434
+
435
+    // Add additional info to our diaspora post object.
436
+    $diaspost->permalink = $this->get_pod_url( '/posts/' . $diaspost->guid );
437
+
438
+    return $diaspost;
439
+  }
440
+
441
+  /**
442
+   * Delete a post or comment from diaspora*.
443
+   *
444
+   * @since 1.6.0
445
+   *
446
+   * @param string $what What to delete, 'post' or 'comment'.
447
+   * @param string $id The ID of the post or comment to delete.
448
+   * @return boolean If the deletion was successful.
449
+   */
450
+  public function delete( $what, $id ) {
451
+    // Are we logged in?
452
+    if ( ! $this->_check_login() ) {
453
+      return false;
454
+    }
455
+
456
+    // For now, only deleting posts and comments is allowed.
457
+    if ( ! in_array( $what, array( 'post', 'comment' ) ) ) {
458
+      $this->_error( 'wp2d_api_delete_failed', __( 'You can only delete posts and comments.', 'wp-to-diaspora' ) );
459
+      return false;
460
+    }
461
+
462
+    $args = array(
463
+      'method'  => 'DELETE',
464
+      'headers' => array(
465
+        'Accept'       => 'application/json',
466
+        'Content-Type' => 'application/json',
467
+        'X-CSRF-Token' => $this->_fetch_token(),
468
+      ),
469
+    );
470
+
471
+    // Try to delete the post or comment.
472
+    $response = $this->_request( '/' . $what . 's/' . $id, $args );
473
+
474
+    $error_message = '';
475
+
476
+    if ( is_wp_error( $response ) ) {
477
+      $error_message = $response->get_error_message();
478
+    } else {
479
+      switch ( $response->code ) {
480
+        case 204:
481
+          return true;
482
+        case 404:
483
+          $error_message = ( 'post' === $what )
484
+            ? __( 'The post you tried to delete does not exist.', 'wp-to-diaspora' )
485
+            : __( 'The comment you tried to delete does not exist.', 'wp-to-diaspora' );
486
+          break;
487
+
488
+        // Due to diaspora* returning a proper 403 when trying to delete a foreign comment
489
+        // but returning a 500 when trying to delete a foreign post, this needs some special attention.
490
+        case 403:
491
+          if ( 'comment' === $what ) {
492
+            $error_message = __( 'The comment you tried to delete does not belong to you.', 'wp-to-diaspora' );
493
+            break;
494
+          }
495
+          // Fall through...
496
+        case 500:
497
+          if ( 'post' === $what ) {
498
+            $error_message = __( 'The post you tried to delete does not belong to you.', 'wp-to-diaspora' );
499
+            break;
500
+          }
501
+          // Fall through...
502
+        default:
503
+          $error_message = _x( 'Unknown error occurred.', 'When an unknown error occurred in the WP2D_API object.', 'wp-to-diaspora' );
504
+          break;
505
+      }
506
+    }
507
+
508
+    $this->_error( 'wp2d_api_delete_' . $what . '_failed', $error_message );
509
+    return false;
510
+  }
511
+
512
+  /**
513
+   * Get the list of aspects.
514
+   *
515
+   * @param boolean $force Force to fetch new aspects.
516
+   * @return array Array of aspect objects.
517
+   */
518
+  public function get_aspects( $force = false ) {
519
+    $this->_aspects = $this->_get_aspects_services( 'aspects', $this->_aspects, $force );
520
+    return ( is_array( $this->_aspects ) ) ? $this->_aspects : false;
521
+  }
522
+
523
+  /**
524
+   * Get the list of connected services.
525
+   *
526
+   * @param boolean $force Force to fetch new connected services.
527
+   * @return array Array of service objects.
528
+   */
529
+  public function get_services( $force = false ) {
530
+    $this->_services = $this->_get_aspects_services( 'services', $this->_services, $force );
531
+    return ( is_array( $this->_services ) ) ? $this->_services : false;
532
+  }
533
+
534
+  /**
535
+   * Get the list of aspects or connected services.
536
+   *
537
+   * @param string  $type  Type of list to get.
538
+   * @param array   $list  The current list of items.
539
+   * @param boolean $force Force to fetch new list.
540
+   * @return boolean Was the list fetched successfully?
541
+   */
542
+  private function _get_aspects_services( $type, $list, $force ) {
543
+    if ( ! $this->_check_login() ) {
544
+      return false;
545
+    }
546
+
547
+    // Fetch the new list if the current list is empty or a reload is forced.
548
+    if ( empty( $list ) || (bool) $force ) {
549
+      $response = $this->_request( '/bookmarklet' );
550
+
551
+      if ( is_wp_error( $response ) || 200 !== $response->code ) {
552
+        switch ( $type ) {
553
+          case 'aspects':
554
+            $this->_error( 'wp2d_api_getting_aspects_failed', __( 'Error loading aspects.', 'wp-to-diaspora' ) );
555
+            break;
556
+          case 'services':
557
+            $this->_error( 'wp2d_api_getting_services_failed', __( 'Error loading services.', 'wp-to-diaspora' ) );
558
+            break;
559
+          default:
560
+            $this->_error( 'wp2d_api_getting_aspects_services_failed', _x( 'Unknown error occurred.', 'When an unknown error occurred in the WP2D_API object.', 'wp-to-diaspora' ) );
561
+            break;
562
+        }
563
+        return false;
564
+      }
565
+
566
+      // Load the aspects or services.
567
+      if ( is_array( $raw_list = json_decode( $this->_parse_regex( $type, $response->body ) ) ) ) {
568
+        // In case this fetch is forced, empty the list.
569
+        $list = array();
570
+
571
+        switch ( $type ) {
572
+          case 'aspects':
573
+            // Add the 'public' aspect, as it's global and not user specific.
574
+            $list['public'] = __( 'Public', 'wp-to-diaspora' );
575
+
576
+            // Add all user specific aspects.
577
+            foreach ( $raw_list as $aspect ) {
578
+              $list[ $aspect->id ] = $aspect->name;
579
+            }
580
+            break;
581
+          case 'services':
582
+            foreach ( $raw_list as $service ) {
583
+              $list[ $service ] = ucfirst( $service );
584
+            }
585
+            break;
586
+        }
587
+      }
588
+    }
589
+    return $list;
590
+  }
591
+
592
+  /**
593
+   * Send an http(s) request via WP_HTTP API.
594
+   *
595
+   * @see WP_Http::request()
596
+   *
597
+   * @param string $url  The URL to request.
598
+   * @param array  $args Arguments to be posted with the request.
599
+   * @return object An object containing details about this request.
600
+   */
601
+  private function _request( $url, $args = array() ) {
602
+    // Prefix the full pod URL if necessary.
603
+    if ( 0 === strpos( $url, '/' ) ) {
604
+      $url = $this->get_pod_url( $url );
605
+    }
606
+
607
+    // Disable redirections so we can verify HTTP response codes.
608
+    $defaults = array(
609
+      'redirection' => 0,
610
+      'sslverify'   => true,
611
+      'timeout'     => 60,
612
+      'method'      => 'GET',
613
+    );
614
+
615
+    // If the certificate bundle has been downloaded manually, use that instead.
616
+    // NOTE: This should actually never be necessary, it's a fallback!
617
+    if ( file_exists( WP2D_DIR . '/cacert.pem' ) ) {
618
+      $defaults['sslcertificates'] = WP2D_DIR . '/cacert.pem';
619
+    }
620
+
621
+    // Set the correct cookie.
622
+    if ( ! empty( $this->_cookies ) ) {
623
+      $defaults['cookies'] = $this->_cookies;
624
+    }
625
+
626
+    $args = wp_parse_args( $args, $defaults );
627
+
628
+    // Get the response from the WP_HTTP request.
629
+    $response = wp_remote_request( $url, $args );
630
+
631
+    if ( is_wp_error( $response ) ) {
632
+      $this->_last_error = $response;
633
+      return $response;
634
+    }
635
+
636
+    // Get the headers and the html response.
637
+    $headers = wp_remote_retrieve_headers( $response );
638
+    $body    = wp_remote_retrieve_body( $response );
639
+
640
+    // Remember this request.
641
+    $this->_last_request = new stdClass();
642
+    $this->_last_request->response = $response;
643
+    $this->_last_request->headers  = $headers;
644
+    $this->_last_request->body     = $body;
645
+    $this->_last_request->message  = wp_remote_retrieve_response_message( $response );
646
+    $this->_last_request->code     = wp_remote_retrieve_response_code( $response );
647
+
648
+    // Save the new token.
649
+    if ( $token = $this->_parse_regex( 'token', $body ) ) {
650
+      $this->_token = $token;
651
+    }
652
+
653
+    // Save the latest cookies.
654
+    if ( isset( $response['cookies'] ) ) {
655
+      $this->_cookies = $response['cookies'];
656
+    }
657
+
658
+    // Return the last request details.
659
+    return $this->_last_request;
660
+  }
661
+
662
+  /**
663
+   * Helper method to set the last occurred error.
664
+   *
665
+   * @see WP_Error::__construct()
666
+   * @since 1.6.0
667
+   *
668
+   * @param  string|int $code    Error code.
669
+   * @param  string     $message Error message.
670
+   * @param  mixed      $data    Error data.
671
+   */
672
+  private function _error( $code, $message, $data = '' ) {
673
+    // Always add the code and message of the last request.
674
+    $data = array_merge( array_filter( (array) $data ), array(
675
+      'code'    => ( isset( $this->_last_request->code ) ) ? $this->_last_request->code : null,
676
+      'message' => ( isset( $this->_last_request->message ) ) ? $this->_last_request->message : null,
677
+    ) );
678
+    $this->_last_error = new WP_Error( $code, $message, $data );
679
+  }
680
+
681
+  /**
682
+   * Parse the regex and return the found string.
683
+   *
684
+   * @param string $regex   Shorthand of a saved regex or a custom regex.
685
+   * @param string $content Text to parse the regex with.
686
+   * @return string The found string, or an empty string.
687
+   */
688
+  private function _parse_regex( $regex, $content ) {
689
+    // Use a shorthand regex if available.
690
+    if ( array_key_exists( $regex, $this->_regexes ) ) {
691
+      $regex = $this->_regexes[ $regex ];
692
+    }
693
+
694
+    preg_match( $regex, $content, $matches );
695
+    return trim( array_pop( $matches ) );
696
+  }
697 697
 }
Please login to merge, or discard this patch.
lib/class-options.php 4 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -738,7 +738,7 @@  discard block
 block discarded – undo
738 738
 	/**
739 739
 	 * Validate checkboxes, make them either true or false.
740 740
 	 *
741
-	 * @param string|array $checkboxes Checkboxes to validate.
741
+	 * @param string[] $checkboxes Checkboxes to validate.
742 742
 	 * @param array        $options    Options values themselves.
743 743
 	 * @return array The validated options.
744 744
 	 */
@@ -752,7 +752,7 @@  discard block
 block discarded – undo
752 752
 	/**
753 753
 	 * Validate single-select fields and make sure their selected value are valid.
754 754
 	 *
755
-	 * @param string|array $selects Name(s) of the select fields.
755
+	 * @param string $selects Name(s) of the select fields.
756 756
 	 * @param array        $options Options values themselves.
757 757
 	 * @return array The validated options.
758 758
 	 */
@@ -768,7 +768,7 @@  discard block
 block discarded – undo
768 768
 	/**
769 769
 	 * Validate multi-select fields and make sure their selected values are valid.
770 770
 	 *
771
-	 * @param string|array $selects Name(s) of the select fields.
771
+	 * @param string $selects Name(s) of the select fields.
772 772
 	 * @param array        $options Options values themselves.
773 773
 	 * @return array The validated options.
774 774
 	 */
@@ -822,7 +822,7 @@  discard block
 block discarded – undo
822 822
 	 * Validate the passed aspects or services.
823 823
 	 *
824 824
 	 * @param array $aspects_services List of aspects or services that need to be validated.
825
-	 * @param array $default          Default value if not valid.
825
+	 * @param string[] $default          Default value if not valid.
826 826
 	 * @return array The validated list of aspects or services.
827 827
 	 */
828 828
 	public function validate_aspects_services( &$aspects_services, $default = array() ) {
Please login to merge, or discard this patch.
Braces   +13 added lines, -5 removed lines patch added patch discarded remove patch
@@ -436,8 +436,11 @@  discard block
 block discarded – undo
436 436
 		if ( 'settings_page_wp_to_diaspora' === get_current_screen()->id ) : ?>
437 437
 			<label><?php echo $checkbox; ?><?php esc_html_e( 'Yes' ); ?></label>
438 438
 			<p class="description"><?php echo esc_html( $description ); ?></p>
439
-		<?php else : ?>
440
-			<label title="<?php echo esc_attr( $description ); ?>"><?php echo $checkbox; ?><?php esc_html_e( 'Show "Posted at" link?', 'wp-to-diaspora' ); ?></label>
439
+		<?php else {
440
+  : ?>
441
+			<label title="<?php echo esc_attr( $description );
442
+}
443
+?>"><?php echo $checkbox; ?><?php esc_html_e( 'Show "Posted at" link?', 'wp-to-diaspora' ); ?></label>
441 444
 		<?php endif;
442 445
 	}
443 446
 
@@ -475,9 +478,11 @@  discard block
 block discarded – undo
475 478
 
476 479
 		<?php if ( $on_settings_page ) : ?>
477 480
 			<p class="description"><?php echo esc_html( $description ); ?></p>
478
-		<?php else : ?>
481
+		<?php else {
482
+  : ?>
479 483
 			</label>
480 484
 		<?php endif;
485
+}
481 486
 	}
482 487
 
483 488
 	/**
@@ -559,8 +564,11 @@  discard block
 block discarded – undo
559 564
 				<?php foreach ( $list as $id => $name ) : ?>
560 565
 					<label><input type="checkbox" name="wp_to_diaspora_settings[<?php echo esc_attr( $type ); ?>][]" value="<?php echo esc_attr( $id ); ?>" <?php checked( in_array( $id, $items ) ); ?>><?php echo esc_html( $name ); ?></label>
561 566
 				<?php endforeach; ?>
562
-			<?php else : ?>
563
-				<label><?php echo $empty_label; ?></label>
567
+			<?php else {
568
+  : ?>
569
+				<label><?php echo $empty_label;
570
+}
571
+?></label>
564 572
 			<?php endif; ?>
565 573
 		</div>
566 574
 		<p class="description">
Please login to merge, or discard this patch.
Spacing   +212 added lines, -212 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  */
8 8
 
9 9
 // Exit if accessed directly.
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 /**
13 13
  * Class to manage the settings using the Settings API.
@@ -31,12 +31,12 @@  discard block
 block discarded – undo
31 31
 		'aspects_list'       => array(),
32 32
 		'services_list'      => array(),
33 33
 		'post_to_diaspora'   => true,
34
-		'enabled_post_types' => array( 'post' ),
34
+		'enabled_post_types' => array('post'),
35 35
 		'fullentrylink'      => true,
36 36
 		'display'            => 'full',
37
-		'tags_to_post'       => array( 'global', 'custom', 'post' ),
37
+		'tags_to_post'       => array('global', 'custom', 'post'),
38 38
 		'global_tags'        => '',
39
-		'aspects'            => array( 'public' ),
39
+		'aspects'            => array('public'),
40 40
 		'services'           => array(),
41 41
 		'version'            => WP2D_VERSION,
42 42
 	);
@@ -47,8 +47,8 @@  discard block
 block discarded – undo
47 47
 	 * @var array
48 48
 	 */
49 49
 	private static $_valid_values = array(
50
-		'display'      => array( 'full', 'excerpt' ),
51
-		'tags_to_post' => array( 'global', 'custom', 'post' ),
50
+		'display'      => array('full', 'excerpt'),
51
+		'tags_to_post' => array('global', 'custom', 'post'),
52 52
 	);
53 53
 
54 54
 	/**
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 	 * @return WP2D_Options Instance of this class.
74 74
 	 */
75 75
 	public static function instance() {
76
-		if ( ! isset( self::$_instance ) ) {
76
+		if ( ! isset(self::$_instance)) {
77 77
 			self::$_instance = new self();
78 78
 			self::$_instance->_setup();
79 79
 		}
@@ -89,10 +89,10 @@  discard block
 block discarded – undo
89 89
 		$this->get_option();
90 90
 
91 91
 		// Setup Options page and Contextual Help.
92
-		add_action( 'admin_menu', array( $this, 'setup_wpadmin_pages' ) );
92
+		add_action('admin_menu', array($this, 'setup_wpadmin_pages'));
93 93
 
94 94
 		// Register all settings.
95
-		add_action( 'admin_init', array( $this, 'register_settings' ) );
95
+		add_action('admin_init', array($this, 'register_settings'));
96 96
 	}
97 97
 
98 98
 
@@ -104,11 +104,11 @@  discard block
 block discarded – undo
104 104
 	 * @param string $default Tab to select if the current selection is invalid.
105 105
 	 * @return string Return the currently selected tab.
106 106
 	 */
107
-	private function _current_tab( $default = 'defaults' ) {
108
-		$tab = ( isset ( $_GET['tab'] ) ? $_GET['tab'] : $default );
107
+	private function _current_tab($default = 'defaults') {
108
+		$tab = (isset ($_GET['tab']) ? $_GET['tab'] : $default);
109 109
 
110 110
 		// If the pod settings aren't configured yet, open the 'Setup' tab.
111
-		if ( ! $this->is_pod_set_up() ) {
111
+		if ( ! $this->is_pod_set_up()) {
112 112
 			$tab = 'setup';
113 113
 		}
114 114
 
@@ -121,21 +121,21 @@  discard block
 block discarded – undo
121 121
 	 * @param bool $return Define if the options tabs should be returned.
122 122
 	 * @return array (If requested) An array of the outputted options tabs.
123 123
 	 */
124
-	private function _options_page_tabs( $return = false ) {
124
+	private function _options_page_tabs($return = false) {
125 125
 		// The array defining all options sections to be shown as tabs.
126 126
 		$tabs = array();
127
-		if ( $this->is_pod_set_up() ) {
128
-			$tabs['defaults'] = __( 'Defaults', 'wp-to-diaspora' );
127
+		if ($this->is_pod_set_up()) {
128
+			$tabs['defaults'] = __('Defaults', 'wp-to-diaspora');
129 129
 		}
130 130
 
131 131
 		// Add the 'Setup' tab to the end of the list.
132
-		$tabs['setup'] = __( 'Setup', 'wp-to-diaspora' ) . '<span id="pod-connection-status" class="dashicons-before hidden"></span><span class="spinner"></span>';
132
+		$tabs['setup'] = __('Setup', 'wp-to-diaspora').'<span id="pod-connection-status" class="dashicons-before hidden"></span><span class="spinner"></span>';
133 133
 
134 134
 		// Container for all options tabs.
135 135
 		$out = '<h2 id="options-tabs" class="nav-tab-wrapper">';
136
-		foreach ( $tabs as $tab => $name ) {
136
+		foreach ($tabs as $tab => $name) {
137 137
 			// The tab link.
138
-			$out .= '<a class="nav-tab' . ( ( $tab === $this->_current_tab() ) ? ' nav-tab-active' : '' ) . '" href="?page=wp_to_diaspora&tab=' . $tab . '">' . $name . '</a>';
138
+			$out .= '<a class="nav-tab'.(($tab === $this->_current_tab()) ? ' nav-tab-active' : '').'" href="?page=wp_to_diaspora&tab='.$tab.'">'.$name.'</a>';
139 139
 		}
140 140
 		$out .= '</h2>';
141 141
 
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 		echo $out;
144 144
 
145 145
 		// Check if the tabs should be returned.
146
-		if ( $return ) {
146
+		if ($return) {
147 147
 			return $tabs;
148 148
 		}
149 149
 	}
@@ -157,15 +157,15 @@  discard block
 block discarded – undo
157 157
 		<div class="wrap">
158 158
 			<h2>WP to diaspora*</h2>
159 159
 
160
-			<div id="wp2d-message" class="notice hidden" <?php echo ( defined( 'WP2D_DEBUGGING' ) ) ? ' data-debugging' : ''; ?>></div>
160
+			<div id="wp2d-message" class="notice hidden" <?php echo (defined('WP2D_DEBUGGING')) ? ' data-debugging' : ''; ?>></div>
161 161
 
162 162
 			<?php
163 163
 			// Check the connection status to diaspora.
164
-			if ( ! $this->is_pod_set_up() ) {
164
+			if ( ! $this->is_pod_set_up()) {
165 165
 				add_settings_error(
166 166
 					'wp_to_diaspora_settings',
167 167
 					'wp_to_diaspora_connected',
168
-					__( 'First of all, set up the connection to your pod below.', 'wp-to-diaspora' ),
168
+					__('First of all, set up the connection to your pod below.', 'wp-to-diaspora'),
169 169
 					'updated'
170 170
 				);
171 171
 			} else {
@@ -173,54 +173,54 @@  discard block
 block discarded – undo
173 173
 				// DON'T check for empty services list here!!
174 174
 				// It could always be empty, resulting in this code being run every time the page is loaded.
175 175
 				// The aspects will at least have a "Public" entry after the initial fetch.
176
-				$aspects_list = $this->get_option( 'aspects_list' );
177
-				if ( ( $force = get_transient( 'wp2d_no_js_force_refetch' ) ) || empty( $aspects_list ) ) {
176
+				$aspects_list = $this->get_option('aspects_list');
177
+				if (($force = get_transient('wp2d_no_js_force_refetch')) || empty($aspects_list)) {
178 178
 
179 179
 					// Set up the connection to diaspora*.
180 180
 					$api = WP2D_Helpers::api_quick_connect();
181
-					if ( ! $api->has_last_error() ) {
181
+					if ( ! $api->has_last_error()) {
182 182
 						// Get the loaded aspects.
183
-						if ( is_array( $aspects = $api->get_aspects() ) ) {
183
+						if (is_array($aspects = $api->get_aspects())) {
184 184
 							// Save the new list of aspects.
185
-							$this->set_option( 'aspects_list', $aspects );
185
+							$this->set_option('aspects_list', $aspects);
186 186
 						}
187 187
 
188 188
 						// Get the loaded services.
189
-						if ( is_array( $services = $api->get_services() ) ) {
189
+						if (is_array($services = $api->get_services())) {
190 190
 							// Save the new list of services.
191
-							$this->set_option( 'services_list', $services );
191
+							$this->set_option('services_list', $services);
192 192
 						}
193 193
 
194 194
 						$this->save();
195 195
 					}
196 196
 
197
-					if ( $force ) {
198
-						delete_transient( 'wp2d_no_js_force_refetch' );
199
-						$message = ( ! $api->has_last_error() ) ? __( 'Connection successful.', 'wp-to-diaspora' ) : $api->get_last_error();
197
+					if ($force) {
198
+						delete_transient('wp2d_no_js_force_refetch');
199
+						$message = ( ! $api->has_last_error()) ? __('Connection successful.', 'wp-to-diaspora') : $api->get_last_error();
200 200
 						add_settings_error(
201 201
 							'wp_to_diaspora_settings',
202 202
 							'wp_to_diaspora_connected',
203 203
 							$message,
204
-							( ! $api->has_last_error() ) ? 'updated' : 'error'
204
+							( ! $api->has_last_error()) ? 'updated' : 'error'
205 205
 						);
206 206
 					}
207 207
 				}
208 208
 
209 209
 				// Attempt to get the cacert.pem file and save it to the plugin's root directory.
210
-				if ( isset( $_GET['wp2d_temp_ssl_fix'] ) ) {
211
-					$cacert_file = file_get_contents( 'http://curl.haxx.se/ca/cacert.pem' );
212
-					if ( $cacert_file && file_put_contents( WP2D_DIR . '/cacert.pem', $cacert_file ) ) {
210
+				if (isset($_GET['wp2d_temp_ssl_fix'])) {
211
+					$cacert_file = file_get_contents('http://curl.haxx.se/ca/cacert.pem');
212
+					if ($cacert_file && file_put_contents(WP2D_DIR.'/cacert.pem', $cacert_file)) {
213 213
 						add_settings_error(
214 214
 							'wp_to_diaspora_settings',
215 215
 							'wp_to_diaspora_temp_ssl_fix',
216
-							__( 'Successfully saved cacert.pem!', 'wp-to-diaspora' ),
216
+							__('Successfully saved cacert.pem!', 'wp-to-diaspora'),
217 217
 							'updated'
218 218
 						);
219 219
 					} else {
220 220
 						add_settings_error(
221 221
 							'wp_to_diaspora_settings',
222 222
 							'wp_to_diaspora_temp_ssl_fix',
223
-							__( 'Failed to save cacert.pem!', 'wp-to-diaspora' ),
223
+							__('Failed to save cacert.pem!', 'wp-to-diaspora'),
224 224
 							'error'
225 225
 						);
226 226
 					}
@@ -228,25 +228,25 @@  discard block
 block discarded – undo
228 228
 			}
229 229
 
230 230
 			// Output success or error message.
231
-			settings_errors( 'wp_to_diaspora_settings' );
231
+			settings_errors('wp_to_diaspora_settings');
232 232
 			?>
233 233
 
234
-			<?php $page_tabs = array_keys( $this->_options_page_tabs( true ) ); ?>
234
+			<?php $page_tabs = array_keys($this->_options_page_tabs(true)); ?>
235 235
 
236 236
 			<form action="options.php" method="post">
237 237
 				<input id="wp2d_no_js" type="hidden" name="wp_to_diaspora_settings[no_js]" value="1">
238 238
 				<?php
239 239
 				// Load the settings fields.
240
-				settings_fields( 'wp_to_diaspora_settings' );
241
-				do_settings_sections( 'wp_to_diaspora_settings' );
240
+				settings_fields('wp_to_diaspora_settings');
241
+				do_settings_sections('wp_to_diaspora_settings');
242 242
 
243 243
 				// Get the name of the current tab, if set, else take the first one from the list.
244
-				$tab = $this->_current_tab( $page_tabs[0] );
244
+				$tab = $this->_current_tab($page_tabs[0]);
245 245
 
246 246
 				// Add Save and Reset buttons.
247
-				echo '<input id="submit-' . esc_attr( $tab ) . '" name="wp_to_diaspora_settings[submit_' . esc_attr( $tab ) . ']" type="submit" class="button-primary" value="' . esc_attr__( 'Save Changes' ) . '" />&nbsp;';
248
-				if ( 'setup' !== $tab ) {
249
-					echo '<input id="reset-' . esc_attr( $tab ) . '" name="wp_to_diaspora_settings[reset_' . esc_attr( $tab ) . ']" type="submit" class="button-secondary" value="' . esc_attr__( 'Reset Defaults', 'wp-to-diaspora' ) . '" />';
247
+				echo '<input id="submit-'.esc_attr($tab).'" name="wp_to_diaspora_settings[submit_'.esc_attr($tab).']" type="submit" class="button-primary" value="'.esc_attr__('Save Changes').'" />&nbsp;';
248
+				if ('setup' !== $tab) {
249
+					echo '<input id="reset-'.esc_attr($tab).'" name="wp_to_diaspora_settings[reset_'.esc_attr($tab).']" type="submit" class="button-secondary" value="'.esc_attr__('Reset Defaults', 'wp-to-diaspora').'" />';
250 250
 				}
251 251
 				?>
252 252
 
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
 	 * @return boolean If the setup for the pod has been done.
263 263
 	 */
264 264
 	public function is_pod_set_up() {
265
-		return ( $this->get_option( 'pod' ) && $this->get_option( 'username' ) && $this->get_option( 'password' ) );
265
+		return ($this->get_option('pod') && $this->get_option('username') && $this->get_option('password'));
266 266
 	}
267 267
 
268 268
 	/**
@@ -270,14 +270,14 @@  discard block
 block discarded – undo
270 270
 	 */
271 271
 	public function setup_wpadmin_pages() {
272 272
 		// Add options page.
273
-		$hook = add_options_page( 'WP to diaspora*', 'WP to diaspora*', 'manage_options', 'wp_to_diaspora', array( $this, 'admin_options_page' ) );
273
+		$hook = add_options_page('WP to diaspora*', 'WP to diaspora*', 'manage_options', 'wp_to_diaspora', array($this, 'admin_options_page'));
274 274
 
275 275
 		// Setup the contextual help menu after the options page has been loaded.
276
-		add_action( 'load-' . $hook, array( 'WP2D_Contextual_Help', 'instance' ) );
276
+		add_action('load-'.$hook, array('WP2D_Contextual_Help', 'instance'));
277 277
 
278 278
 		// Setup the contextual help menu tab for post types. Checks are made there!
279
-		add_action( 'load-post.php', array( 'WP2D_Contextual_Help', 'instance' ) );
280
-		add_action( 'load-post-new.php', array( 'WP2D_Contextual_Help', 'instance' ) );
279
+		add_action('load-post.php', array('WP2D_Contextual_Help', 'instance'));
280
+		add_action('load-post-new.php', array('WP2D_Contextual_Help', 'instance'));
281 281
 	}
282 282
 
283 283
 	/**
@@ -285,17 +285,17 @@  discard block
 block discarded – undo
285 285
 	 */
286 286
 	public function register_settings() {
287 287
 		// Register the settings with validation callback.
288
-		register_setting( 'wp_to_diaspora_settings', 'wp_to_diaspora_settings', array( $this, 'validate_settings' ) );
288
+		register_setting('wp_to_diaspora_settings', 'wp_to_diaspora_settings', array($this, 'validate_settings'));
289 289
 
290 290
 		// Load only the sections of the selected tab.
291
-		switch ( $this->_current_tab() ) {
291
+		switch ($this->_current_tab()) {
292 292
 			case 'defaults' :
293 293
 				// Add a "Defaults" section that contains all posting settings to be used by default.
294
-				add_settings_section( 'wp_to_diaspora_defaults_section', __( 'Posting Defaults', 'wp-to-diaspora' ), array( $this, 'defaults_section' ), 'wp_to_diaspora_settings' );
294
+				add_settings_section('wp_to_diaspora_defaults_section', __('Posting Defaults', 'wp-to-diaspora'), array($this, 'defaults_section'), 'wp_to_diaspora_settings');
295 295
 				break;
296 296
 			case 'setup' :
297 297
 				// Add a "Setup" section that contains the Pod domain, Username and Password.
298
-				add_settings_section( 'wp_to_diaspora_setup_section', __( 'diaspora* Setup', 'wp-to-diaspora' ), array( $this, 'setup_section' ), 'wp_to_diaspora_settings' );
298
+				add_settings_section('wp_to_diaspora_setup_section', __('diaspora* Setup', 'wp-to-diaspora'), array($this, 'setup_section'), 'wp_to_diaspora_settings');
299 299
 				break;
300 300
 		}
301 301
 	}
@@ -305,16 +305,16 @@  discard block
 block discarded – undo
305 305
 	 * Callback for the "Setup" section.
306 306
 	 */
307 307
 	public function setup_section() {
308
-		esc_html_e( 'Set up the connection to your diaspora* account.', 'wp-to-diaspora' );
308
+		esc_html_e('Set up the connection to your diaspora* account.', 'wp-to-diaspora');
309 309
 
310 310
 		// Pod entry field.
311
-		add_settings_field( 'pod', __( 'Diaspora* Pod', 'wp-to-diaspora' ), array( $this, 'pod_render' ), 'wp_to_diaspora_settings', 'wp_to_diaspora_setup_section' );
311
+		add_settings_field('pod', __('Diaspora* Pod', 'wp-to-diaspora'), array($this, 'pod_render'), 'wp_to_diaspora_settings', 'wp_to_diaspora_setup_section');
312 312
 
313 313
 		// Username entry field.
314
-		add_settings_field( 'username', __( 'Username' ), array( $this, 'username_render' ), 'wp_to_diaspora_settings', 'wp_to_diaspora_setup_section' );
314
+		add_settings_field('username', __('Username'), array($this, 'username_render'), 'wp_to_diaspora_settings', 'wp_to_diaspora_setup_section');
315 315
 
316 316
 		// Password entry field.
317
-		add_settings_field( 'password', __( 'Password' ), array( $this, 'password_render' ), 'wp_to_diaspora_settings', 'wp_to_diaspora_setup_section' );
317
+		add_settings_field('password', __('Password'), array($this, 'password_render'), 'wp_to_diaspora_settings', 'wp_to_diaspora_setup_section');
318 318
 	}
319 319
 
320 320
 	/**
@@ -322,10 +322,10 @@  discard block
 block discarded – undo
322 322
 	 */
323 323
 	public function pod_render() {
324 324
 		?>
325
-		https://<input type="text" name="wp_to_diaspora_settings[pod]" value="<?php echo esc_attr( $this->get_option( 'pod' ) ); ?>" placeholder="e.g. joindiaspora.com" autocomplete="on" list="pod-list" required> <a id="refresh-pod-list" class="button hide-if-no-js"><?php esc_html_e( 'Refresh pod list', 'wp-to-diaspora' ); ?></a><span class="spinner"></span>
325
+		https://<input type="text" name="wp_to_diaspora_settings[pod]" value="<?php echo esc_attr($this->get_option('pod')); ?>" placeholder="e.g. joindiaspora.com" autocomplete="on" list="pod-list" required> <a id="refresh-pod-list" class="button hide-if-no-js"><?php esc_html_e('Refresh pod list', 'wp-to-diaspora'); ?></a><span class="spinner"></span>
326 326
 		<datalist id="pod-list">
327
-		<?php foreach ( (array) $this->get_option( 'pod_list' ) as $pod ) : ?>
328
-			<option data-secure="<?php echo esc_attr( $pod['secure'] ); ?>" value="<?php echo esc_attr( $pod['domain'] ); ?>"></option>
327
+		<?php foreach ((array) $this->get_option('pod_list') as $pod) : ?>
328
+			<option data-secure="<?php echo esc_attr($pod['secure']); ?>" value="<?php echo esc_attr($pod['domain']); ?>"></option>
329 329
 		<?php endforeach; ?>
330 330
 		</datalist>
331 331
 		<?php
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
 	 */
337 337
 	public function username_render() {
338 338
 		?>
339
-		<input type="text" name="wp_to_diaspora_settings[username]" value="<?php echo esc_attr( $this->get_option( 'username' ) ); ?>" placeholder="<?php esc_attr_e( 'Username' ); ?>" required>
339
+		<input type="text" name="wp_to_diaspora_settings[username]" value="<?php echo esc_attr($this->get_option('username')); ?>" placeholder="<?php esc_attr_e('Username'); ?>" required>
340 340
 		<?php
341 341
 	}
342 342
 
@@ -345,13 +345,13 @@  discard block
 block discarded – undo
345 345
 	 */
346 346
 	public function password_render() {
347 347
 		// Special case if we already have a password.
348
-		$has_password = ( '' !== $this->get_option( 'password', '' ) );
349
-		$placeholder  = ( $has_password ) ? __( 'Password already set.', 'wp-to-diaspora' ) : __( 'Password' );
350
-		$required     = ( $has_password ) ? '' : ' required';
348
+		$has_password = ('' !== $this->get_option('password', ''));
349
+		$placeholder  = ($has_password) ? __('Password already set.', 'wp-to-diaspora') : __('Password');
350
+		$required     = ($has_password) ? '' : ' required';
351 351
 		?>
352
-		<input type="password" name="wp_to_diaspora_settings[password]" value="" placeholder="<?php echo esc_attr( $placeholder ); ?>"<?php echo esc_attr( $required ); ?>>
353
-		<?php if ( $has_password ) : ?>
354
-			<p class="description"><?php esc_html_e( 'If you would like to change the password type a new one. Otherwise leave this blank.', 'wp-to-diaspora' ); ?></p>
352
+		<input type="password" name="wp_to_diaspora_settings[password]" value="" placeholder="<?php echo esc_attr($placeholder); ?>"<?php echo esc_attr($required); ?>>
353
+		<?php if ($has_password) : ?>
354
+			<p class="description"><?php esc_html_e('If you would like to change the password type a new one. Otherwise leave this blank.', 'wp-to-diaspora'); ?></p>
355 355
 		<?php endif;
356 356
 	}
357 357
 
@@ -360,53 +360,53 @@  discard block
 block discarded – undo
360 360
 	 * Callback for the "Defaults" section.
361 361
 	 */
362 362
 	public function defaults_section() {
363
-		esc_html_e( 'Define the default posting behaviour for all posts here. These settings can be modified for each post individually, by changing the values in the "WP to diaspora*" meta box, which gets displayed in your post edit screen.', 'wp-to-diaspora' );
363
+		esc_html_e('Define the default posting behaviour for all posts here. These settings can be modified for each post individually, by changing the values in the "WP to diaspora*" meta box, which gets displayed in your post edit screen.', 'wp-to-diaspora');
364 364
 
365 365
 		// Post types field.
366
-		add_settings_field( 'enabled_post_types', __( 'Post types', 'wp-to-diaspora' ), array( $this, 'post_types_render' ), 'wp_to_diaspora_settings', 'wp_to_diaspora_defaults_section' );
366
+		add_settings_field('enabled_post_types', __('Post types', 'wp-to-diaspora'), array($this, 'post_types_render'), 'wp_to_diaspora_settings', 'wp_to_diaspora_defaults_section');
367 367
 
368 368
 		 // Post to diaspora* checkbox.
369
-		add_settings_field( 'post_to_diaspora', __( 'Post to diaspora*', 'wp-to-diaspora' ), array( $this, 'post_to_diaspora_render' ), 'wp_to_diaspora_settings', 'wp_to_diaspora_defaults_section', $this->get_option( 'post_to_diaspora' ) );
369
+		add_settings_field('post_to_diaspora', __('Post to diaspora*', 'wp-to-diaspora'), array($this, 'post_to_diaspora_render'), 'wp_to_diaspora_settings', 'wp_to_diaspora_defaults_section', $this->get_option('post_to_diaspora'));
370 370
 
371 371
 		// Full entry link checkbox.
372
-		add_settings_field( 'fullentrylink', __( 'Show "Posted at" link?', 'wp-to-diaspora' ), array( $this, 'fullentrylink_render' ), 'wp_to_diaspora_settings', 'wp_to_diaspora_defaults_section', $this->get_option( 'fullentrylink' ) );
372
+		add_settings_field('fullentrylink', __('Show "Posted at" link?', 'wp-to-diaspora'), array($this, 'fullentrylink_render'), 'wp_to_diaspora_settings', 'wp_to_diaspora_defaults_section', $this->get_option('fullentrylink'));
373 373
 
374 374
 		// Full text or excerpt radio buttons.
375
-		add_settings_field( 'display', __( 'Display', 'wp-to-diaspora' ), array( $this, 'display_render' ), 'wp_to_diaspora_settings', 'wp_to_diaspora_defaults_section', $this->get_option( 'display' ) );
375
+		add_settings_field('display', __('Display', 'wp-to-diaspora'), array($this, 'display_render'), 'wp_to_diaspora_settings', 'wp_to_diaspora_defaults_section', $this->get_option('display'));
376 376
 
377 377
 		// Tags to post dropdown.
378
-		add_settings_field( 'tags_to_post', __( 'Tags to post', 'wp-to-diaspora' ), array( $this, 'tags_to_post_render' ), 'wp_to_diaspora_settings', 'wp_to_diaspora_defaults_section', $this->get_option( 'tags_to_post', 'gc' ) );
378
+		add_settings_field('tags_to_post', __('Tags to post', 'wp-to-diaspora'), array($this, 'tags_to_post_render'), 'wp_to_diaspora_settings', 'wp_to_diaspora_defaults_section', $this->get_option('tags_to_post', 'gc'));
379 379
 
380 380
 		// Global tags field.
381
-		add_settings_field( 'global_tags', __( 'Global tags', 'wp-to-diaspora' ), array( $this, 'global_tags_render' ), 'wp_to_diaspora_settings', 'wp_to_diaspora_defaults_section', $this->get_option( 'global_tags' ) );
381
+		add_settings_field('global_tags', __('Global tags', 'wp-to-diaspora'), array($this, 'global_tags_render'), 'wp_to_diaspora_settings', 'wp_to_diaspora_defaults_section', $this->get_option('global_tags'));
382 382
 
383 383
 		// Aspects checkboxes.
384
-		add_settings_field( 'aspects', __( 'Aspects', 'wp-to-diaspora' ), array( $this, 'aspects_services_render' ), 'wp_to_diaspora_settings', 'wp_to_diaspora_defaults_section', array( 'aspects', $this->get_option( 'aspects' ) ) );
384
+		add_settings_field('aspects', __('Aspects', 'wp-to-diaspora'), array($this, 'aspects_services_render'), 'wp_to_diaspora_settings', 'wp_to_diaspora_defaults_section', array('aspects', $this->get_option('aspects')));
385 385
 
386 386
 		// Services checkboxes.
387
-		add_settings_field( 'services', __( 'Services', 'wp-to-diaspora' ), array( $this, 'aspects_services_render' ), 'wp_to_diaspora_settings', 'wp_to_diaspora_defaults_section', array( 'services', $this->get_option( 'services' ) ) );
387
+		add_settings_field('services', __('Services', 'wp-to-diaspora'), array($this, 'aspects_services_render'), 'wp_to_diaspora_settings', 'wp_to_diaspora_defaults_section', array('services', $this->get_option('services')));
388 388
 	}
389 389
 
390 390
 	/**
391 391
 	 * Render the "Post types" checkboxes.
392 392
 	 */
393 393
 	public function post_types_render() {
394
-		$post_types = get_post_types( array( 'public' => true ), 'objects' );
394
+		$post_types = get_post_types(array('public' => true), 'objects');
395 395
 
396 396
 		// Remove excluded post types from the list.
397
-		$excluded_post_types = array( 'attachment', 'nav_menu_item', 'revision' );
398
-		foreach ( $excluded_post_types as $excluded ) {
399
-			unset( $post_types[ $excluded ] );
397
+		$excluded_post_types = array('attachment', 'nav_menu_item', 'revision');
398
+		foreach ($excluded_post_types as $excluded) {
399
+			unset($post_types[$excluded]);
400 400
 		}
401 401
 		?>
402 402
 
403
-		<select id="enabled-post-types" multiple data-placeholder="<?php esc_attr_e( 'None', 'wp-to-diaspora' ); ?>" class="chosen" name="wp_to_diaspora_settings[enabled_post_types][]">
404
-		<?php foreach ( $post_types as $post_type ) : ?>
405
-			<option value="<?php echo esc_attr( $post_type->name ); ?>" <?php selected( in_array( $post_type->name, $this->get_option( 'enabled_post_types' ) ) ); ?>><?php echo esc_html( $post_type->label ); ?></option>
403
+		<select id="enabled-post-types" multiple data-placeholder="<?php esc_attr_e('None', 'wp-to-diaspora'); ?>" class="chosen" name="wp_to_diaspora_settings[enabled_post_types][]">
404
+		<?php foreach ($post_types as $post_type) : ?>
405
+			<option value="<?php echo esc_attr($post_type->name); ?>" <?php selected(in_array($post_type->name, $this->get_option('enabled_post_types'))); ?>><?php echo esc_html($post_type->label); ?></option>
406 406
 		<?php endforeach; ?>
407 407
 		</select>
408 408
 
409
-		<p class="description"><?php esc_html_e( 'Choose which post types can be posted to diaspora*.', 'wp-to-diaspora' ); ?></p>
409
+		<p class="description"><?php esc_html_e('Choose which post types can be posted to diaspora*.', 'wp-to-diaspora'); ?></p>
410 410
 
411 411
 		<?php
412 412
 	}
@@ -416,10 +416,10 @@  discard block
 block discarded – undo
416 416
 	 *
417 417
 	 * @param bool $post_to_diaspora If this checkbox is checked or not.
418 418
 	 */
419
-	public function post_to_diaspora_render( $post_to_diaspora ) {
420
-		$label = ( 'settings_page_wp_to_diaspora' === get_current_screen()->id ) ? __( 'Yes' ) : __( 'Post to diaspora*', 'wp-to-diaspora' );
419
+	public function post_to_diaspora_render($post_to_diaspora) {
420
+		$label = ('settings_page_wp_to_diaspora' === get_current_screen()->id) ? __('Yes') : __('Post to diaspora*', 'wp-to-diaspora');
421 421
 		?>
422
-		<label><input type="checkbox" id="post-to-diaspora" name="wp_to_diaspora_settings[post_to_diaspora]" value="1" <?php checked( $post_to_diaspora ); ?>><?php echo esc_html( $label ); ?></label>
422
+		<label><input type="checkbox" id="post-to-diaspora" name="wp_to_diaspora_settings[post_to_diaspora]" value="1" <?php checked($post_to_diaspora); ?>><?php echo esc_html($label); ?></label>
423 423
 		<?php
424 424
 	}
425 425
 
@@ -428,15 +428,15 @@  discard block
 block discarded – undo
428 428
 	 *
429 429
 	 * @param bool $show_link If the checkbox is checked or not.
430 430
 	 */
431
-	public function fullentrylink_render( $show_link ) {
432
-		$description = __( 'Include a link back to your original post.', 'wp-to-diaspora' );
433
-		$checkbox = '<input type="checkbox" id="fullentrylink" name="wp_to_diaspora_settings[fullentrylink]" value="1"' . checked( $show_link, true, false ) . '>';
431
+	public function fullentrylink_render($show_link) {
432
+		$description = __('Include a link back to your original post.', 'wp-to-diaspora');
433
+		$checkbox = '<input type="checkbox" id="fullentrylink" name="wp_to_diaspora_settings[fullentrylink]" value="1"'.checked($show_link, true, false).'>';
434 434
 
435
-		if ( 'settings_page_wp_to_diaspora' === get_current_screen()->id ) : ?>
436
-			<label><?php echo $checkbox; ?><?php esc_html_e( 'Yes' ); ?></label>
437
-			<p class="description"><?php echo esc_html( $description ); ?></p>
435
+		if ('settings_page_wp_to_diaspora' === get_current_screen()->id) : ?>
436
+			<label><?php echo $checkbox; ?><?php esc_html_e('Yes'); ?></label>
437
+			<p class="description"><?php echo esc_html($description); ?></p>
438 438
 		<?php else : ?>
439
-			<label title="<?php echo esc_attr( $description ); ?>"><?php echo $checkbox; ?><?php esc_html_e( 'Show "Posted at" link?', 'wp-to-diaspora' ); ?></label>
439
+			<label title="<?php echo esc_attr($description); ?>"><?php echo $checkbox; ?><?php esc_html_e('Show "Posted at" link?', 'wp-to-diaspora'); ?></label>
440 440
 		<?php endif;
441 441
 	}
442 442
 
@@ -445,10 +445,10 @@  discard block
 block discarded – undo
445 445
 	 *
446 446
 	 * @param string $display The selected radio button.
447 447
 	 */
448
-	public function display_render( $display ) {
448
+	public function display_render($display) {
449 449
 		?>
450
-		<label><input type="radio" name="wp_to_diaspora_settings[display]" value="full" <?php checked( $display, 'full' ); ?>><?php esc_html_e( 'Full Post', 'wp-to-diaspora' ); ?></label><br />
451
-		<label><input type="radio" name="wp_to_diaspora_settings[display]" value="excerpt" <?php checked( $display, 'excerpt' ); ?>><?php esc_html_e( 'Excerpt' ); ?></label>
450
+		<label><input type="radio" name="wp_to_diaspora_settings[display]" value="full" <?php checked($display, 'full'); ?>><?php esc_html_e('Full Post', 'wp-to-diaspora'); ?></label><br />
451
+		<label><input type="radio" name="wp_to_diaspora_settings[display]" value="excerpt" <?php checked($display, 'excerpt'); ?>><?php esc_html_e('Excerpt'); ?></label>
452 452
 		<?php
453 453
 	}
454 454
 
@@ -457,23 +457,23 @@  discard block
 block discarded – undo
457 457
 	 *
458 458
 	 * @param array $tags_to_post The types of tags to be posted.
459 459
 	 */
460
-	public function tags_to_post_render( $tags_to_post ) {
461
-		$on_settings_page = ( 'settings_page_wp_to_diaspora' === get_current_screen()->id );
462
-		$description = esc_html__( 'Choose which tags should be posted to diaspora*.', 'wp-to-diaspora' );
460
+	public function tags_to_post_render($tags_to_post) {
461
+		$on_settings_page = ('settings_page_wp_to_diaspora' === get_current_screen()->id);
462
+		$description = esc_html__('Choose which tags should be posted to diaspora*.', 'wp-to-diaspora');
463 463
 
464
-		if ( ! $on_settings_page ) {
465
-			echo '<label>' . esc_html( $description );
464
+		if ( ! $on_settings_page) {
465
+			echo '<label>'.esc_html($description);
466 466
 		}
467 467
 
468 468
 		?>
469
-		<select id="tags-to-post" multiple data-placeholder="<?php esc_attr_e( 'No tags', 'wp-to-diaspora' ); ?>" class="chosen" name="wp_to_diaspora_settings[tags_to_post][]">
470
-			<option value="global" <?php selected( in_array( 'global', $tags_to_post ) ); ?>><?php esc_html_e( 'Global tags', 'wp-to-diaspora' ); ?></option>
471
-			<option value="custom" <?php selected( in_array( 'custom', $tags_to_post ) ); ?>><?php esc_html_e( 'Custom tags', 'wp-to-diaspora' ); ?></option>
472
-			<option value="post"   <?php selected( in_array( 'post',   $tags_to_post ) ); ?>><?php esc_html_e( 'Post tags',   'wp-to-diaspora' ); ?></option>
469
+		<select id="tags-to-post" multiple data-placeholder="<?php esc_attr_e('No tags', 'wp-to-diaspora'); ?>" class="chosen" name="wp_to_diaspora_settings[tags_to_post][]">
470
+			<option value="global" <?php selected(in_array('global', $tags_to_post)); ?>><?php esc_html_e('Global tags', 'wp-to-diaspora'); ?></option>
471
+			<option value="custom" <?php selected(in_array('custom', $tags_to_post)); ?>><?php esc_html_e('Custom tags', 'wp-to-diaspora'); ?></option>
472
+			<option value="post"   <?php selected(in_array('post', $tags_to_post)); ?>><?php esc_html_e('Post tags', 'wp-to-diaspora'); ?></option>
473 473
 		</select>
474 474
 
475
-		<?php if ( $on_settings_page ) : ?>
476
-			<p class="description"><?php echo esc_html( $description ); ?></p>
475
+		<?php if ($on_settings_page) : ?>
476
+			<p class="description"><?php echo esc_html($description); ?></p>
477 477
 		<?php else : ?>
478 478
 			</label>
479 479
 		<?php endif;
@@ -484,11 +484,11 @@  discard block
 block discarded – undo
484 484
 	 *
485 485
 	 * @param array $tags The global tags to be posted.
486 486
 	 */
487
-	public function global_tags_render( $tags ) {
488
-		WP2D_Helpers::arr_to_str( $tags );
487
+	public function global_tags_render($tags) {
488
+		WP2D_Helpers::arr_to_str($tags);
489 489
 		?>
490
-		<input type="text" class="wp2dtags" name="wp_to_diaspora_settings[global_tags]" value="<?php echo esc_attr( $tags ); ?>" placeholder="<?php esc_attr_e( 'Global tags', 'wp-to-diaspora' ); ?>" class="regular-text">
491
-		<p class="description"><?php esc_html_e( 'Custom tags to add to all posts being posted to diaspora*.', 'wp-to-diaspora' ); ?></p>
490
+		<input type="text" class="wp2dtags" name="wp_to_diaspora_settings[global_tags]" value="<?php echo esc_attr($tags); ?>" placeholder="<?php esc_attr_e('Global tags', 'wp-to-diaspora'); ?>" class="regular-text">
491
+		<p class="description"><?php esc_html_e('Custom tags to add to all posts being posted to diaspora*.', 'wp-to-diaspora'); ?></p>
492 492
 		<?php
493 493
 	}
494 494
 
@@ -497,14 +497,14 @@  discard block
 block discarded – undo
497 497
 	 *
498 498
 	 * @param array $tags The custom tags to be posted.
499 499
 	 */
500
-	public function custom_tags_render( $tags ) {
501
-		WP2D_Helpers::arr_to_str( $tags );
500
+	public function custom_tags_render($tags) {
501
+		WP2D_Helpers::arr_to_str($tags);
502 502
 		?>
503
-		<label title="<?php esc_attr_e( 'Custom tags to add to this post when it\'s posted to diaspora*.', 'wp-to-diaspora' ); ?>">
504
-			<?php esc_html_e( 'Custom tags', 'wp-to-diaspora' ); ?>
505
-			<input type="text" class="wp2dtags" name="wp_to_diaspora_settings[custom_tags]" value="<?php echo esc_attr( $tags ); ?>" class="widefat">
503
+		<label title="<?php esc_attr_e('Custom tags to add to this post when it\'s posted to diaspora*.', 'wp-to-diaspora'); ?>">
504
+			<?php esc_html_e('Custom tags', 'wp-to-diaspora'); ?>
505
+			<input type="text" class="wp2dtags" name="wp_to_diaspora_settings[custom_tags]" value="<?php echo esc_attr($tags); ?>" class="widefat">
506 506
 		</label>
507
-		<p class="description"><?php esc_html_e( 'Separate tags with commas' ); ?></p>
507
+		<p class="description"><?php esc_html_e('Separate tags with commas'); ?></p>
508 508
 		<?php
509 509
 	}
510 510
 
@@ -513,50 +513,50 @@  discard block
 block discarded – undo
513 513
 	 *
514 514
 	 * @param array $args Array containing the type and items to output as checkboxes.
515 515
 	 */
516
-	public function aspects_services_render( $args ) {
517
-		list( $type, $items ) = $args;
516
+	public function aspects_services_render($args) {
517
+		list($type, $items) = $args;
518 518
 
519 519
 		$refresh_button = '';
520 520
 		$description    = '';
521 521
 		$empty_label    = '';
522 522
 
523 523
 		// This is where the 2 types show their differences.
524
-		switch ( $type ) {
524
+		switch ($type) {
525 525
 			case 'aspects':
526
-				$refresh_button = __( 'Refresh Aspects', 'wp-to-diaspora' );
527
-				$description    = esc_html__( 'Choose which aspects to share to.', 'wp-to-diaspora' );
528
-				$empty_label    = '<input type="checkbox" name="wp_to_diaspora_settings[aspects][]" value="public" checked="checked">' . esc_html__( 'Public' );
526
+				$refresh_button = __('Refresh Aspects', 'wp-to-diaspora');
527
+				$description    = esc_html__('Choose which aspects to share to.', 'wp-to-diaspora');
528
+				$empty_label    = '<input type="checkbox" name="wp_to_diaspora_settings[aspects][]" value="public" checked="checked">'.esc_html__('Public');
529 529
 				break;
530 530
 
531 531
 			case 'services':
532
-				$refresh_button = __( 'Refresh Services', 'wp-to-diaspora' );
533
-				$description    = sprintf( '%1$s<br><a href="%2$s" target="_blank">%3$s</a>',
534
-					esc_html__( 'Choose which services to share to.', 'wp-to-diaspora' ),
535
-					esc_url( 'https://' . $this->get_option( 'pod' ) . '/services' ),
536
-					esc_html__( 'Show available services on my pod.', 'wp-to-diaspora' )
532
+				$refresh_button = __('Refresh Services', 'wp-to-diaspora');
533
+				$description    = sprintf('%1$s<br><a href="%2$s" target="_blank">%3$s</a>',
534
+					esc_html__('Choose which services to share to.', 'wp-to-diaspora'),
535
+					esc_url('https://'.$this->get_option('pod').'/services'),
536
+					esc_html__('Show available services on my pod.', 'wp-to-diaspora')
537 537
 				);
538
-				$empty_label    = esc_html__( 'No services connected yet.', 'wp-to-diaspora' );
538
+				$empty_label = esc_html__('No services connected yet.', 'wp-to-diaspora');
539 539
 				break;
540 540
 
541 541
 			default:
542 542
 				return;
543 543
 		}
544 544
 
545
-		$items = array_filter( (array) $items ) ?: array();
545
+		$items = array_filter((array) $items) ?: array();
546 546
 
547 547
 		// Special case for this field if it's displayed on the settings page.
548
-		$on_settings_page = ( 'settings_page_wp_to_diaspora' === get_current_screen()->id );
548
+		$on_settings_page = ('settings_page_wp_to_diaspora' === get_current_screen()->id);
549 549
 
550
-		if ( ! $on_settings_page ) {
550
+		if ( ! $on_settings_page) {
551 551
 			echo $description;
552 552
 			$description = '';
553 553
 		}
554 554
 
555 555
 		?>
556
-		<div id="<?php echo esc_attr( $type ); ?>-container" data-<?php echo esc_attr( $type ); ?>-selected="<?php echo esc_attr( implode( ',', $items ) ); ?>">
557
-			<?php if ( $list = (array) $this->get_option( $type . '_list' ) ) : ?>
558
-				<?php foreach ( $list as $id => $name ) : ?>
559
-					<label><input type="checkbox" name="wp_to_diaspora_settings[<?php echo esc_attr( $type ); ?>][]" value="<?php echo esc_attr( $id ); ?>" <?php checked( in_array( $id, $items ) ); ?>><?php echo esc_html( $name ); ?></label>
556
+		<div id="<?php echo esc_attr($type); ?>-container" data-<?php echo esc_attr($type); ?>-selected="<?php echo esc_attr(implode(',', $items)); ?>">
557
+			<?php if ($list = (array) $this->get_option($type.'_list')) : ?>
558
+				<?php foreach ($list as $id => $name) : ?>
559
+					<label><input type="checkbox" name="wp_to_diaspora_settings[<?php echo esc_attr($type); ?>][]" value="<?php echo esc_attr($id); ?>" <?php checked(in_array($id, $items)); ?>><?php echo esc_html($name); ?></label>
560 560
 				<?php endforeach; ?>
561 561
 			<?php else : ?>
562 562
 				<label><?php echo $empty_label; ?></label>
@@ -564,9 +564,9 @@  discard block
 block discarded – undo
564 564
 		</div>
565 565
 		<p class="description">
566 566
 			<?php echo $description; ?>
567
-			<a id="refresh-<?php echo esc_attr( $type ); ?>-list" class="button hide-if-no-js"><?php echo esc_html( $refresh_button ); ?></a>
567
+			<a id="refresh-<?php echo esc_attr($type); ?>-list" class="button hide-if-no-js"><?php echo esc_html($refresh_button); ?></a>
568 568
 			<span class="spinner"></span>
569
-			<span class="hide-if-js"><?php printf( esc_html_x( 'To update this list, %sre-save your login info%s.', 'placeholders are link tags to the settings page.', 'wp-to-diaspora' ), '<a href="' . admin_url( 'options-general.php?page=wp_to_diaspora' ) . '&amp;tab=setup" target="_blank">', '</a>' ); ?></span>
569
+			<span class="hide-if-js"><?php printf(esc_html_x('To update this list, %sre-save your login info%s.', 'placeholders are link tags to the settings page.', 'wp-to-diaspora'), '<a href="'.admin_url('options-general.php?page=wp_to_diaspora').'&amp;tab=setup" target="_blank">', '</a>'); ?></span>
570 570
 		</p>
571 571
 		<?php
572 572
 	}
@@ -579,20 +579,20 @@  discard block
 block discarded – undo
579 579
 	 * @param array|string $default Override default value if option not found.
580 580
 	 * @return array|string Requested option value.
581 581
 	 */
582
-	public function get_option( $option = null, $default = null ) {
583
-		if ( ! isset( self::$_options ) ) {
584
-			self::$_options = get_option( 'wp_to_diaspora_settings', self::$_default_options );
582
+	public function get_option($option = null, $default = null) {
583
+		if ( ! isset(self::$_options)) {
584
+			self::$_options = get_option('wp_to_diaspora_settings', self::$_default_options);
585 585
 		}
586
-		if ( isset( $option ) ) {
587
-			if ( isset( self::$_options[ $option ] ) ) {
586
+		if (isset($option)) {
587
+			if (isset(self::$_options[$option])) {
588 588
 				// Return found option value.
589
-				return self::$_options[ $option ];
590
-			} elseif ( isset( $default ) ) {
589
+				return self::$_options[$option];
590
+			} elseif (isset($default)) {
591 591
 				// Return overridden default value.
592 592
 				return $default;
593
-			} elseif ( isset( self::$_default_options[ $option ] ) ) {
593
+			} elseif (isset(self::$_default_options[$option])) {
594 594
 				// Return default option value.
595
-				return self::$_default_options[ $option ];
595
+				return self::$_default_options[$option];
596 596
 			}
597 597
 		}
598 598
 	}
@@ -613,15 +613,15 @@  discard block
 block discarded – undo
613 613
 	 * @param array|string $value  Value to be set for the passed option.
614 614
 	 * @param boolean      $save   Save the options immediately after setting them.
615 615
 	 */
616
-	public function set_option( $option, $value, $save = false ) {
617
-		if ( isset( $option ) ) {
618
-			if ( isset( $value ) ) {
619
-				self::$_options[ $option ] = $value;
616
+	public function set_option($option, $value, $save = false) {
617
+		if (isset($option)) {
618
+			if (isset($value)) {
619
+				self::$_options[$option] = $value;
620 620
 			} else {
621
-				unset( self::$_options[ $option ] );
621
+				unset(self::$_options[$option]);
622 622
 			}
623 623
 		}
624
-		if ( $save ) {
624
+		if ($save) {
625 625
 			self::save();
626 626
 		}
627 627
 	}
@@ -630,7 +630,7 @@  discard block
 block discarded – undo
630 630
 	 * Save the options.
631 631
 	 */
632 632
 	public function save() {
633
-		update_option( 'wp_to_diaspora_settings', self::$_options );
633
+		update_option('wp_to_diaspora_settings', self::$_options);
634 634
 	}
635 635
 
636 636
 	/**
@@ -639,9 +639,9 @@  discard block
 block discarded – undo
639 639
 	 * @param string $field Field to get the valid values for.
640 640
 	 * @return array List of valid values.
641 641
 	 */
642
-	public function get_valid_values( $field ) {
643
-		if ( array_key_exists( $field, self::$_valid_values ) ) {
644
-			return self::$_valid_values[ $field ];
642
+	public function get_valid_values($field) {
643
+		if (array_key_exists($field, self::$_valid_values)) {
644
+			return self::$_valid_values[$field];
645 645
 		}
646 646
 	}
647 647
 
@@ -652,9 +652,9 @@  discard block
 block discarded – undo
652 652
 	 * @param object $value Value to check validity.
653 653
 	 * @return boolean If the passed value is valid.
654 654
 	 */
655
-	public function is_valid_value( $field, $value ) {
656
-		if ( $valids = self::get_valid_values( $field ) ) {
657
-			return ( in_array( $value, $valids ) );
655
+	public function is_valid_value($field, $value) {
656
+		if ($valids = self::get_valid_values($field)) {
657
+			return (in_array($value, $valids));
658 658
 		}
659 659
 		return false;
660 660
 	}
@@ -665,73 +665,73 @@  discard block
 block discarded – undo
665 665
 	 * @param array $input RAW input values.
666 666
 	 * @return array Validated input values.
667 667
 	 */
668
-	public function validate_settings( $input ) {
668
+	public function validate_settings($input) {
669 669
 		/* Validate all settings before saving to the database. */
670 670
 
671 671
 		// Saving the pod setup details.
672
-		if ( isset( $input['submit_setup'] ) ) {
673
-			$input['pod']      = trim( sanitize_text_field( $input['pod'] ), ' /' );
674
-			$input['username'] = sanitize_text_field( $input['username'] );
675
-			$input['password'] = sanitize_text_field( $input['password'] );
672
+		if (isset($input['submit_setup'])) {
673
+			$input['pod']      = trim(sanitize_text_field($input['pod']), ' /');
674
+			$input['username'] = sanitize_text_field($input['username']);
675
+			$input['password'] = sanitize_text_field($input['password']);
676 676
 
677 677
 			// If password is blank, it hasn't been changed.
678 678
 			// If new password is equal to the encrypted password already saved, it was just passed again. It happens everytime update_option('wp_to_diaspora_settings') is called.
679
-			if ( '' === $input['password'] || $this->get_option( 'password' ) === $input['password'] ) {
680
-				$input['password'] = $this->get_option( 'password' );
679
+			if ('' === $input['password'] || $this->get_option('password') === $input['password']) {
680
+				$input['password'] = $this->get_option('password');
681 681
 			} else {
682
-				$input['password'] = WP2D_Helpers::encrypt( $input['password'] );
682
+				$input['password'] = WP2D_Helpers::encrypt($input['password']);
683 683
 			}
684 684
 
685 685
 			// This is for when JS in not enabled, to make sure that the aspects and services
686 686
 			// are refetched when displaying the options page after saving.
687
-			if ( isset( $input['no_js'] ) ) {
688
-				set_transient( 'wp2d_no_js_force_refetch', true );
687
+			if (isset($input['no_js'])) {
688
+				set_transient('wp2d_no_js_force_refetch', true);
689 689
 			}
690 690
 		}
691 691
 
692 692
 		// Saving the default options.
693
-		if ( isset( $input['submit_defaults'] ) ) {
694
-			if ( ! isset( $input['enabled_post_types'] ) ) {
693
+		if (isset($input['submit_defaults'])) {
694
+			if ( ! isset($input['enabled_post_types'])) {
695 695
 				$input['enabled_post_types'] = array();
696 696
 			}
697 697
 
698 698
 			// Checkboxes.
699
-			$this->validate_checkboxes( array( 'post_to_diaspora', 'fullentrylink' ), $input );
699
+			$this->validate_checkboxes(array('post_to_diaspora', 'fullentrylink'), $input);
700 700
 
701 701
 			// Single Selects.
702
-			$this->validate_single_selects( 'display', $input );
702
+			$this->validate_single_selects('display', $input);
703 703
 
704 704
 			// Multiple Selects.
705
-			$this->validate_multi_selects( 'tags_to_post', $input );
705
+			$this->validate_multi_selects('tags_to_post', $input);
706 706
 
707 707
 			// Get unique, non-empty, trimmed tags and clean them up.
708
-			$this->validate_tags( $input['global_tags'] );
708
+			$this->validate_tags($input['global_tags']);
709 709
 
710 710
 			// Clean up the list of aspects. If the list is empty, only use the 'Public' aspect.
711
-			$this->validate_aspects_services( $input['aspects'], array( 'public' ) );
711
+			$this->validate_aspects_services($input['aspects'], array('public'));
712 712
 
713 713
 			// Clean up the list of services.
714
-			$this->validate_aspects_services( $input['services'] );
714
+			$this->validate_aspects_services($input['services']);
715 715
 		}
716 716
 
717 717
 		// Reset to defaults.
718
-		if ( isset( $input['reset_defaults'] ) ) {
718
+		if (isset($input['reset_defaults'])) {
719 719
 			// Set the input to the default options.
720 720
 			$input = self::$_default_options;
721 721
 
722 722
 			// Don't reset the fetched lists of pods, aspects and services.
723
-			unset( $input['pod_list'] );
724
-			unset( $input['aspects_list'] );
725
-			unset( $input['services_list'] );
723
+			unset($input['pod_list']);
724
+			unset($input['aspects_list']);
725
+			unset($input['services_list']);
726 726
 		}
727 727
 
728 728
 		// Unset all unused input fields.
729
-		unset( $input['submit_defaults'] );
730
-		unset( $input['reset_defaults'] );
731
-		unset( $input['submit_setup'] );
729
+		unset($input['submit_defaults']);
730
+		unset($input['reset_defaults']);
731
+		unset($input['submit_setup']);
732 732
 
733 733
 		// Parse inputs with default options and return.
734
-		return wp_parse_args( $input, array_merge( self::$_default_options, self::$_options ) );
734
+		return wp_parse_args($input, array_merge(self::$_default_options, self::$_options));
735 735
 	}
736 736
 
737 737
 	/**
@@ -741,9 +741,9 @@  discard block
 block discarded – undo
741 741
 	 * @param array        $options    Options values themselves.
742 742
 	 * @return array The validated options.
743 743
 	 */
744
-	public function validate_checkboxes( $checkboxes, &$options ) {
745
-		foreach ( WP2D_Helpers::str_to_arr( $checkboxes ) as $checkbox ) {
746
-			$options[ $checkbox ] = isset( $options[ $checkbox ] );
744
+	public function validate_checkboxes($checkboxes, &$options) {
745
+		foreach (WP2D_Helpers::str_to_arr($checkboxes) as $checkbox) {
746
+			$options[$checkbox] = isset($options[$checkbox]);
747 747
 		}
748 748
 		return $options;
749 749
 	}
@@ -755,10 +755,10 @@  discard block
 block discarded – undo
755 755
 	 * @param array        $options Options values themselves.
756 756
 	 * @return array The validated options.
757 757
 	 */
758
-	public function validate_single_selects( $selects, &$options ) {
759
-		foreach ( WP2D_Helpers::str_to_arr( $selects ) as $select ) {
760
-			if ( isset( $options[ $select ] ) && ! $this->is_valid_value( $select, $options[ $select ] ) ) {
761
-				unset( $options[ $select ] );
758
+	public function validate_single_selects($selects, &$options) {
759
+		foreach (WP2D_Helpers::str_to_arr($selects) as $select) {
760
+			if (isset($options[$select]) && ! $this->is_valid_value($select, $options[$select])) {
761
+				unset($options[$select]);
762 762
 			}
763 763
 		}
764 764
 		return $options;
@@ -771,17 +771,17 @@  discard block
 block discarded – undo
771 771
 	 * @param array        $options Options values themselves.
772 772
 	 * @return array The validated options.
773 773
 	 */
774
-	public function validate_multi_selects( $selects, &$options ) {
775
-		foreach ( WP2D_Helpers::str_to_arr( $selects ) as $select ) {
776
-			if ( isset( $options[ $select ] ) ) {
777
-				foreach ( (array) $options[ $select ] as $option_value ) {
778
-					if ( ! $this->is_valid_value( $select, $option_value ) ) {
779
-						unset( $options[ $select ] );
774
+	public function validate_multi_selects($selects, &$options) {
775
+		foreach (WP2D_Helpers::str_to_arr($selects) as $select) {
776
+			if (isset($options[$select])) {
777
+				foreach ((array) $options[$select] as $option_value) {
778
+					if ( ! $this->is_valid_value($select, $option_value)) {
779
+						unset($options[$select]);
780 780
 						break;
781 781
 					}
782 782
 				}
783 783
 			} else {
784
-				$options[ $select ] = array();
784
+				$options[$select] = array();
785 785
 			}
786 786
 		}
787 787
 		return $options;
@@ -793,12 +793,12 @@  discard block
 block discarded – undo
793 793
 	 * @param array|string $tags Tags to be cleaned as array or comma seperated values.
794 794
 	 * @return array The cleaned tags.
795 795
 	 */
796
-	public function validate_tags( &$tags ) {
797
-		WP2D_Helpers::str_to_arr( $tags );
796
+	public function validate_tags(&$tags) {
797
+		WP2D_Helpers::str_to_arr($tags);
798 798
 
799
-		$tags = array_map( array( $this, 'validate_tag' ),
799
+		$tags = array_map(array($this, 'validate_tag'),
800 800
 			array_unique(
801
-				array_filter( $tags, 'trim' )
801
+				array_filter($tags, 'trim')
802 802
 			)
803 803
 		);
804 804
 		return $tags;
@@ -812,8 +812,8 @@  discard block
 block discarded – undo
812 812
 	 * @param string $tag Tag to be cleaned.
813 813
 	 * @return string The clean tag.
814 814
 	 */
815
-	public function validate_tag( &$tag ) {
816
-		$tag = preg_replace( '/[^\w $\-]/u', '', str_replace( ' ', '-', trim( $tag ) ) );
815
+	public function validate_tag(&$tag) {
816
+		$tag = preg_replace('/[^\w $\-]/u', '', str_replace(' ', '-', trim($tag)));
817 817
 		return $tag;
818 818
 	}
819 819
 
@@ -824,11 +824,11 @@  discard block
 block discarded – undo
824 824
 	 * @param array $default          Default value if not valid.
825 825
 	 * @return array The validated list of aspects or services.
826 826
 	 */
827
-	public function validate_aspects_services( &$aspects_services, $default = array() ) {
828
-		if ( empty( $aspects_services ) || ! is_array( $aspects_services ) ) {
827
+	public function validate_aspects_services(&$aspects_services, $default = array()) {
828
+		if (empty($aspects_services) || ! is_array($aspects_services)) {
829 829
 			$aspects_services = $default;
830 830
 		} else {
831
-			array_walk( $aspects_services, 'sanitize_text_field' );
831
+			array_walk($aspects_services, 'sanitize_text_field');
832 832
 		}
833 833
 		return $aspects_services;
834 834
 	}
Please login to merge, or discard this patch.
Indentation   +717 added lines, -717 removed lines patch added patch discarded remove patch
@@ -14,314 +14,314 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class WP2D_Options {
16 16
 
17
-	/**
18
-	 * Only instance of this class.
19
-	 *
20
-	 * @var WP2D_Options
21
-	 */
22
-	private static $_instance = null;
23
-
24
-	/**
25
-	 * All default plugin options.
26
-	 *
27
-	 * @var array
28
-	 */
29
-	private static $_default_options = array(
30
-		'pod_list'           => array(),
31
-		'aspects_list'       => array(),
32
-		'services_list'      => array(),
33
-		'post_to_diaspora'   => true,
34
-		'enabled_post_types' => array( 'post' ),
35
-		'fullentrylink'      => true,
36
-		'display'            => 'full',
37
-		'tags_to_post'       => array( 'global', 'custom', 'post' ),
38
-		'global_tags'        => '',
39
-		'aspects'            => array( 'public' ),
40
-		'services'           => array(),
41
-		'version'            => WP2D_VERSION,
42
-	);
43
-
44
-	/**
45
-	 * Valid values for select fields.
46
-	 *
47
-	 * @var array
48
-	 */
49
-	private static $_valid_values = array(
50
-		'display'      => array( 'full', 'excerpt' ),
51
-		'tags_to_post' => array( 'global', 'custom', 'post' ),
52
-	);
53
-
54
-	/**
55
-	 * All plugin options.
56
-	 *
57
-	 * @var array
58
-	 */
59
-	private static $_options = null;
60
-
61
-	/** Singleton, keep private. */
62
-	final private function __clone() { }
63
-
64
-	/** Singleton, keep private. */
65
-	final private function __construct() { }
66
-
67
-	/** Singleton, keep private. */
68
-	final private function __wakeup() { }
69
-
70
-	/**
71
-	 * Create / Get the instance of this class.
72
-	 *
73
-	 * @return WP2D_Options Instance of this class.
74
-	 */
75
-	public static function instance() {
76
-		if ( ! isset( self::$_instance ) ) {
77
-			self::$_instance = new self();
78
-			self::$_instance->_setup();
79
-		}
80
-		return self::$_instance;
81
-	}
82
-
83
-	/**
84
-	 * Set up the options menu.
85
-	 */
86
-	private function _setup() {
87
-
88
-		// Populate options array.
89
-		$this->get_option();
90
-
91
-		// Setup Options page and Contextual Help.
92
-		add_action( 'admin_menu', array( $this, 'setup_wpadmin_pages' ) );
93
-
94
-		// Register all settings.
95
-		add_action( 'admin_init', array( $this, 'register_settings' ) );
96
-	}
97
-
98
-
99
-	/**
100
-	 * Get the currently selected tab.
101
-	 *
102
-	 * @todo Multi-level if statement to make it look prettier.
103
-	 *
104
-	 * @param string $default Tab to select if the current selection is invalid.
105
-	 * @return string Return the currently selected tab.
106
-	 */
107
-	private function _current_tab( $default = 'defaults' ) {
108
-		$tab = ( isset ( $_GET['tab'] ) ? $_GET['tab'] : $default );
109
-
110
-		// If the pod settings aren't configured yet, open the 'Setup' tab.
111
-		if ( ! $this->is_pod_set_up() ) {
112
-			$tab = 'setup';
113
-		}
114
-
115
-		return $tab;
116
-	}
117
-
118
-	/**
119
-	 * Output all options tabs and return an array of them all, if requested by $return.
120
-	 *
121
-	 * @param bool $return Define if the options tabs should be returned.
122
-	 * @return array (If requested) An array of the outputted options tabs.
123
-	 */
124
-	private function _options_page_tabs( $return = false ) {
125
-		// The array defining all options sections to be shown as tabs.
126
-		$tabs = array();
127
-		if ( $this->is_pod_set_up() ) {
128
-			$tabs['defaults'] = __( 'Defaults', 'wp-to-diaspora' );
129
-		}
130
-
131
-		// Add the 'Setup' tab to the end of the list.
132
-		$tabs['setup'] = __( 'Setup', 'wp-to-diaspora' ) . '<span id="pod-connection-status" class="dashicons-before hidden"></span><span class="spinner"></span>';
133
-
134
-		// Container for all options tabs.
135
-		$out = '<h2 id="options-tabs" class="nav-tab-wrapper">';
136
-		foreach ( $tabs as $tab => $name ) {
137
-			// The tab link.
138
-			$out .= '<a class="nav-tab' . ( ( $tab === $this->_current_tab() ) ? ' nav-tab-active' : '' ) . '" href="?page=wp_to_diaspora&tab=' . $tab . '">' . $name . '</a>';
139
-		}
140
-		$out .= '</h2>';
141
-
142
-		// Output the container with all tabs.
143
-		echo $out;
144
-
145
-		// Check if the tabs should be returned.
146
-		if ( $return ) {
147
-			return $tabs;
148
-		}
149
-	}
150
-
151
-
152
-	/**
153
-	 * Set up admin options page.
154
-	 */
155
-	public function admin_options_page() {
156
-		?>
17
+  /**
18
+   * Only instance of this class.
19
+   *
20
+   * @var WP2D_Options
21
+   */
22
+  private static $_instance = null;
23
+
24
+  /**
25
+   * All default plugin options.
26
+   *
27
+   * @var array
28
+   */
29
+  private static $_default_options = array(
30
+    'pod_list'           => array(),
31
+    'aspects_list'       => array(),
32
+    'services_list'      => array(),
33
+    'post_to_diaspora'   => true,
34
+    'enabled_post_types' => array( 'post' ),
35
+    'fullentrylink'      => true,
36
+    'display'            => 'full',
37
+    'tags_to_post'       => array( 'global', 'custom', 'post' ),
38
+    'global_tags'        => '',
39
+    'aspects'            => array( 'public' ),
40
+    'services'           => array(),
41
+    'version'            => WP2D_VERSION,
42
+  );
43
+
44
+  /**
45
+   * Valid values for select fields.
46
+   *
47
+   * @var array
48
+   */
49
+  private static $_valid_values = array(
50
+    'display'      => array( 'full', 'excerpt' ),
51
+    'tags_to_post' => array( 'global', 'custom', 'post' ),
52
+  );
53
+
54
+  /**
55
+   * All plugin options.
56
+   *
57
+   * @var array
58
+   */
59
+  private static $_options = null;
60
+
61
+  /** Singleton, keep private. */
62
+  final private function __clone() { }
63
+
64
+  /** Singleton, keep private. */
65
+  final private function __construct() { }
66
+
67
+  /** Singleton, keep private. */
68
+  final private function __wakeup() { }
69
+
70
+  /**
71
+   * Create / Get the instance of this class.
72
+   *
73
+   * @return WP2D_Options Instance of this class.
74
+   */
75
+  public static function instance() {
76
+    if ( ! isset( self::$_instance ) ) {
77
+      self::$_instance = new self();
78
+      self::$_instance->_setup();
79
+    }
80
+    return self::$_instance;
81
+  }
82
+
83
+  /**
84
+   * Set up the options menu.
85
+   */
86
+  private function _setup() {
87
+
88
+    // Populate options array.
89
+    $this->get_option();
90
+
91
+    // Setup Options page and Contextual Help.
92
+    add_action( 'admin_menu', array( $this, 'setup_wpadmin_pages' ) );
93
+
94
+    // Register all settings.
95
+    add_action( 'admin_init', array( $this, 'register_settings' ) );
96
+  }
97
+
98
+
99
+  /**
100
+   * Get the currently selected tab.
101
+   *
102
+   * @todo Multi-level if statement to make it look prettier.
103
+   *
104
+   * @param string $default Tab to select if the current selection is invalid.
105
+   * @return string Return the currently selected tab.
106
+   */
107
+  private function _current_tab( $default = 'defaults' ) {
108
+    $tab = ( isset ( $_GET['tab'] ) ? $_GET['tab'] : $default );
109
+
110
+    // If the pod settings aren't configured yet, open the 'Setup' tab.
111
+    if ( ! $this->is_pod_set_up() ) {
112
+      $tab = 'setup';
113
+    }
114
+
115
+    return $tab;
116
+  }
117
+
118
+  /**
119
+   * Output all options tabs and return an array of them all, if requested by $return.
120
+   *
121
+   * @param bool $return Define if the options tabs should be returned.
122
+   * @return array (If requested) An array of the outputted options tabs.
123
+   */
124
+  private function _options_page_tabs( $return = false ) {
125
+    // The array defining all options sections to be shown as tabs.
126
+    $tabs = array();
127
+    if ( $this->is_pod_set_up() ) {
128
+      $tabs['defaults'] = __( 'Defaults', 'wp-to-diaspora' );
129
+    }
130
+
131
+    // Add the 'Setup' tab to the end of the list.
132
+    $tabs['setup'] = __( 'Setup', 'wp-to-diaspora' ) . '<span id="pod-connection-status" class="dashicons-before hidden"></span><span class="spinner"></span>';
133
+
134
+    // Container for all options tabs.
135
+    $out = '<h2 id="options-tabs" class="nav-tab-wrapper">';
136
+    foreach ( $tabs as $tab => $name ) {
137
+      // The tab link.
138
+      $out .= '<a class="nav-tab' . ( ( $tab === $this->_current_tab() ) ? ' nav-tab-active' : '' ) . '" href="?page=wp_to_diaspora&tab=' . $tab . '">' . $name . '</a>';
139
+    }
140
+    $out .= '</h2>';
141
+
142
+    // Output the container with all tabs.
143
+    echo $out;
144
+
145
+    // Check if the tabs should be returned.
146
+    if ( $return ) {
147
+      return $tabs;
148
+    }
149
+  }
150
+
151
+
152
+  /**
153
+   * Set up admin options page.
154
+   */
155
+  public function admin_options_page() {
156
+    ?>
157 157
 		<div class="wrap">
158 158
 			<h2>WP to diaspora*</h2>
159 159
 
160 160
 			<div id="wp2d-message" class="notice hidden" <?php echo ( defined( 'WP2D_DEBUGGING' ) ) ? ' data-debugging' : ''; ?>></div>
161 161
 
162 162
 			<?php
163
-			// Check the connection status to diaspora.
164
-			if ( ! $this->is_pod_set_up() ) {
165
-				add_settings_error(
166
-					'wp_to_diaspora_settings',
167
-					'wp_to_diaspora_connected',
168
-					__( 'First of all, set up the connection to your pod below.', 'wp-to-diaspora' ),
169
-					'updated'
170
-				);
171
-			} else {
172
-				// Get initial aspects list and connected services.
173
-				// DON'T check for empty services list here!!
174
-				// It could always be empty, resulting in this code being run every time the page is loaded.
175
-				// The aspects will at least have a "Public" entry after the initial fetch.
176
-				$aspects_list = $this->get_option( 'aspects_list' );
177
-				if ( ( $force = get_transient( 'wp2d_no_js_force_refetch' ) ) || empty( $aspects_list ) ) {
178
-
179
-					// Set up the connection to diaspora*.
180
-					$api = WP2D_Helpers::api_quick_connect();
181
-					if ( ! $api->has_last_error() ) {
182
-						// Get the loaded aspects.
183
-						if ( is_array( $aspects = $api->get_aspects() ) ) {
184
-							// Save the new list of aspects.
185
-							$this->set_option( 'aspects_list', $aspects );
186
-						}
187
-
188
-						// Get the loaded services.
189
-						if ( is_array( $services = $api->get_services() ) ) {
190
-							// Save the new list of services.
191
-							$this->set_option( 'services_list', $services );
192
-						}
193
-
194
-						$this->save();
195
-					}
196
-
197
-					if ( $force ) {
198
-						delete_transient( 'wp2d_no_js_force_refetch' );
199
-						$message = ( ! $api->has_last_error() ) ? __( 'Connection successful.', 'wp-to-diaspora' ) : $api->get_last_error();
200
-						add_settings_error(
201
-							'wp_to_diaspora_settings',
202
-							'wp_to_diaspora_connected',
203
-							$message,
204
-							( ! $api->has_last_error() ) ? 'updated' : 'error'
205
-						);
206
-					}
207
-				}
208
-
209
-				// Attempt to get the cacert.pem file and save it to the plugin's root directory.
210
-				if ( isset( $_GET['wp2d_temp_ssl_fix'] ) ) {
211
-					$cacert_file = file_get_contents( 'http://curl.haxx.se/ca/cacert.pem' );
212
-					if ( $cacert_file && file_put_contents( WP2D_DIR . '/cacert.pem', $cacert_file ) ) {
213
-						add_settings_error(
214
-							'wp_to_diaspora_settings',
215
-							'wp_to_diaspora_temp_ssl_fix',
216
-							__( 'Successfully saved cacert.pem!', 'wp-to-diaspora' ),
217
-							'updated'
218
-						);
219
-					} else {
220
-						add_settings_error(
221
-							'wp_to_diaspora_settings',
222
-							'wp_to_diaspora_temp_ssl_fix',
223
-							__( 'Failed to save cacert.pem!', 'wp-to-diaspora' ),
224
-							'error'
225
-						);
226
-					}
227
-				}
228
-			}
229
-
230
-			// Output success or error message.
231
-			settings_errors( 'wp_to_diaspora_settings' );
232
-			?>
163
+      // Check the connection status to diaspora.
164
+      if ( ! $this->is_pod_set_up() ) {
165
+        add_settings_error(
166
+          'wp_to_diaspora_settings',
167
+          'wp_to_diaspora_connected',
168
+          __( 'First of all, set up the connection to your pod below.', 'wp-to-diaspora' ),
169
+          'updated'
170
+        );
171
+      } else {
172
+        // Get initial aspects list and connected services.
173
+        // DON'T check for empty services list here!!
174
+        // It could always be empty, resulting in this code being run every time the page is loaded.
175
+        // The aspects will at least have a "Public" entry after the initial fetch.
176
+        $aspects_list = $this->get_option( 'aspects_list' );
177
+        if ( ( $force = get_transient( 'wp2d_no_js_force_refetch' ) ) || empty( $aspects_list ) ) {
178
+
179
+          // Set up the connection to diaspora*.
180
+          $api = WP2D_Helpers::api_quick_connect();
181
+          if ( ! $api->has_last_error() ) {
182
+            // Get the loaded aspects.
183
+            if ( is_array( $aspects = $api->get_aspects() ) ) {
184
+              // Save the new list of aspects.
185
+              $this->set_option( 'aspects_list', $aspects );
186
+            }
187
+
188
+            // Get the loaded services.
189
+            if ( is_array( $services = $api->get_services() ) ) {
190
+              // Save the new list of services.
191
+              $this->set_option( 'services_list', $services );
192
+            }
193
+
194
+            $this->save();
195
+          }
196
+
197
+          if ( $force ) {
198
+            delete_transient( 'wp2d_no_js_force_refetch' );
199
+            $message = ( ! $api->has_last_error() ) ? __( 'Connection successful.', 'wp-to-diaspora' ) : $api->get_last_error();
200
+            add_settings_error(
201
+              'wp_to_diaspora_settings',
202
+              'wp_to_diaspora_connected',
203
+              $message,
204
+              ( ! $api->has_last_error() ) ? 'updated' : 'error'
205
+            );
206
+          }
207
+        }
208
+
209
+        // Attempt to get the cacert.pem file and save it to the plugin's root directory.
210
+        if ( isset( $_GET['wp2d_temp_ssl_fix'] ) ) {
211
+          $cacert_file = file_get_contents( 'http://curl.haxx.se/ca/cacert.pem' );
212
+          if ( $cacert_file && file_put_contents( WP2D_DIR . '/cacert.pem', $cacert_file ) ) {
213
+            add_settings_error(
214
+              'wp_to_diaspora_settings',
215
+              'wp_to_diaspora_temp_ssl_fix',
216
+              __( 'Successfully saved cacert.pem!', 'wp-to-diaspora' ),
217
+              'updated'
218
+            );
219
+          } else {
220
+            add_settings_error(
221
+              'wp_to_diaspora_settings',
222
+              'wp_to_diaspora_temp_ssl_fix',
223
+              __( 'Failed to save cacert.pem!', 'wp-to-diaspora' ),
224
+              'error'
225
+            );
226
+          }
227
+        }
228
+      }
229
+
230
+      // Output success or error message.
231
+      settings_errors( 'wp_to_diaspora_settings' );
232
+      ?>
233 233
 
234 234
 			<?php $page_tabs = array_keys( $this->_options_page_tabs( true ) ); ?>
235 235
 
236 236
 			<form action="options.php" method="post">
237 237
 				<input id="wp2d_no_js" type="hidden" name="wp_to_diaspora_settings[no_js]" value="1">
238 238
 				<?php
239
-				// Load the settings fields.
240
-				settings_fields( 'wp_to_diaspora_settings' );
241
-				do_settings_sections( 'wp_to_diaspora_settings' );
239
+        // Load the settings fields.
240
+        settings_fields( 'wp_to_diaspora_settings' );
241
+        do_settings_sections( 'wp_to_diaspora_settings' );
242 242
 
243
-				// Get the name of the current tab, if set, else take the first one from the list.
244
-				$tab = $this->_current_tab( $page_tabs[0] );
243
+        // Get the name of the current tab, if set, else take the first one from the list.
244
+        $tab = $this->_current_tab( $page_tabs[0] );
245 245
 
246
-				// Add Save and Reset buttons.
247
-				echo '<input id="submit-' . esc_attr( $tab ) . '" name="wp_to_diaspora_settings[submit_' . esc_attr( $tab ) . ']" type="submit" class="button-primary" value="' . esc_attr__( 'Save Changes' ) . '" />&nbsp;';
248
-				if ( 'setup' !== $tab ) {
249
-					echo '<input id="reset-' . esc_attr( $tab ) . '" name="wp_to_diaspora_settings[reset_' . esc_attr( $tab ) . ']" type="submit" class="button-secondary" value="' . esc_attr__( 'Reset Defaults', 'wp-to-diaspora' ) . '" />';
250
-				}
251
-				?>
246
+        // Add Save and Reset buttons.
247
+        echo '<input id="submit-' . esc_attr( $tab ) . '" name="wp_to_diaspora_settings[submit_' . esc_attr( $tab ) . ']" type="submit" class="button-primary" value="' . esc_attr__( 'Save Changes' ) . '" />&nbsp;';
248
+        if ( 'setup' !== $tab ) {
249
+          echo '<input id="reset-' . esc_attr( $tab ) . '" name="wp_to_diaspora_settings[reset_' . esc_attr( $tab ) . ']" type="submit" class="button-secondary" value="' . esc_attr__( 'Reset Defaults', 'wp-to-diaspora' ) . '" />';
250
+        }
251
+        ?>
252 252
 
253 253
 			</form>
254 254
 		</div>
255 255
 
256 256
 		<?php
257
-	}
258
-
259
-	/**
260
-	 * Return if the settings for the pod setup have been entered.
261
-	 *
262
-	 * @return boolean If the setup for the pod has been done.
263
-	 */
264
-	public function is_pod_set_up() {
265
-		return ( $this->get_option( 'pod' ) && $this->get_option( 'username' ) && $this->get_option( 'password' ) );
266
-	}
267
-
268
-	/**
269
-	 * Setup Contextual Help and Options pages.
270
-	 */
271
-	public function setup_wpadmin_pages() {
272
-		// Add options page.
273
-		$hook = add_options_page( 'WP to diaspora*', 'WP to diaspora*', 'manage_options', 'wp_to_diaspora', array( $this, 'admin_options_page' ) );
274
-
275
-		// Setup the contextual help menu after the options page has been loaded.
276
-		add_action( 'load-' . $hook, array( 'WP2D_Contextual_Help', 'instance' ) );
277
-
278
-		// Setup the contextual help menu tab for post types. Checks are made there!
279
-		add_action( 'load-post.php', array( 'WP2D_Contextual_Help', 'instance' ) );
280
-		add_action( 'load-post-new.php', array( 'WP2D_Contextual_Help', 'instance' ) );
281
-	}
282
-
283
-	/**
284
-	 * Initialise the settings sections and fields of the currently selected tab.
285
-	 */
286
-	public function register_settings() {
287
-		// Register the settings with validation callback.
288
-		register_setting( 'wp_to_diaspora_settings', 'wp_to_diaspora_settings', array( $this, 'validate_settings' ) );
289
-
290
-		// Load only the sections of the selected tab.
291
-		switch ( $this->_current_tab() ) {
292
-			case 'defaults' :
293
-				// Add a "Defaults" section that contains all posting settings to be used by default.
294
-				add_settings_section( 'wp_to_diaspora_defaults_section', __( 'Posting Defaults', 'wp-to-diaspora' ), array( $this, 'defaults_section' ), 'wp_to_diaspora_settings' );
295
-				break;
296
-			case 'setup' :
297
-				// Add a "Setup" section that contains the Pod domain, Username and Password.
298
-				add_settings_section( 'wp_to_diaspora_setup_section', __( 'diaspora* Setup', 'wp-to-diaspora' ), array( $this, 'setup_section' ), 'wp_to_diaspora_settings' );
299
-				break;
300
-		}
301
-	}
302
-
303
-
304
-	/**
305
-	 * Callback for the "Setup" section.
306
-	 */
307
-	public function setup_section() {
308
-		esc_html_e( 'Set up the connection to your diaspora* account.', 'wp-to-diaspora' );
309
-
310
-		// Pod entry field.
311
-		add_settings_field( 'pod', __( 'Diaspora* Pod', 'wp-to-diaspora' ), array( $this, 'pod_render' ), 'wp_to_diaspora_settings', 'wp_to_diaspora_setup_section' );
312
-
313
-		// Username entry field.
314
-		add_settings_field( 'username', __( 'Username' ), array( $this, 'username_render' ), 'wp_to_diaspora_settings', 'wp_to_diaspora_setup_section' );
315
-
316
-		// Password entry field.
317
-		add_settings_field( 'password', __( 'Password' ), array( $this, 'password_render' ), 'wp_to_diaspora_settings', 'wp_to_diaspora_setup_section' );
318
-	}
319
-
320
-	/**
321
-	 * Render the "Pod" field.
322
-	 */
323
-	public function pod_render() {
324
-		?>
257
+  }
258
+
259
+  /**
260
+   * Return if the settings for the pod setup have been entered.
261
+   *
262
+   * @return boolean If the setup for the pod has been done.
263
+   */
264
+  public function is_pod_set_up() {
265
+    return ( $this->get_option( 'pod' ) && $this->get_option( 'username' ) && $this->get_option( 'password' ) );
266
+  }
267
+
268
+  /**
269
+   * Setup Contextual Help and Options pages.
270
+   */
271
+  public function setup_wpadmin_pages() {
272
+    // Add options page.
273
+    $hook = add_options_page( 'WP to diaspora*', 'WP to diaspora*', 'manage_options', 'wp_to_diaspora', array( $this, 'admin_options_page' ) );
274
+
275
+    // Setup the contextual help menu after the options page has been loaded.
276
+    add_action( 'load-' . $hook, array( 'WP2D_Contextual_Help', 'instance' ) );
277
+
278
+    // Setup the contextual help menu tab for post types. Checks are made there!
279
+    add_action( 'load-post.php', array( 'WP2D_Contextual_Help', 'instance' ) );
280
+    add_action( 'load-post-new.php', array( 'WP2D_Contextual_Help', 'instance' ) );
281
+  }
282
+
283
+  /**
284
+   * Initialise the settings sections and fields of the currently selected tab.
285
+   */
286
+  public function register_settings() {
287
+    // Register the settings with validation callback.
288
+    register_setting( 'wp_to_diaspora_settings', 'wp_to_diaspora_settings', array( $this, 'validate_settings' ) );
289
+
290
+    // Load only the sections of the selected tab.
291
+    switch ( $this->_current_tab() ) {
292
+      case 'defaults' :
293
+        // Add a "Defaults" section that contains all posting settings to be used by default.
294
+        add_settings_section( 'wp_to_diaspora_defaults_section', __( 'Posting Defaults', 'wp-to-diaspora' ), array( $this, 'defaults_section' ), 'wp_to_diaspora_settings' );
295
+        break;
296
+      case 'setup' :
297
+        // Add a "Setup" section that contains the Pod domain, Username and Password.
298
+        add_settings_section( 'wp_to_diaspora_setup_section', __( 'diaspora* Setup', 'wp-to-diaspora' ), array( $this, 'setup_section' ), 'wp_to_diaspora_settings' );
299
+        break;
300
+    }
301
+  }
302
+
303
+
304
+  /**
305
+   * Callback for the "Setup" section.
306
+   */
307
+  public function setup_section() {
308
+    esc_html_e( 'Set up the connection to your diaspora* account.', 'wp-to-diaspora' );
309
+
310
+    // Pod entry field.
311
+    add_settings_field( 'pod', __( 'Diaspora* Pod', 'wp-to-diaspora' ), array( $this, 'pod_render' ), 'wp_to_diaspora_settings', 'wp_to_diaspora_setup_section' );
312
+
313
+    // Username entry field.
314
+    add_settings_field( 'username', __( 'Username' ), array( $this, 'username_render' ), 'wp_to_diaspora_settings', 'wp_to_diaspora_setup_section' );
315
+
316
+    // Password entry field.
317
+    add_settings_field( 'password', __( 'Password' ), array( $this, 'password_render' ), 'wp_to_diaspora_settings', 'wp_to_diaspora_setup_section' );
318
+  }
319
+
320
+  /**
321
+   * Render the "Pod" field.
322
+   */
323
+  public function pod_render() {
324
+    ?>
325 325
 		https://<input type="text" name="wp_to_diaspora_settings[pod]" value="<?php echo esc_attr( $this->get_option( 'pod' ) ); ?>" placeholder="e.g. joindiaspora.com" autocomplete="on" list="pod-list" required> <a id="refresh-pod-list" class="button hide-if-no-js"><?php esc_html_e( 'Refresh pod list', 'wp-to-diaspora' ); ?></a><span class="spinner"></span>
326 326
 		<datalist id="pod-list">
327 327
 		<?php foreach ( (array) $this->get_option( 'pod_list' ) as $pod ) : ?>
@@ -329,76 +329,76 @@  discard block
 block discarded – undo
329 329
 		<?php endforeach; ?>
330 330
 		</datalist>
331 331
 		<?php
332
-	}
332
+  }
333 333
 
334
-	/**
335
-	 * Render the "Username" field.
336
-	 */
337
-	public function username_render() {
338
-		?>
334
+  /**
335
+   * Render the "Username" field.
336
+   */
337
+  public function username_render() {
338
+    ?>
339 339
 		<input type="text" name="wp_to_diaspora_settings[username]" value="<?php echo esc_attr( $this->get_option( 'username' ) ); ?>" placeholder="<?php esc_attr_e( 'Username' ); ?>" required>
340 340
 		<?php
341
-	}
342
-
343
-	/**
344
-	 * Render the "Password" field.
345
-	 */
346
-	public function password_render() {
347
-		// Special case if we already have a password.
348
-		$has_password = ( '' !== $this->get_option( 'password', '' ) );
349
-		$placeholder  = ( $has_password ) ? __( 'Password already set.', 'wp-to-diaspora' ) : __( 'Password' );
350
-		$required     = ( $has_password ) ? '' : ' required';
351
-		?>
341
+  }
342
+
343
+  /**
344
+   * Render the "Password" field.
345
+   */
346
+  public function password_render() {
347
+    // Special case if we already have a password.
348
+    $has_password = ( '' !== $this->get_option( 'password', '' ) );
349
+    $placeholder  = ( $has_password ) ? __( 'Password already set.', 'wp-to-diaspora' ) : __( 'Password' );
350
+    $required     = ( $has_password ) ? '' : ' required';
351
+    ?>
352 352
 		<input type="password" name="wp_to_diaspora_settings[password]" value="" placeholder="<?php echo esc_attr( $placeholder ); ?>"<?php echo esc_attr( $required ); ?>>
353 353
 		<?php if ( $has_password ) : ?>
354 354
 			<p class="description"><?php esc_html_e( 'If you would like to change the password type a new one. Otherwise leave this blank.', 'wp-to-diaspora' ); ?></p>
355 355
 		<?php endif;
356
-	}
356
+  }
357 357
 
358 358
 
359
-	/**
360
-	 * Callback for the "Defaults" section.
361
-	 */
362
-	public function defaults_section() {
363
-		esc_html_e( 'Define the default posting behaviour for all posts here. These settings can be modified for each post individually, by changing the values in the "WP to diaspora*" meta box, which gets displayed in your post edit screen.', 'wp-to-diaspora' );
359
+  /**
360
+   * Callback for the "Defaults" section.
361
+   */
362
+  public function defaults_section() {
363
+    esc_html_e( 'Define the default posting behaviour for all posts here. These settings can be modified for each post individually, by changing the values in the "WP to diaspora*" meta box, which gets displayed in your post edit screen.', 'wp-to-diaspora' );
364 364
 
365
-		// Post types field.
366
-		add_settings_field( 'enabled_post_types', __( 'Post types', 'wp-to-diaspora' ), array( $this, 'post_types_render' ), 'wp_to_diaspora_settings', 'wp_to_diaspora_defaults_section' );
365
+    // Post types field.
366
+    add_settings_field( 'enabled_post_types', __( 'Post types', 'wp-to-diaspora' ), array( $this, 'post_types_render' ), 'wp_to_diaspora_settings', 'wp_to_diaspora_defaults_section' );
367 367
 
368
-		 // Post to diaspora* checkbox.
369
-		add_settings_field( 'post_to_diaspora', __( 'Post to diaspora*', 'wp-to-diaspora' ), array( $this, 'post_to_diaspora_render' ), 'wp_to_diaspora_settings', 'wp_to_diaspora_defaults_section', $this->get_option( 'post_to_diaspora' ) );
368
+      // Post to diaspora* checkbox.
369
+    add_settings_field( 'post_to_diaspora', __( 'Post to diaspora*', 'wp-to-diaspora' ), array( $this, 'post_to_diaspora_render' ), 'wp_to_diaspora_settings', 'wp_to_diaspora_defaults_section', $this->get_option( 'post_to_diaspora' ) );
370 370
 
371
-		// Full entry link checkbox.
372
-		add_settings_field( 'fullentrylink', __( 'Show "Posted at" link?', 'wp-to-diaspora' ), array( $this, 'fullentrylink_render' ), 'wp_to_diaspora_settings', 'wp_to_diaspora_defaults_section', $this->get_option( 'fullentrylink' ) );
371
+    // Full entry link checkbox.
372
+    add_settings_field( 'fullentrylink', __( 'Show "Posted at" link?', 'wp-to-diaspora' ), array( $this, 'fullentrylink_render' ), 'wp_to_diaspora_settings', 'wp_to_diaspora_defaults_section', $this->get_option( 'fullentrylink' ) );
373 373
 
374
-		// Full text or excerpt radio buttons.
375
-		add_settings_field( 'display', __( 'Display', 'wp-to-diaspora' ), array( $this, 'display_render' ), 'wp_to_diaspora_settings', 'wp_to_diaspora_defaults_section', $this->get_option( 'display' ) );
374
+    // Full text or excerpt radio buttons.
375
+    add_settings_field( 'display', __( 'Display', 'wp-to-diaspora' ), array( $this, 'display_render' ), 'wp_to_diaspora_settings', 'wp_to_diaspora_defaults_section', $this->get_option( 'display' ) );
376 376
 
377
-		// Tags to post dropdown.
378
-		add_settings_field( 'tags_to_post', __( 'Tags to post', 'wp-to-diaspora' ), array( $this, 'tags_to_post_render' ), 'wp_to_diaspora_settings', 'wp_to_diaspora_defaults_section', $this->get_option( 'tags_to_post', 'gc' ) );
377
+    // Tags to post dropdown.
378
+    add_settings_field( 'tags_to_post', __( 'Tags to post', 'wp-to-diaspora' ), array( $this, 'tags_to_post_render' ), 'wp_to_diaspora_settings', 'wp_to_diaspora_defaults_section', $this->get_option( 'tags_to_post', 'gc' ) );
379 379
 
380
-		// Global tags field.
381
-		add_settings_field( 'global_tags', __( 'Global tags', 'wp-to-diaspora' ), array( $this, 'global_tags_render' ), 'wp_to_diaspora_settings', 'wp_to_diaspora_defaults_section', $this->get_option( 'global_tags' ) );
380
+    // Global tags field.
381
+    add_settings_field( 'global_tags', __( 'Global tags', 'wp-to-diaspora' ), array( $this, 'global_tags_render' ), 'wp_to_diaspora_settings', 'wp_to_diaspora_defaults_section', $this->get_option( 'global_tags' ) );
382 382
 
383
-		// Aspects checkboxes.
384
-		add_settings_field( 'aspects', __( 'Aspects', 'wp-to-diaspora' ), array( $this, 'aspects_services_render' ), 'wp_to_diaspora_settings', 'wp_to_diaspora_defaults_section', array( 'aspects', $this->get_option( 'aspects' ) ) );
383
+    // Aspects checkboxes.
384
+    add_settings_field( 'aspects', __( 'Aspects', 'wp-to-diaspora' ), array( $this, 'aspects_services_render' ), 'wp_to_diaspora_settings', 'wp_to_diaspora_defaults_section', array( 'aspects', $this->get_option( 'aspects' ) ) );
385 385
 
386
-		// Services checkboxes.
387
-		add_settings_field( 'services', __( 'Services', 'wp-to-diaspora' ), array( $this, 'aspects_services_render' ), 'wp_to_diaspora_settings', 'wp_to_diaspora_defaults_section', array( 'services', $this->get_option( 'services' ) ) );
388
-	}
386
+    // Services checkboxes.
387
+    add_settings_field( 'services', __( 'Services', 'wp-to-diaspora' ), array( $this, 'aspects_services_render' ), 'wp_to_diaspora_settings', 'wp_to_diaspora_defaults_section', array( 'services', $this->get_option( 'services' ) ) );
388
+  }
389 389
 
390
-	/**
391
-	 * Render the "Post types" checkboxes.
392
-	 */
393
-	public function post_types_render() {
394
-		$post_types = get_post_types( array( 'public' => true ), 'objects' );
390
+  /**
391
+   * Render the "Post types" checkboxes.
392
+   */
393
+  public function post_types_render() {
394
+    $post_types = get_post_types( array( 'public' => true ), 'objects' );
395 395
 
396
-		// Remove excluded post types from the list.
397
-		$excluded_post_types = array( 'attachment', 'nav_menu_item', 'revision' );
398
-		foreach ( $excluded_post_types as $excluded ) {
399
-			unset( $post_types[ $excluded ] );
400
-		}
401
-		?>
396
+    // Remove excluded post types from the list.
397
+    $excluded_post_types = array( 'attachment', 'nav_menu_item', 'revision' );
398
+    foreach ( $excluded_post_types as $excluded ) {
399
+      unset( $post_types[ $excluded ] );
400
+    }
401
+    ?>
402 402
 
403 403
 		<select id="enabled-post-types" multiple data-placeholder="<?php esc_attr_e( 'None', 'wp-to-diaspora' ); ?>" class="chosen" name="wp_to_diaspora_settings[enabled_post_types][]">
404 404
 		<?php foreach ( $post_types as $post_type ) : ?>
@@ -409,63 +409,63 @@  discard block
 block discarded – undo
409 409
 		<p class="description"><?php esc_html_e( 'Choose which post types can be posted to diaspora*.', 'wp-to-diaspora' ); ?></p>
410 410
 
411 411
 		<?php
412
-	}
413
-
414
-	/**
415
-	 * Render the "Post to diaspora*" checkbox.
416
-	 *
417
-	 * @param bool $post_to_diaspora If this checkbox is checked or not.
418
-	 */
419
-	public function post_to_diaspora_render( $post_to_diaspora ) {
420
-		$label = ( 'settings_page_wp_to_diaspora' === get_current_screen()->id ) ? __( 'Yes' ) : __( 'Post to diaspora*', 'wp-to-diaspora' );
421
-		?>
412
+  }
413
+
414
+  /**
415
+   * Render the "Post to diaspora*" checkbox.
416
+   *
417
+   * @param bool $post_to_diaspora If this checkbox is checked or not.
418
+   */
419
+  public function post_to_diaspora_render( $post_to_diaspora ) {
420
+    $label = ( 'settings_page_wp_to_diaspora' === get_current_screen()->id ) ? __( 'Yes' ) : __( 'Post to diaspora*', 'wp-to-diaspora' );
421
+    ?>
422 422
 		<label><input type="checkbox" id="post-to-diaspora" name="wp_to_diaspora_settings[post_to_diaspora]" value="1" <?php checked( $post_to_diaspora ); ?>><?php echo esc_html( $label ); ?></label>
423 423
 		<?php
424
-	}
425
-
426
-	/**
427
-	 * Render the "Show 'Posted at' link" checkbox.
428
-	 *
429
-	 * @param bool $show_link If the checkbox is checked or not.
430
-	 */
431
-	public function fullentrylink_render( $show_link ) {
432
-		$description = __( 'Include a link back to your original post.', 'wp-to-diaspora' );
433
-		$checkbox = '<input type="checkbox" id="fullentrylink" name="wp_to_diaspora_settings[fullentrylink]" value="1"' . checked( $show_link, true, false ) . '>';
434
-
435
-		if ( 'settings_page_wp_to_diaspora' === get_current_screen()->id ) : ?>
424
+  }
425
+
426
+  /**
427
+   * Render the "Show 'Posted at' link" checkbox.
428
+   *
429
+   * @param bool $show_link If the checkbox is checked or not.
430
+   */
431
+  public function fullentrylink_render( $show_link ) {
432
+    $description = __( 'Include a link back to your original post.', 'wp-to-diaspora' );
433
+    $checkbox = '<input type="checkbox" id="fullentrylink" name="wp_to_diaspora_settings[fullentrylink]" value="1"' . checked( $show_link, true, false ) . '>';
434
+
435
+    if ( 'settings_page_wp_to_diaspora' === get_current_screen()->id ) : ?>
436 436
 			<label><?php echo $checkbox; ?><?php esc_html_e( 'Yes' ); ?></label>
437 437
 			<p class="description"><?php echo esc_html( $description ); ?></p>
438 438
 		<?php else : ?>
439 439
 			<label title="<?php echo esc_attr( $description ); ?>"><?php echo $checkbox; ?><?php esc_html_e( 'Show "Posted at" link?', 'wp-to-diaspora' ); ?></label>
440 440
 		<?php endif;
441
-	}
442
-
443
-	/**
444
-	 * Render the "Display" radio buttons.
445
-	 *
446
-	 * @param string $display The selected radio button.
447
-	 */
448
-	public function display_render( $display ) {
449
-		?>
441
+  }
442
+
443
+  /**
444
+   * Render the "Display" radio buttons.
445
+   *
446
+   * @param string $display The selected radio button.
447
+   */
448
+  public function display_render( $display ) {
449
+    ?>
450 450
 		<label><input type="radio" name="wp_to_diaspora_settings[display]" value="full" <?php checked( $display, 'full' ); ?>><?php esc_html_e( 'Full Post', 'wp-to-diaspora' ); ?></label><br />
451 451
 		<label><input type="radio" name="wp_to_diaspora_settings[display]" value="excerpt" <?php checked( $display, 'excerpt' ); ?>><?php esc_html_e( 'Excerpt' ); ?></label>
452 452
 		<?php
453
-	}
454
-
455
-	/**
456
-	 * Render the "Tags to post" field.
457
-	 *
458
-	 * @param array $tags_to_post The types of tags to be posted.
459
-	 */
460
-	public function tags_to_post_render( $tags_to_post ) {
461
-		$on_settings_page = ( 'settings_page_wp_to_diaspora' === get_current_screen()->id );
462
-		$description = esc_html__( 'Choose which tags should be posted to diaspora*.', 'wp-to-diaspora' );
463
-
464
-		if ( ! $on_settings_page ) {
465
-			echo '<label>' . esc_html( $description );
466
-		}
467
-
468
-		?>
453
+  }
454
+
455
+  /**
456
+   * Render the "Tags to post" field.
457
+   *
458
+   * @param array $tags_to_post The types of tags to be posted.
459
+   */
460
+  public function tags_to_post_render( $tags_to_post ) {
461
+    $on_settings_page = ( 'settings_page_wp_to_diaspora' === get_current_screen()->id );
462
+    $description = esc_html__( 'Choose which tags should be posted to diaspora*.', 'wp-to-diaspora' );
463
+
464
+    if ( ! $on_settings_page ) {
465
+      echo '<label>' . esc_html( $description );
466
+    }
467
+
468
+    ?>
469 469
 		<select id="tags-to-post" multiple data-placeholder="<?php esc_attr_e( 'No tags', 'wp-to-diaspora' ); ?>" class="chosen" name="wp_to_diaspora_settings[tags_to_post][]">
470 470
 			<option value="global" <?php selected( in_array( 'global', $tags_to_post ) ); ?>><?php esc_html_e( 'Global tags', 'wp-to-diaspora' ); ?></option>
471 471
 			<option value="custom" <?php selected( in_array( 'custom', $tags_to_post ) ); ?>><?php esc_html_e( 'Custom tags', 'wp-to-diaspora' ); ?></option>
@@ -477,82 +477,82 @@  discard block
 block discarded – undo
477 477
 		<?php else : ?>
478 478
 			</label>
479 479
 		<?php endif;
480
-	}
481
-
482
-	/**
483
-	 * Render the "Global tags" field.
484
-	 *
485
-	 * @param array $tags The global tags to be posted.
486
-	 */
487
-	public function global_tags_render( $tags ) {
488
-		WP2D_Helpers::arr_to_str( $tags );
489
-		?>
480
+  }
481
+
482
+  /**
483
+   * Render the "Global tags" field.
484
+   *
485
+   * @param array $tags The global tags to be posted.
486
+   */
487
+  public function global_tags_render( $tags ) {
488
+    WP2D_Helpers::arr_to_str( $tags );
489
+    ?>
490 490
 		<input type="text" class="wp2dtags" name="wp_to_diaspora_settings[global_tags]" value="<?php echo esc_attr( $tags ); ?>" placeholder="<?php esc_attr_e( 'Global tags', 'wp-to-diaspora' ); ?>" class="regular-text">
491 491
 		<p class="description"><?php esc_html_e( 'Custom tags to add to all posts being posted to diaspora*.', 'wp-to-diaspora' ); ?></p>
492 492
 		<?php
493
-	}
494
-
495
-	/**
496
-	 * Render the "Custom tags" field.
497
-	 *
498
-	 * @param array $tags The custom tags to be posted.
499
-	 */
500
-	public function custom_tags_render( $tags ) {
501
-		WP2D_Helpers::arr_to_str( $tags );
502
-		?>
493
+  }
494
+
495
+  /**
496
+   * Render the "Custom tags" field.
497
+   *
498
+   * @param array $tags The custom tags to be posted.
499
+   */
500
+  public function custom_tags_render( $tags ) {
501
+    WP2D_Helpers::arr_to_str( $tags );
502
+    ?>
503 503
 		<label title="<?php esc_attr_e( 'Custom tags to add to this post when it\'s posted to diaspora*.', 'wp-to-diaspora' ); ?>">
504 504
 			<?php esc_html_e( 'Custom tags', 'wp-to-diaspora' ); ?>
505 505
 			<input type="text" class="wp2dtags" name="wp_to_diaspora_settings[custom_tags]" value="<?php echo esc_attr( $tags ); ?>" class="widefat">
506 506
 		</label>
507 507
 		<p class="description"><?php esc_html_e( 'Separate tags with commas' ); ?></p>
508 508
 		<?php
509
-	}
510
-
511
-	/**
512
-	 * Render the "Aspects" and "Services" checkboxes.
513
-	 *
514
-	 * @param array $args Array containing the type and items to output as checkboxes.
515
-	 */
516
-	public function aspects_services_render( $args ) {
517
-		list( $type, $items ) = $args;
518
-
519
-		$refresh_button = '';
520
-		$description    = '';
521
-		$empty_label    = '';
522
-
523
-		// This is where the 2 types show their differences.
524
-		switch ( $type ) {
525
-			case 'aspects':
526
-				$refresh_button = __( 'Refresh Aspects', 'wp-to-diaspora' );
527
-				$description    = esc_html__( 'Choose which aspects to share to.', 'wp-to-diaspora' );
528
-				$empty_label    = '<input type="checkbox" name="wp_to_diaspora_settings[aspects][]" value="public" checked="checked">' . esc_html__( 'Public' );
529
-				break;
530
-
531
-			case 'services':
532
-				$refresh_button = __( 'Refresh Services', 'wp-to-diaspora' );
533
-				$description    = sprintf( '%1$s<br><a href="%2$s" target="_blank">%3$s</a>',
534
-					esc_html__( 'Choose which services to share to.', 'wp-to-diaspora' ),
535
-					esc_url( 'https://' . $this->get_option( 'pod' ) . '/services' ),
536
-					esc_html__( 'Show available services on my pod.', 'wp-to-diaspora' )
537
-				);
538
-				$empty_label    = esc_html__( 'No services connected yet.', 'wp-to-diaspora' );
539
-				break;
540
-
541
-			default:
542
-				return;
543
-		}
544
-
545
-		$items = array_filter( (array) $items ) ?: array();
546
-
547
-		// Special case for this field if it's displayed on the settings page.
548
-		$on_settings_page = ( 'settings_page_wp_to_diaspora' === get_current_screen()->id );
549
-
550
-		if ( ! $on_settings_page ) {
551
-			echo $description;
552
-			$description = '';
553
-		}
554
-
555
-		?>
509
+  }
510
+
511
+  /**
512
+   * Render the "Aspects" and "Services" checkboxes.
513
+   *
514
+   * @param array $args Array containing the type and items to output as checkboxes.
515
+   */
516
+  public function aspects_services_render( $args ) {
517
+    list( $type, $items ) = $args;
518
+
519
+    $refresh_button = '';
520
+    $description    = '';
521
+    $empty_label    = '';
522
+
523
+    // This is where the 2 types show their differences.
524
+    switch ( $type ) {
525
+      case 'aspects':
526
+        $refresh_button = __( 'Refresh Aspects', 'wp-to-diaspora' );
527
+        $description    = esc_html__( 'Choose which aspects to share to.', 'wp-to-diaspora' );
528
+        $empty_label    = '<input type="checkbox" name="wp_to_diaspora_settings[aspects][]" value="public" checked="checked">' . esc_html__( 'Public' );
529
+        break;
530
+
531
+      case 'services':
532
+        $refresh_button = __( 'Refresh Services', 'wp-to-diaspora' );
533
+        $description    = sprintf( '%1$s<br><a href="%2$s" target="_blank">%3$s</a>',
534
+          esc_html__( 'Choose which services to share to.', 'wp-to-diaspora' ),
535
+          esc_url( 'https://' . $this->get_option( 'pod' ) . '/services' ),
536
+          esc_html__( 'Show available services on my pod.', 'wp-to-diaspora' )
537
+        );
538
+        $empty_label    = esc_html__( 'No services connected yet.', 'wp-to-diaspora' );
539
+        break;
540
+
541
+      default:
542
+        return;
543
+    }
544
+
545
+    $items = array_filter( (array) $items ) ?: array();
546
+
547
+    // Special case for this field if it's displayed on the settings page.
548
+    $on_settings_page = ( 'settings_page_wp_to_diaspora' === get_current_screen()->id );
549
+
550
+    if ( ! $on_settings_page ) {
551
+      echo $description;
552
+      $description = '';
553
+    }
554
+
555
+    ?>
556 556
 		<div id="<?php echo esc_attr( $type ); ?>-container" data-<?php echo esc_attr( $type ); ?>-selected="<?php echo esc_attr( implode( ',', $items ) ); ?>">
557 557
 			<?php if ( $list = (array) $this->get_option( $type . '_list' ) ) : ?>
558 558
 				<?php foreach ( $list as $id => $name ) : ?>
@@ -569,267 +569,267 @@  discard block
 block discarded – undo
569 569
 			<span class="hide-if-js"><?php printf( esc_html_x( 'To update this list, %sre-save your login info%s.', 'placeholders are link tags to the settings page.', 'wp-to-diaspora' ), '<a href="' . admin_url( 'options-general.php?page=wp_to_diaspora' ) . '&amp;tab=setup" target="_blank">', '</a>' ); ?></span>
570 570
 		</p>
571 571
 		<?php
572
-	}
573
-
574
-
575
-	/**
576
-	 * Get a specific option.
577
-	 *
578
-	 * @param string       $option  ID of option to get.
579
-	 * @param array|string $default Override default value if option not found.
580
-	 * @return array|string Requested option value.
581
-	 */
582
-	public function get_option( $option = null, $default = null ) {
583
-		if ( ! isset( self::$_options ) ) {
584
-			self::$_options = get_option( 'wp_to_diaspora_settings', self::$_default_options );
585
-		}
586
-		if ( isset( $option ) ) {
587
-			if ( isset( self::$_options[ $option ] ) ) {
588
-				// Return found option value.
589
-				return self::$_options[ $option ];
590
-			} elseif ( isset( $default ) ) {
591
-				// Return overridden default value.
592
-				return $default;
593
-			} elseif ( isset( self::$_default_options[ $option ] ) ) {
594
-				// Return default option value.
595
-				return self::$_default_options[ $option ];
596
-			}
597
-		}
598
-	}
599
-
600
-	/**
601
-	 * Get all options.
602
-	 *
603
-	 * @return array All the options.
604
-	 */
605
-	public function get_options() {
606
-		return self::$_options;
607
-	}
608
-
609
-	/**
610
-	 * Set a certain option.
611
-	 *
612
-	 * @param string       $option ID of option to get.
613
-	 * @param array|string $value  Value to be set for the passed option.
614
-	 * @param boolean      $save   Save the options immediately after setting them.
615
-	 */
616
-	public function set_option( $option, $value, $save = false ) {
617
-		if ( isset( $option ) ) {
618
-			if ( isset( $value ) ) {
619
-				self::$_options[ $option ] = $value;
620
-			} else {
621
-				unset( self::$_options[ $option ] );
622
-			}
623
-		}
624
-		if ( $save ) {
625
-			self::save();
626
-		}
627
-	}
628
-
629
-	/**
630
-	 * Save the options.
631
-	 */
632
-	public function save() {
633
-		update_option( 'wp_to_diaspora_settings', self::$_options );
634
-	}
635
-
636
-	/**
637
-	 * Get all valid input values for the passed field.
638
-	 *
639
-	 * @param string $field Field to get the valid values for.
640
-	 * @return array List of valid values.
641
-	 */
642
-	public function get_valid_values( $field ) {
643
-		if ( array_key_exists( $field, self::$_valid_values ) ) {
644
-			return self::$_valid_values[ $field ];
645
-		}
646
-	}
647
-
648
-	/**
649
-	 * Check if a value is valid for the passed field.
650
-	 *
651
-	 * @param string $field Field to check the valid value for.
652
-	 * @param object $value Value to check validity.
653
-	 * @return boolean If the passed value is valid.
654
-	 */
655
-	public function is_valid_value( $field, $value ) {
656
-		if ( $valids = self::get_valid_values( $field ) ) {
657
-			return ( in_array( $value, $valids ) );
658
-		}
659
-		return false;
660
-	}
661
-
662
-	/**
663
-	 * Validate all settings.
664
-	 *
665
-	 * @param array $input RAW input values.
666
-	 * @return array Validated input values.
667
-	 */
668
-	public function validate_settings( $input ) {
669
-		/* Validate all settings before saving to the database. */
670
-
671
-		// Saving the pod setup details.
672
-		if ( isset( $input['submit_setup'] ) ) {
673
-			$input['pod']      = trim( sanitize_text_field( $input['pod'] ), ' /' );
674
-			$input['username'] = sanitize_text_field( $input['username'] );
675
-			$input['password'] = sanitize_text_field( $input['password'] );
676
-
677
-			// If password is blank, it hasn't been changed.
678
-			// If new password is equal to the encrypted password already saved, it was just passed again. It happens everytime update_option('wp_to_diaspora_settings') is called.
679
-			if ( '' === $input['password'] || $this->get_option( 'password' ) === $input['password'] ) {
680
-				$input['password'] = $this->get_option( 'password' );
681
-			} else {
682
-				$input['password'] = WP2D_Helpers::encrypt( $input['password'] );
683
-			}
684
-
685
-			// This is for when JS in not enabled, to make sure that the aspects and services
686
-			// are refetched when displaying the options page after saving.
687
-			if ( isset( $input['no_js'] ) ) {
688
-				set_transient( 'wp2d_no_js_force_refetch', true );
689
-			}
690
-		}
691
-
692
-		// Saving the default options.
693
-		if ( isset( $input['submit_defaults'] ) ) {
694
-			if ( ! isset( $input['enabled_post_types'] ) ) {
695
-				$input['enabled_post_types'] = array();
696
-			}
697
-
698
-			// Checkboxes.
699
-			$this->validate_checkboxes( array( 'post_to_diaspora', 'fullentrylink' ), $input );
700
-
701
-			// Single Selects.
702
-			$this->validate_single_selects( 'display', $input );
703
-
704
-			// Multiple Selects.
705
-			$this->validate_multi_selects( 'tags_to_post', $input );
706
-
707
-			// Get unique, non-empty, trimmed tags and clean them up.
708
-			$this->validate_tags( $input['global_tags'] );
709
-
710
-			// Clean up the list of aspects. If the list is empty, only use the 'Public' aspect.
711
-			$this->validate_aspects_services( $input['aspects'], array( 'public' ) );
712
-
713
-			// Clean up the list of services.
714
-			$this->validate_aspects_services( $input['services'] );
715
-		}
716
-
717
-		// Reset to defaults.
718
-		if ( isset( $input['reset_defaults'] ) ) {
719
-			// Set the input to the default options.
720
-			$input = self::$_default_options;
721
-
722
-			// Don't reset the fetched lists of pods, aspects and services.
723
-			unset( $input['pod_list'] );
724
-			unset( $input['aspects_list'] );
725
-			unset( $input['services_list'] );
726
-		}
727
-
728
-		// Unset all unused input fields.
729
-		unset( $input['submit_defaults'] );
730
-		unset( $input['reset_defaults'] );
731
-		unset( $input['submit_setup'] );
732
-
733
-		// Parse inputs with default options and return.
734
-		return wp_parse_args( $input, array_merge( self::$_default_options, self::$_options ) );
735
-	}
736
-
737
-	/**
738
-	 * Validate checkboxes, make them either true or false.
739
-	 *
740
-	 * @param string|array $checkboxes Checkboxes to validate.
741
-	 * @param array        $options    Options values themselves.
742
-	 * @return array The validated options.
743
-	 */
744
-	public function validate_checkboxes( $checkboxes, &$options ) {
745
-		foreach ( WP2D_Helpers::str_to_arr( $checkboxes ) as $checkbox ) {
746
-			$options[ $checkbox ] = isset( $options[ $checkbox ] );
747
-		}
748
-		return $options;
749
-	}
750
-
751
-	/**
752
-	 * Validate single-select fields and make sure their selected value are valid.
753
-	 *
754
-	 * @param string|array $selects Name(s) of the select fields.
755
-	 * @param array        $options Options values themselves.
756
-	 * @return array The validated options.
757
-	 */
758
-	public function validate_single_selects( $selects, &$options ) {
759
-		foreach ( WP2D_Helpers::str_to_arr( $selects ) as $select ) {
760
-			if ( isset( $options[ $select ] ) && ! $this->is_valid_value( $select, $options[ $select ] ) ) {
761
-				unset( $options[ $select ] );
762
-			}
763
-		}
764
-		return $options;
765
-	}
766
-
767
-	/**
768
-	 * Validate multi-select fields and make sure their selected values are valid.
769
-	 *
770
-	 * @param string|array $selects Name(s) of the select fields.
771
-	 * @param array        $options Options values themselves.
772
-	 * @return array The validated options.
773
-	 */
774
-	public function validate_multi_selects( $selects, &$options ) {
775
-		foreach ( WP2D_Helpers::str_to_arr( $selects ) as $select ) {
776
-			if ( isset( $options[ $select ] ) ) {
777
-				foreach ( (array) $options[ $select ] as $option_value ) {
778
-					if ( ! $this->is_valid_value( $select, $option_value ) ) {
779
-						unset( $options[ $select ] );
780
-						break;
781
-					}
782
-				}
783
-			} else {
784
-				$options[ $select ] = array();
785
-			}
786
-		}
787
-		return $options;
788
-	}
789
-
790
-	/**
791
-	 * Clean up the passed tags. Keep only alphanumeric, hyphen and underscore characters.
792
-	 *
793
-	 * @param array|string $tags Tags to be cleaned as array or comma seperated values.
794
-	 * @return array The cleaned tags.
795
-	 */
796
-	public function validate_tags( &$tags ) {
797
-		WP2D_Helpers::str_to_arr( $tags );
798
-
799
-		$tags = array_map( array( $this, 'validate_tag' ),
800
-			array_unique(
801
-				array_filter( $tags, 'trim' )
802
-			)
803
-		);
804
-		return $tags;
805
-	}
806
-
807
-	/**
808
-	 * Clean up the passed tag. Keep only alphanumeric, hyphen and underscore characters.
809
-	 *
810
-	 * @todo What about eastern characters? (chinese, indian, etc.)
811
-	 *
812
-	 * @param string $tag Tag to be cleaned.
813
-	 * @return string The clean tag.
814
-	 */
815
-	public function validate_tag( &$tag ) {
816
-		$tag = preg_replace( '/[^\w $\-]/u', '', str_replace( ' ', '-', trim( $tag ) ) );
817
-		return $tag;
818
-	}
819
-
820
-	/**
821
-	 * Validate the passed aspects or services.
822
-	 *
823
-	 * @param array $aspects_services List of aspects or services that need to be validated.
824
-	 * @param array $default          Default value if not valid.
825
-	 * @return array The validated list of aspects or services.
826
-	 */
827
-	public function validate_aspects_services( &$aspects_services, $default = array() ) {
828
-		if ( empty( $aspects_services ) || ! is_array( $aspects_services ) ) {
829
-			$aspects_services = $default;
830
-		} else {
831
-			array_walk( $aspects_services, 'sanitize_text_field' );
832
-		}
833
-		return $aspects_services;
834
-	}
572
+  }
573
+
574
+
575
+  /**
576
+   * Get a specific option.
577
+   *
578
+   * @param string       $option  ID of option to get.
579
+   * @param array|string $default Override default value if option not found.
580
+   * @return array|string Requested option value.
581
+   */
582
+  public function get_option( $option = null, $default = null ) {
583
+    if ( ! isset( self::$_options ) ) {
584
+      self::$_options = get_option( 'wp_to_diaspora_settings', self::$_default_options );
585
+    }
586
+    if ( isset( $option ) ) {
587
+      if ( isset( self::$_options[ $option ] ) ) {
588
+        // Return found option value.
589
+        return self::$_options[ $option ];
590
+      } elseif ( isset( $default ) ) {
591
+        // Return overridden default value.
592
+        return $default;
593
+      } elseif ( isset( self::$_default_options[ $option ] ) ) {
594
+        // Return default option value.
595
+        return self::$_default_options[ $option ];
596
+      }
597
+    }
598
+  }
599
+
600
+  /**
601
+   * Get all options.
602
+   *
603
+   * @return array All the options.
604
+   */
605
+  public function get_options() {
606
+    return self::$_options;
607
+  }
608
+
609
+  /**
610
+   * Set a certain option.
611
+   *
612
+   * @param string       $option ID of option to get.
613
+   * @param array|string $value  Value to be set for the passed option.
614
+   * @param boolean      $save   Save the options immediately after setting them.
615
+   */
616
+  public function set_option( $option, $value, $save = false ) {
617
+    if ( isset( $option ) ) {
618
+      if ( isset( $value ) ) {
619
+        self::$_options[ $option ] = $value;
620
+      } else {
621
+        unset( self::$_options[ $option ] );
622
+      }
623
+    }
624
+    if ( $save ) {
625
+      self::save();
626
+    }
627
+  }
628
+
629
+  /**
630
+   * Save the options.
631
+   */
632
+  public function save() {
633
+    update_option( 'wp_to_diaspora_settings', self::$_options );
634
+  }
635
+
636
+  /**
637
+   * Get all valid input values for the passed field.
638
+   *
639
+   * @param string $field Field to get the valid values for.
640
+   * @return array List of valid values.
641
+   */
642
+  public function get_valid_values( $field ) {
643
+    if ( array_key_exists( $field, self::$_valid_values ) ) {
644
+      return self::$_valid_values[ $field ];
645
+    }
646
+  }
647
+
648
+  /**
649
+   * Check if a value is valid for the passed field.
650
+   *
651
+   * @param string $field Field to check the valid value for.
652
+   * @param object $value Value to check validity.
653
+   * @return boolean If the passed value is valid.
654
+   */
655
+  public function is_valid_value( $field, $value ) {
656
+    if ( $valids = self::get_valid_values( $field ) ) {
657
+      return ( in_array( $value, $valids ) );
658
+    }
659
+    return false;
660
+  }
661
+
662
+  /**
663
+   * Validate all settings.
664
+   *
665
+   * @param array $input RAW input values.
666
+   * @return array Validated input values.
667
+   */
668
+  public function validate_settings( $input ) {
669
+    /* Validate all settings before saving to the database. */
670
+
671
+    // Saving the pod setup details.
672
+    if ( isset( $input['submit_setup'] ) ) {
673
+      $input['pod']      = trim( sanitize_text_field( $input['pod'] ), ' /' );
674
+      $input['username'] = sanitize_text_field( $input['username'] );
675
+      $input['password'] = sanitize_text_field( $input['password'] );
676
+
677
+      // If password is blank, it hasn't been changed.
678
+      // If new password is equal to the encrypted password already saved, it was just passed again. It happens everytime update_option('wp_to_diaspora_settings') is called.
679
+      if ( '' === $input['password'] || $this->get_option( 'password' ) === $input['password'] ) {
680
+        $input['password'] = $this->get_option( 'password' );
681
+      } else {
682
+        $input['password'] = WP2D_Helpers::encrypt( $input['password'] );
683
+      }
684
+
685
+      // This is for when JS in not enabled, to make sure that the aspects and services
686
+      // are refetched when displaying the options page after saving.
687
+      if ( isset( $input['no_js'] ) ) {
688
+        set_transient( 'wp2d_no_js_force_refetch', true );
689
+      }
690
+    }
691
+
692
+    // Saving the default options.
693
+    if ( isset( $input['submit_defaults'] ) ) {
694
+      if ( ! isset( $input['enabled_post_types'] ) ) {
695
+        $input['enabled_post_types'] = array();
696
+      }
697
+
698
+      // Checkboxes.
699
+      $this->validate_checkboxes( array( 'post_to_diaspora', 'fullentrylink' ), $input );
700
+
701
+      // Single Selects.
702
+      $this->validate_single_selects( 'display', $input );
703
+
704
+      // Multiple Selects.
705
+      $this->validate_multi_selects( 'tags_to_post', $input );
706
+
707
+      // Get unique, non-empty, trimmed tags and clean them up.
708
+      $this->validate_tags( $input['global_tags'] );
709
+
710
+      // Clean up the list of aspects. If the list is empty, only use the 'Public' aspect.
711
+      $this->validate_aspects_services( $input['aspects'], array( 'public' ) );
712
+
713
+      // Clean up the list of services.
714
+      $this->validate_aspects_services( $input['services'] );
715
+    }
716
+
717
+    // Reset to defaults.
718
+    if ( isset( $input['reset_defaults'] ) ) {
719
+      // Set the input to the default options.
720
+      $input = self::$_default_options;
721
+
722
+      // Don't reset the fetched lists of pods, aspects and services.
723
+      unset( $input['pod_list'] );
724
+      unset( $input['aspects_list'] );
725
+      unset( $input['services_list'] );
726
+    }
727
+
728
+    // Unset all unused input fields.
729
+    unset( $input['submit_defaults'] );
730
+    unset( $input['reset_defaults'] );
731
+    unset( $input['submit_setup'] );
732
+
733
+    // Parse inputs with default options and return.
734
+    return wp_parse_args( $input, array_merge( self::$_default_options, self::$_options ) );
735
+  }
736
+
737
+  /**
738
+   * Validate checkboxes, make them either true or false.
739
+   *
740
+   * @param string|array $checkboxes Checkboxes to validate.
741
+   * @param array        $options    Options values themselves.
742
+   * @return array The validated options.
743
+   */
744
+  public function validate_checkboxes( $checkboxes, &$options ) {
745
+    foreach ( WP2D_Helpers::str_to_arr( $checkboxes ) as $checkbox ) {
746
+      $options[ $checkbox ] = isset( $options[ $checkbox ] );
747
+    }
748
+    return $options;
749
+  }
750
+
751
+  /**
752
+   * Validate single-select fields and make sure their selected value are valid.
753
+   *
754
+   * @param string|array $selects Name(s) of the select fields.
755
+   * @param array        $options Options values themselves.
756
+   * @return array The validated options.
757
+   */
758
+  public function validate_single_selects( $selects, &$options ) {
759
+    foreach ( WP2D_Helpers::str_to_arr( $selects ) as $select ) {
760
+      if ( isset( $options[ $select ] ) && ! $this->is_valid_value( $select, $options[ $select ] ) ) {
761
+        unset( $options[ $select ] );
762
+      }
763
+    }
764
+    return $options;
765
+  }
766
+
767
+  /**
768
+   * Validate multi-select fields and make sure their selected values are valid.
769
+   *
770
+   * @param string|array $selects Name(s) of the select fields.
771
+   * @param array        $options Options values themselves.
772
+   * @return array The validated options.
773
+   */
774
+  public function validate_multi_selects( $selects, &$options ) {
775
+    foreach ( WP2D_Helpers::str_to_arr( $selects ) as $select ) {
776
+      if ( isset( $options[ $select ] ) ) {
777
+        foreach ( (array) $options[ $select ] as $option_value ) {
778
+          if ( ! $this->is_valid_value( $select, $option_value ) ) {
779
+            unset( $options[ $select ] );
780
+            break;
781
+          }
782
+        }
783
+      } else {
784
+        $options[ $select ] = array();
785
+      }
786
+    }
787
+    return $options;
788
+  }
789
+
790
+  /**
791
+   * Clean up the passed tags. Keep only alphanumeric, hyphen and underscore characters.
792
+   *
793
+   * @param array|string $tags Tags to be cleaned as array or comma seperated values.
794
+   * @return array The cleaned tags.
795
+   */
796
+  public function validate_tags( &$tags ) {
797
+    WP2D_Helpers::str_to_arr( $tags );
798
+
799
+    $tags = array_map( array( $this, 'validate_tag' ),
800
+      array_unique(
801
+        array_filter( $tags, 'trim' )
802
+      )
803
+    );
804
+    return $tags;
805
+  }
806
+
807
+  /**
808
+   * Clean up the passed tag. Keep only alphanumeric, hyphen and underscore characters.
809
+   *
810
+   * @todo What about eastern characters? (chinese, indian, etc.)
811
+   *
812
+   * @param string $tag Tag to be cleaned.
813
+   * @return string The clean tag.
814
+   */
815
+  public function validate_tag( &$tag ) {
816
+    $tag = preg_replace( '/[^\w $\-]/u', '', str_replace( ' ', '-', trim( $tag ) ) );
817
+    return $tag;
818
+  }
819
+
820
+  /**
821
+   * Validate the passed aspects or services.
822
+   *
823
+   * @param array $aspects_services List of aspects or services that need to be validated.
824
+   * @param array $default          Default value if not valid.
825
+   * @return array The validated list of aspects or services.
826
+   */
827
+  public function validate_aspects_services( &$aspects_services, $default = array() ) {
828
+    if ( empty( $aspects_services ) || ! is_array( $aspects_services ) ) {
829
+      $aspects_services = $default;
830
+    } else {
831
+      array_walk( $aspects_services, 'sanitize_text_field' );
832
+    }
833
+    return $aspects_services;
834
+  }
835 835
 }
Please login to merge, or discard this patch.
lib/class-post.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -191,7 +191,7 @@
 block discarded – undo
191 191
 	 *
192 192
 	 * @param integer $post_id ID of the post being saved.
193 193
 	 * @param WP_Post $post    Post object being saved.
194
-	 * @return boolean If the post was posted successfully.
194
+	 * @return false|null If the post was posted successfully.
195 195
 	 */
196 196
 	public function post( $post_id, $post ) {
197 197
 		$this->_assign_wp_post( $post );
Please login to merge, or discard this patch.
Indentation   +740 added lines, -740 removed lines patch added patch discarded remove patch
@@ -18,625 +18,625 @@  discard block
 block discarded – undo
18 18
  */
19 19
 class WP2D_Post {
20 20
 
21
-	/**
22
-	 * The original post object.
23
-	 *
24
-	 * @var WP_Posts
25
-	 * @since 1.5.0
26
-	 */
27
-	public $post = null;
28
-
29
-	/**
30
-	 * The original post ID.
31
-	 *
32
-	 * @var int
33
-	 * @since 1.5.0
34
-	 */
35
-	public $ID = null;
36
-
37
-	/**
38
-	 * If this post should be shared on diaspora*.
39
-	 *
40
-	 * @var bool
41
-	 * @since 1.5.0
42
-	 */
43
-	public $post_to_diaspora = null;
44
-
45
-	/**
46
-	 * If a link back to the original post should be added.
47
-	 *
48
-	 * @var bool
49
-	 * @since 1.5.0
50
-	 */
51
-	public $fullentrylink = null;
52
-
53
-	/**
54
-	 * What content gets posted.
55
-	 *
56
-	 * @var string
57
-	 * @since 1.5.0
58
-	 */
59
-	public $display = null;
60
-
61
-	/**
62
-	 * The types of tags to post. (global,custom,post)
63
-	 *
64
-	 * @var array
65
-	 * @since 1.5.0
66
-	 */
67
-	public $tags_to_post = null;
68
-
69
-	/**
70
-	 * The post's custom tags.
71
-	 *
72
-	 * @var array
73
-	 * @since 1.5.0
74
-	 */
75
-	public $custom_tags = null;
76
-
77
-	/**
78
-	 * Aspects this post gets posted to.
79
-	 *
80
-	 * @var array
81
-	 * @since 1.5.0
82
-	 */
83
-	public $aspects = null;
84
-
85
-	/**
86
-	 * Services this post gets posted to.
87
-	 *
88
-	 * @var array
89
-	 * @since 1.5.0
90
-	 */
91
-	public $services = null;
92
-
93
-
94
-	/**
95
-	 * The post's history of diaspora* posts.
96
-	 *
97
-	 * @var array
98
-	 * @since 1.5.0
99
-	 */
100
-	public $post_history = null;
101
-
102
-	/**
103
-	 * If the post actions have all been set up already.
104
-	 *
105
-	 * @var boolean
106
-	 * @since 1.5.0
107
-	 */
108
-	private static $_is_set_up = false;
109
-
110
-	/**
111
-	 * Setup all the necessary WP callbacks.
112
-	 *
113
-	 * @since 1.5.0
114
-	 */
115
-	public static function setup() {
116
-		if ( self::$_is_set_up ) {
117
-			return;
118
-		}
119
-
120
-		$instance = new WP2D_Post( null );
121
-
122
-		// Notices when a post has been shared or if it has failed.
123
-		add_action( 'admin_notices', array( $instance, 'admin_notices' ) );
124
-		add_action( 'admin_init', array( $instance, 'ignore_post_error' ) );
125
-
126
-		// Handle diaspora* posting when saving the post.
127
-		add_action( 'save_post', array( $instance, 'post' ), 11, 2 );
128
-		add_action( 'save_post', array( $instance, 'save_meta_box_data' ), 10 );
129
-
130
-		// Add meta boxes.
131
-		add_action( 'add_meta_boxes', array( $instance, 'add_meta_boxes' ) );
132
-
133
-		self::$_is_set_up = true;
134
-	}
135
-
136
-	/**
137
-	 * Constructor.
138
-	 *
139
-	 * @since 1.5.0
140
-	 *
141
-	 * @param int|WP_Post $post Post ID or the post itself.
142
-	 */
143
-	public function __construct( $post ) {
144
-		$this->_assign_wp_post( $post );
145
-	}
146
-
147
-	/**
148
-	 * Assign the original WP_Post object and all the custom meta data.
149
-	 *
150
-	 * @since 1.5.0
151
-	 *
152
-	 * @param int|WP_Post $post Post ID or the post itself.
153
-	 */
154
-	private function _assign_wp_post( $post ) {
155
-		if ( $this->post = get_post( $post ) ) {
156
-			$this->ID = $this->post->ID;
157
-
158
-			$options = WP2D_Options::instance();
159
-
160
-			// Assign all meta values, expanding non-existent ones with the defaults.
161
-			$meta_current = get_post_meta( $this->ID, '_wp_to_diaspora', true );
162
-			$meta = wp_parse_args(
163
-				$meta_current,
164
-				$options->get_options()
165
-			);
166
-			if ( $meta ) {
167
-				foreach ( $meta as $key => $value ) {
168
-					$this->$key = $value;
169
-				}
170
-			}
171
-
172
-			// If no WP2D meta data has been saved yet, this post shouldn't be published.
173
-			// This can happen if existing posts (before WP2D) get updated externally, not through the post edit screen.
174
-			// Check gutobenn/wp-to-diaspora#91 for reference.
175
-			// Also, when we have a post scheduled for publishing, don't touch it.
176
-			// This is important when modifying scheduled posts using Quick Edit.
177
-			if ( ! in_array( $this->post->post_status, array( 'auto-draft', 'future' ) ) && ! $meta_current ) {
178
-				$this->post_to_diaspora = false;
179
-			}
180
-
181
-			$this->post_history = get_post_meta( $this->ID, '_wp_to_diaspora_post_history', true );
182
-		}
183
-	}
184
-
185
-	/**
186
-	 * Post to diaspora* when saving a post.
187
-	 *
188
-	 * @since 1.5.0
189
-	 *
190
-	 * @todo Maybe somebody wants to share a password protected post to a closed aspect.
191
-	 *
192
-	 * @param integer $post_id ID of the post being saved.
193
-	 * @param WP_Post $post    Post object being saved.
194
-	 * @return boolean If the post was posted successfully.
195
-	 */
196
-	public function post( $post_id, $post ) {
197
-		$this->_assign_wp_post( $post );
198
-
199
-		$options = WP2D_Options::instance();
200
-
201
-		// Is this post type enabled for posting?
202
-		if ( ! in_array( $post->post_type, $options->get_option( 'enabled_post_types' ) ) ) {
203
-			return false;
204
-		}
205
-
206
-		// Make sure we're posting to diaspora* and the post isn't password protected.
207
-		if ( ! ( $this->post_to_diaspora && 'publish' === $post->post_status && '' === $post->post_password ) ) {
208
-			return false;
209
-		}
210
-
211
-		$status_message = $this->_get_title_link();
212
-
213
-		// Post the full post text or just the excerpt?
214
-		if ( 'full' === $this->display ) {
215
-			$status_message .= $this->_get_full_content();
216
-		} else {
217
-			$status_message .= $this->_get_excerpt_content();
218
-		}
219
-
220
-		// Add the tags assigned to the post.
221
-		$status_message .= $this->_get_tags_to_add();
222
-
223
-		// Add the original entry link to the post?
224
-		$status_message .= $this->_get_posted_at_link();
225
-
226
-		$status_converter = new HtmlConverter( array( 'strip_tags' => true ) );
227
-		$status_message  = $status_converter->convert( $status_message );
228
-
229
-		// Set up the connection to diaspora*.
230
-		$api = WP2D_Helpers::api_quick_connect();
231
-		if ( ! empty( $status_message ) ) {
232
-			if ( $api->has_last_error() ) {
233
-				// Save the post error as post meta data, so we can display it to the user.
234
-				update_post_meta( $post_id, '_wp_to_diaspora_post_error', $api->get_last_error() );
235
-				return false;
236
-			}
237
-
238
-			// Add services to share to via diaspora*.
239
-			$extra_data = array(
240
-				'services' => $this->services,
241
-			);
242
-
243
-			// Try to post to diaspora*.
244
-			if ( $response = $api->post( $status_message, $this->aspects, $extra_data ) ) {
245
-				// Save certain diaspora* post data as meta data for future reference.
246
-				$this->_save_to_history( (object) $response );
247
-
248
-				// If there is still a previous post error around, remove it.
249
-				delete_post_meta( $post_id, '_wp_to_diaspora_post_error' );
250
-
251
-				// Unset post_to_diaspora meta field to prevent mistakenly republishing to diaspora*.
252
-				$meta = get_post_meta( $post_id, '_wp_to_diaspora', true );
253
-				$meta['post_to_diaspora'] = false;
254
-				update_post_meta( $post_id, '_wp_to_diaspora', $meta );
255
-			}
256
-		} else {
257
-			return false;
258
-		}
259
-	}
260
-
261
-	/**
262
-	 * Get the title of the post linking to the post itself.
263
-	 *
264
-	 * @since 1.5.0
265
-	 *
266
-	 * @return string Post title as a link.
267
-	 */
268
-	private function _get_title_link() {
269
-		$title = esc_html( $this->post->post_title );
270
-		$permalink = get_permalink( $this->ID );
271
-		$default = sprintf( '<strong><a href="%2$s" title="%2$s">%1$s</a></strong>', $title, $permalink );
272
-
273
-		/**
274
-		 * Filter the title link at the top of the post.
275
-		 *
276
-		 * @since 1.5.4.1
277
-		 *
278
-		 * @param string $default   The whole HTML of the title link to be outputted.
279
-		 * @param string $title     The title of the original post.
280
-		 * @param string $permalink The permalink of the original post.
281
-		 */
282
-		$link = apply_filters( 'wp2d_title_filter', $default, $title, $permalink );
283
-
284
-		return '<p>' . $link . '</p>';
285
-	}
286
-
287
-	/**
288
-	 * Get the full post content with only default filters applied.
289
-	 *
290
-	 * @since 1.5.0
291
-	 *
292
-	 * @return string The full post content.
293
-	 */
294
-	private function _get_full_content() {
295
-		// Only allow certain shortcodes.
296
-		global $shortcode_tags;
297
-		$shortcode_tags_bkp = array();
298
-
299
-		foreach ( $shortcode_tags as $shortcode_tag => $shortcode_function ) {
300
-			if ( ! in_array( $shortcode_tag, apply_filters( 'wp2d_shortcodes_filter', array( 'wp_caption', 'caption', 'gallery' ) ) ) ) {
301
-				$shortcode_tags_bkp[ $shortcode_tag ] = $shortcode_function;
302
-				unset( $shortcode_tags[ $shortcode_tag ] );
303
-			}
304
-		}
305
-
306
-		// Disable all filters and then enable only defaults. This prevents additional filters from being posted to diaspora*.
307
-		remove_all_filters( 'the_content' );
308
-		foreach ( apply_filters( 'wp2d_content_filters_filter', array( 'do_shortcode', 'wptexturize', 'convert_smilies', 'convert_chars', 'wpautop', 'shortcode_unautop', 'prepend_attachment', array( $this, 'embed_remove' ) ) ) as $filter ) {
309
-			add_filter( 'the_content', $filter );
310
-		}
311
-
312
-		// Extract URLs from [embed] shortcodes.
313
-		add_filter( 'embed_oembed_html', array( $this, 'embed_url' ), 10, 2 );
314
-
315
-		// Add the pretty caption after the images.
316
-		add_filter( 'img_caption_shortcode', array( $this, 'custom_img_caption' ), 10, 3 );
317
-
318
-		// Overwrite the native shortcode handler to add pretty captions.
319
-		// http://wordpress.stackexchange.com/a/74675/54456 for explanation.
320
-		add_shortcode( 'gallery', array( $this, 'custom_gallery_shortcode' ) );
321
-
322
-		$full_content = apply_filters( 'the_content', $this->post->post_content );
323
-
324
-		// Put the removed shortcode tags back again.
325
-		$shortcode_tags += $shortcode_tags_bkp;
326
-
327
-		return $full_content;
328
-	}
329
-
330
-	/**
331
-	 * Get the post's excerpt in a nice format.
332
-	 *
333
-	 * @since 1.5.0
334
-	 *
335
-	 * @return string Post's excerpt.
336
-	 */
337
-	private function _get_excerpt_content() {
338
-		// Look for the excerpt in the following order:
339
-		// 1. Custom post excerpt.
340
-		// 2. Text up to the <!--more--> tag.
341
-		// 3. Manually trimmed content.
342
-		$content = $this->post->post_content;
343
-		$excerpt = $this->post->post_excerpt;
344
-		if ( '' === $excerpt ) {
345
-			if ( $more_pos = strpos( $content, '<!--more' ) ) {
346
-				$excerpt = substr( $content, 0, $more_pos );
347
-			} else {
348
-				$excerpt = wp_trim_words( $content, 42, '[...]' );
349
-			}
350
-		}
351
-		return '<p>' . $excerpt . '</p>';
352
-	}
353
-
354
-	/**
355
-	 * Get a string of tags that have been added to the post.
356
-	 *
357
-	 * @since 1.5.0
358
-	 *
359
-	 * @return string Tags added to the post.
360
-	 */
361
-	private function _get_tags_to_add() {
362
-		$options = WP2D_Options::instance();
363
-		$tags_to_post = $this->tags_to_post;
364
-		$tags_to_add  = '';
365
-
366
-		// Add any diaspora* tags?
367
-		if ( ! empty( $tags_to_post ) ) {
368
-			// The diaspora* tags to add to the post.
369
-			$diaspora_tags = array();
370
-
371
-			// Add global tags?
372
-			$global_tags = $options->get_option( 'global_tags' );
373
-			if ( in_array( 'global', $tags_to_post ) && is_array( $global_tags ) ) {
374
-				$diaspora_tags += array_flip( $global_tags );
375
-			}
376
-
377
-			// Add custom tags?
378
-			if ( in_array( 'custom', $tags_to_post ) && is_array( $this->custom_tags ) ) {
379
-				$diaspora_tags += array_flip( $this->custom_tags );
380
-			}
381
-
382
-			// Add post tags?
383
-			$post_tags = wp_get_post_tags( $this->ID, array( 'fields' => 'slugs' ) );
384
-			if ( in_array( 'post', $tags_to_post ) && is_array( $post_tags ) ) {
385
-				$diaspora_tags += array_flip( $post_tags );
386
-			}
387
-
388
-			// Get an array of cleaned up tags.
389
-			// NOTE: Validate method needs a variable, as it's passed by reference!
390
-			$diaspora_tags = array_keys( $diaspora_tags );
391
-			$options->validate_tags( $diaspora_tags );
392
-
393
-			// Get all the tags and list them all nicely in a row.
394
-			$diaspora_tags_clean = array();
395
-			foreach ( $diaspora_tags as $tag ) {
396
-				$diaspora_tags_clean[] = '#' . $tag;
397
-			}
398
-
399
-			// Add all the found tags.
400
-			if ( ! empty( $diaspora_tags_clean ) ) {
401
-				$tags_to_add = implode( ' ', $diaspora_tags_clean ) . '<br />';
402
-			}
403
-		}
404
-
405
-		return $tags_to_add;
406
-	}
407
-
408
-	/**
409
-	 * Get the link to the original post.
410
-	 *
411
-	 * @since 1.5.0
412
-	 *
413
-	 * @return string Original post link.
414
-	 */
415
-	private function _get_posted_at_link() {
416
-		$link = '';
417
-		if ( $this->fullentrylink ) {
418
-
419
-			$text = esc_html( 'Originally posted at:', 'wp-to-diaspora' );
420
-			$permalink = get_permalink( $this->ID );
421
-			$title = esc_html( 'Permalink', 'wp-to-diaspora' );
422
-			$default = sprintf( '%1$s <a href="%2$s" title="%3$s">%2$s</a>', $text, $permalink, $title );
423
-
424
-			/**
425
-			 * Filter the "Originally posted at" link at the bottom of the post.
426
-			 *
427
-			 * @since 1.5.4.1
428
-			 *
429
-			 * @param string $default   The whole HTML of the text and link to be outputted.
430
-			 * @param string $text      The "Originally posted at:" text before the link.
431
-			 * @param string $permalink The permalink of the original post.
432
-			 * @param string $title     The "Permalink" title of the link.
433
-			 */
434
-			$link = apply_filters( 'wp2d_posted_at_link_filter', $default, $text, $permalink, $title );
435
-
436
-			$link = '<p>' . $link . '</p>';
437
-		}
438
-
439
-		return $link;
440
-	}
441
-
442
-	/**
443
-	 * Save the details of the new diaspora* post to this post's history.
444
-	 *
445
-	 * @since 1.5.0
446
-	 *
447
-	 * @param object $response Response from the API containing the diaspora* post details.
448
-	 */
449
-	private function _save_to_history( $response ) {
450
-		// Make sure the post history is an array.
451
-		if ( empty( $this->post_history ) ) {
452
-			$this->post_history = array();
453
-		}
454
-
455
-		// Add a new entry to the history.
456
-		$this->post_history[] = array(
457
-			'id'         => $response->id,
458
-			'guid'       => $response->guid,
459
-			'created_at' => $this->post->post_modified,
460
-			'aspects'    => $this->aspects,
461
-			'nsfw'       => $response->nsfw,
462
-			'post_url'   => $response->permalink,
463
-		);
464
-
465
-		update_post_meta( $this->ID, '_wp_to_diaspora_post_history', $this->post_history );
466
-	}
467
-
468
-	/**
469
-	 * Return URL from [embed] shortcode instead of generated iframe.
470
-	 *
471
-	 * @since 1.5.0
472
-	 * @see WP_Embed::shortcode()
473
-	 *
474
-	 * @param mixed  $html The cached HTML result, stored in post meta.
475
-	 * @param string $url  The attempted embed URL.
476
-	 * @return string URL of the embed.
477
-	 */
478
-	public function embed_url( $html, $url ) {
479
-		return $url;
480
-	}
481
-
482
-	/**
483
-	 * Removes '[embed]' and '[/embed]' left by embed_url.
484
-	 *
485
-	 * @since 1.5.0
486
-	 * @todo It would be great to fix it using only one filter.
487
-	 *       It's happening because embed filter is being removed by remove_all_filters('the_content') on WP2D_Post::post().
488
-	 *
489
-	 * @param string $content Content of the post.
490
-	 * @return string The content with the embed tags removed.
491
-	 */
492
-	public function embed_remove( $content ) {
493
-		return str_replace( array( '[embed]', '[/embed]' ), array( '<p>', '</p>' ), $content );
494
-	}
495
-
496
-	/**
497
-	 * Prettify the image caption.
498
-	 *
499
-	 * @since 1.5.3
500
-	 *
501
-	 * @param string $caption Caption to be prettified.
502
-	 * @return string Prettified image caption.
503
-	 */
504
-	public function get_img_caption( $caption ) {
505
-		$caption = trim( $caption );
506
-		if ( '' === $caption ) {
507
-			return '';
508
-		}
509
-
510
-		$default = sprintf( '<blockquote>%s</blockquote>',  $caption );
511
-
512
-		/**
513
-		 * Filter the image caption to be displayed after images with captions.
514
-		 *
515
-		 * @since 1.5.3
516
-		 *
517
-		 * @param string $default The whole HTML of the caption.
518
-		 * @param string $caption The caption text.
519
-		 */
520
-		return apply_filters( 'wp2d_image_caption', $default, $caption );
521
-	}
522
-
523
-	/**
524
-	 * Filter the default caption shortcode output.
525
-	 *
526
-	 * @since 1.5.3
527
-	 * @see img_caption_shortcode()
528
-	 *
529
-	 * @param string $empty   The caption output. Default empty.
530
-	 * @param array  $attr    Attributes of the caption shortcode.
531
-	 * @param string $content The image element, possibly wrapped in a hyperlink.
532
-	 * @return string The caption shortcode output.
533
-	 */
534
-	public function custom_img_caption( $empty, $attr, $content ) {
535
-		$content = do_shortcode( $content );
536
-
537
-		// If a caption attribute is defined, we'll add it after the image.
538
-		if ( isset( $attr['caption'] ) && '' !== $attr['caption'] ) {
539
-			$content .= "\n" . $this->get_img_caption( $attr['caption'] );
540
-		}
541
-
542
-		return $content;
543
-	}
544
-
545
-	/**
546
-	 * Create a custom gallery caption output.
547
-	 *
548
-	 * @since 1.5.3
549
-	 *
550
-	 * @param   array $attr Gallery attributes.
551
-	 * @return  string
552
-	 */
553
-	public function custom_gallery_shortcode( $attr ) {
554
-		// Default value in WordPress.
555
-		$captiontag = ( current_theme_supports( 'html5', 'gallery' ) ) ? 'figcaption' : 'dd';
556
-
557
-		// User value.
558
-		if ( isset( $attr['captiontag'] ) ) {
559
-			$captiontag = $attr['captiontag'];
560
-		}
561
-
562
-		// Let WordPress create the regular gallery.
563
-		$gallery = gallery_shortcode( $attr );
564
-
565
-		// Change the content of the captions.
566
-		$gallery = preg_replace_callback(
567
-			'~(<' . $captiontag . '.*>)(.*)(</' . $captiontag . '>)~mUus',
568
-			array( $this, 'custom_gallery_regex_callback' ),
569
-			$gallery
570
-		);
571
-
572
-		return $gallery;
573
-	}
574
-
575
-	/**
576
-	 * Change the result of the regex match from custom_gallery_shortcode.
577
-	 *
578
-	 * @param array $m Regex matches.
579
-	 * @return string Prettified gallery image caption.
580
-	 */
581
-	public function custom_gallery_regex_callback( $m ) {
582
-		return $this->get_img_caption( $m[2] );
583
-	}
584
-
585
-	/*
21
+  /**
22
+   * The original post object.
23
+   *
24
+   * @var WP_Posts
25
+   * @since 1.5.0
26
+   */
27
+  public $post = null;
28
+
29
+  /**
30
+   * The original post ID.
31
+   *
32
+   * @var int
33
+   * @since 1.5.0
34
+   */
35
+  public $ID = null;
36
+
37
+  /**
38
+   * If this post should be shared on diaspora*.
39
+   *
40
+   * @var bool
41
+   * @since 1.5.0
42
+   */
43
+  public $post_to_diaspora = null;
44
+
45
+  /**
46
+   * If a link back to the original post should be added.
47
+   *
48
+   * @var bool
49
+   * @since 1.5.0
50
+   */
51
+  public $fullentrylink = null;
52
+
53
+  /**
54
+   * What content gets posted.
55
+   *
56
+   * @var string
57
+   * @since 1.5.0
58
+   */
59
+  public $display = null;
60
+
61
+  /**
62
+   * The types of tags to post. (global,custom,post)
63
+   *
64
+   * @var array
65
+   * @since 1.5.0
66
+   */
67
+  public $tags_to_post = null;
68
+
69
+  /**
70
+   * The post's custom tags.
71
+   *
72
+   * @var array
73
+   * @since 1.5.0
74
+   */
75
+  public $custom_tags = null;
76
+
77
+  /**
78
+   * Aspects this post gets posted to.
79
+   *
80
+   * @var array
81
+   * @since 1.5.0
82
+   */
83
+  public $aspects = null;
84
+
85
+  /**
86
+   * Services this post gets posted to.
87
+   *
88
+   * @var array
89
+   * @since 1.5.0
90
+   */
91
+  public $services = null;
92
+
93
+
94
+  /**
95
+   * The post's history of diaspora* posts.
96
+   *
97
+   * @var array
98
+   * @since 1.5.0
99
+   */
100
+  public $post_history = null;
101
+
102
+  /**
103
+   * If the post actions have all been set up already.
104
+   *
105
+   * @var boolean
106
+   * @since 1.5.0
107
+   */
108
+  private static $_is_set_up = false;
109
+
110
+  /**
111
+   * Setup all the necessary WP callbacks.
112
+   *
113
+   * @since 1.5.0
114
+   */
115
+  public static function setup() {
116
+    if ( self::$_is_set_up ) {
117
+      return;
118
+    }
119
+
120
+    $instance = new WP2D_Post( null );
121
+
122
+    // Notices when a post has been shared or if it has failed.
123
+    add_action( 'admin_notices', array( $instance, 'admin_notices' ) );
124
+    add_action( 'admin_init', array( $instance, 'ignore_post_error' ) );
125
+
126
+    // Handle diaspora* posting when saving the post.
127
+    add_action( 'save_post', array( $instance, 'post' ), 11, 2 );
128
+    add_action( 'save_post', array( $instance, 'save_meta_box_data' ), 10 );
129
+
130
+    // Add meta boxes.
131
+    add_action( 'add_meta_boxes', array( $instance, 'add_meta_boxes' ) );
132
+
133
+    self::$_is_set_up = true;
134
+  }
135
+
136
+  /**
137
+   * Constructor.
138
+   *
139
+   * @since 1.5.0
140
+   *
141
+   * @param int|WP_Post $post Post ID or the post itself.
142
+   */
143
+  public function __construct( $post ) {
144
+    $this->_assign_wp_post( $post );
145
+  }
146
+
147
+  /**
148
+   * Assign the original WP_Post object and all the custom meta data.
149
+   *
150
+   * @since 1.5.0
151
+   *
152
+   * @param int|WP_Post $post Post ID or the post itself.
153
+   */
154
+  private function _assign_wp_post( $post ) {
155
+    if ( $this->post = get_post( $post ) ) {
156
+      $this->ID = $this->post->ID;
157
+
158
+      $options = WP2D_Options::instance();
159
+
160
+      // Assign all meta values, expanding non-existent ones with the defaults.
161
+      $meta_current = get_post_meta( $this->ID, '_wp_to_diaspora', true );
162
+      $meta = wp_parse_args(
163
+        $meta_current,
164
+        $options->get_options()
165
+      );
166
+      if ( $meta ) {
167
+        foreach ( $meta as $key => $value ) {
168
+          $this->$key = $value;
169
+        }
170
+      }
171
+
172
+      // If no WP2D meta data has been saved yet, this post shouldn't be published.
173
+      // This can happen if existing posts (before WP2D) get updated externally, not through the post edit screen.
174
+      // Check gutobenn/wp-to-diaspora#91 for reference.
175
+      // Also, when we have a post scheduled for publishing, don't touch it.
176
+      // This is important when modifying scheduled posts using Quick Edit.
177
+      if ( ! in_array( $this->post->post_status, array( 'auto-draft', 'future' ) ) && ! $meta_current ) {
178
+        $this->post_to_diaspora = false;
179
+      }
180
+
181
+      $this->post_history = get_post_meta( $this->ID, '_wp_to_diaspora_post_history', true );
182
+    }
183
+  }
184
+
185
+  /**
186
+   * Post to diaspora* when saving a post.
187
+   *
188
+   * @since 1.5.0
189
+   *
190
+   * @todo Maybe somebody wants to share a password protected post to a closed aspect.
191
+   *
192
+   * @param integer $post_id ID of the post being saved.
193
+   * @param WP_Post $post    Post object being saved.
194
+   * @return boolean If the post was posted successfully.
195
+   */
196
+  public function post( $post_id, $post ) {
197
+    $this->_assign_wp_post( $post );
198
+
199
+    $options = WP2D_Options::instance();
200
+
201
+    // Is this post type enabled for posting?
202
+    if ( ! in_array( $post->post_type, $options->get_option( 'enabled_post_types' ) ) ) {
203
+      return false;
204
+    }
205
+
206
+    // Make sure we're posting to diaspora* and the post isn't password protected.
207
+    if ( ! ( $this->post_to_diaspora && 'publish' === $post->post_status && '' === $post->post_password ) ) {
208
+      return false;
209
+    }
210
+
211
+    $status_message = $this->_get_title_link();
212
+
213
+    // Post the full post text or just the excerpt?
214
+    if ( 'full' === $this->display ) {
215
+      $status_message .= $this->_get_full_content();
216
+    } else {
217
+      $status_message .= $this->_get_excerpt_content();
218
+    }
219
+
220
+    // Add the tags assigned to the post.
221
+    $status_message .= $this->_get_tags_to_add();
222
+
223
+    // Add the original entry link to the post?
224
+    $status_message .= $this->_get_posted_at_link();
225
+
226
+    $status_converter = new HtmlConverter( array( 'strip_tags' => true ) );
227
+    $status_message  = $status_converter->convert( $status_message );
228
+
229
+    // Set up the connection to diaspora*.
230
+    $api = WP2D_Helpers::api_quick_connect();
231
+    if ( ! empty( $status_message ) ) {
232
+      if ( $api->has_last_error() ) {
233
+        // Save the post error as post meta data, so we can display it to the user.
234
+        update_post_meta( $post_id, '_wp_to_diaspora_post_error', $api->get_last_error() );
235
+        return false;
236
+      }
237
+
238
+      // Add services to share to via diaspora*.
239
+      $extra_data = array(
240
+        'services' => $this->services,
241
+      );
242
+
243
+      // Try to post to diaspora*.
244
+      if ( $response = $api->post( $status_message, $this->aspects, $extra_data ) ) {
245
+        // Save certain diaspora* post data as meta data for future reference.
246
+        $this->_save_to_history( (object) $response );
247
+
248
+        // If there is still a previous post error around, remove it.
249
+        delete_post_meta( $post_id, '_wp_to_diaspora_post_error' );
250
+
251
+        // Unset post_to_diaspora meta field to prevent mistakenly republishing to diaspora*.
252
+        $meta = get_post_meta( $post_id, '_wp_to_diaspora', true );
253
+        $meta['post_to_diaspora'] = false;
254
+        update_post_meta( $post_id, '_wp_to_diaspora', $meta );
255
+      }
256
+    } else {
257
+      return false;
258
+    }
259
+  }
260
+
261
+  /**
262
+   * Get the title of the post linking to the post itself.
263
+   *
264
+   * @since 1.5.0
265
+   *
266
+   * @return string Post title as a link.
267
+   */
268
+  private function _get_title_link() {
269
+    $title = esc_html( $this->post->post_title );
270
+    $permalink = get_permalink( $this->ID );
271
+    $default = sprintf( '<strong><a href="%2$s" title="%2$s">%1$s</a></strong>', $title, $permalink );
272
+
273
+    /**
274
+     * Filter the title link at the top of the post.
275
+     *
276
+     * @since 1.5.4.1
277
+     *
278
+     * @param string $default   The whole HTML of the title link to be outputted.
279
+     * @param string $title     The title of the original post.
280
+     * @param string $permalink The permalink of the original post.
281
+     */
282
+    $link = apply_filters( 'wp2d_title_filter', $default, $title, $permalink );
283
+
284
+    return '<p>' . $link . '</p>';
285
+  }
286
+
287
+  /**
288
+   * Get the full post content with only default filters applied.
289
+   *
290
+   * @since 1.5.0
291
+   *
292
+   * @return string The full post content.
293
+   */
294
+  private function _get_full_content() {
295
+    // Only allow certain shortcodes.
296
+    global $shortcode_tags;
297
+    $shortcode_tags_bkp = array();
298
+
299
+    foreach ( $shortcode_tags as $shortcode_tag => $shortcode_function ) {
300
+      if ( ! in_array( $shortcode_tag, apply_filters( 'wp2d_shortcodes_filter', array( 'wp_caption', 'caption', 'gallery' ) ) ) ) {
301
+        $shortcode_tags_bkp[ $shortcode_tag ] = $shortcode_function;
302
+        unset( $shortcode_tags[ $shortcode_tag ] );
303
+      }
304
+    }
305
+
306
+    // Disable all filters and then enable only defaults. This prevents additional filters from being posted to diaspora*.
307
+    remove_all_filters( 'the_content' );
308
+    foreach ( apply_filters( 'wp2d_content_filters_filter', array( 'do_shortcode', 'wptexturize', 'convert_smilies', 'convert_chars', 'wpautop', 'shortcode_unautop', 'prepend_attachment', array( $this, 'embed_remove' ) ) ) as $filter ) {
309
+      add_filter( 'the_content', $filter );
310
+    }
311
+
312
+    // Extract URLs from [embed] shortcodes.
313
+    add_filter( 'embed_oembed_html', array( $this, 'embed_url' ), 10, 2 );
314
+
315
+    // Add the pretty caption after the images.
316
+    add_filter( 'img_caption_shortcode', array( $this, 'custom_img_caption' ), 10, 3 );
317
+
318
+    // Overwrite the native shortcode handler to add pretty captions.
319
+    // http://wordpress.stackexchange.com/a/74675/54456 for explanation.
320
+    add_shortcode( 'gallery', array( $this, 'custom_gallery_shortcode' ) );
321
+
322
+    $full_content = apply_filters( 'the_content', $this->post->post_content );
323
+
324
+    // Put the removed shortcode tags back again.
325
+    $shortcode_tags += $shortcode_tags_bkp;
326
+
327
+    return $full_content;
328
+  }
329
+
330
+  /**
331
+   * Get the post's excerpt in a nice format.
332
+   *
333
+   * @since 1.5.0
334
+   *
335
+   * @return string Post's excerpt.
336
+   */
337
+  private function _get_excerpt_content() {
338
+    // Look for the excerpt in the following order:
339
+    // 1. Custom post excerpt.
340
+    // 2. Text up to the <!--more--> tag.
341
+    // 3. Manually trimmed content.
342
+    $content = $this->post->post_content;
343
+    $excerpt = $this->post->post_excerpt;
344
+    if ( '' === $excerpt ) {
345
+      if ( $more_pos = strpos( $content, '<!--more' ) ) {
346
+        $excerpt = substr( $content, 0, $more_pos );
347
+      } else {
348
+        $excerpt = wp_trim_words( $content, 42, '[...]' );
349
+      }
350
+    }
351
+    return '<p>' . $excerpt . '</p>';
352
+  }
353
+
354
+  /**
355
+   * Get a string of tags that have been added to the post.
356
+   *
357
+   * @since 1.5.0
358
+   *
359
+   * @return string Tags added to the post.
360
+   */
361
+  private function _get_tags_to_add() {
362
+    $options = WP2D_Options::instance();
363
+    $tags_to_post = $this->tags_to_post;
364
+    $tags_to_add  = '';
365
+
366
+    // Add any diaspora* tags?
367
+    if ( ! empty( $tags_to_post ) ) {
368
+      // The diaspora* tags to add to the post.
369
+      $diaspora_tags = array();
370
+
371
+      // Add global tags?
372
+      $global_tags = $options->get_option( 'global_tags' );
373
+      if ( in_array( 'global', $tags_to_post ) && is_array( $global_tags ) ) {
374
+        $diaspora_tags += array_flip( $global_tags );
375
+      }
376
+
377
+      // Add custom tags?
378
+      if ( in_array( 'custom', $tags_to_post ) && is_array( $this->custom_tags ) ) {
379
+        $diaspora_tags += array_flip( $this->custom_tags );
380
+      }
381
+
382
+      // Add post tags?
383
+      $post_tags = wp_get_post_tags( $this->ID, array( 'fields' => 'slugs' ) );
384
+      if ( in_array( 'post', $tags_to_post ) && is_array( $post_tags ) ) {
385
+        $diaspora_tags += array_flip( $post_tags );
386
+      }
387
+
388
+      // Get an array of cleaned up tags.
389
+      // NOTE: Validate method needs a variable, as it's passed by reference!
390
+      $diaspora_tags = array_keys( $diaspora_tags );
391
+      $options->validate_tags( $diaspora_tags );
392
+
393
+      // Get all the tags and list them all nicely in a row.
394
+      $diaspora_tags_clean = array();
395
+      foreach ( $diaspora_tags as $tag ) {
396
+        $diaspora_tags_clean[] = '#' . $tag;
397
+      }
398
+
399
+      // Add all the found tags.
400
+      if ( ! empty( $diaspora_tags_clean ) ) {
401
+        $tags_to_add = implode( ' ', $diaspora_tags_clean ) . '<br />';
402
+      }
403
+    }
404
+
405
+    return $tags_to_add;
406
+  }
407
+
408
+  /**
409
+   * Get the link to the original post.
410
+   *
411
+   * @since 1.5.0
412
+   *
413
+   * @return string Original post link.
414
+   */
415
+  private function _get_posted_at_link() {
416
+    $link = '';
417
+    if ( $this->fullentrylink ) {
418
+
419
+      $text = esc_html( 'Originally posted at:', 'wp-to-diaspora' );
420
+      $permalink = get_permalink( $this->ID );
421
+      $title = esc_html( 'Permalink', 'wp-to-diaspora' );
422
+      $default = sprintf( '%1$s <a href="%2$s" title="%3$s">%2$s</a>', $text, $permalink, $title );
423
+
424
+      /**
425
+       * Filter the "Originally posted at" link at the bottom of the post.
426
+       *
427
+       * @since 1.5.4.1
428
+       *
429
+       * @param string $default   The whole HTML of the text and link to be outputted.
430
+       * @param string $text      The "Originally posted at:" text before the link.
431
+       * @param string $permalink The permalink of the original post.
432
+       * @param string $title     The "Permalink" title of the link.
433
+       */
434
+      $link = apply_filters( 'wp2d_posted_at_link_filter', $default, $text, $permalink, $title );
435
+
436
+      $link = '<p>' . $link . '</p>';
437
+    }
438
+
439
+    return $link;
440
+  }
441
+
442
+  /**
443
+   * Save the details of the new diaspora* post to this post's history.
444
+   *
445
+   * @since 1.5.0
446
+   *
447
+   * @param object $response Response from the API containing the diaspora* post details.
448
+   */
449
+  private function _save_to_history( $response ) {
450
+    // Make sure the post history is an array.
451
+    if ( empty( $this->post_history ) ) {
452
+      $this->post_history = array();
453
+    }
454
+
455
+    // Add a new entry to the history.
456
+    $this->post_history[] = array(
457
+      'id'         => $response->id,
458
+      'guid'       => $response->guid,
459
+      'created_at' => $this->post->post_modified,
460
+      'aspects'    => $this->aspects,
461
+      'nsfw'       => $response->nsfw,
462
+      'post_url'   => $response->permalink,
463
+    );
464
+
465
+    update_post_meta( $this->ID, '_wp_to_diaspora_post_history', $this->post_history );
466
+  }
467
+
468
+  /**
469
+   * Return URL from [embed] shortcode instead of generated iframe.
470
+   *
471
+   * @since 1.5.0
472
+   * @see WP_Embed::shortcode()
473
+   *
474
+   * @param mixed  $html The cached HTML result, stored in post meta.
475
+   * @param string $url  The attempted embed URL.
476
+   * @return string URL of the embed.
477
+   */
478
+  public function embed_url( $html, $url ) {
479
+    return $url;
480
+  }
481
+
482
+  /**
483
+   * Removes '[embed]' and '[/embed]' left by embed_url.
484
+   *
485
+   * @since 1.5.0
486
+   * @todo It would be great to fix it using only one filter.
487
+   *       It's happening because embed filter is being removed by remove_all_filters('the_content') on WP2D_Post::post().
488
+   *
489
+   * @param string $content Content of the post.
490
+   * @return string The content with the embed tags removed.
491
+   */
492
+  public function embed_remove( $content ) {
493
+    return str_replace( array( '[embed]', '[/embed]' ), array( '<p>', '</p>' ), $content );
494
+  }
495
+
496
+  /**
497
+   * Prettify the image caption.
498
+   *
499
+   * @since 1.5.3
500
+   *
501
+   * @param string $caption Caption to be prettified.
502
+   * @return string Prettified image caption.
503
+   */
504
+  public function get_img_caption( $caption ) {
505
+    $caption = trim( $caption );
506
+    if ( '' === $caption ) {
507
+      return '';
508
+    }
509
+
510
+    $default = sprintf( '<blockquote>%s</blockquote>',  $caption );
511
+
512
+    /**
513
+     * Filter the image caption to be displayed after images with captions.
514
+     *
515
+     * @since 1.5.3
516
+     *
517
+     * @param string $default The whole HTML of the caption.
518
+     * @param string $caption The caption text.
519
+     */
520
+    return apply_filters( 'wp2d_image_caption', $default, $caption );
521
+  }
522
+
523
+  /**
524
+   * Filter the default caption shortcode output.
525
+   *
526
+   * @since 1.5.3
527
+   * @see img_caption_shortcode()
528
+   *
529
+   * @param string $empty   The caption output. Default empty.
530
+   * @param array  $attr    Attributes of the caption shortcode.
531
+   * @param string $content The image element, possibly wrapped in a hyperlink.
532
+   * @return string The caption shortcode output.
533
+   */
534
+  public function custom_img_caption( $empty, $attr, $content ) {
535
+    $content = do_shortcode( $content );
536
+
537
+    // If a caption attribute is defined, we'll add it after the image.
538
+    if ( isset( $attr['caption'] ) && '' !== $attr['caption'] ) {
539
+      $content .= "\n" . $this->get_img_caption( $attr['caption'] );
540
+    }
541
+
542
+    return $content;
543
+  }
544
+
545
+  /**
546
+   * Create a custom gallery caption output.
547
+   *
548
+   * @since 1.5.3
549
+   *
550
+   * @param   array $attr Gallery attributes.
551
+   * @return  string
552
+   */
553
+  public function custom_gallery_shortcode( $attr ) {
554
+    // Default value in WordPress.
555
+    $captiontag = ( current_theme_supports( 'html5', 'gallery' ) ) ? 'figcaption' : 'dd';
556
+
557
+    // User value.
558
+    if ( isset( $attr['captiontag'] ) ) {
559
+      $captiontag = $attr['captiontag'];
560
+    }
561
+
562
+    // Let WordPress create the regular gallery.
563
+    $gallery = gallery_shortcode( $attr );
564
+
565
+    // Change the content of the captions.
566
+    $gallery = preg_replace_callback(
567
+      '~(<' . $captiontag . '.*>)(.*)(</' . $captiontag . '>)~mUus',
568
+      array( $this, 'custom_gallery_regex_callback' ),
569
+      $gallery
570
+    );
571
+
572
+    return $gallery;
573
+  }
574
+
575
+  /**
576
+   * Change the result of the regex match from custom_gallery_shortcode.
577
+   *
578
+   * @param array $m Regex matches.
579
+   * @return string Prettified gallery image caption.
580
+   */
581
+  public function custom_gallery_regex_callback( $m ) {
582
+    return $this->get_img_caption( $m[2] );
583
+  }
584
+
585
+  /*
586 586
 	 * META BOX
587 587
 	 */
588 588
 
589
-	/**
590
-	 * Adds a meta box to the main column on the enabled Post Types' edit screens.
591
-	 *
592
-	 * @since 1.5.0
593
-	 */
594
-	public function add_meta_boxes() {
595
-		$options = WP2D_Options::instance();
596
-		foreach ( $options->get_option( 'enabled_post_types' ) as $post_type ) {
597
-			add_meta_box(
598
-				'wp_to_diaspora_meta_box',
599
-				'WP to diaspora*',
600
-				array( $this, 'meta_box_render' ),
601
-				$post_type,
602
-				'side',
603
-				'high'
604
-			);
605
-		}
606
-	}
607
-
608
-	/**
609
-	 * Prints the meta box content.
610
-	 *
611
-	 * @since 1.5.0
612
-	 *
613
-	 * @param WP_Post $post The object for the current post.
614
-	 */
615
-	public function meta_box_render( $post ) {
616
-		$this->_assign_wp_post( $post );
617
-
618
-		// Add an nonce field so we can check for it later.
619
-		wp_nonce_field( 'wp_to_diaspora_meta_box', 'wp_to_diaspora_meta_box_nonce' );
620
-
621
-		// Get the default values to use, but give priority to the meta data already set.
622
-		$options = WP2D_Options::instance();
623
-
624
-		// Make sure we have some value for post meta fields.
625
-		$this->custom_tags = $this->custom_tags ?: array();
626
-
627
-		// If this post is already published, don't post again to diaspora* by default.
628
-		$this->post_to_diaspora = ( $this->post_to_diaspora && 'publish' !== get_post_status( $this->ID ) );
629
-		$this->aspects          = $this->aspects  ?: array();
630
-		$this->services         = $this->services ?: array();
631
-
632
-		// Have we already posted on diaspora*?
633
-		if ( is_array( $this->post_history ) ) {
634
-			$latest_post = end( $this->post_history );
635
-			?>
589
+  /**
590
+   * Adds a meta box to the main column on the enabled Post Types' edit screens.
591
+   *
592
+   * @since 1.5.0
593
+   */
594
+  public function add_meta_boxes() {
595
+    $options = WP2D_Options::instance();
596
+    foreach ( $options->get_option( 'enabled_post_types' ) as $post_type ) {
597
+      add_meta_box(
598
+        'wp_to_diaspora_meta_box',
599
+        'WP to diaspora*',
600
+        array( $this, 'meta_box_render' ),
601
+        $post_type,
602
+        'side',
603
+        'high'
604
+      );
605
+    }
606
+  }
607
+
608
+  /**
609
+   * Prints the meta box content.
610
+   *
611
+   * @since 1.5.0
612
+   *
613
+   * @param WP_Post $post The object for the current post.
614
+   */
615
+  public function meta_box_render( $post ) {
616
+    $this->_assign_wp_post( $post );
617
+
618
+    // Add an nonce field so we can check for it later.
619
+    wp_nonce_field( 'wp_to_diaspora_meta_box', 'wp_to_diaspora_meta_box_nonce' );
620
+
621
+    // Get the default values to use, but give priority to the meta data already set.
622
+    $options = WP2D_Options::instance();
623
+
624
+    // Make sure we have some value for post meta fields.
625
+    $this->custom_tags = $this->custom_tags ?: array();
626
+
627
+    // If this post is already published, don't post again to diaspora* by default.
628
+    $this->post_to_diaspora = ( $this->post_to_diaspora && 'publish' !== get_post_status( $this->ID ) );
629
+    $this->aspects          = $this->aspects  ?: array();
630
+    $this->services         = $this->services ?: array();
631
+
632
+    // Have we already posted on diaspora*?
633
+    if ( is_array( $this->post_history ) ) {
634
+      $latest_post = end( $this->post_history );
635
+      ?>
636 636
 			<p><a href="<?php echo esc_attr( $latest_post['post_url'] ); ?>" target="_blank"><?php esc_html_e( 'Already posted to diaspora*.', 'wp-to-diaspora' ); ?></a></p>
637 637
 			<?php
638
-		}
639
-		?>
638
+    }
639
+    ?>
640 640
 
641 641
 		<p><?php $options->post_to_diaspora_render( $this->post_to_diaspora ); ?></p>
642 642
 		<p><?php $options->fullentrylink_render( $this->fullentrylink ); ?></p>
@@ -647,133 +647,133 @@  discard block
 block discarded – undo
647 647
 		<p><?php $options->aspects_services_render( array( 'services', $this->services ) ); ?></p>
648 648
 
649 649
 		<?php
650
-	}
651
-
652
-	/**
653
-	 * When the post is saved, save our meta data.
654
-	 *
655
-	 * @since 1.5.0
656
-	 *
657
-	 * @param integer $post_id The ID of the post being saved.
658
-	 */
659
-	public function save_meta_box_data( $post_id ) {
660
-		/*
650
+  }
651
+
652
+  /**
653
+   * When the post is saved, save our meta data.
654
+   *
655
+   * @since 1.5.0
656
+   *
657
+   * @param integer $post_id The ID of the post being saved.
658
+   */
659
+  public function save_meta_box_data( $post_id ) {
660
+    /*
661 661
 		 * We need to verify this came from our screen and with proper authorization,
662 662
 		 * because the save_post action can be triggered at other times.
663 663
 		 */
664
-		if ( ! $this->_is_safe_to_save() ) {
665
-			return;
666
-		}
667
-
668
-		/* OK, it's safe for us to save the data now. */
669
-
670
-		// Meta data to save.
671
-		$meta_to_save = $_POST['wp_to_diaspora_settings'];
672
-		$options = WP2D_Options::instance();
673
-
674
-		// Checkboxes.
675
-		$options->validate_checkboxes( array( 'post_to_diaspora', 'fullentrylink' ), $meta_to_save );
676
-
677
-		// Single Selects.
678
-		$options->validate_single_selects( 'display', $meta_to_save );
679
-
680
-		// Multiple Selects.
681
-		$options->validate_multi_selects( 'tags_to_post', $meta_to_save );
682
-
683
-		// Save custom tags as array.
684
-		$options->validate_tags( $meta_to_save['custom_tags'] );
685
-
686
-		// Clean up the list of aspects. If the list is empty, only use the 'Public' aspect.
687
-		$options->validate_aspects_services( $meta_to_save['aspects'], array( 'public' ) );
688
-
689
-		// Clean up the list of services.
690
-		$options->validate_aspects_services( $meta_to_save['services'] );
691
-
692
-		// Update the meta data for this post.
693
-		update_post_meta( $post_id, '_wp_to_diaspora', $meta_to_save );
694
-	}
695
-
696
-	/**
697
-	 * Perform all checks to see if we are allowed to save the meta data.
698
-	 *
699
-	 * @since 1.5.0
700
-	 *
701
-	 * @return boolean If the verification checks have passed.
702
-	 */
703
-	private function _is_safe_to_save() {
704
-		// Verify that our nonce is set and  valid.
705
-		if ( ! ( isset( $_POST['wp_to_diaspora_meta_box_nonce'] ) && wp_verify_nonce( $_POST['wp_to_diaspora_meta_box_nonce'], 'wp_to_diaspora_meta_box' ) ) ) {
706
-			return false;
707
-		}
708
-
709
-		// If this is an autosave, our form has not been submitted, so we don't want to do anything.
710
-		if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
711
-			return false;
712
-		}
713
-
714
-		// Check the user's permissions.
715
-		$permission = ( isset( $_POST['post_type'] ) && 'page' === $_POST['post_type'] ) ? 'edit_pages' : 'edit_posts';
716
-		if ( ! current_user_can( $permission, $this->ID ) ) {
717
-			return false;
718
-		}
719
-
720
-		// Make real sure that we have some meta data to save.
721
-		if ( ! isset( $_POST['wp_to_diaspora_settings'] ) ) {
722
-			return false;
723
-		}
724
-
725
-		return true;
726
-	}
727
-
728
-	/**
729
-	 * Add admin notices when a post gets displayed.
730
-	 *
731
-	 * @since 1.5.0
732
-	 *
733
-	 * @todo Ignore post error with AJAX.
734
-	 */
735
-	public function admin_notices() {
736
-		global $post, $pagenow;
737
-		if ( ! $post || 'post.php' !== $pagenow ) {
738
-			return;
739
-		}
740
-
741
-		if ( ( $error = get_post_meta( $post->ID, '_wp_to_diaspora_post_error', true ) ) && is_wp_error( $error ) ) {
742
-			// Are we adding a help tab link to this notice?
743
-			$help_link = WP2D_Contextual_Help::get_help_tab_quick_link( $error );
744
-
745
-			// This notice will only be shown if posting to diaspora* has failed.
746
-			printf( '<div class="error notice is-dismissible"><p>%1$s %2$s %3$s <a href="%4$s">%5$s</a></p></div>',
747
-				esc_html__( 'Failed to post to diaspora*.', 'wp-to-diaspora' ),
748
-				esc_html__( $error->get_error_message() ),
749
-				$help_link,
750
-				esc_url( add_query_arg( 'wp2d_ignore_post_error', '' ) ),
751
-				esc_html__( 'Ignore', 'wp-to-diaspora' )
752
-			);
753
-		} elseif ( ( $diaspora_post_history = get_post_meta( $post->ID, '_wp_to_diaspora_post_history', true ) ) && is_array( $diaspora_post_history ) ) {
754
-			// Get the latest post from the history.
755
-			$latest_post = end( $diaspora_post_history );
756
-
757
-			// Only show if this post is showing a message and the post is a fresh share.
758
-			if ( isset( $_GET['message'] ) && $post->post_modified === $latest_post['created_at'] ) {
759
-				printf( '<div class="updated notice is-dismissible"><p>%1$s <a href="%2$s" target="_blank">%3$s</a></p></div>',
760
-					esc_html__( 'Successfully posted to diaspora*.', 'wp-to-diaspora' ),
761
-					esc_url( $latest_post['post_url'] ),
762
-					esc_html__( 'View Post' )
763
-				);
764
-			}
765
-		}
766
-	}
767
-
768
-	/**
769
-	 * Delete the error post meta data if it gets ignored.
770
-	 *
771
-	 * @since 1.5.0
772
-	 */
773
-	public function ignore_post_error() {
774
-		// If "Ignore" link has been clicked, delete the post error meta data.
775
-		if ( isset( $_GET['wp2d_ignore_post_error'], $_GET['post'] ) ) {
776
-			delete_post_meta( $_GET['post'], '_wp_to_diaspora_post_error' );
777
-		}
778
-	}
664
+    if ( ! $this->_is_safe_to_save() ) {
665
+      return;
666
+    }
667
+
668
+    /* OK, it's safe for us to save the data now. */
669
+
670
+    // Meta data to save.
671
+    $meta_to_save = $_POST['wp_to_diaspora_settings'];
672
+    $options = WP2D_Options::instance();
673
+
674
+    // Checkboxes.
675
+    $options->validate_checkboxes( array( 'post_to_diaspora', 'fullentrylink' ), $meta_to_save );
676
+
677
+    // Single Selects.
678
+    $options->validate_single_selects( 'display', $meta_to_save );
679
+
680
+    // Multiple Selects.
681
+    $options->validate_multi_selects( 'tags_to_post', $meta_to_save );
682
+
683
+    // Save custom tags as array.
684
+    $options->validate_tags( $meta_to_save['custom_tags'] );
685
+
686
+    // Clean up the list of aspects. If the list is empty, only use the 'Public' aspect.
687
+    $options->validate_aspects_services( $meta_to_save['aspects'], array( 'public' ) );
688
+
689
+    // Clean up the list of services.
690
+    $options->validate_aspects_services( $meta_to_save['services'] );
691
+
692
+    // Update the meta data for this post.
693
+    update_post_meta( $post_id, '_wp_to_diaspora', $meta_to_save );
694
+  }
695
+
696
+  /**
697
+   * Perform all checks to see if we are allowed to save the meta data.
698
+   *
699
+   * @since 1.5.0
700
+   *
701
+   * @return boolean If the verification checks have passed.
702
+   */
703
+  private function _is_safe_to_save() {
704
+    // Verify that our nonce is set and  valid.
705
+    if ( ! ( isset( $_POST['wp_to_diaspora_meta_box_nonce'] ) && wp_verify_nonce( $_POST['wp_to_diaspora_meta_box_nonce'], 'wp_to_diaspora_meta_box' ) ) ) {
706
+      return false;
707
+    }
708
+
709
+    // If this is an autosave, our form has not been submitted, so we don't want to do anything.
710
+    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
711
+      return false;
712
+    }
713
+
714
+    // Check the user's permissions.
715
+    $permission = ( isset( $_POST['post_type'] ) && 'page' === $_POST['post_type'] ) ? 'edit_pages' : 'edit_posts';
716
+    if ( ! current_user_can( $permission, $this->ID ) ) {
717
+      return false;
718
+    }
719
+
720
+    // Make real sure that we have some meta data to save.
721
+    if ( ! isset( $_POST['wp_to_diaspora_settings'] ) ) {
722
+      return false;
723
+    }
724
+
725
+    return true;
726
+  }
727
+
728
+  /**
729
+   * Add admin notices when a post gets displayed.
730
+   *
731
+   * @since 1.5.0
732
+   *
733
+   * @todo Ignore post error with AJAX.
734
+   */
735
+  public function admin_notices() {
736
+    global $post, $pagenow;
737
+    if ( ! $post || 'post.php' !== $pagenow ) {
738
+      return;
739
+    }
740
+
741
+    if ( ( $error = get_post_meta( $post->ID, '_wp_to_diaspora_post_error', true ) ) && is_wp_error( $error ) ) {
742
+      // Are we adding a help tab link to this notice?
743
+      $help_link = WP2D_Contextual_Help::get_help_tab_quick_link( $error );
744
+
745
+      // This notice will only be shown if posting to diaspora* has failed.
746
+      printf( '<div class="error notice is-dismissible"><p>%1$s %2$s %3$s <a href="%4$s">%5$s</a></p></div>',
747
+        esc_html__( 'Failed to post to diaspora*.', 'wp-to-diaspora' ),
748
+        esc_html__( $error->get_error_message() ),
749
+        $help_link,
750
+        esc_url( add_query_arg( 'wp2d_ignore_post_error', '' ) ),
751
+        esc_html__( 'Ignore', 'wp-to-diaspora' )
752
+      );
753
+    } elseif ( ( $diaspora_post_history = get_post_meta( $post->ID, '_wp_to_diaspora_post_history', true ) ) && is_array( $diaspora_post_history ) ) {
754
+      // Get the latest post from the history.
755
+      $latest_post = end( $diaspora_post_history );
756
+
757
+      // Only show if this post is showing a message and the post is a fresh share.
758
+      if ( isset( $_GET['message'] ) && $post->post_modified === $latest_post['created_at'] ) {
759
+        printf( '<div class="updated notice is-dismissible"><p>%1$s <a href="%2$s" target="_blank">%3$s</a></p></div>',
760
+          esc_html__( 'Successfully posted to diaspora*.', 'wp-to-diaspora' ),
761
+          esc_url( $latest_post['post_url'] ),
762
+          esc_html__( 'View Post' )
763
+        );
764
+      }
765
+    }
766
+  }
767
+
768
+  /**
769
+   * Delete the error post meta data if it gets ignored.
770
+   *
771
+   * @since 1.5.0
772
+   */
773
+  public function ignore_post_error() {
774
+    // If "Ignore" link has been clicked, delete the post error meta data.
775
+    if ( isset( $_GET['wp2d_ignore_post_error'], $_GET['post'] ) ) {
776
+      delete_post_meta( $_GET['post'], '_wp_to_diaspora_post_error' );
777
+    }
778
+  }
779 779
 }
Please login to merge, or discard this patch.
Spacing   +146 added lines, -146 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  */
8 8
 
9 9
 // Exit if accessed directly.
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 use League\HTMLToMarkdown\HtmlConverter;
13 13
 
@@ -113,22 +113,22 @@  discard block
 block discarded – undo
113 113
 	 * @since 1.5.0
114 114
 	 */
115 115
 	public static function setup() {
116
-		if ( self::$_is_set_up ) {
116
+		if (self::$_is_set_up) {
117 117
 			return;
118 118
 		}
119 119
 
120
-		$instance = new WP2D_Post( null );
120
+		$instance = new WP2D_Post(null);
121 121
 
122 122
 		// Notices when a post has been shared or if it has failed.
123
-		add_action( 'admin_notices', array( $instance, 'admin_notices' ) );
124
-		add_action( 'admin_init', array( $instance, 'ignore_post_error' ) );
123
+		add_action('admin_notices', array($instance, 'admin_notices'));
124
+		add_action('admin_init', array($instance, 'ignore_post_error'));
125 125
 
126 126
 		// Handle diaspora* posting when saving the post.
127
-		add_action( 'save_post', array( $instance, 'post' ), 11, 2 );
128
-		add_action( 'save_post', array( $instance, 'save_meta_box_data' ), 10 );
127
+		add_action('save_post', array($instance, 'post'), 11, 2);
128
+		add_action('save_post', array($instance, 'save_meta_box_data'), 10);
129 129
 
130 130
 		// Add meta boxes.
131
-		add_action( 'add_meta_boxes', array( $instance, 'add_meta_boxes' ) );
131
+		add_action('add_meta_boxes', array($instance, 'add_meta_boxes'));
132 132
 
133 133
 		self::$_is_set_up = true;
134 134
 	}
@@ -140,8 +140,8 @@  discard block
 block discarded – undo
140 140
 	 *
141 141
 	 * @param int|WP_Post $post Post ID or the post itself.
142 142
 	 */
143
-	public function __construct( $post ) {
144
-		$this->_assign_wp_post( $post );
143
+	public function __construct($post) {
144
+		$this->_assign_wp_post($post);
145 145
 	}
146 146
 
147 147
 	/**
@@ -151,20 +151,20 @@  discard block
 block discarded – undo
151 151
 	 *
152 152
 	 * @param int|WP_Post $post Post ID or the post itself.
153 153
 	 */
154
-	private function _assign_wp_post( $post ) {
155
-		if ( $this->post = get_post( $post ) ) {
154
+	private function _assign_wp_post($post) {
155
+		if ($this->post = get_post($post)) {
156 156
 			$this->ID = $this->post->ID;
157 157
 
158 158
 			$options = WP2D_Options::instance();
159 159
 
160 160
 			// Assign all meta values, expanding non-existent ones with the defaults.
161
-			$meta_current = get_post_meta( $this->ID, '_wp_to_diaspora', true );
161
+			$meta_current = get_post_meta($this->ID, '_wp_to_diaspora', true);
162 162
 			$meta = wp_parse_args(
163 163
 				$meta_current,
164 164
 				$options->get_options()
165 165
 			);
166
-			if ( $meta ) {
167
-				foreach ( $meta as $key => $value ) {
166
+			if ($meta) {
167
+				foreach ($meta as $key => $value) {
168 168
 					$this->$key = $value;
169 169
 				}
170 170
 			}
@@ -174,11 +174,11 @@  discard block
 block discarded – undo
174 174
 			// Check gutobenn/wp-to-diaspora#91 for reference.
175 175
 			// Also, when we have a post scheduled for publishing, don't touch it.
176 176
 			// This is important when modifying scheduled posts using Quick Edit.
177
-			if ( ! in_array( $this->post->post_status, array( 'auto-draft', 'future' ) ) && ! $meta_current ) {
177
+			if ( ! in_array($this->post->post_status, array('auto-draft', 'future')) && ! $meta_current) {
178 178
 				$this->post_to_diaspora = false;
179 179
 			}
180 180
 
181
-			$this->post_history = get_post_meta( $this->ID, '_wp_to_diaspora_post_history', true );
181
+			$this->post_history = get_post_meta($this->ID, '_wp_to_diaspora_post_history', true);
182 182
 		}
183 183
 	}
184 184
 
@@ -193,25 +193,25 @@  discard block
 block discarded – undo
193 193
 	 * @param WP_Post $post    Post object being saved.
194 194
 	 * @return boolean If the post was posted successfully.
195 195
 	 */
196
-	public function post( $post_id, $post ) {
197
-		$this->_assign_wp_post( $post );
196
+	public function post($post_id, $post) {
197
+		$this->_assign_wp_post($post);
198 198
 
199 199
 		$options = WP2D_Options::instance();
200 200
 
201 201
 		// Is this post type enabled for posting?
202
-		if ( ! in_array( $post->post_type, $options->get_option( 'enabled_post_types' ) ) ) {
202
+		if ( ! in_array($post->post_type, $options->get_option('enabled_post_types'))) {
203 203
 			return false;
204 204
 		}
205 205
 
206 206
 		// Make sure we're posting to diaspora* and the post isn't password protected.
207
-		if ( ! ( $this->post_to_diaspora && 'publish' === $post->post_status && '' === $post->post_password ) ) {
207
+		if ( ! ($this->post_to_diaspora && 'publish' === $post->post_status && '' === $post->post_password)) {
208 208
 			return false;
209 209
 		}
210 210
 
211 211
 		$status_message = $this->_get_title_link();
212 212
 
213 213
 		// Post the full post text or just the excerpt?
214
-		if ( 'full' === $this->display ) {
214
+		if ('full' === $this->display) {
215 215
 			$status_message .= $this->_get_full_content();
216 216
 		} else {
217 217
 			$status_message .= $this->_get_excerpt_content();
@@ -223,15 +223,15 @@  discard block
 block discarded – undo
223 223
 		// Add the original entry link to the post?
224 224
 		$status_message .= $this->_get_posted_at_link();
225 225
 
226
-		$status_converter = new HtmlConverter( array( 'strip_tags' => true ) );
227
-		$status_message  = $status_converter->convert( $status_message );
226
+		$status_converter = new HtmlConverter(array('strip_tags' => true));
227
+		$status_message  = $status_converter->convert($status_message);
228 228
 
229 229
 		// Set up the connection to diaspora*.
230 230
 		$api = WP2D_Helpers::api_quick_connect();
231
-		if ( ! empty( $status_message ) ) {
232
-			if ( $api->has_last_error() ) {
231
+		if ( ! empty($status_message)) {
232
+			if ($api->has_last_error()) {
233 233
 				// Save the post error as post meta data, so we can display it to the user.
234
-				update_post_meta( $post_id, '_wp_to_diaspora_post_error', $api->get_last_error() );
234
+				update_post_meta($post_id, '_wp_to_diaspora_post_error', $api->get_last_error());
235 235
 				return false;
236 236
 			}
237 237
 
@@ -241,17 +241,17 @@  discard block
 block discarded – undo
241 241
 			);
242 242
 
243 243
 			// Try to post to diaspora*.
244
-			if ( $response = $api->post( $status_message, $this->aspects, $extra_data ) ) {
244
+			if ($response = $api->post($status_message, $this->aspects, $extra_data)) {
245 245
 				// Save certain diaspora* post data as meta data for future reference.
246
-				$this->_save_to_history( (object) $response );
246
+				$this->_save_to_history((object) $response);
247 247
 
248 248
 				// If there is still a previous post error around, remove it.
249
-				delete_post_meta( $post_id, '_wp_to_diaspora_post_error' );
249
+				delete_post_meta($post_id, '_wp_to_diaspora_post_error');
250 250
 
251 251
 				// Unset post_to_diaspora meta field to prevent mistakenly republishing to diaspora*.
252
-				$meta = get_post_meta( $post_id, '_wp_to_diaspora', true );
252
+				$meta = get_post_meta($post_id, '_wp_to_diaspora', true);
253 253
 				$meta['post_to_diaspora'] = false;
254
-				update_post_meta( $post_id, '_wp_to_diaspora', $meta );
254
+				update_post_meta($post_id, '_wp_to_diaspora', $meta);
255 255
 			}
256 256
 		} else {
257 257
 			return false;
@@ -266,9 +266,9 @@  discard block
 block discarded – undo
266 266
 	 * @return string Post title as a link.
267 267
 	 */
268 268
 	private function _get_title_link() {
269
-		$title = esc_html( $this->post->post_title );
270
-		$permalink = get_permalink( $this->ID );
271
-		$default = sprintf( '<strong><a href="%2$s" title="%2$s">%1$s</a></strong>', $title, $permalink );
269
+		$title = esc_html($this->post->post_title);
270
+		$permalink = get_permalink($this->ID);
271
+		$default = sprintf('<strong><a href="%2$s" title="%2$s">%1$s</a></strong>', $title, $permalink);
272 272
 
273 273
 		/**
274 274
 		 * Filter the title link at the top of the post.
@@ -279,9 +279,9 @@  discard block
 block discarded – undo
279 279
 		 * @param string $title     The title of the original post.
280 280
 		 * @param string $permalink The permalink of the original post.
281 281
 		 */
282
-		$link = apply_filters( 'wp2d_title_filter', $default, $title, $permalink );
282
+		$link = apply_filters('wp2d_title_filter', $default, $title, $permalink);
283 283
 
284
-		return '<p>' . $link . '</p>';
284
+		return '<p>'.$link.'</p>';
285 285
 	}
286 286
 
287 287
 	/**
@@ -296,30 +296,30 @@  discard block
 block discarded – undo
296 296
 		global $shortcode_tags;
297 297
 		$shortcode_tags_bkp = array();
298 298
 
299
-		foreach ( $shortcode_tags as $shortcode_tag => $shortcode_function ) {
300
-			if ( ! in_array( $shortcode_tag, apply_filters( 'wp2d_shortcodes_filter', array( 'wp_caption', 'caption', 'gallery' ) ) ) ) {
301
-				$shortcode_tags_bkp[ $shortcode_tag ] = $shortcode_function;
302
-				unset( $shortcode_tags[ $shortcode_tag ] );
299
+		foreach ($shortcode_tags as $shortcode_tag => $shortcode_function) {
300
+			if ( ! in_array($shortcode_tag, apply_filters('wp2d_shortcodes_filter', array('wp_caption', 'caption', 'gallery')))) {
301
+				$shortcode_tags_bkp[$shortcode_tag] = $shortcode_function;
302
+				unset($shortcode_tags[$shortcode_tag]);
303 303
 			}
304 304
 		}
305 305
 
306 306
 		// Disable all filters and then enable only defaults. This prevents additional filters from being posted to diaspora*.
307
-		remove_all_filters( 'the_content' );
308
-		foreach ( apply_filters( 'wp2d_content_filters_filter', array( 'do_shortcode', 'wptexturize', 'convert_smilies', 'convert_chars', 'wpautop', 'shortcode_unautop', 'prepend_attachment', array( $this, 'embed_remove' ) ) ) as $filter ) {
309
-			add_filter( 'the_content', $filter );
307
+		remove_all_filters('the_content');
308
+		foreach (apply_filters('wp2d_content_filters_filter', array('do_shortcode', 'wptexturize', 'convert_smilies', 'convert_chars', 'wpautop', 'shortcode_unautop', 'prepend_attachment', array($this, 'embed_remove'))) as $filter) {
309
+			add_filter('the_content', $filter);
310 310
 		}
311 311
 
312 312
 		// Extract URLs from [embed] shortcodes.
313
-		add_filter( 'embed_oembed_html', array( $this, 'embed_url' ), 10, 2 );
313
+		add_filter('embed_oembed_html', array($this, 'embed_url'), 10, 2);
314 314
 
315 315
 		// Add the pretty caption after the images.
316
-		add_filter( 'img_caption_shortcode', array( $this, 'custom_img_caption' ), 10, 3 );
316
+		add_filter('img_caption_shortcode', array($this, 'custom_img_caption'), 10, 3);
317 317
 
318 318
 		// Overwrite the native shortcode handler to add pretty captions.
319 319
 		// http://wordpress.stackexchange.com/a/74675/54456 for explanation.
320
-		add_shortcode( 'gallery', array( $this, 'custom_gallery_shortcode' ) );
320
+		add_shortcode('gallery', array($this, 'custom_gallery_shortcode'));
321 321
 
322
-		$full_content = apply_filters( 'the_content', $this->post->post_content );
322
+		$full_content = apply_filters('the_content', $this->post->post_content);
323 323
 
324 324
 		// Put the removed shortcode tags back again.
325 325
 		$shortcode_tags += $shortcode_tags_bkp;
@@ -341,14 +341,14 @@  discard block
 block discarded – undo
341 341
 		// 3. Manually trimmed content.
342 342
 		$content = $this->post->post_content;
343 343
 		$excerpt = $this->post->post_excerpt;
344
-		if ( '' === $excerpt ) {
345
-			if ( $more_pos = strpos( $content, '<!--more' ) ) {
346
-				$excerpt = substr( $content, 0, $more_pos );
344
+		if ('' === $excerpt) {
345
+			if ($more_pos = strpos($content, '<!--more')) {
346
+				$excerpt = substr($content, 0, $more_pos);
347 347
 			} else {
348
-				$excerpt = wp_trim_words( $content, 42, '[...]' );
348
+				$excerpt = wp_trim_words($content, 42, '[...]');
349 349
 			}
350 350
 		}
351
-		return '<p>' . $excerpt . '</p>';
351
+		return '<p>'.$excerpt.'</p>';
352 352
 	}
353 353
 
354 354
 	/**
@@ -364,41 +364,41 @@  discard block
 block discarded – undo
364 364
 		$tags_to_add  = '';
365 365
 
366 366
 		// Add any diaspora* tags?
367
-		if ( ! empty( $tags_to_post ) ) {
367
+		if ( ! empty($tags_to_post)) {
368 368
 			// The diaspora* tags to add to the post.
369 369
 			$diaspora_tags = array();
370 370
 
371 371
 			// Add global tags?
372
-			$global_tags = $options->get_option( 'global_tags' );
373
-			if ( in_array( 'global', $tags_to_post ) && is_array( $global_tags ) ) {
374
-				$diaspora_tags += array_flip( $global_tags );
372
+			$global_tags = $options->get_option('global_tags');
373
+			if (in_array('global', $tags_to_post) && is_array($global_tags)) {
374
+				$diaspora_tags += array_flip($global_tags);
375 375
 			}
376 376
 
377 377
 			// Add custom tags?
378
-			if ( in_array( 'custom', $tags_to_post ) && is_array( $this->custom_tags ) ) {
379
-				$diaspora_tags += array_flip( $this->custom_tags );
378
+			if (in_array('custom', $tags_to_post) && is_array($this->custom_tags)) {
379
+				$diaspora_tags += array_flip($this->custom_tags);
380 380
 			}
381 381
 
382 382
 			// Add post tags?
383
-			$post_tags = wp_get_post_tags( $this->ID, array( 'fields' => 'slugs' ) );
384
-			if ( in_array( 'post', $tags_to_post ) && is_array( $post_tags ) ) {
385
-				$diaspora_tags += array_flip( $post_tags );
383
+			$post_tags = wp_get_post_tags($this->ID, array('fields' => 'slugs'));
384
+			if (in_array('post', $tags_to_post) && is_array($post_tags)) {
385
+				$diaspora_tags += array_flip($post_tags);
386 386
 			}
387 387
 
388 388
 			// Get an array of cleaned up tags.
389 389
 			// NOTE: Validate method needs a variable, as it's passed by reference!
390
-			$diaspora_tags = array_keys( $diaspora_tags );
391
-			$options->validate_tags( $diaspora_tags );
390
+			$diaspora_tags = array_keys($diaspora_tags);
391
+			$options->validate_tags($diaspora_tags);
392 392
 
393 393
 			// Get all the tags and list them all nicely in a row.
394 394
 			$diaspora_tags_clean = array();
395
-			foreach ( $diaspora_tags as $tag ) {
396
-				$diaspora_tags_clean[] = '#' . $tag;
395
+			foreach ($diaspora_tags as $tag) {
396
+				$diaspora_tags_clean[] = '#'.$tag;
397 397
 			}
398 398
 
399 399
 			// Add all the found tags.
400
-			if ( ! empty( $diaspora_tags_clean ) ) {
401
-				$tags_to_add = implode( ' ', $diaspora_tags_clean ) . '<br />';
400
+			if ( ! empty($diaspora_tags_clean)) {
401
+				$tags_to_add = implode(' ', $diaspora_tags_clean).'<br />';
402 402
 			}
403 403
 		}
404 404
 
@@ -414,12 +414,12 @@  discard block
 block discarded – undo
414 414
 	 */
415 415
 	private function _get_posted_at_link() {
416 416
 		$link = '';
417
-		if ( $this->fullentrylink ) {
417
+		if ($this->fullentrylink) {
418 418
 
419
-			$text = esc_html( 'Originally posted at:', 'wp-to-diaspora' );
420
-			$permalink = get_permalink( $this->ID );
421
-			$title = esc_html( 'Permalink', 'wp-to-diaspora' );
422
-			$default = sprintf( '%1$s <a href="%2$s" title="%3$s">%2$s</a>', $text, $permalink, $title );
419
+			$text = esc_html('Originally posted at:', 'wp-to-diaspora');
420
+			$permalink = get_permalink($this->ID);
421
+			$title = esc_html('Permalink', 'wp-to-diaspora');
422
+			$default = sprintf('%1$s <a href="%2$s" title="%3$s">%2$s</a>', $text, $permalink, $title);
423 423
 
424 424
 			/**
425 425
 			 * Filter the "Originally posted at" link at the bottom of the post.
@@ -431,9 +431,9 @@  discard block
 block discarded – undo
431 431
 			 * @param string $permalink The permalink of the original post.
432 432
 			 * @param string $title     The "Permalink" title of the link.
433 433
 			 */
434
-			$link = apply_filters( 'wp2d_posted_at_link_filter', $default, $text, $permalink, $title );
434
+			$link = apply_filters('wp2d_posted_at_link_filter', $default, $text, $permalink, $title);
435 435
 
436
-			$link = '<p>' . $link . '</p>';
436
+			$link = '<p>'.$link.'</p>';
437 437
 		}
438 438
 
439 439
 		return $link;
@@ -446,9 +446,9 @@  discard block
 block discarded – undo
446 446
 	 *
447 447
 	 * @param object $response Response from the API containing the diaspora* post details.
448 448
 	 */
449
-	private function _save_to_history( $response ) {
449
+	private function _save_to_history($response) {
450 450
 		// Make sure the post history is an array.
451
-		if ( empty( $this->post_history ) ) {
451
+		if (empty($this->post_history)) {
452 452
 			$this->post_history = array();
453 453
 		}
454 454
 
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
 			'post_url'   => $response->permalink,
463 463
 		);
464 464
 
465
-		update_post_meta( $this->ID, '_wp_to_diaspora_post_history', $this->post_history );
465
+		update_post_meta($this->ID, '_wp_to_diaspora_post_history', $this->post_history);
466 466
 	}
467 467
 
468 468
 	/**
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
 	 * @param string $url  The attempted embed URL.
476 476
 	 * @return string URL of the embed.
477 477
 	 */
478
-	public function embed_url( $html, $url ) {
478
+	public function embed_url($html, $url) {
479 479
 		return $url;
480 480
 	}
481 481
 
@@ -489,8 +489,8 @@  discard block
 block discarded – undo
489 489
 	 * @param string $content Content of the post.
490 490
 	 * @return string The content with the embed tags removed.
491 491
 	 */
492
-	public function embed_remove( $content ) {
493
-		return str_replace( array( '[embed]', '[/embed]' ), array( '<p>', '</p>' ), $content );
492
+	public function embed_remove($content) {
493
+		return str_replace(array('[embed]', '[/embed]'), array('<p>', '</p>'), $content);
494 494
 	}
495 495
 
496 496
 	/**
@@ -501,13 +501,13 @@  discard block
 block discarded – undo
501 501
 	 * @param string $caption Caption to be prettified.
502 502
 	 * @return string Prettified image caption.
503 503
 	 */
504
-	public function get_img_caption( $caption ) {
505
-		$caption = trim( $caption );
506
-		if ( '' === $caption ) {
504
+	public function get_img_caption($caption) {
505
+		$caption = trim($caption);
506
+		if ('' === $caption) {
507 507
 			return '';
508 508
 		}
509 509
 
510
-		$default = sprintf( '<blockquote>%s</blockquote>',  $caption );
510
+		$default = sprintf('<blockquote>%s</blockquote>', $caption);
511 511
 
512 512
 		/**
513 513
 		 * Filter the image caption to be displayed after images with captions.
@@ -517,7 +517,7 @@  discard block
 block discarded – undo
517 517
 		 * @param string $default The whole HTML of the caption.
518 518
 		 * @param string $caption The caption text.
519 519
 		 */
520
-		return apply_filters( 'wp2d_image_caption', $default, $caption );
520
+		return apply_filters('wp2d_image_caption', $default, $caption);
521 521
 	}
522 522
 
523 523
 	/**
@@ -531,12 +531,12 @@  discard block
 block discarded – undo
531 531
 	 * @param string $content The image element, possibly wrapped in a hyperlink.
532 532
 	 * @return string The caption shortcode output.
533 533
 	 */
534
-	public function custom_img_caption( $empty, $attr, $content ) {
535
-		$content = do_shortcode( $content );
534
+	public function custom_img_caption($empty, $attr, $content) {
535
+		$content = do_shortcode($content);
536 536
 
537 537
 		// If a caption attribute is defined, we'll add it after the image.
538
-		if ( isset( $attr['caption'] ) && '' !== $attr['caption'] ) {
539
-			$content .= "\n" . $this->get_img_caption( $attr['caption'] );
538
+		if (isset($attr['caption']) && '' !== $attr['caption']) {
539
+			$content .= "\n".$this->get_img_caption($attr['caption']);
540 540
 		}
541 541
 
542 542
 		return $content;
@@ -550,22 +550,22 @@  discard block
 block discarded – undo
550 550
 	 * @param   array $attr Gallery attributes.
551 551
 	 * @return  string
552 552
 	 */
553
-	public function custom_gallery_shortcode( $attr ) {
553
+	public function custom_gallery_shortcode($attr) {
554 554
 		// Default value in WordPress.
555
-		$captiontag = ( current_theme_supports( 'html5', 'gallery' ) ) ? 'figcaption' : 'dd';
555
+		$captiontag = (current_theme_supports('html5', 'gallery')) ? 'figcaption' : 'dd';
556 556
 
557 557
 		// User value.
558
-		if ( isset( $attr['captiontag'] ) ) {
558
+		if (isset($attr['captiontag'])) {
559 559
 			$captiontag = $attr['captiontag'];
560 560
 		}
561 561
 
562 562
 		// Let WordPress create the regular gallery.
563
-		$gallery = gallery_shortcode( $attr );
563
+		$gallery = gallery_shortcode($attr);
564 564
 
565 565
 		// Change the content of the captions.
566 566
 		$gallery = preg_replace_callback(
567
-			'~(<' . $captiontag . '.*>)(.*)(</' . $captiontag . '>)~mUus',
568
-			array( $this, 'custom_gallery_regex_callback' ),
567
+			'~(<'.$captiontag.'.*>)(.*)(</'.$captiontag.'>)~mUus',
568
+			array($this, 'custom_gallery_regex_callback'),
569 569
 			$gallery
570 570
 		);
571 571
 
@@ -578,8 +578,8 @@  discard block
 block discarded – undo
578 578
 	 * @param array $m Regex matches.
579 579
 	 * @return string Prettified gallery image caption.
580 580
 	 */
581
-	public function custom_gallery_regex_callback( $m ) {
582
-		return $this->get_img_caption( $m[2] );
581
+	public function custom_gallery_regex_callback($m) {
582
+		return $this->get_img_caption($m[2]);
583 583
 	}
584 584
 
585 585
 	/*
@@ -593,11 +593,11 @@  discard block
 block discarded – undo
593 593
 	 */
594 594
 	public function add_meta_boxes() {
595 595
 		$options = WP2D_Options::instance();
596
-		foreach ( $options->get_option( 'enabled_post_types' ) as $post_type ) {
596
+		foreach ($options->get_option('enabled_post_types') as $post_type) {
597 597
 			add_meta_box(
598 598
 				'wp_to_diaspora_meta_box',
599 599
 				'WP to diaspora*',
600
-				array( $this, 'meta_box_render' ),
600
+				array($this, 'meta_box_render'),
601 601
 				$post_type,
602 602
 				'side',
603 603
 				'high'
@@ -612,11 +612,11 @@  discard block
 block discarded – undo
612 612
 	 *
613 613
 	 * @param WP_Post $post The object for the current post.
614 614
 	 */
615
-	public function meta_box_render( $post ) {
616
-		$this->_assign_wp_post( $post );
615
+	public function meta_box_render($post) {
616
+		$this->_assign_wp_post($post);
617 617
 
618 618
 		// Add an nonce field so we can check for it later.
619
-		wp_nonce_field( 'wp_to_diaspora_meta_box', 'wp_to_diaspora_meta_box_nonce' );
619
+		wp_nonce_field('wp_to_diaspora_meta_box', 'wp_to_diaspora_meta_box_nonce');
620 620
 
621 621
 		// Get the default values to use, but give priority to the meta data already set.
622 622
 		$options = WP2D_Options::instance();
@@ -625,26 +625,26 @@  discard block
 block discarded – undo
625 625
 		$this->custom_tags = $this->custom_tags ?: array();
626 626
 
627 627
 		// If this post is already published, don't post again to diaspora* by default.
628
-		$this->post_to_diaspora = ( $this->post_to_diaspora && 'publish' !== get_post_status( $this->ID ) );
629
-		$this->aspects          = $this->aspects  ?: array();
628
+		$this->post_to_diaspora = ($this->post_to_diaspora && 'publish' !== get_post_status($this->ID));
629
+		$this->aspects          = $this->aspects ?: array();
630 630
 		$this->services         = $this->services ?: array();
631 631
 
632 632
 		// Have we already posted on diaspora*?
633
-		if ( is_array( $this->post_history ) ) {
634
-			$latest_post = end( $this->post_history );
633
+		if (is_array($this->post_history)) {
634
+			$latest_post = end($this->post_history);
635 635
 			?>
636
-			<p><a href="<?php echo esc_attr( $latest_post['post_url'] ); ?>" target="_blank"><?php esc_html_e( 'Already posted to diaspora*.', 'wp-to-diaspora' ); ?></a></p>
636
+			<p><a href="<?php echo esc_attr($latest_post['post_url']); ?>" target="_blank"><?php esc_html_e('Already posted to diaspora*.', 'wp-to-diaspora'); ?></a></p>
637 637
 			<?php
638 638
 		}
639 639
 		?>
640 640
 
641
-		<p><?php $options->post_to_diaspora_render( $this->post_to_diaspora ); ?></p>
642
-		<p><?php $options->fullentrylink_render( $this->fullentrylink ); ?></p>
643
-		<p><?php $options->display_render( $this->display ); ?></p>
644
-		<p><?php $options->tags_to_post_render( $this->tags_to_post ); ?></p>
645
-		<p><?php $options->custom_tags_render( $this->custom_tags ); ?></p>
646
-		<p><?php $options->aspects_services_render( array( 'aspects', $this->aspects ) ); ?></p>
647
-		<p><?php $options->aspects_services_render( array( 'services', $this->services ) ); ?></p>
641
+		<p><?php $options->post_to_diaspora_render($this->post_to_diaspora); ?></p>
642
+		<p><?php $options->fullentrylink_render($this->fullentrylink); ?></p>
643
+		<p><?php $options->display_render($this->display); ?></p>
644
+		<p><?php $options->tags_to_post_render($this->tags_to_post); ?></p>
645
+		<p><?php $options->custom_tags_render($this->custom_tags); ?></p>
646
+		<p><?php $options->aspects_services_render(array('aspects', $this->aspects)); ?></p>
647
+		<p><?php $options->aspects_services_render(array('services', $this->services)); ?></p>
648 648
 
649 649
 		<?php
650 650
 	}
@@ -656,12 +656,12 @@  discard block
 block discarded – undo
656 656
 	 *
657 657
 	 * @param integer $post_id The ID of the post being saved.
658 658
 	 */
659
-	public function save_meta_box_data( $post_id ) {
659
+	public function save_meta_box_data($post_id) {
660 660
 		/*
661 661
 		 * We need to verify this came from our screen and with proper authorization,
662 662
 		 * because the save_post action can be triggered at other times.
663 663
 		 */
664
-		if ( ! $this->_is_safe_to_save() ) {
664
+		if ( ! $this->_is_safe_to_save()) {
665 665
 			return;
666 666
 		}
667 667
 
@@ -672,25 +672,25 @@  discard block
 block discarded – undo
672 672
 		$options = WP2D_Options::instance();
673 673
 
674 674
 		// Checkboxes.
675
-		$options->validate_checkboxes( array( 'post_to_diaspora', 'fullentrylink' ), $meta_to_save );
675
+		$options->validate_checkboxes(array('post_to_diaspora', 'fullentrylink'), $meta_to_save);
676 676
 
677 677
 		// Single Selects.
678
-		$options->validate_single_selects( 'display', $meta_to_save );
678
+		$options->validate_single_selects('display', $meta_to_save);
679 679
 
680 680
 		// Multiple Selects.
681
-		$options->validate_multi_selects( 'tags_to_post', $meta_to_save );
681
+		$options->validate_multi_selects('tags_to_post', $meta_to_save);
682 682
 
683 683
 		// Save custom tags as array.
684
-		$options->validate_tags( $meta_to_save['custom_tags'] );
684
+		$options->validate_tags($meta_to_save['custom_tags']);
685 685
 
686 686
 		// Clean up the list of aspects. If the list is empty, only use the 'Public' aspect.
687
-		$options->validate_aspects_services( $meta_to_save['aspects'], array( 'public' ) );
687
+		$options->validate_aspects_services($meta_to_save['aspects'], array('public'));
688 688
 
689 689
 		// Clean up the list of services.
690
-		$options->validate_aspects_services( $meta_to_save['services'] );
690
+		$options->validate_aspects_services($meta_to_save['services']);
691 691
 
692 692
 		// Update the meta data for this post.
693
-		update_post_meta( $post_id, '_wp_to_diaspora', $meta_to_save );
693
+		update_post_meta($post_id, '_wp_to_diaspora', $meta_to_save);
694 694
 	}
695 695
 
696 696
 	/**
@@ -702,23 +702,23 @@  discard block
 block discarded – undo
702 702
 	 */
703 703
 	private function _is_safe_to_save() {
704 704
 		// Verify that our nonce is set and  valid.
705
-		if ( ! ( isset( $_POST['wp_to_diaspora_meta_box_nonce'] ) && wp_verify_nonce( $_POST['wp_to_diaspora_meta_box_nonce'], 'wp_to_diaspora_meta_box' ) ) ) {
705
+		if ( ! (isset($_POST['wp_to_diaspora_meta_box_nonce']) && wp_verify_nonce($_POST['wp_to_diaspora_meta_box_nonce'], 'wp_to_diaspora_meta_box'))) {
706 706
 			return false;
707 707
 		}
708 708
 
709 709
 		// If this is an autosave, our form has not been submitted, so we don't want to do anything.
710
-		if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
710
+		if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
711 711
 			return false;
712 712
 		}
713 713
 
714 714
 		// Check the user's permissions.
715
-		$permission = ( isset( $_POST['post_type'] ) && 'page' === $_POST['post_type'] ) ? 'edit_pages' : 'edit_posts';
716
-		if ( ! current_user_can( $permission, $this->ID ) ) {
715
+		$permission = (isset($_POST['post_type']) && 'page' === $_POST['post_type']) ? 'edit_pages' : 'edit_posts';
716
+		if ( ! current_user_can($permission, $this->ID)) {
717 717
 			return false;
718 718
 		}
719 719
 
720 720
 		// Make real sure that we have some meta data to save.
721
-		if ( ! isset( $_POST['wp_to_diaspora_settings'] ) ) {
721
+		if ( ! isset($_POST['wp_to_diaspora_settings'])) {
722 722
 			return false;
723 723
 		}
724 724
 
@@ -734,32 +734,32 @@  discard block
 block discarded – undo
734 734
 	 */
735 735
 	public function admin_notices() {
736 736
 		global $post, $pagenow;
737
-		if ( ! $post || 'post.php' !== $pagenow ) {
737
+		if ( ! $post || 'post.php' !== $pagenow) {
738 738
 			return;
739 739
 		}
740 740
 
741
-		if ( ( $error = get_post_meta( $post->ID, '_wp_to_diaspora_post_error', true ) ) && is_wp_error( $error ) ) {
741
+		if (($error = get_post_meta($post->ID, '_wp_to_diaspora_post_error', true)) && is_wp_error($error)) {
742 742
 			// Are we adding a help tab link to this notice?
743
-			$help_link = WP2D_Contextual_Help::get_help_tab_quick_link( $error );
743
+			$help_link = WP2D_Contextual_Help::get_help_tab_quick_link($error);
744 744
 
745 745
 			// This notice will only be shown if posting to diaspora* has failed.
746
-			printf( '<div class="error notice is-dismissible"><p>%1$s %2$s %3$s <a href="%4$s">%5$s</a></p></div>',
747
-				esc_html__( 'Failed to post to diaspora*.', 'wp-to-diaspora' ),
748
-				esc_html__( $error->get_error_message() ),
746
+			printf('<div class="error notice is-dismissible"><p>%1$s %2$s %3$s <a href="%4$s">%5$s</a></p></div>',
747
+				esc_html__('Failed to post to diaspora*.', 'wp-to-diaspora'),
748
+				esc_html__($error->get_error_message()),
749 749
 				$help_link,
750
-				esc_url( add_query_arg( 'wp2d_ignore_post_error', '' ) ),
751
-				esc_html__( 'Ignore', 'wp-to-diaspora' )
750
+				esc_url(add_query_arg('wp2d_ignore_post_error', '')),
751
+				esc_html__('Ignore', 'wp-to-diaspora')
752 752
 			);
753
-		} elseif ( ( $diaspora_post_history = get_post_meta( $post->ID, '_wp_to_diaspora_post_history', true ) ) && is_array( $diaspora_post_history ) ) {
753
+		} elseif (($diaspora_post_history = get_post_meta($post->ID, '_wp_to_diaspora_post_history', true)) && is_array($diaspora_post_history)) {
754 754
 			// Get the latest post from the history.
755
-			$latest_post = end( $diaspora_post_history );
755
+			$latest_post = end($diaspora_post_history);
756 756
 
757 757
 			// Only show if this post is showing a message and the post is a fresh share.
758
-			if ( isset( $_GET['message'] ) && $post->post_modified === $latest_post['created_at'] ) {
759
-				printf( '<div class="updated notice is-dismissible"><p>%1$s <a href="%2$s" target="_blank">%3$s</a></p></div>',
760
-					esc_html__( 'Successfully posted to diaspora*.', 'wp-to-diaspora' ),
761
-					esc_url( $latest_post['post_url'] ),
762
-					esc_html__( 'View Post' )
758
+			if (isset($_GET['message']) && $post->post_modified === $latest_post['created_at']) {
759
+				printf('<div class="updated notice is-dismissible"><p>%1$s <a href="%2$s" target="_blank">%3$s</a></p></div>',
760
+					esc_html__('Successfully posted to diaspora*.', 'wp-to-diaspora'),
761
+					esc_url($latest_post['post_url']),
762
+					esc_html__('View Post')
763 763
 				);
764 764
 			}
765 765
 		}
@@ -772,8 +772,8 @@  discard block
 block discarded – undo
772 772
 	 */
773 773
 	public function ignore_post_error() {
774 774
 		// If "Ignore" link has been clicked, delete the post error meta data.
775
-		if ( isset( $_GET['wp2d_ignore_post_error'], $_GET['post'] ) ) {
776
-			delete_post_meta( $_GET['post'], '_wp_to_diaspora_post_error' );
775
+		if (isset($_GET['wp2d_ignore_post_error'], $_GET['post'])) {
776
+			delete_post_meta($_GET['post'], '_wp_to_diaspora_post_error');
777 777
 		}
778 778
 	}
779 779
 }
Please login to merge, or discard this patch.
lib/class-contextual-help.php 2 patches
Spacing   +129 added lines, -129 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  */
8 8
 
9 9
 // Exit if accessed directly.
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 /**
13 13
  * Class that handles the contextual help.
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 	 * @return WP2D_Contextual_Help Instance of this class.
28 28
 	 */
29 29
 	public static function instance() {
30
-		if ( ! isset( self::$_instance ) ) {
30
+		if ( ! isset(self::$_instance)) {
31 31
 			self::$_instance = new self();
32 32
 			self::$_instance->_constants();
33 33
 			self::$_instance->_setup();
@@ -41,12 +41,12 @@  discard block
 block discarded – undo
41 41
 	 * @since 1.5.0
42 42
 	 */
43 43
 	private function _constants() {
44
-		define( 'WP2D_EXT_WPORG',         esc_url( 'https://wordpress.org/plugins/wp-to-diaspora' ) );
45
-		define( 'WP2D_EXT_I18N',          esc_url( 'https://poeditor.com/join/project?hash=c085b3654a5e04c69ec942e0f136716a' ) );
46
-		define( 'WP2D_EXT_GH',            esc_url( 'https://github.com/gutobenn/wp-to-diaspora' ) );
47
-		define( 'WP2D_EXT_DONATE',        esc_url( 'https://github.com/gutobenn/wp-to-diaspora#donate' ) );
48
-		define( 'WP2D_EXT_GH_ISSUES',     esc_url( 'https://github.com/gutobenn/wp-to-diaspora/issues' ) );
49
-		define( 'WP2D_EXT_GH_ISSUES_NEW', esc_url( 'https://github.com/gutobenn/wp-to-diaspora/issues/new' ) );
44
+		define('WP2D_EXT_WPORG', esc_url('https://wordpress.org/plugins/wp-to-diaspora'));
45
+		define('WP2D_EXT_I18N', esc_url('https://poeditor.com/join/project?hash=c085b3654a5e04c69ec942e0f136716a'));
46
+		define('WP2D_EXT_GH', esc_url('https://github.com/gutobenn/wp-to-diaspora'));
47
+		define('WP2D_EXT_DONATE', esc_url('https://github.com/gutobenn/wp-to-diaspora#donate'));
48
+		define('WP2D_EXT_GH_ISSUES', esc_url('https://github.com/gutobenn/wp-to-diaspora/issues'));
49
+		define('WP2D_EXT_GH_ISSUES_NEW', esc_url('https://github.com/gutobenn/wp-to-diaspora/issues/new'));
50 50
 	}
51 51
 
52 52
 	/**
@@ -55,13 +55,13 @@  discard block
 block discarded – undo
55 55
 	private function _setup() {
56 56
 		// Do we display the help tabs?
57 57
 		$post_type = get_current_screen()->post_type;
58
-		$enabled_post_types = WP2D_Options::instance()->get_option( 'enabled_post_types' );
59
-		if ( '' !== $post_type && ! in_array( $post_type, $enabled_post_types ) ) {
58
+		$enabled_post_types = WP2D_Options::instance()->get_option('enabled_post_types');
59
+		if ('' !== $post_type && ! in_array($post_type, $enabled_post_types)) {
60 60
 			return;
61 61
 		}
62 62
 
63 63
 		// If we don't have a post type, we're on the main settings page.
64
-		if ( '' === $post_type ) {
64
+		if ('' === $post_type) {
65 65
 			// Set the sidebar in the contextual help.
66 66
 			$this->_set_sidebar();
67 67
 
@@ -87,12 +87,12 @@  discard block
 block discarded – undo
87 87
 	 */
88 88
 	private function _set_sidebar() {
89 89
 		get_current_screen()->set_help_sidebar(
90
-			'<p><strong>' . esc_html__( 'WP to diaspora*', 'wp-to-diaspora' ) . '</strong></p>
90
+			'<p><strong>'.esc_html__('WP to diaspora*', 'wp-to-diaspora').'</strong></p>
91 91
 			<ul>
92
-				<li><a href="' . WP2D_EXT_GH     . '" target="_blank">GitHub</a>
93
-				<li><a href="' . WP2D_EXT_WPORG  . '" target="_blank">WordPress.org</a>
94
-				<li><a href="' . WP2D_EXT_I18N   . '" target="_blank">' . esc_html__( 'Help with translations', 'wp-to-diaspora' ) . '</a>
95
-				<li><a href="' . WP2D_EXT_DONATE . '" target="_blank">' . esc_html__( 'Make a donation', 'wp-to-diaspora' )        . '</a>
92
+				<li><a href="' . WP2D_EXT_GH.'" target="_blank">GitHub</a>
93
+				<li><a href="' . WP2D_EXT_WPORG.'" target="_blank">WordPress.org</a>
94
+				<li><a href="' . WP2D_EXT_I18N.'" target="_blank">'.esc_html__('Help with translations', 'wp-to-diaspora').'</a>
95
+				<li><a href="' . WP2D_EXT_DONATE.'" target="_blank">'.esc_html__('Make a donation', 'wp-to-diaspora').'</a>
96 96
 			</ul>'
97 97
 		);
98 98
 	}
@@ -104,173 +104,173 @@  discard block
 block discarded – undo
104 104
 		$screen = get_current_screen();
105 105
 
106 106
 		// A short overview of the plugin.
107
-		$screen->add_help_tab( array(
107
+		$screen->add_help_tab(array(
108 108
 			'id'      => 'overview',
109
-			'title'   => esc_html__( 'Overview', 'wp-to-diaspora' ),
110
-			'content' => '<p><strong>' . esc_html__( 'With WP to diaspora*, sharing your WordPress posts to diaspora* is as easy as ever.', 'wp-to-diaspora' ) . '</strong></p>
109
+			'title'   => esc_html__('Overview', 'wp-to-diaspora'),
110
+			'content' => '<p><strong>'.esc_html__('With WP to diaspora*, sharing your WordPress posts to diaspora* is as easy as ever.', 'wp-to-diaspora').'</strong></p>
111 111
 				<ol>
112
-					<li>' . esc_html__( 'Enter your diaspora* login details on the "Setup" tab.', 'wp-to-diaspora' ) . '
113
-					<li>' . esc_html__( 'Define the default posting behaviour on the "Defaults" tab.', 'wp-to-diaspora' ) . '
114
-					<li>' . esc_html__( 'Automatically share your WordPress post on diaspora* when publishing it on your website.', 'wp-to-diaspora' ) . '
115
-					<li>' . esc_html__( 'Check out your new post on diaspora*.', 'wp-to-diaspora' ) . '
112
+					<li>' . esc_html__('Enter your diaspora* login details on the "Setup" tab.', 'wp-to-diaspora').'
113
+					<li>' . esc_html__('Define the default posting behaviour on the "Defaults" tab.', 'wp-to-diaspora').'
114
+					<li>' . esc_html__('Automatically share your WordPress post on diaspora* when publishing it on your website.', 'wp-to-diaspora').'
115
+					<li>' . esc_html__('Check out your new post on diaspora*.', 'wp-to-diaspora').'
116 116
 				</ol>'
117
-		) );
117
+		));
118 118
 
119 119
 		// How to set up the connection to diaspora*.
120
-		$screen->add_help_tab( array(
120
+		$screen->add_help_tab(array(
121 121
 			'id'      => 'setup',
122
-			'title'   => esc_html__( 'Setup', 'wp-to-diaspora' ),
123
-			'content' => '<p><strong>' . esc_html__( 'Enter your diaspora* login details to connect your account.', 'wp-to-diaspora' ) . '</strong></p>
122
+			'title'   => esc_html__('Setup', 'wp-to-diaspora'),
123
+			'content' => '<p><strong>'.esc_html__('Enter your diaspora* login details to connect your account.', 'wp-to-diaspora').'</strong></p>
124 124
 				<ul>
125
-					<li><strong>' . esc_html__( 'diaspora* Pod', 'wp-to-diaspora' ) . '</strong>: ' .
126
-						esc_html__( 'This is the domain name of the pod you are on (e.g. joindiaspora.com)', 'wp-to-diaspora' ) . '<br>
127
-							<em>' . sprintf( esc_html__( 'Use the "%s" button to prepopulate the input field to help choose your pod.', 'wp-to-diaspora' ), esc_html__( 'Refresh pod list', 'wp-to-diaspora' ) ) . '</em>
128
-					<li><strong>' . esc_html__( 'Username', 'wp-to-diaspora' ) . '</strong>: ' .
129
-						esc_html__( 'Your diaspora* username (without the pod domain).', 'wp-to-diaspora' ) . '
130
-					<li><strong>' . esc_html__( 'Password', 'wp-to-diaspora' ) . '</strong>: ' .
131
-						esc_html__( 'Your diaspora* password.', 'wp-to-diaspora' ) . '
125
+					<li><strong>' . esc_html__('diaspora* Pod', 'wp-to-diaspora').'</strong>: '.
126
+						esc_html__('This is the domain name of the pod you are on (e.g. joindiaspora.com)', 'wp-to-diaspora').'<br>
127
+							<em>' . sprintf(esc_html__('Use the "%s" button to prepopulate the input field to help choose your pod.', 'wp-to-diaspora'), esc_html__('Refresh pod list', 'wp-to-diaspora')).'</em>
128
+					<li><strong>' . esc_html__('Username', 'wp-to-diaspora').'</strong>: '.
129
+						esc_html__('Your diaspora* username (without the pod domain).', 'wp-to-diaspora').'
130
+					<li><strong>' . esc_html__('Password', 'wp-to-diaspora').'</strong>: '.
131
+						esc_html__('Your diaspora* password.', 'wp-to-diaspora').'
132 132
 				</ul>',
133
-		) );
133
+		));
134 134
 
135 135
 		// Explain the default options and what they do.
136
-		$screen->add_help_tab( array(
136
+		$screen->add_help_tab(array(
137 137
 			'id'      => 'defaults',
138
-			'title'   => esc_html__( 'Defaults', 'wp-to-diaspora' ),
139
-			'content' => '<p><strong>' . esc_html__( 'Define the default posting behaviour.', 'wp-to-diaspora' ) . '</strong></p>
138
+			'title'   => esc_html__('Defaults', 'wp-to-diaspora'),
139
+			'content' => '<p><strong>'.esc_html__('Define the default posting behaviour.', 'wp-to-diaspora').'</strong></p>
140 140
 				<ul>
141
-					<li><strong>' . esc_html__( 'Post types', 'wp-to-diaspora' ) . '</strong>: ' .
142
-						esc_html__( 'Choose the post types that are allowed to be shared to diaspora*.', 'wp-to-diaspora' ) . '
143
-					<li><strong>' . esc_html__( 'Post to diaspora*', 'wp-to-diaspora' ) . '</strong>: ' .
144
-						esc_html__( 'Automatically share new posts to diaspora* when publishing them.', 'wp-to-diaspora' ) . '
145
-					<li><strong>' . esc_html__( 'Show "Posted at" link?', 'wp-to-diaspora' ) . '</strong>: ' .
146
-						esc_html__( 'Add a link back to your original post, at the bottom of the diaspora* post.', 'wp-to-diaspora' ) . '
147
-					<li><strong>' . esc_html__( 'Display', 'wp-to-diaspora' ) . '</strong>: ' .
148
-						esc_html__( 'Choose whether you would like to post the whole post or just the excerpt.', 'wp-to-diaspora' ) . '
149
-					<li><strong>' . esc_html__( 'Tags to post', 'wp-to-diaspora' ) . '</strong>: ' .
150
-						esc_html__( 'You can add tags to your post to make it easier to find on diaspora*.' ) . '<br>
141
+					<li><strong>' . esc_html__('Post types', 'wp-to-diaspora').'</strong>: '.
142
+						esc_html__('Choose the post types that are allowed to be shared to diaspora*.', 'wp-to-diaspora').'
143
+					<li><strong>' . esc_html__('Post to diaspora*', 'wp-to-diaspora').'</strong>: '.
144
+						esc_html__('Automatically share new posts to diaspora* when publishing them.', 'wp-to-diaspora').'
145
+					<li><strong>' . esc_html__('Show "Posted at" link?', 'wp-to-diaspora').'</strong>: '.
146
+						esc_html__('Add a link back to your original post, at the bottom of the diaspora* post.', 'wp-to-diaspora').'
147
+					<li><strong>' . esc_html__('Display', 'wp-to-diaspora').'</strong>: '.
148
+						esc_html__('Choose whether you would like to post the whole post or just the excerpt.', 'wp-to-diaspora').'
149
+					<li><strong>' . esc_html__('Tags to post', 'wp-to-diaspora').'</strong>: '.
150
+						esc_html__('You can add tags to your post to make it easier to find on diaspora*.').'<br>
151 151
 							<ul>
152
-								<li><strong>' . esc_html__( 'Global tags', 'wp-to-diaspora' ) . '</strong>: ' . esc_html__( 'Tags that apply to all posts.', 'wp-to-diaspora' ) . '
153
-								<li><strong>' . esc_html__( 'Custom tags', 'wp-to-diaspora' ) . '</strong>: ' . esc_html__( 'Tags that apply to individual posts (can be set on each post).', 'wp-to-diaspora' ) . '
154
-								<li><strong>' . esc_html__( 'Post tags',   'wp-to-diaspora' ) . '</strong>: ' . esc_html__( 'Default WordPress Tags of individual posts.', 'wp-to-diaspora' ) . '
152
+								<li><strong>' . esc_html__('Global tags', 'wp-to-diaspora').'</strong>: '.esc_html__('Tags that apply to all posts.', 'wp-to-diaspora').'
153
+								<li><strong>' . esc_html__('Custom tags', 'wp-to-diaspora').'</strong>: '.esc_html__('Tags that apply to individual posts (can be set on each post).', 'wp-to-diaspora').'
154
+								<li><strong>' . esc_html__('Post tags', 'wp-to-diaspora').'</strong>: '.esc_html__('Default WordPress Tags of individual posts.', 'wp-to-diaspora').'
155 155
 							</ul>
156
-					<li><strong>' . esc_html__( 'Global tags', 'wp-to-diaspora' ) . '</strong>: ' .
157
-						esc_html__( 'A list of tags that gets added to every post.', 'wp-to-diaspora' ) . '
158
-					<li><strong>' . esc_html__( 'Aspects', 'wp-to-diaspora' ) . '</strong>: ' .
159
-						esc_html__( 'Decide which of your diaspora* aspects can see your posts.', 'wp-to-diaspora' ) . '<br>
160
-							<em>' . sprintf( esc_html__( 'Use the "%s" button to load your aspects from diaspora*.', 'wp-to-diaspora' ), esc_html__( 'Refresh Aspects', 'wp-to-diaspora' ) ) . '</em>
161
-					<li><strong>' . esc_html__( 'Services', 'wp-to-diaspora' ) . '</strong>: ' .
162
-						esc_html__( 'Choose the services your new diaspora* post gets shared to.', 'wp-to-diaspora' ) . '<br>
163
-							<em>' . sprintf( esc_html__( 'Use the "%s" button to fetch the list of your connected services from diaspora*.', 'wp-to-diaspora' ), esc_html__( 'Refresh Services', 'wp-to-diaspora' ) ) . '</em>
156
+					<li><strong>' . esc_html__('Global tags', 'wp-to-diaspora').'</strong>: '.
157
+						esc_html__('A list of tags that gets added to every post.', 'wp-to-diaspora').'
158
+					<li><strong>' . esc_html__('Aspects', 'wp-to-diaspora').'</strong>: '.
159
+						esc_html__('Decide which of your diaspora* aspects can see your posts.', 'wp-to-diaspora').'<br>
160
+							<em>' . sprintf(esc_html__('Use the "%s" button to load your aspects from diaspora*.', 'wp-to-diaspora'), esc_html__('Refresh Aspects', 'wp-to-diaspora')).'</em>
161
+					<li><strong>' . esc_html__('Services', 'wp-to-diaspora').'</strong>: '.
162
+						esc_html__('Choose the services your new diaspora* post gets shared to.', 'wp-to-diaspora').'<br>
163
+							<em>' . sprintf(esc_html__('Use the "%s" button to fetch the list of your connected services from diaspora*.', 'wp-to-diaspora'), esc_html__('Refresh Services', 'wp-to-diaspora')).'</em>
164 164
 				</ul>',
165
-		) );
165
+		));
166 166
 
167 167
 		// Explain the importance of SSL connections to the pod and the CA certificate bundle.
168 168
 		$defined_functions = get_defined_functions();
169
-		$ssl_can_install = ( ! array_diff( array( 'fopen', 'fwrite', 'fclose', 'file_get_contents', 'file_put_contents' ), $defined_functions['internal'] ) );
170
-		$ssl_cert_is_installed = ( file_exists( WP2D_DIR . '/cacert.pem' ) );
169
+		$ssl_can_install = ( ! array_diff(array('fopen', 'fwrite', 'fclose', 'file_get_contents', 'file_put_contents'), $defined_functions['internal']));
170
+		$ssl_cert_is_installed = (file_exists(WP2D_DIR.'/cacert.pem'));
171 171
 
172 172
 		$ssl_install_output = '';
173
-		if ( $ssl_cert_is_installed ) {
174
-			$ssl_install_output = esc_html__( 'Looks like you already have a custom bundle installed!', 'wp-to-diaspora' );
175
-		} elseif ( $ssl_can_install ) {
173
+		if ($ssl_cert_is_installed) {
174
+			$ssl_install_output = esc_html__('Looks like you already have a custom bundle installed!', 'wp-to-diaspora');
175
+		} elseif ($ssl_can_install) {
176 176
 			$ssl_install_output = sprintf(
177
-				esc_html_x( 'Your server should allow us to %sdo this%s for you :-)', 'Placeholders are HTML for links.', 'wp-to-diaspora' ),
178
-				'<a href="' . add_query_arg( 'wp2d_temp_ssl_fix', '' ) . '" class="button">', '</a>'
177
+				esc_html_x('Your server should allow us to %sdo this%s for you :-)', 'Placeholders are HTML for links.', 'wp-to-diaspora'),
178
+				'<a href="'.add_query_arg('wp2d_temp_ssl_fix', '').'" class="button">', '</a>'
179 179
 			);
180 180
 		}
181
-		$screen->add_help_tab( array(
181
+		$screen->add_help_tab(array(
182 182
 			'id'      => 'ssl',
183
-			'title'   => esc_html__( 'SSL', 'wp-to-diaspora' ),
184
-			'content' => '<p><strong>' . esc_html__( 'WP to diaspora* makes sure the connection to your pod is secure!', 'wp-to-diaspora' ) . '</strong></p>
185
-				<p>' . esc_html__( 'Most diaspora* pods are secured using SSL (Secure Sockets Layer), which makes your connection encrypted. For this connection to work, your server needs to know that those SSL certificates can be trusted.', 'wp-to-diaspora' ) . '</p>
186
-				<p>' . esc_html__( 'Therefore, if your WordPress installation or server does not have an up to date CA certificate bundle, WP to diaspora* may not work for you.', 'wp-to-diaspora' ) . '</p>
187
-				<p>' . esc_html__( 'Lucky for you though, we have you covered if this is the case for you!', 'wp-to-diaspora' ) . '</p>
183
+			'title'   => esc_html__('SSL', 'wp-to-diaspora'),
184
+			'content' => '<p><strong>'.esc_html__('WP to diaspora* makes sure the connection to your pod is secure!', 'wp-to-diaspora').'</strong></p>
185
+				<p>' . esc_html__('Most diaspora* pods are secured using SSL (Secure Sockets Layer), which makes your connection encrypted. For this connection to work, your server needs to know that those SSL certificates can be trusted.', 'wp-to-diaspora').'</p>
186
+				<p>' . esc_html__('Therefore, if your WordPress installation or server does not have an up to date CA certificate bundle, WP to diaspora* may not work for you.', 'wp-to-diaspora').'</p>
187
+				<p>' . esc_html__('Lucky for you though, we have you covered if this is the case for you!', 'wp-to-diaspora').'</p>
188 188
 				<ol>
189
-					<li><strong>' . esc_html__( 'Check the WordPress certificate bundle', 'wp-to-diaspora' ) . '</strong>: ' .
190
-						esc_html__( 'The best option is to make sure that the WordPress internal certificate bundle is available and accessible. You should be able to find it here: "wp-includes/certificates/ca-bundle.crt".', 'wp-to-diaspora' ) . '
191
-					<li><strong>' . esc_html__( 'Get in touch with your hosting provider', 'wp-to-diaspora' ) . '</strong>: ' .
192
-						esc_html__( 'Get in touch with your hosting provider and ask them to update the bundle on the server for you. They should know what you\'re talking about.', 'wp-to-diaspora' ) . '
193
-					<li><strong>' . esc_html__( 'Install the CA bundle yourself', 'wp-to-diaspora' ) . '</strong>: ' .
189
+					<li><strong>' . esc_html__('Check the WordPress certificate bundle', 'wp-to-diaspora').'</strong>: '.
190
+						esc_html__('The best option is to make sure that the WordPress internal certificate bundle is available and accessible. You should be able to find it here: "wp-includes/certificates/ca-bundle.crt".', 'wp-to-diaspora').'
191
+					<li><strong>' . esc_html__('Get in touch with your hosting provider', 'wp-to-diaspora').'</strong>: '.
192
+						esc_html__('Get in touch with your hosting provider and ask them to update the bundle on the server for you. They should know what you\'re talking about.', 'wp-to-diaspora').'
193
+					<li><strong>' . esc_html__('Install the CA bundle yourself', 'wp-to-diaspora').'</strong>: '.
194 194
 						sprintf(
195
-							esc_html_x( 'If you maintain your own server, it\'s your job to keep the bundle up to date. You can find a short and simple way on how to do this %shere%s.', 'Placeholders are HTML for a link.', 'wp-to-diaspora' ),
195
+							esc_html_x('If you maintain your own server, it\'s your job to keep the bundle up to date. You can find a short and simple way on how to do this %shere%s.', 'Placeholders are HTML for a link.', 'wp-to-diaspora'),
196 196
 							'<a href="http://serverfault.com/a/394835" target="_blank">', '</a>'
197
-						) . '
198
-					<li><strong>' . esc_html__( 'Quick "temporary" fix', 'wp-to-diaspora' ) . '</strong>: ' .
197
+						).'
198
+					<li><strong>' . esc_html__('Quick "temporary" fix', 'wp-to-diaspora').'</strong>: '.
199 199
 						sprintf(
200
-							esc_html_x( 'As a temporary solution, you can download the up to date %sCA certificate bundle%s (Right-click &#8594; Save As...) and place the cacert.pem file at the top level of the WP to diaspora* plugin folder. This is a "last resort" option.', 'Placeholders are HTML for links.', 'wp-to-diaspora' ),
200
+							esc_html_x('As a temporary solution, you can download the up to date %sCA certificate bundle%s (Right-click &#8594; Save As...) and place the cacert.pem file at the top level of the WP to diaspora* plugin folder. This is a "last resort" option.', 'Placeholders are HTML for links.', 'wp-to-diaspora'),
201 201
 							'<a href="http://curl.haxx.se/ca/cacert.pem" download>', '</a>'
202 202
 						)
203
-						. '<br><p>' .
203
+						. '<br><p>'.
204 204
 						$ssl_install_output
205 205
 						. '</p>
206 206
 				</ul>
207
-				<p class="dashicons-before dashicons-info">' . esc_html__( 'NOTE: If you choose the temporary option, the copy procedure needs to be done every time the plugin is updated because all files get replaced!', 'wp-to-diaspora' ) . '</p>',
208
-		) );
207
+				<p class="dashicons-before dashicons-info">' . esc_html__('NOTE: If you choose the temporary option, the copy procedure needs to be done every time the plugin is updated because all files get replaced!', 'wp-to-diaspora').'</p>',
208
+		));
209 209
 
210 210
 		// Explain the meta box and the differences to the global defaults.
211
-		$screen->add_help_tab( array(
211
+		$screen->add_help_tab(array(
212 212
 			'id' => 'meta-box',
213
-			'title'   => esc_html__( 'Meta Box', 'wp-to-diaspora' ),
214
-			'content' => '<p><strong>' . esc_html__( 'The Meta Box is the new "WP to diaspora*" box you see when editing a post.', 'wp-to-diaspora' ) . '</strong></p>
215
-				<p>' . esc_html__( 'When creating or editing a post, you will notice a new meta box called "WP to diaspora*" which has some options. These options are almost the same as the options you can find in the "Defaults" tab on the settings page. These options are post-specific though, meaning they override the global defaults for the post itself. You will see that the default values are filled in automatically, allowing you to change individual ones as you please.', 'wp-to-diaspora' ) . '</p>
216
-				<p>' . esc_html__( 'There are a few important differences to the settings page:', 'wp-to-diaspora' ) . '</p>
213
+			'title'   => esc_html__('Meta Box', 'wp-to-diaspora'),
214
+			'content' => '<p><strong>'.esc_html__('The Meta Box is the new "WP to diaspora*" box you see when editing a post.', 'wp-to-diaspora').'</strong></p>
215
+				<p>' . esc_html__('When creating or editing a post, you will notice a new meta box called "WP to diaspora*" which has some options. These options are almost the same as the options you can find in the "Defaults" tab on the settings page. These options are post-specific though, meaning they override the global defaults for the post itself. You will see that the default values are filled in automatically, allowing you to change individual ones as you please.', 'wp-to-diaspora').'</p>
216
+				<p>' . esc_html__('There are a few important differences to the settings page:', 'wp-to-diaspora').'</p>
217 217
 				<ul>
218
-					<li><strong>' . esc_html__( 'Already posted to diaspora*', 'wp-to-diaspora' ) . '</strong>: ' .
219
-						esc_html__( 'If the post has already been posted to diaspora* a link to the diaspora* post will appear at the top.', 'wp-to-diaspora' ) . '
220
-					<li><strong>' . esc_html__( 'Custom tags', 'wp-to-diaspora' ) . '</strong>: ' .
221
-						esc_html__( 'A list of tags that gets added to this post. Note that they are seperate from the WordPress post tags!', 'wp-to-diaspora' ) . '
218
+					<li><strong>' . esc_html__('Already posted to diaspora*', 'wp-to-diaspora').'</strong>: '.
219
+						esc_html__('If the post has already been posted to diaspora* a link to the diaspora* post will appear at the top.', 'wp-to-diaspora').'
220
+					<li><strong>' . esc_html__('Custom tags', 'wp-to-diaspora').'</strong>: '.
221
+						esc_html__('A list of tags that gets added to this post. Note that they are seperate from the WordPress post tags!', 'wp-to-diaspora').'
222 222
 				</ul>
223
-				<p class="dashicons-before dashicons-info">' . esc_html__( 'If you don\'t see the meta box, make sure the post type you\'re on has been added to the "Post types" list on the settings page. Also make sure it has been selected from the "Screen Options" at the top of the screen.', 'wp-to-diaspora' ) . '</p>',
224
-		) );
223
+				<p class="dashicons-before dashicons-info">' . esc_html__('If you don\'t see the meta box, make sure the post type you\'re on has been added to the "Post types" list on the settings page. Also make sure it has been selected from the "Screen Options" at the top of the screen.', 'wp-to-diaspora').'</p>',
224
+		));
225 225
 
226 226
 		// Troubleshooting.
227
-		$screen->add_help_tab( array(
227
+		$screen->add_help_tab(array(
228 228
 			'id' => 'troubleshooting',
229
-			'title'   => esc_html__( 'Troubleshooting', 'wp-to-diaspora' ),
230
-			'content' => '<p><strong>' . esc_html__( 'Troubleshooting common errors.', 'wp-to-diaspora' ) . '</strong></p>
231
-				<p>' . esc_html__( 'Here are a few common errors and their possible solutions:', 'wp-to-diaspora' ) . '</p>
229
+			'title'   => esc_html__('Troubleshooting', 'wp-to-diaspora'),
230
+			'content' => '<p><strong>'.esc_html__('Troubleshooting common errors.', 'wp-to-diaspora').'</strong></p>
231
+				<p>' . esc_html__('Here are a few common errors and their possible solutions:', 'wp-to-diaspora').'</p>
232 232
 				<ul>
233
-					<li><strong>' . esc_html( sprintf( __( 'Failed to initialise connection to pod "%s"', 'wp-to-diaspora' ), 'xyz' ) ) . '</strong>: ' .
234
-						esc_html__( 'This could have multiple reasons.' ) . '
233
+					<li><strong>' . esc_html(sprintf(__('Failed to initialise connection to pod "%s"', 'wp-to-diaspora'), 'xyz')).'</strong>: '.
234
+						esc_html__('This could have multiple reasons.').'
235 235
 						<ul>
236
-							<li>' . esc_html__( 'Make sure that your pod domain is entered correctly.', 'wp-to-diaspora' ) . '
236
+							<li>' . esc_html__('Make sure that your pod domain is entered correctly.', 'wp-to-diaspora').'
237 237
 							<li>' .
238
-								esc_html__( 'It might be an SSL problem.', 'wp-to-diaspora' ) .
239
-								sprintf( ' <a href="#" class="open-help-tab" data-help-tab="ssl">%s</a>', esc_html__( 'Learn More', 'wp-to-diaspora' ) ) . '
240
-							<li>' . esc_html__( 'The pod might be offline at the moment.', 'wp-to-diaspora' ) . '
238
+								esc_html__('It might be an SSL problem.', 'wp-to-diaspora').
239
+								sprintf(' <a href="#" class="open-help-tab" data-help-tab="ssl">%s</a>', esc_html__('Learn More', 'wp-to-diaspora')).'
240
+							<li>' . esc_html__('The pod might be offline at the moment.', 'wp-to-diaspora').'
241 241
 						</ul>
242
-					<li><strong>' . esc_html__( 'Login failed. Check your login details.', 'wp-to-diaspora' ) . '</strong>: ' .
243
-						esc_html__( 'Make sure that your username and password are entered correctly.', 'wp-to-diaspora' ) . '
242
+					<li><strong>' . esc_html__('Login failed. Check your login details.', 'wp-to-diaspora').'</strong>: '.
243
+						esc_html__('Make sure that your username and password are entered correctly.', 'wp-to-diaspora').'
244 244
 				</ul>',
245
-		) );
245
+		));
246 246
 
247 247
 		// Show different ways to contribute to the plugin.
248
-		$screen->add_help_tab( array(
248
+		$screen->add_help_tab(array(
249 249
 			'id' => 'contributing',
250
-			'title'   => esc_html__( 'Contributing', 'wp-to-diaspora' ),
251
-			'content' => '<p><strong>' . esc_html__( 'So you feel like contributing to the WP to diaspora* plugin? Great!', 'wp-to-diaspora' ) . '</strong></p>
252
-				<p>' . esc_html__( 'There are many different ways that you can help out with this plugin:', 'wp-to-diaspora' ) . '</p>
250
+			'title'   => esc_html__('Contributing', 'wp-to-diaspora'),
251
+			'content' => '<p><strong>'.esc_html__('So you feel like contributing to the WP to diaspora* plugin? Great!', 'wp-to-diaspora').'</strong></p>
252
+				<p>' . esc_html__('There are many different ways that you can help out with this plugin:', 'wp-to-diaspora').'</p>
253 253
 				<ul>
254
-					<li><a href="' . WP2D_EXT_GH_ISSUES_NEW . '" target="_blank">' . esc_html__( 'Report a bug', 'wp-to-diaspora' )           . '</a>
255
-					<li><a href="' . WP2D_EXT_GH_ISSUES_NEW . '" target="_blank">' . esc_html__( 'Suggest a new feature', 'wp-to-diaspora' )  . '</a>
256
-					<li><a href="' . WP2D_EXT_I18N          . '" target="_blank">' . esc_html__( 'Help with translations', 'wp-to-diaspora' ) . '</a>
257
-					<li><a href="' . WP2D_EXT_DONATE        . '" target="_blank">' . esc_html__( 'Make a donation', 'wp-to-diaspora' )        . '</a>
254
+					<li><a href="' . WP2D_EXT_GH_ISSUES_NEW.'" target="_blank">'.esc_html__('Report a bug', 'wp-to-diaspora').'</a>
255
+					<li><a href="' . WP2D_EXT_GH_ISSUES_NEW.'" target="_blank">'.esc_html__('Suggest a new feature', 'wp-to-diaspora').'</a>
256
+					<li><a href="' . WP2D_EXT_I18N.'" target="_blank">'.esc_html__('Help with translations', 'wp-to-diaspora').'</a>
257
+					<li><a href="' . WP2D_EXT_DONATE.'" target="_blank">'.esc_html__('Make a donation', 'wp-to-diaspora').'</a>
258 258
 				</ul>',
259
-		) );
259
+		));
260 260
 	}
261 261
 
262 262
 	/**
263 263
 	 * Add help tabs to the contextual help on the post pages.
264 264
 	 */
265 265
 	private function _add_post_type_help_tabs() {
266
-		get_current_screen()->add_help_tab( array(
266
+		get_current_screen()->add_help_tab(array(
267 267
 			'id'       => 'wp-to-diaspora',
268
-			'title'    => esc_html__( 'WP to diaspora*', 'wp-to-diaspora' ),
269
-			'content'  => '<p>' . sprintf(
270
-				esc_html__( 'For detailed information, refer to the contextual help on the %sWP to diaspora*%s settings page.', 'Placeholders represent the link.', 'wp-to-diaspora' ),
268
+			'title'    => esc_html__('WP to diaspora*', 'wp-to-diaspora'),
269
+			'content'  => '<p>'.sprintf(
270
+				esc_html__('For detailed information, refer to the contextual help on the %sWP to diaspora*%s settings page.', 'Placeholders represent the link.', 'wp-to-diaspora'),
271 271
 				'<a href="options-general.php?page=wp_to_diaspora" target="_blank">', '</a>'
272
-			) . '</p>',
273
-		) );
272
+			).'</p>',
273
+		));
274 274
 	}
275 275
 
276 276
 	/**
@@ -281,15 +281,15 @@  discard block
 block discarded – undo
281 281
 	 * @param WP_Error|string $error The WP_Error object with the tab id as data or the tab id itself.
282 282
 	 * @return string HTML link.
283 283
 	 */
284
-	public static function get_help_tab_quick_link( $error ) {
284
+	public static function get_help_tab_quick_link($error) {
285 285
 		$help_tab = '';
286
-		if ( is_wp_error( $error ) && ( $error_data = $error->get_error_data() ) && array_key_exists( 'help_tab', $error_data ) ) {
286
+		if (is_wp_error($error) && ($error_data = $error->get_error_data()) && array_key_exists('help_tab', $error_data)) {
287 287
 			$help_tab = $error_data['help_tab'];
288
-		} elseif ( is_string( $error ) ) {
288
+		} elseif (is_string($error)) {
289 289
 			$help_tab = $error;
290 290
 		}
291
-		if ( '' !== $help_tab ) {
292
-			return sprintf( '<a href="#" class="open-help-tab" data-help-tab="%1$s">%2$s</a>', $help_tab, esc_html__( 'Help', 'wp-to-diaspora' ) );
291
+		if ('' !== $help_tab) {
292
+			return sprintf('<a href="#" class="open-help-tab" data-help-tab="%1$s">%2$s</a>', $help_tab, esc_html__('Help', 'wp-to-diaspora'));
293 293
 		}
294 294
 
295 295
 		return '';
Please login to merge, or discard this patch.
Indentation   +190 added lines, -190 removed lines patch added patch discarded remove patch
@@ -14,241 +14,241 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class WP2D_Contextual_Help {
16 16
 
17
-	/**
18
-	 * Only instance of this class.
19
-	 *
20
-	 * @var WP2D_Contextual_Help
21
-	 */
22
-	private static $_instance = null;
17
+  /**
18
+   * Only instance of this class.
19
+   *
20
+   * @var WP2D_Contextual_Help
21
+   */
22
+  private static $_instance = null;
23 23
 
24
-	/**
25
-	 * Create / Get the instance of this class.
26
-	 *
27
-	 * @return WP2D_Contextual_Help Instance of this class.
28
-	 */
29
-	public static function instance() {
30
-		if ( ! isset( self::$_instance ) ) {
31
-			self::$_instance = new self();
32
-			self::$_instance->_constants();
33
-			self::$_instance->_setup();
34
-		}
35
-		return self::$_instance;
36
-	}
24
+  /**
25
+   * Create / Get the instance of this class.
26
+   *
27
+   * @return WP2D_Contextual_Help Instance of this class.
28
+   */
29
+  public static function instance() {
30
+    if ( ! isset( self::$_instance ) ) {
31
+      self::$_instance = new self();
32
+      self::$_instance->_constants();
33
+      self::$_instance->_setup();
34
+    }
35
+    return self::$_instance;
36
+  }
37 37
 
38
-	/**
39
-	 * Define all the required constants.
40
-	 *
41
-	 * @since 1.5.0
42
-	 */
43
-	private function _constants() {
44
-		define( 'WP2D_EXT_WPORG',         esc_url( 'https://wordpress.org/plugins/wp-to-diaspora' ) );
45
-		define( 'WP2D_EXT_I18N',          esc_url( 'https://poeditor.com/join/project?hash=c085b3654a5e04c69ec942e0f136716a' ) );
46
-		define( 'WP2D_EXT_GH',            esc_url( 'https://github.com/gutobenn/wp-to-diaspora' ) );
47
-		define( 'WP2D_EXT_DONATE',        esc_url( 'https://github.com/gutobenn/wp-to-diaspora#donate' ) );
48
-		define( 'WP2D_EXT_GH_ISSUES',     esc_url( 'https://github.com/gutobenn/wp-to-diaspora/issues' ) );
49
-		define( 'WP2D_EXT_GH_ISSUES_NEW', esc_url( 'https://github.com/gutobenn/wp-to-diaspora/issues/new' ) );
50
-	}
38
+  /**
39
+   * Define all the required constants.
40
+   *
41
+   * @since 1.5.0
42
+   */
43
+  private function _constants() {
44
+    define( 'WP2D_EXT_WPORG',         esc_url( 'https://wordpress.org/plugins/wp-to-diaspora' ) );
45
+    define( 'WP2D_EXT_I18N',          esc_url( 'https://poeditor.com/join/project?hash=c085b3654a5e04c69ec942e0f136716a' ) );
46
+    define( 'WP2D_EXT_GH',            esc_url( 'https://github.com/gutobenn/wp-to-diaspora' ) );
47
+    define( 'WP2D_EXT_DONATE',        esc_url( 'https://github.com/gutobenn/wp-to-diaspora#donate' ) );
48
+    define( 'WP2D_EXT_GH_ISSUES',     esc_url( 'https://github.com/gutobenn/wp-to-diaspora/issues' ) );
49
+    define( 'WP2D_EXT_GH_ISSUES_NEW', esc_url( 'https://github.com/gutobenn/wp-to-diaspora/issues/new' ) );
50
+  }
51 51
 
52
-	/**
53
-	 * Set up the contextual help menu.
54
-	 */
55
-	private function _setup() {
56
-		// Do we display the help tabs?
57
-		$post_type = get_current_screen()->post_type;
58
-		$enabled_post_types = WP2D_Options::instance()->get_option( 'enabled_post_types' );
59
-		if ( '' !== $post_type && ! in_array( $post_type, $enabled_post_types ) ) {
60
-			return;
61
-		}
52
+  /**
53
+   * Set up the contextual help menu.
54
+   */
55
+  private function _setup() {
56
+    // Do we display the help tabs?
57
+    $post_type = get_current_screen()->post_type;
58
+    $enabled_post_types = WP2D_Options::instance()->get_option( 'enabled_post_types' );
59
+    if ( '' !== $post_type && ! in_array( $post_type, $enabled_post_types ) ) {
60
+      return;
61
+    }
62 62
 
63
-		// If we don't have a post type, we're on the main settings page.
64
-		if ( '' === $post_type ) {
65
-			// Set the sidebar in the contextual help.
66
-			$this->_set_sidebar();
63
+    // If we don't have a post type, we're on the main settings page.
64
+    if ( '' === $post_type ) {
65
+      // Set the sidebar in the contextual help.
66
+      $this->_set_sidebar();
67 67
 
68
-			// Add the main settings tabs and their content.
69
-			$this->_add_settings_help_tabs();
70
-		} else {
71
-			// Add the post type specific tabs and their content.
72
-			$this->_add_post_type_help_tabs();
73
-		}
74
-	}
68
+      // Add the main settings tabs and their content.
69
+      $this->_add_settings_help_tabs();
70
+    } else {
71
+      // Add the post type specific tabs and their content.
72
+      $this->_add_post_type_help_tabs();
73
+    }
74
+  }
75 75
 
76
-	/** Singleton, keep private. */
77
-	final private function __clone() { }
76
+  /** Singleton, keep private. */
77
+  final private function __clone() { }
78 78
 
79
-	/** Singleton, keep private. */
80
-	final private function __wakeup() { }
79
+  /** Singleton, keep private. */
80
+  final private function __wakeup() { }
81 81
 
82
-	/** Singleton, keep private. */
83
-	final private function __construct() { }
82
+  /** Singleton, keep private. */
83
+  final private function __construct() { }
84 84
 
85
-	/**
86
-	 * Set the sidebar in the contextual help.
87
-	 */
88
-	private function _set_sidebar() {
89
-		get_current_screen()->set_help_sidebar(
90
-			'<p><strong>' . esc_html__( 'WP to diaspora*', 'wp-to-diaspora' ) . '</strong></p>
85
+  /**
86
+   * Set the sidebar in the contextual help.
87
+   */
88
+  private function _set_sidebar() {
89
+    get_current_screen()->set_help_sidebar(
90
+      '<p><strong>' . esc_html__( 'WP to diaspora*', 'wp-to-diaspora' ) . '</strong></p>
91 91
 			<ul>
92 92
 				<li><a href="' . WP2D_EXT_GH     . '" target="_blank">GitHub</a>
93 93
 				<li><a href="' . WP2D_EXT_WPORG  . '" target="_blank">WordPress.org</a>
94 94
 				<li><a href="' . WP2D_EXT_I18N   . '" target="_blank">' . esc_html__( 'Help with translations', 'wp-to-diaspora' ) . '</a>
95 95
 				<li><a href="' . WP2D_EXT_DONATE . '" target="_blank">' . esc_html__( 'Make a donation', 'wp-to-diaspora' )        . '</a>
96 96
 			</ul>'
97
-		);
98
-	}
97
+    );
98
+  }
99 99
 
100
-	/**
101
-	 * Add help tabs to the contextual help on the settings page.
102
-	 */
103
-	private function _add_settings_help_tabs() {
104
-		$screen = get_current_screen();
100
+  /**
101
+   * Add help tabs to the contextual help on the settings page.
102
+   */
103
+  private function _add_settings_help_tabs() {
104
+    $screen = get_current_screen();
105 105
 
106
-		// A short overview of the plugin.
107
-		$screen->add_help_tab( array(
108
-			'id'      => 'overview',
109
-			'title'   => esc_html__( 'Overview', 'wp-to-diaspora' ),
110
-			'content' => '<p><strong>' . esc_html__( 'With WP to diaspora*, sharing your WordPress posts to diaspora* is as easy as ever.', 'wp-to-diaspora' ) . '</strong></p>
106
+    // A short overview of the plugin.
107
+    $screen->add_help_tab( array(
108
+      'id'      => 'overview',
109
+      'title'   => esc_html__( 'Overview', 'wp-to-diaspora' ),
110
+      'content' => '<p><strong>' . esc_html__( 'With WP to diaspora*, sharing your WordPress posts to diaspora* is as easy as ever.', 'wp-to-diaspora' ) . '</strong></p>
111 111
 				<ol>
112 112
 					<li>' . esc_html__( 'Enter your diaspora* login details on the "Setup" tab.', 'wp-to-diaspora' ) . '
113 113
 					<li>' . esc_html__( 'Define the default posting behaviour on the "Defaults" tab.', 'wp-to-diaspora' ) . '
114 114
 					<li>' . esc_html__( 'Automatically share your WordPress post on diaspora* when publishing it on your website.', 'wp-to-diaspora' ) . '
115 115
 					<li>' . esc_html__( 'Check out your new post on diaspora*.', 'wp-to-diaspora' ) . '
116 116
 				</ol>'
117
-		) );
117
+    ) );
118 118
 
119
-		// How to set up the connection to diaspora*.
120
-		$screen->add_help_tab( array(
121
-			'id'      => 'setup',
122
-			'title'   => esc_html__( 'Setup', 'wp-to-diaspora' ),
123
-			'content' => '<p><strong>' . esc_html__( 'Enter your diaspora* login details to connect your account.', 'wp-to-diaspora' ) . '</strong></p>
119
+    // How to set up the connection to diaspora*.
120
+    $screen->add_help_tab( array(
121
+      'id'      => 'setup',
122
+      'title'   => esc_html__( 'Setup', 'wp-to-diaspora' ),
123
+      'content' => '<p><strong>' . esc_html__( 'Enter your diaspora* login details to connect your account.', 'wp-to-diaspora' ) . '</strong></p>
124 124
 				<ul>
125 125
 					<li><strong>' . esc_html__( 'diaspora* Pod', 'wp-to-diaspora' ) . '</strong>: ' .
126
-						esc_html__( 'This is the domain name of the pod you are on (e.g. joindiaspora.com)', 'wp-to-diaspora' ) . '<br>
126
+            esc_html__( 'This is the domain name of the pod you are on (e.g. joindiaspora.com)', 'wp-to-diaspora' ) . '<br>
127 127
 							<em>' . sprintf( esc_html__( 'Use the "%s" button to prepopulate the input field to help choose your pod.', 'wp-to-diaspora' ), esc_html__( 'Refresh pod list', 'wp-to-diaspora' ) ) . '</em>
128 128
 					<li><strong>' . esc_html__( 'Username', 'wp-to-diaspora' ) . '</strong>: ' .
129
-						esc_html__( 'Your diaspora* username (without the pod domain).', 'wp-to-diaspora' ) . '
129
+            esc_html__( 'Your diaspora* username (without the pod domain).', 'wp-to-diaspora' ) . '
130 130
 					<li><strong>' . esc_html__( 'Password', 'wp-to-diaspora' ) . '</strong>: ' .
131
-						esc_html__( 'Your diaspora* password.', 'wp-to-diaspora' ) . '
131
+            esc_html__( 'Your diaspora* password.', 'wp-to-diaspora' ) . '
132 132
 				</ul>',
133
-		) );
133
+    ) );
134 134
 
135
-		// Explain the default options and what they do.
136
-		$screen->add_help_tab( array(
137
-			'id'      => 'defaults',
138
-			'title'   => esc_html__( 'Defaults', 'wp-to-diaspora' ),
139
-			'content' => '<p><strong>' . esc_html__( 'Define the default posting behaviour.', 'wp-to-diaspora' ) . '</strong></p>
135
+    // Explain the default options and what they do.
136
+    $screen->add_help_tab( array(
137
+      'id'      => 'defaults',
138
+      'title'   => esc_html__( 'Defaults', 'wp-to-diaspora' ),
139
+      'content' => '<p><strong>' . esc_html__( 'Define the default posting behaviour.', 'wp-to-diaspora' ) . '</strong></p>
140 140
 				<ul>
141 141
 					<li><strong>' . esc_html__( 'Post types', 'wp-to-diaspora' ) . '</strong>: ' .
142
-						esc_html__( 'Choose the post types that are allowed to be shared to diaspora*.', 'wp-to-diaspora' ) . '
142
+            esc_html__( 'Choose the post types that are allowed to be shared to diaspora*.', 'wp-to-diaspora' ) . '
143 143
 					<li><strong>' . esc_html__( 'Post to diaspora*', 'wp-to-diaspora' ) . '</strong>: ' .
144
-						esc_html__( 'Automatically share new posts to diaspora* when publishing them.', 'wp-to-diaspora' ) . '
144
+            esc_html__( 'Automatically share new posts to diaspora* when publishing them.', 'wp-to-diaspora' ) . '
145 145
 					<li><strong>' . esc_html__( 'Show "Posted at" link?', 'wp-to-diaspora' ) . '</strong>: ' .
146
-						esc_html__( 'Add a link back to your original post, at the bottom of the diaspora* post.', 'wp-to-diaspora' ) . '
146
+            esc_html__( 'Add a link back to your original post, at the bottom of the diaspora* post.', 'wp-to-diaspora' ) . '
147 147
 					<li><strong>' . esc_html__( 'Display', 'wp-to-diaspora' ) . '</strong>: ' .
148
-						esc_html__( 'Choose whether you would like to post the whole post or just the excerpt.', 'wp-to-diaspora' ) . '
148
+            esc_html__( 'Choose whether you would like to post the whole post or just the excerpt.', 'wp-to-diaspora' ) . '
149 149
 					<li><strong>' . esc_html__( 'Tags to post', 'wp-to-diaspora' ) . '</strong>: ' .
150
-						esc_html__( 'You can add tags to your post to make it easier to find on diaspora*.' ) . '<br>
150
+            esc_html__( 'You can add tags to your post to make it easier to find on diaspora*.' ) . '<br>
151 151
 							<ul>
152 152
 								<li><strong>' . esc_html__( 'Global tags', 'wp-to-diaspora' ) . '</strong>: ' . esc_html__( 'Tags that apply to all posts.', 'wp-to-diaspora' ) . '
153 153
 								<li><strong>' . esc_html__( 'Custom tags', 'wp-to-diaspora' ) . '</strong>: ' . esc_html__( 'Tags that apply to individual posts (can be set on each post).', 'wp-to-diaspora' ) . '
154 154
 								<li><strong>' . esc_html__( 'Post tags',   'wp-to-diaspora' ) . '</strong>: ' . esc_html__( 'Default WordPress Tags of individual posts.', 'wp-to-diaspora' ) . '
155 155
 							</ul>
156 156
 					<li><strong>' . esc_html__( 'Global tags', 'wp-to-diaspora' ) . '</strong>: ' .
157
-						esc_html__( 'A list of tags that gets added to every post.', 'wp-to-diaspora' ) . '
157
+            esc_html__( 'A list of tags that gets added to every post.', 'wp-to-diaspora' ) . '
158 158
 					<li><strong>' . esc_html__( 'Aspects', 'wp-to-diaspora' ) . '</strong>: ' .
159
-						esc_html__( 'Decide which of your diaspora* aspects can see your posts.', 'wp-to-diaspora' ) . '<br>
159
+            esc_html__( 'Decide which of your diaspora* aspects can see your posts.', 'wp-to-diaspora' ) . '<br>
160 160
 							<em>' . sprintf( esc_html__( 'Use the "%s" button to load your aspects from diaspora*.', 'wp-to-diaspora' ), esc_html__( 'Refresh Aspects', 'wp-to-diaspora' ) ) . '</em>
161 161
 					<li><strong>' . esc_html__( 'Services', 'wp-to-diaspora' ) . '</strong>: ' .
162
-						esc_html__( 'Choose the services your new diaspora* post gets shared to.', 'wp-to-diaspora' ) . '<br>
162
+            esc_html__( 'Choose the services your new diaspora* post gets shared to.', 'wp-to-diaspora' ) . '<br>
163 163
 							<em>' . sprintf( esc_html__( 'Use the "%s" button to fetch the list of your connected services from diaspora*.', 'wp-to-diaspora' ), esc_html__( 'Refresh Services', 'wp-to-diaspora' ) ) . '</em>
164 164
 				</ul>',
165
-		) );
165
+    ) );
166 166
 
167
-		// Explain the importance of SSL connections to the pod and the CA certificate bundle.
168
-		$defined_functions = get_defined_functions();
169
-		$ssl_can_install = ( ! array_diff( array( 'fopen', 'fwrite', 'fclose', 'file_get_contents', 'file_put_contents' ), $defined_functions['internal'] ) );
170
-		$ssl_cert_is_installed = ( file_exists( WP2D_DIR . '/cacert.pem' ) );
167
+    // Explain the importance of SSL connections to the pod and the CA certificate bundle.
168
+    $defined_functions = get_defined_functions();
169
+    $ssl_can_install = ( ! array_diff( array( 'fopen', 'fwrite', 'fclose', 'file_get_contents', 'file_put_contents' ), $defined_functions['internal'] ) );
170
+    $ssl_cert_is_installed = ( file_exists( WP2D_DIR . '/cacert.pem' ) );
171 171
 
172
-		$ssl_install_output = '';
173
-		if ( $ssl_cert_is_installed ) {
174
-			$ssl_install_output = esc_html__( 'Looks like you already have a custom bundle installed!', 'wp-to-diaspora' );
175
-		} elseif ( $ssl_can_install ) {
176
-			$ssl_install_output = sprintf(
177
-				esc_html_x( 'Your server should allow us to %sdo this%s for you :-)', 'Placeholders are HTML for links.', 'wp-to-diaspora' ),
178
-				'<a href="' . add_query_arg( 'wp2d_temp_ssl_fix', '' ) . '" class="button">', '</a>'
179
-			);
180
-		}
181
-		$screen->add_help_tab( array(
182
-			'id'      => 'ssl',
183
-			'title'   => esc_html__( 'SSL', 'wp-to-diaspora' ),
184
-			'content' => '<p><strong>' . esc_html__( 'WP to diaspora* makes sure the connection to your pod is secure!', 'wp-to-diaspora' ) . '</strong></p>
172
+    $ssl_install_output = '';
173
+    if ( $ssl_cert_is_installed ) {
174
+      $ssl_install_output = esc_html__( 'Looks like you already have a custom bundle installed!', 'wp-to-diaspora' );
175
+    } elseif ( $ssl_can_install ) {
176
+      $ssl_install_output = sprintf(
177
+        esc_html_x( 'Your server should allow us to %sdo this%s for you :-)', 'Placeholders are HTML for links.', 'wp-to-diaspora' ),
178
+        '<a href="' . add_query_arg( 'wp2d_temp_ssl_fix', '' ) . '" class="button">', '</a>'
179
+      );
180
+    }
181
+    $screen->add_help_tab( array(
182
+      'id'      => 'ssl',
183
+      'title'   => esc_html__( 'SSL', 'wp-to-diaspora' ),
184
+      'content' => '<p><strong>' . esc_html__( 'WP to diaspora* makes sure the connection to your pod is secure!', 'wp-to-diaspora' ) . '</strong></p>
185 185
 				<p>' . esc_html__( 'Most diaspora* pods are secured using SSL (Secure Sockets Layer), which makes your connection encrypted. For this connection to work, your server needs to know that those SSL certificates can be trusted.', 'wp-to-diaspora' ) . '</p>
186 186
 				<p>' . esc_html__( 'Therefore, if your WordPress installation or server does not have an up to date CA certificate bundle, WP to diaspora* may not work for you.', 'wp-to-diaspora' ) . '</p>
187 187
 				<p>' . esc_html__( 'Lucky for you though, we have you covered if this is the case for you!', 'wp-to-diaspora' ) . '</p>
188 188
 				<ol>
189 189
 					<li><strong>' . esc_html__( 'Check the WordPress certificate bundle', 'wp-to-diaspora' ) . '</strong>: ' .
190
-						esc_html__( 'The best option is to make sure that the WordPress internal certificate bundle is available and accessible. You should be able to find it here: "wp-includes/certificates/ca-bundle.crt".', 'wp-to-diaspora' ) . '
190
+            esc_html__( 'The best option is to make sure that the WordPress internal certificate bundle is available and accessible. You should be able to find it here: "wp-includes/certificates/ca-bundle.crt".', 'wp-to-diaspora' ) . '
191 191
 					<li><strong>' . esc_html__( 'Get in touch with your hosting provider', 'wp-to-diaspora' ) . '</strong>: ' .
192
-						esc_html__( 'Get in touch with your hosting provider and ask them to update the bundle on the server for you. They should know what you\'re talking about.', 'wp-to-diaspora' ) . '
192
+            esc_html__( 'Get in touch with your hosting provider and ask them to update the bundle on the server for you. They should know what you\'re talking about.', 'wp-to-diaspora' ) . '
193 193
 					<li><strong>' . esc_html__( 'Install the CA bundle yourself', 'wp-to-diaspora' ) . '</strong>: ' .
194
-						sprintf(
195
-							esc_html_x( 'If you maintain your own server, it\'s your job to keep the bundle up to date. You can find a short and simple way on how to do this %shere%s.', 'Placeholders are HTML for a link.', 'wp-to-diaspora' ),
196
-							'<a href="http://serverfault.com/a/394835" target="_blank">', '</a>'
197
-						) . '
194
+            sprintf(
195
+              esc_html_x( 'If you maintain your own server, it\'s your job to keep the bundle up to date. You can find a short and simple way on how to do this %shere%s.', 'Placeholders are HTML for a link.', 'wp-to-diaspora' ),
196
+              '<a href="http://serverfault.com/a/394835" target="_blank">', '</a>'
197
+            ) . '
198 198
 					<li><strong>' . esc_html__( 'Quick "temporary" fix', 'wp-to-diaspora' ) . '</strong>: ' .
199
-						sprintf(
200
-							esc_html_x( 'As a temporary solution, you can download the up to date %sCA certificate bundle%s (Right-click &#8594; Save As...) and place the cacert.pem file at the top level of the WP to diaspora* plugin folder. This is a "last resort" option.', 'Placeholders are HTML for links.', 'wp-to-diaspora' ),
201
-							'<a href="http://curl.haxx.se/ca/cacert.pem" download>', '</a>'
202
-						)
203
-						. '<br><p>' .
204
-						$ssl_install_output
205
-						. '</p>
199
+            sprintf(
200
+              esc_html_x( 'As a temporary solution, you can download the up to date %sCA certificate bundle%s (Right-click &#8594; Save As...) and place the cacert.pem file at the top level of the WP to diaspora* plugin folder. This is a "last resort" option.', 'Placeholders are HTML for links.', 'wp-to-diaspora' ),
201
+              '<a href="http://curl.haxx.se/ca/cacert.pem" download>', '</a>'
202
+            )
203
+            . '<br><p>' .
204
+            $ssl_install_output
205
+            . '</p>
206 206
 				</ul>
207 207
 				<p class="dashicons-before dashicons-info">' . esc_html__( 'NOTE: If you choose the temporary option, the copy procedure needs to be done every time the plugin is updated because all files get replaced!', 'wp-to-diaspora' ) . '</p>',
208
-		) );
208
+    ) );
209 209
 
210
-		// Explain the meta box and the differences to the global defaults.
211
-		$screen->add_help_tab( array(
212
-			'id' => 'meta-box',
213
-			'title'   => esc_html__( 'Meta Box', 'wp-to-diaspora' ),
214
-			'content' => '<p><strong>' . esc_html__( 'The Meta Box is the new "WP to diaspora*" box you see when editing a post.', 'wp-to-diaspora' ) . '</strong></p>
210
+    // Explain the meta box and the differences to the global defaults.
211
+    $screen->add_help_tab( array(
212
+      'id' => 'meta-box',
213
+      'title'   => esc_html__( 'Meta Box', 'wp-to-diaspora' ),
214
+      'content' => '<p><strong>' . esc_html__( 'The Meta Box is the new "WP to diaspora*" box you see when editing a post.', 'wp-to-diaspora' ) . '</strong></p>
215 215
 				<p>' . esc_html__( 'When creating or editing a post, you will notice a new meta box called "WP to diaspora*" which has some options. These options are almost the same as the options you can find in the "Defaults" tab on the settings page. These options are post-specific though, meaning they override the global defaults for the post itself. You will see that the default values are filled in automatically, allowing you to change individual ones as you please.', 'wp-to-diaspora' ) . '</p>
216 216
 				<p>' . esc_html__( 'There are a few important differences to the settings page:', 'wp-to-diaspora' ) . '</p>
217 217
 				<ul>
218 218
 					<li><strong>' . esc_html__( 'Already posted to diaspora*', 'wp-to-diaspora' ) . '</strong>: ' .
219
-						esc_html__( 'If the post has already been posted to diaspora* a link to the diaspora* post will appear at the top.', 'wp-to-diaspora' ) . '
219
+            esc_html__( 'If the post has already been posted to diaspora* a link to the diaspora* post will appear at the top.', 'wp-to-diaspora' ) . '
220 220
 					<li><strong>' . esc_html__( 'Custom tags', 'wp-to-diaspora' ) . '</strong>: ' .
221
-						esc_html__( 'A list of tags that gets added to this post. Note that they are seperate from the WordPress post tags!', 'wp-to-diaspora' ) . '
221
+            esc_html__( 'A list of tags that gets added to this post. Note that they are seperate from the WordPress post tags!', 'wp-to-diaspora' ) . '
222 222
 				</ul>
223 223
 				<p class="dashicons-before dashicons-info">' . esc_html__( 'If you don\'t see the meta box, make sure the post type you\'re on has been added to the "Post types" list on the settings page. Also make sure it has been selected from the "Screen Options" at the top of the screen.', 'wp-to-diaspora' ) . '</p>',
224
-		) );
224
+    ) );
225 225
 
226
-		// Troubleshooting.
227
-		$screen->add_help_tab( array(
228
-			'id' => 'troubleshooting',
229
-			'title'   => esc_html__( 'Troubleshooting', 'wp-to-diaspora' ),
230
-			'content' => '<p><strong>' . esc_html__( 'Troubleshooting common errors.', 'wp-to-diaspora' ) . '</strong></p>
226
+    // Troubleshooting.
227
+    $screen->add_help_tab( array(
228
+      'id' => 'troubleshooting',
229
+      'title'   => esc_html__( 'Troubleshooting', 'wp-to-diaspora' ),
230
+      'content' => '<p><strong>' . esc_html__( 'Troubleshooting common errors.', 'wp-to-diaspora' ) . '</strong></p>
231 231
 				<p>' . esc_html__( 'Here are a few common errors and their possible solutions:', 'wp-to-diaspora' ) . '</p>
232 232
 				<ul>
233 233
 					<li><strong>' . esc_html( sprintf( __( 'Failed to initialise connection to pod "%s"', 'wp-to-diaspora' ), 'xyz' ) ) . '</strong>: ' .
234
-						esc_html__( 'This could have multiple reasons.' ) . '
234
+            esc_html__( 'This could have multiple reasons.' ) . '
235 235
 						<ul>
236 236
 							<li>' . esc_html__( 'Make sure that your pod domain is entered correctly.', 'wp-to-diaspora' ) . '
237 237
 							<li>' .
238
-								esc_html__( 'It might be an SSL problem.', 'wp-to-diaspora' ) .
239
-								sprintf( ' <a href="#" class="open-help-tab" data-help-tab="ssl">%s</a>', esc_html__( 'Learn More', 'wp-to-diaspora' ) ) . '
238
+                esc_html__( 'It might be an SSL problem.', 'wp-to-diaspora' ) .
239
+                sprintf( ' <a href="#" class="open-help-tab" data-help-tab="ssl">%s</a>', esc_html__( 'Learn More', 'wp-to-diaspora' ) ) . '
240 240
 							<li>' . esc_html__( 'The pod might be offline at the moment.', 'wp-to-diaspora' ) . '
241 241
 						</ul>
242 242
 					<li><strong>' . esc_html__( 'Login failed. Check your login details.', 'wp-to-diaspora' ) . '</strong>: ' .
243
-						esc_html__( 'Make sure that your username and password are entered correctly.', 'wp-to-diaspora' ) . '
243
+            esc_html__( 'Make sure that your username and password are entered correctly.', 'wp-to-diaspora' ) . '
244 244
 				</ul>',
245
-		) );
245
+    ) );
246 246
 
247
-		// Show different ways to contribute to the plugin.
248
-		$screen->add_help_tab( array(
249
-			'id' => 'contributing',
250
-			'title'   => esc_html__( 'Contributing', 'wp-to-diaspora' ),
251
-			'content' => '<p><strong>' . esc_html__( 'So you feel like contributing to the WP to diaspora* plugin? Great!', 'wp-to-diaspora' ) . '</strong></p>
247
+    // Show different ways to contribute to the plugin.
248
+    $screen->add_help_tab( array(
249
+      'id' => 'contributing',
250
+      'title'   => esc_html__( 'Contributing', 'wp-to-diaspora' ),
251
+      'content' => '<p><strong>' . esc_html__( 'So you feel like contributing to the WP to diaspora* plugin? Great!', 'wp-to-diaspora' ) . '</strong></p>
252 252
 				<p>' . esc_html__( 'There are many different ways that you can help out with this plugin:', 'wp-to-diaspora' ) . '</p>
253 253
 				<ul>
254 254
 					<li><a href="' . WP2D_EXT_GH_ISSUES_NEW . '" target="_blank">' . esc_html__( 'Report a bug', 'wp-to-diaspora' )           . '</a>
@@ -256,42 +256,42 @@  discard block
 block discarded – undo
256 256
 					<li><a href="' . WP2D_EXT_I18N          . '" target="_blank">' . esc_html__( 'Help with translations', 'wp-to-diaspora' ) . '</a>
257 257
 					<li><a href="' . WP2D_EXT_DONATE        . '" target="_blank">' . esc_html__( 'Make a donation', 'wp-to-diaspora' )        . '</a>
258 258
 				</ul>',
259
-		) );
260
-	}
259
+    ) );
260
+  }
261 261
 
262
-	/**
263
-	 * Add help tabs to the contextual help on the post pages.
264
-	 */
265
-	private function _add_post_type_help_tabs() {
266
-		get_current_screen()->add_help_tab( array(
267
-			'id'       => 'wp-to-diaspora',
268
-			'title'    => esc_html__( 'WP to diaspora*', 'wp-to-diaspora' ),
269
-			'content'  => '<p>' . sprintf(
270
-				esc_html__( 'For detailed information, refer to the contextual help on the %sWP to diaspora*%s settings page.', 'Placeholders represent the link.', 'wp-to-diaspora' ),
271
-				'<a href="options-general.php?page=wp_to_diaspora" target="_blank">', '</a>'
272
-			) . '</p>',
273
-		) );
274
-	}
262
+  /**
263
+   * Add help tabs to the contextual help on the post pages.
264
+   */
265
+  private function _add_post_type_help_tabs() {
266
+    get_current_screen()->add_help_tab( array(
267
+      'id'       => 'wp-to-diaspora',
268
+      'title'    => esc_html__( 'WP to diaspora*', 'wp-to-diaspora' ),
269
+      'content'  => '<p>' . sprintf(
270
+        esc_html__( 'For detailed information, refer to the contextual help on the %sWP to diaspora*%s settings page.', 'Placeholders represent the link.', 'wp-to-diaspora' ),
271
+        '<a href="options-general.php?page=wp_to_diaspora" target="_blank">', '</a>'
272
+      ) . '</p>',
273
+    ) );
274
+  }
275 275
 
276
-	/**
277
-	 * Get a link that directly opens a help tab via JS.
278
-	 *
279
-	 * @since 1.6.0
280
-	 *
281
-	 * @param WP_Error|string $error The WP_Error object with the tab id as data or the tab id itself.
282
-	 * @return string HTML link.
283
-	 */
284
-	public static function get_help_tab_quick_link( $error ) {
285
-		$help_tab = '';
286
-		if ( is_wp_error( $error ) && ( $error_data = $error->get_error_data() ) && array_key_exists( 'help_tab', $error_data ) ) {
287
-			$help_tab = $error_data['help_tab'];
288
-		} elseif ( is_string( $error ) ) {
289
-			$help_tab = $error;
290
-		}
291
-		if ( '' !== $help_tab ) {
292
-			return sprintf( '<a href="#" class="open-help-tab" data-help-tab="%1$s">%2$s</a>', $help_tab, esc_html__( 'Help', 'wp-to-diaspora' ) );
293
-		}
276
+  /**
277
+   * Get a link that directly opens a help tab via JS.
278
+   *
279
+   * @since 1.6.0
280
+   *
281
+   * @param WP_Error|string $error The WP_Error object with the tab id as data or the tab id itself.
282
+   * @return string HTML link.
283
+   */
284
+  public static function get_help_tab_quick_link( $error ) {
285
+    $help_tab = '';
286
+    if ( is_wp_error( $error ) && ( $error_data = $error->get_error_data() ) && array_key_exists( 'help_tab', $error_data ) ) {
287
+      $help_tab = $error_data['help_tab'];
288
+    } elseif ( is_string( $error ) ) {
289
+      $help_tab = $error;
290
+    }
291
+    if ( '' !== $help_tab ) {
292
+      return sprintf( '<a href="#" class="open-help-tab" data-help-tab="%1$s">%2$s</a>', $help_tab, esc_html__( 'Help', 'wp-to-diaspora' ) );
293
+    }
294 294
 
295
-		return '';
296
-	}
295
+    return '';
296
+  }
297 297
 }
Please login to merge, or discard this patch.
uninstall.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@
 block discarded – undo
7 7
  */
8 8
 
9 9
 // Exit if accessed directly.
10
-defined( 'WP_UNINSTALL_PLUGIN' ) || exit;
10
+defined('WP_UNINSTALL_PLUGIN') || exit;
11 11
 
12 12
 // Delete the WP2D settings.
13
-delete_option( 'wp_to_diaspora_settings' );
13
+delete_option('wp_to_diaspora_settings');
Please login to merge, or discard this patch.
lib/class-helpers.php 2 patches
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  */
8 8
 
9 9
 // Exit if accessed directly.
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 /**
13 13
  * Various helper methods.
@@ -26,19 +26,19 @@  discard block
 block discarded – undo
26 26
 	 *
27 27
 	 * @param string $text Text to add.
28 28
 	 */
29
-	public static function add_debugging( $text ) {
29
+	public static function add_debugging($text) {
30 30
 		// Make sure we're in debug mode.
31
-		if ( defined( 'WP2D_DEBUGGING' ) && true === WP2D_DEBUGGING ) {
31
+		if (defined('WP2D_DEBUGGING') && true === WP2D_DEBUGGING) {
32 32
 			$d = '';
33
-			foreach ( debug_backtrace() as $dbt ) {
34
-				extract( $dbt );
33
+			foreach (debug_backtrace() as $dbt) {
34
+				extract($dbt);
35 35
 				// Only trace back as far as the plugin goes.
36
-				if ( strstr( $file, plugin_dir_path( dirname( __FILE__ ) ) ) ) {
37
-					$d = sprintf( "%s%s%s [%s:%s]\n", $class, $type, $function, basename( $file ), $line ) . $d;
36
+				if (strstr($file, plugin_dir_path(dirname(__FILE__)))) {
37
+					$d = sprintf("%s%s%s [%s:%s]\n", $class, $type, $function, basename($file), $line).$d;
38 38
 				}
39 39
 			}
40 40
 
41
-			self::$_debugging .= sprintf( "%s\n%s\n", date( 'Y.m.d H:i:s' ), $d . $text );
41
+			self::$_debugging .= sprintf("%s\n%s\n", date('Y.m.d H:i:s'), $d.$text);
42 42
 
43 43
 			return true;
44 44
 		}
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 	 * @return string The debug output.
52 52
 	 */
53 53
 	public static function get_debugging() {
54
-		if ( defined( 'WP2D_DEBUGGING' ) && true === WP2D_DEBUGGING ) {
54
+		if (defined('WP2D_DEBUGGING') && true === WP2D_DEBUGGING) {
55 55
 			return self::$_debugging;
56 56
 		}
57 57
 		return false;
@@ -65,14 +65,14 @@  discard block
 block discarded – undo
65 65
 	 * @param array|string $input The string to be converted.
66 66
 	 * @return array The converted array.
67 67
 	 */
68
-	public static function str_to_arr( &$input ) {
69
-		if ( ! is_array( $input ) ) {
68
+	public static function str_to_arr(&$input) {
69
+		if ( ! is_array($input)) {
70 70
 			// Explode string > Trim each entry > Remove blanks > Re-index array.
71
-			$input = array_values( array_filter( array_map( 'trim', explode( ',', $input ) ) ) );
71
+			$input = array_values(array_filter(array_map('trim', explode(',', $input))));
72 72
 		} else {
73 73
 			// If we're already an array, make sure we return it clean.
74
-			self::arr_to_str( $input );
75
-			self::str_to_arr( $input );
74
+			self::arr_to_str($input);
75
+			self::str_to_arr($input);
76 76
 		}
77 77
 		return $input;
78 78
 	}
@@ -85,14 +85,14 @@  discard block
 block discarded – undo
85 85
 	 * @param array|string $input The array to be converted.
86 86
 	 * @return string The converted string.
87 87
 	 */
88
-	public static function arr_to_str( &$input ) {
89
-		if ( is_array( $input ) ) {
88
+	public static function arr_to_str(&$input) {
89
+		if (is_array($input)) {
90 90
 			// Trim each entry > Remove blanks > Implode them together.
91
-			$input = implode( ',', array_filter( array_map( 'trim', $input ) ) );
91
+			$input = implode(',', array_filter(array_map('trim', $input)));
92 92
 		} else {
93 93
 			// If we're already a string, make sure we return it clean.
94
-			self::str_to_arr( $input );
95
-			self::arr_to_str( $input );
94
+			self::str_to_arr($input);
95
+			self::arr_to_str($input);
96 96
 		}
97 97
 		return $input;
98 98
 	}
@@ -104,12 +104,12 @@  discard block
 block discarded – undo
104 104
 	 * @param string $key   The key used for the encryption.
105 105
 	 * @return string The encrypted string.
106 106
 	 */
107
-	public static function encrypt( $input, $key = AUTH_KEY ) {
108
-		if ( is_null( $input ) || '' === $input ) {
107
+	public static function encrypt($input, $key = AUTH_KEY) {
108
+		if (is_null($input) || '' === $input) {
109 109
 			return false;
110 110
 		}
111 111
 		global $wpdb;
112
-		return $wpdb->get_var( $wpdb->prepare( 'SELECT HEX(AES_ENCRYPT(%s,%s))', $input, $key ) );
112
+		return $wpdb->get_var($wpdb->prepare('SELECT HEX(AES_ENCRYPT(%s,%s))', $input, $key));
113 113
 	}
114 114
 
115 115
 	/**
@@ -119,12 +119,12 @@  discard block
 block discarded – undo
119 119
 	 * @param string $key   The key used for the decryption.
120 120
 	 * @return string The decrypted string.
121 121
 	 */
122
-	public static function decrypt( $input, $key = AUTH_KEY ) {
123
-		if ( is_null( $input ) || '' === $input ) {
122
+	public static function decrypt($input, $key = AUTH_KEY) {
123
+		if (is_null($input) || '' === $input) {
124 124
 			return false;
125 125
 		}
126 126
 		global $wpdb;
127
-		return $wpdb->get_var( $wpdb->prepare( 'SELECT AES_DECRYPT(UNHEX(%s),%s)', $input, $key ) );
127
+		return $wpdb->get_var($wpdb->prepare('SELECT AES_DECRYPT(UNHEX(%s),%s)', $input, $key));
128 128
 	}
129 129
 
130 130
 	/**
@@ -134,20 +134,20 @@  discard block
 block discarded – undo
134 134
 	 */
135 135
 	public static function api_quick_connect() {
136 136
 		$options   = WP2D_Options::instance();
137
-		$pod       = (string) $options->get_option( 'pod' );
137
+		$pod       = (string) $options->get_option('pod');
138 138
 		$is_secure = true;
139
-		$username  = (string) $options->get_option( 'username' );
140
-		$password  = WP2D_Helpers::decrypt( (string) $options->get_option( 'password' ) );
139
+		$username  = (string) $options->get_option('username');
140
+		$password  = WP2D_Helpers::decrypt((string) $options->get_option('password'));
141 141
 
142
-		$api = new WP2D_API( $pod, $is_secure );
142
+		$api = new WP2D_API($pod, $is_secure);
143 143
 
144 144
 		// This is necessary for correct error handling!
145
-		if ( $api->init() ) {
146
-			$api->login( $username, $password );
145
+		if ($api->init()) {
146
+			$api->login($username, $password);
147 147
 		}
148 148
 
149
-		if ( $api->has_last_error() ) {
150
-			self::add_debugging( $api->get_last_error() );
149
+		if ($api->has_last_error()) {
150
+			self::add_debugging($api->get_last_error());
151 151
 		}
152 152
 
153 153
 		return $api;
Please login to merge, or discard this patch.
Indentation   +138 added lines, -138 removed lines patch added patch discarded remove patch
@@ -14,142 +14,142 @@
 block discarded – undo
14 14
  */
15 15
 class WP2D_Helpers {
16 16
 
17
-	/**
18
-	 * Debug text that get's accumulated before output.
19
-	 *
20
-	 * @var string
21
-	 */
22
-	private static $_debugging = '';
23
-
24
-	/**
25
-	 * Add a line to the debug output. Include the stack trace to see where it's coming from.
26
-	 *
27
-	 * @param string $text Text to add.
28
-	 */
29
-	public static function add_debugging( $text ) {
30
-		// Make sure we're in debug mode.
31
-		if ( defined( 'WP2D_DEBUGGING' ) && true === WP2D_DEBUGGING ) {
32
-			$d = '';
33
-			foreach ( debug_backtrace() as $dbt ) {
34
-				extract( $dbt );
35
-				// Only trace back as far as the plugin goes.
36
-				if ( strstr( $file, plugin_dir_path( dirname( __FILE__ ) ) ) ) {
37
-					$d = sprintf( "%s%s%s [%s:%s]\n", $class, $type, $function, basename( $file ), $line ) . $d;
38
-				}
39
-			}
40
-
41
-			self::$_debugging .= sprintf( "%s\n%s\n", date( 'Y.m.d H:i:s' ), $d . $text );
42
-
43
-			return true;
44
-		}
45
-		return false;
46
-	}
47
-
48
-	/**
49
-	 * Return the debug output.
50
-	 *
51
-	 * @return string The debug output.
52
-	 */
53
-	public static function get_debugging() {
54
-		if ( defined( 'WP2D_DEBUGGING' ) && true === WP2D_DEBUGGING ) {
55
-			return self::$_debugging;
56
-		}
57
-		return false;
58
-	}
59
-
60
-	/**
61
-	 * Convert a string with comma seperated values to an array.
62
-	 *
63
-	 * @todo Make $input by value.
64
-	 *
65
-	 * @param array|string $input The string to be converted.
66
-	 * @return array The converted array.
67
-	 */
68
-	public static function str_to_arr( &$input ) {
69
-		if ( ! is_array( $input ) ) {
70
-			// Explode string > Trim each entry > Remove blanks > Re-index array.
71
-			$input = array_values( array_filter( array_map( 'trim', explode( ',', $input ) ) ) );
72
-		} else {
73
-			// If we're already an array, make sure we return it clean.
74
-			self::arr_to_str( $input );
75
-			self::str_to_arr( $input );
76
-		}
77
-		return $input;
78
-	}
79
-
80
-	/**
81
-	 * Convert an array to a string with comma seperated values.
82
-	 *
83
-	 * @todo Make $input by value.
84
-	 *
85
-	 * @param array|string $input The array to be converted.
86
-	 * @return string The converted string.
87
-	 */
88
-	public static function arr_to_str( &$input ) {
89
-		if ( is_array( $input ) ) {
90
-			// Trim each entry > Remove blanks > Implode them together.
91
-			$input = implode( ',', array_filter( array_map( 'trim', $input ) ) );
92
-		} else {
93
-			// If we're already a string, make sure we return it clean.
94
-			self::str_to_arr( $input );
95
-			self::arr_to_str( $input );
96
-		}
97
-		return $input;
98
-	}
99
-
100
-	/**
101
-	 * Encrypt the passed string with the passed key.
102
-	 *
103
-	 * @param string $input String to be encrypted.
104
-	 * @param string $key   The key used for the encryption.
105
-	 * @return string The encrypted string.
106
-	 */
107
-	public static function encrypt( $input, $key = AUTH_KEY ) {
108
-		if ( is_null( $input ) || '' === $input ) {
109
-			return false;
110
-		}
111
-		global $wpdb;
112
-		return $wpdb->get_var( $wpdb->prepare( 'SELECT HEX(AES_ENCRYPT(%s,%s))', $input, $key ) );
113
-	}
114
-
115
-	/**
116
-	 * Decrypt the passed string with the passed key.
117
-	 *
118
-	 * @param string $input String to be decrypted.
119
-	 * @param string $key   The key used for the decryption.
120
-	 * @return string The decrypted string.
121
-	 */
122
-	public static function decrypt( $input, $key = AUTH_KEY ) {
123
-		if ( is_null( $input ) || '' === $input ) {
124
-			return false;
125
-		}
126
-		global $wpdb;
127
-		return $wpdb->get_var( $wpdb->prepare( 'SELECT AES_DECRYPT(UNHEX(%s),%s)', $input, $key ) );
128
-	}
129
-
130
-	/**
131
-	 * Set up and return an API connection using the currently saved options..
132
-	 *
133
-	 * @return WP2D_API The API object.
134
-	 */
135
-	public static function api_quick_connect() {
136
-		$options   = WP2D_Options::instance();
137
-		$pod       = (string) $options->get_option( 'pod' );
138
-		$is_secure = true;
139
-		$username  = (string) $options->get_option( 'username' );
140
-		$password  = WP2D_Helpers::decrypt( (string) $options->get_option( 'password' ) );
141
-
142
-		$api = new WP2D_API( $pod, $is_secure );
143
-
144
-		// This is necessary for correct error handling!
145
-		if ( $api->init() ) {
146
-			$api->login( $username, $password );
147
-		}
148
-
149
-		if ( $api->has_last_error() ) {
150
-			self::add_debugging( $api->get_last_error() );
151
-		}
152
-
153
-		return $api;
154
-	}
17
+  /**
18
+   * Debug text that get's accumulated before output.
19
+   *
20
+   * @var string
21
+   */
22
+  private static $_debugging = '';
23
+
24
+  /**
25
+   * Add a line to the debug output. Include the stack trace to see where it's coming from.
26
+   *
27
+   * @param string $text Text to add.
28
+   */
29
+  public static function add_debugging( $text ) {
30
+    // Make sure we're in debug mode.
31
+    if ( defined( 'WP2D_DEBUGGING' ) && true === WP2D_DEBUGGING ) {
32
+      $d = '';
33
+      foreach ( debug_backtrace() as $dbt ) {
34
+        extract( $dbt );
35
+        // Only trace back as far as the plugin goes.
36
+        if ( strstr( $file, plugin_dir_path( dirname( __FILE__ ) ) ) ) {
37
+          $d = sprintf( "%s%s%s [%s:%s]\n", $class, $type, $function, basename( $file ), $line ) . $d;
38
+        }
39
+      }
40
+
41
+      self::$_debugging .= sprintf( "%s\n%s\n", date( 'Y.m.d H:i:s' ), $d . $text );
42
+
43
+      return true;
44
+    }
45
+    return false;
46
+  }
47
+
48
+  /**
49
+   * Return the debug output.
50
+   *
51
+   * @return string The debug output.
52
+   */
53
+  public static function get_debugging() {
54
+    if ( defined( 'WP2D_DEBUGGING' ) && true === WP2D_DEBUGGING ) {
55
+      return self::$_debugging;
56
+    }
57
+    return false;
58
+  }
59
+
60
+  /**
61
+   * Convert a string with comma seperated values to an array.
62
+   *
63
+   * @todo Make $input by value.
64
+   *
65
+   * @param array|string $input The string to be converted.
66
+   * @return array The converted array.
67
+   */
68
+  public static function str_to_arr( &$input ) {
69
+    if ( ! is_array( $input ) ) {
70
+      // Explode string > Trim each entry > Remove blanks > Re-index array.
71
+      $input = array_values( array_filter( array_map( 'trim', explode( ',', $input ) ) ) );
72
+    } else {
73
+      // If we're already an array, make sure we return it clean.
74
+      self::arr_to_str( $input );
75
+      self::str_to_arr( $input );
76
+    }
77
+    return $input;
78
+  }
79
+
80
+  /**
81
+   * Convert an array to a string with comma seperated values.
82
+   *
83
+   * @todo Make $input by value.
84
+   *
85
+   * @param array|string $input The array to be converted.
86
+   * @return string The converted string.
87
+   */
88
+  public static function arr_to_str( &$input ) {
89
+    if ( is_array( $input ) ) {
90
+      // Trim each entry > Remove blanks > Implode them together.
91
+      $input = implode( ',', array_filter( array_map( 'trim', $input ) ) );
92
+    } else {
93
+      // If we're already a string, make sure we return it clean.
94
+      self::str_to_arr( $input );
95
+      self::arr_to_str( $input );
96
+    }
97
+    return $input;
98
+  }
99
+
100
+  /**
101
+   * Encrypt the passed string with the passed key.
102
+   *
103
+   * @param string $input String to be encrypted.
104
+   * @param string $key   The key used for the encryption.
105
+   * @return string The encrypted string.
106
+   */
107
+  public static function encrypt( $input, $key = AUTH_KEY ) {
108
+    if ( is_null( $input ) || '' === $input ) {
109
+      return false;
110
+    }
111
+    global $wpdb;
112
+    return $wpdb->get_var( $wpdb->prepare( 'SELECT HEX(AES_ENCRYPT(%s,%s))', $input, $key ) );
113
+  }
114
+
115
+  /**
116
+   * Decrypt the passed string with the passed key.
117
+   *
118
+   * @param string $input String to be decrypted.
119
+   * @param string $key   The key used for the decryption.
120
+   * @return string The decrypted string.
121
+   */
122
+  public static function decrypt( $input, $key = AUTH_KEY ) {
123
+    if ( is_null( $input ) || '' === $input ) {
124
+      return false;
125
+    }
126
+    global $wpdb;
127
+    return $wpdb->get_var( $wpdb->prepare( 'SELECT AES_DECRYPT(UNHEX(%s),%s)', $input, $key ) );
128
+  }
129
+
130
+  /**
131
+   * Set up and return an API connection using the currently saved options..
132
+   *
133
+   * @return WP2D_API The API object.
134
+   */
135
+  public static function api_quick_connect() {
136
+    $options   = WP2D_Options::instance();
137
+    $pod       = (string) $options->get_option( 'pod' );
138
+    $is_secure = true;
139
+    $username  = (string) $options->get_option( 'username' );
140
+    $password  = WP2D_Helpers::decrypt( (string) $options->get_option( 'password' ) );
141
+
142
+    $api = new WP2D_API( $pod, $is_secure );
143
+
144
+    // This is necessary for correct error handling!
145
+    if ( $api->init() ) {
146
+      $api->login( $username, $password );
147
+    }
148
+
149
+    if ( $api->has_last_error() ) {
150
+      self::add_debugging( $api->get_last_error() );
151
+    }
152
+
153
+    return $api;
154
+  }
155 155
 }
Please login to merge, or discard this patch.
wp-to-diaspora.php 3 patches
Indentation   +395 added lines, -395 removed lines patch added patch discarded remove patch
@@ -40,405 +40,405 @@
 block discarded – undo
40 40
  */
41 41
 class WP_To_Diaspora {
42 42
 
43
-	/**
44
-	 * Only instance of this class.
45
-	 *
46
-	 * @var WP_To_Diaspora
47
-	 */
48
-	private static $_instance = null;
49
-
50
-	/**
51
-	 * The minimum required WordPress version.
52
-	 *
53
-	 * @since 1.5.4
54
-	 *
55
-	 * @var string
56
-	 */
57
-	private $_min_wp = '3.9.2';
58
-
59
-	/**
60
-	 * The minimum required PHP version.
61
-	 *
62
-	 * @since 1.5.4
63
-	 *
64
-	 * @var string
65
-	 */
66
-	private $_min_php = '5.3';
67
-
68
-	/**
69
-	 * Instance of the API class.
70
-	 *
71
-	 * @var WP2D_API
72
-	 */
73
-	private $_api = null;
74
-
75
-	/**
76
-	 * Create / Get the instance of this class.
77
-	 *
78
-	 * @return WP_To_Diaspora Instance of this class.
79
-	 */
80
-	public static function instance() {
81
-		if ( ! isset( self::$_instance ) ) {
82
-			self::$_instance = new self();
83
-			self::$_instance->_constants();
84
-			if ( self::$_instance->_version_check() ) {
85
-				self::$_instance->_includes();
86
-				self::$_instance->_setup();
87
-			} else {
88
-				self::$_instance = null;
89
-			}
90
-		}
91
-		return self::$_instance;
92
-	}
93
-
94
-	/**
95
-	 * Define all the required constants.
96
-	 *
97
-	 * @since 1.5.0
98
-	 */
99
-	private function _constants() {
100
-		// Are we in debugging mode?
101
-		if ( isset( $_GET['debugging'] ) ) {
102
-			define( 'WP2D_DEBUGGING', true );
103
-		}
104
-
105
-		define( 'WP2D_DIR', dirname( __FILE__ ) );
106
-		define( 'WP2D_LIB_DIR', WP2D_DIR . '/lib' );
107
-		define( 'WP2D_VENDOR_DIR', WP2D_DIR . '/vendor' );
108
-	}
109
-
110
-	/**
111
-	 * Check the minimum WordPress and PHP requirements.
112
-	 *
113
-	 * @since 1.5.4
114
-	 *
115
-	 * @return bool If version requirements are met.
116
-	 */
117
-	private function _version_check() {
118
-		// Check for version requirements.
119
-		if ( version_compare( $GLOBALS['wp_version'], $this->_min_wp, '<' )
120
-			|| version_compare( PHP_VERSION, $this->_min_php, '<' ) ) {
121
-			add_action( 'admin_notices', array( $this, 'deactivate' ) );
122
-			return false;
123
-		}
124
-
125
-		return true;
126
-	}
127
-
128
-	/**
129
-	 * Callback to deactivate plugin and display admin notice.
130
-	 *
131
-	 * @since 1.5.4
132
-	 */
133
-	public function deactivate() {
134
-		// First of all, deactivate the plugin.
135
-		deactivate_plugins( plugin_basename( __FILE__ ) );
136
-
137
-		// Get rid of the "Plugin activated" message.
138
-		unset( $_GET['activate'] );
139
-
140
-		// Then display the admin notice.
141
-		?>
43
+  /**
44
+   * Only instance of this class.
45
+   *
46
+   * @var WP_To_Diaspora
47
+   */
48
+  private static $_instance = null;
49
+
50
+  /**
51
+   * The minimum required WordPress version.
52
+   *
53
+   * @since 1.5.4
54
+   *
55
+   * @var string
56
+   */
57
+  private $_min_wp = '3.9.2';
58
+
59
+  /**
60
+   * The minimum required PHP version.
61
+   *
62
+   * @since 1.5.4
63
+   *
64
+   * @var string
65
+   */
66
+  private $_min_php = '5.3';
67
+
68
+  /**
69
+   * Instance of the API class.
70
+   *
71
+   * @var WP2D_API
72
+   */
73
+  private $_api = null;
74
+
75
+  /**
76
+   * Create / Get the instance of this class.
77
+   *
78
+   * @return WP_To_Diaspora Instance of this class.
79
+   */
80
+  public static function instance() {
81
+    if ( ! isset( self::$_instance ) ) {
82
+      self::$_instance = new self();
83
+      self::$_instance->_constants();
84
+      if ( self::$_instance->_version_check() ) {
85
+        self::$_instance->_includes();
86
+        self::$_instance->_setup();
87
+      } else {
88
+        self::$_instance = null;
89
+      }
90
+    }
91
+    return self::$_instance;
92
+  }
93
+
94
+  /**
95
+   * Define all the required constants.
96
+   *
97
+   * @since 1.5.0
98
+   */
99
+  private function _constants() {
100
+    // Are we in debugging mode?
101
+    if ( isset( $_GET['debugging'] ) ) {
102
+      define( 'WP2D_DEBUGGING', true );
103
+    }
104
+
105
+    define( 'WP2D_DIR', dirname( __FILE__ ) );
106
+    define( 'WP2D_LIB_DIR', WP2D_DIR . '/lib' );
107
+    define( 'WP2D_VENDOR_DIR', WP2D_DIR . '/vendor' );
108
+  }
109
+
110
+  /**
111
+   * Check the minimum WordPress and PHP requirements.
112
+   *
113
+   * @since 1.5.4
114
+   *
115
+   * @return bool If version requirements are met.
116
+   */
117
+  private function _version_check() {
118
+    // Check for version requirements.
119
+    if ( version_compare( $GLOBALS['wp_version'], $this->_min_wp, '<' )
120
+      || version_compare( PHP_VERSION, $this->_min_php, '<' ) ) {
121
+      add_action( 'admin_notices', array( $this, 'deactivate' ) );
122
+      return false;
123
+    }
124
+
125
+    return true;
126
+  }
127
+
128
+  /**
129
+   * Callback to deactivate plugin and display admin notice.
130
+   *
131
+   * @since 1.5.4
132
+   */
133
+  public function deactivate() {
134
+    // First of all, deactivate the plugin.
135
+    deactivate_plugins( plugin_basename( __FILE__ ) );
136
+
137
+    // Get rid of the "Plugin activated" message.
138
+    unset( $_GET['activate'] );
139
+
140
+    // Then display the admin notice.
141
+    ?>
142 142
 		<div class="error">
143 143
 			<p><?php echo esc_html( sprintf( 'WP to diaspora* requires at least WordPress %1$s (you have %2$s) and PHP %3$s (you have %4$s)!', $this->_min_wp, $GLOBALS['wp_version'], $this->_min_php, PHP_VERSION ) ); ?></p>
144 144
 		</div>
145 145
 		<?php
146
-	}
147
-
148
-	/**
149
-	 * Include all the required files.
150
-	 *
151
-	 * @since 1.5.0
152
-	 */
153
-	private function _includes() {
154
-		require WP2D_VENDOR_DIR . '/autoload.php';
155
-		require_once WP2D_LIB_DIR . '/class-api.php';
156
-		require_once WP2D_LIB_DIR . '/class-contextual-help.php';
157
-		require_once WP2D_LIB_DIR . '/class-helpers.php';
158
-		require_once WP2D_LIB_DIR . '/class-options.php';
159
-		require_once WP2D_LIB_DIR . '/class-post.php';
160
-	}
161
-
162
-	/**
163
-	 * Set up the plugin.
164
-	 */
165
-	private function _setup() {
166
-
167
-		// Load languages.
168
-		add_action( 'plugins_loaded', array( $this, 'l10n' ) );
169
-
170
-		// Add "Settings" link to plugin page.
171
-		add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'settings_link' ) );
172
-
173
-		// Perform any necessary data upgrades.
174
-		add_action( 'admin_init', array( $this, 'upgrade' ) );
175
-
176
-		// Enqueue CSS and JS scripts.
177
-		add_action( 'admin_enqueue_scripts', array( $this, 'admin_load_scripts' ) );
178
-
179
-		// Set up the options.
180
-		add_action( 'init', array( 'WP2D_Options', 'instance' ) );
181
-
182
-		// WP2D Post.
183
-		add_action( 'init', array( 'WP2D_Post', 'setup' ) );
184
-
185
-		// AJAX actions for loading pods, aspects and services.
186
-		add_action( 'wp_ajax_wp_to_diaspora_update_pod_list', array( $this, 'update_pod_list_callback' ) );
187
-		add_action( 'wp_ajax_wp_to_diaspora_update_aspects_list', array( $this, 'update_aspects_list_callback' ) );
188
-		add_action( 'wp_ajax_wp_to_diaspora_update_services_list', array( $this, 'update_services_list_callback' ) );
189
-
190
-		// Check the pod connection status on the options page.
191
-		add_action( 'wp_ajax_wp_to_diaspora_check_pod_connection_status', array( $this, 'check_pod_connection_status_callback' ) );
192
-	}
193
-
194
-	/**
195
-	 * Load the diaspora* API for ease of use.
196
-	 *
197
-	 * @return WP2D_API|boolean The API object, or false.
198
-	 */
199
-	private function _load_api() {
200
-		if ( ! isset( $this->_api ) ) {
201
-			$this->_api = WP2D_Helpers::api_quick_connect();
202
-		}
203
-		return $this->_api;
204
-	}
205
-
206
-	/**
207
-	 * Initialise upgrade sequence.
208
-	 */
209
-	public function upgrade() {
210
-		// Get the current options, or assign defaults.
211
-		$options = WP2D_Options::instance();
212
-		$version = $options->get_option( 'version' );
213
-
214
-		// If the versions differ, this is probably an update. Need to save updated options.
215
-		if ( WP2D_VERSION !== $version ) {
216
-
217
-			// Password is stored encrypted since version 1.2.7.
218
-			// When upgrading to it, the plain text password is encrypted and saved again.
219
-			if ( version_compare( $version, '1.2.7', '<' ) ) {
220
-				$options->set_option( 'password', WP2D_Helpers::encrypt( (string) $options->get_option( 'password' ) ) );
221
-			}
222
-
223
-			if ( version_compare( $version, '1.3.0', '<' ) ) {
224
-				// The 'user' setting is renamed to 'username'.
225
-				$options->set_option( 'username', $options->get_option( 'user' ) );
226
-				$options->set_option( 'user', null );
227
-
228
-				// Save tags as arrays instead of comma seperated values.
229
-				$global_tags = $options->get_option( 'global_tags' );
230
-				$options->set_option( 'global_tags', $options->validate_tags( $global_tags ) );
231
-			}
232
-
233
-			if ( version_compare( $version, '1.4.0', '<' ) ) {
234
-				// Turn tags_to_post string into an array.
235
-				$tags_to_post_old = $options->get_option( 'tags_to_post' );
236
-				$tags_to_post = array_filter( array(
237
-					( ( false !== strpos( $tags_to_post_old, 'g' ) ) ? 'global' : null ),
238
-					( ( false !== strpos( $tags_to_post_old, 'c' ) ) ? 'custom' : null ),
239
-					( ( false !== strpos( $tags_to_post_old, 'p' ) ) ? 'post'   : null ),
240
-				) );
241
-				$options->set_option( 'tags_to_post', $tags_to_post );
242
-			}
243
-
244
-			// Update version.
245
-			$options->set_option( 'version', WP2D_VERSION );
246
-			$options->save();
247
-		}
248
-	}
249
-
250
-	/**
251
-	 * Set up i18n.
252
-	 */
253
-	public function l10n() {
254
-		load_plugin_textdomain( 'wp-to-diaspora', false, 'wp-to-diaspora/languages' );
255
-	}
256
-
257
-	/**
258
-	 * Load scripts and styles for Settings and Post pages of allowed post types.
259
-	 */
260
-	public function admin_load_scripts() {
261
-		// Get the enabled post types to load the script for.
262
-		$enabled_post_types = WP2D_Options::instance()->get_option( 'enabled_post_types', array() );
263
-
264
-		// Get the screen to find out where we are.
265
-		$screen = get_current_screen();
266
-
267
-		// Only load the styles and scripts on the settings page and the allowed post types.
268
-		if ( 'settings_page_wp_to_diaspora' === $screen->id || ( in_array( $screen->post_type, $enabled_post_types ) && 'post' === $screen->base ) ) {
269
-			wp_enqueue_style( 'tag-it', plugins_url( '/css/jquery.tagit.css', __FILE__ ) );
270
-			wp_enqueue_style( 'chosen', plugins_url( '/css/chosen.min.css', __FILE__ ) );
271
-			wp_enqueue_style( 'wp-to-diaspora-admin', plugins_url( '/css/wp-to-diaspora.css', __FILE__ ) );
272
-			wp_enqueue_script( 'chosen', plugins_url( '/js/chosen.jquery.min.js', __FILE__ ), array( 'jquery' ), false, true );
273
-			wp_enqueue_script( 'tag-it', plugins_url( '/js/tag-it.min.js', __FILE__ ), array( 'jquery', 'jquery-ui-autocomplete' ), false, true );
274
-			wp_enqueue_script( 'wp-to-diaspora-admin', plugins_url( '/js/wp-to-diaspora.js', __FILE__ ), array( 'jquery' ), false, true );
275
-			// Javascript-specific l10n.
276
-			wp_localize_script( 'wp-to-diaspora-admin', 'WP2DL10n', array(
277
-				'no_services_connected' => __( 'No services connected yet.', 'wp-to-diaspora' ),
278
-				'sure_reset_defaults'   => __( 'Are you sure you want to reset to default values?', 'wp-to-diaspora' ),
279
-				'conn_testing'          => __( 'Testing connection...', 'wp-to-diaspora' ),
280
-				'conn_successful'       => __( 'Connection successful.', 'wp-to-diaspora' ),
281
-				'conn_failed'           => __( 'Connection failed.', 'wp-to-diaspora' ),
282
-			) );
283
-		}
284
-	}
285
-
286
-	/**
287
-	 * Add the "Settings" link to the plugins page.
288
-	 *
289
-	 * @param array $links Links to display for plugin on plugins page.
290
-	 * @return array Links to display for plugin on plugins page.
291
-	 */
292
-	public function settings_link( $links ) {
293
-		$links[] = '<a href="' . admin_url( 'options-general.php?page=wp_to_diaspora' ) . '">' . __( 'Settings' ) . '</a>';
294
-		return $links;
295
-	}
296
-
297
-	/**
298
-	 * Fetch the updated list of pods from podupti.me and save it to the settings.
299
-	 *
300
-	 * @return array The list of pods.
301
-	 */
302
-	private function _update_pod_list() {
303
-		// API url to fetch pods list from podupti.me.
304
-		$pod_list_url = 'http://podupti.me/api.php?format=json&key=4r45tg';
305
-		$pods = array();
306
-
307
-		// Get the response from the WP_HTTP request.
308
-		$response = wp_safe_remote_get( $pod_list_url );
309
-
310
-		if ( $json = wp_remote_retrieve_body( $response ) ) {
311
-			$pod_list = json_decode( $json );
312
-
313
-			if ( isset( $pod_list->pods ) ) {
314
-				foreach ( $pod_list->pods as $pod ) {
315
-					if ( 'no' === $pod->hidden ) {
316
-						$pods[] = array(
317
-							'secure' => $pod->secure,
318
-							'domain' => $pod->domain,
319
-						);
320
-					}
321
-				}
322
-
323
-				$options = WP2D_Options::instance();
324
-				$options->set_option( 'pod_list', $pods );
325
-				$options->save();
326
-			}
327
-		}
328
-
329
-		return $pods;
330
-	}
331
-
332
-	/**
333
-	 * Update the list of pods and return them for use with AJAX.
334
-	 */
335
-	public function update_pod_list_callback() {
336
-		wp_send_json( $this->_update_pod_list() );
337
-	}
338
-
339
-	/**
340
-	 * Fetch the list of aspects or services and save them to the settings.
341
-	 *
342
-	 * NOTE: When updating the lists, always force a fresh fetch.
343
-	 *
344
-	 * @param string $type Type of list to update.
345
-	 * @return array|boolean The list of aspects or services, false if an illegal parameter is passed.
346
-	 */
347
-	private function _update_aspects_services_list( $type ) {
348
-		// Check for correct argument value.
349
-		if ( ! in_array( $type, array( 'aspects', 'services' ) ) ) {
350
-			return false;
351
-		}
352
-
353
-		$options = WP2D_Options::instance();
354
-		$list    = $options->get_option( $type . '_list' );
355
-
356
-		// Make sure that we have at least the 'Public' aspect.
357
-		if ( 'aspects' === $type && empty( $list ) ) {
358
-			$list = array( 'public' => __( 'Public' ) );
359
-		}
360
-
361
-		// Set up the connection to diaspora*.
362
-		$api = $this->_load_api();
363
-
364
-		// If there was a problem loading the API, return false.
365
-		if ( $api->has_last_error() ) {
366
-			return false;
367
-		}
368
-
369
-		if ( 'aspects' === $type ) {
370
-			$list_new = $api->get_aspects( true );
371
-		} elseif ( 'services' === $type ) {
372
-			$list_new = $api->get_services( true );
373
-		}
374
-		// If the new list couldn't be fetched successfully, return false.
375
-		if ( $api->has_last_error() ) {
376
-			return false;
377
-		}
378
-
379
-		// We have a new list to save and return!
380
-		$options->set_option( $type . '_list', $list_new );
381
-		$options->save();
382
-
383
-		return $list_new;
384
-	}
385
-
386
-	/**
387
-	 * Update the list of aspects and return them for use with AJAX.
388
-	 */
389
-	public function update_aspects_list_callback() {
390
-		wp_send_json( $this->_update_aspects_services_list( 'aspects' ) );
391
-	}
392
-
393
-	/**
394
-	 * Update the list of services and return them for use with AJAX.
395
-	 */
396
-	public function update_services_list_callback() {
397
-		wp_send_json( $this->_update_aspects_services_list( 'services' ) );
398
-	}
399
-
400
-	/**
401
-	 * Check the pod connection status.
402
-	 *
403
-	 * @return string The status of the connection.
404
-	 */
405
-	private function _check_pod_connection_status() {
406
-		$options = WP2D_Options::instance();
407
-
408
-		$status = null;
409
-
410
-		if ( $options->is_pod_set_up() ) {
411
-			$status = ! $this->_load_api()->has_last_error();
412
-		}
413
-
414
-		return $status;
415
-	}
416
-
417
-	/**
418
-	 * Check the connection to the pod and return the status for use with AJAX.
419
-	 *
420
-	 * @todo esc_html
421
-	 */
422
-	public function check_pod_connection_status_callback() {
423
-		if ( isset( $_REQUEST['debugging'] ) && ! defined( 'WP2D_DEBUGGING' ) ) {
424
-			define( 'WP2D_DEBUGGING', true );
425
-		}
426
-
427
-		$status = $this->_check_pod_connection_status();
428
-
429
-		$data = array(
430
-			'debug'   => esc_textarea( WP2D_Helpers::get_debugging() ),
431
-			'message' => __( 'Connection successful.', 'wp-to-diaspora' ),
432
-		);
433
-
434
-		if ( true === $status ) {
435
-			wp_send_json_success( $data );
436
-		} elseif ( false === $status && $this->_load_api()->has_last_error() ) {
437
-			$data['message'] = $this->_load_api()->get_last_error() . ' ' . WP2D_Contextual_Help::get_help_tab_quick_link( $this->_load_api()->get_last_error_object() );
438
-			wp_send_json_error( $data );
439
-		}
440
-		// If $status === null, do nothing.
441
-	}
146
+  }
147
+
148
+  /**
149
+   * Include all the required files.
150
+   *
151
+   * @since 1.5.0
152
+   */
153
+  private function _includes() {
154
+    require WP2D_VENDOR_DIR . '/autoload.php';
155
+    require_once WP2D_LIB_DIR . '/class-api.php';
156
+    require_once WP2D_LIB_DIR . '/class-contextual-help.php';
157
+    require_once WP2D_LIB_DIR . '/class-helpers.php';
158
+    require_once WP2D_LIB_DIR . '/class-options.php';
159
+    require_once WP2D_LIB_DIR . '/class-post.php';
160
+  }
161
+
162
+  /**
163
+   * Set up the plugin.
164
+   */
165
+  private function _setup() {
166
+
167
+    // Load languages.
168
+    add_action( 'plugins_loaded', array( $this, 'l10n' ) );
169
+
170
+    // Add "Settings" link to plugin page.
171
+    add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'settings_link' ) );
172
+
173
+    // Perform any necessary data upgrades.
174
+    add_action( 'admin_init', array( $this, 'upgrade' ) );
175
+
176
+    // Enqueue CSS and JS scripts.
177
+    add_action( 'admin_enqueue_scripts', array( $this, 'admin_load_scripts' ) );
178
+
179
+    // Set up the options.
180
+    add_action( 'init', array( 'WP2D_Options', 'instance' ) );
181
+
182
+    // WP2D Post.
183
+    add_action( 'init', array( 'WP2D_Post', 'setup' ) );
184
+
185
+    // AJAX actions for loading pods, aspects and services.
186
+    add_action( 'wp_ajax_wp_to_diaspora_update_pod_list', array( $this, 'update_pod_list_callback' ) );
187
+    add_action( 'wp_ajax_wp_to_diaspora_update_aspects_list', array( $this, 'update_aspects_list_callback' ) );
188
+    add_action( 'wp_ajax_wp_to_diaspora_update_services_list', array( $this, 'update_services_list_callback' ) );
189
+
190
+    // Check the pod connection status on the options page.
191
+    add_action( 'wp_ajax_wp_to_diaspora_check_pod_connection_status', array( $this, 'check_pod_connection_status_callback' ) );
192
+  }
193
+
194
+  /**
195
+   * Load the diaspora* API for ease of use.
196
+   *
197
+   * @return WP2D_API|boolean The API object, or false.
198
+   */
199
+  private function _load_api() {
200
+    if ( ! isset( $this->_api ) ) {
201
+      $this->_api = WP2D_Helpers::api_quick_connect();
202
+    }
203
+    return $this->_api;
204
+  }
205
+
206
+  /**
207
+   * Initialise upgrade sequence.
208
+   */
209
+  public function upgrade() {
210
+    // Get the current options, or assign defaults.
211
+    $options = WP2D_Options::instance();
212
+    $version = $options->get_option( 'version' );
213
+
214
+    // If the versions differ, this is probably an update. Need to save updated options.
215
+    if ( WP2D_VERSION !== $version ) {
216
+
217
+      // Password is stored encrypted since version 1.2.7.
218
+      // When upgrading to it, the plain text password is encrypted and saved again.
219
+      if ( version_compare( $version, '1.2.7', '<' ) ) {
220
+        $options->set_option( 'password', WP2D_Helpers::encrypt( (string) $options->get_option( 'password' ) ) );
221
+      }
222
+
223
+      if ( version_compare( $version, '1.3.0', '<' ) ) {
224
+        // The 'user' setting is renamed to 'username'.
225
+        $options->set_option( 'username', $options->get_option( 'user' ) );
226
+        $options->set_option( 'user', null );
227
+
228
+        // Save tags as arrays instead of comma seperated values.
229
+        $global_tags = $options->get_option( 'global_tags' );
230
+        $options->set_option( 'global_tags', $options->validate_tags( $global_tags ) );
231
+      }
232
+
233
+      if ( version_compare( $version, '1.4.0', '<' ) ) {
234
+        // Turn tags_to_post string into an array.
235
+        $tags_to_post_old = $options->get_option( 'tags_to_post' );
236
+        $tags_to_post = array_filter( array(
237
+          ( ( false !== strpos( $tags_to_post_old, 'g' ) ) ? 'global' : null ),
238
+          ( ( false !== strpos( $tags_to_post_old, 'c' ) ) ? 'custom' : null ),
239
+          ( ( false !== strpos( $tags_to_post_old, 'p' ) ) ? 'post'   : null ),
240
+        ) );
241
+        $options->set_option( 'tags_to_post', $tags_to_post );
242
+      }
243
+
244
+      // Update version.
245
+      $options->set_option( 'version', WP2D_VERSION );
246
+      $options->save();
247
+    }
248
+  }
249
+
250
+  /**
251
+   * Set up i18n.
252
+   */
253
+  public function l10n() {
254
+    load_plugin_textdomain( 'wp-to-diaspora', false, 'wp-to-diaspora/languages' );
255
+  }
256
+
257
+  /**
258
+   * Load scripts and styles for Settings and Post pages of allowed post types.
259
+   */
260
+  public function admin_load_scripts() {
261
+    // Get the enabled post types to load the script for.
262
+    $enabled_post_types = WP2D_Options::instance()->get_option( 'enabled_post_types', array() );
263
+
264
+    // Get the screen to find out where we are.
265
+    $screen = get_current_screen();
266
+
267
+    // Only load the styles and scripts on the settings page and the allowed post types.
268
+    if ( 'settings_page_wp_to_diaspora' === $screen->id || ( in_array( $screen->post_type, $enabled_post_types ) && 'post' === $screen->base ) ) {
269
+      wp_enqueue_style( 'tag-it', plugins_url( '/css/jquery.tagit.css', __FILE__ ) );
270
+      wp_enqueue_style( 'chosen', plugins_url( '/css/chosen.min.css', __FILE__ ) );
271
+      wp_enqueue_style( 'wp-to-diaspora-admin', plugins_url( '/css/wp-to-diaspora.css', __FILE__ ) );
272
+      wp_enqueue_script( 'chosen', plugins_url( '/js/chosen.jquery.min.js', __FILE__ ), array( 'jquery' ), false, true );
273
+      wp_enqueue_script( 'tag-it', plugins_url( '/js/tag-it.min.js', __FILE__ ), array( 'jquery', 'jquery-ui-autocomplete' ), false, true );
274
+      wp_enqueue_script( 'wp-to-diaspora-admin', plugins_url( '/js/wp-to-diaspora.js', __FILE__ ), array( 'jquery' ), false, true );
275
+      // Javascript-specific l10n.
276
+      wp_localize_script( 'wp-to-diaspora-admin', 'WP2DL10n', array(
277
+        'no_services_connected' => __( 'No services connected yet.', 'wp-to-diaspora' ),
278
+        'sure_reset_defaults'   => __( 'Are you sure you want to reset to default values?', 'wp-to-diaspora' ),
279
+        'conn_testing'          => __( 'Testing connection...', 'wp-to-diaspora' ),
280
+        'conn_successful'       => __( 'Connection successful.', 'wp-to-diaspora' ),
281
+        'conn_failed'           => __( 'Connection failed.', 'wp-to-diaspora' ),
282
+      ) );
283
+    }
284
+  }
285
+
286
+  /**
287
+   * Add the "Settings" link to the plugins page.
288
+   *
289
+   * @param array $links Links to display for plugin on plugins page.
290
+   * @return array Links to display for plugin on plugins page.
291
+   */
292
+  public function settings_link( $links ) {
293
+    $links[] = '<a href="' . admin_url( 'options-general.php?page=wp_to_diaspora' ) . '">' . __( 'Settings' ) . '</a>';
294
+    return $links;
295
+  }
296
+
297
+  /**
298
+   * Fetch the updated list of pods from podupti.me and save it to the settings.
299
+   *
300
+   * @return array The list of pods.
301
+   */
302
+  private function _update_pod_list() {
303
+    // API url to fetch pods list from podupti.me.
304
+    $pod_list_url = 'http://podupti.me/api.php?format=json&key=4r45tg';
305
+    $pods = array();
306
+
307
+    // Get the response from the WP_HTTP request.
308
+    $response = wp_safe_remote_get( $pod_list_url );
309
+
310
+    if ( $json = wp_remote_retrieve_body( $response ) ) {
311
+      $pod_list = json_decode( $json );
312
+
313
+      if ( isset( $pod_list->pods ) ) {
314
+        foreach ( $pod_list->pods as $pod ) {
315
+          if ( 'no' === $pod->hidden ) {
316
+            $pods[] = array(
317
+              'secure' => $pod->secure,
318
+              'domain' => $pod->domain,
319
+            );
320
+          }
321
+        }
322
+
323
+        $options = WP2D_Options::instance();
324
+        $options->set_option( 'pod_list', $pods );
325
+        $options->save();
326
+      }
327
+    }
328
+
329
+    return $pods;
330
+  }
331
+
332
+  /**
333
+   * Update the list of pods and return them for use with AJAX.
334
+   */
335
+  public function update_pod_list_callback() {
336
+    wp_send_json( $this->_update_pod_list() );
337
+  }
338
+
339
+  /**
340
+   * Fetch the list of aspects or services and save them to the settings.
341
+   *
342
+   * NOTE: When updating the lists, always force a fresh fetch.
343
+   *
344
+   * @param string $type Type of list to update.
345
+   * @return array|boolean The list of aspects or services, false if an illegal parameter is passed.
346
+   */
347
+  private function _update_aspects_services_list( $type ) {
348
+    // Check for correct argument value.
349
+    if ( ! in_array( $type, array( 'aspects', 'services' ) ) ) {
350
+      return false;
351
+    }
352
+
353
+    $options = WP2D_Options::instance();
354
+    $list    = $options->get_option( $type . '_list' );
355
+
356
+    // Make sure that we have at least the 'Public' aspect.
357
+    if ( 'aspects' === $type && empty( $list ) ) {
358
+      $list = array( 'public' => __( 'Public' ) );
359
+    }
360
+
361
+    // Set up the connection to diaspora*.
362
+    $api = $this->_load_api();
363
+
364
+    // If there was a problem loading the API, return false.
365
+    if ( $api->has_last_error() ) {
366
+      return false;
367
+    }
368
+
369
+    if ( 'aspects' === $type ) {
370
+      $list_new = $api->get_aspects( true );
371
+    } elseif ( 'services' === $type ) {
372
+      $list_new = $api->get_services( true );
373
+    }
374
+    // If the new list couldn't be fetched successfully, return false.
375
+    if ( $api->has_last_error() ) {
376
+      return false;
377
+    }
378
+
379
+    // We have a new list to save and return!
380
+    $options->set_option( $type . '_list', $list_new );
381
+    $options->save();
382
+
383
+    return $list_new;
384
+  }
385
+
386
+  /**
387
+   * Update the list of aspects and return them for use with AJAX.
388
+   */
389
+  public function update_aspects_list_callback() {
390
+    wp_send_json( $this->_update_aspects_services_list( 'aspects' ) );
391
+  }
392
+
393
+  /**
394
+   * Update the list of services and return them for use with AJAX.
395
+   */
396
+  public function update_services_list_callback() {
397
+    wp_send_json( $this->_update_aspects_services_list( 'services' ) );
398
+  }
399
+
400
+  /**
401
+   * Check the pod connection status.
402
+   *
403
+   * @return string The status of the connection.
404
+   */
405
+  private function _check_pod_connection_status() {
406
+    $options = WP2D_Options::instance();
407
+
408
+    $status = null;
409
+
410
+    if ( $options->is_pod_set_up() ) {
411
+      $status = ! $this->_load_api()->has_last_error();
412
+    }
413
+
414
+    return $status;
415
+  }
416
+
417
+  /**
418
+   * Check the connection to the pod and return the status for use with AJAX.
419
+   *
420
+   * @todo esc_html
421
+   */
422
+  public function check_pod_connection_status_callback() {
423
+    if ( isset( $_REQUEST['debugging'] ) && ! defined( 'WP2D_DEBUGGING' ) ) {
424
+      define( 'WP2D_DEBUGGING', true );
425
+    }
426
+
427
+    $status = $this->_check_pod_connection_status();
428
+
429
+    $data = array(
430
+      'debug'   => esc_textarea( WP2D_Helpers::get_debugging() ),
431
+      'message' => __( 'Connection successful.', 'wp-to-diaspora' ),
432
+    );
433
+
434
+    if ( true === $status ) {
435
+      wp_send_json_success( $data );
436
+    } elseif ( false === $status && $this->_load_api()->has_last_error() ) {
437
+      $data['message'] = $this->_load_api()->get_last_error() . ' ' . WP2D_Contextual_Help::get_help_tab_quick_link( $this->_load_api()->get_last_error_object() );
438
+      wp_send_json_error( $data );
439
+    }
440
+    // If $status === null, do nothing.
441
+  }
442 442
 }
443 443
 
444 444
 // Get the party started!
Please login to merge, or discard this patch.
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
 	 * Add the "Settings" link to the plugins page.
288 288
 	 *
289 289
 	 * @param array $links Links to display for plugin on plugins page.
290
-	 * @return array Links to display for plugin on plugins page.
290
+	 * @return string[] Links to display for plugin on plugins page.
291 291
 	 */
292 292
 	public function settings_link( $links ) {
293 293
 		$links[] = '<a href="' . admin_url( 'options-general.php?page=wp_to_diaspora' ) . '">' . __( 'Settings' ) . '</a>';
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
 	/**
401 401
 	 * Check the pod connection status.
402 402
 	 *
403
-	 * @return string The status of the connection.
403
+	 * @return boolean|null The status of the connection.
404 404
 	 */
405 405
 	private function _check_pod_connection_status() {
406 406
 		$options = WP2D_Options::instance();
Please login to merge, or discard this patch.
Spacing   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -30,10 +30,10 @@  discard block
 block discarded – undo
30 30
  */
31 31
 
32 32
 // Exit if accessed directly.
33
-defined( 'ABSPATH' ) || exit;
33
+defined('ABSPATH') || exit;
34 34
 
35 35
 // Set the current version.
36
-define( 'WP2D_VERSION', '1.7.1' );
36
+define('WP2D_VERSION', '1.7.1');
37 37
 
38 38
 /**
39 39
  * WP to diaspora* main plugin class.
@@ -78,10 +78,10 @@  discard block
 block discarded – undo
78 78
 	 * @return WP_To_Diaspora Instance of this class.
79 79
 	 */
80 80
 	public static function instance() {
81
-		if ( ! isset( self::$_instance ) ) {
81
+		if ( ! isset(self::$_instance)) {
82 82
 			self::$_instance = new self();
83 83
 			self::$_instance->_constants();
84
-			if ( self::$_instance->_version_check() ) {
84
+			if (self::$_instance->_version_check()) {
85 85
 				self::$_instance->_includes();
86 86
 				self::$_instance->_setup();
87 87
 			} else {
@@ -98,13 +98,13 @@  discard block
 block discarded – undo
98 98
 	 */
99 99
 	private function _constants() {
100 100
 		// Are we in debugging mode?
101
-		if ( isset( $_GET['debugging'] ) ) {
102
-			define( 'WP2D_DEBUGGING', true );
101
+		if (isset($_GET['debugging'])) {
102
+			define('WP2D_DEBUGGING', true);
103 103
 		}
104 104
 
105
-		define( 'WP2D_DIR', dirname( __FILE__ ) );
106
-		define( 'WP2D_LIB_DIR', WP2D_DIR . '/lib' );
107
-		define( 'WP2D_VENDOR_DIR', WP2D_DIR . '/vendor' );
105
+		define('WP2D_DIR', dirname(__FILE__));
106
+		define('WP2D_LIB_DIR', WP2D_DIR.'/lib');
107
+		define('WP2D_VENDOR_DIR', WP2D_DIR.'/vendor');
108 108
 	}
109 109
 
110 110
 	/**
@@ -116,9 +116,9 @@  discard block
 block discarded – undo
116 116
 	 */
117 117
 	private function _version_check() {
118 118
 		// Check for version requirements.
119
-		if ( version_compare( $GLOBALS['wp_version'], $this->_min_wp, '<' )
120
-			|| version_compare( PHP_VERSION, $this->_min_php, '<' ) ) {
121
-			add_action( 'admin_notices', array( $this, 'deactivate' ) );
119
+		if (version_compare($GLOBALS['wp_version'], $this->_min_wp, '<')
120
+			|| version_compare(PHP_VERSION, $this->_min_php, '<')) {
121
+			add_action('admin_notices', array($this, 'deactivate'));
122 122
 			return false;
123 123
 		}
124 124
 
@@ -132,15 +132,15 @@  discard block
 block discarded – undo
132 132
 	 */
133 133
 	public function deactivate() {
134 134
 		// First of all, deactivate the plugin.
135
-		deactivate_plugins( plugin_basename( __FILE__ ) );
135
+		deactivate_plugins(plugin_basename(__FILE__));
136 136
 
137 137
 		// Get rid of the "Plugin activated" message.
138
-		unset( $_GET['activate'] );
138
+		unset($_GET['activate']);
139 139
 
140 140
 		// Then display the admin notice.
141 141
 		?>
142 142
 		<div class="error">
143
-			<p><?php echo esc_html( sprintf( 'WP to diaspora* requires at least WordPress %1$s (you have %2$s) and PHP %3$s (you have %4$s)!', $this->_min_wp, $GLOBALS['wp_version'], $this->_min_php, PHP_VERSION ) ); ?></p>
143
+			<p><?php echo esc_html(sprintf('WP to diaspora* requires at least WordPress %1$s (you have %2$s) and PHP %3$s (you have %4$s)!', $this->_min_wp, $GLOBALS['wp_version'], $this->_min_php, PHP_VERSION)); ?></p>
144 144
 		</div>
145 145
 		<?php
146 146
 	}
@@ -151,12 +151,12 @@  discard block
 block discarded – undo
151 151
 	 * @since 1.5.0
152 152
 	 */
153 153
 	private function _includes() {
154
-		require WP2D_VENDOR_DIR . '/autoload.php';
155
-		require_once WP2D_LIB_DIR . '/class-api.php';
156
-		require_once WP2D_LIB_DIR . '/class-contextual-help.php';
157
-		require_once WP2D_LIB_DIR . '/class-helpers.php';
158
-		require_once WP2D_LIB_DIR . '/class-options.php';
159
-		require_once WP2D_LIB_DIR . '/class-post.php';
154
+		require WP2D_VENDOR_DIR.'/autoload.php';
155
+		require_once WP2D_LIB_DIR.'/class-api.php';
156
+		require_once WP2D_LIB_DIR.'/class-contextual-help.php';
157
+		require_once WP2D_LIB_DIR.'/class-helpers.php';
158
+		require_once WP2D_LIB_DIR.'/class-options.php';
159
+		require_once WP2D_LIB_DIR.'/class-post.php';
160 160
 	}
161 161
 
162 162
 	/**
@@ -165,30 +165,30 @@  discard block
 block discarded – undo
165 165
 	private function _setup() {
166 166
 
167 167
 		// Load languages.
168
-		add_action( 'plugins_loaded', array( $this, 'l10n' ) );
168
+		add_action('plugins_loaded', array($this, 'l10n'));
169 169
 
170 170
 		// Add "Settings" link to plugin page.
171
-		add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'settings_link' ) );
171
+		add_filter('plugin_action_links_'.plugin_basename(__FILE__), array($this, 'settings_link'));
172 172
 
173 173
 		// Perform any necessary data upgrades.
174
-		add_action( 'admin_init', array( $this, 'upgrade' ) );
174
+		add_action('admin_init', array($this, 'upgrade'));
175 175
 
176 176
 		// Enqueue CSS and JS scripts.
177
-		add_action( 'admin_enqueue_scripts', array( $this, 'admin_load_scripts' ) );
177
+		add_action('admin_enqueue_scripts', array($this, 'admin_load_scripts'));
178 178
 
179 179
 		// Set up the options.
180
-		add_action( 'init', array( 'WP2D_Options', 'instance' ) );
180
+		add_action('init', array('WP2D_Options', 'instance'));
181 181
 
182 182
 		// WP2D Post.
183
-		add_action( 'init', array( 'WP2D_Post', 'setup' ) );
183
+		add_action('init', array('WP2D_Post', 'setup'));
184 184
 
185 185
 		// AJAX actions for loading pods, aspects and services.
186
-		add_action( 'wp_ajax_wp_to_diaspora_update_pod_list', array( $this, 'update_pod_list_callback' ) );
187
-		add_action( 'wp_ajax_wp_to_diaspora_update_aspects_list', array( $this, 'update_aspects_list_callback' ) );
188
-		add_action( 'wp_ajax_wp_to_diaspora_update_services_list', array( $this, 'update_services_list_callback' ) );
186
+		add_action('wp_ajax_wp_to_diaspora_update_pod_list', array($this, 'update_pod_list_callback'));
187
+		add_action('wp_ajax_wp_to_diaspora_update_aspects_list', array($this, 'update_aspects_list_callback'));
188
+		add_action('wp_ajax_wp_to_diaspora_update_services_list', array($this, 'update_services_list_callback'));
189 189
 
190 190
 		// Check the pod connection status on the options page.
191
-		add_action( 'wp_ajax_wp_to_diaspora_check_pod_connection_status', array( $this, 'check_pod_connection_status_callback' ) );
191
+		add_action('wp_ajax_wp_to_diaspora_check_pod_connection_status', array($this, 'check_pod_connection_status_callback'));
192 192
 	}
193 193
 
194 194
 	/**
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 	 * @return WP2D_API|boolean The API object, or false.
198 198
 	 */
199 199
 	private function _load_api() {
200
-		if ( ! isset( $this->_api ) ) {
200
+		if ( ! isset($this->_api)) {
201 201
 			$this->_api = WP2D_Helpers::api_quick_connect();
202 202
 		}
203 203
 		return $this->_api;
@@ -209,40 +209,40 @@  discard block
 block discarded – undo
209 209
 	public function upgrade() {
210 210
 		// Get the current options, or assign defaults.
211 211
 		$options = WP2D_Options::instance();
212
-		$version = $options->get_option( 'version' );
212
+		$version = $options->get_option('version');
213 213
 
214 214
 		// If the versions differ, this is probably an update. Need to save updated options.
215
-		if ( WP2D_VERSION !== $version ) {
215
+		if (WP2D_VERSION !== $version) {
216 216
 
217 217
 			// Password is stored encrypted since version 1.2.7.
218 218
 			// When upgrading to it, the plain text password is encrypted and saved again.
219
-			if ( version_compare( $version, '1.2.7', '<' ) ) {
220
-				$options->set_option( 'password', WP2D_Helpers::encrypt( (string) $options->get_option( 'password' ) ) );
219
+			if (version_compare($version, '1.2.7', '<')) {
220
+				$options->set_option('password', WP2D_Helpers::encrypt((string) $options->get_option('password')));
221 221
 			}
222 222
 
223
-			if ( version_compare( $version, '1.3.0', '<' ) ) {
223
+			if (version_compare($version, '1.3.0', '<')) {
224 224
 				// The 'user' setting is renamed to 'username'.
225
-				$options->set_option( 'username', $options->get_option( 'user' ) );
226
-				$options->set_option( 'user', null );
225
+				$options->set_option('username', $options->get_option('user'));
226
+				$options->set_option('user', null);
227 227
 
228 228
 				// Save tags as arrays instead of comma seperated values.
229
-				$global_tags = $options->get_option( 'global_tags' );
230
-				$options->set_option( 'global_tags', $options->validate_tags( $global_tags ) );
229
+				$global_tags = $options->get_option('global_tags');
230
+				$options->set_option('global_tags', $options->validate_tags($global_tags));
231 231
 			}
232 232
 
233
-			if ( version_compare( $version, '1.4.0', '<' ) ) {
233
+			if (version_compare($version, '1.4.0', '<')) {
234 234
 				// Turn tags_to_post string into an array.
235
-				$tags_to_post_old = $options->get_option( 'tags_to_post' );
236
-				$tags_to_post = array_filter( array(
237
-					( ( false !== strpos( $tags_to_post_old, 'g' ) ) ? 'global' : null ),
238
-					( ( false !== strpos( $tags_to_post_old, 'c' ) ) ? 'custom' : null ),
239
-					( ( false !== strpos( $tags_to_post_old, 'p' ) ) ? 'post'   : null ),
240
-				) );
241
-				$options->set_option( 'tags_to_post', $tags_to_post );
235
+				$tags_to_post_old = $options->get_option('tags_to_post');
236
+				$tags_to_post = array_filter(array(
237
+					((false !== strpos($tags_to_post_old, 'g')) ? 'global' : null),
238
+					((false !== strpos($tags_to_post_old, 'c')) ? 'custom' : null),
239
+					((false !== strpos($tags_to_post_old, 'p')) ? 'post' : null),
240
+				));
241
+				$options->set_option('tags_to_post', $tags_to_post);
242 242
 			}
243 243
 
244 244
 			// Update version.
245
-			$options->set_option( 'version', WP2D_VERSION );
245
+			$options->set_option('version', WP2D_VERSION);
246 246
 			$options->save();
247 247
 		}
248 248
 	}
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 	 * Set up i18n.
252 252
 	 */
253 253
 	public function l10n() {
254
-		load_plugin_textdomain( 'wp-to-diaspora', false, 'wp-to-diaspora/languages' );
254
+		load_plugin_textdomain('wp-to-diaspora', false, 'wp-to-diaspora/languages');
255 255
 	}
256 256
 
257 257
 	/**
@@ -259,27 +259,27 @@  discard block
 block discarded – undo
259 259
 	 */
260 260
 	public function admin_load_scripts() {
261 261
 		// Get the enabled post types to load the script for.
262
-		$enabled_post_types = WP2D_Options::instance()->get_option( 'enabled_post_types', array() );
262
+		$enabled_post_types = WP2D_Options::instance()->get_option('enabled_post_types', array());
263 263
 
264 264
 		// Get the screen to find out where we are.
265 265
 		$screen = get_current_screen();
266 266
 
267 267
 		// Only load the styles and scripts on the settings page and the allowed post types.
268
-		if ( 'settings_page_wp_to_diaspora' === $screen->id || ( in_array( $screen->post_type, $enabled_post_types ) && 'post' === $screen->base ) ) {
269
-			wp_enqueue_style( 'tag-it', plugins_url( '/css/jquery.tagit.css', __FILE__ ) );
270
-			wp_enqueue_style( 'chosen', plugins_url( '/css/chosen.min.css', __FILE__ ) );
271
-			wp_enqueue_style( 'wp-to-diaspora-admin', plugins_url( '/css/wp-to-diaspora.css', __FILE__ ) );
272
-			wp_enqueue_script( 'chosen', plugins_url( '/js/chosen.jquery.min.js', __FILE__ ), array( 'jquery' ), false, true );
273
-			wp_enqueue_script( 'tag-it', plugins_url( '/js/tag-it.min.js', __FILE__ ), array( 'jquery', 'jquery-ui-autocomplete' ), false, true );
274
-			wp_enqueue_script( 'wp-to-diaspora-admin', plugins_url( '/js/wp-to-diaspora.js', __FILE__ ), array( 'jquery' ), false, true );
268
+		if ('settings_page_wp_to_diaspora' === $screen->id || (in_array($screen->post_type, $enabled_post_types) && 'post' === $screen->base)) {
269
+			wp_enqueue_style('tag-it', plugins_url('/css/jquery.tagit.css', __FILE__));
270
+			wp_enqueue_style('chosen', plugins_url('/css/chosen.min.css', __FILE__));
271
+			wp_enqueue_style('wp-to-diaspora-admin', plugins_url('/css/wp-to-diaspora.css', __FILE__));
272
+			wp_enqueue_script('chosen', plugins_url('/js/chosen.jquery.min.js', __FILE__), array('jquery'), false, true);
273
+			wp_enqueue_script('tag-it', plugins_url('/js/tag-it.min.js', __FILE__), array('jquery', 'jquery-ui-autocomplete'), false, true);
274
+			wp_enqueue_script('wp-to-diaspora-admin', plugins_url('/js/wp-to-diaspora.js', __FILE__), array('jquery'), false, true);
275 275
 			// Javascript-specific l10n.
276
-			wp_localize_script( 'wp-to-diaspora-admin', 'WP2DL10n', array(
277
-				'no_services_connected' => __( 'No services connected yet.', 'wp-to-diaspora' ),
278
-				'sure_reset_defaults'   => __( 'Are you sure you want to reset to default values?', 'wp-to-diaspora' ),
279
-				'conn_testing'          => __( 'Testing connection...', 'wp-to-diaspora' ),
280
-				'conn_successful'       => __( 'Connection successful.', 'wp-to-diaspora' ),
281
-				'conn_failed'           => __( 'Connection failed.', 'wp-to-diaspora' ),
282
-			) );
276
+			wp_localize_script('wp-to-diaspora-admin', 'WP2DL10n', array(
277
+				'no_services_connected' => __('No services connected yet.', 'wp-to-diaspora'),
278
+				'sure_reset_defaults'   => __('Are you sure you want to reset to default values?', 'wp-to-diaspora'),
279
+				'conn_testing'          => __('Testing connection...', 'wp-to-diaspora'),
280
+				'conn_successful'       => __('Connection successful.', 'wp-to-diaspora'),
281
+				'conn_failed'           => __('Connection failed.', 'wp-to-diaspora'),
282
+			));
283 283
 		}
284 284
 	}
285 285
 
@@ -289,8 +289,8 @@  discard block
 block discarded – undo
289 289
 	 * @param array $links Links to display for plugin on plugins page.
290 290
 	 * @return array Links to display for plugin on plugins page.
291 291
 	 */
292
-	public function settings_link( $links ) {
293
-		$links[] = '<a href="' . admin_url( 'options-general.php?page=wp_to_diaspora' ) . '">' . __( 'Settings' ) . '</a>';
292
+	public function settings_link($links) {
293
+		$links[] = '<a href="'.admin_url('options-general.php?page=wp_to_diaspora').'">'.__('Settings').'</a>';
294 294
 		return $links;
295 295
 	}
296 296
 
@@ -305,14 +305,14 @@  discard block
 block discarded – undo
305 305
 		$pods = array();
306 306
 
307 307
 		// Get the response from the WP_HTTP request.
308
-		$response = wp_safe_remote_get( $pod_list_url );
308
+		$response = wp_safe_remote_get($pod_list_url);
309 309
 
310
-		if ( $json = wp_remote_retrieve_body( $response ) ) {
311
-			$pod_list = json_decode( $json );
310
+		if ($json = wp_remote_retrieve_body($response)) {
311
+			$pod_list = json_decode($json);
312 312
 
313
-			if ( isset( $pod_list->pods ) ) {
314
-				foreach ( $pod_list->pods as $pod ) {
315
-					if ( 'no' === $pod->hidden ) {
313
+			if (isset($pod_list->pods)) {
314
+				foreach ($pod_list->pods as $pod) {
315
+					if ('no' === $pod->hidden) {
316 316
 						$pods[] = array(
317 317
 							'secure' => $pod->secure,
318 318
 							'domain' => $pod->domain,
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
 				}
322 322
 
323 323
 				$options = WP2D_Options::instance();
324
-				$options->set_option( 'pod_list', $pods );
324
+				$options->set_option('pod_list', $pods);
325 325
 				$options->save();
326 326
 			}
327 327
 		}
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 	 * Update the list of pods and return them for use with AJAX.
334 334
 	 */
335 335
 	public function update_pod_list_callback() {
336
-		wp_send_json( $this->_update_pod_list() );
336
+		wp_send_json($this->_update_pod_list());
337 337
 	}
338 338
 
339 339
 	/**
@@ -344,40 +344,40 @@  discard block
 block discarded – undo
344 344
 	 * @param string $type Type of list to update.
345 345
 	 * @return array|boolean The list of aspects or services, false if an illegal parameter is passed.
346 346
 	 */
347
-	private function _update_aspects_services_list( $type ) {
347
+	private function _update_aspects_services_list($type) {
348 348
 		// Check for correct argument value.
349
-		if ( ! in_array( $type, array( 'aspects', 'services' ) ) ) {
349
+		if ( ! in_array($type, array('aspects', 'services'))) {
350 350
 			return false;
351 351
 		}
352 352
 
353 353
 		$options = WP2D_Options::instance();
354
-		$list    = $options->get_option( $type . '_list' );
354
+		$list    = $options->get_option($type.'_list');
355 355
 
356 356
 		// Make sure that we have at least the 'Public' aspect.
357
-		if ( 'aspects' === $type && empty( $list ) ) {
358
-			$list = array( 'public' => __( 'Public' ) );
357
+		if ('aspects' === $type && empty($list)) {
358
+			$list = array('public' => __('Public'));
359 359
 		}
360 360
 
361 361
 		// Set up the connection to diaspora*.
362 362
 		$api = $this->_load_api();
363 363
 
364 364
 		// If there was a problem loading the API, return false.
365
-		if ( $api->has_last_error() ) {
365
+		if ($api->has_last_error()) {
366 366
 			return false;
367 367
 		}
368 368
 
369
-		if ( 'aspects' === $type ) {
370
-			$list_new = $api->get_aspects( true );
371
-		} elseif ( 'services' === $type ) {
372
-			$list_new = $api->get_services( true );
369
+		if ('aspects' === $type) {
370
+			$list_new = $api->get_aspects(true);
371
+		} elseif ('services' === $type) {
372
+			$list_new = $api->get_services(true);
373 373
 		}
374 374
 		// If the new list couldn't be fetched successfully, return false.
375
-		if ( $api->has_last_error() ) {
375
+		if ($api->has_last_error()) {
376 376
 			return false;
377 377
 		}
378 378
 
379 379
 		// We have a new list to save and return!
380
-		$options->set_option( $type . '_list', $list_new );
380
+		$options->set_option($type.'_list', $list_new);
381 381
 		$options->save();
382 382
 
383 383
 		return $list_new;
@@ -387,14 +387,14 @@  discard block
 block discarded – undo
387 387
 	 * Update the list of aspects and return them for use with AJAX.
388 388
 	 */
389 389
 	public function update_aspects_list_callback() {
390
-		wp_send_json( $this->_update_aspects_services_list( 'aspects' ) );
390
+		wp_send_json($this->_update_aspects_services_list('aspects'));
391 391
 	}
392 392
 
393 393
 	/**
394 394
 	 * Update the list of services and return them for use with AJAX.
395 395
 	 */
396 396
 	public function update_services_list_callback() {
397
-		wp_send_json( $this->_update_aspects_services_list( 'services' ) );
397
+		wp_send_json($this->_update_aspects_services_list('services'));
398 398
 	}
399 399
 
400 400
 	/**
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
 
408 408
 		$status = null;
409 409
 
410
-		if ( $options->is_pod_set_up() ) {
410
+		if ($options->is_pod_set_up()) {
411 411
 			$status = ! $this->_load_api()->has_last_error();
412 412
 		}
413 413
 
@@ -420,22 +420,22 @@  discard block
 block discarded – undo
420 420
 	 * @todo esc_html
421 421
 	 */
422 422
 	public function check_pod_connection_status_callback() {
423
-		if ( isset( $_REQUEST['debugging'] ) && ! defined( 'WP2D_DEBUGGING' ) ) {
424
-			define( 'WP2D_DEBUGGING', true );
423
+		if (isset($_REQUEST['debugging']) && ! defined('WP2D_DEBUGGING')) {
424
+			define('WP2D_DEBUGGING', true);
425 425
 		}
426 426
 
427 427
 		$status = $this->_check_pod_connection_status();
428 428
 
429 429
 		$data = array(
430
-			'debug'   => esc_textarea( WP2D_Helpers::get_debugging() ),
431
-			'message' => __( 'Connection successful.', 'wp-to-diaspora' ),
430
+			'debug'   => esc_textarea(WP2D_Helpers::get_debugging()),
431
+			'message' => __('Connection successful.', 'wp-to-diaspora'),
432 432
 		);
433 433
 
434
-		if ( true === $status ) {
435
-			wp_send_json_success( $data );
436
-		} elseif ( false === $status && $this->_load_api()->has_last_error() ) {
437
-			$data['message'] = $this->_load_api()->get_last_error() . ' ' . WP2D_Contextual_Help::get_help_tab_quick_link( $this->_load_api()->get_last_error_object() );
438
-			wp_send_json_error( $data );
434
+		if (true === $status) {
435
+			wp_send_json_success($data);
436
+		} elseif (false === $status && $this->_load_api()->has_last_error()) {
437
+			$data['message'] = $this->_load_api()->get_last_error().' '.WP2D_Contextual_Help::get_help_tab_quick_link($this->_load_api()->get_last_error_object());
438
+			wp_send_json_error($data);
439 439
 		}
440 440
 		// If $status === null, do nothing.
441 441
 	}
Please login to merge, or discard this patch.