Completed
Push — master ( 4e7b4c...a8a8a5 )
by Matt
37:00 queued 17:02
created
includes/class-give-db-customers.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 	 * @param int $user_id
283 283
 	 * @param $old_user_data
284 284
 	 *
285
-	 * @return bool
285
+	 * @return false|null
286 286
 	 */
287 287
 	public function update_customer_email_on_user_update( $user_id = 0, $old_user_data ) {
288 288
 
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
 	 * @since  1.0
332 332
 	 *
333 333
 	 * @param  string $field id or email
334
-	 * @param  mixed  $value The Customer ID or email to search
334
+	 * @param  integer  $value The Customer ID or email to search
335 335
 	 *
336 336
 	 * @return mixed          Upon success, an object of the customer. Upon failure, NULL
337 337
 	 */
Please login to merge, or discard this patch.
Spacing   +129 added lines, -129 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
  */
13 13
 
14 14
 // Exit if accessed directly
15
-if ( ! defined( 'ABSPATH' ) ) {
15
+if ( ! defined('ABSPATH')) {
16 16
 	exit;
17 17
 }
18 18
 
@@ -33,11 +33,11 @@  discard block
 block discarded – undo
33 33
 
34 34
 		global $wpdb;
35 35
 
36
-		$this->table_name  = $wpdb->prefix . 'give_customers';
36
+		$this->table_name  = $wpdb->prefix.'give_customers';
37 37
 		$this->primary_key = 'id';
38 38
 		$this->version     = '1.0';
39 39
 		
40
-		add_action( 'profile_update', array( $this, 'update_customer_email_on_user_update' ), 10, 2 );
40
+		add_action('profile_update', array($this, 'update_customer_email_on_user_update'), 10, 2);
41 41
 
42 42
 	}
43 43
 
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 			'purchase_value' => 0.00,
77 77
 			'purchase_count' => 0,
78 78
 			'notes'          => '',
79
-			'date_created'   => date( 'Y-m-d H:i:s' ),
79
+			'date_created'   => date('Y-m-d H:i:s'),
80 80
 		);
81 81
 	}
82 82
 
@@ -86,40 +86,40 @@  discard block
 block discarded – undo
86 86
 	 * @access  public
87 87
 	 * @since   1.0
88 88
 	 */
