Passed
Push — ci ( 38d7bc...9f72b5 )
by litefeel
03:33
created
views/textarea-setting-field.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -5,8 +5,8 @@
 block discarded – undo
5 5
  */
6 6
 
7 7
 ?>
8
-<?php $value = get_option( $args['name'], $args['default'] ); ?>
9
-<textarea name="<?php echo esc_attr( $args['name'] ); ?>" id="<?php echo esc_attr( $args['name'] ); ?>" rows="10" cols="40">
10
-<?php echo esc_attr( $value ); ?>
8
+<?php $value = get_option($args['name'], $args['default']); ?>
9
+<textarea name="<?php echo esc_attr($args['name']); ?>" id="<?php echo esc_attr($args['name']); ?>" rows="10" cols="40">
10
+<?php echo esc_attr($value); ?>
11 11
 </textarea>
12 12
 <p class="description"><?php echo $args['help_text']; ?></p>
Please login to merge, or discard this patch.
views/options.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -6,27 +6,27 @@
 block discarded – undo
6 6
 
7 7
 ?>
8 8
 <div class="wrap">
9
-	<h2><?php esc_html_e( 'Writing On GitHub', 'writing-on-github' ); ?></h2>
9
+	<h2><?php esc_html_e('Writing On GitHub', 'writing-on-github'); ?></h2>
10 10
 
11 11
 	<form method="post" action="options.php">
12
-		<?php settings_fields( Writing_On_GitHub::$text_domain ); ?>
13
-		<?php do_settings_sections( Writing_On_GitHub::$text_domain ); ?>
12
+		<?php settings_fields(Writing_On_GitHub::$text_domain); ?>
13
+		<?php do_settings_sections(Writing_On_GitHub::$text_domain); ?>
14 14
 		<table class="form-table">
15 15
 			<tr>
16
-				<th scope="row"><?php esc_html_e( 'Webhook callback', 'writing-on-github' ); ?></th>
17
-				<td><code><?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>?action=wogh_push_request</code></td>
16
+				<th scope="row"><?php esc_html_e('Webhook callback', 'writing-on-github'); ?></th>
17
+				<td><code><?php echo esc_url(admin_url('admin-ajax.php')); ?>?action=wogh_push_request</code></td>
18 18
 			</tr>
19 19
 			<tr>
20
-				<th scope="row"><?php esc_html_e( 'Bulk actions', 'writing-on-github' ); ?></th>
20
+				<th scope="row"><?php esc_html_e('Bulk actions', 'writing-on-github'); ?></th>
21 21
 				<td>
22
-					<a href="<?php echo esc_url( add_query_arg( array( 'action' => 'export' ) ) ); ?>">
23
-						<?php esc_html_e( 'Export to GitHub', 'writing-on-github' ); ?>
22
+					<a href="<?php echo esc_url(add_query_arg(array('action' => 'export'))); ?>">
23
+						<?php esc_html_e('Export to GitHub', 'writing-on-github'); ?>
24 24
 					</a> |
25
-                    <a href="<?php echo esc_url( add_query_arg( array( 'action' => 'force_export' ) ) ); ?>">
26
-                        <?php esc_html_e( 'Force export to GitHub', 'writing-on-github' ); ?>
25
+                    <a href="<?php echo esc_url(add_query_arg(array('action' => 'force_export'))); ?>">
26
+                        <?php esc_html_e('Force export to GitHub', 'writing-on-github'); ?>
27 27
                     </a> |
28
-					<a href="<?php echo esc_url( add_query_arg( array( 'action' => 'import' ) ) ); ?>">
29
-						<?php esc_html_e( 'Import from GitHub', 'writing-on-github' ); ?>
28
+					<a href="<?php echo esc_url(add_query_arg(array('action' => 'import'))); ?>">
29
+						<?php esc_html_e('Import from GitHub', 'writing-on-github'); ?>
30 30
 					</a>
31 31
 				</td>
32 32
 		</table>
Please login to merge, or discard this patch.
views/user-setting-field.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@
 block discarded – undo
1
-<?php $value = get_option( $args['name'], $args['default'] ); ?>
2
-<select name="<?php echo esc_attr( $args['name'] ) ?>" id="<?php echo esc_attr( $args['name'] ) ?>">
3
-	<?php foreach ( get_users() as $user ) : ?>
4
-		<option value="<?php echo esc_attr( $user->ID ); ?>"<?php echo (int) $value === $user->ID ? ' selected' : '';?>>
5
-			<?php echo esc_html( $user->display_name ); ?>
1
+<?php $value = get_option($args['name'], $args['default']); ?>
2
+<select name="<?php echo esc_attr($args['name']) ?>" id="<?php echo esc_attr($args['name']) ?>">
3
+	<?php foreach (get_users() as $user) : ?>
4
+		<option value="<?php echo esc_attr($user->ID); ?>"<?php echo (int) $value === $user->ID ? ' selected' : ''; ?>>
5
+			<?php echo esc_html($user->display_name); ?>
6 6
 		</option>
7 7
 	<?php endforeach; ?>
8 8
 </select>
Please login to merge, or discard this patch.
views/checkbox-setting-field.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -5,6 +5,6 @@
 block discarded – undo
5 5
  */
6 6
 
7 7
 ?>
8
-<?php $value = get_option( $args['name'], $args['default'] ); ?>
9
-<input type="checkbox" name="<?php echo esc_attr( $args['name'] ); ?>" id="<?php echo esc_attr( $args['name'] ); ?>" value="yes" <?php echo 'yes' === $value ? 'checked' : '';  ?> />
8
+<?php $value = get_option($args['name'], $args['default']); ?>
9
+<input type="checkbox" name="<?php echo esc_attr($args['name']); ?>" id="<?php echo esc_attr($args['name']); ?>" value="yes" <?php echo 'yes' === $value ? 'checked' : ''; ?> />
10 10
 <p class="description"><?php echo $args['help_text']; ?></p>
Please login to merge, or discard this patch.
views/setting-field.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -5,6 +5,6 @@
 block discarded – undo
5 5
  */
6 6
 
7 7
 ?>
8
-<?php $value = get_option( $args['name'], $args['default'] ); ?>
9
-<input name="<?php echo esc_attr( $args['name'] ); ?>" id="<?php echo esc_attr( $args['name'] ); ?>" type="<?php echo 'wogh_secret' === $args['name'] ? 'password' : 'text'; ?>" value="<?php echo esc_attr( $value ); ?>" />
8
+<?php $value = get_option($args['name'], $args['default']); ?>
9
+<input name="<?php echo esc_attr($args['name']); ?>" id="<?php echo esc_attr($args['name']); ?>" type="<?php echo 'wogh_secret' === $args['name'] ? 'password' : 'text'; ?>" value="<?php echo esc_attr($value); ?>" />
10 10
 <p class="description"><?php echo $args['help_text']; ?></p>
Please login to merge, or discard this patch.
writing-on-github.php 2 patches
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 // This fixes function duplication during unit testing.
15 15
 $path = dirname( __FILE__ ) . '/vendor/autoload.php';
16 16
 if ( file_exists( $path ) ) {
17
-    require_once( $path );
17
+	require_once( $path );
18 18
 }
19 19
 
20 20
 add_action( 'plugins_loaded', array( new Writing_On_GitHub, 'boot' ) );
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 		add_action( 'save_post', array( $this->controller, 'export_post' ) );
132 132
 		add_action( 'delete_post', array( $this->controller, 'delete_post' ) );
133 133
 		add_action( 'wp_ajax_nopriv_wogh_push_request', array( $this->controller, 'pull_posts' ) );
134
-        add_action( 'wogh_export', array( $this->controller, 'export_all' ), 10, 2 );
134
+		add_action( 'wogh_export', array( $this->controller, 'export_all' ), 10, 2 );
135 135
 		add_action( 'wogh_import', array( $this->controller, 'import_master' ), 10, 1 );
136 136
 		add_filter( 'get_edit_post_link', array( $this, 'edit_post_link' ), 10, 3 );
137 137
 
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 			}
151 151
 		}
152 152
 
153
-	    return $link;
153
+		return $link;
154 154
 	}
155 155
 
