PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.3.2
GiveWP – Donation Plugin and Fundraising Platform v2.3.2
4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / admin / donors / class-donor-table.php
give / includes / admin / donors Last commit date
class-donor-table.php 7 years ago donor-actions.php 7 years ago donor-functions.php 7 years ago donors.php 7 years ago
class-donor-table.php
525 lines
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 public function __construct() {
62
63 // Set parent defaults.
64 parent::__construct( array(
65 'singular' => __( 'Donor', 'give' ), // Singular name of the listed records.
66 'plural' => __( 'Donors', 'give' ), // Plural name of the listed records.
67 'ajax' => false, // Does this table support ajax?.
68 ) );
69
70 }
71
72 /**
73 * Show the search field.
74 *
75 * @param string $text Label for the search box.
76 * @param string $input_id ID of the search box.
77 *
78 * @since 1.0
79 * @access public
80 *
81 * @return void
82 */
83 public function search_box( $text, $input_id ) {
84 $input_id = $input_id . '-search-input';
85
86 if ( ! empty( $_REQUEST['orderby'] ) ) {
87 echo sprintf( '<input type="hidden" name="orderby" value="%1$s" />', esc_attr( $_REQUEST['orderby'] ) );
88 }
89
90 if ( ! empty( $_REQUEST['order'] ) ) {
91 echo sprintf( '<input type="hidden" name="order" value="%1$s" />', esc_attr( $_REQUEST['order'] ) );
92 }
93 ?>
94 <p class="search-box" role="search">
95 <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label>
96 <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>"/>
97 <?php submit_button( $text, 'button', false, false, array(
98 'ID' => 'search-submit',
99 ) ); ?>
100 </p>
101 <?php
102 }
103
104 /**
105 * This function renders most of the columns in the list table.
106 *
107 * @param array $donor Contains all the data of the donors.
108 * @param string $column_name The name of the column.
109 *
110 * @access public
111 * @since 1.0
112 *
113 * @return string Column Name.
114 */
115 public function column_default( $donor, $column_name ) {
116
117 switch ( $column_name ) {
118
119 case 'num_donations' :
120 $value = sprintf(
121 '<a href="%s">%s</a>',
122 admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&donor=' . absint( $donor['id'] ) ),
123 esc_html( $donor['num_donations'] )
124 );
125 break;
126
127 case 'amount_spent' :
128 $value = give_currency_filter( give_format_amount( $donor[ $column_name ], array( 'sanitize' => false ) ) );
129 break;
130
131 case 'date_created' :
132 $value = date_i18n( give_date_format(), strtotime( $donor['date_created'] ) );
133 break;
134
135 default:
136 $value = isset( $donor[ $column_name ] ) ? $donor[ $column_name ] : null;
137 break;
138 }
139
140 return apply_filters( "give_donors_column_{$column_name}", $value, $donor['id'] );
141
142 }
143
144 /**
145 * For CheckBox Column
146 *
147 * @param array $donor Donor Data.
148 *
149 * @access public
150 * @since 1.8.16
151 *
152 * @return string
153 */
154 public function column_cb( $donor ) {
155 return sprintf(
156 '<input class="donor-selector" type="checkbox" name="donor[]" value="%1$d" data-name="%2$s" />',
157 $donor['id'],
158 esc_attr( $donor['name'] )
159 );
160 }
161
162 /**
163 * Column name.
164 *
165 * @param array $donor Donor Data.
166 *
167 * @access public
168 * @since 1.0
169 *
170 * @return string
171 */
172 public function column_name( $donor ) {
173 $name = ! empty( $donor['name'] ) ? $donor['name'] : '<em>' . __( 'Unnamed Donor', 'give' ) . '</em>';
174 $view_url = admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor['id'] );
175 $actions = $this->get_row_actions( $donor );
176
177 return '<a href="' . esc_url( $view_url ) . '">' . esc_attr( $name ) . '</a>' . $this->row_actions( $actions );
178 }
179
180 /**
181 * Retrieve the table columns.
182 *
183 * @access public
184 * @since 1.0
185 *
186 * @return array $columns Array of all the list table columns.
187 */
188 public function get_columns() {
189 $columns = array(
190 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text.
191 'name' => __( 'Name', 'give' ),
192 'email' => __( 'Email', 'give' ),
193 'num_donations' => __( 'Donations', 'give' ),
194 'amount_spent' => __( 'Total Donated', 'give' ),
195 'date_created' => __( 'Date Created', 'give' ),
196 );
197
198 return apply_filters( 'give_list_donors_columns', $columns );
199
200 }
201
202 /**
203 * Get the sortable columns.
204 *
205 * @access public
206 * @since 2.1
207 * @return array Array of all the sortable columns.
208 */
209 public function get_sortable_columns() {
210
211 $columns = array(
212 'date_created' => array( 'date_created', true ),
213 'name' => array( 'name', true ),
214 'num_donations' => array( 'purchase_count', false ),
215 'amount_spent' => array( 'purchase_value', false ),
216 );
217
218 return apply_filters( 'give_list_donors_sortable_columns', $columns );
219 }
220
221 /**
222 * Retrieve row actions.
223 *
224 * @param array $donor Donor Data.
225 *
226 * @since 1.7
227 * @access public
228 *
229 * @return array An array of action links.
230 */
231 public function get_row_actions( $donor ) {
232
233 $actions = array(
234 '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' ), esc_attr( $donor['name'] ) ), __( 'View Donor', 'give' ) ),
235 'notes' => sprintf( '<a href="%1$s" aria-label="%2$s">%3$s</a>', admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=notes&id=' . $donor['id'] ), sprintf( esc_attr__( 'Notes for "%s"', 'give' ), esc_attr( $donor['name'] ) ), __( 'Notes', 'give' ) ),
236 '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' ), esc_attr( $donor['name'] ) ), __( 'Delete', 'give' ) ),
237 );
238
239 return apply_filters( 'give_donor_row_actions', $actions, $donor );
240
241 }
242
243 /**
244 * Retrieve the current page number.
245 *
246 * @access public
247 * @since 1.0
248 *
249 * @return int Current page number.
250 */
251 public function get_paged() {
252 return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
253 }
254
255 /**
256 * Retrieves the search query string.
257 *
258 * @access public
259 * @since 1.0
260 *
261 * @return mixed string If search is present, false otherwise.
262 */
263 public function get_search() {
264 return ! empty( $_GET['s'] ) ? urldecode( trim( $_GET['s'] ) ) : false;
265 }
266
267 /**
268 * Get the Bulk Actions.
269 *
270 * @access public
271 * @since 1.8.16
272 *
273 * @return array
274 */
275 public function get_bulk_actions() {
276 $actions = array(
277 'delete' => __( 'Delete', 'give' ),
278 );
279 return $actions;
280 }
281
282 /**
283 * Generate the table navigation above or below the table
284 *
285 * @param string $which Position to trigger i.e. Top/Bottom.
286 *
287 * @access protected
288 * @since 1.8.16
289 */
290 protected function display_tablenav( $which ) {
291 if ( 'top' === $which ) {
292 wp_nonce_field( 'bulk-donors','_wpnonce', false );
293 }
294 ?>
295 <div class="tablenav <?php echo esc_attr( $which ); ?>">
296 <?php if ( $this->has_items() ) : ?>
297 <div class="alignleft actions bulkactions">
298 <?php $this->bulk_actions( $which ); ?>
299 </div>
300 <?php endif;
301 $this->extra_tablenav( $which );
302 $this->pagination( $which );
303 ?>
304 <br class="clear" />
305 </div>
306 <?php
307 }
308
309 /**
310 * Retrieves the donor data from db.
311 *
312 * @access public
313 * @since 1.0
314 *
315 * @return array $data The Donor data.
316 */
317 public function donor_data() {
318
319 $data = array();
320
321 // Get donor query.
322 $args = $this->get_donor_query();
323 $donors = Give()->donors->get_donors( $args );
324
325 if ( $donors ) {
326
327 foreach ( $donors as $donor ) {
328
329 $user_id = ! empty( $donor->user_id ) ? intval( $donor->user_id ) : 0;
330 $title_prefix = Give()->donor_meta->get_meta( $donor->id, '_give_donor_title_prefix', true );
331
332 // If title prefix is set, then update the donor name.
333 $donor->name = give_get_donor_name_with_title_prefixes( $title_prefix, $donor->name );
334
335 $data[] = array(
336 'id' => $donor->id,
337 'user_id' => $user_id,
338 'name' => $donor->name,
339 'email' => $donor->email,
340 'num_donations' => $donor->purchase_count,
341 'amount_spent' => $donor->purchase_value,
342 'date_created' => $donor->date_created,
343 );
344 }
345 }
346
347 return apply_filters( 'give_donors_column_query_data', $data );
348 }
349
350 /**
351 * Get donor count.
352 *
353 * @since 1.8.1
354 * @access private
355 */
356 private function get_donor_count() {
357 // Get donor query.
358 $_donor_query = $this->get_donor_query();
359
360 $_donor_query['number'] = - 1;
361 $_donor_query['offset'] = 0;
362 $donors = Give()->donors->get_donors( $_donor_query );
363
364 return count( $donors );
365 }
366
367 /**
368 * Get donor query.
369 *
370 * @since 1.8.1
371 * @access public
372 *
373 * @return array
374 */
375 public function get_donor_query() {
376 $paged = $this->get_paged();
377 $offset = $this->per_page * ( $paged - 1 );
378 $search = $this->get_search();
379 $order = isset( $_GET['order'] ) ? sanitize_text_field( $_GET['order'] ) : 'DESC';
380 $orderby = isset( $_GET['orderby'] ) ? sanitize_text_field( $_GET['orderby'] ) : 'id';
381
382 $args = array(
383 'number' => $this->per_page,
384 'offset' => $offset,
385 'order' => $order,
386 'orderby' => $orderby,
387 );
388
389 if ( $search ) {
390 if ( is_email( $search ) ) {
391 $args['email'] = $search;
392 } elseif ( is_numeric( $search ) ) {
393 $args['id'] = $search;
394 } else {
395 $args['name'] = $search;
396 }
397 }
398
399 return $args;
400 }
401
402 /**
403 * Generates content for a single row of the table
404 *
405 * @param object $item The current item.
406 *
407 * @since 1.8.17
408 * @access public
409 */
410 public function single_row( $item ) {
411 echo sprintf( '<tr id="donor-%1$d" data-id="%2$d" data-name="%3$s">', $item['id'], $item['id'], esc_attr( $item['name'] ) );
412 $this->single_row_columns( $item );
413 echo '</tr>';
414 }
415
416 /**
417 * Display the final donor table
418 *
419 * @since 1.8.17
420 * @access public
421 */
422 public function display() {
423 $singular = $this->_args['singular'];
424
425 $this->display_tablenav( 'top' );
426
427 $this->screen->render_screen_reader_content( 'heading_list' );
428
429 $get_data = give_clean( $_GET ); // WPCS: input var ok, sanitization ok, CSRF ok.
430
431 $search_keyword = ! empty( $get_data['s'] ) ? $get_data['s'] : '';
432 $order = ! empty( $get_data['order'] ) ? $get_data['order'] : 'DESC';
433 $order_by = ! empty( $get_data['orderby'] ) ? $get_data['orderby'] : 'id';
434 ?>
435 <table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
436 <thead>
437 <tr>
438 <?php $this->print_column_headers(); ?>
439 </tr>
440 </thead>
441
442 <tbody id="the-list"<?php
443 if ( $singular ) {
444 echo " data-wp-lists='list:$singular'";
445 } ?>>
446 <tr class="hidden"></tr>
447 <tr id="give-bulk-delete" class="inline-edit-row inline-edit-row-page inline-edit-page bulk-edit-row bulk-edit-row-page bulk-edit-page inline-editor" style="display: none;" >
448 <td colspan="6" class="colspanchange">
449
450 <fieldset class="inline-edit-col-left">
451 <legend class="inline-edit-legend"><?php esc_attr_e( 'BULK DELETE', 'give' ); ?></legend>
452 <div class="inline-edit-col">
453 <div id="bulk-titles">
454 <div id="give-bulk-donors" class="give-bulk-donors">
455
456 </div>
457 </div>
458 </fieldset>
459
460 <fieldset class="inline-edit-col-right">
461 <div class="inline-edit-col">
462 <label>
463 <input class="give-donor-delete-confirm" type="checkbox" name="give-donor-delete-confirm"/>
464 <?php esc_attr_e( 'Are you sure you want to delete the selected donor(s)?', 'give' ); ?>
465 </label>
466 <label>
467 <input class="give-donor-delete-records" type="checkbox" name="give-donor-delete-records"/>
468 <?php esc_attr_e( 'Delete all associated donations and records?', 'give' ); ?>
469 </label>
470 </div>
471 </fieldset>
472
473 <p class="submit inline-edit-save">
474 <input type="hidden" name="give_action" value="delete_bulk_donor"/>
475 <input type="hidden" name="s" value="<?php echo esc_html( $search_keyword ); ?>"/>
476 <input type="hidden" name="orderby" value="<?php echo esc_html( $order_by ); ?>"/>
477 <input type="hidden" name="order" value="<?php echo esc_html( $order ); ?>"/>
478 <button type="button" id="give-bulk-delete-cancel" class="button cancel alignleft"><?php esc_attr_e( 'Cancel', 'give' ); ?></button>
479 <input type="submit" id="give-bulk-delete-button" disabled class="button button-primary alignright" value="<?php esc_attr_e( 'Delete', 'give' ); ?>">
480 <br class="clear">
481 </p>
482 </td>
483 </tr>
484 <?php $this->display_rows_or_placeholder(); ?>
485 </tbody>
486
487 <tfoot>
488 <tr>
489 <?php $this->print_column_headers( false ); ?>
490 </tr>
491 </tfoot>
492
493 </table>
494 <?php
495 $this->display_tablenav( 'bottom' );
496 }
497
498 /**
499 * Setup the final data for the table.
500 *
501 * @access public
502 * @since 1.0
503 *
504 * @return void
505 */
506 public function prepare_items() {
507
508 $columns = $this->get_columns();
509 $hidden = array(); // No hidden columns.
510 $sortable = $this->get_sortable_columns();
511
512 $this->_column_headers = array( $columns, $hidden, $sortable );
513
514 $this->items = $this->donor_data();
515
516 $this->total = $this->get_donor_count();
517
518 $this->set_pagination_args( array(
519 'total_items' => $this->total,
520 'per_page' => $this->per_page,
521 'total_pages' => ceil( $this->total / $this->per_page ),
522 ) );
523 }
524 }
525