PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.4.3
GiveWP – Donation Plugin and Fundraising Platform v2.4.3
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 / forms / dashboard-columns.php
give / includes / admin / forms Last commit date
class-give-form-duplicator.php 7 years ago class-metabox-form-data.php 7 years ago dashboard-columns.php 7 years ago metabox.php 7 years ago
dashboard-columns.php
599 lines
1 <?php
2 /**
3 * Dashboard Columns
4 *
5 * @package GIVE
6 * @subpackage Admin/Forms
7 * @copyright Copyright (c) 2016, GiveWP
8 * @license https://opensource.org/licenses/gpl-license GNU Public License
9 * @since 1.0
10 */
11
12 // Exit if accessed directly.
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17
18 /**
19 * Give Forms Columns
20 *
21 * Defines the custom columns and their order
22 *
23 * @since 1.0
24 *
25 * @param array $give_form_columns Array of forms columns
26 *
27 * @return array $form_columns Updated array of forms columns
28 * Post Type List Table
29 */
30 function give_form_columns( $give_form_columns ) {
31
32 // Standard columns
33 $give_form_columns = array(
34 'cb' => '<input type="checkbox"/>',
35 'title' => __( 'Name', 'give' ),
36 'form_category' => __( 'Categories', 'give' ),
37 'form_tag' => __( 'Tags', 'give' ),
38 'price' => __( 'Amount', 'give' ),
39 'goal' => __( 'Goal', 'give' ),
40 'donations' => __( 'Donations', 'give' ),
41 'earnings' => __( 'Income', 'give' ),
42 'shortcode' => __( 'Shortcode', 'give' ),
43 'date' => __( 'Date', 'give' ),
44 );
45
46 // Does the user want categories / tags?
47 if ( ! give_is_setting_enabled( give_get_option( 'categories', 'disabled' ) ) ) {
48 unset( $give_form_columns['form_category'] );
49 }
50 if ( ! give_is_setting_enabled( give_get_option( 'tags', 'disabled' ) ) ) {
51 unset( $give_form_columns['form_tag'] );
52 }
53
54 return apply_filters( 'give_forms_columns', $give_form_columns );
55 }
56
57 add_filter( 'manage_edit-give_forms_columns', 'give_form_columns' );
58
59 /**
60 * Render Give Form Columns
61 *
62 * @since 1.0
63 *
64 * @param string $column_name Column name
65 * @param int $post_id Give Form (Post) ID
66 *
67 * @return void
68 */
69 function give_render_form_columns( $column_name, $post_id ) {
70 if ( get_post_type( $post_id ) == 'give_forms' ) {
71
72 switch ( $column_name ) {
73 case 'form_category':
74 echo get_the_term_list( $post_id, 'give_forms_category', '', ', ', '' );
75 break;
76 case 'form_tag':
77 echo get_the_term_list( $post_id, 'give_forms_tag', '', ', ', '' );
78 break;
79 case 'price':
80 if ( give_has_variable_prices( $post_id ) ) {
81 echo give_price_range( $post_id );
82 } else {
83 echo give_price( $post_id, false );
84 printf( '<input type="hidden" class="formprice-%1$s" value="%2$s" />', esc_attr( $post_id ), esc_attr( give_get_form_price( $post_id ) ) );
85 }
86 break;
87 case 'goal':
88 if ( give_is_setting_enabled( give_get_meta( $post_id, '_give_goal_option', true ) ) ) {
89
90 echo give_admin_form_goal_stats( $post_id );
91
92 } else {
93 _e( 'No Goal Set', 'give' );
94 }
95
96 printf(
97 '<input type="hidden" class="formgoal-%1$s" value="%2$s" />',
98 esc_attr( $post_id ),
99 give_get_form_goal( $post_id )
100 );
101
102 break;
103 case 'donations':
104 if ( current_user_can( 'view_give_form_stats', $post_id ) ) {
105 printf(
106 '<a href="%1$s">%2$s</a>',
107 esc_url( admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&form_id=' . $post_id ) ),
108 give_get_form_sales_stats( $post_id )
109 );
110 } else {
111 echo '-';
112 }
113 break;
114 case 'earnings':
115 if ( current_user_can( 'view_give_form_stats', $post_id ) ) {
116 printf(
117 '<a href="%1$s">%2$s</a>',
118 esc_url( admin_url( 'edit.php?post_type=give_forms&page=give-reports&tab=forms&form-id=' . $post_id ) ),
119 give_currency_filter( give_format_amount( give_get_form_earnings_stats( $post_id ), array( 'sanitize' => false ) ) )
120 );
121 } else {
122 echo '-';
123 }
124 break;
125 case 'shortcode':
126 $shortcode = sprintf( '[give_form id="%s"]', absint( $post_id ) );
127 printf(
128 '<button type="button" class="button hint-tooltip hint--top js-give-shortcode-button" aria-label="%1$s" data-give-shortcode="%2$s"><span class="dashicons dashicons-admin-page"></span> %3$s</button>',
129 esc_attr( $shortcode ),
130 esc_attr( $shortcode ),
131 esc_html__( 'Copy Shortcode', 'give' )
132 );
133 break;
134 }// End switch().
135 }// End if().
136 }
137
138 add_action( 'manage_posts_custom_column', 'give_render_form_columns', 10, 2 );
139
140 /**
141 * Registers the sortable columns in the list table
142 *
143 * @since 1.0
144 *
145 * @param array $columns Array of the columns
146 *
147 * @return array $columns Array of sortable columns
148 */
149 function give_sortable_form_columns( $columns ) {
150 $columns['price'] = 'amount';
151 $columns['sales'] = 'sales';
152 $columns['earnings'] = 'earnings';
153 $columns['goal'] = 'goal';
154 $columns['donations'] = 'donations';
155
156 return $columns;
157 }
158
159 add_filter( 'manage_edit-give_forms_sortable_columns', 'give_sortable_form_columns' );
160
161 /**
162 * Sorts Columns in the Forms List Table
163 *
164 * @since 1.0
165 *
166 * @param array $vars Array of all the sort variables.
167 *
168 * @return array $vars Array of all the sort variables.
169 */
170 function give_sort_forms( $vars ) {
171 // Check if we're viewing the "give_forms" post type.
172 if ( ! isset( $vars['post_type'] ) || ! isset( $vars['orderby'] ) || 'give_forms' !== $vars['post_type'] ) {
173 return $vars;
174 }
175
176 switch ( $vars['orderby'] ) {
177 // Check if 'orderby' is set to "sales".
178 case 'sales':
179 $vars = array_merge(
180 $vars,
181 array(
182 'meta_key' => '_give_form_sales',
183 'orderby' => 'meta_value_num',
184 )
185 );
186 break;
187
188 // Check if "orderby" is set to "earnings".
189 case 'earnings':
190 $vars = array_merge(
191 $vars,
192 array(
193 'meta_key' => '_give_form_earnings',
194 'orderby' => 'meta_value_num',
195 )
196 );
197 break;
198
199 // Check if "orderby" is set to "price/amount".
200 case 'amount':
201 $multi_level_meta_key = ( 'asc' === $vars['order'] ) ? '_give_levels_minimum_amount' : '_give_levels_maximum_amount';
202
203 $vars['orderby'] = 'meta_value_num';
204 $vars['meta_query'] = array(
205 'relation' => 'OR',
206 array(
207 'key' => $multi_level_meta_key,
208 'type' => 'NUMERIC',
209 ),
210 array(
211 'key' => '_give_set_price',
212 'type' => 'NUMERIC',
213 ),
214 );
215
216 break;
217
218 // Check if "orderby" is set to "goal".
219 case 'goal':
220 $meta_key = give_has_upgrade_completed( 'v240_update_form_goal_progress' )
221 ? '_give_form_goal_progress'
222 : '_give_set_goal'; // Backward compatibility
223
224 $vars = array_merge(
225 $vars,
226 array(
227 'meta_key' => $meta_key,
228 'orderby' => 'meta_value_num',
229 )
230 );
231 break;
232
233 // Check if "orderby" is set to "donations".
234 case 'donations':
235 $vars = array_merge(
236 $vars,
237 array(
238 'meta_key' => '_give_form_sales',
239 'orderby' => 'meta_value_num',
240 )
241 );
242 break;
243 }// End switch().
244
245 return $vars;
246 }
247
248 /**
249 * Sets restrictions on author of Forms List Table
250 *
251 * @since 1.0
252 *
253 * @param array $vars Array of all sort variables.
254 *
255 * @return array Array of all sort variables.
256 */
257 function give_filter_forms( $vars ) {
258 if ( isset( $vars['post_type'] ) && 'give_forms' == $vars['post_type'] ) {
259
260 // If an author ID was passed, use it
261 if ( isset( $_REQUEST['author'] ) && ! current_user_can( 'view_give_reports' ) ) {
262
263 $author_id = $_REQUEST['author'];
264 if ( (int) $author_id !== get_current_user_id() ) {
265 wp_die(
266 esc_html__( 'You do not have permission to view this data.', 'give' ), esc_html__( 'Error', 'give' ), array(
267 'response' => 403,
268 )
269 );
270 }
271 $vars = array_merge(
272 $vars,
273 array(
274 'author' => get_current_user_id(),
275 )
276 );
277
278 }
279 }
280
281 return $vars;
282 }
283
284 /**
285 * Form Load
286 *
287 * Sorts the form columns.
288 *
289 * @since 1.0
290 * @return void
291 */
292 function give_forms_load() {
293 add_filter( 'request', 'give_sort_forms' );
294 add_filter( 'request', 'give_filter_forms' );
295 }
296
297 add_action( 'load-edit.php', 'give_forms_load', 9999 );
298
299 /**
300 * Remove Forms Month Filter
301 *
302 * Removes the default drop down filter for forms by date.
303 *
304 * @since 1.0
305 *
306 * @param array $dates The preset array of dates.
307 *
308 * @global $typenow The post type we are viewing.
309 * @return array Empty array disables the dropdown.
310 */
311 function give_remove_month_filter( $dates ) {
312 global $typenow;
313
314 if ( $typenow == 'give_forms' ) {
315 $dates = array();
316 }
317
318 return $dates;
319 }
320
321 add_filter( 'months_dropdown_results', 'give_remove_month_filter', 99 );
322
323 /**
324 * Updates price when saving post
325 *
326 * @since 1.0
327 * @since 2.1.4 If the donation amount is less than the Minimum amount then set the donation amount as Donation minimum amount.
328 *
329 * @param int $post_id Download (Post) ID
330 *
331 * @return int|null
332 */
333 function give_price_save_quick_edit( $post_id ) {
334 if ( ! isset( $_POST['post_type'] ) || 'give_forms' !== $_POST['post_type'] ) {
335 return;
336 }
337 if ( ! current_user_can( 'edit_post', $post_id ) ) {
338 return $post_id;
339 }
340 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
341 return $post_id;
342 }
343
344 if ( isset( $_REQUEST['_give_regprice'] ) ) {
345 give_update_meta( $post_id, '_give_set_price', give_sanitize_amount_for_db( strip_tags( stripslashes( $_REQUEST['_give_regprice'] ) ) ) );
346 }
347
348 // Override the Donation minimum amount.
349 if (
350 isset( $_REQUEST['_give_custom_amount'], $_REQUEST['_give_set_price'], $_REQUEST['_give_price_option'], $_REQUEST['_give_custom_amount_range'] )
351 && 'set' === $_REQUEST['_give_price_option']
352 && give_is_setting_enabled( $_REQUEST['_give_custom_amount'] )
353 && give_maybe_sanitize_amount( $_REQUEST['_give_set_price'] ) < give_maybe_sanitize_amount( $_REQUEST['_give_custom_amount_range']['minimum'] )
354 ) {
355 give_update_meta( $post_id, '_give_custom_amount_range_minimum', give_sanitize_amount_for_db( $_REQUEST['_give_set_price'] ) );
356 }
357 }
358
359 add_action( 'save_post', 'give_price_save_quick_edit' );
360
361 /**
362 * Process bulk edit actions via AJAX
363 *
364 * @since 1.0
365 * @return void
366 */
367 function give_save_bulk_edit() {
368
369 $post_ids = ( isset( $_POST['post_ids'] ) && ! empty( $_POST['post_ids'] ) ) ? $_POST['post_ids'] : array();
370
371 if ( ! empty( $post_ids ) && is_array( $post_ids ) ) {
372 $price = isset( $_POST['price'] ) ? strip_tags( stripslashes( $_POST['price'] ) ) : 0;
373 foreach ( $post_ids as $post_id ) {
374
375 if ( ! current_user_can( 'edit_post', $post_id ) ) {
376 continue;
377 }
378
379 if ( ! empty( $price ) ) {
380 give_update_meta( $post_id, '_give_set_price', give_sanitize_amount_for_db( $price ) );
381 }
382 }
383 }
384
385 die();
386 }
387
388 add_action( 'wp_ajax_give_save_bulk_edit', 'give_save_bulk_edit' );
389
390 /**
391 * Function is used to filter the query for search result.
392 *
393 * @since 2.4.0
394 *
395 * @param $wp WP WordPress environment instance (passed by reference).
396 */
397 function give_form_search_query_filter( $wp ) {
398
399 if (
400 isset( $wp->query_vars['post_type'] )
401 && 'give_forms' == $wp->query_vars['post_type']
402 && isset( $_GET['give-forms-goal-filter'] )
403 ) {
404
405 $wp->query_vars['date_query'] =
406 array(
407 'after' => ! empty( $_GET['start-date'] ) ? date( 'Y-m-d', strtotime( give_clean( $_GET['start-date'] ) ) ) : false,
408 'before' => ! empty( $_GET['end-date'] ) ? date( 'Y-m-d 23:59:59 ', strtotime( give_clean( $_GET['end-date'] ) ) ) : false,
409 'inclusive' => true,
410 );
411 switch ( $_GET['give-forms-goal-filter'] ) {
412 case 'goal_in_progress':
413 $wp->query_vars['meta_query'] =
414 array(
415 'relation' => 'AND',
416 array(
417 'key' => '_give_form_goal_progress',
418 'value' => array( 1, 99 ),
419 'compare' => 'BETWEEN',
420 'type' => 'NUMERIC',
421 ),
422 );
423
424 break;
425 case 'goal_achieved':
426 $wp->query_vars['meta_query'] =
427 array(
428 'relation' => 'AND',
429 array(
430 'key' => '_give_form_goal_progress',
431 'value' => 100,
432 'compare' => '>=',
433 'type' => 'NUMERIC',
434 ),
435 );
436 break;
437 case 'goal_not_set':
438 $wp->query_vars['meta_query'] =
439 array(
440 'relation' => 'OR',
441 array(
442 'key' => '_give_goal_option',
443 'value' => 'disabled',
444 'compare' => '=',
445 ),
446 array(
447 'key' => '_give_goal_option',
448 'compare' => 'NOT EXISTS',
449 ),
450 );
451 break;
452 }
453 }
454 }
455
456 add_action( 'parse_request', 'give_form_search_query_filter' );
457
458 /**
459 * function is used to search give forms by ID or title.
460 *
461 * @since 2.4.0
462 *
463 * @param $query WP_Query the WP_Query instance (passed by reference).
464 */
465
466 function give_search_form_by_id( $query ) {
467 // Verify that we are on the give forms list page.
468 if (
469 empty( $query->query_vars['post_type'] )
470 || 'give_forms' !== $query->query_vars['post_type']
471 ) {
472 return;
473 }
474
475 if ( '' !== $query->query_vars['s'] && is_search() ) {
476 if ( absint( $query->query_vars['s'] ) ) {
477 // Set the post id value
478 $query->set( 'p', $query->query_vars['s'] );
479 // Reset the search value
480 $query->set( 's', '' );
481 }
482 }
483 }
484
485 add_filter( 'pre_get_posts', 'give_search_form_by_id' );
486
487 /**
488 * Outputs advanced filter html in Give forms list admin screen.
489 *
490 * @sicne 2.4.0
491 *
492 * @param $which
493 */
494 function give_forms_advanced_filter( $which ) {
495 /* @var stdClass $screen */
496 $screen = get_current_screen();
497
498 if ( 'edit' !== $screen->parent_base || 'give_forms' !== $screen->post_type ) {
499 return;
500 }
501
502 // Apply this only on a specific post type
503 if ( 'top' !== $which ) {
504 return;
505 }
506
507 $start_date = isset( $_GET['start-date'] ) ? strtotime( give_clean( $_GET['start-date'] ) ) : '';
508 $end_date = isset( $_GET['end-date'] ) ? strtotime( give_clean( $_GET['end-date'] ) ) : '';
509 $search = isset( $_GET['s'] ) ? give_clean( $_GET['s'] ) : '';
510 $give_forms_goal_filter = isset( $_GET['give-forms-goal-filter'] ) ? $_GET['give-forms-goal-filter'] : '';
511 ?>
512 <div id="give-forms-advanced-filter" class="give-filters">
513 <div class="give-filter give-filter-search">
514 <input type="text" id="give-forms-search-input" placeholder="<?php _e( 'Form Name or ID', 'give' ); ?>" name="s" value="<?php echo $search; ?>">
515 <?php
516 submit_button(
517 __( 'Search', 'give' ), 'button', false, false, array(
518 'ID' => 'form-search-submit',
519 )
520 );
521 ?>
522 </div>
523 <div id="give-payment-date-filters">
524 <div class="give-filter give-filter-half">
525 <label for="start-date"
526 class="give-start-date-label"><?php _e( 'Start Date', 'give' ); ?></label>
527 <input type="text"
528 id="start-date"
529 name="start-date"
530 class="give_datepicker"
531 autocomplete="off"
532 value="<?php echo $start_date ? date_i18n( give_date_format(), $start_date ) : ''; ?>"
533 data-standard-date="<?php echo $start_date ? date( 'Y-m-d', $start_date ) : $start_date; ?>"
534 placeholder="<?php _e( 'Start Date', 'give' ); ?>"
535 />
536 </div>
537 <div class="give-filter give-filter-half">
538 <label for="end-date" class="give-end-date-label"><?php _e( 'End Date', 'give' ); ?></label>
539 <input type="text"
540 id="end-date"
541 name="end-date"
542 class="give_datepicker"
543 autocomplete="off"
544 value="<?php echo $end_date ? date_i18n( give_date_format(), $end_date ) : ''; ?>"
545 data-standard-date="<?php echo $end_date ? date( 'Y-m-d', $end_date ) : $end_date; ?>"
546 placeholder="<?php _e( 'End Date', 'give' ); ?>"
547 />
548 </div>
549 </div>
550 <div id="give-payment-form-filter" class="give-filter">
551 <label for="give-donation-forms-filter"
552 class="give-donation-forms-filter-label"><?php _e( 'Goal', 'give' ); ?></label>
553 <select id="give-forms-goal-filter" name="give-forms-goal-filter" class="give-forms-goal-filter">
554 <option value="any_goal_status"
555 <?php
556 if ( 'any_goal_status' === $give_forms_goal_filter ) {
557 echo 'selected';
558 }
559 ?>
560 ><?php _e( 'Any Goal Status', 'give' ); ?></option>
561 <option value="goal_achieved"
562 <?php
563 if ( 'goal_achieved' === $give_forms_goal_filter ) {
564 echo 'selected';
565 }
566 ?>
567 ><?php _e( 'Goal Achieved', 'give' ); ?></option>
568 <option value="goal_in_progress"
569 <?php
570 if ( 'goal_in_progress' === $give_forms_goal_filter ) {
571 echo 'selected';
572 }
573 ?>
574 ><?php _e( 'Goal In Progress', 'give' ); ?></option>
575 <option value="goal_not_set"
576 <?php
577 if ( 'goal_not_set' === $give_forms_goal_filter ) {
578 echo 'selected';
579 }
580 ?>
581 ><?php _e( 'Goal Not Set', 'give' ); ?></option>
582 </select>
583 </div>
584 <div class="give-filter">
585 <?php submit_button( __( 'Apply', 'give' ), 'secondary', '', false ); ?>
586 <?php
587 // Clear active filters button.
588 if ( ! empty( $start_date ) || ! empty( $end_date ) || ! empty( $search ) || ! empty( $give_forms_goal_filter ) ) :
589 ?>
590 <a href="<?php echo admin_url( 'edit.php?post_type=give_forms' ); ?>"
591 class="button give-clear-filters-button"><?php _e( 'Clear Filters', 'give' ); ?></a>
592 <?php endif; ?>
593 </div>
594 </div>
595 <?php
596 }
597
598 add_action( 'manage_posts_extra_tablenav', 'give_forms_advanced_filter', 10, 1 );
599