Test Failed
Push — master ( 0a75e1...2c5ac2 )
by Ravinder
08:47
created

Give_Donor_List_Table   C

Complexity

Total Complexity 55

Size/Duplication

Total Lines 578
Duplicated Lines 14.19 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 82
loc 578
rs 6
c 0
b 0
f 0
wmc 55
lcom 1
cbo 4

18 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 9 9 1
D advanced_filters() 5 78 14
A column_default() 10 28 5
A column_cb() 0 7 1
A column_name() 0 23 4
A get_columns() 0 13 1
A get_sortable_columns() 11 11 1
A get_row_actions() 0 11 1
A get_paged() 0 3 2
A get_search() 0 3 2
A get_bulk_actions() 0 7 1
A display_tablenav() 18 18 3
A donor_data() 0 32 4
A get_donor_count() 10 10 1
B get_donor_query() 0 35 8
A single_row() 0 5 1
B display() 0 80 4
A prepare_items() 18 18 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like Give_Donor_List_Table often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Give_Donor_List_Table, and based on these observations, apply Extract Interface, too.

1
<?php
2
/**
3
 * Donor List Table Class.
4
 *
5
 * The list view under WP-Admin > Donations > Donors.
6
 *
7
 * @package     Give
8
 * @subpackage  Admin/Reports
9
 * @copyright   Copyright (c) 2016, GiveWP
10
 * @license     https://opensource.org/licenses/gpl-license GNU Public License
11
 * @since       1.0
12
 */
13
14
// Exit if accessed directly.
15
if ( ! defined( 'ABSPATH' ) ) {
16
	exit;
17
}
18
19
// Load WP_List_Table if not loaded.
20
if ( ! class_exists( 'WP_List_Table' ) ) {
21
	require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
22
}
23
24
/**
25
 * Give_Donor_List_Table Class.
26
 *
27
 * @since 1.0
28
 */
