Test Setup Failed
Push — issue/3871 ( 31b6b8 )
by Ravinder
07:30
created

Give_Donors_Query::get_where_user()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 0
dl 15
loc 15
rs 9.7666
c 0
b 0
f 0
1
<?php
2
/**
3
 * Donors Query
4
 *
5
 * @package     Give
6
 * @subpackage  Classes/Stats
7
 * @copyright   Copyright (c) 2017, GiveWP
8
 * @license     https://opensource.org/licenses/gpl-license GNU Public License
9
 * @since       1.8.14
10
 */
11
12
// Exit if accessed directly.
13
if ( ! defined( 'ABSPATH' ) ) {
14
	exit;
15
}
16
17
/**
18
 * Give_Donors_Query Class
19
 *
20
 * This class is for retrieving donors data.
21
 *
22
 * Donors can be retrieved for date ranges and pre-defined periods.
23
 *
24
 * @since 1.8.14
25
 */
26
class Give_Donors_Query {
27
28
	/**
29
	 * The args to pass to the give_get_donors() query
30
	 *
31
	 * @since  1.8.14
32
	 * @access public
33
	 *
34
	 * @var    array
35
	 */
36
	public $args = array();
37
38
	/**
39
	 * The donors found based on the criteria set
40
	 *
41
	 * @since  1.8.14
42
	 * @access public
43
	 *
44
	 * @var    array
45
	 */
46
	public $donors = array();
47
48
	/**
49
	 * The donors found based on the criteria set
50
	 *
51
	 * @since  1.8.14
52
	 * @access public
53
	 *
54
	 * @var    string
55
	 */
56
	public $table_name = '';
57
58
	/**
59
	 * The donors found based on the criteria set
60
	 *
61
	 * @since  1.8.14
62
	 * @access public
63
	 *
64
	 * @var    string
65
	 */
66
	public $meta_table_name = '';
67
68
	/**
69
	 * The donors found based on the criteria set
70
	 *
71
	 * @since  1.8.14
72
	 * @access public
73
	 *
74
	 * @var    string
75
	 */
76
	public $meta_type = '';
77
78
	/**
79
	 * Preserve args
80
	 *
81
	 * @since  2.4.0
82
	 * @access public
83
	 *
84
	 * @var    array
85
	 */
86
	public $_args = array();
87
88
	/**
89
	 * Default query arguments.
90
	 *
91
	 * Not all of these are valid arguments that can be passed to WP_Query. The ones that are not, are modified before
92
	 * the query is run to convert them to the proper syntax.
93
	 *
94
	 * @since  1.8.14
95
	 * @access public
96
	 *
97
	 * @param  $args array The array of arguments that can be passed in and used for setting up this payment query.
98
	 */
99
	public function __construct( $args = array() ) {
100
		$defaults = array(
101
			'number'          => 20,
102
			'offset'          => 0,
103
			'paged'           => 1,
104
			'orderby'         => 'id',
105
			'order'           => 'DESC',
106
			'user'            => null,
107
			'email'           => null,
108
			'donor'           => null,
109
			'meta_query'      => array(),
0 ignored issues
show
introduced by
Detected usage of meta_query, possible slow query.
Loading history...
110
			'date_query'      => array(),
111
			's'               => null,
112
			'fields'          => 'all', // Supports donors (all fields) or valid column as string or array list.
113
			'count'           => false,
114
			'give_forms'      => array(),
115
			'start_date'      => false,
116
			'end_date'        => false,
117
118
			/**
119
			 * donation_amount will contain value like:
120
			 * array(
121
			 *     'compare' => *compare symbol* (by default set to > )
122
			 *     'amount'  => *numeric_value*
123
			 * )
124
			 *
125
			 * You can also pass number value to this param then compare symbol will auto set to >
126
			 */
127
			'donation_amount' => array(),
128
		);
129
130
		$this->args            = $this->_args = wp_parse_args( $args, $defaults );
131
		$this->table_name      = Give()->donors->table_name;
132
		$this->meta_table_name = Give()->donor_meta->table_name;
133
		$this->meta_type       = Give()->donor_meta->meta_type;
134
	}
135
136
	/**
137
	 * Modify the query/query arguments before we retrieve donors.
138
	 *
139
	 * @since  1.8.14
140
	 * @access public
141
	 *
142
	 * @return void
143
	 */
144
	public function init() {
145
	}
146
147
148
	/**
149
	 * Retrieve donors.
150
	 *
151
	 * The query can be modified in two ways; either the action before the
152
	 * query is run, or the filter on the arguments (existing mainly for backwards
153
	 * compatibility).
154
	 *
155
	 * @since  1.8.14
156
	 * @access public
157
	 *
158
	 * @global wpdb $wpdb
159
	 *
160
	 * @return array
161
	 */
162
	public function get_donors() {
163
		global $wpdb;
164
165
		/**
166
		 * Fires before retrieving donors.
167
		 *
168
		 * @since 1.8.14
169
		 *
170
		 * @param Give_Donors_Query $this Donors query object.
171
		 */
172
		do_action( 'give_pre_get_donors', $this );
173
174
		$cache_key = Give_Cache::get_key( 'give_donor', $this->get_sql(), false );
0 ignored issues
show
Documentation introduced by
$this->get_sql() is of type string, but the function expects a array|null.

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...
175
176
		// Get donors from cache.
177
		$this->donors = Give_Cache::get_db_query( $cache_key );
0 ignored issues
show
Documentation Bug introduced by
It seems like \Give_Cache::get_db_query($cache_key) of type * is incompatible with the declared type array of property $donors.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
178
179
		// Modify the query/query arguments before we retrieve donors.
180
		$this->args = $this->_args;
181
		$this->date_filter_pre();
182
183
		if ( is_null( $this->donors ) ) {
184
			if ( empty( $this->args['count'] ) ) {
185
				$this->donors = $wpdb->get_results( $this->get_sql() );
0 ignored issues
show
introduced by
Usage of a direct database call is discouraged.
Loading history...
introduced by
Usage of a direct database call without caching is prohibited. Use wp_cache_get / wp_cache_set.
Loading history...
186
			} else {
187
				$this->donors = $wpdb->get_var( $this->get_sql() );
0 ignored issues
show
introduced by
Usage of a direct database call is discouraged.
Loading history...
introduced by
Usage of a direct database call without caching is prohibited. Use wp_cache_get / wp_cache_set.
Loading history...
188
			}
189
190
			Give_Cache::set_db_query( $cache_key, $this->donors );
191
		}
192
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
193
194
		/**
195
		 * Fires after retrieving donors.
196
		 *
197
		 * @since 1.8.14
198
		 *
199
		 * @param Give_Donors_Query $this Donors query object.
200
		 */
201
		do_action( 'give_post_get_donors', $this );
202
203
		return $this->donors;
204
	}
205
206
	/**
207
	 * Get sql query from queried array.
208
	 *
209
	 * @since  2.0
210
	 * @access public
211
	 *
212
	 * @global wpdb $wpdb
213
	 * @return string
214
	 */
215
	public function get_sql() {
216
		global $wpdb;
217
218
		if ( $this->args['number'] < 1 ) {
219
			$this->args['number'] = 99999999999;
220
		}
221
222
		$where = $this->get_where_query();
223
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
224
225
		// Set offset.
226
		if ( empty( $this->args['offset'] ) && ( 0 < $this->args['paged'] ) ) {
227
			$this->args['offset'] = $this->args['number'] * ( $this->args['paged'] - 1 );
228
		}
229
230
		// Set fields.
231
		$fields = "{$this->table_name}.*";
232
		if ( ! empty( $this->args['fields'] ) && 'all' !== $this->args['fields'] ) {
233
			if ( is_string( $this->args['fields'] ) ) {
234
				$fields = "{$this->table_name}.{$this->args['fields']}";
235 View Code Duplication
			} elseif ( is_array( $this->args['fields'] ) ) {
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...
236
				$fields = "{$this->table_name}." . implode( " , {$this->table_name}.", $this->args['fields'] );
237
			}
238
		}
239
240
		// Set count.
241
		if ( ! empty( $this->args['count'] ) ) {
242
			$fields = "COUNT({$this->table_name}.id)";
243
		}
244
245
		$orderby = $this->get_order_query();
246
247
		$sql = $wpdb->prepare( "SELECT {$fields} FROM {$this->table_name} LIMIT %d,%d;", absint( $this->args['offset'] ), absint( $this->args['number'] ) );
248
249
		// $where, $orderby and order already prepared query they can generate notice if you re prepare them in above.
250
		// WordPress consider LIKE condition as placeholder if start with s,f, or d.
251
		$sql = str_replace( 'LIMIT', "{$where} {$orderby} LIMIT", $sql );
252
253
		return $sql;
254
	}
255
256
	/**
257
	 * Set query where clause.
258
	 *
259
	 * @since  1.8.14
260
	 * @access private
261
	 *
262
	 * @global wpdb $wpdb
263
	 * @return string
264
	 */
265
	private function get_where_query() {
266
267
		// Get sql query for meta.
268
		if ( ! empty( $this->args['meta_query'] ) ) {
269
			$meta_query_object = new WP_Meta_Query( $this->args['meta_query'] );
270
			$meta_query        = $meta_query_object->get_sql( $this->meta_type, $this->table_name, 'id' );
271
272
			$where[] = implode( '', $meta_query );
273
		}
274
275
		$where[] = 'WHERE 1=1';
276
		$where[] = $this->get_where_search();
277
		$where[] = $this->get_where_email();
278
		$where[] = $this->get_where_donor();
279
		$where[] = $this->get_where_user();
280
		$where[] = $this->get_where_date();
281
		$where[] = $this->get_where_donation_amount();
282
		$where[] = $this->get_where_donation_count();
283
		$where[] = $this->get_where_give_forms();
284
285
		$where = array_filter( $where );
286
287
		return trim( implode( ' ', array_map( 'trim', $where ) ) );
288
289
	}
290
291
	/**
292
	 * Set email where clause.
293
	 *
294
	 * @since  1.8.14
295
	 * @access private
296
	 *
297
	 * @global wpdb $wpdb
298
	 * @return string
299
	 */
300
	private function get_where_email() {
301
		global $wpdb;
302
303
		$where = '';
304
305
		if ( ! empty( $this->args['email'] ) ) {
306
307
			if ( is_array( $this->args['email'] ) ) {
308
309
				$emails_count       = count( $this->args['email'] );
310
				$emails_placeholder = array_fill( 0, $emails_count, '%s' );
311
				$emails             = implode( ', ', $emails_placeholder );
312
313
				$where .= $wpdb->prepare( "AND {$this->table_name}.email IN( $emails )", $this->args['email'] );
314
			} else {
315
				$where .= $wpdb->prepare( "AND {$this->table_name}.email = %s", $this->args['email'] );
316
			}
317
		}
318
319
		return $where;
320
	}
321
322
	/**
323
	 * Set donor where clause.
324
	 *
325
	 * @since  1.8.14
326
	 * @access private
327
	 *
328
	 * @global wpdb $wpdb
329
	 * @return string
330
	 */
331 View Code Duplication
	private function get_where_donor() {
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...
332
		$where = '';
333
334
		// Specific donors.
335
		if ( ! empty( $this->args['donor'] ) ) {
336
			if ( ! is_array( $this->args['donor'] ) ) {
337
				$this->args['donor'] = explode( ',', $this->args['donor'] );
338
			}
339
			$donor_ids = implode( ',', array_map( 'intval', $this->args['donor'] ) );
340
341
			$where .= "AND {$this->table_name}.id IN( {$donor_ids} )";
342
		}
343
344
		return $where;
345
	}
346
347
	/**
348
	 * Set date where clause.
349
	 *
350
	 * @since  1.8.14
351
	 * @access private
352
	 *
353
	 * @global wpdb $wpdb
354
	 * @return string
355
	 */
356
	private function get_where_date() {
357
		$where = '';
358
359
		// Donors created for a specific date or in a date range
360
		if ( ! empty( $this->args['date_query'] ) ) {
361
			$date_query_object = new WP_Date_Query( is_array( $this->args['date_query'] ) ? $this->args['date_query'] : wp_parse_args( $this->args['date_query'] ), "{$this->table_name}.date_created" );
362
363
			$where .= str_replace( array(
364
				"\n",
365
				'(   (',
366
				'))',
367
			), array(
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 16 spaces, but found 12.
Loading history...
368
				'',
369
				'( (',
370
				') )',
371
			), $date_query_object->get_sql() );
372
		}
373
374
		return $where;
375
	}
376
377
	/**
378
	 * Set search where clause.
379
	 *
380
	 * @since  1.8.14
381
	 * @access private
382
	 *
383
	 * @global wpdb $wpdb
384
	 * @return string
385
	 */
386
	private function get_where_search() {
387
		$where = '';
388
389
		// Bailout.
390
		if( empty( $this->args['s'] ) ) {
0 ignored issues
show
introduced by
Space after opening control structure is required
Loading history...
introduced by
No space before opening parenthesis is prohibited
Loading history...
391
			return $where;
392
		}
393
394
		// Donors created for a specific date or in a date range
395
		if ( false !== strpos( $this->args['s'], ':' ) ) {
396
			$search_parts = explode( ':', $this->args['s'] );
397
			if ( ! empty( $search_parts[0] ) ) {
398
				switch ( $search_parts[0] ) {
399
					// Backward compatibility.
400
					case 'name':
401
						$where = "AND {$this->table_name}.name LIKE '%{$search_parts[1]}%'";
402
						break;
403
					case 'note':
404
						$where = "AND {$this->table_name}.notes LIKE '%{$search_parts[1]}%'";
405
						break;
406
				}
407
			}
0 ignored issues
show
introduced by
Blank line found after control structure
Loading history...
408
409
		} else if ( is_numeric( $this->args['s'] ) ) {
410
			$where = "AND {$this->table_name}.id ='{$this->args['s']}'";
411
412
		} else {
413
			$search_field = is_email( $this->args['s'] ) ? 'email' : 'name';
414
			$where        = "AND {$this->table_name}.$search_field LIKE '%{$this->args['s']}%'";
415
		}
416
417
		return $where;
418
	}
419
420
	/**
421
	 * Set user where clause.
422
	 *
423
	 * @since  1.8.14
424
	 * @access private
425
	 *
426
	 * @global wpdb $wpdb
427
	 * @return string
428
	 */
429 View Code Duplication
	private function get_where_user() {
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...
430
		$where = '';
431
432
		// Donors create for specific wp user.
433
		if ( ! empty( $this->args['user'] ) ) {
434
			if ( ! is_array( $this->args['user'] ) ) {
435
				$this->args['user'] = explode( ',', $this->args['user'] );
436
			}
437
			$user_ids = implode( ',', array_map( 'intval', $this->args['user'] ) );
438
439
			$where .= "AND {$this->table_name}.user_id IN( {$user_ids} )";
440
		}
441
442
		return $where;
443
	}
444
445
	/**
446
	 * Set orderby query
447
	 *
448
	 * @since  1.8.14
449
	 * @access private
450
	 *
451
	 * @return string
452
	 */
453
	private function get_order_query() {
454
		$table_columns = Give()->donors->get_columns();
455
456
		$query = array();
457
		$ordersby = $this->args['orderby'];
458
459
		if( ! is_array( $ordersby ) ) {
0 ignored issues
show
introduced by
Space after opening control structure is required
Loading history...
introduced by
No space before opening parenthesis is prohibited
Loading history...
460
			$ordersby = array(
461
				$this->args['orderby'] => $this->args['order']
462
			);
463
		}
464
465
		// Remove non existing column.
466
		// Filter orderby values.
467
		foreach ( $ordersby as $orderby => $order ) {
468
			if( ! array_key_exists( $orderby, $table_columns ) ) {
0 ignored issues
show
introduced by
Space after opening control structure is required
Loading history...
introduced by
No space before opening parenthesis is prohibited
Loading history...
469
				unset( $ordersby[$orderby] );
0 ignored issues
show
introduced by
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
470
			}
471
472
			$ordersby[ esc_sql( $orderby ) ] = esc_sql( $order );
473
		}
474
475
		if( empty( $ordersby ) ) {
0 ignored issues
show
introduced by
Space after opening control structure is required
Loading history...
introduced by
No space before opening parenthesis is prohibited
Loading history...
476
			$ordersby = array(
477
				'id' => $this->args['order']
478
			);
479
		}
480
481
		// Create query.
482
		foreach ( $ordersby as $orderby => $order ) {
483
			switch ( $table_columns[ $orderby ] ) {
484
				case '%d':
485
				case '%f':
486
					$query[] = "{$this->table_name}.{$orderby}+0 {$order}";
487
					break;
488
489
				default:
490
					$query[] = "{$this->table_name}.{$orderby} {$order}";
491
			}
492
		}
493
494
		return ! empty( $query ) ? 'ORDER BY ' . implode( ', ', $query ) : '';
495
	}
496
497
	/**
498
	 * Set donation count value where clause.
499
	 * @todo: add phpunit test
500
	 *
501
	 * @since  2.2.0
502
	 * @access private
503
	 *
504
	 * @global wpdb $wpdb
505
	 * @return string
506
	 */
507 View Code Duplication
	private function get_where_donation_count() {
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...
508
		$where = '';
509
510
		if ( ! empty( $this->args['donation_count'] ) ) {
511
			$compare = '>';
512
			$amount  = $this->args['donation_count'];
513
			if ( is_array( $this->args['donation_count'] ) ) {
514
				$compare = $this->args['donation_count'] ['compare'];
515
				$amount = $this->args['donation_count']['amount'];
516
			}
517
518
			$where .= "AND {$this->table_name}.purchase_count{$compare}{$amount}";
519
		}
520
521
		return $where;
522
	}
523
524
	/**
525
	 * Set purchase value where clause.
526
	 * @todo: add phpunit test
527
	 *
528
	 * @since  2.1.0
529
	 * @access private
530
	 *
531
	 * @global wpdb $wpdb
532
	 * @return string
533
	 */
534 View Code Duplication
	private function get_where_donation_amount() {
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...
535
		$where = '';
536
537
		if ( ! empty( $this->args['donation_amount'] ) ) {
538
			$compare = '>';
539
			$amount  = $this->args['donation_amount'];
540
			if ( is_array( $this->args['donation_amount'] ) ) {
541
				$compare = $this->args['donation_amount'] ['compare'];
542
				$amount = $this->args['donation_amount']['amount'];
543
			}
544
545
			$where .= "AND {$this->table_name}.purchase_value{$compare}{$amount}";
546
		}
547
548
		return $where;
549
	}
550
551
	/**
552
	 * Set give_forms where clause.
553
	 *
554
	 * @todo   : add phpunit test
555
	 *
556
	 * @since  2.1.0
557
	 * @access private
558
	 *
559
	 * @global wpdb $wpdb
560
	 * @return string
561
	 */
562
	private function get_where_give_forms() {
563
		global $wpdb;
564
		$where = '';
565
566
		if ( ! empty( $this->args['give_forms'] ) ) {
567
			if ( ! is_array( $this->args['give_forms'] ) ) {
568
				$this->args['give_forms'] = explode( ',', $this->args['give_forms'] );
569
			}
570
571
			$form_ids        = implode( ',', array_map( 'intval', $this->args['give_forms'] ) );
572
			$donation_id_col = Give()->payment_meta->get_meta_type() . '_id';
573
574
			$query = $wpdb->prepare(
575
				"
576
			SELECT DISTINCT meta_value as donor_id
577
			FROM {$wpdb->donationmeta}
578
			WHERE meta_key=%s
579
			AND {$donation_id_col} IN(
580
				SELECT {$donation_id_col}
581
				FROM {$wpdb->paymentmeta}
582
				WHERE meta_key=%s
583
				AND meta_value IN (%s)
584
			)
585
			",
586
				'_give_payment_donor_id',
587
				'_give_payment_form_id',
588
				$form_ids
589
			);
590
591
			$donor_ids = $wpdb->get_results( $query, ARRAY_A );
0 ignored issues
show
introduced by
Usage of a direct database call is discouraged.
Loading history...
introduced by
Usage of a direct database call without caching is prohibited. Use wp_cache_get / wp_cache_set.
Loading history...
592
593
			if ( ! empty( $donor_ids ) ) {
594
				$donor_ids = wp_list_pluck( $donor_ids, 'donor_id' );
595
				$donor_ids = implode( ',', array_map( 'intval', $donor_ids ) );
596
				$where     .= "AND {$this->table_name}.id IN ({$donor_ids})";
597
			} else {
598
				$where .= "AND {$this->table_name}.id IN ('0')";
599
			}
600
		}
601
602
		return $where;
603
	}
604
605
	/**
606
	 * If querying a specific date, add the proper filters.
607
	 * Note: This function currently only accept dates with admin defined core date format
608
	 *
609
	 * @since  2.4.0
610
	 * @access public
611
	 *
612
	 * @return void
613
	 */
614
	public function date_filter_pre() {
615
		if ( ! ( $this->args['start_date'] || $this->args['end_date'] ) ) {
616
			return;
617
		}
618
619
		$date_query = array();
620
621 View Code Duplication
		if ( ! empty ( $this->args['start_date'] ) ) {
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...
Coding Style introduced by
Space before opening parenthesis of function call prohibited
Loading history...
622
			$date_query['after'] = give_get_formatted_date( $this->args['start_date'] );
623
		}
624
625 View Code Duplication
		if ( ! empty ( $this->args['end_date'] ) ) {
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...
Coding Style introduced by
Space before opening parenthesis of function call prohibited
Loading history...
626
			$date_query['before'] = give_get_formatted_date( $this->args['end_date'] ) . ' 23:59:59';
627
		}
628
629
		// Include Start Date and End Date while querying.
630
		$date_query['inclusive'] = true;
631
632
		$this->__set( 'date_query', $date_query );
633
	}
634
635
	/**
636
	 * Set a query variable.
637
	 *
638
	 * @since  2.4.0
639
	 * @access public
640
	 *
641
	 * @param $query_var
642
	 * @param $value
643
	 */
644 View Code Duplication
	public function __set( $query_var, $value ) {
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...
645
		if ( in_array( $query_var, array( 'meta_query', 'tax_query' ) ) ) {
646
			$this->args[ $query_var ][] = $value;
647
		} else {
648
			$this->args[ $query_var ] = $value;
649
		}
650
	}
651
652
}
653