Test Failed
Pull Request — master (#2558)
by Devin
04:48
created

Give_DB_Donors::create_table()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 5

Duplication

Lines 23
Ratio 88.46 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 23
loc 26
rs 8.8571
c 0
b 0
f 0
1
<?php
2
/**
3
 * Donors DB
4
 *
5
 * @package     Give
6
 * @subpackage  Classes/Give_DB_Donors
7
 * @copyright   Copyright (c) 2016, WordImpress
8
 * @license     https://opensource.org/licenses/gpl-license GNU Public License
9
 * @since       1.0
10
 */
11
12
// Exit if accessed directly.
13
if ( ! defined( 'ABSPATH' ) ) {
14
	exit;
15
}
16
17
/**
18
 * Give_DB_Donors Class
19
 *
20
 * This class is for interacting with the donor database table.
21
 *
22
 * @since 1.0
23
 */
24
class Give_DB_Donors extends Give_DB {
25
26
	/**
27
	 * Give_DB_Donors constructor.
28
	 *
29
	 * Set up the Give DB Donor class.
30
	 *
31
	 * @since  1.0
32
	 * @access public
33
	 */
34
	public function __construct() {
35
		/* @var WPDB $wpdb */
36
		global $wpdb;
37
38
		$this->table_name  = $wpdb->prefix . 'give_customers';
39
		$this->primary_key = 'id';
40
		$this->version     = '1.0';
41
42
		// Set hooks and register table only if instance loading first time.
43
		if ( ! ( Give()->donors instanceof Give_DB_Donors ) ) {
44
			// Setup hook.
45
			add_action( 'profile_update', array( $this, 'update_donor_email_on_user_update' ), 10, 2 );
46
47
			// Install table.
48
			$this->register_table();
49
		}
50
51
	}
52
53
	/**
54
	 * Get columns and formats
55
	 *
56
	 * @since  1.0
57
	 * @access public
58
	 *
59
	 * @return array  Columns and formats.
60
	 */
61 View Code Duplication
	public function get_columns() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
62
		return array(
63
			'id'              => '%d',
64
			'user_id'         => '%d',
65
			'name'            => '%s',
66
			'email'           => '%s',
67
			'payment_ids'     => '%s',
68
			'purchase_value'  => '%f',
69
			'purchase_count'  => '%d',
70
			'notes'           => '%s',
71
			'date_created'    => '%s',
72
			'token'           => '%s',
73
			'verify_key'      => '%s',
74
			'verify_throttle' => '%s',
75
		);
76
	}
77
78
	/**
79
	 * Get default column values
80
	 *
81
	 * @since  1.0
82
	 * @access public
83
	 *
84
	 * @return array  Default column values.
85
	 */
86 View Code Duplication
	public function get_column_defaults() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
87
		return array(
88
			'user_id'         => 0,
89
			'email'           => '',
90
			'name'            => '',
91
			'payment_ids'     => '',
92
			'purchase_value'  => 0.00,
93
			'purchase_count'  => 0,
94
			'notes'           => '',
95
			'date_created'    => date( 'Y-m-d H:i:s' ),
96
			'token'           => '',
97
			'verify_key'      => '',
98
			'verify_throttle' => '',
99
		);
100
	}
101
102
	/**
103
	 * Add a donor
104
	 *
105
	 * @since  1.0
106
	 * @access public
107
	 *
108
	 * @param  array $data
109
	 *
110
	 * @return int|bool
111
	 */