29
class Give_Donor_List_Table extends WP_List_Table {
30
31
	/**
32
	 * Number of items per page.
33
	 *
34
	 * @var int
35
	 * @since 1.0
36
	 */
37
	public $per_page = 30;
38
39
	/**
40
	 * Number of donors found.
41
	 *
42
	 * @var int
43
	 * @since 1.0
44
	 */
45
	public $count = 0;
46
47
	/**
48
	 * Total donors.
49
	 *
50
	 * @var int
51
	 * @since 1.0
52
	 */
53
	public $total = 0;
54
55
	/**
56
	 * Get things started.
57
	 *
58
	 * @since 1.0
59
	 * @see   WP_List_Table::__construct()
60
	 */
61 View Code Duplication
	public function __construct() {
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
		// Set parent defaults.
63
		parent::__construct( array(
64
			'singular' => __( 'Donor', 'give' ), // Singular name of the listed records.
65
			'plural'   => __( 'Donors', 'give' ), // Plural name of the listed records.
66
			'ajax'     => false, // Does this table support ajax?.
67
		) );
68
69
	}
70
	/**
71
	 * Add donors search filter.
72
	 *
73
	 * @since 2.4.0
74
	 * @return void
75
	 */
76
	public function advanced_filters() {
77
		$start_date  = isset( $_GET['start-date'] ) ? give_clean( $_GET['start-date'] ) : null;
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_GET
Loading history...
78
		$end_date    = isset( $_GET['end-date'] ) ? give_clean( $_GET['end-date'] ) : null;
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_GET
Loading history...
79
		$status      = isset( $_GET['status'] ) ? give_clean( $_GET['status'] ) : '';
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_GET
Loading history...
80
		$donor       = isset( $_GET['donor'] ) ? absint( $_GET['donor'] ) : '';
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
81
		$search      = $this->get_search();
82
		$form_id     = ! empty( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : 0;
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
83
		?>
84
		<div id="give-donor-filters" class="give-filters">
85
			<div class="give-donor-search-box">
86
				<input type="text" id="give-donors-search-input" placeholder="<?php _e( 'Name, Email, or Donor ID', 'give' ); ?>" name="s" value="<?php echo $search; ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$search'
Loading history...
87
				<?php submit_button( __( 'Search', 'give' ), 'button', false, false, array(
88
					'ID' => 'donor-search-submit',
89
				) ); ?>
90
			</div>
91
			<div id="give-donor-date-filters">
92
				<div class="give-filter give-filter-half">
93
					<label for="start-date"
94
					       class="give-start-date-label"><?php _e( 'Start Date', 'give' ); ?></label>
95
					<input type="text" id="start-date" name="start-date" class="give_datepicker" autocomplete="off"
96
					       value="<?php printf( esc_attr( $start_date ) ); ?>" placeholder="<?php _e( 'Start Date', 'give' ); ?>" />
97
				</div>
98
				<div class="give-filter give-filter-half">
99
					<label for="end-date" class="give-end-date-label"><?php _e( 'End Date', 'give' ); ?></label>
100
					<input type="text" id="end-date" name="end-date" class="give_datepicker" autocomplete="off"
101
					       value="<?php printf( esc_attr( $end_date ) ); ?>" placeholder="<?php _e( 'End Date', 'give' ); ?>" />
102
				</div>
103
			</div>
104
			<div id="give-payment-form-filter" class="give-filter">
105
				<label for="give-donation-forms-filter"
106
				       class="give-donation-forms-filter-label"><?php _e( 'Form', 'give' ); ?></label>
107
				<?php
108
				// Filter Donations by Donation Forms.
109
				echo Give()->html->forms_dropdown(
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
110
					array(
111
						'name'     => 'form_id',
112
						'id'       => 'give-donation-forms-filter',
113
						'class'    => 'give-donation-forms-filter',
114
						'selected' => $form_id, // Make sure to have $form_id set to 0, if there is no selection.
115
						'chosen'   => true,
116
						'number'   => 30,
117
					)
118
				);
119
				?>
120
			</div>
121
122
			<?php
123
			/**
124
			 * Action to add hidden fields and HTML in donor search.
125
			 *
126
			 * @since 2.4.0
127
			 */
128
			do_action( 'give_donor_table_advanced_filters' );
129
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
130
131
			if ( ! empty( $status ) ) {
132
				echo sprintf( '<input type="hidden" name="status" value="%s"/>', esc_attr( $status ) );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'sprintf'
Loading history...
133
			}
134
135
			if ( ! empty( $donor ) ) {
136
				echo sprintf( '<input type="hidden" name="donor" value="%s"/>', absint( $donor ) );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'sprintf'
Loading history...
137
			}
138
			?>
139
140
			<div class="give-filter">
141
				<?php submit_button( __( 'Apply', 'give' ), 'secondary', '', false ); ?>
142
				<?php
143
				// Clear active filters button.
144 View Code Duplication
				if ( ! empty( $start_date ) || ! empty( $end_date ) || ! empty( $donor ) || ! empty( $search ) || ! empty( $status ) || ! empty( $form_id ) ) :
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...
145
					?>
146
					<a href="<?php echo admin_url( 'edit.php?post_type=give_forms&page=give-donors' ); ?>"
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'admin_url'
Loading history...
147
					   class="button give-clear-filters-button"><?php _e( 'Clear Filters', 'give' ); ?></a>
148
				<?php endif; ?>
149
			</div>
150
		</div>
151
152
		<?php
153
	}
154
155
	/**
156
	 * This function renders most of the columns in the list table.
157
	 *
158
	 * @param array  $donor       Contains all the data of the donors.
159
	 * @param string $column_name The name of the column.
160
	 *
161
	 * @access public
162
	 * @since  1.0
163
	 *
164
	 * @return string Column Name.
165
	 */
166
	public function column_default( $donor, $column_name ) {
167
168
		switch ( $column_name ) {
169
170 View Code Duplication
			case 'num_donations' :
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...
171
				$value = sprintf(
172
					'<a href="%s">%s</a>',
173
					admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&donor=' . absint( $donor['id'] ) ),
174
					esc_html( $donor['num_donations'] )
175
				);
176
				break;
177
178 View Code Duplication
			case 'amount_spent' :
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...
179
				$value = give_currency_filter( give_format_amount( $donor[ $column_name ], array( 'sanitize' => false ) ) );
180
				break;
181
182
			case 'date_created' :
183
				$value = date_i18n( give_date_format(), strtotime( $donor['date_created'] ) );
184
				break;
185
186
			default:
187
				$value = isset( $donor[ $column_name ] ) ? $donor[ $column_name ] : null;
188
				break;
189
		}
190
191
		return apply_filters( "give_donors_column_{$column_name}", $value, $donor['id'] );
192
193
	}
194
195
	/**
196
	 * For CheckBox Column
197
	 *
198
	 * @param array $donor Donor Data.
199
	 *
200
	 * @access public
201
	 * @since  1.8.16
202
	 *
203
	 * @return string
204
	 */
205
	public function column_cb( $donor ) {
206
		return sprintf(
207
			'<input class="donor-selector" type="checkbox" name="donor[]" value="%1$d" data-name="%2$s" />',
208
			$donor['id'],
209
			$donor['name']
210
		);
211
	}
212
213
	/**
214
	 * Column name.
215
	 *
216
	 * @param array $donor Donor Data.
217
	 *
218
	 * @access public
219
	 * @since  1.0
220
	 *
221
	 * @return string
222
	 */
223
	public function column_name( $donor ) {
224
225
		// Get donor's initials for non-gravatars
226
		$title_prefix                 = Give()->donor_meta->get_meta( $donor['id'], '_give_donor_title_prefix', true );
227
		$donor_name_without_prefix    = trim( str_replace( $title_prefix, '', $donor['name'] ) );
228
		$donor_name_array             = explode( " ", $donor_name_without_prefix );
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 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...
229
		$donor_name_args['firstname'] = ! empty( $donor_name_array[0] ) ? $donor_name_array[0] : '';
230
		$donor_name_args['lastname']  = ! empty( $donor_name_array[1] ) ? $donor_name_array[1] : '';
231
		$donor_name_initial           = give_get_name_initial( $donor_name_args );
232
233
		$donation_gravatar_image = sprintf(
234
			'<span class="give-donor__image give-donor-admin-avatar" data-donor_email="%1$s" data-has-valid-gravatar="%2$s">%3$s</span>',
235
			md5( strtolower( trim( $donor['email'] ) ) ),
236
			absint( give_validate_gravatar( $donor['email'] ) ),
237
			$donor_name_initial
238
		);
239
240
		$name     = ! empty( $donor['name'] ) ? ( $donation_gravatar_image . '<span class="give-donor-name-text">' . $donor['name'] . '</span>' ) : '<em>' . __( 'Unnamed Donor', 'give' ) . '</em>';
241
		$view_url = admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor['id'] );
242
		$actions  = $this->get_row_actions( $donor );
243
244
		return '<a href="' . esc_url( $view_url ) . '" class="give-donor-name">' . $name . '</a>' . $this->row_actions( $actions );
245
	}
246
247
	/**
248
	 * Retrieve the table columns.
249
	 *
250
	 * @access public
251
	 * @since  1.0
252
	 *
253
	 * @return array $columns Array of all the list table columns.
254
	 */
255
	public function get_columns() {
256
		$columns = array(
257
			'cb'            => '<input type="checkbox" />', // Render a checkbox instead of text.
258
			'name'          => __( 'Name', 'give' ),
259
			'email'         => __( 'Email', 'give' ),
260
			'num_donations' => __( 'Donations', 'give' ),
261
			'amount_spent'  => __( 'Total Donated', 'give' ),
262
			'date_created'  => __( 'Date Created', 'give' ),
263
		);
264
265
		return apply_filters( 'give_list_donors_columns', $columns );
266
267
	}
268
269
	/**
270
	 * Get the sortable columns.
271
	 *
272
	 * @access public
273
	 * @since  2.1
274
	 * @return array Array of all the sortable columns.
275
	 */
276 View Code Duplication
	public function get_sortable_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...
277
278
		$columns = array(
279
			'date_created'  => array( 'date_created', true ),
280
			'name'          => array( 'name', true ),
281
			'num_donations' => array( 'purchase_count', false ),
282
			'amount_spent'  => array( 'purchase_value', false ),
283
		);
284
285
		return apply_filters( 'give_list_donors_sortable_columns', $columns );
286
	}
