@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | * @since 1.0 |
21 | 21 | * @return void |
22 | 22 | */ |
23 | -add_action( 'give_manual_cc_form', '__return_false' ); |
|
23 | +add_action('give_manual_cc_form', '__return_false'); |
|
24 | 24 | |
25 | 25 | /** |
26 | 26 | * Processes the purchase data and uses the Manual Payment gateway to record |
@@ -32,17 +32,17 @@ discard block |
||
32 | 32 | * |
33 | 33 | * @return void |
34 | 34 | */ |
35 | -function give_manual_payment( $purchase_data ) { |
|
35 | +function give_manual_payment($purchase_data) { |
|
36 | 36 | |
37 | - if ( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'give-gateway' ) ) { |
|
38 | - wp_die( __( 'Nonce verification has failed', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
37 | + if ( ! wp_verify_nonce($purchase_data['gateway_nonce'], 'give-gateway')) { |
|
38 | + wp_die(__('Nonce verification has failed', 'give'), __('Error', 'give'), array('response' => 403)); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | //Create payment_data array |
42 | 42 | $payment_data = array( |
43 | 43 | 'price' => $purchase_data['price'], |
44 | 44 | 'give_form_title' => $purchase_data['post_data']['give-form-title'], |
45 | - 'give_form_id' => intval( $purchase_data['post_data']['give-form-id'] ), |
|
45 | + 'give_form_id' => intval($purchase_data['post_data']['give-form-id']), |
|
46 | 46 | 'give_price_id' => $purchase_data['post_data']['give-price-id'], |
47 | 47 | 'date' => $purchase_data['date'], |
48 | 48 | 'user_email' => $purchase_data['user_email'], |
@@ -52,16 +52,16 @@ discard block |
||
52 | 52 | 'status' => 'pending' |
53 | 53 | ); |
54 | 54 | // Record the pending payment |
55 | - $payment = give_insert_payment( $payment_data ); |
|
55 | + $payment = give_insert_payment($payment_data); |
|
56 | 56 | |
57 | - if ( $payment ) { |
|
58 | - give_update_payment_status( $payment, 'publish' ); |
|
57 | + if ($payment) { |
|
58 | + give_update_payment_status($payment, 'publish'); |
|
59 | 59 | give_send_to_success_page(); |
60 | 60 | } else { |
61 | - give_record_gateway_error( __( 'Payment Error', 'give' ), sprintf( __( 'The payment creation failed while processing a manual (free or test) donation. Payment data: %s', 'give' ), json_encode( $payment_data ) ), $payment ); |
|
61 | + give_record_gateway_error(__('Payment Error', 'give'), sprintf(__('The payment creation failed while processing a manual (free or test) donation. Payment data: %s', 'give'), json_encode($payment_data)), $payment); |
|
62 | 62 | // If errors are present, send the user back to the purchase page so they can be corrected |
63 | - give_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['give-gateway'] ); |
|
63 | + give_send_back_to_checkout('?payment-mode='.$purchase_data['post_data']['give-gateway']); |
|
64 | 64 | } |
65 | 65 | } |
66 | 66 | |
67 | -add_action( 'give_gateway_manual', 'give_manual_payment' ); |
|
67 | +add_action('give_gateway_manual', 'give_manual_payment'); |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | */ |
13 | 13 | |
14 | 14 | // Exit if accessed directly |
15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
15 | +if ( ! defined('ABSPATH')) { |
|
16 | 16 | exit; |
17 | 17 | } |
18 | 18 | |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * |
34 | 34 | * @return string $output Give forms dropdown |
35 | 35 | */ |
36 | - public function forms_dropdown( $args = array() ) { |
|
36 | + public function forms_dropdown($args = array()) { |
|
37 | 37 | |
38 | 38 | $defaults = array( |
39 | 39 | 'name' => 'forms', |
@@ -43,43 +43,43 @@ discard block |
||
43 | 43 | 'selected' => 0, |
44 | 44 | 'chosen' => false, |
45 | 45 | 'number' => 30, |
46 | - 'placeholder' => sprintf( __( 'Select a %s', 'give' ), give_get_forms_label_singular() ) |
|
46 | + 'placeholder' => sprintf(__('Select a %s', 'give'), give_get_forms_label_singular()) |
|
47 | 47 | ); |
48 | 48 | |
49 | - $args = wp_parse_args( $args, $defaults ); |
|
49 | + $args = wp_parse_args($args, $defaults); |
|
50 | 50 | |
51 | - $forms = get_posts( array( |
|
51 | + $forms = get_posts(array( |
|
52 | 52 | 'post_type' => 'give_forms', |
53 | 53 | 'orderby' => 'title', |
54 | 54 | 'order' => 'ASC', |
55 | 55 | 'posts_per_page' => $args['number'] |
56 | - ) ); |
|
56 | + )); |
|
57 | 57 | |
58 | 58 | $options = array(); |
59 | 59 | |
60 | - if ( $forms ) { |
|
61 | - $options[0] = sprintf( __( 'Select a %s', 'give' ), give_get_forms_label_singular() ); |
|
62 | - foreach ( $forms as $form ) { |
|
63 | - $options[ absint( $form->ID ) ] = esc_html( $form->post_title ); |
|
60 | + if ($forms) { |
|
61 | + $options[0] = sprintf(__('Select a %s', 'give'), give_get_forms_label_singular()); |
|
62 | + foreach ($forms as $form) { |
|
63 | + $options[absint($form->ID)] = esc_html($form->post_title); |
|
64 | 64 | } |
65 | 65 | } else { |
66 | - $options[0] = __( 'No Give Forms Found', 'give' ); |
|
66 | + $options[0] = __('No Give Forms Found', 'give'); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | // This ensures that any selected forms are included in the drop down |
70 | - if ( is_array( $args['selected'] ) ) { |
|
71 | - foreach ( $args['selected'] as $item ) { |
|
72 | - if ( ! in_array( $item, $options ) ) { |
|
73 | - $options[ $item ] = get_the_title( $item ); |
|
70 | + if (is_array($args['selected'])) { |
|
71 | + foreach ($args['selected'] as $item) { |
|
72 | + if ( ! in_array($item, $options)) { |
|
73 | + $options[$item] = get_the_title($item); |
|
74 | 74 | } |
75 | 75 | } |
76 | - } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) { |
|
77 | - if ( ! in_array( $args['selected'], $options ) ) { |
|
78 | - $options[ $args['selected'] ] = get_the_title( $args['selected'] ); |
|
76 | + } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) { |
|
77 | + if ( ! in_array($args['selected'], $options)) { |
|
78 | + $options[$args['selected']] = get_the_title($args['selected']); |
|
79 | 79 | } |
80 | 80 | } |
81 | 81 | |
82 | - $output = $this->select( array( |
|
82 | + $output = $this->select(array( |
|
83 | 83 | 'name' => $args['name'], |
84 | 84 | 'selected' => $args['selected'], |
85 | 85 | 'id' => $args['id'], |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | 'placeholder' => $args['placeholder'], |
91 | 91 | 'show_option_all' => false, |
92 | 92 | 'show_option_none' => false |
93 | - ) ); |
|
93 | + )); |
|
94 | 94 | |
95 | 95 | return $output; |
96 | 96 | } |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * |
106 | 106 | * @return string $output Donor dropdown |
107 | 107 | */ |
108 | - public function donor_dropdown( $args = array() ) { |
|
108 | + public function donor_dropdown($args = array()) { |
|
109 | 109 | |
110 | 110 | $defaults = array( |
111 | 111 | 'name' => 'customers', |
@@ -114,38 +114,38 @@ discard block |
||
114 | 114 | 'multiple' => false, |
115 | 115 | 'selected' => 0, |
116 | 116 | 'chosen' => true, |
117 | - 'placeholder' => __( 'Select a Donor', 'give' ), |
|
117 | + 'placeholder' => __('Select a Donor', 'give'), |
|
118 | 118 | 'number' => 30 |
119 | 119 | ); |
120 | 120 | |
121 | - $args = wp_parse_args( $args, $defaults ); |
|
121 | + $args = wp_parse_args($args, $defaults); |
|
122 | 122 | |
123 | - $customers = Give()->customers->get_customers( array( |
|
123 | + $customers = Give()->customers->get_customers(array( |
|
124 | 124 | 'number' => $args['number'] |
125 | - ) ); |
|
125 | + )); |
|
126 | 126 | |
127 | 127 | $options = array(); |
128 | 128 | |
129 | - if ( $customers ) { |
|
130 | - $options[0] = __( 'No donor attached', 'give' ); |
|
131 | - foreach ( $customers as $customer ) { |
|
132 | - $options[ absint( $customer->id ) ] = esc_html( $customer->name . ' (' . $customer->email . ')' ); |
|
129 | + if ($customers) { |
|
130 | + $options[0] = __('No donor attached', 'give'); |
|
131 | + foreach ($customers as $customer) { |
|
132 | + $options[absint($customer->id)] = esc_html($customer->name.' ('.$customer->email.')'); |
|
133 | 133 | } |
134 | 134 | } else { |
135 | - $options[0] = __( 'No donors found', 'give' ); |
|
135 | + $options[0] = __('No donors found', 'give'); |
|
136 | 136 | } |
137 | 137 | |
138 | - if ( ! empty( $args['selected'] ) ) { |
|
138 | + if ( ! empty($args['selected'])) { |
|
139 | 139 | |
140 | 140 | // If a selected customer has been specified, we need to ensure it's in the initial list of customers displayed |
141 | 141 | |
142 | - if ( ! array_key_exists( $args['selected'], $options ) ) { |
|
142 | + if ( ! array_key_exists($args['selected'], $options)) { |
|
143 | 143 | |
144 | - $customer = new Give_Customer( $args['selected'] ); |
|
144 | + $customer = new Give_Customer($args['selected']); |
|
145 | 145 | |
146 | - if ( $customer ) { |
|
146 | + if ($customer) { |
|
147 | 147 | |
148 | - $options[ absint( $args['selected'] ) ] = esc_html( $customer->name . ' (' . $customer->email . ')' ); |
|
148 | + $options[absint($args['selected'])] = esc_html($customer->name.' ('.$customer->email.')'); |
|
149 | 149 | |
150 | 150 | } |
151 | 151 | |
@@ -153,17 +153,17 @@ discard block |
||
153 | 153 | |
154 | 154 | } |
155 | 155 | |
156 | - $output = $this->select( array( |
|
156 | + $output = $this->select(array( |
|
157 | 157 | 'name' => $args['name'], |
158 | 158 | 'selected' => $args['selected'], |
159 | 159 | 'id' => $args['id'], |
160 | - 'class' => $args['class'] . ' give-customer-select', |
|
160 | + 'class' => $args['class'].' give-customer-select', |
|
161 | 161 | 'options' => $options, |
162 | 162 | 'multiple' => $args['multiple'], |
163 | 163 | 'chosen' => $args['chosen'], |
164 | 164 | 'show_option_all' => false, |
165 | 165 | 'show_option_none' => false |
166 | - ) ); |
|
166 | + )); |
|
167 | 167 | |
168 | 168 | return $output; |
169 | 169 | } |
@@ -180,21 +180,21 @@ discard block |
||
180 | 180 | * |
181 | 181 | * @return string $output Category dropdown |
182 | 182 | */ |
183 | - public function category_dropdown( $name = 'give_forms_categories', $selected = 0 ) { |
|
184 | - $categories = get_terms( 'give_forms_category', apply_filters( 'give_forms_category_dropdown', array() ) ); |
|
183 | + public function category_dropdown($name = 'give_forms_categories', $selected = 0) { |
|
184 | + $categories = get_terms('give_forms_category', apply_filters('give_forms_category_dropdown', array())); |
|
185 | 185 | $options = array(); |
186 | 186 | |
187 | - foreach ( $categories as $category ) { |
|
188 | - $options[ absint( $category->term_id ) ] = esc_html( $category->name ); |
|
187 | + foreach ($categories as $category) { |
|
188 | + $options[absint($category->term_id)] = esc_html($category->name); |
|
189 | 189 | } |
190 | 190 | |
191 | - $output = $this->select( array( |
|
191 | + $output = $this->select(array( |
|
192 | 192 | 'name' => $name, |
193 | 193 | 'selected' => $selected, |
194 | 194 | 'options' => $options, |
195 | - 'show_option_all' => __( 'All Categories', 'give' ), |
|
195 | + 'show_option_all' => __('All Categories', 'give'), |
|
196 | 196 | 'show_option_none' => false |
197 | - ) ); |
|
197 | + )); |
|
198 | 198 | |
199 | 199 | return $output; |
200 | 200 | } |
@@ -212,25 +212,25 @@ discard block |
||
212 | 212 | * |
213 | 213 | * @return string $output Year dropdown |
214 | 214 | */ |
215 | - public function year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) { |
|
216 | - $current = date( 'Y' ); |
|
217 | - $start_year = $current - absint( $years_before ); |
|
218 | - $end_year = $current + absint( $years_after ); |
|
219 | - $selected = empty( $selected ) ? date( 'Y' ) : $selected; |
|
215 | + public function year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) { |
|
216 | + $current = date('Y'); |
|
217 | + $start_year = $current - absint($years_before); |
|
218 | + $end_year = $current + absint($years_after); |
|
219 | + $selected = empty($selected) ? date('Y') : $selected; |
|
220 | 220 | $options = array(); |
221 | 221 | |
222 | - while ( $start_year <= $end_year ) { |
|
223 | - $options[ absint( $start_year ) ] = $start_year; |
|
224 | - $start_year ++; |
|
222 | + while ($start_year <= $end_year) { |
|
223 | + $options[absint($start_year)] = $start_year; |
|
224 | + $start_year++; |
|
225 | 225 | } |
226 | 226 | |
227 | - $output = $this->select( array( |
|
227 | + $output = $this->select(array( |
|
228 | 228 | 'name' => $name, |
229 | 229 | 'selected' => $selected, |
230 | 230 | 'options' => $options, |
231 | 231 | 'show_option_all' => false, |
232 | 232 | 'show_option_none' => false |
233 | - ) ); |
|
233 | + )); |
|
234 | 234 | |
235 | 235 | return $output; |
236 | 236 | } |
@@ -247,23 +247,23 @@ discard block |
||
247 | 247 | * |
248 | 248 | * @return string $output Month dropdown |
249 | 249 | */ |
250 | - public function month_dropdown( $name = 'month', $selected = 0 ) { |
|
250 | + public function month_dropdown($name = 'month', $selected = 0) { |
|
251 | 251 | $month = 1; |
252 | 252 | $options = array(); |
253 | - $selected = empty( $selected ) ? date( 'n' ) : $selected; |
|
253 | + $selected = empty($selected) ? date('n') : $selected; |
|
254 | 254 | |
255 | - while ( $month <= 12 ) { |
|
256 | - $options[ absint( $month ) ] = give_month_num_to_name( $month ); |
|
257 | - $month ++; |
|
255 | + while ($month <= 12) { |
|
256 | + $options[absint($month)] = give_month_num_to_name($month); |
|
257 | + $month++; |
|
258 | 258 | } |
259 | 259 | |
260 | - $output = $this->select( array( |
|
260 | + $output = $this->select(array( |
|
261 | 261 | 'name' => $name, |
262 | 262 | 'selected' => $selected, |
263 | 263 | 'options' => $options, |
264 | 264 | 'show_option_all' => false, |
265 | 265 | 'show_option_none' => false |
266 | - ) ); |
|
266 | + )); |
|
267 | 267 | |
268 | 268 | return $output; |
269 | 269 | } |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | * |
278 | 278 | * @return string |
279 | 279 | */ |
280 | - public function select( $args = array() ) { |
|
280 | + public function select($args = array()) { |
|
281 | 281 | $defaults = array( |
282 | 282 | 'options' => array(), |
283 | 283 | 'name' => null, |
@@ -287,60 +287,60 @@ discard block |
||
287 | 287 | 'chosen' => false, |
288 | 288 | 'placeholder' => null, |
289 | 289 | 'multiple' => false, |
290 | - 'show_option_all' => _x( 'All', 'all dropdown items', 'give' ), |
|
291 | - 'show_option_none' => _x( 'None', 'no dropdown items', 'give' ) |
|
290 | + 'show_option_all' => _x('All', 'all dropdown items', 'give'), |
|
291 | + 'show_option_none' => _x('None', 'no dropdown items', 'give') |
|
292 | 292 | ); |
293 | 293 | |
294 | - $args = wp_parse_args( $args, $defaults ); |
|
294 | + $args = wp_parse_args($args, $defaults); |
|
295 | 295 | |
296 | 296 | |
297 | - if ( $args['multiple'] ) { |
|
297 | + if ($args['multiple']) { |
|
298 | 298 | $multiple = ' MULTIPLE'; |
299 | 299 | } else { |
300 | 300 | $multiple = ''; |
301 | 301 | } |
302 | 302 | |
303 | - if ( $args['chosen'] ) { |
|
303 | + if ($args['chosen']) { |
|
304 | 304 | $args['class'] .= ' give-select-chosen'; |
305 | 305 | } |
306 | 306 | |
307 | - if ( $args['placeholder'] ) { |
|
307 | + if ($args['placeholder']) { |
|
308 | 308 | $placeholder = $args['placeholder']; |
309 | 309 | } else { |
310 | 310 | $placeholder = ''; |
311 | 311 | } |
312 | 312 | |
313 | - $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( sanitize_key( str_replace( '-', '_', $args['id'] ) ) ) . '" class="give-select ' . esc_attr( $args['class'] ) . '"' . $multiple . ' data-placeholder="' . $placeholder . '">'; |
|
313 | + $output = '<select name="'.esc_attr($args['name']).'" id="'.esc_attr(sanitize_key(str_replace('-', '_', $args['id']))).'" class="give-select '.esc_attr($args['class']).'"'.$multiple.' data-placeholder="'.$placeholder.'">'; |
|
314 | 314 | |
315 | - if ( $args['show_option_all'] ) { |
|
316 | - if ( $args['multiple'] ) { |
|
317 | - $selected = selected( true, in_array( 0, $args['selected'] ), false ); |
|
315 | + if ($args['show_option_all']) { |
|
316 | + if ($args['multiple']) { |
|
317 | + $selected = selected(true, in_array(0, $args['selected']), false); |
|
318 | 318 | } else { |
319 | - $selected = selected( $args['selected'], 0, false ); |
|
319 | + $selected = selected($args['selected'], 0, false); |
|
320 | 320 | } |
321 | - $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>'; |
|
321 | + $output .= '<option value="all"'.$selected.'>'.esc_html($args['show_option_all']).'</option>'; |
|
322 | 322 | } |
323 | 323 | |
324 | - if ( ! empty( $args['options'] ) ) { |
|
324 | + if ( ! empty($args['options'])) { |
|
325 | 325 | |
326 | - if ( $args['show_option_none'] ) { |
|
327 | - if ( $args['multiple'] ) { |
|
328 | - $selected = selected( true, in_array( - 1, $args['selected'] ), false ); |
|
326 | + if ($args['show_option_none']) { |
|
327 | + if ($args['multiple']) { |
|
328 | + $selected = selected(true, in_array( -1, $args['selected'] ), false); |
|
329 | 329 | } else { |
330 | - $selected = selected( $args['selected'], - 1, false ); |
|
330 | + $selected = selected($args['selected'], - 1, false); |
|
331 | 331 | } |
332 | - $output .= '<option value="-1"' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>'; |
|
332 | + $output .= '<option value="-1"'.$selected.'>'.esc_html($args['show_option_none']).'</option>'; |
|
333 | 333 | } |
334 | 334 | |
335 | - foreach ( $args['options'] as $key => $option ) { |
|
335 | + foreach ($args['options'] as $key => $option) { |
|
336 | 336 | |
337 | - if ( $args['multiple'] && is_array( $args['selected'] ) ) { |
|
338 | - $selected = selected( true, in_array( $key, $args['selected'] ), false ); |
|
337 | + if ($args['multiple'] && is_array($args['selected'])) { |
|
338 | + $selected = selected(true, in_array($key, $args['selected']), false); |
|
339 | 339 | } else { |
340 | - $selected = selected( $args['selected'], $key, false ); |
|
340 | + $selected = selected($args['selected'], $key, false); |
|
341 | 341 | } |
342 | 342 | |
343 | - $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>'; |
|
343 | + $output .= '<option value="'.esc_attr($key).'"'.$selected.'>'.esc_html($option).'</option>'; |
|
344 | 344 | } |
345 | 345 | } |
346 | 346 | |
@@ -358,7 +358,7 @@ discard block |
||
358 | 358 | * |
359 | 359 | * @return string |
360 | 360 | */ |
361 | - public function checkbox( $args = array() ) { |
|
361 | + public function checkbox($args = array()) { |
|
362 | 362 | $defaults = array( |
363 | 363 | 'name' => null, |
364 | 364 | 'current' => null, |
@@ -369,16 +369,16 @@ discard block |
||
369 | 369 | ) |
370 | 370 | ); |
371 | 371 | |
372 | - $args = wp_parse_args( $args, $defaults ); |
|
372 | + $args = wp_parse_args($args, $defaults); |
|
373 | 373 | |
374 | 374 | $options = ''; |
375 | - if ( ! empty( $args['options']['disabled'] ) ) { |
|
375 | + if ( ! empty($args['options']['disabled'])) { |
|
376 | 376 | $options .= ' disabled="disabled"'; |
377 | - } elseif ( ! empty( $args['options']['readonly'] ) ) { |
|
377 | + } elseif ( ! empty($args['options']['readonly'])) { |
|
378 | 378 | $options .= ' readonly'; |
379 | 379 | } |
380 | 380 | |
381 | - $output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $args['class'] . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />'; |
|
381 | + $output = '<input type="checkbox"'.$options.' name="'.esc_attr($args['name']).'" id="'.esc_attr($args['name']).'" class="'.$args['class'].' '.esc_attr($args['name']).'" '.checked(1, $args['current'], false).' />'; |
|
382 | 382 | |
383 | 383 | return $output; |
384 | 384 | } |
@@ -392,22 +392,22 @@ discard block |
||
392 | 392 | * |
393 | 393 | * @return string Text field |
394 | 394 | */ |
395 | - public function text( $args = array() ) { |
|
395 | + public function text($args = array()) { |
|
396 | 396 | // Backwards compatabliity |
397 | - if ( func_num_args() > 1 ) { |
|
397 | + if (func_num_args() > 1) { |
|
398 | 398 | $args = func_get_args(); |
399 | 399 | |
400 | 400 | $name = $args[0]; |
401 | - $value = isset( $args[1] ) ? $args[1] : ''; |
|
402 | - $label = isset( $args[2] ) ? $args[2] : ''; |
|
403 | - $desc = isset( $args[3] ) ? $args[3] : ''; |
|
401 | + $value = isset($args[1]) ? $args[1] : ''; |
|
402 | + $label = isset($args[2]) ? $args[2] : ''; |
|
403 | + $desc = isset($args[3]) ? $args[3] : ''; |
|
404 | 404 | } |
405 | 405 | |
406 | 406 | $defaults = array( |
407 | - 'name' => isset( $name ) ? $name : 'text', |
|
408 | - 'value' => isset( $value ) ? $value : null, |
|
409 | - 'label' => isset( $label ) ? $label : null, |
|
410 | - 'desc' => isset( $desc ) ? $desc : null, |
|
407 | + 'name' => isset($name) ? $name : 'text', |
|
408 | + 'value' => isset($value) ? $value : null, |
|
409 | + 'label' => isset($label) ? $label : null, |
|
410 | + 'desc' => isset($desc) ? $desc : null, |
|
411 | 411 | 'placeholder' => '', |
412 | 412 | 'class' => 'regular-text', |
413 | 413 | 'disabled' => false, |
@@ -415,29 +415,29 @@ discard block |
||
415 | 415 | 'data' => false |
416 | 416 | ); |
417 | 417 | |
418 | - $args = wp_parse_args( $args, $defaults ); |
|
418 | + $args = wp_parse_args($args, $defaults); |
|
419 | 419 | |
420 | 420 | $disabled = ''; |
421 | - if ( $args['disabled'] ) { |
|
421 | + if ($args['disabled']) { |
|
422 | 422 | $disabled = ' disabled="disabled"'; |
423 | 423 | } |
424 | 424 | |
425 | 425 | $data = ''; |
426 | - if ( ! empty( $args['data'] ) ) { |
|
427 | - foreach ( $args['data'] as $key => $value ) { |
|
428 | - $data .= 'data-' . $key . '="' . $value . '" '; |
|
426 | + if ( ! empty($args['data'])) { |
|
427 | + foreach ($args['data'] as $key => $value) { |
|
428 | + $data .= 'data-'.$key.'="'.$value.'" '; |
|
429 | 429 | } |
430 | 430 | } |
431 | 431 | |
432 | - $output = '<span id="give-' . sanitize_key( $args['name'] ) . '-wrap">'; |
|
432 | + $output = '<span id="give-'.sanitize_key($args['name']).'-wrap">'; |
|
433 | 433 | |
434 | - $output .= '<label class="give-label" for="give-' . sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
434 | + $output .= '<label class="give-label" for="give-'.sanitize_key($args['name']).'">'.esc_html($args['label']).'</label>'; |
|
435 | 435 | |
436 | - if ( ! empty( $args['desc'] ) ) { |
|
437 | - $output .= '<span class="give-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
436 | + if ( ! empty($args['desc'])) { |
|
437 | + $output .= '<span class="give-description">'.esc_html($args['desc']).'</span>'; |
|
438 | 438 | } |
439 | 439 | |
440 | - $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" autocomplete="' . esc_attr( $args['autocomplete'] ) . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $args['class'] . '" ' . $data . '' . $disabled . '/>'; |
|
440 | + $output .= '<input type="text" name="'.esc_attr($args['name']).'" id="'.esc_attr($args['name']).'" autocomplete="'.esc_attr($args['autocomplete']).'" value="'.esc_attr($args['value']).'" placeholder="'.esc_attr($args['placeholder']).'" class="'.$args['class'].'" '.$data.''.$disabled.'/>'; |
|
441 | 441 | |
442 | 442 | $output .= '</span>'; |
443 | 443 | |
@@ -453,15 +453,15 @@ discard block |
||
453 | 453 | * |
454 | 454 | * @return string Datepicker field |
455 | 455 | */ |
456 | - public function date_field( $args = array() ) { |
|
456 | + public function date_field($args = array()) { |
|
457 | 457 | |
458 | - if ( empty( $args['class'] ) ) { |
|
458 | + if (empty($args['class'])) { |
|
459 | 459 | $args['class'] = 'give_datepicker'; |
460 | - } elseif ( ! strpos( $args['class'], 'give_datepicker' ) ) { |
|
460 | + } elseif ( ! strpos($args['class'], 'give_datepicker')) { |
|
461 | 461 | $args['class'] .= ' give_datepicker'; |
462 | 462 | } |
463 | 463 | |
464 | - return $this->text( $args ); |
|
464 | + return $this->text($args); |
|
465 | 465 | } |
466 | 466 | |
467 | 467 | |
@@ -474,7 +474,7 @@ discard block |
||
474 | 474 | * |
475 | 475 | * @return string textarea |
476 | 476 | */ |
477 | - public function textarea( $args = array() ) { |
|
477 | + public function textarea($args = array()) { |
|
478 | 478 | $defaults = array( |
479 | 479 | 'name' => 'textarea', |
480 | 480 | 'value' => null, |
@@ -484,21 +484,21 @@ discard block |
||
484 | 484 | 'disabled' => false |
485 | 485 | ); |
486 | 486 | |
487 | - $args = wp_parse_args( $args, $defaults ); |
|
487 | + $args = wp_parse_args($args, $defaults); |
|
488 | 488 | |
489 | 489 | $disabled = ''; |
490 | - if ( $args['disabled'] ) { |
|
490 | + if ($args['disabled']) { |
|
491 | 491 | $disabled = ' disabled="disabled"'; |
492 | 492 | } |
493 | 493 | |
494 | - $output = '<span id="give-' . sanitize_key( $args['name'] ) . '-wrap">'; |
|
494 | + $output = '<span id="give-'.sanitize_key($args['name']).'-wrap">'; |
|
495 | 495 | |
496 | - $output .= '<label class="give-label" for="give-' . sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
496 | + $output .= '<label class="give-label" for="give-'.sanitize_key($args['name']).'">'.esc_html($args['label']).'</label>'; |
|
497 | 497 | |
498 | - $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $args['class'] . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>'; |
|
498 | + $output .= '<textarea name="'.esc_attr($args['name']).'" id="'.esc_attr($args['name']).'" class="'.$args['class'].'"'.$disabled.'>'.esc_attr($args['value']).'</textarea>'; |
|
499 | 499 | |
500 | - if ( ! empty( $args['desc'] ) ) { |
|
501 | - $output .= '<span class="give-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
500 | + if ( ! empty($args['desc'])) { |
|
501 | + $output .= '<span class="give-description">'.esc_html($args['desc']).'</span>'; |
|
502 | 502 | } |
503 | 503 | |
504 | 504 | $output .= '</span>'; |
@@ -515,12 +515,12 @@ discard block |
||
515 | 515 | * |
516 | 516 | * @return string text field with ajax search |
517 | 517 | */ |
518 | - public function ajax_user_search( $args = array() ) { |
|
518 | + public function ajax_user_search($args = array()) { |
|
519 | 519 | |
520 | 520 | $defaults = array( |
521 | 521 | 'name' => 'user_id', |
522 | 522 | 'value' => null, |
523 | - 'placeholder' => __( 'Enter username', 'give' ), |
|
523 | + 'placeholder' => __('Enter username', 'give'), |
|
524 | 524 | 'label' => null, |
525 | 525 | 'desc' => null, |
526 | 526 | 'class' => '', |
@@ -529,13 +529,13 @@ discard block |
||
529 | 529 | 'data' => false |
530 | 530 | ); |
531 | 531 | |
532 | - $args = wp_parse_args( $args, $defaults ); |
|
532 | + $args = wp_parse_args($args, $defaults); |
|
533 | 533 | |
534 | - $args['class'] = 'give-ajax-user-search ' . $args['class']; |
|
534 | + $args['class'] = 'give-ajax-user-search '.$args['class']; |
|
535 | 535 | |
536 | 536 | $output = '<span class="give_user_search_wrap">'; |
537 | - $output .= $this->text( $args ); |
|
538 | - $output .= '<span class="give_user_search_results hidden"><a class="give-ajax-user-cancel" title="' . __( 'Cancel', 'give' ) . '" aria-label="' . __( 'Cancel', 'give' ) . '" href="#">x</a><span></span></span>'; |
|
537 | + $output .= $this->text($args); |
|
538 | + $output .= '<span class="give_user_search_results hidden"><a class="give-ajax-user-cancel" title="'.__('Cancel', 'give').'" aria-label="'.__('Cancel', 'give').'" href="#">x</a><span></span></span>'; |
|
539 | 539 | $output .= '</span>'; |
540 | 540 | |
541 | 541 | return $output; |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | */ |
13 | 13 | |
14 | 14 | // Exit if accessed directly |
15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
15 | +if ( ! defined('ABSPATH')) { |
|
16 | 16 | exit; |
17 | 17 | } |
18 | 18 | |
@@ -139,27 +139,27 @@ discard block |
||
139 | 139 | 'v1' => 'GIVE_API_V1', |
140 | 140 | ); |
141 | 141 | |
142 | - foreach ( $this->get_versions() as $version => $class ) { |
|
143 | - require_once GIVE_PLUGIN_DIR . 'includes/api/class-give-api-' . $version . '.php'; |
|
142 | + foreach ($this->get_versions() as $version => $class) { |
|
143 | + require_once GIVE_PLUGIN_DIR.'includes/api/class-give-api-'.$version.'.php'; |
|
144 | 144 | } |
145 | 145 | |
146 | - add_action( 'init', array( $this, 'add_endpoint' ) ); |
|
147 | - add_action( 'wp', array( $this, 'process_query' ), - 1 ); |
|
148 | - add_filter( 'query_vars', array( $this, 'query_vars' ) ); |
|
149 | - add_action( 'show_user_profile', array( $this, 'user_key_field' ) ); |
|
150 | - add_action( 'edit_user_profile', array( $this, 'user_key_field' ) ); |
|
151 | - add_action( 'personal_options_update', array( $this, 'update_key' ) ); |
|
152 | - add_action( 'edit_user_profile_update', array( $this, 'update_key' ) ); |
|
153 | - add_action( 'give_process_api_key', array( $this, 'process_api_key' ) ); |
|
146 | + add_action('init', array($this, 'add_endpoint')); |
|
147 | + add_action('wp', array($this, 'process_query'), - 1); |
|
148 | + add_filter('query_vars', array($this, 'query_vars')); |
|
149 | + add_action('show_user_profile', array($this, 'user_key_field')); |
|
150 | + add_action('edit_user_profile', array($this, 'user_key_field')); |
|
151 | + add_action('personal_options_update', array($this, 'update_key')); |
|
152 | + add_action('edit_user_profile_update', array($this, 'update_key')); |
|
153 | + add_action('give_process_api_key', array($this, 'process_api_key')); |
|
154 | 154 | |
155 | 155 | // Setup a backwards compatibility check for user API Keys |
156 | - add_filter( 'get_user_metadata', array( $this, 'api_key_backwards_compat' ), 10, 4 ); |
|
156 | + add_filter('get_user_metadata', array($this, 'api_key_backwards_compat'), 10, 4); |
|
157 | 157 | |
158 | 158 | // Determine if JSON_PRETTY_PRINT is available |
159 | - $this->pretty_print = defined( 'JSON_PRETTY_PRINT' ) ? JSON_PRETTY_PRINT : null; |
|
159 | + $this->pretty_print = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : null; |
|
160 | 160 | |
161 | 161 | // Allow API request logging to be turned off |
162 | - $this->log_requests = apply_filters( 'give_api_log_requests', $this->log_requests ); |
|
162 | + $this->log_requests = apply_filters('give_api_log_requests', $this->log_requests); |
|
163 | 163 | |
164 | 164 | // Setup Give_Payment_Stats instance |
165 | 165 | $this->stats = new Give_Payment_Stats; |
@@ -175,8 +175,8 @@ discard block |
||
175 | 175 | * |
176 | 176 | * @since 1.1 |
177 | 177 | */ |
178 | - public function add_endpoint( $rewrite_rules ) { |
|
179 | - add_rewrite_endpoint( 'give-api', EP_ALL ); |
|
178 | + public function add_endpoint($rewrite_rules) { |
|
179 | + add_rewrite_endpoint('give-api', EP_ALL); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | /** |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | * |
190 | 190 | * @return string[] $vars New query vars |
191 | 191 | */ |
192 | - public function query_vars( $vars ) { |
|
192 | + public function query_vars($vars) { |
|
193 | 193 | |
194 | 194 | $vars[] = 'token'; |
195 | 195 | $vars[] = 'key'; |
@@ -240,11 +240,11 @@ discard block |
||
240 | 240 | */ |
241 | 241 | public function get_default_version() { |
242 | 242 | |
243 | - $version = get_option( 'give_default_api_version' ); |
|
243 | + $version = get_option('give_default_api_version'); |
|
244 | 244 | |
245 | - if ( defined( 'GIVE_API_VERSION' ) ) { |
|
245 | + if (defined('GIVE_API_VERSION')) { |
|
246 | 246 | $version = GIVE_API_VERSION; |
247 | - } elseif ( ! $version ) { |
|
247 | + } elseif ( ! $version) { |
|
248 | 248 | $version = 'v1'; |
249 | 249 | } |
250 | 250 | |
@@ -265,14 +265,14 @@ discard block |
||
265 | 265 | |
266 | 266 | $version = $wp_query->query_vars['give-api']; |
267 | 267 | |
268 | - if ( strpos( $version, '/' ) ) { |
|
268 | + if (strpos($version, '/')) { |
|
269 | 269 | |
270 | - $version = explode( '/', $version ); |
|
271 | - $version = strtolower( $version[0] ); |
|
270 | + $version = explode('/', $version); |
|
271 | + $version = strtolower($version[0]); |
|
272 | 272 | |
273 | - $wp_query->query_vars['give-api'] = str_replace( $version . '/', '', $wp_query->query_vars['give-api'] ); |
|
273 | + $wp_query->query_vars['give-api'] = str_replace($version.'/', '', $wp_query->query_vars['give-api']); |
|
274 | 274 | |
275 | - if ( array_key_exists( $version, $this->versions ) ) { |
|
275 | + if (array_key_exists($version, $this->versions)) { |
|
276 | 276 | |
277 | 277 | $this->queried_version = $version; |
278 | 278 | |
@@ -309,32 +309,32 @@ discard block |
||
309 | 309 | $this->override = false; |
310 | 310 | |
311 | 311 | // Make sure we have both user and api key |
312 | - if ( ! empty( $wp_query->query_vars['give-api'] ) && ( $wp_query->query_vars['give-api'] != 'forms' || ! empty( $wp_query->query_vars['token'] ) ) ) { |
|
312 | + if ( ! empty($wp_query->query_vars['give-api']) && ($wp_query->query_vars['give-api'] != 'forms' || ! empty($wp_query->query_vars['token']))) { |
|
313 | 313 | |
314 | - if ( empty( $wp_query->query_vars['token'] ) || empty( $wp_query->query_vars['key'] ) ) { |
|
314 | + if (empty($wp_query->query_vars['token']) || empty($wp_query->query_vars['key'])) { |
|
315 | 315 | $this->missing_auth(); |
316 | 316 | } |
317 | 317 | |
318 | 318 | // Retrieve the user by public API key and ensure they exist |
319 | - if ( ! ( $user = $this->get_user( $wp_query->query_vars['key'] ) ) ) { |
|
319 | + if ( ! ($user = $this->get_user($wp_query->query_vars['key']))) { |
|
320 | 320 | |
321 | 321 | $this->invalid_key(); |
322 | 322 | |
323 | 323 | } else { |
324 | 324 | |
325 | - $token = urldecode( $wp_query->query_vars['token'] ); |
|
326 | - $secret = $this->get_user_secret_key( $user ); |
|
327 | - $public = urldecode( $wp_query->query_vars['key'] ); |
|
325 | + $token = urldecode($wp_query->query_vars['token']); |
|
326 | + $secret = $this->get_user_secret_key($user); |
|
327 | + $public = urldecode($wp_query->query_vars['key']); |
|
328 | 328 | |
329 | - if ( hash_equals( md5( $secret . $public ), $token ) ) { |
|
329 | + if (hash_equals(md5($secret.$public), $token)) { |
|
330 | 330 | $this->is_valid_request = true; |
331 | 331 | } else { |
332 | 332 | $this->invalid_auth(); |
333 | 333 | } |
334 | 334 | } |
335 | - } elseif ( ! empty( $wp_query->query_vars['give-api'] ) && $wp_query->query_vars['give-api'] == 'forms' ) { |
|
335 | + } elseif ( ! empty($wp_query->query_vars['give-api']) && $wp_query->query_vars['give-api'] == 'forms') { |
|
336 | 336 | $this->is_valid_request = true; |
337 | - $wp_query->set( 'key', 'public' ); |
|
337 | + $wp_query->set('key', 'public'); |
|
338 | 338 | } |
339 | 339 | } |
340 | 340 | |
@@ -350,25 +350,25 @@ discard block |
||
350 | 350 | * |
351 | 351 | * @return bool if user ID is found, false otherwise |
352 | 352 | */ |
353 | - public function get_user( $key = '' ) { |
|
353 | + public function get_user($key = '') { |
|
354 | 354 | global $wpdb, $wp_query; |
355 | 355 | |
356 | - if ( empty( $key ) ) { |
|
357 | - $key = urldecode( $wp_query->query_vars['key'] ); |
|
356 | + if (empty($key)) { |
|
357 | + $key = urldecode($wp_query->query_vars['key']); |
|
358 | 358 | } |
359 | 359 | |
360 | - if ( empty( $key ) ) { |
|
360 | + if (empty($key)) { |
|
361 | 361 | return false; |
362 | 362 | } |
363 | 363 | |
364 | - $user = get_transient( md5( 'give_api_user_' . $key ) ); |
|
364 | + $user = get_transient(md5('give_api_user_'.$key)); |
|
365 | 365 | |
366 | - if ( false === $user ) { |
|
367 | - $user = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s LIMIT 1", $key ) ); |
|
368 | - set_transient( md5( 'give_api_user_' . $key ), $user, DAY_IN_SECONDS ); |
|
366 | + if (false === $user) { |
|
367 | + $user = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s LIMIT 1", $key)); |
|
368 | + set_transient(md5('give_api_user_'.$key), $user, DAY_IN_SECONDS); |
|
369 | 369 | } |
370 | 370 | |
371 | - if ( $user != null ) { |
|
371 | + if ($user != null) { |
|
372 | 372 | $this->user_id = $user; |
373 | 373 | |
374 | 374 | return $user; |
@@ -377,37 +377,37 @@ discard block |
||
377 | 377 | return false; |
378 | 378 | } |
379 | 379 | |
380 | - public function get_user_public_key( $user_id = 0 ) { |
|
380 | + public function get_user_public_key($user_id = 0) { |
|
381 | 381 | global $wpdb; |
382 | 382 | |
383 | - if ( empty( $user_id ) ) { |
|
383 | + if (empty($user_id)) { |
|
384 | 384 | return ''; |
385 | 385 | } |
386 | 386 | |
387 | - $cache_key = md5( 'give_api_user_public_key' . $user_id ); |
|
388 | - $user_public_key = get_transient( $cache_key ); |
|
387 | + $cache_key = md5('give_api_user_public_key'.$user_id); |
|
388 | + $user_public_key = get_transient($cache_key); |
|
389 | 389 | |
390 | - if ( empty( $user_public_key ) ) { |
|
391 | - $user_public_key = $wpdb->get_var( $wpdb->prepare( "SELECT meta_key FROM $wpdb->usermeta WHERE meta_value = 'give_user_public_key' AND user_id = %d", $user_id ) ); |
|
392 | - set_transient( $cache_key, $user_public_key, HOUR_IN_SECONDS ); |
|
390 | + if (empty($user_public_key)) { |
|
391 | + $user_public_key = $wpdb->get_var($wpdb->prepare("SELECT meta_key FROM $wpdb->usermeta WHERE meta_value = 'give_user_public_key' AND user_id = %d", $user_id)); |
|
392 | + set_transient($cache_key, $user_public_key, HOUR_IN_SECONDS); |
|
393 | 393 | } |
394 | 394 | |
395 | 395 | return $user_public_key; |
396 | 396 | } |
397 | 397 | |
398 | - public function get_user_secret_key( $user_id = 0 ) { |
|
398 | + public function get_user_secret_key($user_id = 0) { |
|
399 | 399 | global $wpdb; |
400 | 400 | |
401 | - if ( empty( $user_id ) ) { |
|
401 | + if (empty($user_id)) { |
|
402 | 402 | return ''; |
403 | 403 | } |
404 | 404 | |
405 | - $cache_key = md5( 'give_api_user_secret_key' . $user_id ); |
|
406 | - $user_secret_key = get_transient( $cache_key ); |
|
405 | + $cache_key = md5('give_api_user_secret_key'.$user_id); |
|
406 | + $user_secret_key = get_transient($cache_key); |
|
407 | 407 | |
408 | - if ( empty( $user_secret_key ) ) { |
|
409 | - $user_secret_key = $wpdb->get_var( $wpdb->prepare( "SELECT meta_key FROM $wpdb->usermeta WHERE meta_value = 'give_user_secret_key' AND user_id = %d", $user_id ) ); |
|
410 | - set_transient( $cache_key, $user_secret_key, HOUR_IN_SECONDS ); |
|
408 | + if (empty($user_secret_key)) { |
|
409 | + $user_secret_key = $wpdb->get_var($wpdb->prepare("SELECT meta_key FROM $wpdb->usermeta WHERE meta_value = 'give_user_secret_key' AND user_id = %d", $user_id)); |
|
410 | + set_transient($cache_key, $user_secret_key, HOUR_IN_SECONDS); |
|
411 | 411 | } |
412 | 412 | |
413 | 413 | return $user_secret_key; |
@@ -423,10 +423,10 @@ discard block |
||
423 | 423 | */ |
424 | 424 | private function missing_auth() { |
425 | 425 | $error = array(); |
426 | - $error['error'] = esc_attr__( 'You must specify both a token and API key!', 'give' ); |
|
426 | + $error['error'] = esc_attr__('You must specify both a token and API key!', 'give'); |
|
427 | 427 | |
428 | 428 | $this->data = $error; |
429 | - $this->output( 401 ); |
|
429 | + $this->output(401); |
|
430 | 430 | } |
431 | 431 | |
432 | 432 | /** |
@@ -440,10 +440,10 @@ discard block |
||
440 | 440 | */ |
441 | 441 | private function invalid_auth() { |
442 | 442 | $error = array(); |
443 | - $error['error'] = esc_attr__( 'Your request could not be authenticated!', 'give' ); |
|
443 | + $error['error'] = esc_attr__('Your request could not be authenticated!', 'give'); |
|
444 | 444 | |
445 | 445 | $this->data = $error; |
446 | - $this->output( 403 ); |
|
446 | + $this->output(403); |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
@@ -457,10 +457,10 @@ discard block |
||
457 | 457 | */ |
458 | 458 | private function invalid_key() { |
459 | 459 | $error = array(); |
460 | - $error['error'] = esc_attr__( 'Invalid API key!', 'give' ); |
|
460 | + $error['error'] = esc_attr__('Invalid API key!', 'give'); |
|
461 | 461 | |
462 | 462 | $this->data = $error; |
463 | - $this->output( 403 ); |
|
463 | + $this->output(403); |
|
464 | 464 | } |
465 | 465 | |
466 | 466 | /** |
@@ -473,10 +473,10 @@ discard block |
||
473 | 473 | */ |
474 | 474 | private function invalid_version() { |
475 | 475 | $error = array(); |
476 | - $error['error'] = esc_attr__( 'Invalid API version!', 'give' ); |
|
476 | + $error['error'] = esc_attr__('Invalid API version!', 'give'); |
|
477 | 477 | |
478 | 478 | $this->data = $error; |
479 | - $this->output( 404 ); |
|
479 | + $this->output(404); |
|
480 | 480 | } |
481 | 481 | |
482 | 482 | /** |
@@ -492,10 +492,10 @@ discard block |
||
492 | 492 | global $wp_query; |
493 | 493 | |
494 | 494 | // Start logging how long the request takes for logging |
495 | - $before = microtime( true ); |
|
495 | + $before = microtime(true); |
|
496 | 496 | |
497 | 497 | // Check for give-api var. Get out if not present |
498 | - if ( empty( $wp_query->query_vars['give-api'] ) ) { |
|
498 | + if (empty($wp_query->query_vars['give-api'])) { |
|
499 | 499 | return; |
500 | 500 | } |
501 | 501 | |
@@ -509,45 +509,45 @@ discard block |
||
509 | 509 | $this->validate_request(); |
510 | 510 | |
511 | 511 | // Only proceed if no errors have been noted |
512 | - if ( ! $this->is_valid_request ) { |
|
512 | + if ( ! $this->is_valid_request) { |
|
513 | 513 | return; |
514 | 514 | } |
515 | 515 | |
516 | - if ( ! defined( 'GIVE_DOING_API' ) ) { |
|
517 | - define( 'GIVE_DOING_API', true ); |
|
516 | + if ( ! defined('GIVE_DOING_API')) { |
|
517 | + define('GIVE_DOING_API', true); |
|
518 | 518 | } |
519 | 519 | |
520 | 520 | $data = array(); |
521 | 521 | $this->routes = new $this->versions[$this->get_queried_version()]; |
522 | 522 | $this->routes->validate_request(); |
523 | 523 | |
524 | - switch ( $this->endpoint ) : |
|
524 | + switch ($this->endpoint) : |
|
525 | 525 | |
526 | 526 | case 'stats' : |
527 | 527 | |
528 | - $data = $this->routes->get_stats( array( |
|
529 | - 'type' => isset( $wp_query->query_vars['type'] ) ? $wp_query->query_vars['type'] : null, |
|
530 | - 'form' => isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null, |
|
531 | - 'date' => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null, |
|
532 | - 'startdate' => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null, |
|
533 | - 'enddate' => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null |
|
534 | - ) ); |
|
528 | + $data = $this->routes->get_stats(array( |
|
529 | + 'type' => isset($wp_query->query_vars['type']) ? $wp_query->query_vars['type'] : null, |
|
530 | + 'form' => isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null, |
|
531 | + 'date' => isset($wp_query->query_vars['date']) ? $wp_query->query_vars['date'] : null, |
|
532 | + 'startdate' => isset($wp_query->query_vars['startdate']) ? $wp_query->query_vars['startdate'] : null, |
|
533 | + 'enddate' => isset($wp_query->query_vars['enddate']) ? $wp_query->query_vars['enddate'] : null |
|
534 | + )); |
|
535 | 535 | |
536 | 536 | break; |
537 | 537 | |
538 | 538 | case 'forms' : |
539 | 539 | |
540 | - $form = isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null; |
|
540 | + $form = isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null; |
|
541 | 541 | |
542 | - $data = $this->routes->get_forms( $form ); |
|
542 | + $data = $this->routes->get_forms($form); |
|
543 | 543 | |
544 | 544 | break; |
545 | 545 | |
546 | 546 | case 'donors' : |
547 | 547 | |
548 | - $customer = isset( $wp_query->query_vars['donor'] ) ? $wp_query->query_vars['donor'] : null; |
|
548 | + $customer = isset($wp_query->query_vars['donor']) ? $wp_query->query_vars['donor'] : null; |
|
549 | 549 | |
550 | - $data = $this->routes->get_customers( $customer ); |
|
550 | + $data = $this->routes->get_customers($customer); |
|
551 | 551 | |
552 | 552 | break; |
553 | 553 | |
@@ -560,14 +560,14 @@ discard block |
||
560 | 560 | endswitch; |
561 | 561 | |
562 | 562 | // Allow extensions to setup their own return data |
563 | - $this->data = apply_filters( 'give_api_output_data', $data, $this->endpoint, $this ); |
|
563 | + $this->data = apply_filters('give_api_output_data', $data, $this->endpoint, $this); |
|
564 | 564 | |
565 | - $after = microtime( true ); |
|
566 | - $request_time = ( $after - $before ); |
|
565 | + $after = microtime(true); |
|
566 | + $request_time = ($after - $before); |
|
567 | 567 | $this->data['request_speed'] = $request_time; |
568 | 568 | |
569 | 569 | // Log this API request, if enabled. We log it here because we have access to errors. |
570 | - $this->log_request( $this->data ); |
|
570 | + $this->log_request($this->data); |
|
571 | 571 | |
572 | 572 | // Send out data to the output function |
573 | 573 | $this->output(); |
@@ -597,25 +597,25 @@ discard block |
||
597 | 597 | global $wp_query; |
598 | 598 | |
599 | 599 | // Whitelist our query options |
600 | - $accepted = apply_filters( 'give_api_valid_query_modes', array( |
|
600 | + $accepted = apply_filters('give_api_valid_query_modes', array( |
|
601 | 601 | 'stats', |
602 | 602 | 'forms', |
603 | 603 | 'donors', |
604 | 604 | 'donations' |
605 | - ) ); |
|
605 | + )); |
|
606 | 606 | |
607 | - $query = isset( $wp_query->query_vars['give-api'] ) ? $wp_query->query_vars['give-api'] : null; |
|
608 | - $query = str_replace( $this->queried_version . '/', '', $query ); |
|
607 | + $query = isset($wp_query->query_vars['give-api']) ? $wp_query->query_vars['give-api'] : null; |
|
608 | + $query = str_replace($this->queried_version.'/', '', $query); |
|
609 | 609 | |
610 | 610 | $error = array(); |
611 | 611 | |
612 | 612 | // Make sure our query is valid |
613 | - if ( ! in_array( $query, $accepted ) ) { |
|
614 | - $error['error'] = __( 'Invalid query!', 'give' ); |
|
613 | + if ( ! in_array($query, $accepted)) { |
|
614 | + $error['error'] = __('Invalid query!', 'give'); |
|
615 | 615 | |
616 | 616 | $this->data = $error; |
617 | 617 | // 400 is Bad Request |
618 | - $this->output( 400 ); |
|
618 | + $this->output(400); |
|
619 | 619 | } |
620 | 620 | |
621 | 621 | $this->endpoint = $query; |
@@ -632,7 +632,7 @@ discard block |
||
632 | 632 | public function get_paged() { |
633 | 633 | global $wp_query; |
634 | 634 | |
635 | - return isset( $wp_query->query_vars['page'] ) ? $wp_query->query_vars['page'] : 1; |
|
635 | + return isset($wp_query->query_vars['page']) ? $wp_query->query_vars['page'] : 1; |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | |
@@ -647,13 +647,13 @@ discard block |
||
647 | 647 | public function per_page() { |
648 | 648 | global $wp_query; |
649 | 649 | |
650 | - $per_page = isset( $wp_query->query_vars['number'] ) ? $wp_query->query_vars['number'] : 10; |
|
650 | + $per_page = isset($wp_query->query_vars['number']) ? $wp_query->query_vars['number'] : 10; |
|
651 | 651 | |
652 | - if ( $per_page < 0 && $this->get_query_mode() == 'donors' ) { |
|
652 | + if ($per_page < 0 && $this->get_query_mode() == 'donors') { |
|
653 | 653 | $per_page = 99999999; |
654 | 654 | } // Customers query doesn't support -1 |
655 | 655 | |
656 | - return apply_filters( 'give_api_results_per_page', $per_page ); |
|
656 | + return apply_filters('give_api_results_per_page', $per_page); |
|
657 | 657 | } |
658 | 658 | |
659 | 659 | /** |
@@ -666,7 +666,7 @@ discard block |
||
666 | 666 | * |
667 | 667 | * @return array $dates |
668 | 668 | */ |
669 | - public function get_dates( $args = array() ) { |
|
669 | + public function get_dates($args = array()) { |
|
670 | 670 | $dates = array(); |
671 | 671 | |
672 | 672 | $defaults = array( |
@@ -677,60 +677,60 @@ discard block |
||
677 | 677 | 'enddate' => null |
678 | 678 | ); |
679 | 679 | |
680 | - $args = wp_parse_args( $args, $defaults ); |
|
680 | + $args = wp_parse_args($args, $defaults); |
|
681 | 681 | |
682 | - $current_time = current_time( 'timestamp' ); |
|
682 | + $current_time = current_time('timestamp'); |
|
683 | 683 | |
684 | - if ( 'range' === $args['date'] ) { |
|
685 | - $startdate = strtotime( $args['startdate'] ); |
|
686 | - $enddate = strtotime( $args['enddate'] ); |
|
687 | - $dates['day_start'] = date( 'd', $startdate ); |
|
688 | - $dates['day_end'] = date( 'd', $enddate ); |
|
689 | - $dates['m_start'] = date( 'n', $startdate ); |
|
690 | - $dates['m_end'] = date( 'n', $enddate ); |
|
691 | - $dates['year'] = date( 'Y', $startdate ); |
|
692 | - $dates['year_end'] = date( 'Y', $enddate ); |
|
684 | + if ('range' === $args['date']) { |
|
685 | + $startdate = strtotime($args['startdate']); |
|
686 | + $enddate = strtotime($args['enddate']); |
|
687 | + $dates['day_start'] = date('d', $startdate); |
|
688 | + $dates['day_end'] = date('d', $enddate); |
|
689 | + $dates['m_start'] = date('n', $startdate); |
|
690 | + $dates['m_end'] = date('n', $enddate); |
|
691 | + $dates['year'] = date('Y', $startdate); |
|
692 | + $dates['year_end'] = date('Y', $enddate); |
|
693 | 693 | } else { |
694 | 694 | // Modify dates based on predefined ranges |
695 | - switch ( $args['date'] ) : |
|
695 | + switch ($args['date']) : |
|
696 | 696 | |
697 | 697 | case 'this_month' : |
698 | 698 | $dates['day'] = null; |
699 | - $dates['m_start'] = date( 'n', $current_time ); |
|
700 | - $dates['m_end'] = date( 'n', $current_time ); |
|
701 | - $dates['year'] = date( 'Y', $current_time ); |
|
699 | + $dates['m_start'] = date('n', $current_time); |
|
700 | + $dates['m_end'] = date('n', $current_time); |
|
701 | + $dates['year'] = date('Y', $current_time); |
|
702 | 702 | break; |
703 | 703 | |
704 | 704 | case 'last_month' : |
705 | 705 | $dates['day'] = null; |
706 | - $dates['m_start'] = date( 'n', $current_time ) == 1 ? 12 : date( 'n', $current_time ) - 1; |
|
706 | + $dates['m_start'] = date('n', $current_time) == 1 ? 12 : date('n', $current_time) - 1; |
|
707 | 707 | $dates['m_end'] = $dates['m_start']; |
708 | - $dates['year'] = date( 'n', $current_time ) == 1 ? date( 'Y', $current_time ) - 1 : date( 'Y', $current_time ); |
|
708 | + $dates['year'] = date('n', $current_time) == 1 ? date('Y', $current_time) - 1 : date('Y', $current_time); |
|
709 | 709 | break; |
710 | 710 | |
711 | 711 | case 'today' : |
712 | - $dates['day'] = date( 'd', $current_time ); |
|
713 | - $dates['m_start'] = date( 'n', $current_time ); |
|
714 | - $dates['m_end'] = date( 'n', $current_time ); |
|
715 | - $dates['year'] = date( 'Y', $current_time ); |
|
712 | + $dates['day'] = date('d', $current_time); |
|
713 | + $dates['m_start'] = date('n', $current_time); |
|
714 | + $dates['m_end'] = date('n', $current_time); |
|
715 | + $dates['year'] = date('Y', $current_time); |
|
716 | 716 | break; |
717 | 717 | |
718 | 718 | case 'yesterday' : |
719 | 719 | |
720 | - $year = date( 'Y', $current_time ); |
|
721 | - $month = date( 'n', $current_time ); |
|
722 | - $day = date( 'd', $current_time ); |
|
720 | + $year = date('Y', $current_time); |
|
721 | + $month = date('n', $current_time); |
|
722 | + $day = date('d', $current_time); |
|
723 | 723 | |
724 | - if ( $month == 1 && $day == 1 ) { |
|
724 | + if ($month == 1 && $day == 1) { |
|
725 | 725 | |
726 | 726 | $year -= 1; |
727 | 727 | $month = 12; |
728 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
728 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
729 | 729 | |
730 | - } elseif ( $month > 1 && $day == 1 ) { |
|
730 | + } elseif ($month > 1 && $day == 1) { |
|
731 | 731 | |
732 | 732 | $month -= 1; |
733 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
733 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
734 | 734 | |
735 | 735 | } else { |
736 | 736 | |
@@ -746,65 +746,65 @@ discard block |
||
746 | 746 | break; |
747 | 747 | |
748 | 748 | case 'this_quarter' : |
749 | - $month_now = date( 'n', $current_time ); |
|
749 | + $month_now = date('n', $current_time); |
|
750 | 750 | |
751 | 751 | $dates['day'] = null; |
752 | 752 | |
753 | - if ( $month_now <= 3 ) { |
|
753 | + if ($month_now <= 3) { |
|
754 | 754 | |
755 | 755 | $dates['m_start'] = 1; |
756 | 756 | $dates['m_end'] = 3; |
757 | - $dates['year'] = date( 'Y', $current_time ); |
|
757 | + $dates['year'] = date('Y', $current_time); |
|
758 | 758 | |
759 | - } else if ( $month_now <= 6 ) { |
|
759 | + } else if ($month_now <= 6) { |
|
760 | 760 | |
761 | 761 | $dates['m_start'] = 4; |
762 | 762 | $dates['m_end'] = 6; |
763 | - $dates['year'] = date( 'Y', $current_time ); |
|
763 | + $dates['year'] = date('Y', $current_time); |
|
764 | 764 | |
765 | - } else if ( $month_now <= 9 ) { |
|
765 | + } else if ($month_now <= 9) { |
|
766 | 766 | |
767 | 767 | $dates['m_start'] = 7; |
768 | 768 | $dates['m_end'] = 9; |
769 | - $dates['year'] = date( 'Y', $current_time ); |
|
769 | + $dates['year'] = date('Y', $current_time); |
|
770 | 770 | |
771 | 771 | } else { |
772 | 772 | |
773 | 773 | $dates['m_start'] = 10; |
774 | 774 | $dates['m_end'] = 12; |
775 | - $dates['year'] = date( 'Y', $current_time ); |
|
775 | + $dates['year'] = date('Y', $current_time); |
|
776 | 776 | |
777 | 777 | } |
778 | 778 | break; |
779 | 779 | |
780 | 780 | case 'last_quarter' : |
781 | - $month_now = date( 'n', $current_time ); |
|
781 | + $month_now = date('n', $current_time); |
|
782 | 782 | |
783 | 783 | $dates['day'] = null; |
784 | 784 | |
785 | - if ( $month_now <= 3 ) { |
|
785 | + if ($month_now <= 3) { |
|
786 | 786 | |
787 | 787 | $dates['m_start'] = 10; |
788 | 788 | $dates['m_end'] = 12; |
789 | - $dates['year'] = date( 'Y', $current_time ) - 1; // Previous year |
|
789 | + $dates['year'] = date('Y', $current_time) - 1; // Previous year |
|
790 | 790 | |
791 | - } else if ( $month_now <= 6 ) { |
|
791 | + } else if ($month_now <= 6) { |
|
792 | 792 | |
793 | 793 | $dates['m_start'] = 1; |
794 | 794 | $dates['m_end'] = 3; |
795 | - $dates['year'] = date( 'Y', $current_time ); |
|
795 | + $dates['year'] = date('Y', $current_time); |
|
796 | 796 | |
797 | - } else if ( $month_now <= 9 ) { |
|
797 | + } else if ($month_now <= 9) { |
|
798 | 798 | |
799 | 799 | $dates['m_start'] = 4; |
800 | 800 | $dates['m_end'] = 6; |
801 | - $dates['year'] = date( 'Y', $current_time ); |
|
801 | + $dates['year'] = date('Y', $current_time); |
|
802 | 802 | |
803 | 803 | } else { |
804 | 804 | |
805 | 805 | $dates['m_start'] = 7; |
806 | 806 | $dates['m_end'] = 9; |
807 | - $dates['year'] = date( 'Y', $current_time ); |
|
807 | + $dates['year'] = date('Y', $current_time); |
|
808 | 808 | |
809 | 809 | } |
810 | 810 | break; |
@@ -813,14 +813,14 @@ discard block |
||
813 | 813 | $dates['day'] = null; |
814 | 814 | $dates['m_start'] = null; |
815 | 815 | $dates['m_end'] = null; |
816 | - $dates['year'] = date( 'Y', $current_time ); |
|
816 | + $dates['year'] = date('Y', $current_time); |
|
817 | 817 | break; |
818 | 818 | |
819 | 819 | case 'last_year' : |
820 | 820 | $dates['day'] = null; |
821 | 821 | $dates['m_start'] = null; |
822 | 822 | $dates['m_end'] = null; |
823 | - $dates['year'] = date( 'Y', $current_time ) - 1; |
|
823 | + $dates['year'] = date('Y', $current_time) - 1; |
|
824 | 824 | break; |
825 | 825 | |
826 | 826 | endswitch; |
@@ -834,7 +834,7 @@ discard block |
||
834 | 834 | * @param object $dates The dates used for retreiving earnings/donations |
835 | 835 | */ |
836 | 836 | |
837 | - return apply_filters( 'give_api_stat_dates', $dates ); |
|
837 | + return apply_filters('give_api_stat_dates', $dates); |
|
838 | 838 | } |
839 | 839 | |
840 | 840 | /** |
@@ -849,11 +849,11 @@ discard block |
||
849 | 849 | * |
850 | 850 | * @return array $customers Multidimensional array of the customers |
851 | 851 | */ |
852 | - public function get_customers( $customer = null ) { |
|
852 | + public function get_customers($customer = null) { |
|
853 | 853 | |
854 | 854 | $customers = array(); |
855 | 855 | $error = array(); |
856 | - if ( ! user_can( $this->user_id, 'view_give_sensitive_data' ) && ! $this->override ) { |
|
856 | + if ( ! user_can($this->user_id, 'view_give_sensitive_data') && ! $this->override) { |
|
857 | 857 | return $customers; |
858 | 858 | } |
859 | 859 | |
@@ -861,68 +861,68 @@ discard block |
||
861 | 861 | |
862 | 862 | $paged = $this->get_paged(); |
863 | 863 | $per_page = $this->per_page(); |
864 | - $offset = $per_page * ( $paged - 1 ); |
|
864 | + $offset = $per_page * ($paged - 1); |
|
865 | 865 | |
866 | - if ( is_numeric( $customer ) ) { |
|
866 | + if (is_numeric($customer)) { |
|
867 | 867 | $field = 'id'; |
868 | 868 | } else { |
869 | 869 | $field = 'email'; |
870 | 870 | } |
871 | 871 | |
872 | - $customer_query = Give()->customers->get_customers( array( |
|
872 | + $customer_query = Give()->customers->get_customers(array( |
|
873 | 873 | 'number' => $per_page, |
874 | 874 | 'offset' => $offset, |
875 | 875 | $field => $customer |
876 | - ) ); |
|
876 | + )); |
|
877 | 877 | $customer_count = 0; |
878 | 878 | |
879 | - if ( $customer_query ) { |
|
879 | + if ($customer_query) { |
|
880 | 880 | |
881 | - foreach ( $customer_query as $customer_obj ) { |
|
881 | + foreach ($customer_query as $customer_obj) { |
|
882 | 882 | |
883 | - $names = explode( ' ', $customer_obj->name ); |
|
884 | - $first_name = ! empty( $names[0] ) ? $names[0] : ''; |
|
883 | + $names = explode(' ', $customer_obj->name); |
|
884 | + $first_name = ! empty($names[0]) ? $names[0] : ''; |
|
885 | 885 | $last_name = ''; |
886 | - if ( ! empty( $names[1] ) ) { |
|
887 | - unset( $names[0] ); |
|
888 | - $last_name = implode( ' ', $names ); |
|
886 | + if ( ! empty($names[1])) { |
|
887 | + unset($names[0]); |
|
888 | + $last_name = implode(' ', $names); |
|
889 | 889 | } |
890 | 890 | |
891 | - $customers['donors'][ $customer_count ]['info']['user_id'] = ''; |
|
892 | - $customers['donors'][ $customer_count ]['info']['username'] = ''; |
|
893 | - $customers['donors'][ $customer_count ]['info']['display_name'] = ''; |
|
894 | - $customers['donors'][ $customer_count ]['info']['customer_id'] = $customer_obj->id; |
|
895 | - $customers['donors'][ $customer_count ]['info']['first_name'] = $first_name; |
|
896 | - $customers['donors'][ $customer_count ]['info']['last_name'] = $last_name; |
|
897 | - $customers['donors'][ $customer_count ]['info']['email'] = $customer_obj->email; |
|
891 | + $customers['donors'][$customer_count]['info']['user_id'] = ''; |
|
892 | + $customers['donors'][$customer_count]['info']['username'] = ''; |
|
893 | + $customers['donors'][$customer_count]['info']['display_name'] = ''; |
|
894 | + $customers['donors'][$customer_count]['info']['customer_id'] = $customer_obj->id; |
|
895 | + $customers['donors'][$customer_count]['info']['first_name'] = $first_name; |
|
896 | + $customers['donors'][$customer_count]['info']['last_name'] = $last_name; |
|
897 | + $customers['donors'][$customer_count]['info']['email'] = $customer_obj->email; |
|
898 | 898 | |
899 | - if ( ! empty( $customer_obj->user_id ) ) { |
|
899 | + if ( ! empty($customer_obj->user_id)) { |
|
900 | 900 | |
901 | - $user_data = get_userdata( $customer_obj->user_id ); |
|
901 | + $user_data = get_userdata($customer_obj->user_id); |
|
902 | 902 | |
903 | 903 | // Customer with registered account |
904 | - $customers['donors'][ $customer_count ]['info']['user_id'] = $customer_obj->user_id; |
|
905 | - $customers['donors'][ $customer_count ]['info']['username'] = $user_data->user_login; |
|
906 | - $customers['donors'][ $customer_count ]['info']['display_name'] = $user_data->display_name; |
|
904 | + $customers['donors'][$customer_count]['info']['user_id'] = $customer_obj->user_id; |
|
905 | + $customers['donors'][$customer_count]['info']['username'] = $user_data->user_login; |
|
906 | + $customers['donors'][$customer_count]['info']['display_name'] = $user_data->display_name; |
|
907 | 907 | |
908 | 908 | } |
909 | 909 | |
910 | - $customers['donors'][ $customer_count ]['stats']['total_donations'] = $customer_obj->purchase_count; |
|
911 | - $customers['donors'][ $customer_count ]['stats']['total_spent'] = $customer_obj->purchase_value; |
|
910 | + $customers['donors'][$customer_count]['stats']['total_donations'] = $customer_obj->purchase_count; |
|
911 | + $customers['donors'][$customer_count]['stats']['total_spent'] = $customer_obj->purchase_value; |
|
912 | 912 | |
913 | - $customer_count ++; |
|
913 | + $customer_count++; |
|
914 | 914 | |
915 | 915 | } |
916 | 916 | |
917 | - } elseif ( $customer ) { |
|
917 | + } elseif ($customer) { |
|
918 | 918 | |
919 | - $error['error'] = sprintf( __( 'Donor %s not found!', 'give' ), $customer ); |
|
919 | + $error['error'] = sprintf(__('Donor %s not found!', 'give'), $customer); |
|
920 | 920 | |
921 | 921 | return $error; |
922 | 922 | |
923 | 923 | } else { |
924 | 924 | |
925 | - $error['error'] = __( 'No donors found!', 'give' ); |
|
925 | + $error['error'] = __('No donors found!', 'give'); |
|
926 | 926 | |
927 | 927 | return $error; |
928 | 928 | |
@@ -941,36 +941,36 @@ discard block |
||
941 | 941 | * |
942 | 942 | * @return array $customers Multidimensional array of the forms |
943 | 943 | */ |
944 | - public function get_forms( $form = null ) { |
|
944 | + public function get_forms($form = null) { |
|
945 | 945 | |
946 | 946 | $forms = array(); |
947 | 947 | $error = array(); |
948 | 948 | |
949 | - if ( $form == null ) { |
|
949 | + if ($form == null) { |
|
950 | 950 | $forms['forms'] = array(); |
951 | 951 | |
952 | - $form_list = get_posts( array( |
|
952 | + $form_list = get_posts(array( |
|
953 | 953 | 'post_type' => 'give_forms', |
954 | 954 | 'posts_per_page' => $this->per_page(), |
955 | 955 | 'suppress_filters' => true, |
956 | 956 | 'paged' => $this->get_paged() |
957 | - ) ); |
|
957 | + )); |
|
958 | 958 | |
959 | - if ( $form_list ) { |
|
959 | + if ($form_list) { |
|
960 | 960 | $i = 0; |
961 | - foreach ( $form_list as $form_info ) { |
|
962 | - $forms['forms'][ $i ] = $this->get_form_data( $form_info ); |
|
963 | - $i ++; |
|
961 | + foreach ($form_list as $form_info) { |
|
962 | + $forms['forms'][$i] = $this->get_form_data($form_info); |
|
963 | + $i++; |
|
964 | 964 | } |
965 | 965 | } |
966 | 966 | } else { |
967 | - if ( get_post_type( $form ) == 'give_forms' ) { |
|
968 | - $form_info = get_post( $form ); |
|
967 | + if (get_post_type($form) == 'give_forms') { |
|
968 | + $form_info = get_post($form); |
|
969 | 969 | |
970 | - $forms['forms'][0] = $this->get_form_data( $form_info ); |
|
970 | + $forms['forms'][0] = $this->get_form_data($form_info); |
|
971 | 971 | |
972 | 972 | } else { |
973 | - $error['error'] = sprintf( __( 'Form %s not found!', 'give' ), $form ); |
|
973 | + $error['error'] = sprintf(__('Form %s not found!', 'give'), $form); |
|
974 | 974 | |
975 | 975 | return $error; |
976 | 976 | } |
@@ -988,7 +988,7 @@ discard block |
||
988 | 988 | * |
989 | 989 | * @return array Array of post data to return back in the API |
990 | 990 | */ |
991 | - private function get_form_data( $form_info ) { |
|
991 | + private function get_form_data($form_info) { |
|
992 | 992 | |
993 | 993 | $form = array(); |
994 | 994 | |
@@ -998,46 +998,46 @@ discard block |
||
998 | 998 | $form['info']['create_date'] = $form_info->post_date; |
999 | 999 | $form['info']['modified_date'] = $form_info->post_modified; |
1000 | 1000 | $form['info']['status'] = $form_info->post_status; |
1001 | - $form['info']['link'] = html_entity_decode( $form_info->guid ); |
|
1002 | - $form['info']['content'] = get_post_meta( $form_info->ID, '_give_form_content', true ); |
|
1003 | - $form['info']['thumbnail'] = wp_get_attachment_url( get_post_thumbnail_id( $form_info->ID ) ); |
|
1001 | + $form['info']['link'] = html_entity_decode($form_info->guid); |
|
1002 | + $form['info']['content'] = get_post_meta($form_info->ID, '_give_form_content', true); |
|
1003 | + $form['info']['thumbnail'] = wp_get_attachment_url(get_post_thumbnail_id($form_info->ID)); |
|
1004 | 1004 | |
1005 | - if ( give_get_option( 'enable_categories' ) == 'on' ) { |
|
1006 | - $form['info']['category'] = get_the_terms( $form_info, 'give_forms_category' ); |
|
1007 | - $form['info']['tags'] = get_the_terms( $form_info, 'give_forms_tag' ); |
|
1005 | + if (give_get_option('enable_categories') == 'on') { |
|
1006 | + $form['info']['category'] = get_the_terms($form_info, 'give_forms_category'); |
|
1007 | + $form['info']['tags'] = get_the_terms($form_info, 'give_forms_tag'); |
|
1008 | 1008 | } |
1009 | - if ( give_get_option( 'enable_tags' ) == 'on' ) { |
|
1010 | - $form['info']['tags'] = get_the_terms( $form_info, 'give_forms_tag' ); |
|
1009 | + if (give_get_option('enable_tags') == 'on') { |
|
1010 | + $form['info']['tags'] = get_the_terms($form_info, 'give_forms_tag'); |
|
1011 | 1011 | } |
1012 | 1012 | |
1013 | - if ( user_can( $this->user_id, 'view_give_reports' ) || $this->override ) { |
|
1014 | - $form['stats']['total']['donations'] = give_get_form_sales_stats( $form_info->ID ); |
|
1015 | - $form['stats']['total']['earnings'] = give_get_form_earnings_stats( $form_info->ID ); |
|
1016 | - $form['stats']['monthly_average']['donations'] = give_get_average_monthly_form_sales( $form_info->ID ); |
|
1017 | - $form['stats']['monthly_average']['earnings'] = give_get_average_monthly_form_earnings( $form_info->ID ); |
|
1013 | + if (user_can($this->user_id, 'view_give_reports') || $this->override) { |
|
1014 | + $form['stats']['total']['donations'] = give_get_form_sales_stats($form_info->ID); |
|
1015 | + $form['stats']['total']['earnings'] = give_get_form_earnings_stats($form_info->ID); |
|
1016 | + $form['stats']['monthly_average']['donations'] = give_get_average_monthly_form_sales($form_info->ID); |
|
1017 | + $form['stats']['monthly_average']['earnings'] = give_get_average_monthly_form_earnings($form_info->ID); |
|
1018 | 1018 | } |
1019 | 1019 | |
1020 | 1020 | $counter = 0; |
1021 | - if ( give_has_variable_prices( $form_info->ID ) ) { |
|
1022 | - foreach ( give_get_variable_prices( $form_info->ID ) as $price ) { |
|
1023 | - $counter ++; |
|
1021 | + if (give_has_variable_prices($form_info->ID)) { |
|
1022 | + foreach (give_get_variable_prices($form_info->ID) as $price) { |
|
1023 | + $counter++; |
|
1024 | 1024 | //muli-level item |
1025 | - $level = isset( $price['_give_text'] ) ? $price['_give_text'] : 'level-' . $counter; |
|
1026 | - $form['pricing'][ sanitize_key( $level ) ] = $price['_give_amount']; |
|
1025 | + $level = isset($price['_give_text']) ? $price['_give_text'] : 'level-'.$counter; |
|
1026 | + $form['pricing'][sanitize_key($level)] = $price['_give_amount']; |
|
1027 | 1027 | |
1028 | 1028 | } |
1029 | 1029 | } else { |
1030 | - $form['pricing']['amount'] = give_get_form_price( $form_info->ID ); |
|
1030 | + $form['pricing']['amount'] = give_get_form_price($form_info->ID); |
|
1031 | 1031 | } |
1032 | 1032 | |
1033 | - if ( user_can( $this->user_id, 'view_give_sensitive_data' ) || $this->override ) { |
|
1033 | + if (user_can($this->user_id, 'view_give_sensitive_data') || $this->override) { |
|
1034 | 1034 | |
1035 | 1035 | //Sensitive data here |
1036 | - do_action( 'give_api_sensitive_data' ); |
|
1036 | + do_action('give_api_sensitive_data'); |
|
1037 | 1037 | |
1038 | 1038 | } |
1039 | 1039 | |
1040 | - return apply_filters( 'give_api_forms_form', $form ); |
|
1040 | + return apply_filters('give_api_forms_form', $form); |
|
1041 | 1041 | |
1042 | 1042 | } |
1043 | 1043 | |
@@ -1052,7 +1052,7 @@ discard block |
||
1052 | 1052 | * |
1053 | 1053 | * @return array |
1054 | 1054 | */ |
1055 | - public function get_stats( $args = array() ) { |
|
1055 | + public function get_stats($args = array()) { |
|
1056 | 1056 | $defaults = array( |
1057 | 1057 | 'type' => null, |
1058 | 1058 | 'form' => null, |
@@ -1061,9 +1061,9 @@ discard block |
||
1061 | 1061 | 'enddate' => null |
1062 | 1062 | ); |
1063 | 1063 | |
1064 | - $args = wp_parse_args( $args, $defaults ); |
|
1064 | + $args = wp_parse_args($args, $defaults); |
|
1065 | 1065 | |
1066 | - $dates = $this->get_dates( $args ); |
|
1066 | + $dates = $this->get_dates($args); |
|
1067 | 1067 | |
1068 | 1068 | $stats = array(); |
1069 | 1069 | $earnings = array( |
@@ -1074,41 +1074,41 @@ discard block |
||
1074 | 1074 | ); |
1075 | 1075 | $error = array(); |
1076 | 1076 | |
1077 | - if ( ! user_can( $this->user_id, 'view_give_reports' ) && ! $this->override ) { |
|
1077 | + if ( ! user_can($this->user_id, 'view_give_reports') && ! $this->override) { |
|
1078 | 1078 | return $stats; |
1079 | 1079 | } |
1080 | 1080 | |
1081 | - if ( $args['type'] == 'donations' ) { |
|
1081 | + if ($args['type'] == 'donations') { |
|
1082 | 1082 | |
1083 | - if ( $args['form'] == null ) { |
|
1084 | - if ( $args['date'] == null ) { |
|
1083 | + if ($args['form'] == null) { |
|
1084 | + if ($args['date'] == null) { |
|
1085 | 1085 | $sales = $this->get_default_sales_stats(); |
1086 | - } elseif ( $args['date'] === 'range' ) { |
|
1086 | + } elseif ($args['date'] === 'range') { |
|
1087 | 1087 | // Return sales for a date range |
1088 | 1088 | |
1089 | 1089 | // Ensure the end date is later than the start date |
1090 | - if ( $args['enddate'] < $args['startdate'] ) { |
|
1091 | - $error['error'] = __( 'The end date must be later than the start date!', 'give' ); |
|
1090 | + if ($args['enddate'] < $args['startdate']) { |
|
1091 | + $error['error'] = __('The end date must be later than the start date!', 'give'); |
|
1092 | 1092 | } |
1093 | 1093 | |
1094 | 1094 | // Ensure both the start and end date are specified |
1095 | - if ( empty( $args['startdate'] ) || empty( $args['enddate'] ) ) { |
|
1096 | - $error['error'] = __( 'Invalid or no date range specified!', 'give' ); |
|
1095 | + if (empty($args['startdate']) || empty($args['enddate'])) { |
|
1096 | + $error['error'] = __('Invalid or no date range specified!', 'give'); |
|
1097 | 1097 | } |
1098 | 1098 | |
1099 | 1099 | $total = 0; |
1100 | 1100 | |
1101 | 1101 | // Loop through the years |
1102 | 1102 | $y = $dates['year']; |
1103 | - while ( $y <= $dates['year_end'] ) : |
|
1103 | + while ($y <= $dates['year_end']) : |
|
1104 | 1104 | |
1105 | - if ( $dates['year'] == $dates['year_end'] ) { |
|
1105 | + if ($dates['year'] == $dates['year_end']) { |
|
1106 | 1106 | $month_start = $dates['m_start']; |
1107 | 1107 | $month_end = $dates['m_end']; |
1108 | - } elseif ( $y == $dates['year'] && $dates['year_end'] > $dates['year'] ) { |
|
1108 | + } elseif ($y == $dates['year'] && $dates['year_end'] > $dates['year']) { |
|
1109 | 1109 | $month_start = $dates['m_start']; |
1110 | 1110 | $month_end = 12; |
1111 | - } elseif ( $y == $dates['year_end'] ) { |
|
1111 | + } elseif ($y == $dates['year_end']) { |
|
1112 | 1112 | $month_start = 1; |
1113 | 1113 | $month_end = $dates['m_end']; |
1114 | 1114 | } else { |
@@ -1117,109 +1117,109 @@ discard block |
||
1117 | 1117 | } |
1118 | 1118 | |
1119 | 1119 | $i = $month_start; |
1120 | - while ( $i <= $month_end ) : |
|
1120 | + while ($i <= $month_end) : |
|
1121 | 1121 | |
1122 | - if ( $i == $dates['m_start'] ) { |
|
1122 | + if ($i == $dates['m_start']) { |
|
1123 | 1123 | $d = $dates['day_start']; |
1124 | 1124 | } else { |
1125 | 1125 | $d = 1; |
1126 | 1126 | } |
1127 | 1127 | |
1128 | - if ( $i == $dates['m_end'] ) { |
|
1128 | + if ($i == $dates['m_end']) { |
|
1129 | 1129 | $num_of_days = $dates['day_end']; |
1130 | 1130 | } else { |
1131 | - $num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y ); |
|
1131 | + $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y); |
|
1132 | 1132 | } |
1133 | 1133 | |
1134 | - while ( $d <= $num_of_days ) : |
|
1135 | - $sale_count = give_get_sales_by_date( $d, $i, $y ); |
|
1136 | - $date_key = date( 'Ymd', strtotime( $y . '/' . $i . '/' . $d ) ); |
|
1137 | - if ( ! isset( $sales['sales'][ $date_key ] ) ) { |
|
1138 | - $sales['sales'][ $date_key ] = 0; |
|
1134 | + while ($d <= $num_of_days) : |
|
1135 | + $sale_count = give_get_sales_by_date($d, $i, $y); |
|
1136 | + $date_key = date('Ymd', strtotime($y.'/'.$i.'/'.$d)); |
|
1137 | + if ( ! isset($sales['sales'][$date_key])) { |
|
1138 | + $sales['sales'][$date_key] = 0; |
|
1139 | 1139 | } |
1140 | - $sales['sales'][ $date_key ] += $sale_count; |
|
1140 | + $sales['sales'][$date_key] += $sale_count; |
|
1141 | 1141 | $total += $sale_count; |
1142 | - $d ++; |
|
1142 | + $d++; |
|
1143 | 1143 | endwhile; |
1144 | - $i ++; |
|
1144 | + $i++; |
|
1145 | 1145 | endwhile; |
1146 | 1146 | |
1147 | - $y ++; |
|
1147 | + $y++; |
|
1148 | 1148 | endwhile; |
1149 | 1149 | |
1150 | 1150 | $sales['totals'] = $total; |
1151 | 1151 | } else { |
1152 | - if ( $args['date'] == 'this_quarter' || $args['date'] == 'last_quarter' ) { |
|
1152 | + if ($args['date'] == 'this_quarter' || $args['date'] == 'last_quarter') { |
|
1153 | 1153 | $sales_count = 0; |
1154 | 1154 | |
1155 | 1155 | // Loop through the months |
1156 | 1156 | $month = $dates['m_start']; |
1157 | 1157 | |
1158 | - while ( $month <= $dates['m_end'] ) : |
|
1159 | - $sales_count += give_get_sales_by_date( null, $month, $dates['year'] ); |
|
1160 | - $month ++; |
|
1158 | + while ($month <= $dates['m_end']) : |
|
1159 | + $sales_count += give_get_sales_by_date(null, $month, $dates['year']); |
|
1160 | + $month++; |
|
1161 | 1161 | endwhile; |
1162 | 1162 | |
1163 | - $sales['donations'][ $args['date'] ] = $sales_count; |
|
1163 | + $sales['donations'][$args['date']] = $sales_count; |
|
1164 | 1164 | } else { |
1165 | - $sales['donations'][ $args['date'] ] = give_get_sales_by_date( $dates['day'], $dates['m_start'], $dates['year'] ); |
|
1165 | + $sales['donations'][$args['date']] = give_get_sales_by_date($dates['day'], $dates['m_start'], $dates['year']); |
|
1166 | 1166 | } |
1167 | 1167 | } |
1168 | - } elseif ( $args['form'] == 'all' ) { |
|
1169 | - $forms = get_posts( array( 'post_type' => 'give_forms', 'nopaging' => true ) ); |
|
1168 | + } elseif ($args['form'] == 'all') { |
|
1169 | + $forms = get_posts(array('post_type' => 'give_forms', 'nopaging' => true)); |
|
1170 | 1170 | $i = 0; |
1171 | - foreach ( $forms as $form_info ) { |
|
1172 | - $sales['donations'][ $i ] = array( $form_info->post_name => give_get_form_sales_stats( $form_info->ID ) ); |
|
1173 | - $i ++; |
|
1171 | + foreach ($forms as $form_info) { |
|
1172 | + $sales['donations'][$i] = array($form_info->post_name => give_get_form_sales_stats($form_info->ID)); |
|
1173 | + $i++; |
|
1174 | 1174 | } |
1175 | 1175 | } else { |
1176 | - if ( get_post_type( $args['form'] ) == 'give_forms' ) { |
|
1177 | - $form_info = get_post( $args['form'] ); |
|
1178 | - $sales['donations'][0] = array( $form_info->post_name => give_get_form_sales_stats( $args['form'] ) ); |
|
1176 | + if (get_post_type($args['form']) == 'give_forms') { |
|
1177 | + $form_info = get_post($args['form']); |
|
1178 | + $sales['donations'][0] = array($form_info->post_name => give_get_form_sales_stats($args['form'])); |
|
1179 | 1179 | } else { |
1180 | - $error['error'] = sprintf( __( 'Product %s not found!', 'give' ), $args['form'] ); |
|
1180 | + $error['error'] = sprintf(__('Product %s not found!', 'give'), $args['form']); |
|
1181 | 1181 | } |
1182 | 1182 | } |
1183 | 1183 | |
1184 | - if ( ! empty( $error ) ) { |
|
1184 | + if ( ! empty($error)) { |
|
1185 | 1185 | return $error; |
1186 | 1186 | } |
1187 | 1187 | |
1188 | 1188 | return $sales; |
1189 | 1189 | |
1190 | - } elseif ( $args['type'] == 'earnings' ) { |
|
1191 | - if ( $args['form'] == null ) { |
|
1192 | - if ( $args['date'] == null ) { |
|
1190 | + } elseif ($args['type'] == 'earnings') { |
|
1191 | + if ($args['form'] == null) { |
|
1192 | + if ($args['date'] == null) { |
|
1193 | 1193 | $earnings = $this->get_default_earnings_stats(); |
1194 | - } elseif ( $args['date'] === 'range' ) { |
|
1194 | + } elseif ($args['date'] === 'range') { |
|
1195 | 1195 | // Return sales for a date range |
1196 | 1196 | |
1197 | 1197 | // Ensure the end date is later than the start date |
1198 | - if ( $args['enddate'] < $args['startdate'] ) { |
|
1199 | - $error['error'] = __( 'The end date must be later than the start date!', 'give' ); |
|
1198 | + if ($args['enddate'] < $args['startdate']) { |
|
1199 | + $error['error'] = __('The end date must be later than the start date!', 'give'); |
|
1200 | 1200 | } |
1201 | 1201 | |
1202 | 1202 | // Ensure both the start and end date are specified |
1203 | - if ( empty( $args['startdate'] ) || empty( $args['enddate'] ) ) { |
|
1204 | - $error['error'] = __( 'Invalid or no date range specified!', 'give' ); |
|
1203 | + if (empty($args['startdate']) || empty($args['enddate'])) { |
|
1204 | + $error['error'] = __('Invalid or no date range specified!', 'give'); |
|
1205 | 1205 | } |
1206 | 1206 | |
1207 | 1207 | $total = (float) 0.00; |
1208 | 1208 | |
1209 | 1209 | // Loop through the years |
1210 | 1210 | $y = $dates['year']; |
1211 | - if ( ! isset( $earnings['earnings'] ) ) { |
|
1211 | + if ( ! isset($earnings['earnings'])) { |
|
1212 | 1212 | $earnings['earnings'] = array(); |
1213 | 1213 | } |
1214 | - while ( $y <= $dates['year_end'] ) : |
|
1214 | + while ($y <= $dates['year_end']) : |
|
1215 | 1215 | |
1216 | - if ( $dates['year'] == $dates['year_end'] ) { |
|
1216 | + if ($dates['year'] == $dates['year_end']) { |
|
1217 | 1217 | $month_start = $dates['m_start']; |
1218 | 1218 | $month_end = $dates['m_end']; |
1219 | - } elseif ( $y == $dates['year'] && $dates['year_end'] > $dates['year'] ) { |
|
1219 | + } elseif ($y == $dates['year'] && $dates['year_end'] > $dates['year']) { |
|
1220 | 1220 | $month_start = $dates['m_start']; |
1221 | 1221 | $month_end = 12; |
1222 | - } elseif ( $y == $dates['year_end'] ) { |
|
1222 | + } elseif ($y == $dates['year_end']) { |
|
1223 | 1223 | $month_start = 1; |
1224 | 1224 | $month_end = $dates['m_end']; |
1225 | 1225 | } else { |
@@ -1228,88 +1228,88 @@ discard block |
||
1228 | 1228 | } |
1229 | 1229 | |
1230 | 1230 | $i = $month_start; |
1231 | - while ( $i <= $month_end ) : |
|
1231 | + while ($i <= $month_end) : |
|
1232 | 1232 | |
1233 | - if ( $i == $dates['m_start'] ) { |
|
1233 | + if ($i == $dates['m_start']) { |
|
1234 | 1234 | $d = $dates['day_start']; |
1235 | 1235 | } else { |
1236 | 1236 | $d = 1; |
1237 | 1237 | } |
1238 | 1238 | |
1239 | - if ( $i == $dates['m_end'] ) { |
|
1239 | + if ($i == $dates['m_end']) { |
|
1240 | 1240 | $num_of_days = $dates['day_end']; |
1241 | 1241 | } else { |
1242 | - $num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y ); |
|
1242 | + $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y); |
|
1243 | 1243 | } |
1244 | 1244 | |
1245 | - while ( $d <= $num_of_days ) : |
|
1246 | - $earnings_stat = give_get_earnings_by_date( $d, $i, $y ); |
|
1247 | - $date_key = date( 'Ymd', strtotime( $y . '/' . $i . '/' . $d ) ); |
|
1248 | - if ( ! isset( $earnings['earnings'][ $date_key ] ) ) { |
|
1249 | - $earnings['earnings'][ $date_key ] = 0; |
|
1245 | + while ($d <= $num_of_days) : |
|
1246 | + $earnings_stat = give_get_earnings_by_date($d, $i, $y); |
|
1247 | + $date_key = date('Ymd', strtotime($y.'/'.$i.'/'.$d)); |
|
1248 | + if ( ! isset($earnings['earnings'][$date_key])) { |
|
1249 | + $earnings['earnings'][$date_key] = 0; |
|
1250 | 1250 | } |
1251 | - $earnings['earnings'][ $date_key ] += $earnings_stat; |
|
1251 | + $earnings['earnings'][$date_key] += $earnings_stat; |
|
1252 | 1252 | $total += $earnings_stat; |
1253 | - $d ++; |
|
1253 | + $d++; |
|
1254 | 1254 | endwhile; |
1255 | 1255 | |
1256 | - $i ++; |
|
1256 | + $i++; |
|
1257 | 1257 | endwhile; |
1258 | 1258 | |
1259 | - $y ++; |
|
1259 | + $y++; |
|
1260 | 1260 | endwhile; |
1261 | 1261 | |
1262 | 1262 | $earnings['totals'] = $total; |
1263 | 1263 | } else { |
1264 | - if ( $args['date'] == 'this_quarter' || $args['date'] == 'last_quarter' ) { |
|
1264 | + if ($args['date'] == 'this_quarter' || $args['date'] == 'last_quarter') { |
|
1265 | 1265 | $earnings_count = (float) 0.00; |
1266 | 1266 | |
1267 | 1267 | // Loop through the months |
1268 | 1268 | $month = $dates['m_start']; |
1269 | 1269 | |
1270 | - while ( $month <= $dates['m_end'] ) : |
|
1271 | - $earnings_count += give_get_earnings_by_date( null, $month, $dates['year'] ); |
|
1272 | - $month ++; |
|
1270 | + while ($month <= $dates['m_end']) : |
|
1271 | + $earnings_count += give_get_earnings_by_date(null, $month, $dates['year']); |
|
1272 | + $month++; |
|
1273 | 1273 | endwhile; |
1274 | 1274 | |
1275 | - $earnings['earnings'][ $args['date'] ] = $earnings_count; |
|
1275 | + $earnings['earnings'][$args['date']] = $earnings_count; |
|
1276 | 1276 | } else { |
1277 | - $earnings['earnings'][ $args['date'] ] = give_get_earnings_by_date( $dates['day'], $dates['m_start'], $dates['year'] ); |
|
1277 | + $earnings['earnings'][$args['date']] = give_get_earnings_by_date($dates['day'], $dates['m_start'], $dates['year']); |
|
1278 | 1278 | } |
1279 | 1279 | } |
1280 | - } elseif ( $args['form'] == 'all' ) { |
|
1281 | - $forms = get_posts( array( 'post_type' => 'give_forms', 'nopaging' => true ) ); |
|
1280 | + } elseif ($args['form'] == 'all') { |
|
1281 | + $forms = get_posts(array('post_type' => 'give_forms', 'nopaging' => true)); |
|
1282 | 1282 | |
1283 | 1283 | $i = 0; |
1284 | - foreach ( $forms as $form_info ) { |
|
1285 | - $earnings['earnings'][ $i ] = array( $form_info->post_name => give_get_form_earnings_stats( $form_info->ID ) ); |
|
1286 | - $i ++; |
|
1284 | + foreach ($forms as $form_info) { |
|
1285 | + $earnings['earnings'][$i] = array($form_info->post_name => give_get_form_earnings_stats($form_info->ID)); |
|
1286 | + $i++; |
|
1287 | 1287 | } |
1288 | 1288 | } else { |
1289 | - if ( get_post_type( $args['form'] ) == 'give_forms' ) { |
|
1290 | - $form_info = get_post( $args['form'] ); |
|
1291 | - $earnings['earnings'][0] = array( $form_info->post_name => give_get_form_earnings_stats( $args['form'] ) ); |
|
1289 | + if (get_post_type($args['form']) == 'give_forms') { |
|
1290 | + $form_info = get_post($args['form']); |
|
1291 | + $earnings['earnings'][0] = array($form_info->post_name => give_get_form_earnings_stats($args['form'])); |
|
1292 | 1292 | } else { |
1293 | - $error['error'] = sprintf( __( 'Form %s not found!', 'give' ), $args['form'] ); |
|
1293 | + $error['error'] = sprintf(__('Form %s not found!', 'give'), $args['form']); |
|
1294 | 1294 | } |
1295 | 1295 | } |
1296 | 1296 | |
1297 | - if ( ! empty( $error ) ) { |
|
1297 | + if ( ! empty($error)) { |
|
1298 | 1298 | return $error; |
1299 | 1299 | } |
1300 | 1300 | |
1301 | 1301 | return $earnings; |
1302 | - } elseif ( $args['type'] == 'donors' ) { |
|
1302 | + } elseif ($args['type'] == 'donors') { |
|
1303 | 1303 | $customers = new Give_DB_Customers(); |
1304 | 1304 | $stats['donations']['total_donors'] = $customers->count(); |
1305 | 1305 | |
1306 | 1306 | return $stats; |
1307 | 1307 | |
1308 | - } elseif ( empty( $args['type'] ) ) { |
|
1309 | - $stats = array_merge( $stats, $this->get_default_sales_stats() ); |
|
1310 | - $stats = array_merge( $stats, $this->get_default_earnings_stats() ); |
|
1308 | + } elseif (empty($args['type'])) { |
|
1309 | + $stats = array_merge($stats, $this->get_default_sales_stats()); |
|
1310 | + $stats = array_merge($stats, $this->get_default_earnings_stats()); |
|
1311 | 1311 | |
1312 | - return array( 'stats' => $stats ); |
|
1312 | + return array('stats' => $stats); |
|
1313 | 1313 | } |
1314 | 1314 | } |
1315 | 1315 | |
@@ -1325,18 +1325,18 @@ discard block |
||
1325 | 1325 | |
1326 | 1326 | $sales = array(); |
1327 | 1327 | |
1328 | - if ( ! user_can( $this->user_id, 'view_give_reports' ) && ! $this->override ) { |
|
1328 | + if ( ! user_can($this->user_id, 'view_give_reports') && ! $this->override) { |
|
1329 | 1329 | return $sales; |
1330 | 1330 | } |
1331 | 1331 | |
1332 | - if ( isset( $wp_query->query_vars['id'] ) ) { |
|
1332 | + if (isset($wp_query->query_vars['id'])) { |
|
1333 | 1333 | $query = array(); |
1334 | - $query[] = new Give_Payment( $wp_query->query_vars['id'] ); |
|
1335 | - } elseif ( isset( $wp_query->query_vars['purchasekey'] ) ) { |
|
1334 | + $query[] = new Give_Payment($wp_query->query_vars['id']); |
|
1335 | + } elseif (isset($wp_query->query_vars['purchasekey'])) { |
|
1336 | 1336 | $query = array(); |
1337 | - $query[] = give_get_payment_by( 'key', $wp_query->query_vars['purchasekey'] ); |
|
1338 | - } elseif ( isset( $wp_query->query_vars['email'] ) ) { |
|
1339 | - $args = array( |
|
1337 | + $query[] = give_get_payment_by('key', $wp_query->query_vars['purchasekey']); |
|
1338 | + } elseif (isset($wp_query->query_vars['email'])) { |
|
1339 | + $args = array( |
|
1340 | 1340 | 'fields' => 'ids', |
1341 | 1341 | 'meta_key' => '_give_payment_user_email', |
1342 | 1342 | 'meta_value' => $wp_query->query_vars['email'], |
@@ -1344,7 +1344,7 @@ discard block |
||
1344 | 1344 | 'page' => $this->get_paged(), |
1345 | 1345 | 'status' => 'publish' |
1346 | 1346 | ); |
1347 | - $query = give_get_payments( $args ); |
|
1347 | + $query = give_get_payments($args); |
|
1348 | 1348 | } else { |
1349 | 1349 | $args = array( |
1350 | 1350 | 'fields' => 'ids', |
@@ -1352,14 +1352,14 @@ discard block |
||
1352 | 1352 | 'page' => $this->get_paged(), |
1353 | 1353 | 'status' => 'publish' |
1354 | 1354 | ); |
1355 | - $query = give_get_payments( $args ); |
|
1355 | + $query = give_get_payments($args); |
|
1356 | 1356 | } |
1357 | - if ( $query ) { |
|
1357 | + if ($query) { |
|
1358 | 1358 | $i = 0; |
1359 | - foreach ( $query as $payment ) { |
|
1359 | + foreach ($query as $payment) { |
|
1360 | 1360 | |
1361 | - if ( is_numeric( $payment ) ) { |
|
1362 | - $payment = new Give_Payment( $payment ); |
|
1361 | + if (is_numeric($payment)) { |
|
1362 | + $payment = new Give_Payment($payment); |
|
1363 | 1363 | $payment_meta = $payment->get_meta(); |
1364 | 1364 | $user_info = $payment->user_info; |
1365 | 1365 | } else { |
@@ -1369,40 +1369,40 @@ discard block |
||
1369 | 1369 | $payment_meta = $payment->get_meta(); |
1370 | 1370 | $user_info = $payment->user_info; |
1371 | 1371 | |
1372 | - $first_name = isset( $user_info['first_name'] ) ? $user_info['first_name'] : ''; |
|
1373 | - $last_name = isset( $user_info['last_name'] ) ? $user_info['last_name'] : ''; |
|
1374 | - |
|
1375 | - $sales['donations'][ $i ]['ID'] = $payment->number; |
|
1376 | - $sales['donations'][ $i ]['transaction_id'] = $payment->transaction_id; |
|
1377 | - $sales['donations'][ $i ]['key'] = $payment->key; |
|
1378 | - $sales['donations'][ $i ]['total'] = $payment->total; |
|
1379 | - $sales['donations'][ $i ]['gateway'] = $payment->gateway; |
|
1380 | - $sales['donations'][ $i ]['name'] = $first_name . ' ' . $last_name; |
|
1381 | - $sales['donations'][ $i ]['fname'] = $first_name; |
|
1382 | - $sales['donations'][ $i ]['lname'] = $last_name; |
|
1383 | - $sales['donations'][ $i ]['email'] = $payment->email; |
|
1384 | - $sales['donations'][ $i ]['date'] = $payment->date; |
|
1385 | - |
|
1386 | - $form_id = isset( $payment_meta['form_id'] ) ? $payment_meta['form_id'] : $payment_meta; |
|
1387 | - $price = isset( $payment_meta['form_id'] ) ? give_get_form_price( $payment_meta['form_id'] ) : false; |
|
1388 | - $price_id = isset( $payment_meta['price_id'] ) ? $payment_meta['price_id'] : null; |
|
1389 | - |
|
1390 | - $sales['donations'][ $i ]['form']['id'] = $form_id; |
|
1391 | - $sales['donations'][ $i ]['form']['name'] = get_the_title( $payment_meta['form_id'] ); |
|
1392 | - $sales['donations'][ $i ]['form']['price'] = $price; |
|
1393 | - |
|
1394 | - if ( give_has_variable_prices( $form_id ) ) { |
|
1395 | - if ( isset( $payment_meta['price_id'] ) ) { |
|
1396 | - $price_name = give_get_price_option_name( $form_id, $payment_meta['price_id'], $payment->ID ); |
|
1397 | - $sales['donations'][ $i ]['form']['price_name'] = $price_name; |
|
1398 | - $sales['donations'][ $i ]['form']['price_id'] = $price_id; |
|
1399 | - $sales['donations'][ $i ]['form']['price'] = give_get_price_option_amount( $form_id, $price_id ); |
|
1372 | + $first_name = isset($user_info['first_name']) ? $user_info['first_name'] : ''; |
|
1373 | + $last_name = isset($user_info['last_name']) ? $user_info['last_name'] : ''; |
|
1374 | + |
|
1375 | + $sales['donations'][$i]['ID'] = $payment->number; |
|
1376 | + $sales['donations'][$i]['transaction_id'] = $payment->transaction_id; |
|
1377 | + $sales['donations'][$i]['key'] = $payment->key; |
|
1378 | + $sales['donations'][$i]['total'] = $payment->total; |
|
1379 | + $sales['donations'][$i]['gateway'] = $payment->gateway; |
|
1380 | + $sales['donations'][$i]['name'] = $first_name.' '.$last_name; |
|
1381 | + $sales['donations'][$i]['fname'] = $first_name; |
|
1382 | + $sales['donations'][$i]['lname'] = $last_name; |
|
1383 | + $sales['donations'][$i]['email'] = $payment->email; |
|
1384 | + $sales['donations'][$i]['date'] = $payment->date; |
|
1385 | + |
|
1386 | + $form_id = isset($payment_meta['form_id']) ? $payment_meta['form_id'] : $payment_meta; |
|
1387 | + $price = isset($payment_meta['form_id']) ? give_get_form_price($payment_meta['form_id']) : false; |
|
1388 | + $price_id = isset($payment_meta['price_id']) ? $payment_meta['price_id'] : null; |
|
1389 | + |
|
1390 | + $sales['donations'][$i]['form']['id'] = $form_id; |
|
1391 | + $sales['donations'][$i]['form']['name'] = get_the_title($payment_meta['form_id']); |
|
1392 | + $sales['donations'][$i]['form']['price'] = $price; |
|
1393 | + |
|
1394 | + if (give_has_variable_prices($form_id)) { |
|
1395 | + if (isset($payment_meta['price_id'])) { |
|
1396 | + $price_name = give_get_price_option_name($form_id, $payment_meta['price_id'], $payment->ID); |
|
1397 | + $sales['donations'][$i]['form']['price_name'] = $price_name; |
|
1398 | + $sales['donations'][$i]['form']['price_id'] = $price_id; |
|
1399 | + $sales['donations'][$i]['form']['price'] = give_get_price_option_amount($form_id, $price_id); |
|
1400 | 1400 | |
1401 | 1401 | } |
1402 | 1402 | } |
1403 | 1403 | |
1404 | 1404 | //Add custom meta to API |
1405 | - foreach ( $payment_meta as $meta_key => $meta_value ) { |
|
1405 | + foreach ($payment_meta as $meta_key => $meta_value) { |
|
1406 | 1406 | |
1407 | 1407 | $exceptions = array( |
1408 | 1408 | 'form_title', |
@@ -1415,19 +1415,19 @@ discard block |
||
1415 | 1415 | ); |
1416 | 1416 | |
1417 | 1417 | //Don't clutter up results with dupes |
1418 | - if ( in_array( $meta_key, $exceptions ) ) { |
|
1418 | + if (in_array($meta_key, $exceptions)) { |
|
1419 | 1419 | continue; |
1420 | 1420 | } |
1421 | 1421 | |
1422 | - $sales['donations'][ $i ]['payment_meta'][ $meta_key ] = $meta_value; |
|
1422 | + $sales['donations'][$i]['payment_meta'][$meta_key] = $meta_value; |
|
1423 | 1423 | |
1424 | 1424 | } |
1425 | 1425 | |
1426 | - $i ++; |
|
1426 | + $i++; |
|
1427 | 1427 | } |
1428 | 1428 | } |
1429 | 1429 | |
1430 | - return apply_filters( 'give_api_donations_endpoint', $sales ); |
|
1430 | + return apply_filters('give_api_donations_endpoint', $sales); |
|
1431 | 1431 | } |
1432 | 1432 | |
1433 | 1433 | /** |
@@ -1442,9 +1442,9 @@ discard block |
||
1442 | 1442 | public function get_output_format() { |
1443 | 1443 | global $wp_query; |
1444 | 1444 | |
1445 | - $format = isset( $wp_query->query_vars['format'] ) ? $wp_query->query_vars['format'] : 'json'; |
|
1445 | + $format = isset($wp_query->query_vars['format']) ? $wp_query->query_vars['format'] : 'json'; |
|
1446 | 1446 | |
1447 | - return apply_filters( 'give_api_output_format', $format ); |
|
1447 | + return apply_filters('give_api_output_format', $format); |
|
1448 | 1448 | } |
1449 | 1449 | |
1450 | 1450 | |
@@ -1460,8 +1460,8 @@ discard block |
||
1460 | 1460 | * |
1461 | 1461 | * @return void |
1462 | 1462 | */ |
1463 | - private function log_request( $data = array() ) { |
|
1464 | - if ( ! $this->log_requests ) { |
|
1463 | + private function log_request($data = array()) { |
|
1464 | + if ( ! $this->log_requests) { |
|
1465 | 1465 | return; |
1466 | 1466 | } |
1467 | 1467 | |
@@ -1469,36 +1469,36 @@ discard block |
||
1469 | 1469 | |
1470 | 1470 | $query = array( |
1471 | 1471 | 'give-api' => $wp_query->query_vars['give-api'], |
1472 | - 'key' => isset( $wp_query->query_vars['key'] ) ? $wp_query->query_vars['key'] : null, |
|
1473 | - 'token' => isset( $wp_query->query_vars['token'] ) ? $wp_query->query_vars['token'] : null, |
|
1474 | - 'query' => isset( $wp_query->query_vars['query'] ) ? $wp_query->query_vars['query'] : null, |
|
1475 | - 'type' => isset( $wp_query->query_vars['type'] ) ? $wp_query->query_vars['type'] : null, |
|
1476 | - 'form' => isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null, |
|
1477 | - 'customer' => isset( $wp_query->query_vars['customer'] ) ? $wp_query->query_vars['customer'] : null, |
|
1478 | - 'date' => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null, |
|
1479 | - 'startdate' => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null, |
|
1480 | - 'enddate' => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null, |
|
1481 | - 'id' => isset( $wp_query->query_vars['id'] ) ? $wp_query->query_vars['id'] : null, |
|
1482 | - 'purchasekey' => isset( $wp_query->query_vars['purchasekey'] ) ? $wp_query->query_vars['purchasekey'] : null, |
|
1483 | - 'email' => isset( $wp_query->query_vars['email'] ) ? $wp_query->query_vars['email'] : null, |
|
1472 | + 'key' => isset($wp_query->query_vars['key']) ? $wp_query->query_vars['key'] : null, |
|
1473 | + 'token' => isset($wp_query->query_vars['token']) ? $wp_query->query_vars['token'] : null, |
|
1474 | + 'query' => isset($wp_query->query_vars['query']) ? $wp_query->query_vars['query'] : null, |
|
1475 | + 'type' => isset($wp_query->query_vars['type']) ? $wp_query->query_vars['type'] : null, |
|
1476 | + 'form' => isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null, |
|
1477 | + 'customer' => isset($wp_query->query_vars['customer']) ? $wp_query->query_vars['customer'] : null, |
|
1478 | + 'date' => isset($wp_query->query_vars['date']) ? $wp_query->query_vars['date'] : null, |
|
1479 | + 'startdate' => isset($wp_query->query_vars['startdate']) ? $wp_query->query_vars['startdate'] : null, |
|
1480 | + 'enddate' => isset($wp_query->query_vars['enddate']) ? $wp_query->query_vars['enddate'] : null, |
|
1481 | + 'id' => isset($wp_query->query_vars['id']) ? $wp_query->query_vars['id'] : null, |
|
1482 | + 'purchasekey' => isset($wp_query->query_vars['purchasekey']) ? $wp_query->query_vars['purchasekey'] : null, |
|
1483 | + 'email' => isset($wp_query->query_vars['email']) ? $wp_query->query_vars['email'] : null, |
|
1484 | 1484 | ); |
1485 | 1485 | |
1486 | 1486 | $log_data = array( |
1487 | 1487 | 'log_type' => 'api_request', |
1488 | - 'post_excerpt' => http_build_query( $query ), |
|
1489 | - 'post_content' => ! empty( $data['error'] ) ? $data['error'] : '', |
|
1488 | + 'post_excerpt' => http_build_query($query), |
|
1489 | + 'post_content' => ! empty($data['error']) ? $data['error'] : '', |
|
1490 | 1490 | ); |
1491 | 1491 | |
1492 | 1492 | $log_meta = array( |
1493 | 1493 | 'request_ip' => give_get_ip(), |
1494 | 1494 | 'user' => $this->user_id, |
1495 | - 'key' => isset( $wp_query->query_vars['key'] ) ? $wp_query->query_vars['key'] : null, |
|
1496 | - 'token' => isset( $wp_query->query_vars['token'] ) ? $wp_query->query_vars['token'] : null, |
|
1495 | + 'key' => isset($wp_query->query_vars['key']) ? $wp_query->query_vars['key'] : null, |
|
1496 | + 'token' => isset($wp_query->query_vars['token']) ? $wp_query->query_vars['token'] : null, |
|
1497 | 1497 | 'time' => $data['request_speed'], |
1498 | 1498 | 'version' => $this->get_queried_version() |
1499 | 1499 | ); |
1500 | 1500 | |
1501 | - $give_logs->insert_log( $log_data, $log_meta ); |
|
1501 | + $give_logs->insert_log($log_data, $log_meta); |
|
1502 | 1502 | } |
1503 | 1503 | |
1504 | 1504 | |
@@ -1522,32 +1522,32 @@ discard block |
||
1522 | 1522 | * |
1523 | 1523 | * @param int $status_code |
1524 | 1524 | */ |
1525 | - public function output( $status_code = 200 ) { |
|
1525 | + public function output($status_code = 200) { |
|
1526 | 1526 | global $wp_query; |
1527 | 1527 | |
1528 | 1528 | $format = $this->get_output_format(); |
1529 | 1529 | |
1530 | - status_header( $status_code ); |
|
1530 | + status_header($status_code); |
|
1531 | 1531 | |
1532 | - do_action( 'give_api_output_before', $this->data, $this, $format ); |
|
1532 | + do_action('give_api_output_before', $this->data, $this, $format); |
|
1533 | 1533 | |
1534 | - switch ( $format ) : |
|
1534 | + switch ($format) : |
|
1535 | 1535 | |
1536 | 1536 | case 'xml' : |
1537 | 1537 | |
1538 | - require_once GIVE_PLUGIN_DIR . 'includes/libraries/array2xml.php'; |
|
1539 | - $xml = Array2XML::createXML( 'give', $this->data ); |
|
1538 | + require_once GIVE_PLUGIN_DIR.'includes/libraries/array2xml.php'; |
|
1539 | + $xml = Array2XML::createXML('give', $this->data); |
|
1540 | 1540 | echo $xml->saveXML(); |
1541 | 1541 | |
1542 | 1542 | break; |
1543 | 1543 | |
1544 | 1544 | case 'json' : |
1545 | 1545 | |
1546 | - header( 'Content-Type: application/json' ); |
|
1547 | - if ( ! empty( $this->pretty_print ) ) { |
|
1548 | - echo json_encode( $this->data, $this->pretty_print ); |
|
1546 | + header('Content-Type: application/json'); |
|
1547 | + if ( ! empty($this->pretty_print)) { |
|
1548 | + echo json_encode($this->data, $this->pretty_print); |
|
1549 | 1549 | } else { |
1550 | - echo json_encode( $this->data ); |
|
1550 | + echo json_encode($this->data); |
|
1551 | 1551 | } |
1552 | 1552 | |
1553 | 1553 | break; |
@@ -1556,13 +1556,13 @@ discard block |
||
1556 | 1556 | default : |
1557 | 1557 | |
1558 | 1558 | // Allow other formats to be added via extensions |
1559 | - do_action( 'give_api_output_' . $format, $this->data, $this ); |
|
1559 | + do_action('give_api_output_'.$format, $this->data, $this); |
|
1560 | 1560 | |
1561 | 1561 | break; |
1562 | 1562 | |
1563 | 1563 | endswitch; |
1564 | 1564 | |
1565 | - do_action( 'give_api_output_after', $this->data, $this, $format ); |
|
1565 | + do_action('give_api_output_after', $this->data, $this, $format); |
|
1566 | 1566 | |
1567 | 1567 | give_die(); |
1568 | 1568 | } |
@@ -1579,37 +1579,37 @@ discard block |
||
1579 | 1579 | * |
1580 | 1580 | * @return void |
1581 | 1581 | */ |
1582 | - function user_key_field( $user ) { |
|
1582 | + function user_key_field($user) { |
|
1583 | 1583 | |
1584 | - if ( ( give_get_option( 'api_allow_user_keys', false ) || current_user_can( 'manage_give_settings' ) ) && current_user_can( 'edit_user', $user->ID ) ) { |
|
1585 | - $user = get_userdata( $user->ID ); |
|
1584 | + if ((give_get_option('api_allow_user_keys', false) || current_user_can('manage_give_settings')) && current_user_can('edit_user', $user->ID)) { |
|
1585 | + $user = get_userdata($user->ID); |
|
1586 | 1586 | ?> |
1587 | 1587 | <table class="form-table"> |
1588 | 1588 | <tbody> |
1589 | 1589 | <tr> |
1590 | 1590 | <th> |
1591 | - <?php esc_attr_e( 'Give API Keys', 'give' ); ?> |
|
1591 | + <?php esc_attr_e('Give API Keys', 'give'); ?> |
|
1592 | 1592 | </th> |
1593 | 1593 | <td> |
1594 | 1594 | <?php |
1595 | - $public_key = $this->get_user_public_key( $user->ID ); |
|
1596 | - $secret_key = $this->get_user_secret_key( $user->ID ); |
|
1595 | + $public_key = $this->get_user_public_key($user->ID); |
|
1596 | + $secret_key = $this->get_user_secret_key($user->ID); |
|
1597 | 1597 | ?> |
1598 | - <?php if ( empty( $user->give_user_public_key ) ) { ?> |
|
1598 | + <?php if (empty($user->give_user_public_key)) { ?> |
|
1599 | 1599 | <input name="give_set_api_key" type="checkbox" id="give_set_api_key" value="0"/> |
1600 | - <span class="description"><?php esc_attr_e( 'Generate API Key', 'give' ); ?></span> |
|
1600 | + <span class="description"><?php esc_attr_e('Generate API Key', 'give'); ?></span> |
|
1601 | 1601 | <?php } else { ?> |
1602 | - <strong style="display:inline-block; width: 125px;"><?php _e( 'Public key:', 'give' ); ?> </strong> |
|
1603 | - <input type="text" disabled="disabled" class="regular-text" id="publickey" value="<?php echo esc_attr( $public_key ); ?>"/> |
|
1602 | + <strong style="display:inline-block; width: 125px;"><?php _e('Public key:', 'give'); ?> </strong> |
|
1603 | + <input type="text" disabled="disabled" class="regular-text" id="publickey" value="<?php echo esc_attr($public_key); ?>"/> |
|
1604 | 1604 | <br/> |
1605 | - <strong style="display:inline-block; width: 125px;"><?php esc_attr_e( 'Secret key:', 'give' ); ?> </strong> |
|
1606 | - <input type="text" disabled="disabled" class="regular-text" id="privatekey" value="<?php echo esc_attr( $secret_key ); ?>"/> |
|
1605 | + <strong style="display:inline-block; width: 125px;"><?php esc_attr_e('Secret key:', 'give'); ?> </strong> |
|
1606 | + <input type="text" disabled="disabled" class="regular-text" id="privatekey" value="<?php echo esc_attr($secret_key); ?>"/> |
|
1607 | 1607 | <br/> |
1608 | - <strong style="display:inline-block; width: 125px;"><?php esc_attr_e( 'Token:', 'give' ); ?> </strong> |
|
1609 | - <input type="text" disabled="disabled" class="regular-text" id="token" value="<?php echo esc_attr( $this->get_token( $user->ID ) ); ?>"/> |
|
1608 | + <strong style="display:inline-block; width: 125px;"><?php esc_attr_e('Token:', 'give'); ?> </strong> |
|
1609 | + <input type="text" disabled="disabled" class="regular-text" id="token" value="<?php echo esc_attr($this->get_token($user->ID)); ?>"/> |
|
1610 | 1610 | <br/> |
1611 | 1611 | <input name="give_set_api_key" type="checkbox" id="give_set_api_key" value="0"/> |
1612 | - <span class="description"><label for="give_set_api_key"><?php esc_attr_e( 'Revoke API Keys', 'give' ); ?></label></span> |
|
1612 | + <span class="description"><label for="give_set_api_key"><?php esc_attr_e('Revoke API Keys', 'give'); ?></label></span> |
|
1613 | 1613 | <?php } ?> |
1614 | 1614 | </td> |
1615 | 1615 | </tr> |
@@ -1628,53 +1628,53 @@ discard block |
||
1628 | 1628 | * |
1629 | 1629 | * @return void |
1630 | 1630 | */ |
1631 | - public function process_api_key( $args ) { |
|
1631 | + public function process_api_key($args) { |
|
1632 | 1632 | |
1633 | - if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'give-api-nonce' ) ) { |
|
1633 | + if ( ! wp_verify_nonce($_REQUEST['_wpnonce'], 'give-api-nonce')) { |
|
1634 | 1634 | |
1635 | - wp_die( esc_attr__( 'Nonce verification failed', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
1635 | + wp_die(esc_attr__('Nonce verification failed', 'give'), __('Error', 'give'), array('response' => 403)); |
|
1636 | 1636 | |
1637 | 1637 | } |
1638 | 1638 | |
1639 | - if ( empty( $args['user_id'] ) ) { |
|
1640 | - wp_die( esc_attr__( 'User ID Required', 'give' ), esc_attr__( 'Error', 'give' ), array( 'response' => 401 ) ); |
|
1639 | + if (empty($args['user_id'])) { |
|
1640 | + wp_die(esc_attr__('User ID Required', 'give'), esc_attr__('Error', 'give'), array('response' => 401)); |
|
1641 | 1641 | } |
1642 | 1642 | |
1643 | - if ( is_numeric( $args['user_id'] ) ) { |
|
1644 | - $user_id = isset( $args['user_id'] ) ? absint( $args['user_id'] ) : get_current_user_id(); |
|
1643 | + if (is_numeric($args['user_id'])) { |
|
1644 | + $user_id = isset($args['user_id']) ? absint($args['user_id']) : get_current_user_id(); |
|
1645 | 1645 | } else { |
1646 | - $userdata = get_user_by( 'login', $args['user_id'] ); |
|
1646 | + $userdata = get_user_by('login', $args['user_id']); |
|
1647 | 1647 | $user_id = $userdata->ID; |
1648 | 1648 | } |
1649 | - $process = isset( $args['give_api_process'] ) ? strtolower( $args['give_api_process'] ) : false; |
|
1649 | + $process = isset($args['give_api_process']) ? strtolower($args['give_api_process']) : false; |
|
1650 | 1650 | |
1651 | - if ( $user_id == get_current_user_id() && ! give_get_option( 'allow_user_api_keys' ) && ! current_user_can( 'manage_give_settings' ) ) { |
|
1652 | - wp_die( sprintf( __( 'You do not have permission to %s API keys for this user', 'give' ), $process ), __( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
1653 | - } elseif ( ! current_user_can( 'manage_give_settings' ) ) { |
|
1654 | - wp_die( sprintf( __( 'You do not have permission to %s API keys for this user', 'give' ), $process ), __( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
1651 | + if ($user_id == get_current_user_id() && ! give_get_option('allow_user_api_keys') && ! current_user_can('manage_give_settings')) { |
|
1652 | + wp_die(sprintf(__('You do not have permission to %s API keys for this user', 'give'), $process), __('Error', 'give'), array('response' => 403)); |
|
1653 | + } elseif ( ! current_user_can('manage_give_settings')) { |
|
1654 | + wp_die(sprintf(__('You do not have permission to %s API keys for this user', 'give'), $process), __('Error', 'give'), array('response' => 403)); |
|
1655 | 1655 | } |
1656 | 1656 | |
1657 | - switch ( $process ) { |
|
1657 | + switch ($process) { |
|
1658 | 1658 | case 'generate': |
1659 | - if ( $this->generate_api_key( $user_id ) ) { |
|
1660 | - delete_transient( 'give-total-api-keys' ); |
|
1661 | - wp_redirect( add_query_arg( 'give-message', 'api-key-generated', 'edit.php?post_type=give_forms&page=give-settings&tab=api' ) ); |
|
1659 | + if ($this->generate_api_key($user_id)) { |
|
1660 | + delete_transient('give-total-api-keys'); |
|
1661 | + wp_redirect(add_query_arg('give-message', 'api-key-generated', 'edit.php?post_type=give_forms&page=give-settings&tab=api')); |
|
1662 | 1662 | exit(); |
1663 | 1663 | } else { |
1664 | - wp_redirect( add_query_arg( 'give-message', 'api-key-failed', 'edit.php?post_type=give_forms&page=give-settings&tab=api' ) ); |
|
1664 | + wp_redirect(add_query_arg('give-message', 'api-key-failed', 'edit.php?post_type=give_forms&page=give-settings&tab=api')); |
|
1665 | 1665 | exit(); |
1666 | 1666 | } |
1667 | 1667 | break; |
1668 | 1668 | case 'regenerate': |
1669 | - $this->generate_api_key( $user_id, true ); |
|
1670 | - delete_transient( 'give-total-api-keys' ); |
|
1671 | - wp_redirect( add_query_arg( 'give-message', 'api-key-regenerated', 'edit.php?post_type=give_forms&page=give-settings&tab=api' ) ); |
|
1669 | + $this->generate_api_key($user_id, true); |
|
1670 | + delete_transient('give-total-api-keys'); |
|
1671 | + wp_redirect(add_query_arg('give-message', 'api-key-regenerated', 'edit.php?post_type=give_forms&page=give-settings&tab=api')); |
|
1672 | 1672 | exit(); |
1673 | 1673 | break; |
1674 | 1674 | case 'revoke': |
1675 | - $this->revoke_api_key( $user_id ); |
|
1676 | - delete_transient( 'give-total-api-keys' ); |
|
1677 | - wp_redirect( add_query_arg( 'give-message', 'api-key-revoked', 'edit.php?post_type=give_forms&page=give-settings&tab=api' ) ); |
|
1675 | + $this->revoke_api_key($user_id); |
|
1676 | + delete_transient('give-total-api-keys'); |
|
1677 | + wp_redirect(add_query_arg('give-message', 'api-key-revoked', 'edit.php?post_type=give_forms&page=give-settings&tab=api')); |
|
1678 | 1678 | exit(); |
1679 | 1679 | break; |
1680 | 1680 | default; |
@@ -1693,34 +1693,34 @@ discard block |
||
1693 | 1693 | * |
1694 | 1694 | * @return boolean True if (re)generated succesfully, false otherwise. |
1695 | 1695 | */ |
1696 | - public function generate_api_key( $user_id = 0, $regenerate = false ) { |
|
1696 | + public function generate_api_key($user_id = 0, $regenerate = false) { |
|
1697 | 1697 | |
1698 | - if ( empty( $user_id ) ) { |
|
1698 | + if (empty($user_id)) { |
|
1699 | 1699 | return false; |
1700 | 1700 | } |
1701 | 1701 | |
1702 | - $user = get_userdata( $user_id ); |
|
1702 | + $user = get_userdata($user_id); |
|
1703 | 1703 | |
1704 | - if ( ! $user ) { |
|
1704 | + if ( ! $user) { |
|
1705 | 1705 | return false; |
1706 | 1706 | } |
1707 | 1707 | |
1708 | - $public_key = $this->get_user_public_key( $user_id ); |
|
1709 | - $secret_key = $this->get_user_secret_key( $user_id ); |
|
1708 | + $public_key = $this->get_user_public_key($user_id); |
|
1709 | + $secret_key = $this->get_user_secret_key($user_id); |
|
1710 | 1710 | |
1711 | - if ( empty( $public_key ) || $regenerate == true ) { |
|
1712 | - $new_public_key = $this->generate_public_key( $user->user_email ); |
|
1713 | - $new_secret_key = $this->generate_private_key( $user->ID ); |
|
1711 | + if (empty($public_key) || $regenerate == true) { |
|
1712 | + $new_public_key = $this->generate_public_key($user->user_email); |
|
1713 | + $new_secret_key = $this->generate_private_key($user->ID); |
|
1714 | 1714 | } else { |
1715 | 1715 | return false; |
1716 | 1716 | } |
1717 | 1717 | |
1718 | - if ( $regenerate == true ) { |
|
1719 | - $this->revoke_api_key( $user->ID ); |
|
1718 | + if ($regenerate == true) { |
|
1719 | + $this->revoke_api_key($user->ID); |
|
1720 | 1720 | } |
1721 | 1721 | |
1722 | - update_user_meta( $user_id, $new_public_key, 'give_user_public_key' ); |
|
1723 | - update_user_meta( $user_id, $new_secret_key, 'give_user_secret_key' ); |
|
1722 | + update_user_meta($user_id, $new_public_key, 'give_user_public_key'); |
|
1723 | + update_user_meta($user_id, $new_secret_key, 'give_user_secret_key'); |
|
1724 | 1724 | |
1725 | 1725 | return true; |
1726 | 1726 | } |
@@ -1735,26 +1735,26 @@ discard block |
||
1735 | 1735 | * |
1736 | 1736 | * @return string |
1737 | 1737 | */ |
1738 | - public function revoke_api_key( $user_id = 0 ) { |
|
1738 | + public function revoke_api_key($user_id = 0) { |
|
1739 | 1739 | |
1740 | - if ( empty( $user_id ) ) { |
|
1740 | + if (empty($user_id)) { |
|
1741 | 1741 | return false; |
1742 | 1742 | } |
1743 | 1743 | |
1744 | - $user = get_userdata( $user_id ); |
|
1744 | + $user = get_userdata($user_id); |
|
1745 | 1745 | |
1746 | - if ( ! $user ) { |
|
1746 | + if ( ! $user) { |
|
1747 | 1747 | return false; |
1748 | 1748 | } |
1749 | 1749 | |
1750 | - $public_key = $this->get_user_public_key( $user_id ); |
|
1751 | - $secret_key = $this->get_user_secret_key( $user_id ); |
|
1752 | - if ( ! empty( $public_key ) ) { |
|
1753 | - delete_transient( md5( 'give_api_user_' . $public_key ) ); |
|
1754 | - delete_transient( md5( 'give_api_user_public_key' . $user_id ) ); |
|
1755 | - delete_transient( md5( 'give_api_user_secret_key' . $user_id ) ); |
|
1756 | - delete_user_meta( $user_id, $public_key ); |
|
1757 | - delete_user_meta( $user_id, $secret_key ); |
|
1750 | + $public_key = $this->get_user_public_key($user_id); |
|
1751 | + $secret_key = $this->get_user_secret_key($user_id); |
|
1752 | + if ( ! empty($public_key)) { |
|
1753 | + delete_transient(md5('give_api_user_'.$public_key)); |
|
1754 | + delete_transient(md5('give_api_user_public_key'.$user_id)); |
|
1755 | + delete_transient(md5('give_api_user_secret_key'.$user_id)); |
|
1756 | + delete_user_meta($user_id, $public_key); |
|
1757 | + delete_user_meta($user_id, $secret_key); |
|
1758 | 1758 | } else { |
1759 | 1759 | return false; |
1760 | 1760 | } |
@@ -1779,22 +1779,22 @@ discard block |
||
1779 | 1779 | * |
1780 | 1780 | * @return void |
1781 | 1781 | */ |
1782 | - public function update_key( $user_id ) { |
|
1783 | - if ( current_user_can( 'edit_user', $user_id ) && isset( $_POST['give_set_api_key'] ) ) { |
|
1782 | + public function update_key($user_id) { |
|
1783 | + if (current_user_can('edit_user', $user_id) && isset($_POST['give_set_api_key'])) { |
|
1784 | 1784 | |
1785 | - $user = get_userdata( $user_id ); |
|
1785 | + $user = get_userdata($user_id); |
|
1786 | 1786 | |
1787 | - $public_key = $this->get_user_public_key( $user_id ); |
|
1788 | - $secret_key = $this->get_user_secret_key( $user_id ); |
|
1787 | + $public_key = $this->get_user_public_key($user_id); |
|
1788 | + $secret_key = $this->get_user_secret_key($user_id); |
|
1789 | 1789 | |
1790 | - if ( empty( $public_key ) ) { |
|
1791 | - $new_public_key = $this->generate_public_key( $user->user_email ); |
|
1792 | - $new_secret_key = $this->generate_private_key( $user->ID ); |
|
1790 | + if (empty($public_key)) { |
|
1791 | + $new_public_key = $this->generate_public_key($user->user_email); |
|
1792 | + $new_secret_key = $this->generate_private_key($user->ID); |
|
1793 | 1793 | |
1794 | - update_user_meta( $user_id, $new_public_key, 'give_user_public_key' ); |
|
1795 | - update_user_meta( $user_id, $new_secret_key, 'give_user_secret_key' ); |
|
1794 | + update_user_meta($user_id, $new_public_key, 'give_user_public_key'); |
|
1795 | + update_user_meta($user_id, $new_secret_key, 'give_user_secret_key'); |
|
1796 | 1796 | } else { |
1797 | - $this->revoke_api_key( $user_id ); |
|
1797 | + $this->revoke_api_key($user_id); |
|
1798 | 1798 | } |
1799 | 1799 | } |
1800 | 1800 | } |
@@ -1809,9 +1809,9 @@ discard block |
||
1809 | 1809 | * |
1810 | 1810 | * @return string |
1811 | 1811 | */ |
1812 | - private function generate_public_key( $user_email = '' ) { |
|
1813 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
1814 | - $public = hash( 'md5', $user_email . $auth_key . date( 'U' ) ); |
|
1812 | + private function generate_public_key($user_email = '') { |
|
1813 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
1814 | + $public = hash('md5', $user_email.$auth_key.date('U')); |
|
1815 | 1815 | |
1816 | 1816 | return $public; |
1817 | 1817 | } |
@@ -1826,9 +1826,9 @@ discard block |
||
1826 | 1826 | * |
1827 | 1827 | * @return string |
1828 | 1828 | */ |
1829 | - private function generate_private_key( $user_id = 0 ) { |
|
1830 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
1831 | - $secret = hash( 'md5', $user_id . $auth_key . date( 'U' ) ); |
|
1829 | + private function generate_private_key($user_id = 0) { |
|
1830 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
1831 | + $secret = hash('md5', $user_id.$auth_key.date('U')); |
|
1832 | 1832 | |
1833 | 1833 | return $secret; |
1834 | 1834 | } |
@@ -1843,8 +1843,8 @@ discard block |
||
1843 | 1843 | * |
1844 | 1844 | * @return string |
1845 | 1845 | */ |
1846 | - public function get_token( $user_id = 0 ) { |
|
1847 | - return hash( 'md5', $this->get_user_secret_key( $user_id ) . $this->get_user_public_key( $user_id ) ); |
|
1846 | + public function get_token($user_id = 0) { |
|
1847 | + return hash('md5', $this->get_user_secret_key($user_id).$this->get_user_public_key($user_id)); |
|
1848 | 1848 | } |
1849 | 1849 | |
1850 | 1850 | /** |
@@ -1858,9 +1858,9 @@ discard block |
||
1858 | 1858 | |
1859 | 1859 | // Default sales return |
1860 | 1860 | $sales = array(); |
1861 | - $sales['donations']['today'] = $this->stats->get_sales( 0, 'today' ); |
|
1862 | - $sales['donations']['current_month'] = $this->stats->get_sales( 0, 'this_month' ); |
|
1863 | - $sales['donations']['last_month'] = $this->stats->get_sales( 0, 'last_month' ); |
|
1861 | + $sales['donations']['today'] = $this->stats->get_sales(0, 'today'); |
|
1862 | + $sales['donations']['current_month'] = $this->stats->get_sales(0, 'this_month'); |
|
1863 | + $sales['donations']['last_month'] = $this->stats->get_sales(0, 'last_month'); |
|
1864 | 1864 | $sales['donations']['totals'] = give_get_total_sales(); |
1865 | 1865 | |
1866 | 1866 | return $sales; |
@@ -1877,9 +1877,9 @@ discard block |
||
1877 | 1877 | |
1878 | 1878 | // Default earnings return |
1879 | 1879 | $earnings = array(); |
1880 | - $earnings['earnings']['today'] = $this->stats->get_earnings( 0, 'today' ); |
|
1881 | - $earnings['earnings']['current_month'] = $this->stats->get_earnings( 0, 'this_month' ); |
|
1882 | - $earnings['earnings']['last_month'] = $this->stats->get_earnings( 0, 'last_month' ); |
|
1880 | + $earnings['earnings']['today'] = $this->stats->get_earnings(0, 'today'); |
|
1881 | + $earnings['earnings']['current_month'] = $this->stats->get_earnings(0, 'this_month'); |
|
1882 | + $earnings['earnings']['last_month'] = $this->stats->get_earnings(0, 'last_month'); |
|
1883 | 1883 | $earnings['earnings']['totals'] = give_get_total_earnings(); |
1884 | 1884 | |
1885 | 1885 | return $earnings; |
@@ -1899,25 +1899,25 @@ discard block |
||
1899 | 1899 | * |
1900 | 1900 | * @return string The API key/secret for the user supplied |
1901 | 1901 | */ |
1902 | - public function api_key_backwards_compat( $check, $object_id, $meta_key, $single ) { |
|
1902 | + public function api_key_backwards_compat($check, $object_id, $meta_key, $single) { |
|
1903 | 1903 | |
1904 | - if ( $meta_key !== 'give_user_public_key' && $meta_key !== 'give_user_secret_key' ) { |
|
1904 | + if ($meta_key !== 'give_user_public_key' && $meta_key !== 'give_user_secret_key') { |
|
1905 | 1905 | return $check; |
1906 | 1906 | } |
1907 | 1907 | |
1908 | 1908 | $return = $check; |
1909 | 1909 | |
1910 | - switch ( $meta_key ) { |
|
1910 | + switch ($meta_key) { |
|
1911 | 1911 | case 'give_user_public_key': |
1912 | - $return = Give()->api->get_user_public_key( $object_id ); |
|
1912 | + $return = Give()->api->get_user_public_key($object_id); |
|
1913 | 1913 | break; |
1914 | 1914 | case 'give_user_secret_key': |
1915 | - $return = Give()->api->get_user_secret_key( $object_id ); |
|
1915 | + $return = Give()->api->get_user_secret_key($object_id); |
|
1916 | 1916 | break; |
1917 | 1917 | } |
1918 | 1918 | |
1919 | - if ( ! $single ) { |
|
1920 | - $return = array( $return ); |
|
1919 | + if ( ! $single) { |
|
1920 | + $return = array($return); |
|
1921 | 1921 | } |
1922 | 1922 | |
1923 | 1923 | return $return; |