112
	public function add( $data = array() ) {
113
114
		$defaults = array(
115
			'payment_ids' => '',
116
		);
117
118
		$args = wp_parse_args( $data, $defaults );
119
120
		if ( empty( $args['email'] ) ) {
121
			return false;
122
		}
123
124 View Code Duplication
		if ( ! empty( $args['payment_ids'] ) && is_array( $args['payment_ids'] ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
125
			$args['payment_ids'] = implode( ',', array_unique( array_values( $args['payment_ids'] ) ) );
126
		}
127
128
		$donor = $this->get_donor_by( 'email', $args['email'] );
129
130
		// update an existing donor.
131
		if ( $donor ) {
132
133
			// Update the payment IDs attached to the donor
134
			if ( ! empty( $args['payment_ids'] ) ) {
135
136
				if ( empty( $donor->payment_ids ) ) {
137
138
					$donor->payment_ids = $args['payment_ids'];
139
140
				} else {
141
142
					$existing_ids       = array_map( 'absint', explode( ',', $donor->payment_ids ) );
143
					$payment_ids        = array_map( 'absint', explode( ',', $args['payment_ids'] ) );
144
					$payment_ids        = array_merge( $payment_ids, $existing_ids );
145
					$donor->payment_ids = implode( ',', array_unique( array_values( $payment_ids ) ) );
146
147
				}
148
149
				$args['payment_ids'] = $donor->payment_ids;
150
151
			}
152
153
			$this->update( $donor->id, $args );
154
155
			return $donor->id;
156
157
		} else {
158
159
			return $this->insert( $args, 'donor' );
160
161
		}
162
163
	}
164
165
	/**
166
	 * Delete a donor.
167
	 *
168
	 * NOTE: This should not be called directly as it does not make necessary changes to
169
	 * the payment meta and logs. Use give_donor_delete() instead.
170
	 *
171
	 * @since  1.0
172
	 * @access public
173
	 *
174
	 * @param  bool|string|int $_id_or_email
175
	 *
176
	 * @return bool|int
177
	 */
178
	public function delete( $_id_or_email = false ) {
179
180
		if ( empty( $_id_or_email ) ) {
181
			return false;
182
		}
183
184
		$column = is_email( $_id_or_email ) ? 'email' : 'id';
185
		$donor  = $this->get_donor_by( $column, $_id_or_email );
186
187
		if ( $donor->id > 0 ) {
188
189
			global $wpdb;
190
191
			/**
192
			 * Deleting the donor meta.
193
			 *
194
			 * @since 1.8.14
195
			 */
196
			Give()->donor_meta->delete_all_meta( $donor->id );
197
198
			return $wpdb->delete( $this->table_name, array( 'id' => $donor->id ), array( '%d' ) );
199
200
		} else {
201
			return false;
202
		}
203
204
	}
205
206
	/**
207
	 * Delete a donor by user ID.
208
	 *
209
	 * NOTE: This should not be called directly as it does not make necessary changes to
210
	 * the payment meta and logs. Use give_donor_delete() instead.
211
	 *
212
	 * @since  1.0
213
	 * @access public
214
	 *
215
	 * @param  int|bool $user_id
216
	 *
217
	 * @return bool|int
218
	 */
219
	public function delete_by_user_id( $user_id = false ) {
220
221
		if ( empty( $user_id ) ) {
222
			return false;
223
		}
224
225
		/**
226
		 * Deleting the donor meta.
227
		 *
228
		 * @since 1.8.14
229
		 */
230
		$donor = new Give_Donor( $user_id, true );
0 ignored issues
show
Bug introduced by
It seems like $user_id defined by parameter $user_id on line 219 can also be of type integer; however, Give_Donor::__construct() does only seem to accept boolean, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
231
		if ( ! empty( $donor->id ) ) {
232
			Give()->donor_meta->delete_all_meta( $donor->id );
233
		}
234
235
		global $wpdb;
236
237
		return $wpdb->delete( $this->table_name, array( 'user_id' => $user_id ), array( '%d' ) );
238
	}
239
240
	/**
241
	 * Checks if a donor exists
242
	 *
243
	 * @since  1.0
244
	 * @access public
245
	 *
246
	 * @param  string $value The value to search for. Default is empty.
247
	 * @param  string $field The Donor ID or email to search in. Default is 'email'.
248
	 *
249
	 * @return bool          True is exists, false otherwise.
250
	 */
251
	public function exists( $value = '', $field = 'email' ) {
252
253
		$columns = $this->get_columns();
254
		if ( ! array_key_exists( $field, $columns ) ) {
255
			return false;
256
		}
257
258
		return (bool) $this->get_column_by( 'id', $field, $value );
259
260
	}
261
262
	/**
263
	 * Attaches a payment ID to a donor
264
	 *
265
	 * @since  1.0
266
	 * @access public
267
	 *
268
	 * @param  int $donor_id   Donor ID.
269
	 * @param  int $payment_id Payment ID.
270
	 *
271
	 * @return bool
272
	 */
273
	public function attach_payment( $donor_id = 0, $payment_id = 0 ) {
274
275
		$donor = new Give_Donor( $donor_id );
0 ignored issues
show
Documentation introduced by
$donor_id is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
276
277
		if ( empty( $donor->id ) ) {
278
			return false;
279
		}
280
281
		// Attach the payment, but don't increment stats, as this function previously did not
282
		return $donor->attach_payment( $payment_id, false );
283
284
	}
285
286
	/**
287
	 * Removes a payment ID from a donor.
288
	 *
289
	 * @since  1.0
290
	 * @access public
291
	 *
292
	 * @param  int $donor_id   Donor ID.
293
	 * @param  int $payment_id Payment ID.
294
	 *
295
	 * @return bool
296
	 */
297
	public function remove_payment( $donor_id = 0, $payment_id = 0 ) {
298
299
		$donor = new Give_Donor( $donor_id );
0 ignored issues
show
Documentation introduced by
$donor_id is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
300
301
		if ( ! $donor ) {
302
			return false;
303
		}
304
305
		// Remove the payment, but don't decrease stats, as this function previously did not
306
		return $donor->remove_payment( $payment_id, false );
307
308
	}
309
310
	/**
311
	 * Increments donor's donation stats.
312
	 *
313
	 * @access public
314
	 *
315
	 * @param int   $donor_id Donor ID.
316
	 * @param float $amount   THe amount to increase.
317
	 *
318
	 * @return bool
319
	 */
320 View Code Duplication
	public function increment_stats( $donor_id = 0, $amount = 0.00 ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
321
322
		$donor = new Give_Donor( $donor_id );
0 ignored issues
show
Documentation introduced by
$donor_id is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
323
324
		if ( empty( $donor->id ) ) {
325
			return false;
326
		}
327
328
		$increased_count = $donor->increase_purchase_count();
329
		$increased_value = $donor->increase_value( $amount );
330
331
		return ( $increased_count && $increased_value ) ? true : false;
0 ignored issues
show
Bug Best Practice introduced by
The expression $increased_count of type false|integer is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
332
333
	}
334
335
	/**
336
	 * Decrements donor's donation stats.
337
	 *
338
	 * @since  1.0
339
	 * @access public
340
	 *
341
	 * @param  int   $donor_id Donor ID.
342
	 * @param  float $amount   Amount.
343
	 *
344
	 * @return bool
345
	 */
346 View Code Duplication
	public function decrement_stats( $donor_id = 0, $amount = 0.00 ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
347
348
		$donor = new Give_Donor( $donor_id );
0 ignored issues
show
Documentation introduced by
$donor_id is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
349
350
		if ( ! $donor ) {
351
			return false;
352
		}
353
354
		$decreased_count = $donor->decrease_donation_count();
355
		$decreased_value = $donor->decrease_value( $amount );
356
357
		return ( $decreased_count && $decreased_value ) ? true : false;
0 ignored issues
show
Bug Best Practice introduced by
The expression $decreased_count of type false|integer is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
358
359
	}
360
361
	/**
362
	 * Updates the email address of a donor record when the email on a user is updated
363
	 *
364
	 * @since  1.4.3
365
	 * @access public
366
	 *
367
	 * @param  int          $user_id       User ID.
368
	 * @param  WP_User|bool $old_user_data User data.
369
	 *
370
	 * @return bool
371
	 */
372
	public function update_donor_email_on_user_update( $user_id = 0, $old_user_data = false ) {
0 ignored issues
show
Unused Code introduced by
The parameter $old_user_data is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
373
374
		$donor = new Give_Donor( $user_id, true );
0 ignored issues
show
Documentation introduced by
$user_id is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
375
376
		if ( ! $donor ) {
377
			return false;
378
		}
379
380
		$user = get_userdata( $user_id );
381
382
		if ( ! empty( $user ) && $user->user_email !== $donor->email ) {
383
384
			if ( ! $this->get_donor_by( 'email', $user->user_email ) ) {
385
386
				$success = $this->update( $donor->id, array( 'email' => $user->user_email ) );
387
388
				if ( $success ) {
389
					// Update some payment meta if we need to
390
					$payments_array = explode( ',', $donor->payment_ids );
391
392
					if ( ! empty( $payments_array ) ) {
393
394
						foreach ( $payments_array as $payment_id ) {
395
396
							give_update_payment_meta( $payment_id, 'email', $user->user_email );
397
398
						}
0 ignored issues
show
introduced by
Blank line found after control structure
Loading history...
399
400
					}
401
402
					/**
403
					 * Fires after updating donor email on user update.
404
					 *
405
					 * @since 1.4.3
406
					 *
407
					 * @param  WP_User    $user  WordPress User object.
408
					 * @param  Give_Donor $donor Give donor object.
409
					 */
410
					do_action( 'give_update_donor_email_on_user_update', $user, $donor );
411
412
				}
0 ignored issues
show
introduced by
Blank line found after control structure
Loading history...
413
414
			}
0 ignored issues
show
introduced by
Blank line found after control structure
Loading history...
415
416
		}
417
418
	}
419
420
	/**
421
	 * Retrieves a single donor from the database
422
	 *
423
	 * @since  1.0
424
	 * @access public
425
	 *
426
	 * @param  string $field ID or email. Default is 'id'.
427
	 * @param  mixed  $value The Customer ID or email to search. Default is 0.
428
	 *
429
	 * @return mixed         Upon success, an object of the donor. Upon failure, NULL
430
	 */
431
	public function get_donor_by( $field = 'id', $value = 0 ) {
432
		$value = sanitize_text_field( $value );
433
434
		// Bailout.
435
		if ( empty( $field ) || empty( $value ) ) {
436
			return null;
437
		}
438
439
		// Verify values.
440
		if ( 'id' === $field || 'user_id' === $field ) {
441
			// Make sure the value is numeric to avoid casting objects, for example,
442
			// to int 1.
443
			if ( ! is_numeric( $value ) ) {
444
				return false;
445
			}
446
447
			$value = absint( $value );
448
449
			if ( $value < 1 ) {
450
				return false;
451
			}
0 ignored issues
show
introduced by
Blank line found after control structure
Loading history...
452
453
		} elseif ( 'email' === $field ) {
454
455
			if ( ! is_email( $value ) ) {
456
				return false;
457
			}
458
459
			$value = trim( $value );
460
		}
461
462
		// Bailout
463
		if ( ! $value ) {
464
			return false;
465
		}
466
467
		// Set query params.
468
		switch ( $field ) {
469
			case 'id':
470
				$args['donor'] = $value;
471
				break;
472
			case 'email':
473
				$args['email'] = $value;
474
				break;
475
			case 'user_id':
476
				$args['user'] = $value;
477
				break;
478
			default:
479
				return false;
480
		}
481
482
		// Get donors.
483
		$donor = new Give_Donors_Query( $args );
484
485
		if ( ! $donor = $donor->get_donors() ) {
486
			// Look for donor from an additional email.
487
			$args = array(
488
				'meta_query' => array(
0 ignored issues
show
introduced by
Detected usage of meta_query, possible slow query.
Loading history...
489
					array(
490
						'key'   => 'additional_email',
491
						'value' => $value,
492
					),
493
				),
494
			);
495
496
			$donor = new Give_Donors_Query( $args );
497
			$donor = $donor->get_donors();
498
499
			if ( empty( $donor ) ) {
500
				return false;
501
			}
502
		}
503
504
		return current( $donor );
505
	}
506
507
	/**
508
	 * Retrieve donors from the database.
509
	 *
510
	 * @since  1.0
511
	 * @access public
512
	 *
513
	 * @param  array $args
514
	 *
515
	 * @return array|object|null Donors array or object. Null if not found.
516
	 */
517
	public function get_donors( $args = array() ) {
518
		$this->bc_1814_params( $args );
519
520
		$cache_key = md5( 'give_donors_' . serialize( $args ) );
521
522
		$donors = wp_cache_get( $cache_key, 'donors' );
523
524 View Code Duplication
		if ( $donors === false ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
introduced by
Found "=== false". Use Yoda Condition checks, you must
Loading history...
525
			$donors = new Give_Donors_Query( $args );
526
			$donors = $donors->get_donors();
527
528
			wp_cache_set( $cache_key, $donors, 'donors', 3600 );
529
		}
530
531
		return $donors;
532
533
	}
534
535
536
	/**
537
	 * Count the total number of donors in the database
538
	 *
539
	 * @since  1.0
540
	 * @access public
541
	 *
542
	 * @param  array $args
543
	 *
544
	 * @return int         Total number of donors.
545
	 */
546
	public function count( $args = array() ) {
547
		$this->bc_1814_params( $args );
548
		$args['count'] = true;
549
550
		$cache_key = md5( 'give_donors_count' . serialize( $args ) );
551
		$count     = wp_cache_get( $cache_key, 'donors' );
552
553 View Code Duplication
		if ( $count === false ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
introduced by
Found "=== false". Use Yoda Condition checks, you must
Loading history...
554
			$donors = new Give_Donors_Query( $args );
555
			$count  = $donors->get_donors();
556
557
			wp_cache_set( $cache_key, $count, 'donors', 3600 );
558
		}
559
560
		return absint( $count );
561
562
	}
563
564
	/**
565
	 * Create the table
566
	 *
567
	 * @since  1.0
568
	 * @access public
569
	 *
570
	 * @return void
571
	 */
572 View Code Duplication
	public function create_table() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
573
574
		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
575
576
		$sql = "CREATE TABLE " . $this->table_name . " (
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal CREATE TABLE does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal (\n id bigint(20...OLLATE utf8_general_ci; does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
577
		id bigint(20) NOT NULL AUTO_INCREMENT,
578
		user_id bigint(20) NOT NULL,
579
		email varchar(50) NOT NULL,
580
		name mediumtext NOT NULL,
581
		purchase_value mediumtext NOT NULL,
582
		purchase_count bigint(20) NOT NULL,
583
		payment_ids longtext NOT NULL,
584
		notes longtext NOT NULL,
585
		date_created datetime NOT NULL,
586
		token VARCHAR(255) CHARACTER SET utf8 NOT NULL,
587
		verify_key VARCHAR(255) CHARACTER SET utf8 NOT NULL,
588
		verify_throttle DATETIME NOT NULL,
589
		PRIMARY KEY  (id),
590
		UNIQUE KEY email (email),
591
		KEY user (user_id)
592
		) CHARACTER SET utf8 COLLATE utf8_general_ci;";
593
594
		dbDelta( $sql );
595
596
		update_option( $this->table_name . '_db_version', $this->version );
597
	}
598
599
	/**
600
	 * Check if the Customers table was ever installed
601
	 *
602
	 * @since  1.4.3
603
	 * @access public
604
	 *
605
	 * @return bool Returns if the donors table was installed and upgrade routine run.
606
	 */
607
	public function installed() {
608
		return $this->table_exists( $this->table_name );
609
	}
610
611
	/**
612
	 * Add backward compatibility for deprecated param
613
	 *
614
	 * @since  1.8.14
615
	 * @access private
616
	 *
617
	 * @param $args
618
	 */
619
	private function bc_1814_params( &$args ) {
620
		// Backward compatibility: user_id
621
		if ( ! empty( $args['user_id'] ) ) {
622
			$args['user'] = $args['user_id'];
623
		}
624
625
		// Backward compatibility: id
626
		if ( ! empty( $args['id'] ) ) {
627
			$args['donor'] = $args['id'];
628
		}
629
630
		// Backward compatibility: name
631
		if ( ! empty( $args['name'] ) ) {
632
			$args['s'] = "name:{$args['name']}";
633
		}
634
635
		// Backward compatibility: date
636
		// Donors created for a specific date or in a date range.
637
		if ( ! empty( $args['date'] ) ) {
638
639
			if ( is_array( $args['date'] ) ) {
640
641 View Code Duplication
				if ( ! empty( $args['date']['start'] ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
642
					$args['date_query']['after'] = date( 'Y-m-d H:i:s', strtotime( $args['date']['start'] ) );
643
				}
644
645 View Code Duplication
				if ( ! empty( $args['date']['end'] ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
646
					$args['date_query']['before'] = date( 'Y-m-d H:i:s', strtotime( $args['date']['end'] ) );
647
				}
0 ignored issues
show
introduced by
Blank line found after control structure
Loading history...
648
649
			} else {
650
651
				$args['date_query']['year']  = date( 'Y', strtotime( $args['date'] ) );
652
				$args['date_query']['month'] = date( 'm', strtotime( $args['date'] ) );
653
				$args['date_query']['day']   = date( 'd', strtotime( $args['date'] ) );
654
			}
0 ignored issues
show
introduced by
Blank line found after control structure
Loading history...
655
656
		}
657
	}
658
}
659