287
288
	/**
289
	 * Retrieve row actions.
290
	 *
291
	 * @param array $donor Donor Data.
292
	 *
293
	 * @since  1.7
294
	 * @access public
295
	 *
296
	 * @return array An array of action links.
297
	 */
298
	public function get_row_actions( $donor ) {
299
300
		$actions = array(
301
			'id'     => '<span class="give-donor-id">ID: ' . $donor['id'] . '  </span>',
302
			'view'   => sprintf( '<a href="%1$s" aria-label="%2$s">%3$s</a>', admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor['id'] ), sprintf( esc_attr__( 'View "%s"', 'give' ), $donor['name'] ), __( 'View Donor', 'give' ) ),
303
			'delete' => sprintf( '<a class="%1$s" data-id="%2$s" href="#" aria-label="%3$s">%4$s</a>', 'give-single-donor-delete', $donor['id'], sprintf( esc_attr__( 'Delete "%s"', 'give' ), $donor['name'] ), __( 'Delete', 'give' ) ),
304
		);
305
306
		return apply_filters( 'give_donor_row_actions', $actions, $donor );
307
308
	}
309
310
	/**
311
	 * Retrieve the current page number.
312
	 *
313
	 * @access public
314
	 * @since  1.0
315
	 *
316
	 * @return int Current page number.
317
	 */
