1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* Payment History Table Class |
4
|
|
|
* |
5
|
|
|
* @package Give |
6
|
|
|
* @subpackage Admin/Payments |
7
|
|
|
* @copyright Copyright (c) 2015, Give |
8
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
9
|
|
|
* @since 1.0 |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
// Exit if accessed directly |
13
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
14
|
|
|
exit; |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
// Load WP_List_Table if not loaded |
18
|
|
|
if ( ! class_exists( 'WP_List_Table' ) ) { |
19
|
|
|
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Give_Payment_History_Table Class |
24
|
|
|
* |
25
|
|
|
* Renders the Payment History table on the Payment History page |
26
|
|
|
* |
27
|
|
|
* @since 1.0 |
28
|
|
|
*/ |
29
|
|
|
class Give_Payment_History_Table extends WP_List_Table { |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Number of results to show per page |
33
|
|
|
* |
34
|
|
|
* @var string |
35
|
|
|
* @since 1.0 |
36
|
|
|
*/ |
37
|
|
|
public $per_page = 30; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* URL of this page |
41
|
|
|
* |
42
|
|
|
* @var string |
43
|
|
|
* @since 1.0.1 |
44
|
|
|
*/ |
45
|
|
|
public $base_url; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Total number of payments |
49
|
|
|
* |
50
|
|
|
* @var int |
51
|
|
|
* @since 1.0 |
52
|
|
|
*/ |
53
|
|
|
public $total_count; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Total number of complete payments |
57
|
|
|
* |
58
|
|
|
* @var int |
59
|
|
|
* @since 1.0 |
60
|
|
|
*/ |
61
|
|
|
public $complete_count; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Total number of pending payments |
65
|
|
|
* |
66
|
|
|
* @var int |
67
|
|
|
* @since 1.0 |
68
|
|
|
*/ |
69
|
|
|
public $pending_count; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Total number of refunded payments |
73
|
|
|
* |
74
|
|
|
* @var int |
75
|
|
|
* @since 1.0 |
76
|
|
|
*/ |
77
|
|
|
public $refunded_count; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Total number of failed payments |
81
|
|
|
* |
82
|
|
|
* @var int |
83
|
|
|
* @since 1.0 |
84
|
|
|
*/ |
85
|
|
|
public $failed_count; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Total number of revoked payments |
89
|
|
|
* |
90
|
|
|
* @var int |
91
|
|
|
* @since 1.0 |
92
|
|
|
*/ |
93
|
|
|
public $revoked_count; |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Total number of cancelled payments |
97
|
|
|
* |
98
|
|
|
* @var int |
99
|
|
|
* @since 1.3.7 |
100
|
|
|
*/ |
101
|
|
|
public $cancelled_count; |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Total number of abandoned payments |
105
|
|
|
* |
106
|
|
|
* @var int |
107
|
|
|
* @since 1.6 |
108
|
|
|
*/ |
109
|
|
|
public $abandoned_count; |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Get things started |
113
|
|
|
* |
114
|
|
|
* @since 1.0 |
115
|
|
|
* @uses Give_Payment_History_Table::get_payment_counts() |
116
|
|
|
* @see WP_List_Table::__construct() |
117
|
|
|
*/ |
118
|
|
|
public function __construct() { |
119
|
|
|
|
120
|
|
|
global $status, $page; |
|
|
|
|
121
|
|
|
|
122
|
|
|
// Set parent defaults |
123
|
|
|
parent::__construct( array( |
124
|
|
|
'singular' => give_get_forms_label_singular(), // Singular name of the listed records |
125
|
|
|
'plural' => give_get_forms_label_plural(), // Plural name of the listed records |
126
|
|
|
'ajax' => false // Does this table support ajax? |
127
|
|
|
) ); |
128
|
|
|
|
129
|
|
|
$this->get_payment_counts(); |
130
|
|
|
$this->process_bulk_action(); |
131
|
|
|
$this->base_url = admin_url( 'edit.php?post_type=give_forms&page=give-payment-history' ); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public function advanced_filters() { |
135
|
|
|
$start_date = isset( $_GET['start-date'] ) ? sanitize_text_field( $_GET['start-date'] ) : null; |
136
|
|
|
$end_date = isset( $_GET['end-date'] ) ? sanitize_text_field( $_GET['end-date'] ) : null; |
137
|
|
|
$status = isset( $_GET['status'] ) ? $_GET['status'] : ''; |
138
|
|
|
?> |
139
|
|
|
<div id="give-payment-filters"> |
140
|
|
|
<span id="give-payment-date-filters"> |
141
|
|
|
<label for="start-date" class="give-start-date-label"><?php _e( 'Start Date:', 'give' ); ?></label> |
142
|
|
|
<input type="text" id="start-date" name="start-date" class="give_datepicker" value="<?php echo $start_date; ?>" placeholder="mm/dd/yyyy" /> |
143
|
|
|
<label for="end-date" class="give-end-date-label"><?php _e( 'End Date:', 'give' ); ?></label> |
144
|
|
|
<input type="text" id="end-date" name="end-date" class="give_datepicker" value="<?php echo $end_date; ?>" placeholder="mm/dd/yyyy" /> |
145
|
|
|
<input type="submit" class="button-secondary" value="<?php _e( 'Apply', 'give' ); ?>" /> |
146
|
|
|
</span> |
147
|
|
|
<?php if ( ! empty( $status ) ) : ?> |
148
|
|
|
<input type="hidden" name="status" value="<?php echo esc_attr( $status ); ?>" /> |
149
|
|
|
<?php endif; ?> |
150
|
|
|
<?php if ( ! empty( $start_date ) || ! empty( $end_date ) ) : ?> |
151
|
|
|
<a href="<?php echo admin_url( 'edit.php?post_type=give_forms&page=give-payment-history' ); ?>" class="button-secondary"><?php _e( 'Clear Filter', 'give' ); ?></a> |
152
|
|
|
<?php endif; ?> |
153
|
|
|
<?php $this->search_box( __( 'Search', 'give' ), 'give-payments' ); ?> |
154
|
|
|
</div> |
155
|
|
|
|
156
|
|
|
<?php |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Show the search field |
161
|
|
|
* |
162
|
|
|
* @since 1.0 |
163
|
|
|
* @access public |
164
|
|
|
* |
165
|
|
|
* @param string $text Label for the search box |
166
|
|
|
* @param string $input_id ID of the search box |
167
|
|
|
* |
168
|
|
|
* @return void |
169
|
|
|
*/ |
170
|
|
|
public function search_box( $text, $input_id ) { |
171
|
|
|
if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) { |
172
|
|
|
return; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
$input_id = $input_id . '-search-input'; |
176
|
|
|
|
177
|
|
|
if ( ! empty( $_REQUEST['orderby'] ) ) { |
178
|
|
|
echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />'; |
179
|
|
|
} |
180
|
|
|
if ( ! empty( $_REQUEST['order'] ) ) { |
181
|
|
|
echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />'; |
182
|
|
|
} |
183
|
|
|
?> |
184
|
|
|
<p class="search-box"> |
185
|
|
|
<?php do_action( 'give_payment_history_search' ); ?> |
186
|
|
|
<label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label> |
187
|
|
|
<input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" /> |
188
|
|
|
<?php submit_button( $text, 'button', false, false, array( 'ID' => 'search-submit' ) ); ?><br /> |
189
|
|
|
</p> |
190
|
|
|
<?php |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* Retrieve the view types |
195
|
|
|
* |
196
|
|
|
* @access public |
197
|
|
|
* @since 1.0 |
198
|
|
|
* @return array $views All the views available |
199
|
|
|
*/ |
200
|
|
|
public function get_views() { |
201
|
|
|
|
202
|
|
|
$current = isset( $_GET['status'] ) ? $_GET['status'] : ''; |
203
|
|
|
$total_count = ' <span class="count">(' . $this->total_count . ')</span>'; |
204
|
|
|
$complete_count = ' <span class="count">(' . $this->complete_count . ')</span>'; |
205
|
|
|
$cancelled_count = ' <span class="count">(' . $this->cancelled_count . ')</span>'; |
206
|
|
|
$pending_count = ' <span class="count">(' . $this->pending_count . ')</span>'; |
207
|
|
|
$refunded_count = ' <span class="count">(' . $this->refunded_count . ')</span>'; |
208
|
|
|
$failed_count = ' <span class="count">(' . $this->failed_count . ')</span>'; |
209
|
|
|
$abandoned_count = ' <span class="count">(' . $this->abandoned_count . ')</span>'; |
210
|
|
|
$revoked_count = ' <span class="count">(' . $this->revoked_count . ')</span>'; |
211
|
|
|
|
212
|
|
|
$views = array( |
213
|
|
|
'all' => sprintf( '<a href="%s"%s>%s</a>', remove_query_arg( array( |
214
|
|
|
'status', |
215
|
|
|
'paged' |
216
|
|
|
) ), $current === 'all' || $current == '' ? ' class="current"' : '', __( 'All', 'give' ) . $total_count ), |
217
|
|
|
'publish' => sprintf( '<a href="%s"%s>%s</a>', esc_url( add_query_arg( array( |
218
|
|
|
'status' => 'publish', |
219
|
|
|
'paged' => false |
220
|
|
|
) ) ), $current === 'publish' ? ' class="current"' : '', __( 'Completed', 'give' ) . $complete_count ), |
221
|
|
|
'pending' => sprintf( '<a href="%s"%s>%s</a>', esc_url( add_query_arg( array( |
222
|
|
|
'status' => 'pending', |
223
|
|
|
'paged' => false |
224
|
|
|
) ) ), $current === 'pending' ? ' class="current"' : '', __( 'Pending', 'give' ) . $pending_count ), |
225
|
|
|
'refunded' => sprintf( '<a href="%s"%s>%s</a>', esc_url( add_query_arg( array( |
226
|
|
|
'status' => 'refunded', |
227
|
|
|
'paged' => false |
228
|
|
|
) ) ), $current === 'refunded' ? ' class="current"' : '', __( 'Refunded', 'give' ) . $refunded_count ), |
229
|
|
|
'revoked' => sprintf( '<a href="%s"%s>%s</a>', esc_url( add_query_arg( array( |
230
|
|
|
'status' => 'revoked', |
231
|
|
|
'paged' => false |
232
|
|
|
) ) ), $current === 'revoked' ? ' class="current"' : '', __( 'Revoked', 'give' ) . $revoked_count ), |
233
|
|
|
'failed' => sprintf( '<a href="%s"%s>%s</a>', esc_url( add_query_arg( array( |
234
|
|
|
'status' => 'failed', |
235
|
|
|
'paged' => false |
236
|
|
|
) ) ), $current === 'failed' ? ' class="current"' : '', __( 'Failed', 'give' ) . $failed_count ), |
237
|
|
|
'cancelled' => sprintf( '<a href="%s"%s>%s</a>', esc_url( add_query_arg( array( |
238
|
|
|
'status' => 'cancelled', |
239
|
|
|
'paged' => false |
240
|
|
|
) ) ), $current === 'cancelled' ? ' class="current"' : '', __( 'Cancelled', 'give' ) . $cancelled_count ), |
241
|
|
|
'abandoned' => sprintf( '<a href="%s"%s>%s</a>', esc_url( add_query_arg( array( |
242
|
|
|
'status' => 'abandoned', |
243
|
|
|
'paged' => false |
244
|
|
|
) ) ), $current === 'abandoned' ? ' class="current"' : '', __( 'Abandoned', 'give' ) . $abandoned_count ) |
245
|
|
|
); |
246
|
|
|
|
247
|
|
|
return apply_filters( 'give_payments_table_views', $views ); |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* Retrieve the table columns |
252
|
|
|
* |
253
|
|
|
* @access public |
254
|
|
|
* @since 1.0 |
255
|
|
|
* @return array $columns Array of all the list table columns |
256
|
|
|
*/ |
257
|
|
|
public function get_columns() { |
258
|
|
|
$columns = array( |
259
|
|
|
'cb' => '<input type="checkbox" />', //Render a checkbox instead of text |
260
|
|
|
'email' => __( 'Email', 'give' ), |
261
|
|
|
'details' => __( 'Details', 'give' ), |
262
|
|
|
'amount' => __( 'Amount', 'give' ), |
263
|
|
|
'status' => __( 'Status', 'give' ), |
264
|
|
|
'date' => __( 'Date', 'give' ), |
265
|
|
|
'donor' => __( 'Donor', 'give' ), |
266
|
|
|
'ID' => __( 'ID', 'give' ), |
267
|
|
|
); |
268
|
|
|
|
269
|
|
|
return apply_filters( 'give_payments_table_columns', $columns ); |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* Retrieve the table's sortable columns |
274
|
|
|
* |
275
|
|
|
* @access public |
276
|
|
|
* @since 1.0 |
277
|
|
|
* @return array Array of all the sortable columns |
278
|
|
|
*/ |
279
|
|
|
public function get_sortable_columns() { |
280
|
|
|
$columns = array( |
281
|
|
|
'ID' => array( 'ID', true ), |
282
|
|
|
'amount' => array( 'amount', false ), |
283
|
|
|
'date' => array( 'date', false ) |
284
|
|
|
); |
285
|
|
|
|
286
|
|
|
return apply_filters( 'give_payments_table_sortable_columns', $columns ); |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
/** |
290
|
|
|
* This function renders most of the columns in the list table. |
291
|
|
|
* |
292
|
|
|
* @access public |
293
|
|
|
* @since 1.0 |
294
|
|
|
* |
295
|
|
|
* @param array $item Contains all the data of the discount code |
|
|
|
|
296
|
|
|
* @param string $column_name The name of the column |
297
|
|
|
* |
298
|
|
|
* @return string Column Name |
299
|
|
|
*/ |
300
|
|
|
public function column_default( $payment, $column_name ) { |
301
|
|
|
switch ( $column_name ) { |
302
|
|
|
case 'amount' : |
303
|
|
|
$amount = ! empty( $payment->total ) ? $payment->total : 0; |
304
|
|
|
$value = give_currency_filter( give_format_amount( $amount ), give_get_payment_currency_code( $payment->ID ) ); |
305
|
|
|
break; |
306
|
|
|
case 'date' : |
307
|
|
|
$date = strtotime( $payment->date ); |
308
|
|
|
$value = date_i18n( get_option( 'date_format' ), $date ); |
309
|
|
|
break; |
310
|
|
|
case 'status' : |
311
|
|
|
$payment = get_post( $payment->ID ); |
312
|
|
|
$value = '<div class="give-donation-status status-' . sanitize_title( give_get_payment_status( $payment, true ) ) . '"><span class="give-donation-status-icon"></span> ' . give_get_payment_status( $payment, true ) . '</div>'; |
313
|
|
|
break; |
314
|
|
|
case 'details' : |
315
|
|
|
$value = '<div class="give-payment-details-link-wrap"><a href="' . esc_url( add_query_arg( 'id', $payment->ID, admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-order-details' ) ) ) . '" class="give-payment-details-link button button-small">' . __( 'View Donation Details', 'give' ) . '</a></div>'; |
316
|
|
|
break; |
317
|
|
|
default: |
318
|
|
|
$value = isset( $payment->$column_name ) ? $payment->$column_name : ''; |
319
|
|
|
break; |
320
|
|
|
|
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
return apply_filters( 'give_payments_table_column', $value, $payment->ID, $column_name ); |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
/** |
327
|
|
|
* Render the Email Column |
328
|
|
|
* |
329
|
|
|
* @access public |
330
|
|
|
* @since 1.0 |
331
|
|
|
* |
332
|
|
|
* @param array $payment Contains all the data of the payment |
333
|
|
|
* |
334
|
|
|
* @return string Data shown in the Email column |
335
|
|
|
*/ |
336
|
|
|
public function column_email( $payment ) { |
337
|
|
|
|
338
|
|
|
$row_actions = array(); |
339
|
|
|
|
340
|
|
|
if ( give_is_payment_complete( $payment->ID ) ) { |
341
|
|
|
$row_actions['email_links'] = '<a href="' . add_query_arg( array( |
342
|
|
|
'give-action' => 'email_links', |
343
|
|
|
'purchase_id' => $payment->ID |
344
|
|
|
), $this->base_url ) . '">' . __( 'Resend Donation Receipt', 'give' ) . '</a>'; |
345
|
|
|
|
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
$row_actions['delete'] = '<a href="' . wp_nonce_url( add_query_arg( array( |
349
|
|
|
'give-action' => 'delete_payment', |
350
|
|
|
'purchase_id' => $payment->ID |
351
|
|
|
), $this->base_url ), 'give_payment_nonce' ) . '">' . __( 'Delete', 'give' ) . '</a>'; |
352
|
|
|
|
353
|
|
|
$row_actions = apply_filters( 'give_payment_row_actions', $row_actions, $payment ); |
354
|
|
|
|
355
|
|
|
if ( ! isset( $payment->user_info['email'] ) ) { |
356
|
|
|
$payment->user_info['email'] = __( '(unknown)', 'give' ); |
357
|
|
|
} |
358
|
|
|
|
359
|
|
|
$value = '<span class="give-email-column-value">' . $payment->user_info['email'] . '</span>' . $this->row_actions( $row_actions ); |
360
|
|
|
|
361
|
|
|
return apply_filters( 'give_payments_table_column', $value, $payment->ID, 'email' ); |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
/** |
365
|
|
|
* Render the checkbox column |
366
|
|
|
* |
367
|
|
|
* @access public |
368
|
|
|
* @since 1.0 |
369
|
|
|
* |
370
|
|
|
* @param array $payment Contains all the data for the checkbox column |
371
|
|
|
* |
372
|
|
|
* @return string Displays a checkbox |
373
|
|
|
*/ |
374
|
|
|
public function column_cb( $payment ) { |
375
|
|
|
return sprintf( |
376
|
|
|
'<input type="checkbox" name="%1$s[]" value="%2$s" />', |
377
|
|
|
'payment', |
378
|
|
|
$payment->ID |
379
|
|
|
); |
380
|
|
|
} |
381
|
|
|
|
382
|
|
|
/** |
383
|
|
|
* Render the ID column |
384
|
|
|
* |
385
|
|
|
* @access public |
386
|
|
|
* @since 1.0 |
387
|
|
|
* |
388
|
|
|
* @param array $payment Contains all the data for the checkbox column |
389
|
|
|
* |
390
|
|
|
* @return string Displays a checkbox |
391
|
|
|
*/ |
392
|
|
|
public function column_ID( $payment ) { |
393
|
|
|
return '<span class="give-payment-id">' . give_get_payment_number( $payment->ID ) . '</span>'; |
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
/** |
397
|
|
|
* Render the User Column |
398
|
|
|
* |
399
|
|
|
* @access public |
400
|
|
|
* @since 1.0 |
401
|
|
|
* |
402
|
|
|
* @param array $payment Contains all the data of the payment |
403
|
|
|
* |
404
|
|
|
* @return string Data shown in the User column |
405
|
|
|
*/ |
406
|
|
|
public function column_donor( $payment ) { |
407
|
|
|
|
408
|
|
|
// $user_id = give_get_payment_user_id( $payment->ID ); |
|
|
|
|
409
|
|
|
|
410
|
|
|
$customer_id = give_get_payment_customer_id( $payment->ID ); |
411
|
|
|
$customer = new Give_Customer( $customer_id ); |
412
|
|
|
|
413
|
|
|
$view_url = admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $customer_id ); |
414
|
|
|
|
415
|
|
|
$value = '<a href="' . esc_url( $view_url ) . '" data-tooltip="' . __( 'Click here to view this Donor\'s profile', 'give' ) . '">' . $customer->name . '</a>'; |
416
|
|
|
|
417
|
|
|
return apply_filters( 'give_payments_table_column', $value, $payment->ID, 'donor' ); |
418
|
|
|
} |
419
|
|
|
|
420
|
|
|
/** |
421
|
|
|
* Retrieve the bulk actions |
422
|
|
|
* |
423
|
|
|
* @access public |
424
|
|
|
* @since 1.0 |
425
|
|
|
* @return array $actions Array of the bulk actions |
426
|
|
|
*/ |
427
|
|
|
public function get_bulk_actions() { |
428
|
|
|
$actions = array( |
429
|
|
|
'delete' => __( 'Delete', 'give' ), |
430
|
|
|
'set-status-publish' => __( 'Set To Completed', 'give' ), |
431
|
|
|
'set-status-pending' => __( 'Set To Pending', 'give' ), |
432
|
|
|
'set-status-refunded' => __( 'Set To Refunded', 'give' ), |
433
|
|
|
'set-status-revoked' => __( 'Set To Revoked', 'give' ), |
434
|
|
|
'set-status-failed' => __( 'Set To Failed', 'give' ), |
435
|
|
|
'set-status-cancelled' => __( 'Set To Cancelled', 'give' ), |
436
|
|
|
'set-status-abandoned' => __( 'Set To Abandoned', 'give' ), |
437
|
|
|
'resend-receipt' => __( 'Resend Email Receipts', 'give' ) |
438
|
|
|
); |
439
|
|
|
|
440
|
|
|
return apply_filters( 'give_payments_table_bulk_actions', $actions ); |
441
|
|
|
} |
442
|
|
|
|
443
|
|
|
/** |
444
|
|
|
* Process the bulk actions |
445
|
|
|
* |
446
|
|
|
* @access public |
447
|
|
|
* @since 1.0 |
448
|
|
|
* @return void |
449
|
|
|
*/ |
450
|
|
|
public function process_bulk_action() { |
451
|
|
|
$ids = isset( $_GET['payment'] ) ? $_GET['payment'] : false; |
452
|
|
|
$action = $this->current_action(); |
453
|
|
|
|
454
|
|
|
if ( ! is_array( $ids ) ) { |
455
|
|
|
$ids = array( $ids ); |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
if ( empty( $action ) ) { |
459
|
|
|
return; |
460
|
|
|
} |
461
|
|
|
|
462
|
|
|
foreach ( $ids as $id ) { |
463
|
|
|
|
464
|
|
|
// Detect when a bulk action is being triggered... |
465
|
|
|
if ( 'delete' === $this->current_action() ) { |
466
|
|
|
give_delete_purchase( $id ); |
467
|
|
|
} |
468
|
|
|
|
469
|
|
|
if ( 'set-status-publish' === $this->current_action() ) { |
470
|
|
|
give_update_payment_status( $id, 'publish' ); |
471
|
|
|
} |
472
|
|
|
|
473
|
|
|
if ( 'set-status-pending' === $this->current_action() ) { |
474
|
|
|
give_update_payment_status( $id, 'pending' ); |
475
|
|
|
} |
476
|
|
|
|
477
|
|
|
if ( 'set-status-refunded' === $this->current_action() ) { |
478
|
|
|
give_update_payment_status( $id, 'refunded' ); |
479
|
|
|
} |
480
|
|
|
|
481
|
|
|
if ( 'set-status-revoked' === $this->current_action() ) { |
482
|
|
|
give_update_payment_status( $id, 'revoked' ); |
483
|
|
|
} |
484
|
|
|
|
485
|
|
|
if ( 'set-status-failed' === $this->current_action() ) { |
486
|
|
|
give_update_payment_status( $id, 'failed' ); |
487
|
|
|
} |
488
|
|
|
|
489
|
|
|
if ( 'set-status-cancelled' === $this->current_action() ) { |
490
|
|
|
give_update_payment_status( $id, 'cancelled' ); |
491
|
|
|
} |
492
|
|
|
|
493
|
|
|
if ( 'set-status-abandoned' === $this->current_action() ) { |
494
|
|
|
give_update_payment_status( $id, 'abandoned' ); |
495
|
|
|
} |
496
|
|
|
|
497
|
|
|
if ( 'resend-receipt' === $this->current_action() ) { |
498
|
|
|
give_email_donation_receipt( $id, false ); |
499
|
|
|
} |
500
|
|
|
|
501
|
|
|
do_action( 'give_payments_table_do_bulk_action', $id, $this->current_action() ); |
502
|
|
|
} |
503
|
|
|
|
504
|
|
|
} |
505
|
|
|
|
506
|
|
|
/** |
507
|
|
|
* Retrieve the payment counts |
508
|
|
|
* |
509
|
|
|
* @access public |
510
|
|
|
* @since 1.0 |
511
|
|
|
* @return void |
512
|
|
|
*/ |
513
|
|
|
public function get_payment_counts() { |
514
|
|
|
|
515
|
|
|
global $wp_query; |
|
|
|
|
516
|
|
|
|
517
|
|
|
$args = array(); |
518
|
|
|
|
519
|
|
|
if ( isset( $_GET['user'] ) ) { |
520
|
|
|
$args['user'] = urldecode( $_GET['user'] ); |
521
|
|
|
} elseif ( isset( $_GET['s'] ) ) { |
522
|
|
|
$args['s'] = urldecode( $_GET['s'] ); |
523
|
|
|
} |
524
|
|
|
|
525
|
|
|
if ( ! empty( $_GET['start-date'] ) ) { |
526
|
|
|
$args['start-date'] = urldecode( $_GET['start-date'] ); |
527
|
|
|
} |
528
|
|
|
|
529
|
|
|
if ( ! empty( $_GET['end-date'] ) ) { |
530
|
|
|
$args['end-date'] = urldecode( $_GET['end-date'] ); |
531
|
|
|
} |
532
|
|
|
|
533
|
|
|
$payment_count = give_count_payments( $args ); |
534
|
|
|
$this->complete_count = $payment_count->publish; |
535
|
|
|
$this->pending_count = $payment_count->pending; |
536
|
|
|
$this->refunded_count = $payment_count->refunded; |
537
|
|
|
$this->failed_count = $payment_count->failed; |
538
|
|
|
$this->revoked_count = $payment_count->revoked; |
539
|
|
|
$this->cancelled_count = $payment_count->cancelled; |
540
|
|
|
$this->abandoned_count = $payment_count->abandoned; |
541
|
|
|
|
542
|
|
|
foreach ( $payment_count as $count ) { |
543
|
|
|
$this->total_count += $count; |
544
|
|
|
} |
545
|
|
|
} |
546
|
|
|
|
547
|
|
|
/** |
548
|
|
|
* Retrieve all the data for all the payments |
549
|
|
|
* |
550
|
|
|
* @access public |
551
|
|
|
* @since 1.0 |
552
|
|
|
* @return array $payment_data Array of all the data for the payments |
553
|
|
|
*/ |
554
|
|
|
public function payments_data() { |
555
|
|
|
|
556
|
|
|
$per_page = $this->per_page; |
557
|
|
|
$orderby = isset( $_GET['orderby'] ) ? urldecode( $_GET['orderby'] ) : 'ID'; |
558
|
|
|
$order = isset( $_GET['order'] ) ? $_GET['order'] : 'DESC'; |
559
|
|
|
$user = isset( $_GET['user'] ) ? $_GET['user'] : null; |
560
|
|
|
$status = isset( $_GET['status'] ) ? $_GET['status'] : give_get_payment_status_keys(); |
561
|
|
|
$meta_key = isset( $_GET['meta_key'] ) ? $_GET['meta_key'] : null; |
562
|
|
|
$year = isset( $_GET['year'] ) ? $_GET['year'] : null; |
563
|
|
|
$month = isset( $_GET['m'] ) ? $_GET['m'] : null; |
564
|
|
|
$day = isset( $_GET['day'] ) ? $_GET['day'] : null; |
565
|
|
|
$search = isset( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : null; |
566
|
|
|
$start_date = isset( $_GET['start-date'] ) ? sanitize_text_field( $_GET['start-date'] ) : null; |
567
|
|
|
$end_date = isset( $_GET['end-date'] ) ? sanitize_text_field( $_GET['end-date'] ) : $start_date; |
568
|
|
|
|
569
|
|
|
if ( ! empty( $search ) ) { |
570
|
|
|
$status = 'any'; // Force all payment statuses when searching |
571
|
|
|
} |
572
|
|
|
|
573
|
|
|
$args = array( |
574
|
|
|
'output' => 'payments', |
575
|
|
|
'number' => $per_page, |
576
|
|
|
'page' => isset( $_GET['paged'] ) ? $_GET['paged'] : null, |
577
|
|
|
'orderby' => $orderby, |
578
|
|
|
'order' => $order, |
579
|
|
|
'user' => $user, |
580
|
|
|
'status' => $status, |
581
|
|
|
'meta_key' => $meta_key, |
582
|
|
|
'year' => $year, |
583
|
|
|
'month' => $month, |
584
|
|
|
'day' => $day, |
585
|
|
|
's' => $search, |
586
|
|
|
'start_date' => $start_date, |
587
|
|
|
'end_date' => $end_date, |
588
|
|
|
); |
589
|
|
|
|
590
|
|
|
if ( is_string( $search ) && false !== strpos( $search, 'txn:' ) ) { |
591
|
|
|
|
592
|
|
|
$args['search_in_notes'] = true; |
593
|
|
|
$args['s'] = trim( str_replace( 'txn:', '', $args['s'] ) ); |
594
|
|
|
|
595
|
|
|
} |
596
|
|
|
|
597
|
|
|
$p_query = new Give_Payments_Query( $args ); |
598
|
|
|
|
599
|
|
|
return $p_query->get_payments(); |
600
|
|
|
|
601
|
|
|
} |
602
|
|
|
|
603
|
|
|
/** |
604
|
|
|
* Setup the final data for the table |
605
|
|
|
* |
606
|
|
|
* @access public |
607
|
|
|
* @since 1.0 |
608
|
|
|
* @uses Give_Payment_History_Table::get_columns() |
609
|
|
|
* @uses Give_Payment_History_Table::get_sortable_columns() |
610
|
|
|
* @uses Give_Payment_History_Table::payments_data() |
611
|
|
|
* @uses WP_List_Table::get_pagenum() |
612
|
|
|
* @uses WP_List_Table::set_pagination_args() |
613
|
|
|
* @return void |
614
|
|
|
*/ |
615
|
|
|
public function prepare_items() { |
616
|
|
|
|
617
|
|
|
wp_reset_vars( array( 'action', 'payment', 'orderby', 'order', 's' ) ); |
618
|
|
|
|
619
|
|
|
$columns = $this->get_columns(); |
620
|
|
|
$hidden = array(); // No hidden columns |
621
|
|
|
$sortable = $this->get_sortable_columns(); |
622
|
|
|
$data = $this->payments_data(); |
623
|
|
|
$status = isset( $_GET['status'] ) ? $_GET['status'] : 'any'; |
624
|
|
|
|
625
|
|
|
$this->_column_headers = array( $columns, $hidden, $sortable ); |
626
|
|
|
|
627
|
|
|
switch ( $status ) { |
628
|
|
|
case 'publish': |
629
|
|
|
$total_items = $this->complete_count; |
630
|
|
|
break; |
631
|
|
|
case 'pending': |
632
|
|
|
$total_items = $this->pending_count; |
633
|
|
|
break; |
634
|
|
|
case 'refunded': |
635
|
|
|
$total_items = $this->refunded_count; |
636
|
|
|
break; |
637
|
|
|
case 'failed': |
638
|
|
|
$total_items = $this->failed_count; |
639
|
|
|
break; |
640
|
|
|
case 'revoked': |
641
|
|
|
$total_items = $this->revoked_count; |
642
|
|
|
break; |
643
|
|
|
case 'cancelled': |
644
|
|
|
$total_items = $this->cancelled_count; |
645
|
|
|
break; |
646
|
|
|
case 'abandoned': |
647
|
|
|
$total_items = $this->abandoned_count; |
648
|
|
|
break; |
649
|
|
|
case 'any': |
650
|
|
|
$total_items = $this->total_count; |
651
|
|
|
break; |
652
|
|
|
default: |
653
|
|
|
// Retrieve the count of the non-default-Give status |
654
|
|
|
$count = wp_count_posts( 'give_payment' ); |
655
|
|
|
$total_items = $count->{$status}; |
656
|
|
|
} |
657
|
|
|
|
658
|
|
|
$this->items = $data; |
659
|
|
|
|
660
|
|
|
$this->set_pagination_args( array( |
661
|
|
|
'total_items' => $total_items, |
662
|
|
|
// WE have to calculate the total number of items |
663
|
|
|
'per_page' => $this->per_page, |
664
|
|
|
// WE have to determine how many items to show on a page |
665
|
|
|
'total_pages' => ceil( $total_items / $this->per_page ) |
666
|
|
|
// WE have to calculate the total number of pages |
667
|
|
|
) |
668
|
|
|
); |
669
|
|
|
} |
670
|
|
|
} |
671
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.