Passed
Push — ci ( 870864...bcfa97 )
by litefeel
02:42
created
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   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -113,8 +113,8 @@  discard block
 block discarded – undo
113 113
 		$this->app->semaphore()->unlock();
114 114
 
115 115
 		if ( is_wp_error( $result ) ) {
116
-            //@var WP_Error $result
117
-            update_option( '_wogh_import_error', $result->get_error_message() );
116
+			//@var WP_Error $result
117
+			update_option( '_wogh_import_error', $result->get_error_message() );
118 118
 
119 119
 			return $this->app->response()->error( $result );
120 120
 		}
@@ -127,10 +127,10 @@  discard block
 block discarded – undo
127 127
 	/**
128 128
 	 * Export all the posts in the database to GitHub.
129 129
 	 *
130
-     * @param  int        $user_id
131
-     * @param  boolean    $force
132
-     * @return boolean
133
-     */
130
+	 * @param  int        $user_id
131
+	 * @param  boolean    $force
132
+	 * @return boolean
133
+	 */
134 134
 	public function export_all( $user_id, $force = false ) {
135 135
 		if ( ! $this->app->semaphore()->is_open() ) {
136 136
 			return $this->app->response()->error( new WP_Error(
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,57 +34,57 @@  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 ) ) {
84
-			return $this->app->response()->error( $result );
83
+		if (is_wp_error($result)) {
84
+			return $this->app->response()->error($result);
85 85
 		}
86 86
 
87
-		return $this->app->response()->success( $result );
87
+		return $this->app->response()->success($result);
88 88
 	}
89 89
 
90 90
 	/**
@@ -92,36 +92,36 @@  discard block
 block discarded – undo
92 92
 	 *
93 93
 	 * @return boolean
94 94
 	 */
95
-	public function import_master( $user_id ) {
96
-		if ( ! $this->app->semaphore()->is_open() ) {
97
-			return $this->app->response()->error( new WP_Error(
95
+	public function import_master($user_id) {
96
+		if ( ! $this->app->semaphore()->is_open()) {
97
+			return $this->app->response()->error(new WP_Error(
98 98
 				'semaphore_locked',
99
-				sprintf( __( '%s : Semaphore is locked, import/export already in progress.', 'writing-on-github' ), 'Controller::import_master()' )
100
-			) );
99
+				sprintf(__('%s : Semaphore is locked, import/export already in progress.', 'writing-on-github'), 'Controller::import_master()')
100
+			));
101 101
 		}
102 102
 
103 103
 		$this->app->semaphore()->lock();
104
-		remove_action( 'save_post', array( $this, 'export_post' ) );
105
-		remove_action( 'save_post', array( $this, 'delete_post' ) );
104
+		remove_action('save_post', array($this, 'export_post'));
105
+		remove_action('save_post', array($this, 'delete_post'));
106 106
 
107
-		if ( $user_id ) {
108
-			wp_set_current_user( $user_id );
107
+		if ($user_id) {
108
+			wp_set_current_user($user_id);
109 109
 		}
110 110
 
111 111
 		$result = $this->app->import()->master();
112 112
 
113 113
 		$this->app->semaphore()->unlock();
114 114
 
115
-		if ( is_wp_error( $result ) ) {
115
+		if (is_wp_error($result)) {
116 116
             //@var WP_Error $result
117
-            update_option( '_wogh_import_error', $result->get_error_message() );
117
+            update_option('_wogh_import_error', $result->get_error_message());
118 118
 
119
-			return $this->app->response()->error( $result );
119
+			return $this->app->response()->error($result);
120 120
 		}
121 121
 
122
-		update_option( '_wogh_import_complete', 'yes' );
122
+		update_option('_wogh_import_complete', 'yes');
123 123
 
124
-		return $this->app->response()->success( $result );
124
+		return $this->app->response()->success($result);
125 125
 	}
126 126
 
127 127
 	/**
@@ -131,33 +131,33 @@  discard block
 block discarded – undo
131 131
      * @param  boolean    $force
132 132
      * @return boolean
133 133
      */
134
-	public function export_all( $user_id, $force = false ) {
135
-		if ( ! $this->app->semaphore()->is_open() ) {
136
-			return $this->app->response()->error( new WP_Error(
134
+	public function export_all($user_id, $force = false) {
135
+		if ( ! $this->app->semaphore()->is_open()) {
136
+			return $this->app->response()->error(new WP_Error(
137 137
 				'semaphore_locked',
138
-				sprintf( __( '%s : Semaphore is locked, import/export already in progress.', 'writing-on-github' ), 'Controller::export_all()' )
139
-			) );
138
+				sprintf(__('%s : Semaphore is locked, import/export already in progress.', 'writing-on-github'), 'Controller::export_all()')
139
+			));
140 140
 		}
141 141
 
142 142
 		$this->app->semaphore()->lock();
143 143
 
144
-		if ( $user_id ) {
145
-			wp_set_current_user( $user_id );
144
+		if ($user_id) {
145
+			wp_set_current_user($user_id);
146 146
 		}
147 147
 
148 148
 		$result = $this->app->export()->full($force);
149 149
 		$this->app->semaphore()->unlock();
150 150
 
151 151
 		// Maybe move option updating out of this class/upgrade message display?
152
-		if ( is_wp_error( $result ) ) {
153
-			update_option( '_wogh_export_error', $result->get_error_message() );
152
+		if (is_wp_error($result)) {
153
+			update_option('_wogh_export_error', $result->get_error_message());
154 154
 
155
-			return $this->app->response()->error( $result );
155
+			return $this->app->response()->error($result);
156 156
 		} else {
157
-			update_option( '_wogh_export_complete', 'yes' );
158
-			update_option( '_wogh_fully_exported', 'yes' );
157
+			update_option('_wogh_export_complete', 'yes');
158
+			update_option('_wogh_fully_exported', 'yes');
159 159
 
160
-			return $this->app->response()->success( $result );
160
+			return $this->app->response()->success($result);
161 161
 		}
162 162
 	}
163 163
 
@@ -170,27 +170,27 @@  discard block
 block discarded – undo
170 170
 	 *
171 171
 	 * @return boolean
172 172
 	 */
173
-	public function export_post( $post_id ) {
174
-		if ( wp_is_post_revision( $post_id ) ) {
173
+	public function export_post($post_id) {
174
+		if (wp_is_post_revision($post_id)) {
175 175
 			return;
176 176
 		}
177 177
 
178
-		if ( ! $this->app->semaphore()->is_open() ) {
179
-			return $this->app->response()->error( new WP_Error(
178
+		if ( ! $this->app->semaphore()->is_open()) {
179
+			return $this->app->response()->error(new WP_Error(
180 180
 				'semaphore_locked',
181
-				sprintf( __( '%s : Semaphore is locked, import/export already in progress.', 'writing-on-github' ), 'Controller::export_post()' )
182
-			) );
181
+				sprintf(__('%s : Semaphore is locked, import/export already in progress.', 'writing-on-github'), 'Controller::export_post()')
182
+			));
183 183
 		}
184 184
 
185 185
 		$this->app->semaphore()->lock();
186
-		$result = $this->app->export()->update( $post_id );
186
+		$result = $this->app->export()->update($post_id);
187 187
 		$this->app->semaphore()->unlock();
188 188
 
189
-		if ( is_wp_error( $result ) ) {
190
-			return $this->app->response()->error( $result );
189
+		if (is_wp_error($result)) {
190
+			return $this->app->response()->error($result);
191 191
 		}
192 192
 
193
-		return $this->app->response()->success( $result );
193
+		return $this->app->response()->success($result);
194 194
 	}
195 195
 
196 196
 	/**
@@ -202,27 +202,27 @@  discard block
 block discarded – undo
202 202
 	 *
203 203
 	 * @return boolean
204 204
 	 */
205
-	public function delete_post( $post_id ) {
206
-		if ( wp_is_post_revision( $post_id ) ) {
205
+	public function delete_post($post_id) {
206
+		if (wp_is_post_revision($post_id)) {
207 207
 			return;
208 208
 		}
209 209
 
210
-		if ( ! $this->app->semaphore()->is_open() ) {
211
-			return $this->app->response()->error( new WP_Error(
210
+		if ( ! $this->app->semaphore()->is_open()) {
211
+			return $this->app->response()->error(new WP_Error(
212 212
 				'semaphore_locked',
213
-				sprintf( __( '%s : Semaphore is locked, import/export already in progress.', 'writing-on-github' ), 'Controller::delete_post()' )
214
-			) );
213
+				sprintf(__('%s : Semaphore is locked, import/export already in progress.', 'writing-on-github'), 'Controller::delete_post()')
214
+			));
215 215
 		}
216 216
 
217 217
 		$this->app->semaphore()->lock();
218
-		$result = $this->app->export()->delete( $post_id );
218
+		$result = $this->app->export()->delete($post_id);
219 219
 		$this->app->semaphore()->unlock();
220 220
 
221
-		if ( is_wp_error( $result ) ) {
222
-			return $this->app->response()->error( $result );
221
+		if (is_wp_error($result)) {
222
+			return $this->app->response()->error($result);
223 223
 		}
224 224
 
225
-		return $this->app->response()->success( $result );
225
+		return $this->app->response()->success($result);
226 226
 	}
227 227
 
228 228
 	/**
@@ -231,8 +231,8 @@  discard block
 block discarded – undo
231 231
 	 * than just returning data.
232 232
 	 */
233 233
 	protected function set_ajax() {
234
-		if ( ! defined( 'WOGH_AJAX' ) ) {
235
-			define( 'WOGH_AJAX', true );
234
+		if ( ! defined('WOGH_AJAX')) {
235
+			define('WOGH_AJAX', true);
236 236
 		}
237 237
 	}
238 238
 }
Please login to merge, or discard this patch.