PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.0.3
GiveWP – Donation Plugin and Fundraising Platform v2.0.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-metabox-form-data.php 8 years ago dashboard-columns.php 8 years ago metabox.php 9 years ago
dashboard-columns.php
355 lines
1 <?php
2 /**
3 * Dashboard Columns
4 *
5 * @package GIVE
6 * @subpackage Admin/Downloads
7 * @copyright Copyright (c) 2016, WordImpress
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 echo '<input type="hidden" class="formprice-' . $post_id . '" value="' . 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 echo give_goal( $post_id, false );
90 } else {
91 esc_html_e( 'No Goal Set', 'give' );
92 }
93
94 echo '<input type="hidden" class="formgoal-' . $post_id . '" value="' . give_get_form_goal( $post_id ) . '" />';
95 break;
96 case 'donations':
97 if ( current_user_can( 'view_give_form_stats', $post_id ) ) {
98 echo '<a href="' . esc_url( admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&form_id=' . $post_id ) ) . '">';
99 echo give_get_form_sales_stats( $post_id );
100 echo '</a>';
101 } else {
102 echo '-';
103 }
104 break;
105 case 'earnings':
106 if ( current_user_can( 'view_give_form_stats', $post_id ) ) {
107 echo '<a href="' . esc_url( admin_url( 'edit.php?post_type=give_forms&page=give-reports&tab=forms&form-id=' . $post_id ) ) . '">';
108 echo give_currency_filter( give_format_amount( give_get_form_earnings_stats( $post_id ), array( 'sanitize' => false ) ) );
109 echo '</a>';
110 } else {
111 echo '-';
112 }
113 break;
114 case 'shortcode':
115 echo '<input onclick="this.setSelectionRange(0, this.value.length)" type="text" class="shortcode-input" readonly="" value="[give_form id=&#34;' . absint( $post_id ) . '&#34;]">';
116 break;
117 }// End switch().
118 }// End if().
119 }
120
121 add_action( 'manage_posts_custom_column', 'give_render_form_columns', 10, 2 );
122
123 /**
124 * Registers the sortable columns in the list table
125 *
126 * @since 1.0
127 *
128 * @param array $columns Array of the columns
129 *
130 * @return array $columns Array of sortable columns
131 */
132 function give_sortable_form_columns( $columns ) {
133 $columns['price'] = 'amount';
134 $columns['sales'] = 'sales';
135 $columns['earnings'] = 'earnings';
136 $columns['goal'] = 'goal';
137 $columns['donations'] = 'donations';
138
139 return $columns;
140 }
141
142 add_filter( 'manage_edit-give_forms_sortable_columns', 'give_sortable_form_columns' );
143
144 /**
145 * Sorts Columns in the Forms List Table
146 *
147 * @since 1.0
148 *
149 * @param array $vars Array of all the sort variables.
150 *
151 * @return array $vars Array of all the sort variables.
152 */
153 function give_sort_forms( $vars ) {
154 // Check if we're viewing the "give_forms" post type.
155 if ( ! isset( $vars['post_type'] ) || ! isset( $vars['orderby'] ) || 'give_forms' !== $vars['post_type'] ) {
156 return $vars;
157 }
158
159 switch ( $vars['orderby'] ) {
160 // Check if 'orderby' is set to "sales".
161 case 'sales':
162 $vars = array_merge(
163 $vars,
164 array(
165 'meta_key' => '_give_form_sales',
166 'orderby' => 'meta_value_num',
167 )
168 );
169 break;
170
171 // Check if "orderby" is set to "earnings".
172 case 'earnings':
173 $vars = array_merge(
174 $vars,
175 array(
176 'meta_key' => '_give_form_earnings',
177 'orderby' => 'meta_value_num',
178 )
179 );
180 break;
181
182 // Check if "orderby" is set to "price/amount".
183 case 'amount':
184 $multi_level_meta_key = ( 'asc' === $vars['order'] ) ? '_give_levels_minimum_amount' : '_give_levels_maximum_amount';
185
186 $vars['orderby'] = 'meta_value_num';
187 $vars['meta_query'] = array(
188 'relation' => 'OR',
189 array(
190 'key' => $multi_level_meta_key,
191 'type' => 'NUMERIC',
192 ),
193 array(
194 'key' => '_give_set_price',
195 'type' => 'NUMERIC',
196 )
197 );
198
199 break;
200
201 // Check if "orderby" is set to "goal".
202 case 'goal':
203 $vars = array_merge(
204 $vars,
205 array(
206 'meta_key' => '_give_set_goal',
207 'orderby' => 'meta_value_num',
208 )
209 );
210 break;
211
212 // Check if "orderby" is set to "donations".
213 case 'donations':
214 $vars = array_merge(
215 $vars,
216 array(
217 'meta_key' => '_give_form_sales',
218 'orderby' => 'meta_value_num',
219 )
220 );
221 break;
222 }// End switch().
223
224 return $vars;
225 }
226
227 /**
228 * Sets restrictions on author of Forms List Table
229 *
230 * @since 1.0
231 *
232 * @param array $vars Array of all sort variables.
233 *
234 * @return array Array of all sort variables.
235 */
236 function give_filter_forms( $vars ) {
237 if ( isset( $vars['post_type'] ) && 'give_forms' == $vars['post_type'] ) {
238
239 // If an author ID was passed, use it
240 if ( isset( $_REQUEST['author'] ) && ! current_user_can( 'view_give_reports' ) ) {
241
242 $author_id = $_REQUEST['author'];
243 if ( (int) $author_id !== get_current_user_id() ) {
244 wp_die( esc_html__( 'You do not have permission to view this data.', 'give' ), esc_html__( 'Error', 'give' ), array(
245 'response' => 403,
246 ) );
247 }
248 $vars = array_merge(
249 $vars,
250 array(
251 'author' => get_current_user_id(),
252 )
253 );
254
255 }
256 }
257
258 return $vars;
259 }
260
261 /**
262 * Form Load
263 *
264 * Sorts the form columns.
265 *
266 * @since 1.0
267 * @return void
268 */
269 function give_forms_load() {
270 add_filter( 'request', 'give_sort_forms' );
271 add_filter( 'request', 'give_filter_forms' );
272 }
273
274 add_action( 'load-edit.php', 'give_forms_load', 9999 );
275
276 /**
277 * Remove Forms Month Filter
278 *
279 * Removes the default drop down filter for forms by date.
280 *
281 * @since 1.0
282 *
283 * @param array $dates The preset array of dates.
284 *
285 * @global $typenow The post type we are viewing.
286 * @return array Empty array disables the dropdown.
287 */
288 function give_remove_month_filter( $dates ) {
289 global $typenow;
290
291 if ( $typenow == 'give_forms' ) {
292 $dates = array();
293 }
294
295 return $dates;
296 }
297
298 add_filter( 'months_dropdown_results', 'give_remove_month_filter', 99 );
299
300 /**
301 * Updates price when saving post
302 *
303 * @since 1.0
304 *
305 * @param int $post_id Download (Post) ID
306 *
307 * @return int|null
308 */
309 function give_price_save_quick_edit( $post_id ) {
310 if ( ! isset( $_POST['post_type'] ) || 'give_forms' !== $_POST['post_type'] ) {
311 return;
312 }
313 if ( ! current_user_can( 'edit_post', $post_id ) ) {
314 return $post_id;
315 }
316 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
317 return $post_id;
318 }
319
320 if ( isset( $_REQUEST['_give_regprice'] ) ) {
321 give_update_meta( $post_id, '_give_set_price', give_sanitize_amount_for_db( strip_tags( stripslashes( $_REQUEST['_give_regprice'] ) ) ) );
322 }
323 }
324
325 add_action( 'save_post', 'give_price_save_quick_edit' );
326
327 /**
328 * Process bulk edit actions via AJAX
329 *
330 * @since 1.0
331 * @return void
332 */
333 function give_save_bulk_edit() {
334
335 $post_ids = ( isset( $_POST['post_ids'] ) && ! empty( $_POST['post_ids'] ) ) ? $_POST['post_ids'] : array();
336
337 if ( ! empty( $post_ids ) && is_array( $post_ids ) ) {
338 $price = isset( $_POST['price'] ) ? strip_tags( stripslashes( $_POST['price'] ) ) : 0;
339 foreach ( $post_ids as $post_id ) {
340
341 if ( ! current_user_can( 'edit_post', $post_id ) ) {
342 continue;
343 }
344
345 if ( ! empty( $price ) ) {
346 give_update_meta( $post_id, '_give_set_price', give_sanitize_amount_for_db( $price ) );
347 }
348 }
349 }
350
351 die();
352 }
353
354 add_action( 'wp_ajax_give_save_bulk_edit', 'give_save_bulk_edit' );
355