89
-	public function add( $data = array() ) {
89
+	public function add($data = array()) {
90 90
 
91 91
 		$defaults = array(
92 92
 			'payment_ids' => ''
93 93
 		);
94 94
 
95
-		$args = wp_parse_args( $data, $defaults );
95
+		$args = wp_parse_args($data, $defaults);
96 96
 
97
-		if ( empty( $args['email'] ) ) {
97
+		if (empty($args['email'])) {
98 98
 			return false;
99 99
 		}
100 100
 
101
-		if ( ! empty( $args['payment_ids'] ) && is_array( $args['payment_ids'] ) ) {
102
-			$args['payment_ids'] = implode( ',', array_unique( array_values( $args['payment_ids'] ) ) );
101
+		if ( ! empty($args['payment_ids']) && is_array($args['payment_ids'])) {
102
+			$args['payment_ids'] = implode(',', array_unique(array_values($args['payment_ids'])));
103 103
 		}
104 104
 
105
-		$customer = $this->get_customer_by( 'email', $args['email'] );
105
+		$customer = $this->get_customer_by('email', $args['email']);
106 106
 
107
-		if ( $customer ) {
107
+		if ($customer) {
108 108
 			// update an existing customer
109 109
 
110 110
 			// Update the payment IDs attached to the customer
111
-			if ( ! empty( $args['payment_ids'] ) ) {
111
+			if ( ! empty($args['payment_ids'])) {
112 112
 
113
-				if ( empty( $customer->payment_ids ) ) {
113
+				if (empty($customer->payment_ids)) {
114 114
 
115 115
 					$customer->payment_ids = $args['payment_ids'];
116 116
 
117 117
 				} else {
118 118
 
119
-					$existing_ids          = array_map( 'absint', explode( ',', $customer->payment_ids ) );
120
-					$payment_ids           = array_map( 'absint', explode( ',', $args['payment_ids'] ) );
121
-					$payment_ids           = array_merge( $payment_ids, $existing_ids );
122
-					$customer->payment_ids = implode( ',', array_unique( array_values( $payment_ids ) ) );
119
+					$existing_ids          = array_map('absint', explode(',', $customer->payment_ids));
120
+					$payment_ids           = array_map('absint', explode(',', $args['payment_ids']));
121
+					$payment_ids           = array_merge($payment_ids, $existing_ids);
122
+					$customer->payment_ids = implode(',', array_unique(array_values($payment_ids)));
123 123
 
124 124
 				}
125 125
 
@@ -127,13 +127,13 @@  discard block
 block discarded – undo
127 127
 
128 128
 			}
129 129
 
130
-			$this->update( $customer->id, $args );
130
+			$this->update($customer->id, $args);
131 131
 
132 132
 			return $customer->id;
133 133
 
134 134
 		} else {
135 135
 
136
-			return $this->insert( $args, 'customer' );
136
+			return $this->insert($args, 'customer');
137 137
 
138 138
 		}
139 139
 
@@ -152,20 +152,20 @@  discard block
 block discarded – undo
152 152
 	 *
153 153
 	 * @return bool|false|int
154 154
 	 */
155
-	public function delete( $_id_or_email = false ) {
155
+	public function delete($_id_or_email = false) {
156 156
 
157
-		if ( empty( $_id_or_email ) ) {
157
+		if (empty($_id_or_email)) {
158 158
 			return false;
159 159
 		}
160 160
 
161
-		$column   = is_email( $_id_or_email ) ? 'email' : 'id';
162
-		$customer = $this->get_customer_by( $column, $_id_or_email );
161
+		$column   = is_email($_id_or_email) ? 'email' : 'id';
162
+		$customer = $this->get_customer_by($column, $_id_or_email);
163 163
 
164
-		if ( $customer->id > 0 ) {
164
+		if ($customer->id > 0) {
165 165
 
166 166
 			global $wpdb;
167 167
 
168
-			return $wpdb->delete( $this->table_name, array( 'id' => $customer->id ), array( '%d' ) );
168
+			return $wpdb->delete($this->table_name, array('id' => $customer->id), array('%d'));
169 169
 
170 170
 		} else {
171 171
 			return false;
@@ -179,14 +179,14 @@  discard block
 block discarded – undo
179 179
 	 * @access  public
180 180
 	 * @since   1.0
181 181
 	 */
182
-	public function exists( $value = '', $field = 'email' ) {
182
+	public function exists($value = '', $field = 'email') {
183 183
 		
184 184
 		$columns = $this->get_columns();
185
-		if ( ! array_key_exists( $field, $columns ) ) {
185
+		if ( ! array_key_exists($field, $columns)) {
186 186
 			return false;
187 187
 		}
188 188
 
189
-		return (bool) $this->get_column_by( 'id', $field, $value );
189
+		return (bool) $this->get_column_by('id', $field, $value);
190 190
 
191 191
 	}
192 192
 
@@ -196,16 +196,16 @@  discard block
 block discarded – undo
196 196
 	 * @access  public
197 197
 	 * @since   1.0
198 198
 	 */
199
-	public function attach_payment( $customer_id = 0, $payment_id = 0 ) {
199
+	public function attach_payment($customer_id = 0, $payment_id = 0) {
200 200
 
201
-		$customer = new Give_Customer( $customer_id );
201
+		$customer = new Give_Customer($customer_id);
202 202
 
203
-		if ( empty( $customer->id ) ) {
203
+		if (empty($customer->id)) {
204 204
 			return false;
205 205
 		}
206 206
 
207 207
 		// Attach the payment, but don't increment stats, as this function previously did not
208
-		return $customer->attach_payment( $payment_id, false );
208
+		return $customer->attach_payment($payment_id, false);
209 209
 
210 210
 	}
211 211
 
@@ -215,16 +215,16 @@  discard block
 block discarded – undo
215 215
 	 * @access  public
216 216
 	 * @since   1.0
217 217
 	 */
218
-	public function remove_payment( $customer_id = 0, $payment_id = 0 ) {
218
+	public function remove_payment($customer_id = 0, $payment_id = 0) {
219 219
 
220
-		$customer = new Give_Customer( $customer_id );
220
+		$customer = new Give_Customer($customer_id);
221 221
 
222
-		if ( ! $customer ) {
222
+		if ( ! $customer) {
223 223
 			return false;
224 224
 		}
225 225
 
226 226
 		// Remove the payment, but don't decrease stats, as this function previously did not
227
-		return $customer->remove_payment( $payment_id, false );
227
+		return $customer->remove_payment($payment_id, false);
228 228
 
229 229
 	}
230 230
 
@@ -236,18 +236,18 @@  discard block
 block discarded – undo
236 236
 	 *
237 237
 	 * @return bool
238 238
 	 */
239
-	public function increment_stats( $customer_id = 0, $amount = 0.00 ) {
239
+	public function increment_stats($customer_id = 0, $amount = 0.00) {
240 240
 
241
-		$customer = new Give_Customer( $customer_id );
241
+		$customer = new Give_Customer($customer_id);
242 242
 
243
-		if ( empty( $customer->id ) ) {
243
+		if (empty($customer->id)) {
244 244
 			return false;
245 245
 		}
246 246
 
247 247
 		$increased_count = $customer->increase_purchase_count();
248
-		$increased_value = $customer->increase_value( $amount );
248
+		$increased_value = $customer->increase_value($amount);
249 249
 
250
-		return ( $increased_count && $increased_value ) ? true : false;
250
+		return ($increased_count && $increased_value) ? true : false;
251 251
 
252 252
 	}
253 253
 
@@ -257,18 +257,18 @@  discard block
 block discarded – undo
257 257
 	 * @access  public
258 258
 	 * @since   1.0
259 259
 	 */
260
-	public function decrement_stats( $customer_id = 0, $amount = 0.00 ) {
260
+	public function decrement_stats($customer_id = 0, $amount = 0.00) {
261 261
 
262
-		$customer = new Give_Customer( $customer_id );
262
+		$customer = new Give_Customer($customer_id);
263 263
 
264
-		if ( ! $customer ) {
264
+		if ( ! $customer) {
265 265
 			return false;
266 266
 		}
267 267
 
268 268
 		$decreased_count = $customer->decrease_purchase_count();
269
-		$decreased_value = $customer->decrease_value( $amount );
269
+		$decreased_value = $customer->decrease_value($amount);
270 270
 
271
-		return ( $decreased_count && $decreased_value ) ? true : false;
271
+		return ($decreased_count && $decreased_value) ? true : false;
272 272
 
273 273
 	}
274 274
 
@@ -284,37 +284,37 @@  discard block
 block discarded – undo
284 284
 	 *
285 285
 	 * @return bool
286 286
 	 */
287
-	public function update_customer_email_on_user_update( $user_id = 0, $old_user_data ) {
287
+	public function update_customer_email_on_user_update($user_id = 0, $old_user_data) {
288 288
 
289
-		$customer = new Give_Customer( $user_id, true );
289
+		$customer = new Give_Customer($user_id, true);
290 290
 
291
-		if( ! $customer ) {
291
+		if ( ! $customer) {
292 292
 			return false;
293 293
 		}
294 294
 
295
-		$user = get_userdata( $user_id );
295
+		$user = get_userdata($user_id);
296 296
 
297
-		if( ! empty( $user ) && $user->user_email !== $customer->email ) {
297
+		if ( ! empty($user) && $user->user_email !== $customer->email) {
298 298
 
299
-			if( ! $this->get_customer_by( 'email', $user->user_email ) ) {
299
+			if ( ! $this->get_customer_by('email', $user->user_email)) {
300 300
 
301
-				$success = $this->update( $customer->id, array( 'email' => $user->user_email ) );
301
+				$success = $this->update($customer->id, array('email' => $user->user_email));
302 302
 
303
-				if( $success ) {
303
+				if ($success) {
304 304
 					// Update some payment meta if we need to
305
-					$payments_array = explode( ',', $customer->payment_ids );
305
+					$payments_array = explode(',', $customer->payment_ids);
306 306
 
307
-					if( ! empty( $payments_array ) ) {
307
+					if ( ! empty($payments_array)) {
308 308
 
309
-						foreach ( $payments_array as $payment_id ) {
309
+						foreach ($payments_array as $payment_id) {
310 310
 
311
-							give_update_payment_meta( $payment_id, 'email', $user->user_email );
311
+							give_update_payment_meta($payment_id, 'email', $user->user_email);
312 312
 
313 313
 						}
314 314
 
315 315
 					}
316 316
 
317
-					do_action( 'give_update_customer_email_on_user_update', $user, $customer );
317
+					do_action('give_update_customer_email_on_user_update', $user, $customer);
318 318
 
319 319
 				}
320 320
 
@@ -335,45 +335,45 @@  discard block
 block discarded – undo
335 335
 	 *
336 336
 	 * @return mixed          Upon success, an object of the customer. Upon failure, NULL
337 337
 	 */
338
-	public function get_customer_by( $field = 'id', $value = 0 ) {
338
+	public function get_customer_by($field = 'id', $value = 0) {
339 339
 		global $wpdb;
340 340
 
341
-		if ( empty( $field ) || empty( $value ) ) {
341
+		if (empty($field) || empty($value)) {
342 342
 			return null;
343 343
 		}
344 344
 
345
-		if ( 'id' == $field || 'user_id' == $field ) {
345
+		if ('id' == $field || 'user_id' == $field) {
346 346
 			// Make sure the value is numeric to avoid casting objects, for example,
347 347
 			// to int 1.
348
-			if ( ! is_numeric( $value ) ) {
348
+			if ( ! is_numeric($value)) {
349 349
 				return false;
350 350
 			}
351 351
 
352
-			$value = intval( $value );
352
+			$value = intval($value);
353 353
 
354
-			if ( $value < 1 ) {
354
+			if ($value < 1) {
355 355
 				return false;
356 356
 			}
357 357
 
358
-		} elseif ( 'email' === $field ) {
358
+		} elseif ('email' === $field) {
359 359
 
360
-			if ( ! is_email( $value ) ) {
360
+			if ( ! is_email($value)) {
361 361
 				return false;
362 362
 			}
363 363
 
364
-			$value = trim( $value );
364
+			$value = trim($value);
365 365
 		}
366 366
 
367
-		if ( ! $value ) {
367
+		if ( ! $value) {
368 368
 			return false;
369 369
 		}
370 370
 
371
-		switch ( $field ) {
371
+		switch ($field) {
372 372
 			case 'id':
373 373
 				$db_field = 'id';
374 374
 				break;
375 375
 			case 'email':
376
-				$value    = sanitize_text_field( $value );
376
+				$value    = sanitize_text_field($value);
377 377
 				$db_field = 'email';
378 378
 				break;
379 379
 			case 'user_id':
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
 				return false;
384 384
 		}
385 385
 
386
-		if ( ! $customer = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $db_field = %s LIMIT 1", $value ) ) ) {
386
+		if ( ! $customer = $wpdb->get_row($wpdb->prepare("SELECT * FROM $this->table_name WHERE $db_field = %s LIMIT 1", $value))) {
387 387
 			return false;
388 388
 		}
389 389
 
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
 	 * @access  public
397 397
 	 * @since   1.0
398 398
 	 */
399
-	public function get_customers( $args = array() ) {
399
+	public function get_customers($args = array()) {
400 400
 
401 401
 		global $wpdb;
402 402
 
@@ -408,21 +408,21 @@  discard block
 block discarded – undo
408 408
 			'order'   => 'DESC'
409 409
 		);
410 410
 
411
-		$args = wp_parse_args( $args, $defaults );
411
+		$args = wp_parse_args($args, $defaults);
412 412
 
413
-		if ( $args['number'] < 1 ) {
413
+		if ($args['number'] < 1) {
414 414
 			$args['number'] = 999999999999;
415 415
 		}
416 416
 
417 417
 		$where = ' WHERE 1=1 ';
418 418
 
419 419
 		// specific customers
420
-		if ( ! empty( $args['id'] ) ) {
420
+		if ( ! empty($args['id'])) {
421 421
 
422
-			if ( is_array( $args['id'] ) ) {
423
-				$ids = implode( ',', array_map( 'intval', $args['id'] ) );
422
+			if (is_array($args['id'])) {
423
+				$ids = implode(',', array_map('intval', $args['id']));
424 424
 			} else {
425
-				$ids = intval( $args['id'] );
425
+				$ids = intval($args['id']);
426 426
 			}
427 427
 
428 428
 			$where .= " AND `id` IN( {$ids} ) ";
@@ -430,12 +430,12 @@  discard block
 block discarded – undo
430 430
 		}
431 431
 
432 432
 		// customers for specific user accounts
433
-		if ( ! empty( $args['user_id'] ) ) {
433
+		if ( ! empty($args['user_id'])) {
434 434
 
435
-			if ( is_array( $args['user_id'] ) ) {
436
-				$user_ids = implode( ',', array_map( 'intval', $args['user_id'] ) );
435
+			if (is_array($args['user_id'])) {
436
+				$user_ids = implode(',', array_map('intval', $args['user_id']));
437 437
 			} else {
438
-				$user_ids = intval( $args['user_id'] );
438
+				$user_ids = intval($args['user_id']);
439 439
 			}
440 440
 
441 441
 			$where .= " AND `user_id` IN( {$user_ids} ) ";
@@ -443,41 +443,41 @@  discard block
 block discarded – undo
443 443
 		}
444 444
 
445 445
 		//specific customers by email
446
-		if( ! empty( $args['email'] ) ) {
446
+		if ( ! empty($args['email'])) {
447 447
 
448
-			if( is_array( $args['email'] ) ) {
448
+			if (is_array($args['email'])) {
449 449
 
450
-				$emails_count       = count( $args['email'] );
451
-				$emails_placeholder = array_fill( 0, $emails_count, '%s' );
452
-				$emails             = implode( ', ', $emails_placeholder );
450
+				$emails_count       = count($args['email']);
451
+				$emails_placeholder = array_fill(0, $emails_count, '%s');
452
+				$emails             = implode(', ', $emails_placeholder);
453 453
 
454
-				$where .= $wpdb->prepare( " AND `email` IN( $emails ) ", $args['email'] );
454
+				$where .= $wpdb->prepare(" AND `email` IN( $emails ) ", $args['email']);
455 455
 			} else {
456
-				$where .= $wpdb->prepare( " AND `email` = %s ", $args['email'] );
456
+				$where .= $wpdb->prepare(" AND `email` = %s ", $args['email']);
457 457
 			}
458 458
 		}
459 459
 
460 460
 		// specific customers by name
461
-		if( ! empty( $args['name'] ) ) {
462
-			$where .= $wpdb->prepare( " AND `name` LIKE '%%%%" . '%s' . "%%%%' ", $args['name'] );
461
+		if ( ! empty($args['name'])) {
462
+			$where .= $wpdb->prepare(" AND `name` LIKE '%%%%".'%s'."%%%%' ", $args['name']);
463 463
 		}
464 464
 
465 465
 		// Customers created for a specific date or in a date range
466
-		if ( ! empty( $args['date'] ) ) {
466
+		if ( ! empty($args['date'])) {
467 467
 
468
-			if ( is_array( $args['date'] ) ) {
468
+			if (is_array($args['date'])) {
469 469
 
470
-				if ( ! empty( $args['date']['start'] ) ) {
470
+				if ( ! empty($args['date']['start'])) {
471 471
 
472
-					$start = date( 'Y-m-d H:i:s', strtotime( $args['date']['start'] ) );
472
+					$start = date('Y-m-d H:i:s', strtotime($args['date']['start']));
473 473
 
474 474
 					$where .= " AND `date_created` >= '{$start}'";
475 475
 
476 476
 				}
477 477
 
478
-				if ( ! empty( $args['date']['end'] ) ) {
478
+				if ( ! empty($args['date']['end'])) {
479 479
 
480
-					$end = date( 'Y-m-d H:i:s', strtotime( $args['date']['end'] ) );
480
+					$end = date('Y-m-d H:i:s', strtotime($args['date']['end']));
481 481
 
482 482
 					$where .= " AND `date_created` <= '{$end}'";
483 483
 
@@ -485,31 +485,31 @@  discard block
 block discarded – undo
485 485
 
486 486
 			} else {
487 487
 
488
-				$year  = date( 'Y', strtotime( $args['date'] ) );
489
-				$month = date( 'm', strtotime( $args['date'] ) );
490
-				$day   = date( 'd', strtotime( $args['date'] ) );
488
+				$year  = date('Y', strtotime($args['date']));
489
+				$month = date('m', strtotime($args['date']));
490
+				$day   = date('d', strtotime($args['date']));
491 491
 
492 492
 				$where .= " AND $year = YEAR ( date_created ) AND $month = MONTH ( date_created ) AND $day = DAY ( date_created )";
493 493
 			}
494 494
 
495 495
 		}
496 496
 
497
-		$args['orderby'] = ! array_key_exists( $args['orderby'], $this->get_columns() ) ? 'id' : $args['orderby'];
497
+		$args['orderby'] = ! array_key_exists($args['orderby'], $this->get_columns()) ? 'id' : $args['orderby'];
498 498
 
499
-		if ( 'purchase_value' == $args['orderby'] ) {
499
+		if ('purchase_value' == $args['orderby']) {
500 500
 			$args['orderby'] = 'purchase_value+0';
501 501
 		}
502 502
 
503
-		$cache_key = md5( 'give_customers_' . serialize( $args ) );
503
+		$cache_key = md5('give_customers_'.serialize($args));
504 504
 
505
-		$customers = wp_cache_get( $cache_key, 'customers' );
505
+		$customers = wp_cache_get($cache_key, 'customers');
506 506
 
507
-		$args['orderby'] = esc_sql( $args['orderby'] );
508
-		$args['order']   = esc_sql( $args['order'] );
507
+		$args['orderby'] = esc_sql($args['orderby']);
508
+		$args['order']   = esc_sql($args['order']);
509 509
 
510
-		if ( $customers === false ) {
511
-			$customers = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM  $this->table_name $where ORDER BY {$args['orderby']} {$args['order']} LIMIT %d,%d;", absint( $args['offset'] ), absint( $args['number'] ) ) );
512
-			wp_cache_set( $cache_key, $customers, 'customers', 3600 );
510
+		if ($customers === false) {
511
+			$customers = $wpdb->get_results($wpdb->prepare("SELECT * FROM  $this->table_name $where ORDER BY {$args['orderby']} {$args['order']} LIMIT %d,%d;", absint($args['offset']), absint($args['number'])));
512
+			wp_cache_set($cache_key, $customers, 'customers', 3600);
513 513
 		}
514 514
 
515 515
 		return $customers;
@@ -523,26 +523,26 @@  discard block
 block discarded – undo
523 523
 	 * @access  public
524 524
 	 * @since   1.0
525 525
 	 */
526
-	public function count( $args = array() ) {
526
+	public function count($args = array()) {
527 527
 
528 528
 		global $wpdb;
529 529
 
530 530
 		$where = ' WHERE 1=1 ';
531 531
 
532
-		if ( ! empty( $args['date'] ) ) {
532
+		if ( ! empty($args['date'])) {
533 533
 
534
-			if ( is_array( $args['date'] ) ) {
534
+			if (is_array($args['date'])) {
535 535
 
536
-				$start = date( 'Y-m-d H:i:s', strtotime( $args['date']['start'] ) );
537
-				$end   = date( 'Y-m-d H:i:s', strtotime( $args['date']['end'] ) );
536
+				$start = date('Y-m-d H:i:s', strtotime($args['date']['start']));
537
+				$end   = date('Y-m-d H:i:s', strtotime($args['date']['end']));
538 538
 
539 539
 				$where .= " AND `date_created` >= '{$start}' AND `date_created` <= '{$end}'";
540 540
 
541 541
 			} else {
542 542
 
543
-				$year  = date( 'Y', strtotime( $args['date'] ) );
544
-				$month = date( 'm', strtotime( $args['date'] ) );
545
-				$day   = date( 'd', strtotime( $args['date'] ) );
543
+				$year  = date('Y', strtotime($args['date']));
544
+				$month = date('m', strtotime($args['date']));
545
+				$day   = date('d', strtotime($args['date']));
546 546
 
547 547
 				$where .= " AND $year = YEAR ( date_created ) AND $month = MONTH ( date_created ) AND $day = DAY ( date_created )";
548 548
 			}
@@ -550,16 +550,16 @@  discard block
 block discarded – undo
550 550
 		}
551 551
 
552 552
 
553
-		$cache_key = md5( 'give_customers_count' . serialize( $args ) );
553
+		$cache_key = md5('give_customers_count'.serialize($args));
554 554
 
555
-		$count = wp_cache_get( $cache_key, 'customers' );
555
+		$count = wp_cache_get($cache_key, 'customers');
556 556
 
557
-		if ( $count === false ) {
558
-			$count = $wpdb->get_var( "SELECT COUNT($this->primary_key) FROM " . $this->table_name . "{$where};" );
559
-			wp_cache_set( $cache_key, $count, 'customers', 3600 );
557
+		if ($count === false) {
558
+			$count = $wpdb->get_var("SELECT COUNT($this->primary_key) FROM ".$this->table_name."{$where};");
559
+			wp_cache_set($cache_key, $count, 'customers', 3600);
560 560
 		}
561 561
 
562
-		return absint( $count );
562
+		return absint($count);
563 563
 
564 564
 	}
565 565
 
@@ -571,9 +571,9 @@  discard block
 block discarded – undo
571 571
 	 */
572 572
 	public function create_table() {
573 573
 		
574
-		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
574
+		require_once(ABSPATH.'wp-admin/includes/upgrade.php');
575 575
 
576
-		$sql = "CREATE TABLE " . $this->table_name . " (
576
+		$sql = "CREATE TABLE ".$this->table_name." (
577 577
 		id bigint(20) NOT NULL AUTO_INCREMENT,
578 578
 		user_id bigint(20) NOT NULL,
579 579
 		email varchar(50) NOT NULL,
@@ -588,9 +588,9 @@  discard block
 block discarded – undo
588 588
 		KEY user (user_id)
589 589
 		) CHARACTER SET utf8 COLLATE utf8_general_ci;";
590 590
 
591
-		dbDelta( $sql );
591
+		dbDelta($sql);
592 592
 
593
-		update_option( $this->table_name . '_db_version', $this->version );
593
+		update_option($this->table_name.'_db_version', $this->version);
594 594
 	}
595 595
 	
596 596
 	/**
@@ -600,6 +600,6 @@  discard block
 block discarded – undo
600 600
 	 * @return bool Returns if the customers table was installed and upgrade routine run
601 601
 	 */
602 602
 	public function installed() {
603
-		return $this->table_exists( $this->table_name );
603
+		return $this->table_exists($this->table_name);
604 604
 	}
605 605
 }
Please login to merge, or discard this patch.
includes/install.php 1 patch
Spacing   +53 added lines, -53 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
 
@@ -24,15 +24,15 @@  discard block
 block discarded – undo
24 24
  * @global $wp_version
25 25
  * @return void
26 26
  */
27
-function give_install( $network_wide = false ) {
27
+function give_install($network_wide = false) {
28 28
 
29 29
 	global $wpdb;
30 30
 
31
-	if ( is_multisite() && $network_wide ) {
31
+	if (is_multisite() && $network_wide) {
32 32
 
33
-		foreach ( $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs LIMIT 100" ) as $blog_id ) {
33
+		foreach ($wpdb->get_col("SELECT blog_id FROM $wpdb->blogs LIMIT 100") as $blog_id) {
34 34
 
35
-			switch_to_blog( $blog_id );
35
+			switch_to_blog($blog_id);
36 36
 			give_run_install();
37 37
 			restore_current_blog();
38 38
 
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 
47 47
 }
48 48
 
49
-register_activation_hook( GIVE_PLUGIN_FILE, 'give_install' );
49
+register_activation_hook(GIVE_PLUGIN_FILE, 'give_install');
50 50
 
51 51
 /**
52 52
  * Run the Give Install process
@@ -62,25 +62,25 @@  discard block
 block discarded – undo
62 62
 	give_setup_post_types();
63 63
 
64 64
 	// Clear the permalinks
65
-	flush_rewrite_rules( false );
65
+	flush_rewrite_rules(false);
66 66
 
67 67
 	// Add Upgraded From Option
68
-	$current_version = get_option( 'give_version' );
69
-	if ( $current_version ) {
70
-		update_option( 'give_version_upgraded_from', $current_version );
68
+	$current_version = get_option('give_version');
69
+	if ($current_version) {
70
+		update_option('give_version_upgraded_from', $current_version);
71 71
 	}
72 72
 
73 73
 	// Setup some default options
74 74
 	$options = array();
75 75
 
76 76
 	// Checks if the Success Page option exists AND that the page exists
77
-	if ( ! get_post( give_get_option( 'success_page' ) ) ) {
77
+	if ( ! get_post(give_get_option('success_page'))) {
78 78
 
79 79
 		// Purchase Confirmation (Success) Page
80 80
 		$success = wp_insert_post(
81 81
 			array(
82
-				'post_title'     => __( 'Donation Confirmation', 'give' ),
83
-				'post_content'   => __( '[give_receipt]', 'give' ),
82
+				'post_title'     => __('Donation Confirmation', 'give'),
83
+				'post_content'   => __('[give_receipt]', 'give'),
84 84
 				'post_status'    => 'publish',
85 85
 				'post_author'    => 1,
86 86
 				'post_type'      => 'page',
@@ -93,13 +93,13 @@  discard block
 block discarded – undo
93 93
 	}
94 94
 
95 95
 	// Checks if the Failure Page option exists AND that the page exists
96
-	if ( ! get_post( give_get_option( 'failure_page' ) ) ) {
96
+	if ( ! get_post(give_get_option('failure_page'))) {
97 97
 
98 98
 		// Failed Purchase Page
99 99
 		$failed = wp_insert_post(
100 100
 			array(
101
-				'post_title'     => __( 'Transaction Failed', 'give' ),
102
-				'post_content'   => __( 'We\'re sorry, your transaction failed to process. Please try again or contact site support.', 'give' ),
101
+				'post_title'     => __('Transaction Failed', 'give'),
102
+				'post_content'   => __('We\'re sorry, your transaction failed to process. Please try again or contact site support.', 'give'),
103 103
 				'post_status'    => 'publish',
104 104
 				'post_author'    => 1,
105 105
 				'post_type'      => 'page',
@@ -111,11 +111,11 @@  discard block
 block discarded – undo
111 111
 	}
112 112
 
113 113
 	// Checks if the History Page option exists AND that the page exists
114
-	if ( ! get_post( give_get_option( 'history_page' ) ) ) {
114
+	if ( ! get_post(give_get_option('history_page'))) {
115 115
 		// Purchase History (History) Page
116 116
 		$history = wp_insert_post(
117 117
 			array(
118
-				'post_title'     => __( 'Donation History', 'give' ),
118
+				'post_title'     => __('Donation History', 'give'),
119 119
 				'post_content'   => '[donation_history]',
120 120
 				'post_status'    => 'publish',
121 121
 				'post_author'    => 1,
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 	}
129 129
 
130 130
 	//Fresh Install? Setup Test Mode, Base Country (US), Test Gateway, Currency
131
-	if ( empty( $current_version ) ) {
131
+	if (empty($current_version)) {
132 132
 		$options['base_country']       = 'US';
133 133
 		$options['test_mode']          = 1;
134 134
 		$options['currency']           = 'USD';
@@ -145,12 +145,12 @@  discard block
 block discarded – undo
145 145
 	}
146 146
 
147 147
 	// Populate some default values
148
-	update_option( 'give_settings', array_merge( $give_options, $options ) );
149
-	update_option( 'give_version', GIVE_VERSION );
148
+	update_option('give_settings', array_merge($give_options, $options));
149
+	update_option('give_version', GIVE_VERSION);
150 150
 
151 151
 	//Update Version Number
152
-	if ( $current_version ) {
153
-		update_option( 'give_version_upgraded_from', $current_version );
152
+	if ($current_version) {
153
+		update_option('give_version_upgraded_from', $current_version);
154 154
 	}
155 155
 
156 156
 	// Create Give roles
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 	$roles->add_caps();
160 160
 
161 161
 	$api = new Give_API();
162
-	update_option( 'give_default_api_version', 'v' . $api->get_version() );
162
+	update_option('give_default_api_version', 'v'.$api->get_version());
163 163
 
164 164
 	// Create the customers database
165 165
 	@Give()->customers->create_table();
@@ -168,11 +168,11 @@  discard block
 block discarded – undo
168 168
 	Give()->session->use_php_sessions();
169 169
 
170 170
 	// Add a temporary option to note that Give pages have been created
171
-	set_transient( '_give_installed', $options, 30 );
171
+	set_transient('_give_installed', $options, 30);
172 172
 	
173
-	if ( ! $current_version ) {
173
+	if ( ! $current_version) {
174 174
 
175
-		require_once GIVE_PLUGIN_DIR . 'includes/admin/upgrades/upgrade-functions.php';
175
+		require_once GIVE_PLUGIN_DIR.'includes/admin/upgrades/upgrade-functions.php';
176 176
 
177 177
 		// When new upgrade routines are added, mark them as complete on fresh install
178 178
 		$upgrade_routines = array(
@@ -180,22 +180,22 @@  discard block
 block discarded – undo
180 180
 			'upgrade_give_offline_status'
181 181
 		);
182 182
 
183
-		foreach ( $upgrade_routines as $upgrade ) {
184
-			give_set_upgrade_complete( $upgrade );
183
+		foreach ($upgrade_routines as $upgrade) {
184
+			give_set_upgrade_complete($upgrade);
185 185
 		}
186 186
 	}
187 187
 
188 188
 	// Bail if activating from network, or bulk
189
-	if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
189
+	if (is_network_admin() || isset($_GET['activate-multi'])) {
190 190
 		return;
191 191
 	}
192 192
 
193 193
 	// Add the transient to redirect
194
-	set_transient( '_give_activation_redirect', true, 30 );
194
+	set_transient('_give_activation_redirect', true, 30);
195 195
 
196 196
 }
197 197
 
198
-register_activation_hook( GIVE_PLUGIN_FILE, 'give_install' );
198
+register_activation_hook(GIVE_PLUGIN_FILE, 'give_install');
199 199
 
200 200
 /**
201 201
  * Network Activated New Site Setup
@@ -211,11 +211,11 @@  discard block
 block discarded – undo
211 211
  * @param  int    $site_id The Site ID
212 212
  * @param  array  $meta    Blog Meta
213 213
  */
214
-function on_create_blog( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
214
+function on_create_blog($blog_id, $user_id, $domain, $path, $site_id, $meta) {
215 215
 
216
-	if ( is_plugin_active_for_network( GIVE_PLUGIN_BASENAME ) ) {
216
+	if (is_plugin_active_for_network(GIVE_PLUGIN_BASENAME)) {
217 217
 
218
-		switch_to_blog( $blog_id );
218
+		switch_to_blog($blog_id);
219 219
 		give_install();
220 220
 		restore_current_blog();
221 221
 
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
 
224 224
 }
225 225
 
226
-add_action( 'wpmu_new_blog', 'on_create_blog', 10, 6 );
226
+add_action('wpmu_new_blog', 'on_create_blog', 10, 6);
227 227
 
228 228
 
229 229
 /**
@@ -236,11 +236,11 @@  discard block
 block discarded – undo
236 236
  *
237 237
  * @return array          The tables to drop
238 238
  */
239
-function give_wpmu_drop_tables( $tables, $blog_id ) {
239
+function give_wpmu_drop_tables($tables, $blog_id) {
240 240
 
241
-	switch_to_blog( $blog_id );
241
+	switch_to_blog($blog_id);
242 242
 	$customers_db = new Give_DB_Customers();
243
-	if ( $customers_db->installed() ) {
243
+	if ($customers_db->installed()) {
244 244
 		$tables[] = $customers_db->table_name;
245 245
 	}
246 246
 	restore_current_blog();
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 
250 250
 }
251 251
 
252
-add_filter( 'wpmu_drop_tables', 'give_wpmu_drop_tables', 10, 2 );
252
+add_filter('wpmu_drop_tables', 'give_wpmu_drop_tables', 10, 2);
253 253
 
254 254
 /**
255 255
  * Post-installation
@@ -261,35 +261,35 @@  discard block
 block discarded – undo
261 261
  */
262 262
 function give_after_install() {
263 263
 
264
-	if ( ! is_admin() ) {
264
+	if ( ! is_admin()) {
265 265
 		return;
266 266
 	}
267 267
 
268
-	$give_options     = get_transient( '_give_installed' );
269
-	$give_table_check = get_option( '_give_table_check', false );
268
+	$give_options     = get_transient('_give_installed');
269
+	$give_table_check = get_option('_give_table_check', false);
270 270
 
271
-	if ( false === $give_table_check || current_time( 'timestamp' ) > $give_table_check ) {
271
+	if (false === $give_table_check || current_time('timestamp') > $give_table_check) {
272 272
 
273
-		if ( ! @Give()->customers->installed() ) {
273
+		if ( ! @Give()->customers->installed()) {
274 274
 			// Create the customers database (this ensures it creates it on multisite instances where it is network activated)
275 275
 			@Give()->customers->create_table();
276 276
 
277
-			do_action( 'give_after_install', $give_options );
277
+			do_action('give_after_install', $give_options);
278 278
 		}
279 279
 
280
-		update_option( '_give_table_check', ( current_time( 'timestamp' ) + WEEK_IN_SECONDS ) );
280
+		update_option('_give_table_check', (current_time('timestamp') + WEEK_IN_SECONDS));
281 281
 
282 282
 	}
283 283
 
284 284
 	// Delete the transient
285
-	if ( false !== $give_options ) {
286
-		delete_transient( '_give_installed' );
285
+	if (false !== $give_options) {
286
+		delete_transient('_give_installed');
287 287
 	}
288 288
 
289 289
 
290 290
 }
291 291
 
292
-add_action( 'admin_init', 'give_after_install' );
292
+add_action('admin_init', 'give_after_install');
293 293
 
294 294
 
295 295
 /**
@@ -304,11 +304,11 @@  discard block
 block discarded – undo
304 304
 
305 305
 	global $wp_roles;
306 306
 
307
-	if ( ! is_object( $wp_roles ) ) {
307
+	if ( ! is_object($wp_roles)) {
308 308
 		return;
309 309
 	}
310 310
 
311
-	if ( ! array_key_exists( 'give_manager', $wp_roles->roles ) ) {
311
+	if ( ! array_key_exists('give_manager', $wp_roles->roles)) {
312 312
 
313 313
 		// Create Give plugin roles
314 314
 		$roles = new Give_Roles;
@@ -319,4 +319,4 @@  discard block
 block discarded – undo
319 319
 
320 320
 }
321 321
 
322
-add_action( 'admin_init', 'give_install_roles_on_network' );
323 322
\ No newline at end of file
323
+add_action('admin_init', 'give_install_roles_on_network');
324 324
\ No newline at end of file
Please login to merge, or discard this patch.