156 156
 	public function ignore_post_meta($meta) {
@@ -392,9 +392,9 @@  discard block
 block discarded – undo
392 392
 	/**
393 393
 	 * Kicks of an import or export cronjob.
394 394
 	 *
395
-     * @param bool   $force
396
-     * @param string $type
397
-     */
395
+	 * @param bool   $force
396
+	 * @param string $type
397
+	 */
398 398
 	protected function start_cron( $type, $force = false ) {
399 399
 		update_option( '_wogh_' . $type . '_started', 'yes' );
400 400
 		$user_id = get_current_user_id();
Please login to merge, or discard this patch.
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -12,12 +12,12 @@  discard block
 block discarded – undo
12 12
 
13 13
 // If the functions have already been autoloaded, don't reload.
14 14
 // This fixes function duplication during unit testing.
15
-$path = dirname( __FILE__ ) . '/vendor/autoload.php';
16
-if ( file_exists( $path ) ) {
17
-    require_once( $path );
15
+$path = dirname(__FILE__) . '/vendor/autoload.php';
16
+if (file_exists($path)) {
17
+    require_once($path);
18 18
 }
19 19
 
20
-add_action( 'plugins_loaded', array( new Writing_On_GitHub, 'boot' ) );
20
+add_action('plugins_loaded', array(new Writing_On_GitHub, 'boot'));
21 21
 
22 22
 class Writing_On_GitHub {
23 23
 
@@ -107,14 +107,14 @@  discard block
 block discarded – undo
107 107
 	public function __construct() {
108 108
 		self::$instance = $this;
109 109
 
110
-		if ( is_admin() ) {
110
+		if (is_admin()) {
111 111
 			$this->admin = new Writing_On_GitHub_Admin;
112 112
 		}
113 113
 
114
-		$this->controller = new Writing_On_GitHub_Controller( $this );
114
+		$this->controller = new Writing_On_GitHub_Controller($this);
115 115
 
116
-		if ( defined( 'WP_CLI' ) && WP_CLI ) {
117
-			WP_CLI::add_command( 'wogh', $this->cli() );
116
+		if (defined('WP_CLI') && WP_CLI) {
117
+			WP_CLI::add_command('wogh', $this->cli());
118 118
 		}
119 119
 	}
120 120
 
@@ -122,30 +122,30 @@  discard block
 block discarded – undo
122 122
 	 * Attaches the plugin's hooks into WordPress.
123 123
 	 */
124 124
 	public function boot() {
125
-		register_activation_hook( __FILE__, array( $this, 'activate' ) );
126
-		add_action( 'admin_notices', array( $this, 'activation_notice' ) );
125
+		register_activation_hook(__FILE__, array($this, 'activate'));
126
+		add_action('admin_notices', array($this, 'activation_notice'));
127 127
 
128
-		add_action( 'init', array( $this, 'l10n' ) );
128
+		add_action('init', array($this, 'l10n'));
129 129
 
130 130
 		// Controller actions.
131
-		add_action( 'save_post', array( $this->controller, 'export_post' ) );
132
-		add_action( 'delete_post', array( $this->controller, 'delete_post' ) );
133
-		add_action( 'wp_ajax_nopriv_wogh_push_request', array( $this->controller, 'pull_posts' ) );
134
-        add_action( 'wogh_export', array( $this->controller, 'export_all' ), 10, 2 );
135
-		add_action( 'wogh_import', array( $this->controller, 'import_master' ), 10, 1 );
136
-		add_filter( 'get_edit_post_link', array( $this, 'edit_post_link' ), 10, 3 );
131
+		add_action('save_post', array($this->controller, 'export_post'));
132
+		add_action('delete_post', array($this->controller, 'delete_post'));
133
+		add_action('wp_ajax_nopriv_wogh_push_request', array($this->controller, 'pull_posts'));
134
+        add_action('wogh_export', array($this->controller, 'export_all'), 10, 2);
135
+		add_action('wogh_import', array($this->controller, 'import_master'), 10, 1);
136
+		add_filter('get_edit_post_link', array($this, 'edit_post_link'), 10, 3);
137 137
 
138 138
 		// add_filter( 'wogh_post_meta', array( $this, 'ignore_post_meta' ), 10, 1 );
139 139
 		// add_filter( 'wogh_pre_import_meta', array( $this, 'ignore_post_meta' ), 10, 1 );
140
-		add_filter( 'the_content', array( $this, 'the_content' ) );
140
+		add_filter('the_content', array($this, 'the_content'));
141 141
 
142
-		do_action( 'wogh_boot', $this );
142
+		do_action('wogh_boot', $this);
143 143
 	}
144 144
 
145 145
 	public function edit_post_link($link, $postID, $context) {
146
-		if ( ! wp_is_post_revision( $postID ) ) {
147
-			$post = new Writing_On_GitHub_Post( $postID, Writing_On_GitHub::$instance->api() );
148
-			if ( $post->is_on_github() ) {
146
+		if ( ! wp_is_post_revision($postID)) {
147
+			$post = new Writing_On_GitHub_Post($postID, Writing_On_GitHub::$instance->api());
148
+			if ($post->is_on_github()) {
149 149
 				return $post->github_edit_url();
150 150
 			}
151 151
 		}
@@ -204,29 +204,29 @@  discard block
 block discarded – undo
204 204
 	 * Init i18n files
205 205
 	 */
206 206
 	public function l10n() {
207
-		load_plugin_textdomain( self::$text_domain );
207
+		load_plugin_textdomain(self::$text_domain);
208 208
 	}
209 209
 
210 210
 	/**
211 211
 	 * Sets and kicks off the export cronjob
212 212
 	 */
213
-	public function start_export( $force = false ) {
214
-		$this->start_cron( 'export', $force );
213
+	public function start_export($force = false) {
214
+		$this->start_cron('export', $force);
215 215
 	}
216 216
 
217 217
 	/**
218 218
 	 * Sets and kicks off the import cronjob
219 219
 	 */
220 220
 	public function start_import() {
221
-		$this->start_cron( 'import' );
221
+		$this->start_cron('import');
222 222
 	}
223 223
 
224 224
 	/**
225 225
 	 * Enables the admin notice on initial activation
226 226
 	 */
227 227
 	public function activate() {
228
-		if ( 'yes' !== get_option( '_wogh_fully_exported' ) ) {
229
-			set_transient( '_wogh_activated', 'yes' );
228
+		if ('yes' !== get_option('_wogh_fully_exported')) {
229
+			set_transient('_wogh_activated', 'yes');
230 230
 		}
231 231
 	}
232 232
 
@@ -234,18 +234,18 @@  discard block
 block discarded – undo
234 234
 	 * Displays the activation admin notice
235 235
 	 */
236 236
 	public function activation_notice() {
237
-		if ( ! get_transient( '_wogh_activated' ) ) {
237
+		if ( ! get_transient('_wogh_activated')) {
238 238
 			return;
239 239
 		}
240 240
 
241
-		delete_transient( '_wogh_activated' );
241
+		delete_transient('_wogh_activated');
242 242
 
243 243
 		?><div class="updated">
244 244
 			<p>
245 245
 				<?php
246 246
 					printf(
247
-						__( 'To set up your site to sync with GitHub, update your <a href="%s">settings</a> and click "Export to GitHub."', 'writing-on-github' ),
248
-						admin_url( 'options-general.php?page=' . static::$text_domain)
247
+						__('To set up your site to sync with GitHub, update your <a href="%s">settings</a> and click "Export to GitHub."', 'writing-on-github'),
248
+						admin_url('options-general.php?page=' . static::$text_domain)
249 249
 					);
250 250
 				?>
251 251
 			</p>
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 	 * @return Writing_On_GitHub_CLI
268 268
 	 */
269 269
 	public function cli() {
270
-		if ( ! $this->cli ) {
270
+		if ( ! $this->cli) {
271 271
 			$this->cli = new Writing_On_GitHub_CLI;
272 272
 		}
273 273
 
@@ -280,8 +280,8 @@  discard block
 block discarded – undo
280 280
 	 * @return Writing_On_GitHub_Request
281 281
 	 */
282 282
 	public function request() {
283
-		if ( ! $this->request ) {
284
-			$this->request = new Writing_On_GitHub_Request( $this );
283
+		if ( ! $this->request) {
284
+			$this->request = new Writing_On_GitHub_Request($this);
285 285
 		}
286 286
 
287 287
 		return $this->request;
@@ -293,8 +293,8 @@  discard block
 block discarded – undo
293 293
 	 * @return Writing_On_GitHub_Response
294 294
 	 */
295 295
 	public function response() {
296
-		if ( ! $this->response ) {
297
-			$this->response = new Writing_On_GitHub_Response( $this );
296
+		if ( ! $this->response) {
297
+			$this->response = new Writing_On_GitHub_Response($this);
298 298
 		}
299 299
 
300 300
 		return $this->response;
@@ -306,8 +306,8 @@  discard block
 block discarded – undo
306 306
 	 * @return Writing_On_GitHub_Api
307 307
 	 */
308 308
 	public function api() {
309
-		if ( ! $this->api ) {
310
-			$this->api = new Writing_On_GitHub_Api( $this );
309
+		if ( ! $this->api) {
310
+			$this->api = new Writing_On_GitHub_Api($this);
311 311
 		}
312 312
 
313 313
 		return $this->api;
@@ -319,8 +319,8 @@  discard block
 block discarded – undo
319 319
 	 * @return Writing_On_GitHub_Import
320 320
 	 */
321 321
 	public function import() {
322
-		if ( ! $this->import ) {
323
-			$this->import = new Writing_On_GitHub_Import( $this );
322
+		if ( ! $this->import) {
323
+			$this->import = new Writing_On_GitHub_Import($this);
324 324
 		}
325 325
 
326 326
 		return $this->import;
@@ -332,8 +332,8 @@  discard block
 block discarded – undo
332 332
 	 * @return Writing_On_GitHub_Export
333 333
 	 */
334 334
 	public function export() {
335
-		if ( ! $this->export ) {
336
-			$this->export = new Writing_On_GitHub_Export( $this );
335
+		if ( ! $this->export) {
336
+			$this->export = new Writing_On_GitHub_Export($this);
337 337
 		}
338 338
 
339 339
 		return $this->export;
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
 	 * @return Writing_On_GitHub_Semaphore
346 346
 	 */
347 347
 	public function semaphore() {
348
-		if ( ! $this->semaphore ) {
348
+		if ( ! $this->semaphore) {
349 349
 			$this->semaphore = new Writing_On_GitHub_Semaphore;
350 350
 		}
351 351
 
@@ -358,8 +358,8 @@  discard block
 block discarded – undo
358 358
 	 * @return Writing_On_GitHub_Database
359 359
 	 */
360 360
 	public function database() {
361
-		if ( ! $this->database ) {
362
-			$this->database = new Writing_On_GitHub_Database( $this );
361
+		if ( ! $this->database) {
362
+			$this->database = new Writing_On_GitHub_Database($this);
363 363
 		}
364 364
 
365 365
 		return $this->database;
@@ -373,18 +373,18 @@  discard block
 block discarded – undo
373 373
 	 * @param mixed $msg
374 374
 	 * @param string $write
375 375
 	 */
376
-	public static function write_log( $msg, $write = 'line' ) {
377
-		if ( defined( 'WP_CLI' ) && WP_CLI ) {
378
-			if ( is_array( $msg ) || is_object( $msg ) ) {
379
-				WP_CLI::print_value( $msg );
376
+	public static function write_log($msg, $write = 'line') {
377
+		if (defined('WP_CLI') && WP_CLI) {
378
+			if (is_array($msg) || is_object($msg)) {
379
+				WP_CLI::print_value($msg);
380 380
 			} else {
381
-				WP_CLI::$write( $msg );
381
+				WP_CLI::$write($msg);
382 382
 			}
383
-		} elseif ( true === WP_DEBUG ) {
384
-			if ( is_array( $msg ) || is_object( $msg ) ) {
385
-				error_log( print_r( $msg, true ) );
383
+		} elseif (true === WP_DEBUG) {
384
+			if (is_array($msg) || is_object($msg)) {
385
+				error_log(print_r($msg, true));
386 386
 			} else {
387
-				error_log( $msg );
387
+				error_log($msg);
388 388
 			}
389 389
 		}
390 390
 	}
@@ -395,10 +395,10 @@  discard block
 block discarded – undo
395 395
      * @param bool   $force
396 396
      * @param string $type
397 397
      */
398
-	protected function start_cron( $type, $force = false ) {
399
-		update_option( '_wogh_' . $type . '_started', 'yes' );
398
+	protected function start_cron($type, $force = false) {
399
+		update_option('_wogh_' . $type . '_started', 'yes');
400 400
 		$user_id = get_current_user_id();
401
-		wp_schedule_single_event( time(), 'wogh_' . $type . '', array( $user_id, $force ) );
401
+		wp_schedule_single_event(time(), 'wogh_' . $type . '', array($user_id, $force));
402 402
 		spawn_cron();
403 403
 	}
404 404
 }
Please login to merge, or discard this patch.
lib/client/fetch.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -16,13 +16,13 @@  discard block
 block discarded – undo
16 16
 	 *
17 17
 	 * @return Writing_On_GitHub_File_Info[]|WP_Error
18 18
 	 */
19
-	public function compare( $sha ) {
19
+	public function compare($sha) {
20 20
 		// https://api.github.com/repos/litefeel/testwpsync/compare/861f87e8851b8debb78db548269d29f8da4d94ac...master
21 21
 		$endpoint = $this->compare_endpoint();
22 22
 		$branch = $this->branch();
23
-		$data = $this->call( 'GET', "$endpoint/$sha...$branch" );
23
+		$data = $this->call('GET', "$endpoint/$sha...$branch");
24 24
 
25
-		if ( is_wp_error( $data ) ) {
25
+		if (is_wp_error($data)) {
26 26
 			return $data;
27 27
 		}
28 28
 
@@ -44,13 +44,13 @@  discard block
 block discarded – undo
44 44
 	 *
45 45
 	 * @return mixed
46 46
 	 */
47
-	public function remote_contents( $post ) {
48
-		return $this->call( 'GET', $this->content_endpoint( $post->github_path() ) );
47
+	public function remote_contents($post) {
48
+		return $this->call('GET', $this->content_endpoint($post->github_path()));
49 49
 	}
50 50
 
51
-	public function exists( $path ) {
52
-		$result = $this->call( 'GET', $this->content_endpoint( $path ) );
53
-		if ( is_wp_error( $result ) ) {
51
+	public function exists($path) {
52
+		$result = $this->call('GET', $this->content_endpoint($path));
53
+		if (is_wp_error($result)) {
54 54
 			return false;
55 55
 		}
56 56
 		return true;
@@ -63,27 +63,27 @@  discard block
 block discarded – undo
63 63
 	 *
64 64
 	 * @return Writing_On_GitHub_File_Info[]|WP_Error
65 65
 	 */
66
-	public function tree_recursive( $sha = '_default' ) {
66
+	public function tree_recursive($sha = '_default') {
67 67
 
68
-		if ( '_default' === $sha ) {
68
+		if ('_default' === $sha) {
69 69
 			$sha = $this->branch();
70 70
 		}
71 71
 
72
-		$data = $this->call( 'GET', $this->tree_endpoint() . '/' . $sha . '?recursive=1' );
72
+		$data = $this->call('GET', $this->tree_endpoint() . '/' . $sha . '?recursive=1');
73 73
 
74
-		if ( is_wp_error( $data ) ) {
74
+		if (is_wp_error($data)) {
75 75
 			return $data;
76 76
 		}
77 77
 
78 78
 		$files = array();
79 79
 
80
-		foreach ( $data->tree as $index => $thing ) {
80
+		foreach ($data->tree as $index => $thing) {
81 81
 			// We need to remove the trees because
82 82
 			// the recursive tree includes both
83 83
 			// the subtrees as well the subtrees' blobs.
84
-			if ( 'blob' === $thing->type ) {
84
+			if ('blob' === $thing->type) {
85 85
 				$thing->status = '';
86
-				$files[] = new Writing_On_GitHub_File_Info( $thing );
86
+				$files[] = new Writing_On_GitHub_File_Info($thing);
87 87
 			}
88 88
 		}
89 89
 
@@ -97,14 +97,14 @@  discard block
 block discarded – undo
97 97
 	 *
98 98
 	 * @return Writing_On_GitHub_Blob|WP_Error
99 99
 	 */
100
-	public function blob( Writing_On_GitHub_File_Info $fileinfo ) {
101
-		$data = $this->call( 'GET', $this->blob_endpoint() . '/' . $fileinfo->sha );
100
+	public function blob(Writing_On_GitHub_File_Info $fileinfo) {
101
+		$data = $this->call('GET', $this->blob_endpoint() . '/' . $fileinfo->sha);
102 102
 
103
-		if ( is_wp_error( $data ) ) {
103
+		if (is_wp_error($data)) {
104 104
 			return $data;
105 105
 		}
106 106
 
107 107
 		$data->path = $fileinfo->path;
108
-		return new Writing_On_GitHub_Blob( $data );
108
+		return new Writing_On_GitHub_Blob($data);
109 109
 	}
110 110
 }
Please login to merge, or discard this patch.
lib/database.php 2 patches
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -42,10 +42,10 @@  discard block
 block discarded – undo
42 42
 	/**
43 43
 	 * Queries the database for all of the supported posts.
44 44
 	 *
45
-     * @param  bool $force
46
-     *
47
-     * @return Writing_On_GitHub_Post[]|WP_Error
48
-     */
45
+	 * @param  bool $force
46
+	 *
47
+	 * @return Writing_On_GitHub_Post[]|WP_Error
48
+	 */
49 49
 	public function fetch_all_supported( $force = false ) {
50 50
 		$args  = array(
51 51
 			'post_type'   => $this->get_whitelisted_post_types(),
@@ -187,45 +187,45 @@  discard block
 block discarded – undo
187 187
 
188 188
 		// update tags
189 189
 		if ( isset( $meta['tags'] ) && $meta['tags'] ) {
190
-		    $args['tags_input'] = $meta['tags'];
190
+			$args['tags_input'] = $meta['tags'];
191 191
 		}
192 192
 
193 193
 		// update categories
194 194
 		if ( isset( $meta['categories'] ) && $meta['categories'] ) {
195
-		    $categories = $meta['categories'];
196
-		    if (!is_array($categories)) {
197
-		        $categories = array($categories);
198
-		    }
199
-		    $terms = get_terms(array(
200
-		        'taxonomy' => 'category',
201
-		        'fields' => 'id=>name',
202
-		        'hide_empty' => 0,
203
-		        'name' => $categories
204
-		        )
205
-		    );
206
-		    $map = array();
207
-		    foreach ($categories as $name) {
208
-		        $map[$name] = 1;
209
-		    }
210
-
211
-		    $ids = array();
212
-		    if (!empty($terms)) {
213
-		        foreach ($terms as $id => $name) {
214
-		            $ids[] = $id;
215
-		            unset($map[$name]);
216
-		        }
217
-		    }
218
-
219
-		    // create new terms
220
-		    if (!empty($map)) {
221
-		        foreach ($map as $name => $value) {
222
-		            $term = wp_insert_term($name, 'category', array('parent' => 0));
223
-		            // array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id);
224
-		            $ids[] = $term['term_id'];
225
-		        }
226
-		    }
227
-
228
-		    $args['post_category'] = $ids;
195
+			$categories = $meta['categories'];
196
+			if (!is_array($categories)) {
197
+				$categories = array($categories);
198
+			}
199
+			$terms = get_terms(array(
200
+				'taxonomy' => 'category',
201
+				'fields' => 'id=>name',
202
+				'hide_empty' => 0,
203
+				'name' => $categories
204
+				)
205
+			);
206
+			$map = array();
207
+			foreach ($categories as $name) {
208
+				$map[$name] = 1;
209
+			}
210
+
211
+			$ids = array();
212
+			if (!empty($terms)) {
213
+				foreach ($terms as $id => $name) {
214
+					$ids[] = $id;
215
+					unset($map[$name]);
216
+				}
217
+			}
218
+
219
+			// create new terms
220
+			if (!empty($map)) {
221
+				foreach ($map as $name => $value) {
222
+					$term = wp_insert_term($name, 'category', array('parent' => 0));
223
+					// array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id);
224
+					$ids[] = $term['term_id'];
225
+				}
226
+			}
227
+
228
+			$args['post_category'] = $ids;
229 229
 		}
230 230
 
231 231
 		return $args;
@@ -427,12 +427,12 @@  discard block
 block discarded – undo
427 427
 		if ( ! empty( $display_name ) ) {
428 428
 			$search_string = esc_attr( $display_name );
429 429
 			$query = new WP_User_Query( array(
430
-			    'search'         => "{$search_string}",
431
-			    'search_columns' => array(
432
-			        'display_name',
433
-			        'user_nicename',
434
-			        'user_login',
435
-			    )
430
+				'search'         => "{$search_string}",
431
+				'search_columns' => array(
432
+					'display_name',
433
+					'user_nicename',
434
+					'user_login',
435
+				)
436 436
 			) );
437 437
 			$users = $query->get_results();
438 438
 			$user = empty($users) ? false : $users[0];
Please login to merge, or discard this patch.
Spacing   +115 added lines, -116 removed lines patch added patch discarded remove patch
@@ -21,21 +21,21 @@  discard block
 block discarded – undo
21 21
 	 *
22 22
 	 * @var array
23 23
 	 */
24
-	protected $whitelisted_post_types = array( 'post', 'page' );
24
+	protected $whitelisted_post_types = array('post', 'page');
25 25
 
26 26
 	/**
27 27
 	 * Currently whitelisted post statuses.
28 28
 	 *
29 29
 	 * @var array
30 30
 	 */
31
-	protected $whitelisted_post_statuses = array( 'publish' );
31
+	protected $whitelisted_post_statuses = array('publish');
32 32
 
33 33
 	/**
34 34
 	 * Instantiates a new Database object.
35 35
 	 *
36 36
 	 * @param Writing_On_GitHub $app Application container.
37 37
 	 */
38
-	public function __construct( Writing_On_GitHub $app ) {
38
+	public function __construct(Writing_On_GitHub $app) {
39 39
 		$this->app = $app;
40 40
 	}
41 41
 
@@ -46,32 +46,32 @@  discard block
 block discarded – undo
46 46
      *
47 47
      * @return Writing_On_GitHub_Post[]|WP_Error
48 48
      */
49
-	public function fetch_all_supported( $force = false ) {
50
-		$args  = array(
49
+	public function fetch_all_supported($force = false) {
50
+		$args = array(
51 51
 			'post_type'   => $this->get_whitelisted_post_types(),
52 52
 			'post_status' => $this->get_whitelisted_post_statuses(),
53 53
 			'nopaging'    => true,
54 54
 			'fields'      => 'ids',
55 55
 		);
56 56
 
57
-		$query = new WP_Query( apply_filters( 'wogh_pre_fetch_all_supported', $args ) );
57
+		$query = new WP_Query(apply_filters('wogh_pre_fetch_all_supported', $args));
58 58
 
59 59
 		$post_ids = $query->get_posts();
60 60
 
61
-		if ( ! $post_ids ) {
61
+		if ( ! $post_ids) {
62 62
 			return new WP_Error(
63 63
 				'no_results',
64
-				__( 'Querying for supported posts returned no results.', 'writing-on-github' )
64
+				__('Querying for supported posts returned no results.', 'writing-on-github')
65 65
 			);
66 66
 		}
67 67
 
68 68
 		$results = array();
69
-		foreach ( $post_ids as $post_id ) {
69
+		foreach ($post_ids as $post_id) {
70 70
 			// Do not export posts that have already been exported
71
-			if ( $force || ! get_post_meta( $post_id, '_wogh_sha', true ) ||
72
-				 ! get_post_meta( $post_id, '_wogh_github_path', true ) ) {
71
+			if ($force || ! get_post_meta($post_id, '_wogh_sha', true) ||
72
+				 ! get_post_meta($post_id, '_wogh_github_path', true)) {
73 73
 
74
-				$results[] = new Writing_On_GitHub_Post( $post_id, $this->app->api() );
74
+				$results[] = new Writing_On_GitHub_Post($post_id, $this->app->api());
75 75
 			}
76 76
 		}
77 77
 
@@ -85,10 +85,10 @@  discard block
 block discarded – undo
85 85
 	 *
86 86
 	 * @return WP_Error|Writing_On_GitHub_Post
87 87
 	 */
88
-	public function fetch_by_id( $post_id ) {
89
-		$post = new Writing_On_GitHub_Post( $post_id, $this->app->api() );
88
+	public function fetch_by_id($post_id) {
89
+		$post = new Writing_On_GitHub_Post($post_id, $this->app->api());
90 90
 
91
-		if ( ! $this->is_post_supported( $post ) ) {
91
+		if ( ! $this->is_post_supported($post)) {
92 92
 			return new WP_Error(
93 93
 				'unsupported_post',
94 94
 				sprintf(
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 	 *
113 113
 	 * @return string|WP_Error
114 114
 	 */
115
-	public function save_posts( array $posts ) {
115
+	public function save_posts(array $posts) {
116 116
 
117 117
 		/**
118 118
 		 * Whether an error has occurred.
@@ -121,20 +121,19 @@  discard block
 block discarded – undo
121 121
 		 */
122 122
 		$error = false;
123 123
 
124
-		foreach ( $posts as $post ) {
125
-			$args = apply_filters( 'wogh_pre_import_args', $this->post_args( $post ), $post );
124
+		foreach ($posts as $post) {
125
+			$args = apply_filters('wogh_pre_import_args', $this->post_args($post), $post);
126 126
 
127
-			remove_filter( 'content_save_pre', 'wp_filter_post_kses' );
127
+			remove_filter('content_save_pre', 'wp_filter_post_kses');
128 128
 			$post_id = $post->is_new() ?
129
-				wp_insert_post( $args, true ) :
130
-				wp_update_post( $args, true );
131
-			add_filter( 'content_save_pre', 'wp_filter_post_kses' );
129
+				wp_insert_post($args, true) : wp_update_post($args, true);
130
+			add_filter('content_save_pre', 'wp_filter_post_kses');
132 131
 
133
-			if ( is_wp_error( $post_id ) ) {
134
-				if ( ! $error ) {
132
+			if (is_wp_error($post_id)) {
133
+				if ( ! $error) {
135 134
 					$error = $post_id;
136 135
 				} else {
137
-					$error->add( $post_id->get_error_code(), $post_id->get_error_message() );
136
+					$error->add($post_id->get_error_code(), $post_id->get_error_message());
138 137
 				}
139 138
 
140 139
 				// Abort saving if updating the post fails.
@@ -143,20 +142,20 @@  discard block
 block discarded – undo
143 142
 
144 143
 			// $this->set_revision_author( $post_id, $user_id );
145 144
 
146
-			if ( $post->is_new() ) {
145
+			if ($post->is_new()) {
147 146
 				$author = false;
148 147
 				$meta = $post->get_meta();
149
-				if ( ! empty( $meta ) && ! empty( $meta['author'] ) ) {
148
+				if ( ! empty($meta) && ! empty($meta['author'])) {
150 149
 					$author = $meta['author'];
151 150
 				}
152
-				$user    = $this->fetch_commit_user( $author );
153
-				$user_id = ! is_wp_error( $user ) ? $user->ID : 0;
154
-				$this->set_post_author( $post_id, $user_id );
151
+				$user    = $this->fetch_commit_user($author);
152
+				$user_id = ! is_wp_error($user) ? $user->ID : 0;
153
+				$this->set_post_author($post_id, $user_id);
155 154
 			}
156 155
 
157
-			$post->set_post( get_post( $post_id ) );
156
+			$post->set_post(get_post($post_id));
158 157
 
159
-			$meta = apply_filters( 'wogh_pre_import_meta', $post->get_meta(), $post );
158
+			$meta = apply_filters('wogh_pre_import_meta', $post->get_meta(), $post);
160 159
 
161 160
 			// unset( $meta['tags'] );
162 161
 			// unset( $meta['categories'] );
@@ -171,14 +170,14 @@  discard block
 block discarded – undo
171 170
 			// }
172 171
 		}
173 172
 
174
-		if ( $error ) {
173
+		if ($error) {
175 174
 			return $error;
176 175
 		}
177 176
 
178
-		return __( 'Successfully saved posts.', 'writing-on-github' );
177
+		return __('Successfully saved posts.', 'writing-on-github');
179 178
 	}
180 179
 
181
-	protected function post_args( $post ) {
180
+	protected function post_args($post) {
182 181
 		$args = $post->get_args();
183 182
 		$meta = $post->get_meta();
184 183
 
@@ -186,14 +185,14 @@  discard block
 block discarded – undo
186 185
 		$args['post_content'] = addslashes($args['post_content']);
187 186
 
188 187
 		// update tags
189
-		if ( isset( $meta['tags'] ) && $meta['tags'] ) {
188
+		if (isset($meta['tags']) && $meta['tags']) {
190 189
 		    $args['tags_input'] = $meta['tags'];
191 190
 		}
192 191
 
193 192
 		// update categories
194
-		if ( isset( $meta['categories'] ) && $meta['categories'] ) {
193
+		if (isset($meta['categories']) && $meta['categories']) {
195 194
 		    $categories = $meta['categories'];
196
-		    if (!is_array($categories)) {
195
+		    if ( ! is_array($categories)) {
197 196
 		        $categories = array($categories);
198 197
 		    }
199 198
 		    $terms = get_terms(array(
@@ -209,7 +208,7 @@  discard block
 block discarded – undo
209 208
 		    }
210 209
 
211 210
 		    $ids = array();
212
-		    if (!empty($terms)) {
211
+		    if ( ! empty($terms)) {
213 212
 		        foreach ($terms as $id => $name) {
214 213
 		            $ids[] = $id;
215 214
 		            unset($map[$name]);
@@ -217,7 +216,7 @@  discard block
 block discarded – undo
217 216
 		    }
218 217
 
219 218
 		    // create new terms
220
-		    if (!empty($map)) {
219
+		    if ( ! empty($map)) {
221 220
 		        foreach ($map as $name => $value) {
222 221
 		            $term = wp_insert_term($name, 'category', array('parent' => 0));
223 222
 		            // array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id);
@@ -238,77 +237,77 @@  discard block
 block discarded – undo
238 237
 	 *
239 238
 	 * @return string|WP_Error
240 239
 	 */
241
-	public function delete_post_by_path( $path ) {
242
-		$query = new WP_Query( array(
240
+	public function delete_post_by_path($path) {
241
+		$query = new WP_Query(array(
243 242
 			'meta_key'       => '_wogh_github_path',
244 243
 			'meta_value'     => $path,
245 244
 			'meta_compare'   => '=',
246 245
 			'posts_per_page' => 1,
247 246
 			'fields'         => 'ids',
248
-		) );
247
+		));
249 248
 
250 249
 		$post_id = $query->get_posts();
251
-		$post_id = array_pop( $post_id );
250
+		$post_id = array_pop($post_id);
252 251
 
253
-		if ( ! $post_id ) {
254
-			$parts     = explode( '/', $path );
255
-			$filename  = array_pop( $parts );
256
-			$directory = $parts ? array_shift( $parts ) : '';
252
+		if ( ! $post_id) {
253
+			$parts     = explode('/', $path);
254
+			$filename  = array_pop($parts);
255
+			$directory = $parts ? array_shift($parts) : '';
257 256
 
258
-			if ( false !== strpos( $directory, 'post' ) ) {
259
-				preg_match( '/([0-9]{4})-([0-9]{2})-([0-9]{2})-(.*)\.md/', $filename, $matches );
257
+			if (false !== strpos($directory, 'post')) {
258
+				preg_match('/([0-9]{4})-([0-9]{2})-([0-9]{2})-(.*)\.md/', $filename, $matches);
260 259
 				$title = $matches[4];
261 260
 
262
-				$query = new WP_Query( array(
261
+				$query = new WP_Query(array(
263 262
 					'name'     => $title,
264 263
 					'posts_per_page' => 1,
265 264
 					'post_type' => $this->get_whitelisted_post_types(),
266 265
 					'fields'         => 'ids',
267
-				) );
266
+				));
268 267
 
269 268
 				$post_id = $query->get_posts();
270
-				$post_id = array_pop( $post_id );
269
+				$post_id = array_pop($post_id);
271 270
 			}
272 271
 
273
-			if ( ! $post_id ) {
274
-				preg_match( '/(.*)\.md/', $filename, $matches );
272
+			if ( ! $post_id) {
273
+				preg_match('/(.*)\.md/', $filename, $matches);
275 274
 				$title = $matches[1];
276 275
 
277
-				$query = new WP_Query( array(
276
+				$query = new WP_Query(array(
278 277
 					'name'     => $title,
279 278
 					'posts_per_page' => 1,
280 279
 					'post_type' => $this->get_whitelisted_post_types(),
281 280
 					'fields'         => 'ids',
282
-				) );
281
+				));
283 282
 
284 283
 				$post_id = $query->get_posts();
285
-				$post_id = array_pop( $post_id );
284
+				$post_id = array_pop($post_id);
286 285
 			}
287 286
 		}
288 287
 
289
-		if ( ! $post_id ) {
288
+		if ( ! $post_id) {
290 289
 			return new WP_Error(
291 290
 				'path_not_found',
292 291
 				sprintf(
293
-					__( 'Post not found for path %s.', 'writing-on-github' ),
292
+					__('Post not found for path %s.', 'writing-on-github'),
294 293
 					$path
295 294
 				)
296 295
 			);
297 296
 		}
298 297
 
299
-		$result = wp_delete_post( $post_id );
298
+		$result = wp_delete_post($post_id);
300 299
 
301 300
 		// If deleting fails...
302
-		if ( false === $result ) {
303
-			$post = get_post( $post_id );
301
+		if (false === $result) {
302
+			$post = get_post($post_id);
304 303
 
305 304
 			// ...and the post both exists and isn't in the trash...
306
-			if ( $post && 'trash' !== $post->post_status ) {
305
+			if ($post && 'trash' !== $post->post_status) {
307 306
 				// ... then something went wrong.
308 307
 				return new WP_Error(
309 308
 					'db_error',
310 309
 					sprintf(
311
-						__( 'Failed to delete post ID %d.', 'writing-on-github' ),
310
+						__('Failed to delete post ID %d.', 'writing-on-github'),
312 311
 						$post_id
313 312
 					)
314 313
 				);
@@ -316,25 +315,25 @@  discard block
 block discarded – undo
316 315
 		}
317 316
 
318 317
 		return sprintf(
319
-			__( 'Successfully deleted post ID %d.', 'writing-on-github' ),
318
+			__('Successfully deleted post ID %d.', 'writing-on-github'),
320 319
 			$post_id
321 320
 		);
322 321
 	}
323 322
 
324
-	public function delete_post( $post_id ) {
325
-		$result = wp_delete_post( $post_id );
323
+	public function delete_post($post_id) {
324
+		$result = wp_delete_post($post_id);
326 325
 
327 326
 		// If deleting fails...
328
-		if ( false === $result ) {
329
-			$post = get_post( $post_id );
327
+		if (false === $result) {
328
+			$post = get_post($post_id);
330 329
 
331 330
 			// ...and the post both exists and isn't in the trash...
332
-			if ( $post && 'trash' !== $post->post_status ) {
331
+			if ($post && 'trash' !== $post->post_status) {
333 332
 				// ... then something went wrong.
334 333
 				return new WP_Error(
335 334
 					'db_error',
336 335
 					sprintf(
337
-						__( 'Failed to delete post ID %d.', 'writing-on-github' ),
336
+						__('Failed to delete post ID %d.', 'writing-on-github'),
338 337
 						$post_id
339 338
 					)
340 339
 				);
@@ -342,7 +341,7 @@  discard block
 block discarded – undo
342 341
 		}
343 342
 
344 343
 		return sprintf(
345
-			__( 'Successfully deleted post ID %d.', 'writing-on-github' ),
344
+			__('Successfully deleted post ID %d.', 'writing-on-github'),
346 345
 			$post_id
347 346
 		);
348 347
 	}
@@ -353,7 +352,7 @@  discard block
 block discarded – undo
353 352
 	 * @return array
354 353
 	 */
355 354
 	protected function get_whitelisted_post_types() {
356
-		return apply_filters( 'wogh_whitelisted_post_types', $this->whitelisted_post_types );
355
+		return apply_filters('wogh_whitelisted_post_types', $this->whitelisted_post_types);
357 356
 	}
358 357
 
359 358
 	/**
@@ -362,7 +361,7 @@  discard block
 block discarded – undo
362 361
 	 * @return array
363 362
 	 */
364 363
 	protected function get_whitelisted_post_statuses() {
365
-		return apply_filters( 'wogh_whitelisted_post_statuses', $this->whitelisted_post_statuses );
364
+		return apply_filters('wogh_whitelisted_post_statuses', $this->whitelisted_post_statuses);
366 365
 	}
367 366
 
368 367
 	/**
@@ -372,12 +371,12 @@  discard block
 block discarded – undo
372 371
 	 *
373 372
 	 * @return string Whitelist formatted for query
374 373
 	 */
375
-	protected function format_for_query( $whitelist ) {
376
-		foreach ( $whitelist as $key => $value ) {
377
-			$whitelist[ $key ] = "'$value'";
374
+	protected function format_for_query($whitelist) {
375
+		foreach ($whitelist as $key => $value) {
376
+			$whitelist[$key] = "'$value'";
378 377
 		}
379 378
 
380
-		return implode( ', ', $whitelist );
379
+		return implode(', ', $whitelist);
381 380
 	}
382 381
 
383 382
 	/**
@@ -388,25 +387,25 @@  discard block
 block discarded – undo
388 387
 	 *
389 388
 	 * @return boolean                          True if supported, false if not.
390 389
 	 */
391
-	protected function is_post_supported( Writing_On_GitHub_Post $post ) {
392
-		if ( wp_is_post_revision( $post->id ) ) {
390
+	protected function is_post_supported(Writing_On_GitHub_Post $post) {
391
+		if (wp_is_post_revision($post->id)) {
393 392
 			return false;
394 393
 		}
395 394
 
396 395
 		// We need to allow trashed posts to be queried, but they are not whitelisted for export.
397
-		if ( ! in_array( $post->status(), $this->get_whitelisted_post_statuses() ) && 'trash' !== $post->status() ) {
396
+		if ( ! in_array($post->status(), $this->get_whitelisted_post_statuses()) && 'trash' !== $post->status()) {
398 397
 			return false;
399 398
 		}
400 399
 
401
-		if ( ! in_array( $post->type(), $this->get_whitelisted_post_types() ) ) {
400
+		if ( ! in_array($post->type(), $this->get_whitelisted_post_types())) {
402 401
 			return false;
403 402
 		}
404 403
 
405
-		if ( $post->has_password() ) {
404
+		if ($post->has_password()) {
406 405
 			return false;
407 406
 		}
408 407
 
409
-		return apply_filters( 'wogh_is_post_supported', true, $post );
408
+		return apply_filters('wogh_is_post_supported', true, $post);
410 409
 	}
411 410
 
412 411
 	/**
@@ -419,35 +418,35 @@  discard block
 block discarded – undo
419 418
 	 *
420 419
 	 * @return WP_Error|WP_User
421 420
 	 */
422
-	protected function fetch_commit_user( $display_name ) {
421
+	protected function fetch_commit_user($display_name) {
423 422
 		// If we can't find a user and a default hasn't been set,
424 423
 		// we're just going to set the revision author to 0.
425 424
 		$user = false;
426 425
 
427
-		if ( ! empty( $display_name ) ) {
428
-			$search_string = esc_attr( $display_name );
429
-			$query = new WP_User_Query( array(
426
+		if ( ! empty($display_name)) {
427
+			$search_string = esc_attr($display_name);
428
+			$query = new WP_User_Query(array(
430 429
 			    'search'         => "{$search_string}",
431 430
 			    'search_columns' => array(
432 431
 			        'display_name',
433 432
 			        'user_nicename',
434 433
 			        'user_login',
435 434
 			    )
436
-			) );
435
+			));
437 436
 			$users = $query->get_results();
438 437
 			$user = empty($users) ? false : $users[0];
439 438
 		}
440 439
 
441
-		if ( ! $user ) {
440
+		if ( ! $user) {
442 441
 			// Use the default user.
443
-			$user = get_user_by( 'id', (int) get_option( 'wogh_default_user' ) );
442
+			$user = get_user_by('id', (int) get_option('wogh_default_user'));
444 443
 		}
445 444
 
446
-		if ( ! $user ) {
445
+		if ( ! $user) {
447 446
 			return new WP_Error(
448 447
 				'user_not_found',
449 448
 				sprintf(
450
-					__( 'Commit user not found for email %s', 'writing-on-github' ),
449
+					__('Commit user not found for email %s', 'writing-on-github'),
451 450
 					$email
452 451
 				)
453 452
 			);
@@ -465,28 +464,28 @@  discard block
 block discarded – undo
465 464
 	 *
466 465
 	 * @return string|WP_Error
467 466
 	 */
468
-	protected function set_revision_author( $post_id, $user_id ) {
469
-		$revision = wp_get_post_revisions( $post_id );
467
+	protected function set_revision_author($post_id, $user_id) {
468
+		$revision = wp_get_post_revisions($post_id);
470 469
 
471
-		if ( ! $revision ) {
472
-			$new_revision = wp_save_post_revision( $post_id );
470
+		if ( ! $revision) {
471
+			$new_revision = wp_save_post_revision($post_id);
473 472
 
474
-			if ( ! $new_revision || is_wp_error( $new_revision ) ) {
475
-				return new WP_Error( 'db_error', 'There was a problem saving a new revision.' );
473
+			if ( ! $new_revision || is_wp_error($new_revision)) {
474
+				return new WP_Error('db_error', 'There was a problem saving a new revision.');
476 475
 			}
477 476
 
478 477
 			// `wp_save_post_revision` returns the ID, whereas `get_post_revision` returns the whole object
479 478
 			// in order to be consistent, let's make sure we have the whole object before continuing.
480
-			$revision = get_post( $new_revision );
479
+			$revision = get_post($new_revision);
481 480
 
482
-			if ( ! $revision ) {
483
-				return new WP_Error( 'db_error', 'There was a problem retrieving the newly recreated revision.' );
481
+			if ( ! $revision) {
482
+				return new WP_Error('db_error', 'There was a problem retrieving the newly recreated revision.');
484 483
 			}
485 484
 		} else {
486
-			$revision = array_shift( $revision );
485
+			$revision = array_shift($revision);
487 486
 		}
488 487
 
489
-		return $this->set_post_author( $revision->ID, $user_id );
488
+		return $this->set_post_author($revision->ID, $user_id);
490 489
 	}
491 490
 
492 491
 	/**
@@ -499,7 +498,7 @@  discard block
 block discarded – undo
499 498
 	 *
500 499
 	 * @return string|WP_Error
501 500
 	 */
502
-	protected function set_post_author( $post_id, $user_id ) {
501
+	protected function set_post_author($post_id, $user_id) {
503 502
 		global $wpdb;
504 503
 
505 504
 		$result = $wpdb->update(
@@ -510,25 +509,25 @@  discard block
 block discarded – undo
510 509
 			array(
511 510
 				'ID' => (int) $post_id,
512 511
 			),
513
-			array( '%d' ),
514
-			array( '%d' )
512
+			array('%d'),
513
+			array('%d')
515 514
 		);
516 515
 
517
-		if ( false === $result ) {
518
-			return new WP_Error( 'db_error', $wpdb->last_error );
516
+		if (false === $result) {
517
+			return new WP_Error('db_error', $wpdb->last_error);
519 518
 		}
520 519
 
521
-		if ( 0 === $result ) {
520
+		if (0 === $result) {
522 521
 			return sprintf(
523
-				__( 'No change for post ID %d.', 'writing-on-github' ),
522
+				__('No change for post ID %d.', 'writing-on-github'),
524 523
 				$post_id
525 524
 			);
526 525
 		}
527 526
 
528
-		clean_post_cache( $post_id );
527
+		clean_post_cache($post_id);
529 528
 
530 529
 		return sprintf(
531
-			__( 'Successfully updated post ID %d.', 'writing-on-github' ),
530
+			__('Successfully updated post ID %d.', 'writing-on-github'),
532 531
 			$post_id
533 532
 		);
534 533
 	}
@@ -541,7 +540,7 @@  discard block
 block discarded – undo
541 540
 	 *
542 541
 	 * @return bool|int
543 542
 	 */
544
-	public function set_post_sha( $post, $sha ) {
545
-		return update_post_meta( $post->id, '_wogh_sha', $sha );
543
+	public function set_post_sha($post, $sha) {
544
+		return update_post_meta($post->id, '_wogh_sha', $sha);
546 545
 	}
547 546
 }
Please login to merge, or discard this patch.
lib/controller.php 2 patches
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 		$this->app->semaphore()->unlock();
82 82
 
83 83
 		if ( is_wp_error( $result ) ) {
84
-            /* @var WP_Error $result */
84
+			/* @var WP_Error $result */
85 85
 			return $this->app->response()->error( $result );
86 86
 		}
87 87
 
@@ -113,9 +113,9 @@  discard block
 block discarded – undo
113 113
 
114 114
 		$this->app->semaphore()->unlock();
115 115
 
116
-        if ( is_wp_error( $result ) ) {
117
-            /* @var WP_Error $result */
118
-            update_option( '_wogh_import_error', $result->get_error_message() );
116
+		if ( is_wp_error( $result ) ) {
117
+			/* @var WP_Error $result */
118
+			update_option( '_wogh_import_error', $result->get_error_message() );
119 119
 
120 120
 			return $this->app->response()->error( $result );
121 121
 		}
@@ -128,10 +128,10 @@  discard block
 block discarded – undo
128 128
 	/**
129 129
 	 * Export all the posts in the database to GitHub.
130 130
 	 *
131
-     * @param  int        $user_id
132
-     * @param  boolean    $force
133
-     * @return boolean
134
-     */
131
+	 * @param  int        $user_id
132
+	 * @param  boolean    $force
133
+	 * @return boolean
134
+	 */
135 135
 	public function export_all( $user_id = 0, $force = false ) {
136 136
 		if ( ! $this->app->semaphore()->is_open() ) {
137 137
 			return $this->app->response()->error( new WP_Error(
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 
152 152
 		// Maybe move option updating out of this class/upgrade message display?
153 153
 		if ( is_wp_error( $result ) ) {
154
-            /* @var WP_Error $result */
154
+			/* @var WP_Error $result */
155 155
 			update_option( '_wogh_export_error', $result->get_error_message() );
156 156
 
157 157
 			return $this->app->response()->error( $result );
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 		$this->app->semaphore()->unlock();
190 190
 
191 191
 		if ( is_wp_error( $result ) ) {
192
-            /* @var WP_Error $result */
192
+			/* @var WP_Error $result */
193 193
 			return $this->app->response()->error( $result );
194 194
 		}
195 195
 
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
 		$this->app->semaphore()->unlock();
223 223
 
224 224
 		if ( is_wp_error( $result ) ) {
225
-            /* @var WP_Error $result */
225
+			/* @var WP_Error $result */
226 226
 			return $this->app->response()->error( $result );
227 227
 		}
228 228
 
Please login to merge, or discard this patch.
Spacing   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 	 *
22 22
 	 * @param Writing_On_GitHub $app Applicatio container.
23 23
 	 */
24
-	public function __construct( Writing_On_GitHub $app ) {
24
+	public function __construct(Writing_On_GitHub $app) {
25 25
 		$this->app = $app;
26 26
 	}
27 27
 
@@ -34,58 +34,58 @@  discard block
 block discarded – undo
34 34
 	 */
35 35
 	public function pull_posts() {
36 36
 		$this->set_ajax();
37
-		if ( ! $this->app->semaphore()->is_open() ) {
38
-			return $this->app->response()->error( new WP_Error(
37
+		if ( ! $this->app->semaphore()->is_open()) {
38
+			return $this->app->response()->error(new WP_Error(
39 39
 				'semaphore_locked',
40
-				sprintf( __( '%s : Semaphore is locked, import/export already in progress.', 'writing-on-github' ), 'Controller::pull_posts()' )
41
-			) );
40
+				sprintf(__('%s : Semaphore is locked, import/export already in progress.', 'writing-on-github'), 'Controller::pull_posts()')
41
+			));
42 42
 		}
43 43
 
44
-		if ( ! $this->app->request()->is_secret_valid() ) {
45
-			return $this->app->response()->error( new WP_Error(
44
+		if ( ! $this->app->request()->is_secret_valid()) {
45
+			return $this->app->response()->error(new WP_Error(
46 46
 				'invalid_headers',
47
-				__( 'Failed to validate secret.', 'writing-on-github' )
48
-			) );
47
+				__('Failed to validate secret.', 'writing-on-github')
48
+			));
49 49
 		}
50 50
 
51 51
 		// ping
52
-		if ( $this->app->request()->is_ping() ) {
53
-			return $this->app->response()->success( __( 'Wordpress is ready.', 'writing-on-github' ) );
52
+		if ($this->app->request()->is_ping()) {
53
+			return $this->app->response()->success(__('Wordpress is ready.', 'writing-on-github'));
54 54
 		}
55 55
 
56 56
 		// push
57
-		if ( ! $this->app->request()->is_push() ) {
58
-			return $this->app->response()->error( new WP_Error(
57
+		if ( ! $this->app->request()->is_push()) {
58
+			return $this->app->response()->error(new WP_Error(
59 59
 				'invalid_headers',
60
-				__( 'Failed to validate webhook event.', 'writing-on-github' )
61
-			) );
60
+				__('Failed to validate webhook event.', 'writing-on-github')
61
+			));
62 62
 		}
63 63
 		$payload = $this->app->request()->payload();
64 64
 
65
-		if ( ! $payload->should_import() ) {
66
-			return $this->app->response()->error( new WP_Error(
65
+		if ( ! $payload->should_import()) {
66
+			return $this->app->response()->error(new WP_Error(
67 67
 				'invalid_payload',
68 68
 				sprintf(
69
-					__( "%s won't be imported.", 'writing-on-github' ),
70
-					strtolower( $payload->get_commit_id() ) ? : '[Missing Commit ID]'
69
+					__("%s won't be imported.", 'writing-on-github'),
70
+					strtolower($payload->get_commit_id()) ?: '[Missing Commit ID]'
71 71
 				)
72
-			) );
72
+			));
73 73
 		}
74 74
 
75 75
 		$this->app->semaphore()->lock();
76
-		remove_action( 'save_post', array( $this, 'export_post' ) );
77
-		remove_action( 'delete_post', array( $this, 'delete_post' ) );
76
+		remove_action('save_post', array($this, 'export_post'));
77
+		remove_action('delete_post', array($this, 'delete_post'));
78 78
 
79
-		$result = $this->app->import()->payload( $payload );
79
+		$result = $this->app->import()->payload($payload);
80 80
 
81 81
 		$this->app->semaphore()->unlock();
82 82
 
83
-		if ( is_wp_error( $result ) ) {
83
+		if (is_wp_error($result)) {
84 84
             /* @var WP_Error $result */
85
-			return $this->app->response()->error( $result );
85
+			return $this->app->response()->error($result);
86 86
 		}
87 87
 
88
-		return $this->app->response()->success( $result );
88
+		return $this->app->response()->success($result);
89 89
 	}
90 90
 
91 91
 	/**
@@ -93,36 +93,36 @@  discard block
 block discarded – undo
93 93
 	 *
94 94
 	 * @return boolean
95 95
 	 */
96
-	public function import_master( $user_id = 0 ) {
97
-		if ( ! $this->app->semaphore()->is_open() ) {
98
-			return $this->app->response()->error( new WP_Error(
96
+	public function import_master($user_id = 0) {
97
+		if ( ! $this->app->semaphore()->is_open()) {
98
+			return $this->app->response()->error(new WP_Error(
99 99
 				'semaphore_locked',
100
-				sprintf( __( '%s : Semaphore is locked, import/export already in progress.', 'writing-on-github' ), 'Controller::import_master()' )
101
-			) );
100
+				sprintf(__('%s : Semaphore is locked, import/export already in progress.', 'writing-on-github'), 'Controller::import_master()')
101
+			));
102 102
 		}
103 103
 
104 104
 		$this->app->semaphore()->lock();
105
-		remove_action( 'save_post', array( $this, 'export_post' ) );
106
-		remove_action( 'save_post', array( $this, 'delete_post' ) );
105
+		remove_action('save_post', array($this, 'export_post'));
106
+		remove_action('save_post', array($this, 'delete_post'));
107 107
 
108
-		if ( $user_id ) {
109
-			wp_set_current_user( $user_id );
108
+		if ($user_id) {
109
+			wp_set_current_user($user_id);
110 110
 		}
111 111
 
112 112
 		$result = $this->app->import()->master();
113 113
 
114 114
 		$this->app->semaphore()->unlock();
115 115
 
116
-        if ( is_wp_error( $result ) ) {
116
+        if (is_wp_error($result)) {
117 117
             /* @var WP_Error $result */
118
-            update_option( '_wogh_import_error', $result->get_error_message() );
118
+            update_option('_wogh_import_error', $result->get_error_message());
119 119
 
120
-			return $this->app->response()->error( $result );
120
+			return $this->app->response()->error($result);
121 121
 		}
122 122
 
123
-		update_option( '_wogh_import_complete', 'yes' );
123
+		update_option('_wogh_import_complete', 'yes');
124 124
 
125
-		return $this->app->response()->success( $result );
125
+		return $this->app->response()->success($result);
126 126
 	}
127 127
 
128 128
 	/**
@@ -132,34 +132,34 @@  discard block
 block discarded – undo
132 132
      * @param  boolean    $force
133 133
      * @return boolean
134 134
      */
135
-	public function export_all( $user_id = 0, $force = false ) {
136
-		if ( ! $this->app->semaphore()->is_open() ) {
137
-			return $this->app->response()->error( new WP_Error(
135
+	public function export_all($user_id = 0, $force = false) {
136
+		if ( ! $this->app->semaphore()->is_open()) {
137
+			return $this->app->response()->error(new WP_Error(
138 138
 				'semaphore_locked',
139
-				sprintf( __( '%s : Semaphore is locked, import/export already in progress.', 'writing-on-github' ), 'Controller::export_all()' )
140
-			) );
139
+				sprintf(__('%s : Semaphore is locked, import/export already in progress.', 'writing-on-github'), 'Controller::export_all()')
140
+			));
141 141
 		}
142 142
 
143 143
 		$this->app->semaphore()->lock();
144 144
 
145
-		if ( $user_id ) {
146
-			wp_set_current_user( $user_id );
145
+		if ($user_id) {
146
+			wp_set_current_user($user_id);
147 147
 		}
148 148
 
149 149
 		$result = $this->app->export()->full($force);
150 150
 		$this->app->semaphore()->unlock();
151 151
 
152 152
 		// Maybe move option updating out of this class/upgrade message display?
153
-		if ( is_wp_error( $result ) ) {
153
+		if (is_wp_error($result)) {
154 154
             /* @var WP_Error $result */
155
-			update_option( '_wogh_export_error', $result->get_error_message() );
155
+			update_option('_wogh_export_error', $result->get_error_message());
156 156
 
157
-			return $this->app->response()->error( $result );
157
+			return $this->app->response()->error($result);
158 158
 		} else {
159
-			update_option( '_wogh_export_complete', 'yes' );
160
-			update_option( '_wogh_fully_exported', 'yes' );
159
+			update_option('_wogh_export_complete', 'yes');
160
+			update_option('_wogh_fully_exported', 'yes');
161 161
 
162
-			return $this->app->response()->success( $result );
162
+			return $this->app->response()->success($result);
163 163
 		}
164 164
 	}
165 165
 
@@ -172,28 +172,28 @@  discard block
 block discarded – undo
172 172
 	 *
173 173
 	 * @return boolean
174 174
 	 */
175
-	public function export_post( $post_id ) {
176
-		if ( wp_is_post_revision( $post_id ) ) {
175
+	public function export_post($post_id) {
176
+		if (wp_is_post_revision($post_id)) {
177 177
 			return;
178 178
 		}
179 179
 
180
-		if ( ! $this->app->semaphore()->is_open() ) {
181
-			return $this->app->response()->error( new WP_Error(
180
+		if ( ! $this->app->semaphore()->is_open()) {
181
+			return $this->app->response()->error(new WP_Error(
182 182
 				'semaphore_locked',
183
-				sprintf( __( '%s : Semaphore is locked, import/export already in progress.', 'writing-on-github' ), 'Controller::export_post()' )
184
-			) );
183
+				sprintf(__('%s : Semaphore is locked, import/export already in progress.', 'writing-on-github'), 'Controller::export_post()')
184
+			));
185 185
 		}
186 186
 
187 187
 		$this->app->semaphore()->lock();
188
-		$result = $this->app->export()->update( $post_id );
188
+		$result = $this->app->export()->update($post_id);
189 189
 		$this->app->semaphore()->unlock();
190 190
 
191
-		if ( is_wp_error( $result ) ) {
191
+		if (is_wp_error($result)) {
192 192
             /* @var WP_Error $result */
193
-			return $this->app->response()->error( $result );
193
+			return $this->app->response()->error($result);
194 194
 		}
195 195
 
196
-		return $this->app->response()->success( $result );
196
+		return $this->app->response()->success($result);
197 197
 	}
198 198
 
199 199
 	/**
@@ -205,28 +205,28 @@  discard block
 block discarded – undo
205 205
 	 *
206 206
 	 * @return boolean
207 207
 	 */
208
-	public function delete_post( $post_id ) {
209
-		if ( wp_is_post_revision( $post_id ) ) {
208
+	public function delete_post($post_id) {
209
+		if (wp_is_post_revision($post_id)) {
210 210
 			return;
211 211
 		}
212 212
 
213
-		if ( ! $this->app->semaphore()->is_open() ) {
214
-			return $this->app->response()->error( new WP_Error(
213
+		if ( ! $this->app->semaphore()->is_open()) {
214
+			return $this->app->response()->error(new WP_Error(
215 215
 				'semaphore_locked',
216
-				sprintf( __( '%s : Semaphore is locked, import/export already in progress.', 'writing-on-github' ), 'Controller::delete_post()' )
217
-			) );
216
+				sprintf(__('%s : Semaphore is locked, import/export already in progress.', 'writing-on-github'), 'Controller::delete_post()')
217
+			));
218 218
 		}
219 219
 
220 220
 		$this->app->semaphore()->lock();
221
-		$result = $this->app->export()->delete( $post_id );
221
+		$result = $this->app->export()->delete($post_id);
222 222
 		$this->app->semaphore()->unlock();
223 223
 
224
-		if ( is_wp_error( $result ) ) {
224
+		if (is_wp_error($result)) {
225 225
             /* @var WP_Error $result */
226
-			return $this->app->response()->error( $result );
226
+			return $this->app->response()->error($result);
227 227
 		}
228 228
 
229
-		return $this->app->response()->success( $result );
229
+		return $this->app->response()->success($result);
230 230
 	}
231 231
 
232 232
 	/**
@@ -235,8 +235,8 @@  discard block
 block discarded – undo
235 235
 	 * than just returning data.
236 236
 	 */
237 237
 	protected function set_ajax() {
238
-		if ( ! defined( 'WOGH_AJAX' ) ) {
239
-			define( 'WOGH_AJAX', true );
238
+		if ( ! defined('WOGH_AJAX')) {
239
+			define('WOGH_AJAX', true);
240 240
 		}
241 241
 	}
242 242
 }
Please login to merge, or discard this patch.