318
	public function get_paged() {
319
		return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
320
	}
321
322
	/**
323
	 * Retrieves the search query string.
324
	 *
325
	 * @access public
326
	 * @since  1.0
327
	 *
328
	 * @return mixed string If search is present, false otherwise.
329
	 */
330
	public function get_search() {
331
		return ! empty( $_GET['s'] ) ? urldecode( trim( $_GET['s'] ) ) : false;
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_GET
Loading history...
332
	}
333
334
	/**
335
	 * Get the Bulk Actions.
336
	 *
337
	 * @access public
338
	 * @since  1.8.16
339
	 *
340
	 * @return array
341
	 */
342
	public function get_bulk_actions() {
343
		$actions = array(
344
			'delete' => __( 'Delete', 'give' ),
345
		);
346
347
		return $actions;
348
	}
349
350
	/**
351
	 * Generate the table navigation above or below the table
352
	 *
353
	 * @param string $which Position to trigger i.e. Top/Bottom.
354
	 *
355
	 * @access protected
356
	 * @since  1.8.16
357
	 */
358 View Code Duplication
	protected function display_tablenav( $which ) {
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...
359
		if ( 'top' === $which ) {
360
			wp_nonce_field( 'bulk-donors','_wpnonce', false );
361
		}
362
		?>
363
		<div class="tablenav <?php echo esc_attr( $which ); ?>">
364
			<?php if ( $this->has_items() ) : ?>
365
				<div class="alignleft actions bulkactions">
366
					<?php $this->bulk_actions( $which ); ?>
367
				</div>
368
			<?php endif;
369
			$this->extra_tablenav( $which );
370
			$this->pagination( $which );
371
			?>
372
			<br class="clear"/>
373
		</div>
374
		<?php
375
	}
376
377
	/**
378
	 * Retrieves the donor data from db.
379
	 *
380
	 * @access public
381
	 * @since  1.0
382
	 *
383
	 * @return array $data The Donor data.
384
	 */
