Test Failed
Push — master ( fe1ced...9e7bbe )
by Ravinder
11:43
created
includes/class-give-db-meta.php 1 patch
Spacing   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
  */
11 11
 
12 12
 // Exit if accessed directly.
13
-if ( ! defined( 'ABSPATH' ) ) {
13
+if ( ! defined('ABSPATH')) {
14 14
 	exit;
15 15
 }
16 16
 
@@ -75,40 +75,40 @@  discard block
 block discarded – undo
75 75
 	 */
76 76
 	function __construct() {
77 77
 		// Bailout.
78
-		if ( empty( $this->supports ) || ! $this->is_custom_meta_table_active() ) {
78
+		if (empty($this->supports) || ! $this->is_custom_meta_table_active()) {
79 79
 			return;
80 80
 		}
81 81
 
82
-		if ( in_array( 'add_post_metadata', $this->supports ) ) {
83
-			add_filter( 'add_post_metadata', array( $this, '__add_meta' ), 0, 5 );
82
+		if (in_array('add_post_metadata', $this->supports)) {
83
+			add_filter('add_post_metadata', array($this, '__add_meta'), 0, 5);
84 84
 		}
85 85
 
86
-		if ( in_array( 'get_post_metadata', $this->supports ) ) {
87
-			add_filter( 'get_post_metadata', array( $this, '__get_meta' ), 0, 4 );
86
+		if (in_array('get_post_metadata', $this->supports)) {
87
+			add_filter('get_post_metadata', array($this, '__get_meta'), 0, 4);
88 88
 		}
89 89
 
90
-		if ( in_array( 'update_post_metadata', $this->supports ) ) {
91
-			add_filter( 'update_post_metadata', array( $this, '__update_meta' ), 0, 5 );
90
+		if (in_array('update_post_metadata', $this->supports)) {
91
+			add_filter('update_post_metadata', array($this, '__update_meta'), 0, 5);
92 92
 		}
93 93
 
94
-		if ( in_array( 'delete_post_metadata', $this->supports ) ) {
95
-			add_filter( 'delete_post_metadata', array( $this, '__delete_meta' ), 0, 5 );
94
+		if (in_array('delete_post_metadata', $this->supports)) {
95
+			add_filter('delete_post_metadata', array($this, '__delete_meta'), 0, 5);
96 96
 		}
97 97
 
98
-		if ( in_array( 'posts_where', $this->supports ) ) {
99
-			add_filter( 'posts_where', array( $this, '__rename_meta_table_name_in_query' ), 99999, 2 );
98
+		if (in_array('posts_where', $this->supports)) {
99
+			add_filter('posts_where', array($this, '__rename_meta_table_name_in_query'), 99999, 2);
100 100
 		}
101 101
 
102
-		if ( in_array( 'posts_join', $this->supports ) ) {
103
-			add_filter( 'posts_join', array( $this, '__rename_meta_table_name_in_query' ), 99999, 2 );
102
+		if (in_array('posts_join', $this->supports)) {
103
+			add_filter('posts_join', array($this, '__rename_meta_table_name_in_query'), 99999, 2);
104 104
 		}
105 105
 
106
-		if ( in_array( 'posts_groupby', $this->supports ) ) {
107
-			add_filter( 'posts_groupby', array( $this, '__rename_meta_table_name_in_query' ), 99999, 2 );
106
+		if (in_array('posts_groupby', $this->supports)) {
107
+			add_filter('posts_groupby', array($this, '__rename_meta_table_name_in_query'), 99999, 2);
108 108
 		}
109 109
 
110
-		if ( in_array( 'posts_orderby', $this->supports ) ) {
111
-			add_filter( 'posts_orderby', array( $this, '__rename_meta_table_name_in_query' ), 99999, 2 );
110
+		if (in_array('posts_orderby', $this->supports)) {
111
+			add_filter('posts_orderby', array($this, '__rename_meta_table_name_in_query'), 99999, 2);
112 112
 		}
113 113
 	}
114 114
 
@@ -126,16 +126,16 @@  discard block
 block discarded – undo
126 126
 	 * @return  mixed                 Will be an array if $single is false. Will be value of meta data field if $single
127 127
 	 *                                is true.
128 128
 	 */
129
-	public function get_meta( $id = 0, $meta_key = '', $single = false ) {
130
-		$id = $this->sanitize_id( $id );
129
+	public function get_meta($id = 0, $meta_key = '', $single = false) {
130
+		$id = $this->sanitize_id($id);
131 131
 
132 132
 		// Bailout.
133
-		if ( ! $this->is_valid_post_type( $id ) ) {
133
+		if ( ! $this->is_valid_post_type($id)) {
134 134
 			return $this->check;
135 135
 		}
136 136
 
137
-		if ( $this->raw_result ) {
138
-			if ( ! ( $value = get_metadata( $this->meta_type, $id, $meta_key, false ) ) ) {
137
+		if ($this->raw_result) {
138
+			if ( ! ($value = get_metadata($this->meta_type, $id, $meta_key, false))) {
139 139
 				$value = '';
140 140
 			}
141 141
 
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 			$this->raw_result = false;
144 144
 
145 145
 		} else {
146
-			$value = get_metadata( $this->meta_type, $id, $meta_key, $single );
146
+			$value = get_metadata($this->meta_type, $id, $meta_key, $single);
147 147
 		}
148 148
 
149 149
 		return $value;
@@ -165,18 +165,18 @@  discard block
 block discarded – undo
165 165
 	 *
166 166
 	 * @return  int|bool                  False for failure. True for success.
167 167
 	 */
168
-	public function add_meta( $id = 0, $meta_key = '', $meta_value, $unique = false ) {
169
-		$id = $this->sanitize_id( $id );
168
+	public function add_meta($id = 0, $meta_key = '', $meta_value, $unique = false) {
169
+		$id = $this->sanitize_id($id);
170 170
 
171 171
 		// Bailout.
172
-		if ( ! $this->is_valid_post_type( $id ) ) {
172
+		if ( ! $this->is_valid_post_type($id)) {
173 173
 			return $this->check;
174 174
 		}
175 175
 
176
-		$meta_id = add_metadata( $this->meta_type, $id, $meta_key, $meta_value, $unique );
176
+		$meta_id = add_metadata($this->meta_type, $id, $meta_key, $meta_value, $unique);
177 177
 
178
-		if ( $meta_id ) {
179
-			$this->delete_cache( $id );
178
+		if ($meta_id) {
179
+			$this->delete_cache($id);
180 180
 		}
181 181
 
182 182
 		return $meta_id;
@@ -202,18 +202,18 @@  discard block
 block discarded – undo
202 202
 	 *
203 203
 	 * @return  int|bool                  False on failure, true if success.
204 204
 	 */
205
-	public function update_meta( $id = 0, $meta_key = '', $meta_value, $prev_value = '' ) {
206
-		$id = $this->sanitize_id( $id );
205
+	public function update_meta($id = 0, $meta_key = '', $meta_value, $prev_value = '') {
206
+		$id = $this->sanitize_id($id);
207 207
 
208 208
 		// Bailout.
209
-		if ( ! $this->is_valid_post_type( $id ) ) {
209
+		if ( ! $this->is_valid_post_type($id)) {
210 210
 			return $this->check;
211 211
 		}
212 212
 
213
-		$meta_id = update_metadata( $this->meta_type, $id, $meta_key, $meta_value, $prev_value );
213
+		$meta_id = update_metadata($this->meta_type, $id, $meta_key, $meta_value, $prev_value);
214 214
 
215
-		if ( $meta_id ) {
216
-			$this->delete_cache( $id );
215
+		if ($meta_id) {
216
+			$this->delete_cache($id);
217 217
 		}
218 218
 
219 219
 		return $meta_id;
@@ -236,18 +236,18 @@  discard block
 block discarded – undo
236 236
 	 *
237 237
 	 * @return  bool                  False for failure. True for success.
238 238
 	 */
239
-	public function delete_meta( $id = 0, $meta_key = '', $meta_value = '', $delete_all = '' ) {
240
-		$id = $this->sanitize_id( $id );
239
+	public function delete_meta($id = 0, $meta_key = '', $meta_value = '', $delete_all = '') {
240
+		$id = $this->sanitize_id($id);
241 241
 
242 242
 		// Bailout.
243
-		if ( ! $this->is_valid_post_type( $id ) ) {
243
+		if ( ! $this->is_valid_post_type($id)) {
244 244
 			return $this->check;
245 245
 		}
246 246
 
247
-		$is_meta_deleted = delete_metadata( $this->meta_type, $id, $meta_key, $meta_value, $delete_all );
247
+		$is_meta_deleted = delete_metadata($this->meta_type, $id, $meta_key, $meta_value, $delete_all);
248 248
 
249
-		if ( $is_meta_deleted ) {
250
-			$this->delete_cache( $id );
249
+		if ($is_meta_deleted) {
250
+			$this->delete_cache($id);
251 251
 		}
252 252
 
253 253
 		return $is_meta_deleted;
@@ -264,41 +264,41 @@  discard block
 block discarded – undo
264 264
 	 *
265 265
 	 * @return string
266 266
 	 */
267
-	public function __rename_meta_table_name_in_query( $clause, $wp_query ) {
267
+	public function __rename_meta_table_name_in_query($clause, $wp_query) {
268 268
 		global $wpdb;
269 269
 
270 270
 		// Add new table to sql query.
271
-		if ( $this->is_post_type_query( $wp_query ) && ! empty( $wp_query->meta_query->queries ) ) {
272
-			$clause = str_replace( "{$wpdb->postmeta}.post_id", "{$this->table_name}.{$this->meta_type}_id", $clause );
273
-			$clause = str_replace( $wpdb->postmeta, $this->table_name, $clause );
271
+		if ($this->is_post_type_query($wp_query) && ! empty($wp_query->meta_query->queries)) {
272
+			$clause = str_replace("{$wpdb->postmeta}.post_id", "{$this->table_name}.{$this->meta_type}_id", $clause);
273
+			$clause = str_replace($wpdb->postmeta, $this->table_name, $clause);
274 274
 
275
-			switch( current_filter() ) {
275
+			switch (current_filter()) {
276 276
 				case 'posts_join':
277
-					$joins = array( 'INNER JOIN', 'LEFT JOIN' );
277
+					$joins = array('INNER JOIN', 'LEFT JOIN');
278 278
 
279
-					foreach ( $joins as $join ) {
280
-						if( false !== strpos( $clause, $join ) ) {
281
-							$clause = explode( $join, $clause );
279
+					foreach ($joins as $join) {
280
+						if (false !== strpos($clause, $join)) {
281
+							$clause = explode($join, $clause);
282 282
 
283
-							foreach ( $clause as $key => $clause_part ) {
284
-								if( empty( $clause_part ) ) {
283
+							foreach ($clause as $key => $clause_part) {
284
+								if (empty($clause_part)) {
285 285
 									continue;
286 286
 								}
287 287
 
288
-								preg_match( '/' . $wpdb->prefix . 'give_paymentmeta AS (.*) ON/', $clause_part, $alias_table_name );
288
+								preg_match('/'.$wpdb->prefix.'give_paymentmeta AS (.*) ON/', $clause_part, $alias_table_name);
289 289
 
290
-								if( isset( $alias_table_name[1] ) ) {
291
-									$clause[$key] = str_replace( "{$alias_table_name[1]}.post_id", "{$alias_table_name[1]}.{$this->meta_type}_id", $clause_part );
290
+								if (isset($alias_table_name[1])) {
291
+									$clause[$key] = str_replace("{$alias_table_name[1]}.post_id", "{$alias_table_name[1]}.{$this->meta_type}_id", $clause_part);
292 292
 								}
293 293
 							}
294 294
 
295
-							$clause = implode( "{$join} ", $clause );
295
+							$clause = implode("{$join} ", $clause);
296 296
 						}
297 297
 					}
298 298
 					break;
299 299
 
300 300
 				case 'posts_where':
301
-					$clause = str_replace( array( 'mt2.post_id', 'mt1.post_id' ), array( "mt2.{$this->meta_type}_id", "mt1.{$this->meta_type}_id" ), $clause );
301
+					$clause = str_replace(array('mt2.post_id', 'mt1.post_id'), array("mt2.{$this->meta_type}_id", "mt1.{$this->meta_type}_id"), $clause);
302 302
 					break;
303 303
 			}
304 304
 		}
@@ -317,19 +317,19 @@  discard block
 block discarded – undo
317 317
 	 *
318 318
 	 * @return bool
319 319
 	 */
320
-	protected function is_post_type_query( $wp_query ) {
320
+	protected function is_post_type_query($wp_query) {
321 321
 		$status = false;
322 322
 
323 323
 		// Check if it is payment query.
324
-		if ( ! empty( $wp_query->query['post_type'] ) ) {
324
+		if ( ! empty($wp_query->query['post_type'])) {
325 325
 			if (
326
-				is_string( $wp_query->query['post_type'] ) &&
326
+				is_string($wp_query->query['post_type']) &&
327 327
 				$this->post_type === $wp_query->query['post_type']
328 328
 			) {
329 329
 				$status = true;
330 330
 			} elseif (
331
-				is_array( $wp_query->query['post_type'] ) &&
332
-				in_array( $this->post_type, $wp_query->query['post_type'] )
331
+				is_array($wp_query->query['post_type']) &&
332
+				in_array($this->post_type, $wp_query->query['post_type'])
333 333
 			) {
334 334
 				$status = true;
335 335
 			}
@@ -348,8 +348,8 @@  discard block
 block discarded – undo
348 348
 	 *
349 349
 	 * @return bool
350 350
 	 */
351
-	protected function is_valid_post_type( $ID ) {
352
-		return $ID && ( $this->post_type === get_post_type( $ID ) );
351
+	protected function is_valid_post_type($ID) {
352
+		return $ID && ($this->post_type === get_post_type($ID));
353 353
 	}
354 354
 
355 355
 	/**
@@ -375,8 +375,8 @@  discard block
 block discarded – undo
375 375
 	 *
376 376
 	 * @return void
377 377
 	 */
378
-	private function delete_cache( $id, $meta_type = '' ) {
379
-		$meta_type = empty( $meta_type ) ? $this->meta_type : $meta_type;
378
+	private function delete_cache($id, $meta_type = '') {
379
+		$meta_type = empty($meta_type) ? $this->meta_type : $meta_type;
380 380
 
381 381
 		$group = array(
382 382
 			// 'form'    => 'give-forms',
@@ -386,8 +386,8 @@  discard block
 block discarded – undo
386 386
 			// 'log'     => 'give-logs',
387 387
 		);
388 388
 
389
-		if ( array_key_exists( $meta_type, $group ) ) {
390
-			Give_Cache::delete_group( $id, $group[ $meta_type ] );
389
+		if (array_key_exists($meta_type, $group)) {
390
+			Give_Cache::delete_group($id, $group[$meta_type]);
391 391
 		}
392 392
 	}
393 393
 
@@ -402,8 +402,8 @@  discard block
 block discarded – undo
402 402
 	 *
403 403
 	 * @return mixed
404 404
 	 */
405
-	public function __call( $name, $arguments ) {
406
-		switch ( $name ) {
405
+	public function __call($name, $arguments) {
406
+		switch ($name) {
407 407
 			case '__add_meta':
408 408
 				$this->check = $arguments[0];
409 409
 				$id          = $arguments[1];
@@ -412,11 +412,11 @@  discard block
 block discarded – undo
412 412
 				$unique      = $arguments[4];
413 413
 
414 414
 				// Bailout.
415
-				if ( ! $this->is_valid_post_type( $id ) ) {
415
+				if ( ! $this->is_valid_post_type($id)) {
416 416
 					return $this->check;
417 417
 				}
418 418
 
419
-				return $this->add_meta( $id, $meta_key, $meta_value, $unique );
419
+				return $this->add_meta($id, $meta_key, $meta_value, $unique);
420 420
 
421 421
 			case '__get_meta':
422 422
 				$this->check = $arguments[0];
@@ -425,13 +425,13 @@  discard block
 block discarded – undo
425 425
 				$single      = $arguments[3];
426 426
 
427 427
 				// Bailout.
428
-				if ( ! $this->is_valid_post_type( $id ) ) {
428
+				if ( ! $this->is_valid_post_type($id)) {
429 429
 					return $this->check;
430 430
 				}
431 431
 
432 432
 				$this->raw_result = true;
433 433
 
434
-				return $this->get_meta( $id, $meta_key, $single );
434
+				return $this->get_meta($id, $meta_key, $single);
435 435
 
436 436
 			case '__update_meta':
437 437
 				$this->check = $arguments[0];
@@ -440,11 +440,11 @@  discard block
 block discarded – undo
440 440
 				$meta_value  = $arguments[3];
441 441
 
442 442
 				// Bailout.
443
-				if ( ! $this->is_valid_post_type( $id ) ) {
443
+				if ( ! $this->is_valid_post_type($id)) {
444 444
 					return $this->check;
445 445
 				}
446 446
 
447
-				return $this->update_meta( $id, $meta_key, $meta_value );
447
+				return $this->update_meta($id, $meta_key, $meta_value);
448 448
 
449 449
 			case '__delete_meta':
450 450
 				$this->check = $arguments[0];
@@ -454,11 +454,11 @@  discard block
 block discarded – undo
454 454
 				$delete_all  = $arguments[3];
455 455
 
456 456
 				// Bailout.
457
-				if ( ! $this->is_valid_post_type( $id ) ) {
457
+				if ( ! $this->is_valid_post_type($id)) {
458 458
 					return $this->check;
459 459
 				}
460 460
 
461
-				return $this->delete_meta( $id, $meta_key, $meta_value, $delete_all );
461
+				return $this->delete_meta($id, $meta_key, $meta_value, $delete_all);
462 462
 		}
463 463
 	}
464 464
 }
465 465
\ No newline at end of file
Please login to merge, or discard this patch.