385
	public function donor_data() {
386
387
		$data = array();
388
389
		// Get donor query.
390
		$args   = $this->get_donor_query();
391
		$donors = Give()->donors->get_donors( $args );
392
393
		if ( $donors ) {
394
395
			foreach ( $donors as $donor ) {
396
397
				$user_id      = ! empty( $donor->user_id ) ? intval( $donor->user_id ) : 0;
398
				$title_prefix = Give()->donor_meta->get_meta( $donor->id, '_give_donor_title_prefix', true );
399
400
				// If title prefix is set, then update the donor name.
401
				$donor->name = give_get_donor_name_with_title_prefixes( $title_prefix, $donor->name );
402
403
				$data[] = array(
404
					'id'            => $donor->id,
405
					'user_id'       => $user_id,
406
					'name'          => $donor->name,
407
					'email'         => $donor->email,
408
					'num_donations' => $donor->purchase_count,
409
					'amount_spent'  => $donor->purchase_value,
410
					'date_created'  => $donor->date_created,
411
				);
412
			}
413
		}
414
415
		return apply_filters( 'give_donors_column_query_data', $data );
416
	}
417
418
	/**
419
	 * Get donor count.
420
	 *
421
	 * @since  1.8.1
422
	 * @access private
423
	 */
424 View Code Duplication
	private function get_donor_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...
425
		// Get donor query.
426
		$_donor_query = $this->get_donor_query();
427
428
		$_donor_query['number'] = - 1;
429
		$_donor_query['offset'] = 0;
430
		$donors                 = Give()->donors->get_donors( $_donor_query );
431
432
		return count( $donors );
433
	}
434
435
	/**
436
	 * Get donor query.
437
	 *
438
	 * @since  1.8.1
439
	 * @access public
440
	 *
441
	 * @return array
442
	 */
443
	public function get_donor_query() {
444
		$per_page   = $this->per_page;
445
		$paged      = $this->get_paged();
446
		$donor      = isset( $_GET['donor'] ) ? $_GET['donor'] : null;
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_GET
Loading history...
447
		$start_date = ! empty ( $_GET['start-date'] ) ? sanitize_text_field( $_GET['start-date'] ) : false;
0 ignored issues
show
Coding Style introduced by
Space before opening parenthesis of function call prohibited
Loading history...
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_GET
Loading history...
448
		$end_date   = ! empty( $_GET['end-date'] ) ? sanitize_text_field( $_GET['end-date'] ) : false;
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
449
		$form_id    = ! empty( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : null;
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
450
		$offset     = $this->per_page * ( $paged - 1 );
451
		$search     = $this->get_search();
452
		$order      = isset( $_GET['order'] ) ? sanitize_text_field( $_GET['order'] ) : 'DESC';
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
453
		$orderby    = isset( $_GET['orderby'] ) ? sanitize_text_field( $_GET['orderby'] ) : 'id';
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
454
455
		$args = array(
456
			'output'     => 'payments',
457
			'number'     => $per_page,
458
			'offset'     => $offset,
459
			'page'       => isset( $_GET['paged'] ) ? $_GET['paged'] : null,
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_GET
Loading history...
460
			'orderby'    => $orderby,
461
			'order'      => $order,
462
			'donor'      => $donor,
463
			's'          => $search,
464
			'start_date' => $start_date,
465
			'end_date'   => $end_date,
466
			'give_forms' => $form_id,
467
		);
468
469
		/**
470
		 * Filter to modify donor table argument.
471
		 *
472
		 * @since 2.4.0
473
		 */
474
		$args = (array) apply_filters( 'give_donor_table_query', $args );
475
476
		return $args;
477
	}
478
479
	/**
480
	 * Generates content for a single row of the table
481
	 *
482
	 * @param object $item The current item.
483
	 *
484
	 * @since  1.8.17
485
	 * @access public
486
	 */
487
	public function single_row( $item ) {
488
		echo sprintf( '<tr id="donor-%1$d" data-id="%2$d" data-name="%3$s">', $item['id'], $item['id'], $item['name'] );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'sprintf'
Loading history...
489
		$this->single_row_columns( $item );
490
		echo '</tr>';
491
	}
492
493
	/**
494
	 * Display the final donor table
495
	 *
496
	 * @since  1.8.17
497
	 * @access public
498
	 */
499
	public function display() {
500
		$singular = $this->_args['singular'];
501
502
		$this->display_tablenav( 'top' );
503
504
		$this->screen->render_screen_reader_content( 'heading_list' );
505
506
		$get_data = give_clean( $_GET ); // WPCS: input var ok, sanitization ok, CSRF ok.
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
507
508
		$order          = ! empty( $get_data['order'] ) ? $get_data['order'] : 'DESC';
509
		$order_by       = ! empty( $get_data['orderby'] ) ? $get_data['orderby'] : 'id';
510
		?>
511
		<table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'implode'
Loading history...
512
			<thead>
513
			<tr>
514
				<?php $this->print_column_headers(); ?>
515
			</tr>
516
			</thead>
517
518
			<tbody id="the-list"<?php
519
			if ( $singular ) {
520
				echo " data-wp-lists='list:$singular'";
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '" data-wp-lists='list:$singular'"'
Loading history...
521
			} ?>>
522
			<tr class="hidden"></tr>
523
			<tr id="give-bulk-delete"
524
			    class="inline-edit-row inline-edit-row-page inline-edit-page bulk-edit-row bulk-edit-row-page bulk-edit-page inline-editor"
525
			    style="display: none;">
526
				<td colspan="6" class="colspanchange">
527
528
					<fieldset class="inline-edit-col-left">
529
						<legend class="inline-edit-legend"><?php esc_attr_e( 'BULK DELETE', 'give' ); ?></legend>
530
						<div class="inline-edit-col">
531
							<div id="bulk-titles">
532
								<div id="give-bulk-donors" class="give-bulk-donors">
533
534
								</div>
535
							</div>
536
					</fieldset>
537
538
					<fieldset class="inline-edit-col-right">
539
						<div class="inline-edit-col">
540
							<label>
541
								<input class="give-donor-delete-confirm" type="checkbox"
542
								       name="give-donor-delete-confirm"/>
543
								<?php esc_attr_e( 'Are you sure you want to delete the selected donor(s)?', 'give' ); ?>
544
							</label>
545
							<label>
546
								<input class="give-donor-delete-records" type="checkbox"
547
								       name="give-donor-delete-records"/>
548
								<?php esc_attr_e( 'Delete all associated donations and records?', 'give' ); ?>
549
							</label>
550
						</div>
551
					</fieldset>
552
553
					<p class="submit inline-edit-save">
554
						<input type="hidden" name="give_action" value="delete_bulk_donor"/>
555
						<input type="hidden" name="orderby" value="<?php echo esc_html( $order_by ); ?>"/>
556
						<input type="hidden" name="order" value="<?php echo esc_html( $order ); ?>"/>
557
						<button type="button" id="give-bulk-delete-cancel"
558
						        class="button cancel alignleft"><?php esc_attr_e( 'Cancel', 'give' ); ?></button>
559
						<input type="submit" id="give-bulk-delete-button" disabled
560
						       class="button button-primary alignright"
561
						       value="<?php esc_attr_e( 'Delete', 'give' ); ?>">
562
						<br class="clear">
563
					</p>
564
				</td>
565
			</tr>
566
			<?php $this->display_rows_or_placeholder(); ?>
567
			</tbody>
568
569
			<tfoot>
570
			<tr>
571
				<?php $this->print_column_headers( false ); ?>
572
			</tr>
573
			</tfoot>
574
575
		</table>
576
		<?php
577
		$this->display_tablenav( 'bottom' );
578
	}
579
580
	/**
581
	 * Setup the final data for the table.
582
	 *
583
	 * @access public
584
	 * @since  1.0
585
	 *
586
	 * @return void
587
	 */
588 View Code Duplication
	public function prepare_items() {
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...
589
590
		$columns  = $this->get_columns();
591
		$hidden   = array(); // No hidden columns.
592
		$sortable = $this->get_sortable_columns();
593
594
		$this->_column_headers = array( $columns, $hidden, $sortable );
595
596
		$this->items = $this->donor_data();
597
598
		$this->total = $this->get_donor_count();
599
600
		$this->set_pagination_args( array(
601
			'total_items' => $this->total,
602
			'per_page'    => $this->per_page,
603
			'total_pages' => ceil( $this->total / $this->per_page ),
604
		) );
605
	}
606
}
607