@@ -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 | |
@@ -26,26 +26,26 @@ discard block |
||
26 | 26 | function give_test_ajax_works() { |
27 | 27 | |
28 | 28 | // Check if the Airplane Mode plugin is installed. |
29 | - if ( class_exists( 'Airplane_Mode_Core' ) ) { |
|
29 | + if (class_exists('Airplane_Mode_Core')) { |
|
30 | 30 | |
31 | 31 | $airplane = Airplane_Mode_Core::getInstance(); |
32 | 32 | |
33 | - if ( method_exists( $airplane, 'enabled' ) ) { |
|
33 | + if (method_exists($airplane, 'enabled')) { |
|
34 | 34 | |
35 | - if ( $airplane->enabled() ) { |
|
35 | + if ($airplane->enabled()) { |
|
36 | 36 | return true; |
37 | 37 | } |
38 | 38 | } else { |
39 | 39 | |
40 | - if ( 'on' === $airplane->check_status() ) { |
|
40 | + if ('on' === $airplane->check_status()) { |
|
41 | 41 | return true; |
42 | 42 | } |
43 | 43 | } |
44 | 44 | } |
45 | 45 | |
46 | - add_filter( 'block_local_requests', '__return_false' ); |
|
46 | + add_filter('block_local_requests', '__return_false'); |
|
47 | 47 | |
48 | - if ( Give_Cache::get( '_give_ajax_works', true ) ) { |
|
48 | + if (Give_Cache::get('_give_ajax_works', true)) { |
|
49 | 49 | return true; |
50 | 50 | } |
51 | 51 | |
@@ -57,35 +57,35 @@ discard block |
||
57 | 57 | ), |
58 | 58 | ); |
59 | 59 | |
60 | - $ajax = wp_remote_post( give_get_ajax_url(), $params ); |
|
60 | + $ajax = wp_remote_post(give_get_ajax_url(), $params); |
|
61 | 61 | |
62 | 62 | $works = true; |
63 | 63 | |
64 | - if ( is_wp_error( $ajax ) ) { |
|
64 | + if (is_wp_error($ajax)) { |
|
65 | 65 | |
66 | 66 | $works = false; |
67 | 67 | |
68 | 68 | } else { |
69 | 69 | |
70 | - if ( empty( $ajax['response'] ) ) { |
|
70 | + if (empty($ajax['response'])) { |
|
71 | 71 | $works = false; |
72 | 72 | } |
73 | 73 | |
74 | - if ( empty( $ajax['response']['code'] ) || 200 !== (int) $ajax['response']['code'] ) { |
|
74 | + if (empty($ajax['response']['code']) || 200 !== (int) $ajax['response']['code']) { |
|
75 | 75 | $works = false; |
76 | 76 | } |
77 | 77 | |
78 | - if ( empty( $ajax['response']['message'] ) || 'OK' !== $ajax['response']['message'] ) { |
|
78 | + if (empty($ajax['response']['message']) || 'OK' !== $ajax['response']['message']) { |
|
79 | 79 | $works = false; |
80 | 80 | } |
81 | 81 | |
82 | - if ( ! isset( $ajax['body'] ) || 0 !== (int) $ajax['body'] ) { |
|
82 | + if ( ! isset($ajax['body']) || 0 !== (int) $ajax['body']) { |
|
83 | 83 | $works = false; |
84 | 84 | } |
85 | 85 | } |
86 | 86 | |
87 | - if ( $works ) { |
|
88 | - Give_Cache::set( '_give_ajax_works', '1', DAY_IN_SECONDS, true ); |
|
87 | + if ($works) { |
|
88 | + Give_Cache::set('_give_ajax_works', '1', DAY_IN_SECONDS, true); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | return $works; |
@@ -100,16 +100,16 @@ discard block |
||
100 | 100 | * @return string |
101 | 101 | */ |
102 | 102 | function give_get_ajax_url() { |
103 | - $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
103 | + $scheme = defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
104 | 104 | |
105 | 105 | $current_url = give_get_current_page_url(); |
106 | - $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
106 | + $ajax_url = admin_url('admin-ajax.php', $scheme); |
|
107 | 107 | |
108 | - if ( preg_match( '/^https/', $current_url ) && ! preg_match( '/^https/', $ajax_url ) ) { |
|
109 | - $ajax_url = preg_replace( '/^http/', 'https', $ajax_url ); |
|
108 | + if (preg_match('/^https/', $current_url) && ! preg_match('/^https/', $ajax_url)) { |
|
109 | + $ajax_url = preg_replace('/^http/', 'https', $ajax_url); |
|
110 | 110 | } |
111 | 111 | |
112 | - return apply_filters( 'give_ajax_url', $ajax_url ); |
|
112 | + return apply_filters('give_ajax_url', $ajax_url); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -125,12 +125,12 @@ discard block |
||
125 | 125 | * |
126 | 126 | * @since 1.7 |
127 | 127 | */ |
128 | - do_action( 'give_donation_form_login_fields' ); |
|
128 | + do_action('give_donation_form_login_fields'); |
|
129 | 129 | |
130 | 130 | give_die(); |
131 | 131 | } |
132 | 132 | |
133 | -add_action( 'wp_ajax_nopriv_give_checkout_login', 'give_load_checkout_login_fields' ); |
|
133 | +add_action('wp_ajax_nopriv_give_checkout_login', 'give_load_checkout_login_fields'); |
|
134 | 134 | |
135 | 135 | /** |
136 | 136 | * Load Checkout Fields |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | * @return void |
141 | 141 | */ |
142 | 142 | function give_load_checkout_fields() { |
143 | - $form_id = isset( $_POST['form_id'] ) ? $_POST['form_id'] : ''; |
|
143 | + $form_id = isset($_POST['form_id']) ? $_POST['form_id'] : ''; |
|
144 | 144 | |
145 | 145 | ob_start(); |
146 | 146 | |
@@ -149,18 +149,18 @@ discard block |
||
149 | 149 | * |
150 | 150 | * @since 1.7 |
151 | 151 | */ |
152 | - do_action( 'give_donation_form_register_login_fields', $form_id ); |
|
152 | + do_action('give_donation_form_register_login_fields', $form_id); |
|
153 | 153 | |
154 | 154 | $fields = ob_get_clean(); |
155 | 155 | |
156 | - wp_send_json( array( |
|
157 | - 'fields' => wp_json_encode( $fields ), |
|
158 | - 'submit' => wp_json_encode( give_get_donation_form_submit_button( $form_id ) ), |
|
159 | - ) ); |
|
156 | + wp_send_json(array( |
|
157 | + 'fields' => wp_json_encode($fields), |
|
158 | + 'submit' => wp_json_encode(give_get_donation_form_submit_button($form_id)), |
|
159 | + )); |
|
160 | 160 | } |
161 | 161 | |
162 | -add_action( 'wp_ajax_nopriv_give_cancel_login', 'give_load_checkout_fields' ); |
|
163 | -add_action( 'wp_ajax_nopriv_give_checkout_register', 'give_load_checkout_fields' ); |
|
162 | +add_action('wp_ajax_nopriv_give_cancel_login', 'give_load_checkout_fields'); |
|
163 | +add_action('wp_ajax_nopriv_give_checkout_register', 'give_load_checkout_fields'); |
|
164 | 164 | |
165 | 165 | /** |
166 | 166 | * Get Form Title via AJAX (used only in WordPress Admin) |
@@ -170,9 +170,9 @@ discard block |
||
170 | 170 | * @return void |
171 | 171 | */ |
172 | 172 | function give_ajax_get_form_title() { |
173 | - if ( isset( $_POST['form_id'] ) ) { |
|
174 | - $title = get_the_title( $_POST['form_id'] ); |
|
175 | - if ( $title ) { |
|
173 | + if (isset($_POST['form_id'])) { |
|
174 | + $title = get_the_title($_POST['form_id']); |
|
175 | + if ($title) { |
|
176 | 176 | echo $title; |
177 | 177 | } else { |
178 | 178 | echo 'fail'; |
@@ -181,8 +181,8 @@ discard block |
||
181 | 181 | give_die(); |
182 | 182 | } |
183 | 183 | |
184 | -add_action( 'wp_ajax_give_get_form_title', 'give_ajax_get_form_title' ); |
|
185 | -add_action( 'wp_ajax_nopriv_give_get_form_title', 'give_ajax_get_form_title' ); |
|
184 | +add_action('wp_ajax_give_get_form_title', 'give_ajax_get_form_title'); |
|
185 | +add_action('wp_ajax_nopriv_give_get_form_title', 'give_ajax_get_form_title'); |
|
186 | 186 | |
187 | 187 | /** |
188 | 188 | * Retrieve a states drop down |
@@ -196,35 +196,35 @@ discard block |
||
196 | 196 | $show_field = true; |
197 | 197 | $states_require = true; |
198 | 198 | // Get the Country code from the $_POST. |
199 | - $country = sanitize_text_field( $_POST['country'] ); |
|
199 | + $country = sanitize_text_field($_POST['country']); |
|
200 | 200 | |
201 | 201 | // Get the field name from the $_POST. |
202 | - $field_name = sanitize_text_field( $_POST['field_name'] ); |
|
202 | + $field_name = sanitize_text_field($_POST['field_name']); |
|
203 | 203 | |
204 | - $label = __( 'State', 'give' ); |
|
204 | + $label = __('State', 'give'); |
|
205 | 205 | $states_label = give_get_states_label(); |
206 | 206 | |
207 | 207 | // Check if $country code exists in the array key for states label. |
208 | - if ( array_key_exists( $country, $states_label ) ) { |
|
209 | - $label = $states_label[ $country ]; |
|
208 | + if (array_key_exists($country, $states_label)) { |
|
209 | + $label = $states_label[$country]; |
|
210 | 210 | } |
211 | 211 | |
212 | - if ( empty( $country ) ) { |
|
212 | + if (empty($country)) { |
|
213 | 213 | $country = give_get_country(); |
214 | 214 | } |
215 | 215 | |
216 | - $states = give_get_states( $country ); |
|
217 | - if ( ! empty( $states ) ) { |
|
216 | + $states = give_get_states($country); |
|
217 | + if ( ! empty($states)) { |
|
218 | 218 | $args = array( |
219 | 219 | 'name' => $field_name, |
220 | 220 | 'id' => $field_name, |
221 | - 'class' => $field_name . ' give-select', |
|
221 | + 'class' => $field_name.' give-select', |
|
222 | 222 | 'options' => $states, |
223 | 223 | 'show_option_all' => false, |
224 | 224 | 'show_option_none' => false, |
225 | 225 | 'placeholder' => $label, |
226 | 226 | ); |
227 | - $data = Give()->html->select( $args ); |
|
227 | + $data = Give()->html->select($args); |
|
228 | 228 | $states_found = true; |
229 | 229 | } else { |
230 | 230 | $data = 'nostates'; |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | $no_states_country = give_no_states_country_list(); |
234 | 234 | |
235 | 235 | // Check if $country code exists in the array key. |
236 | - if ( array_key_exists( $country, $no_states_country ) ) { |
|
236 | + if (array_key_exists($country, $no_states_country)) { |
|
237 | 237 | $show_field = false; |
238 | 238 | } |
239 | 239 | |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | $states_not_required_country_list = give_states_not_required_country_list(); |
242 | 242 | |
243 | 243 | // Check if $country code exists in the array key. |
244 | - if ( array_key_exists( $country, $states_not_required_country_list ) ) { |
|
244 | + if (array_key_exists($country, $states_not_required_country_list)) { |
|
245 | 245 | $states_require = false; |
246 | 246 | } |
247 | 247 | } |
@@ -253,10 +253,10 @@ discard block |
||
253 | 253 | 'states_require' => $states_require, |
254 | 254 | 'data' => $data, |
255 | 255 | ); |
256 | - wp_send_json( $response ); |
|
256 | + wp_send_json($response); |
|
257 | 257 | } |
258 | -add_action( 'wp_ajax_give_get_states', 'give_ajax_get_states_field' ); |
|
259 | -add_action( 'wp_ajax_nopriv_give_get_states', 'give_ajax_get_states_field' ); |
|
258 | +add_action('wp_ajax_give_get_states', 'give_ajax_get_states_field'); |
|
259 | +add_action('wp_ajax_nopriv_give_get_states', 'give_ajax_get_states_field'); |
|
260 | 260 | |
261 | 261 | /** |
262 | 262 | * Retrieve donation forms via AJAX for chosen dropdown search field. |
@@ -268,19 +268,19 @@ discard block |
||
268 | 268 | function give_ajax_form_search() { |
269 | 269 | global $wpdb; |
270 | 270 | |
271 | - $search = esc_sql( sanitize_text_field( $_GET['s'] ) ); |
|
272 | - $excludes = ( isset( $_GET['current_id'] ) ? (array) $_GET['current_id'] : array() ); |
|
271 | + $search = esc_sql(sanitize_text_field($_GET['s'])); |
|
272 | + $excludes = (isset($_GET['current_id']) ? (array) $_GET['current_id'] : array()); |
|
273 | 273 | |
274 | 274 | $results = array(); |
275 | - if ( current_user_can( 'edit_give_forms' ) ) { |
|
276 | - $items = $wpdb->get_results( "SELECT ID,post_title FROM $wpdb->posts WHERE `post_type` = 'give_forms' AND `post_title` LIKE '%$search%' LIMIT 50" ); |
|
275 | + if (current_user_can('edit_give_forms')) { |
|
276 | + $items = $wpdb->get_results("SELECT ID,post_title FROM $wpdb->posts WHERE `post_type` = 'give_forms' AND `post_title` LIKE '%$search%' LIMIT 50"); |
|
277 | 277 | } else { |
278 | - $items = $wpdb->get_results( "SELECT ID,post_title FROM $wpdb->posts WHERE `post_type` = 'give_forms' AND `post_status` = 'publish' AND `post_title` LIKE '%$search%' LIMIT 50" ); |
|
278 | + $items = $wpdb->get_results("SELECT ID,post_title FROM $wpdb->posts WHERE `post_type` = 'give_forms' AND `post_status` = 'publish' AND `post_title` LIKE '%$search%' LIMIT 50"); |
|
279 | 279 | } |
280 | 280 | |
281 | - if ( $items ) { |
|
281 | + if ($items) { |
|
282 | 282 | |
283 | - foreach ( $items as $item ) { |
|
283 | + foreach ($items as $item) { |
|
284 | 284 | |
285 | 285 | $results[] = array( |
286 | 286 | 'id' => $item->ID, |
@@ -291,18 +291,18 @@ discard block |
||
291 | 291 | |
292 | 292 | $items[] = array( |
293 | 293 | 'id' => 0, |
294 | - 'name' => __( 'No forms found.', 'give' ), |
|
294 | + 'name' => __('No forms found.', 'give'), |
|
295 | 295 | ); |
296 | 296 | |
297 | 297 | } |
298 | 298 | |
299 | - echo json_encode( $results ); |
|
299 | + echo json_encode($results); |
|
300 | 300 | |
301 | 301 | give_die(); |
302 | 302 | } |
303 | 303 | |
304 | -add_action( 'wp_ajax_give_form_search', 'give_ajax_form_search' ); |
|
305 | -add_action( 'wp_ajax_nopriv_give_form_search', 'give_ajax_form_search' ); |
|
304 | +add_action('wp_ajax_give_form_search', 'give_ajax_form_search'); |
|
305 | +add_action('wp_ajax_nopriv_give_form_search', 'give_ajax_form_search'); |
|
306 | 306 | |
307 | 307 | /** |
308 | 308 | * Search the donors database via Ajax |
@@ -314,38 +314,38 @@ discard block |
||
314 | 314 | function give_ajax_donor_search() { |
315 | 315 | global $wpdb; |
316 | 316 | |
317 | - $search = esc_sql( sanitize_text_field( $_GET['s'] ) ); |
|
317 | + $search = esc_sql(sanitize_text_field($_GET['s'])); |
|
318 | 318 | $results = array(); |
319 | - if ( ! current_user_can( 'view_give_reports' ) ) { |
|
319 | + if ( ! current_user_can('view_give_reports')) { |
|
320 | 320 | $donors = array(); |
321 | 321 | } else { |
322 | - $donors = $wpdb->get_results( "SELECT id,name,email FROM {$wpdb->prefix}give_customers WHERE `name` LIKE '%$search%' OR `email` LIKE '%$search%' LIMIT 50" ); |
|
322 | + $donors = $wpdb->get_results("SELECT id,name,email FROM {$wpdb->prefix}give_customers WHERE `name` LIKE '%$search%' OR `email` LIKE '%$search%' LIMIT 50"); |
|
323 | 323 | } |
324 | 324 | |
325 | - if ( $donors ) { |
|
325 | + if ($donors) { |
|
326 | 326 | |
327 | - foreach ( $donors as $donor ) { |
|
327 | + foreach ($donors as $donor) { |
|
328 | 328 | |
329 | 329 | $results[] = array( |
330 | 330 | 'id' => $donor->id, |
331 | - 'name' => $donor->name . ' (' . $donor->email . ')', |
|
331 | + 'name' => $donor->name.' ('.$donor->email.')', |
|
332 | 332 | ); |
333 | 333 | } |
334 | 334 | } else { |
335 | 335 | |
336 | 336 | $donors[] = array( |
337 | 337 | 'id' => 0, |
338 | - 'name' => __( 'No donors found.', 'give' ), |
|
338 | + 'name' => __('No donors found.', 'give'), |
|
339 | 339 | ); |
340 | 340 | |
341 | 341 | } |
342 | 342 | |
343 | - echo json_encode( $results ); |
|
343 | + echo json_encode($results); |
|
344 | 344 | |
345 | 345 | give_die(); |
346 | 346 | } |
347 | 347 | |
348 | -add_action( 'wp_ajax_give_donor_search', 'give_ajax_donor_search' ); |
|
348 | +add_action('wp_ajax_give_donor_search', 'give_ajax_donor_search'); |
|
349 | 349 | |
350 | 350 | |
351 | 351 | /** |
@@ -357,39 +357,39 @@ discard block |
||
357 | 357 | */ |
358 | 358 | function give_ajax_search_users() { |
359 | 359 | |
360 | - if ( current_user_can( 'manage_give_settings' ) ) { |
|
360 | + if (current_user_can('manage_give_settings')) { |
|
361 | 361 | |
362 | - $search = esc_sql( sanitize_text_field( $_GET['s'] ) ); |
|
362 | + $search = esc_sql(sanitize_text_field($_GET['s'])); |
|
363 | 363 | |
364 | 364 | $get_users_args = array( |
365 | 365 | 'number' => 9999, |
366 | - 'search' => $search . '*', |
|
366 | + 'search' => $search.'*', |
|
367 | 367 | ); |
368 | 368 | |
369 | - $get_users_args = apply_filters( 'give_search_users_args', $get_users_args ); |
|
369 | + $get_users_args = apply_filters('give_search_users_args', $get_users_args); |
|
370 | 370 | |
371 | - $found_users = apply_filters( 'give_ajax_found_users', get_users( $get_users_args ), $search ); |
|
371 | + $found_users = apply_filters('give_ajax_found_users', get_users($get_users_args), $search); |
|
372 | 372 | $results = array(); |
373 | 373 | |
374 | - if ( $found_users ) { |
|
374 | + if ($found_users) { |
|
375 | 375 | |
376 | - foreach ( $found_users as $user ) { |
|
376 | + foreach ($found_users as $user) { |
|
377 | 377 | |
378 | 378 | $results[] = array( |
379 | 379 | 'id' => $user->ID, |
380 | - 'name' => esc_html( $user->user_login . ' (' . $user->user_email . ')' ), |
|
380 | + 'name' => esc_html($user->user_login.' ('.$user->user_email.')'), |
|
381 | 381 | ); |
382 | 382 | } |
383 | 383 | } else { |
384 | 384 | |
385 | 385 | $results[] = array( |
386 | 386 | 'id' => 0, |
387 | - 'name' => __( 'No users found.', 'give' ), |
|
387 | + 'name' => __('No users found.', 'give'), |
|
388 | 388 | ); |
389 | 389 | |
390 | 390 | } |
391 | 391 | |
392 | - echo json_encode( $results ); |
|
392 | + echo json_encode($results); |
|
393 | 393 | |
394 | 394 | }// End if(). |
395 | 395 | |
@@ -397,7 +397,7 @@ discard block |
||
397 | 397 | |
398 | 398 | } |
399 | 399 | |
400 | -add_action( 'wp_ajax_give_user_search', 'give_ajax_search_users' ); |
|
400 | +add_action('wp_ajax_give_user_search', 'give_ajax_search_users'); |
|
401 | 401 | |
402 | 402 | |
403 | 403 | /** |
@@ -409,32 +409,32 @@ discard block |
||
409 | 409 | */ |
410 | 410 | function give_check_for_form_price_variations() { |
411 | 411 | |
412 | - if ( ! current_user_can( 'edit_give_forms', get_current_user_id() ) ) { |
|
413 | - die( '-1' ); |
|
412 | + if ( ! current_user_can('edit_give_forms', get_current_user_id())) { |
|
413 | + die('-1'); |
|
414 | 414 | } |
415 | 415 | |
416 | - $form_id = intval( $_POST['form_id'] ); |
|
417 | - $form = get_post( $form_id ); |
|
416 | + $form_id = intval($_POST['form_id']); |
|
417 | + $form = get_post($form_id); |
|
418 | 418 | |
419 | - if ( 'give_forms' != $form->post_type ) { |
|
420 | - die( '-2' ); |
|
419 | + if ('give_forms' != $form->post_type) { |
|
420 | + die('-2'); |
|
421 | 421 | } |
422 | 422 | |
423 | - if ( give_has_variable_prices( $form_id ) ) { |
|
424 | - $variable_prices = give_get_variable_prices( $form_id ); |
|
423 | + if (give_has_variable_prices($form_id)) { |
|
424 | + $variable_prices = give_get_variable_prices($form_id); |
|
425 | 425 | |
426 | - if ( $variable_prices ) { |
|
426 | + if ($variable_prices) { |
|
427 | 427 | $ajax_response = '<select class="give_price_options_select give-select give-select" name="give_price_option">'; |
428 | 428 | |
429 | - if ( isset( $_POST['all_prices'] ) ) { |
|
430 | - $ajax_response .= '<option value="all">' . esc_html__( 'All Levels', 'give' ) . '</option>'; |
|
429 | + if (isset($_POST['all_prices'])) { |
|
430 | + $ajax_response .= '<option value="all">'.esc_html__('All Levels', 'give').'</option>'; |
|
431 | 431 | } |
432 | 432 | |
433 | - foreach ( $variable_prices as $key => $price ) { |
|
433 | + foreach ($variable_prices as $key => $price) { |
|
434 | 434 | |
435 | - $level_text = ! empty( $price['_give_text'] ) ? esc_html( $price['_give_text'] ) : give_currency_filter( give_format_amount( $price['_give_amount'], array( 'sanitize' => false ) ) ); |
|
435 | + $level_text = ! empty($price['_give_text']) ? esc_html($price['_give_text']) : give_currency_filter(give_format_amount($price['_give_amount'], array('sanitize' => false))); |
|
436 | 436 | |
437 | - $ajax_response .= '<option value="' . esc_attr( $price['_give_id']['level_id'] ) . '">' . $level_text . '</option>'; |
|
437 | + $ajax_response .= '<option value="'.esc_attr($price['_give_id']['level_id']).'">'.$level_text.'</option>'; |
|
438 | 438 | } |
439 | 439 | $ajax_response .= '</select>'; |
440 | 440 | echo $ajax_response; |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | give_die(); |
445 | 445 | } |
446 | 446 | |
447 | -add_action( 'wp_ajax_give_check_for_form_price_variations', 'give_check_for_form_price_variations' ); |
|
447 | +add_action('wp_ajax_give_check_for_form_price_variations', 'give_check_for_form_price_variations'); |
|
448 | 448 | |
449 | 449 | |
450 | 450 | /** |
@@ -455,25 +455,25 @@ discard block |
||
455 | 455 | * @return void |
456 | 456 | */ |
457 | 457 | function give_check_for_form_price_variations_html() { |
458 | - if ( ! current_user_can( 'edit_give_payments', get_current_user_id() ) ) { |
|
458 | + if ( ! current_user_can('edit_give_payments', get_current_user_id())) { |
|
459 | 459 | wp_die(); |
460 | 460 | } |
461 | 461 | |
462 | - $form_id = ! empty( $_POST['form_id'] ) ? intval( $_POST['form_id'] ) : 0; |
|
463 | - $payment_id = ! empty( $_POST['payment_id'] ) ? intval( $_POST['payment_id'] ) : 0; |
|
464 | - $form = get_post( $form_id ); |
|
462 | + $form_id = ! empty($_POST['form_id']) ? intval($_POST['form_id']) : 0; |
|
463 | + $payment_id = ! empty($_POST['payment_id']) ? intval($_POST['payment_id']) : 0; |
|
464 | + $form = get_post($form_id); |
|
465 | 465 | |
466 | - if ( 'give_forms' != $form->post_type ) { |
|
466 | + if ('give_forms' != $form->post_type) { |
|
467 | 467 | wp_die(); |
468 | 468 | } |
469 | 469 | |
470 | - if ( ! give_has_variable_prices( $form_id ) || ! $form_id ) { |
|
471 | - esc_html_e( 'n/a', 'give' ); |
|
470 | + if ( ! give_has_variable_prices($form_id) || ! $form_id) { |
|
471 | + esc_html_e('n/a', 'give'); |
|
472 | 472 | } else { |
473 | 473 | $prices_atts = ''; |
474 | - if ( $variable_prices = give_get_variable_prices( $form_id ) ) { |
|
475 | - foreach ( $variable_prices as $variable_price ) { |
|
476 | - $prices_atts[ $variable_price['_give_id']['level_id'] ] = give_format_amount( $variable_price['_give_amount'], array( 'sanitize' => false ) ); |
|
474 | + if ($variable_prices = give_get_variable_prices($form_id)) { |
|
475 | + foreach ($variable_prices as $variable_price) { |
|
476 | + $prices_atts[$variable_price['_give_id']['level_id']] = give_format_amount($variable_price['_give_amount'], array('sanitize' => false)); |
|
477 | 477 | } |
478 | 478 | } |
479 | 479 | |
@@ -484,12 +484,12 @@ discard block |
||
484 | 484 | 'chosen' => true, |
485 | 485 | 'show_option_all' => '', |
486 | 486 | 'show_option_none' => '', |
487 | - 'select_atts' => 'data-prices=' . esc_attr( json_encode( $prices_atts ) ), |
|
487 | + 'select_atts' => 'data-prices='.esc_attr(json_encode($prices_atts)), |
|
488 | 488 | ); |
489 | 489 | |
490 | - if ( $payment_id ) { |
|
490 | + if ($payment_id) { |
|
491 | 491 | // Payment object. |
492 | - $payment = new Give_Payment( $payment_id ); |
|
492 | + $payment = new Give_Payment($payment_id); |
|
493 | 493 | |
494 | 494 | // Payment meta. |
495 | 495 | $payment_meta = $payment->get_meta(); |
@@ -497,10 +497,10 @@ discard block |
||
497 | 497 | } |
498 | 498 | |
499 | 499 | // Render variable prices select tag html. |
500 | - give_get_form_variable_price_dropdown( $variable_price_dropdown_option, true ); |
|
500 | + give_get_form_variable_price_dropdown($variable_price_dropdown_option, true); |
|
501 | 501 | } |
502 | 502 | |
503 | 503 | give_die(); |
504 | 504 | } |
505 | 505 | |
506 | -add_action( 'wp_ajax_give_check_for_form_price_variations_html', 'give_check_for_form_price_variations_html' ); |
|
506 | +add_action('wp_ajax_give_check_for_form_price_variations_html', 'give_check_for_form_price_variations_html'); |
@@ -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 | |
@@ -337,11 +337,11 @@ discard block |
||
337 | 337 | * @param bool $_id Post id. Default is false. |
338 | 338 | * @param array $_args Arguments passed. |
339 | 339 | */ |
340 | - public function __construct( $_id = false, $_args = array() ) { |
|
340 | + public function __construct($_id = false, $_args = array()) { |
|
341 | 341 | |
342 | - $donation_form = WP_Post::get_instance( $_id ); |
|
342 | + $donation_form = WP_Post::get_instance($_id); |
|
343 | 343 | |
344 | - return $this->setup_donation_form( $donation_form ); |
|
344 | + return $this->setup_donation_form($donation_form); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | /** |
@@ -354,23 +354,23 @@ discard block |
||
354 | 354 | * |
355 | 355 | * @return bool If the setup was successful or not. |
356 | 356 | */ |
357 | - private function setup_donation_form( $donation_form ) { |
|
357 | + private function setup_donation_form($donation_form) { |
|
358 | 358 | |
359 | - if ( ! is_object( $donation_form ) ) { |
|
359 | + if ( ! is_object($donation_form)) { |
|
360 | 360 | return false; |
361 | 361 | } |
362 | 362 | |
363 | - if ( ! is_a( $donation_form, 'WP_Post' ) ) { |
|
363 | + if ( ! is_a($donation_form, 'WP_Post')) { |
|
364 | 364 | return false; |
365 | 365 | } |
366 | 366 | |
367 | - if ( 'give_forms' !== $donation_form->post_type ) { |
|
367 | + if ('give_forms' !== $donation_form->post_type) { |
|
368 | 368 | return false; |
369 | 369 | } |
370 | 370 | |
371 | - foreach ( $donation_form as $key => $value ) { |
|
371 | + foreach ($donation_form as $key => $value) { |
|
372 | 372 | |
373 | - switch ( $key ) { |
|
373 | + switch ($key) { |
|
374 | 374 | |
375 | 375 | default: |
376 | 376 | $this->$key = $value; |
@@ -394,16 +394,16 @@ discard block |
||
394 | 394 | * |
395 | 395 | * @return mixed |
396 | 396 | */ |
397 | - public function __get( $key ) { |
|
397 | + public function __get($key) { |
|
398 | 398 | |
399 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
399 | + if (method_exists($this, 'get_'.$key)) { |
|
400 | 400 | |
401 | - return call_user_func( array( $this, 'get_' . $key ) ); |
|
401 | + return call_user_func(array($this, 'get_'.$key)); |
|
402 | 402 | |
403 | 403 | } else { |
404 | 404 | |
405 | 405 | /* translators: %s: property key */ |
406 | - return new WP_Error( 'give-form-invalid-property', sprintf( esc_html__( 'Can\'t get property %s.', 'give' ), $key ) ); |
|
406 | + return new WP_Error('give-form-invalid-property', sprintf(esc_html__('Can\'t get property %s.', 'give'), $key)); |
|
407 | 407 | |
408 | 408 | } |
409 | 409 | |
@@ -419,30 +419,30 @@ discard block |
||
419 | 419 | * |
420 | 420 | * @return bool|int False if data isn't passed and class not instantiated for creation, or New Form ID. |
421 | 421 | */ |
422 | - public function create( $data = array() ) { |
|
422 | + public function create($data = array()) { |
|
423 | 423 | |
424 | - if ( $this->id != 0 ) { |
|
424 | + if ($this->id != 0) { |
|
425 | 425 | return false; |
426 | 426 | } |
427 | 427 | |
428 | 428 | $defaults = array( |
429 | 429 | 'post_type' => 'give_forms', |
430 | 430 | 'post_status' => 'draft', |
431 | - 'post_title' => __( 'New Donation Form', 'give' ), |
|
431 | + 'post_title' => __('New Donation Form', 'give'), |
|
432 | 432 | ); |
433 | 433 | |
434 | - $args = wp_parse_args( $data, $defaults ); |
|
434 | + $args = wp_parse_args($data, $defaults); |
|
435 | 435 | |
436 | 436 | /** |
437 | 437 | * Fired before a donation form is created |
438 | 438 | * |
439 | 439 | * @param array $args The post object arguments used for creation. |
440 | 440 | */ |
441 | - do_action( 'give_form_pre_create', $args ); |
|
441 | + do_action('give_form_pre_create', $args); |
|
442 | 442 | |
443 | - $id = wp_insert_post( $args, true ); |
|
443 | + $id = wp_insert_post($args, true); |
|
444 | 444 | |
445 | - $donation_form = WP_Post::get_instance( $id ); |
|
445 | + $donation_form = WP_Post::get_instance($id); |
|
446 | 446 | |
447 | 447 | /** |
448 | 448 | * Fired after a donation form is created |
@@ -450,9 +450,9 @@ discard block |
||
450 | 450 | * @param int $id The post ID of the created item. |
451 | 451 | * @param array $args The post object arguments used for creation. |
452 | 452 | */ |
453 | - do_action( 'give_form_post_create', $id, $args ); |
|
453 | + do_action('give_form_post_create', $id, $args); |
|
454 | 454 | |
455 | - return $this->setup_donation_form( $donation_form ); |
|
455 | + return $this->setup_donation_form($donation_form); |
|
456 | 456 | |
457 | 457 | } |
458 | 458 | |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | * @return string Donation form name. |
478 | 478 | */ |
479 | 479 | public function get_name() { |
480 | - return get_the_title( $this->ID ); |
|
480 | + return get_the_title($this->ID); |
|
481 | 481 | } |
482 | 482 | |
483 | 483 | /** |
@@ -490,7 +490,7 @@ discard block |
||
490 | 490 | */ |
491 | 491 | public function get_price() { |
492 | 492 | |
493 | - if ( ! isset( $this->price ) ) { |
|
493 | + if ( ! isset($this->price)) { |
|
494 | 494 | |
495 | 495 | $this->price = give_maybe_sanitize_amount( |
496 | 496 | give_get_meta( |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | ) |
501 | 501 | ); |
502 | 502 | |
503 | - if ( ! $this->price ) { |
|
503 | + if ( ! $this->price) { |
|
504 | 504 | $this->price = 0; |
505 | 505 | } |
506 | 506 | |
@@ -514,7 +514,7 @@ discard block |
||
514 | 514 | * @param string $price The donation form price. |
515 | 515 | * @param string|int $id The form ID. |
516 | 516 | */ |
517 | - return apply_filters( 'give_get_set_price', $this->price, $this->ID ); |
|
517 | + return apply_filters('give_get_set_price', $this->price, $this->ID); |
|
518 | 518 | } |
519 | 519 | |
520 | 520 | /** |
@@ -527,18 +527,18 @@ discard block |
||
527 | 527 | */ |
528 | 528 | public function get_minimum_price() { |
529 | 529 | |
530 | - if ( ! isset( $this->minimum_price ) ) { |
|
530 | + if ( ! isset($this->minimum_price)) { |
|
531 | 531 | |
532 | - $allow_custom_amount = give_get_meta( $this->ID, '_give_custom_amount', true ); |
|
533 | - $this->minimum_price = give_get_meta( $this->ID, '_give_custom_amount_minimum', true ); |
|
532 | + $allow_custom_amount = give_get_meta($this->ID, '_give_custom_amount', true); |
|
533 | + $this->minimum_price = give_get_meta($this->ID, '_give_custom_amount_minimum', true); |
|
534 | 534 | |
535 | - if ( ! give_is_setting_enabled( $allow_custom_amount ) ) { |
|
535 | + if ( ! give_is_setting_enabled($allow_custom_amount)) { |
|
536 | 536 | $this->minimum_price = 0; |
537 | 537 | } |
538 | 538 | |
539 | 539 | } |
540 | 540 | |
541 | - return apply_filters( 'give_get_set_minimum_price', $this->minimum_price, $this->ID ); |
|
541 | + return apply_filters('give_get_set_minimum_price', $this->minimum_price, $this->ID); |
|
542 | 542 | } |
543 | 543 | |
544 | 544 | /** |
@@ -551,9 +551,9 @@ discard block |
||
551 | 551 | */ |
552 | 552 | public function get_prices() { |
553 | 553 | |
554 | - if ( ! isset( $this->prices ) ) { |
|
554 | + if ( ! isset($this->prices)) { |
|
555 | 555 | |
556 | - $this->prices = give_get_meta( $this->ID, '_give_donation_levels', true ); |
|
556 | + $this->prices = give_get_meta($this->ID, '_give_donation_levels', true); |
|
557 | 557 | |
558 | 558 | } |
559 | 559 | |
@@ -565,7 +565,7 @@ discard block |
||
565 | 565 | * @param array $prices The array of mulit-level prices. |
566 | 566 | * @param int|string $ID The ID of the form. |
567 | 567 | */ |
568 | - return apply_filters( 'give_get_donation_levels', $this->prices, $this->ID ); |
|
568 | + return apply_filters('give_get_donation_levels', $this->prices, $this->ID); |
|
569 | 569 | |
570 | 570 | } |
571 | 571 | |
@@ -579,17 +579,17 @@ discard block |
||
579 | 579 | */ |
580 | 580 | public function get_goal() { |
581 | 581 | |
582 | - if ( ! isset( $this->goal ) ) { |
|
582 | + if ( ! isset($this->goal)) { |
|
583 | 583 | |
584 | - $this->goal = give_get_meta( $this->ID, '_give_set_goal', true ); |
|
584 | + $this->goal = give_get_meta($this->ID, '_give_set_goal', true); |
|
585 | 585 | |
586 | - if ( ! $this->goal ) { |
|
586 | + if ( ! $this->goal) { |
|
587 | 587 | $this->goal = 0; |
588 | 588 | } |
589 | 589 | |
590 | 590 | } |
591 | 591 | |
592 | - return apply_filters( 'give_get_set_goal', $this->goal, $this->ID ); |
|
592 | + return apply_filters('give_get_set_goal', $this->goal, $this->ID); |
|
593 | 593 | |
594 | 594 | } |
595 | 595 | |
@@ -603,10 +603,10 @@ discard block |
||
603 | 603 | */ |
604 | 604 | public function is_single_price_mode() { |
605 | 605 | |
606 | - $option = give_get_meta( $this->ID, '_give_price_option', true ); |
|
606 | + $option = give_get_meta($this->ID, '_give_price_option', true); |
|
607 | 607 | $ret = 0; |
608 | 608 | |
609 | - if ( empty( $option ) || $option === 'set' ) { |
|
609 | + if (empty($option) || $option === 'set') { |
|
610 | 610 | $ret = 1; |
611 | 611 | } |
612 | 612 | |
@@ -618,7 +618,7 @@ discard block |
||
618 | 618 | * @param bool $ret Is donation form in single price mode? |
619 | 619 | * @param int|string $ID The ID of the donation form. |
620 | 620 | */ |
621 | - return (bool) apply_filters( 'give_single_price_option_mode', $ret, $this->ID ); |
|
621 | + return (bool) apply_filters('give_single_price_option_mode', $ret, $this->ID); |
|
622 | 622 | |
623 | 623 | } |
624 | 624 | |
@@ -632,10 +632,10 @@ discard block |
||
632 | 632 | */ |
633 | 633 | public function is_custom_price_mode() { |
634 | 634 | |
635 | - $option = give_get_meta( $this->ID, '_give_custom_amount', true ); |
|
635 | + $option = give_get_meta($this->ID, '_give_custom_amount', true); |
|
636 | 636 | $ret = 0; |
637 | 637 | |
638 | - if ( give_is_setting_enabled( $option ) ) { |
|
638 | + if (give_is_setting_enabled($option)) { |
|
639 | 639 | $ret = 1; |
640 | 640 | } |
641 | 641 | |
@@ -647,7 +647,7 @@ discard block |
||
647 | 647 | * @param bool $ret Is donation form in custom price mode? |
648 | 648 | * @param int|string $ID The ID of the donation form. |
649 | 649 | */ |
650 | - return (bool) apply_filters( 'give_custom_price_option_mode', $ret, $this->ID ); |
|
650 | + return (bool) apply_filters('give_custom_price_option_mode', $ret, $this->ID); |
|
651 | 651 | |
652 | 652 | } |
653 | 653 | |
@@ -663,10 +663,10 @@ discard block |
||
663 | 663 | */ |
664 | 664 | public function has_variable_prices() { |
665 | 665 | |
666 | - $option = give_get_meta( $this->ID, '_give_price_option', true ); |
|
666 | + $option = give_get_meta($this->ID, '_give_price_option', true); |
|
667 | 667 | $ret = 0; |
668 | 668 | |
669 | - if ( $option === 'multi' ) { |
|
669 | + if ($option === 'multi') { |
|
670 | 670 | $ret = 1; |
671 | 671 | } |
672 | 672 | |
@@ -676,7 +676,7 @@ discard block |
||
676 | 676 | * @param bool $ret Does donation form have variable prices? |
677 | 677 | * @param int|string $ID The ID of the donation form. |
678 | 678 | */ |
679 | - return (bool) apply_filters( 'give_has_variable_prices', $ret, $this->ID ); |
|
679 | + return (bool) apply_filters('give_has_variable_prices', $ret, $this->ID); |
|
680 | 680 | |
681 | 681 | } |
682 | 682 | |
@@ -690,17 +690,17 @@ discard block |
||
690 | 690 | */ |
691 | 691 | public function get_type() { |
692 | 692 | |
693 | - if ( ! isset( $this->type ) ) { |
|
693 | + if ( ! isset($this->type)) { |
|
694 | 694 | |
695 | - $this->type = give_get_meta( $this->ID, '_give_price_option', true ); |
|
695 | + $this->type = give_get_meta($this->ID, '_give_price_option', true); |
|
696 | 696 | |
697 | - if ( empty( $this->type ) ) { |
|
697 | + if (empty($this->type)) { |
|
698 | 698 | $this->type = 'set'; |
699 | 699 | } |
700 | 700 | |
701 | 701 | } |
702 | 702 | |
703 | - return apply_filters( 'give_get_form_type', $this->type, $this->ID ); |
|
703 | + return apply_filters('give_get_form_type', $this->type, $this->ID); |
|
704 | 704 | |
705 | 705 | } |
706 | 706 | |
@@ -716,23 +716,23 @@ discard block |
||
716 | 716 | * |
717 | 717 | * @return string |
718 | 718 | */ |
719 | - public function get_form_classes( $args ) { |
|
719 | + public function get_form_classes($args) { |
|
720 | 720 | |
721 | - $float_labels_option = give_is_float_labels_enabled( $args ) |
|
721 | + $float_labels_option = give_is_float_labels_enabled($args) |
|
722 | 722 | ? 'float-labels-enabled' |
723 | 723 | : ''; |
724 | 724 | |
725 | - $form_classes_array = apply_filters( 'give_form_classes', array( |
|
725 | + $form_classes_array = apply_filters('give_form_classes', array( |
|
726 | 726 | 'give-form', |
727 | - 'give-form-' . $this->ID, |
|
728 | - 'give-form-type-' . $this->get_type(), |
|
727 | + 'give-form-'.$this->ID, |
|
728 | + 'give-form-type-'.$this->get_type(), |
|
729 | 729 | $float_labels_option, |
730 | - ), $this->ID, $args ); |
|
730 | + ), $this->ID, $args); |
|
731 | 731 | |
732 | 732 | // Remove empty class names. |
733 | - $form_classes_array = array_filter( $form_classes_array ); |
|
733 | + $form_classes_array = array_filter($form_classes_array); |
|
734 | 734 | |
735 | - return implode( ' ', $form_classes_array ); |
|
735 | + return implode(' ', $form_classes_array); |
|
736 | 736 | |
737 | 737 | } |
738 | 738 | |
@@ -747,24 +747,24 @@ discard block |
||
747 | 747 | * |
748 | 748 | * @return string |
749 | 749 | */ |
750 | - public function get_form_wrap_classes( $args ) { |
|
750 | + public function get_form_wrap_classes($args) { |
|
751 | 751 | |
752 | - $display_option = ( isset( $args['display_style'] ) && ! empty( $args['display_style'] ) ) |
|
752 | + $display_option = (isset($args['display_style']) && ! empty($args['display_style'])) |
|
753 | 753 | ? $args['display_style'] |
754 | - : give_get_meta( $this->ID, '_give_payment_display', true ); |
|
754 | + : give_get_meta($this->ID, '_give_payment_display', true); |
|
755 | 755 | |
756 | 756 | // If admin want to show only button for form then user inbuilt modal functionality. |
757 | - if( 'button' === $display_option ) { |
|
757 | + if ('button' === $display_option) { |
|
758 | 758 | $display_option = 'modal give-display-button-only'; |
759 | 759 | } |
760 | 760 | |
761 | - $form_wrap_classes_array = apply_filters( 'give_form_wrap_classes', array( |
|
761 | + $form_wrap_classes_array = apply_filters('give_form_wrap_classes', array( |
|
762 | 762 | 'give-form-wrap', |
763 | - 'give-display-' . $display_option, |
|
764 | - ), $this->ID, $args ); |
|
763 | + 'give-display-'.$display_option, |
|
764 | + ), $this->ID, $args); |
|
765 | 765 | |
766 | 766 | |
767 | - return implode( ' ', $form_wrap_classes_array ); |
|
767 | + return implode(' ', $form_wrap_classes_array); |
|
768 | 768 | |
769 | 769 | } |
770 | 770 | |
@@ -779,7 +779,7 @@ discard block |
||
779 | 779 | public function is_set_type_donation_form() { |
780 | 780 | $form_type = $this->get_type(); |
781 | 781 | |
782 | - return ( 'set' === $form_type ? true : false ); |
|
782 | + return ('set' === $form_type ? true : false); |
|
783 | 783 | } |
784 | 784 | |
785 | 785 | /** |
@@ -793,7 +793,7 @@ discard block |
||
793 | 793 | public function is_multi_type_donation_form() { |
794 | 794 | $form_type = $this->get_type(); |
795 | 795 | |
796 | - return ( 'multi' === $form_type ? true : false ); |
|
796 | + return ('multi' === $form_type ? true : false); |
|
797 | 797 | |
798 | 798 | } |
799 | 799 | |
@@ -807,15 +807,15 @@ discard block |
||
807 | 807 | */ |
808 | 808 | public function get_sales() { |
809 | 809 | |
810 | - if ( ! isset( $this->sales ) ) { |
|
810 | + if ( ! isset($this->sales)) { |
|
811 | 811 | |
812 | - if ( '' == give_get_meta( $this->ID, '_give_form_sales', true ) ) { |
|
813 | - add_post_meta( $this->ID, '_give_form_sales', 0 ); |
|
812 | + if ('' == give_get_meta($this->ID, '_give_form_sales', true)) { |
|
813 | + add_post_meta($this->ID, '_give_form_sales', 0); |
|
814 | 814 | } // End if |
815 | 815 | |
816 | - $this->sales = give_get_meta( $this->ID, '_give_form_sales', true ); |
|
816 | + $this->sales = give_get_meta($this->ID, '_give_form_sales', true); |
|
817 | 817 | |
818 | - if ( $this->sales < 0 ) { |
|
818 | + if ($this->sales < 0) { |
|
819 | 819 | // Never let sales be less than zero |
820 | 820 | $this->sales = 0; |
821 | 821 | } |
@@ -836,13 +836,13 @@ discard block |
||
836 | 836 | * |
837 | 837 | * @return int|false New number of total sales. |
838 | 838 | */ |
839 | - public function increase_sales( $quantity = 1 ) { |
|
839 | + public function increase_sales($quantity = 1) { |
|
840 | 840 | |
841 | - $sales = give_get_form_sales_stats( $this->ID ); |
|
842 | - $quantity = absint( $quantity ); |
|
841 | + $sales = give_get_form_sales_stats($this->ID); |
|
842 | + $quantity = absint($quantity); |
|
843 | 843 | $total_sales = $sales + $quantity; |
844 | 844 | |
845 | - if ( $this->update_meta( '_give_form_sales', $total_sales ) ) { |
|
845 | + if ($this->update_meta('_give_form_sales', $total_sales)) { |
|
846 | 846 | |
847 | 847 | $this->sales = $total_sales; |
848 | 848 | |
@@ -863,17 +863,17 @@ discard block |
||
863 | 863 | * |
864 | 864 | * @return int|false New number of total sales. |
865 | 865 | */ |
866 | - public function decrease_sales( $quantity = 1 ) { |
|
866 | + public function decrease_sales($quantity = 1) { |
|
867 | 867 | |
868 | - $sales = give_get_form_sales_stats( $this->ID ); |
|
868 | + $sales = give_get_form_sales_stats($this->ID); |
|
869 | 869 | |
870 | 870 | // Only decrease if not already zero |
871 | - if ( $sales > 0 ) { |
|
871 | + if ($sales > 0) { |
|
872 | 872 | |
873 | - $quantity = absint( $quantity ); |
|
873 | + $quantity = absint($quantity); |
|
874 | 874 | $total_sales = $sales - $quantity; |
875 | 875 | |
876 | - if ( $this->update_meta( '_give_form_sales', $total_sales ) ) { |
|
876 | + if ($this->update_meta('_give_form_sales', $total_sales)) { |
|
877 | 877 | |
878 | 878 | $this->sales = $sales; |
879 | 879 | |
@@ -897,15 +897,15 @@ discard block |
||
897 | 897 | */ |
898 | 898 | public function get_earnings() { |
899 | 899 | |
900 | - if ( ! isset( $this->earnings ) ) { |
|
900 | + if ( ! isset($this->earnings)) { |
|
901 | 901 | |
902 | - if ( '' == give_get_meta( $this->ID, '_give_form_earnings', true ) ) { |
|
903 | - add_post_meta( $this->ID, '_give_form_earnings', 0 ); |
|
902 | + if ('' == give_get_meta($this->ID, '_give_form_earnings', true)) { |
|
903 | + add_post_meta($this->ID, '_give_form_earnings', 0); |
|
904 | 904 | } |
905 | 905 | |
906 | - $this->earnings = give_get_meta( $this->ID, '_give_form_earnings', true ); |
|
906 | + $this->earnings = give_get_meta($this->ID, '_give_form_earnings', true); |
|
907 | 907 | |
908 | - if ( $this->earnings < 0 ) { |
|
908 | + if ($this->earnings < 0) { |
|
909 | 909 | // Never let earnings be less than zero |
910 | 910 | $this->earnings = 0; |
911 | 911 | } |
@@ -926,12 +926,12 @@ discard block |
||
926 | 926 | * |
927 | 927 | * @return float|false |
928 | 928 | */ |
929 | - public function increase_earnings( $amount = 0 ) { |
|
929 | + public function increase_earnings($amount = 0) { |
|
930 | 930 | |
931 | - $earnings = give_get_form_earnings_stats( $this->ID ); |
|
931 | + $earnings = give_get_form_earnings_stats($this->ID); |
|
932 | 932 | $new_amount = $earnings + (float) $amount; |
933 | 933 | |
934 | - if ( $this->update_meta( '_give_form_earnings', $new_amount ) ) { |
|
934 | + if ($this->update_meta('_give_form_earnings', $new_amount)) { |
|
935 | 935 | |
936 | 936 | $this->earnings = $new_amount; |
937 | 937 | |
@@ -953,16 +953,16 @@ discard block |
||
953 | 953 | * |
954 | 954 | * @return float|false |
955 | 955 | */ |
956 | - public function decrease_earnings( $amount ) { |
|
956 | + public function decrease_earnings($amount) { |
|
957 | 957 | |
958 | - $earnings = give_get_form_earnings_stats( $this->ID ); |
|
958 | + $earnings = give_get_form_earnings_stats($this->ID); |
|
959 | 959 | |
960 | - if ( $earnings > 0 ) { |
|
960 | + if ($earnings > 0) { |
|
961 | 961 | // Only decrease if greater than zero |
962 | 962 | $new_amount = $earnings - (float) $amount; |
963 | 963 | |
964 | 964 | |
965 | - if ( $this->update_meta( '_give_form_earnings', $new_amount ) ) { |
|
965 | + if ($this->update_meta('_give_form_earnings', $new_amount)) { |
|
966 | 966 | |
967 | 967 | $this->earnings = $new_amount; |
968 | 968 | |
@@ -986,22 +986,22 @@ discard block |
||
986 | 986 | * |
987 | 987 | * @return bool |
988 | 988 | */ |
989 | - public function is_free( $price_id = false ) { |
|
989 | + public function is_free($price_id = false) { |
|
990 | 990 | |
991 | 991 | $is_free = false; |
992 | - $variable_pricing = give_has_variable_prices( $this->ID ); |
|
992 | + $variable_pricing = give_has_variable_prices($this->ID); |
|
993 | 993 | |
994 | - if ( $variable_pricing && ! is_null( $price_id ) && $price_id !== false ) { |
|
995 | - $price = give_get_price_option_amount( $this->ID, $price_id ); |
|
996 | - } elseif ( ! $variable_pricing ) { |
|
997 | - $price = give_get_meta( $this->ID, '_give_set_price', true ); |
|
994 | + if ($variable_pricing && ! is_null($price_id) && $price_id !== false) { |
|
995 | + $price = give_get_price_option_amount($this->ID, $price_id); |
|
996 | + } elseif ( ! $variable_pricing) { |
|
997 | + $price = give_get_meta($this->ID, '_give_set_price', true); |
|
998 | 998 | } |
999 | 999 | |
1000 | - if ( isset( $price ) && (float) $price == 0 ) { |
|
1000 | + if (isset($price) && (float) $price == 0) { |
|
1001 | 1001 | $is_free = true; |
1002 | 1002 | } |
1003 | 1003 | |
1004 | - return (bool) apply_filters( 'give_is_free_donation', $is_free, $this->ID, $price_id ); |
|
1004 | + return (bool) apply_filters('give_is_free_donation', $is_free, $this->ID, $price_id); |
|
1005 | 1005 | |
1006 | 1006 | } |
1007 | 1007 | |
@@ -1028,9 +1028,9 @@ discard block |
||
1028 | 1028 | $is_close_form = apply_filters( |
1029 | 1029 | 'give_is_close_donation_form', |
1030 | 1030 | ( |
1031 | - give_is_setting_enabled( give_get_meta( $this->ID, '_give_goal_option', true ) ) ) |
|
1032 | - && give_is_setting_enabled( give_get_meta( $this->ID, '_give_close_form_when_goal_achieved', true ) ) |
|
1033 | - && ( $this->get_goal() <= $this->get_earnings() |
|
1031 | + give_is_setting_enabled(give_get_meta($this->ID, '_give_goal_option', true)) ) |
|
1032 | + && give_is_setting_enabled(give_get_meta($this->ID, '_give_close_form_when_goal_achieved', true)) |
|
1033 | + && ($this->get_goal() <= $this->get_earnings() |
|
1034 | 1034 | ), |
1035 | 1035 | $this->ID |
1036 | 1036 | ); |
@@ -1049,29 +1049,29 @@ discard block |
||
1049 | 1049 | * |
1050 | 1050 | * @return bool The result of the update query. |
1051 | 1051 | */ |
1052 | - private function update_meta( $meta_key = '', $meta_value = '' ) { |
|
1052 | + private function update_meta($meta_key = '', $meta_value = '') { |
|
1053 | 1053 | |
1054 | 1054 | /* @var WPDB $wpdb */ |
1055 | 1055 | global $wpdb; |
1056 | 1056 | |
1057 | - if ( empty( $meta_key ) ) { |
|
1057 | + if (empty($meta_key)) { |
|
1058 | 1058 | return false; |
1059 | 1059 | } |
1060 | 1060 | |
1061 | 1061 | // Make sure if it needs to be serialized, we do |
1062 | - $meta_value = maybe_serialize( $meta_value ); |
|
1062 | + $meta_value = maybe_serialize($meta_value); |
|
1063 | 1063 | |
1064 | - if ( is_numeric( $meta_value ) ) { |
|
1065 | - $value_type = is_float( $meta_value ) ? '%f' : '%d'; |
|
1064 | + if (is_numeric($meta_value)) { |
|
1065 | + $value_type = is_float($meta_value) ? '%f' : '%d'; |
|
1066 | 1066 | } else { |
1067 | 1067 | $value_type = "'%s'"; |
1068 | 1068 | } |
1069 | 1069 | |
1070 | - $sql = $wpdb->prepare( "UPDATE $wpdb->postmeta SET meta_value = $value_type WHERE post_id = $this->ID AND meta_key = '%s'", $meta_value, $meta_key ); |
|
1070 | + $sql = $wpdb->prepare("UPDATE $wpdb->postmeta SET meta_value = $value_type WHERE post_id = $this->ID AND meta_key = '%s'", $meta_value, $meta_key); |
|
1071 | 1071 | |
1072 | - if ( $wpdb->query( $sql ) ) { |
|
1072 | + if ($wpdb->query($sql)) { |
|
1073 | 1073 | |
1074 | - clean_post_cache( $this->ID ); |
|
1074 | + clean_post_cache($this->ID); |
|
1075 | 1075 | |
1076 | 1076 | return true; |
1077 | 1077 |
@@ -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 | |
@@ -26,15 +26,15 @@ discard block |
||
26 | 26 | * @global $wpdb |
27 | 27 | * @return void |
28 | 28 | */ |
29 | -function give_install( $network_wide = false ) { |
|
29 | +function give_install($network_wide = false) { |
|
30 | 30 | |
31 | 31 | global $wpdb; |
32 | 32 | |
33 | - if ( is_multisite() && $network_wide ) { |
|
33 | + if (is_multisite() && $network_wide) { |
|
34 | 34 | |
35 | - foreach ( $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs LIMIT 100" ) as $blog_id ) { |
|
35 | + foreach ($wpdb->get_col("SELECT blog_id FROM $wpdb->blogs LIMIT 100") as $blog_id) { |
|
36 | 36 | |
37 | - switch_to_blog( $blog_id ); |
|
37 | + switch_to_blog($blog_id); |
|
38 | 38 | give_run_install(); |
39 | 39 | restore_current_blog(); |
40 | 40 | |
@@ -62,34 +62,34 @@ discard block |
||
62 | 62 | give_setup_post_types(); |
63 | 63 | |
64 | 64 | // Clear the permalinks. |
65 | - flush_rewrite_rules( false ); |
|
65 | + flush_rewrite_rules(false); |
|
66 | 66 | |
67 | 67 | // Add Upgraded From Option. |
68 | - $current_version = get_option( 'give_version' ); |
|
69 | - if ( $current_version ) { |
|
70 | - update_option( 'give_version_upgraded_from', $current_version ); |
|
68 | + $current_version = get_option('give_version'); |
|
69 | + if ($current_version) { |
|
70 | + update_option('give_version_upgraded_from', $current_version); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | // Setup some default options. |
74 | 74 | $options = array(); |
75 | 75 | |
76 | 76 | //Fresh Install? Setup Test Mode, Base Country (US), Test Gateway, Currency. |
77 | - if ( empty( $current_version ) ) { |
|
78 | - $options = array_merge( $options, give_get_default_settings() ); |
|
77 | + if (empty($current_version)) { |
|
78 | + $options = array_merge($options, give_get_default_settings()); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | // Populate the default values. |
82 | - update_option( 'give_settings', array_merge( $give_options, $options ) ); |
|
82 | + update_option('give_settings', array_merge($give_options, $options)); |
|
83 | 83 | |
84 | 84 | /** |
85 | 85 | * Run plugin upgrades. |
86 | 86 | * |
87 | 87 | * @since 1.8 |
88 | 88 | */ |
89 | - do_action( 'give_upgrades' ); |
|
89 | + do_action('give_upgrades'); |
|
90 | 90 | |
91 | - if ( GIVE_VERSION !== get_option( 'give_version' ) ) { |
|
92 | - update_option( 'give_version', GIVE_VERSION ); |
|
91 | + if (GIVE_VERSION !== get_option('give_version')) { |
|
92 | + update_option('give_version', GIVE_VERSION); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | // Create Give roles. |
@@ -98,18 +98,18 @@ discard block |
||
98 | 98 | $roles->add_caps(); |
99 | 99 | |
100 | 100 | $api = new Give_API(); |
101 | - update_option( 'give_default_api_version', 'v' . $api->get_version() ); |
|
101 | + update_option('give_default_api_version', 'v'.$api->get_version()); |
|
102 | 102 | |
103 | 103 | // Check for PHP Session support, and enable if available. |
104 | 104 | $give_sessions = new Give_Session(); |
105 | 105 | $give_sessions->use_php_sessions(); |
106 | 106 | |
107 | 107 | // Add a temporary option to note that Give pages have been created. |
108 | - Give_Cache::set( '_give_installed', $options, 30, true ); |
|
108 | + Give_Cache::set('_give_installed', $options, 30, true); |
|
109 | 109 | |
110 | - if ( ! $current_version ) { |
|
110 | + if ( ! $current_version) { |
|
111 | 111 | |
112 | - require_once GIVE_PLUGIN_DIR . 'includes/admin/upgrades/upgrade-functions.php'; |
|
112 | + require_once GIVE_PLUGIN_DIR.'includes/admin/upgrades/upgrade-functions.php'; |
|
113 | 113 | |
114 | 114 | // When new upgrade routines are added, mark them as complete on fresh install. |
115 | 115 | $upgrade_routines = array( |
@@ -123,18 +123,18 @@ discard block |
||
123 | 123 | 'v1812_update_donor_purchase_values' |
124 | 124 | ); |
125 | 125 | |
126 | - foreach ( $upgrade_routines as $upgrade ) { |
|
127 | - give_set_upgrade_complete( $upgrade ); |
|
126 | + foreach ($upgrade_routines as $upgrade) { |
|
127 | + give_set_upgrade_complete($upgrade); |
|
128 | 128 | } |
129 | 129 | } |
130 | 130 | |
131 | 131 | // Bail if activating from network, or bulk. |
132 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
132 | + if (is_network_admin() || isset($_GET['activate-multi'])) { |
|
133 | 133 | return; |
134 | 134 | } |
135 | 135 | |
136 | 136 | // Add the transient to redirect. |
137 | - Give_Cache::set( '_give_activation_redirect', true, 30, true ); |
|
137 | + Give_Cache::set('_give_activation_redirect', true, 30, true); |
|
138 | 138 | |
139 | 139 | // Set 'Donation Form' meta box enabled by default. |
140 | 140 | give_nav_donation_metabox_enabled(); |
@@ -154,11 +154,11 @@ discard block |
||
154 | 154 | * @param int $site_id The Site ID. |
155 | 155 | * @param array $meta Blog Meta. |
156 | 156 | */ |
157 | -function give_on_create_blog( $blog_id, $user_id, $domain, $path, $site_id, $meta ) { |
|
157 | +function give_on_create_blog($blog_id, $user_id, $domain, $path, $site_id, $meta) { |
|
158 | 158 | |
159 | - if ( is_plugin_active_for_network( GIVE_PLUGIN_BASENAME ) ) { |
|
159 | + if (is_plugin_active_for_network(GIVE_PLUGIN_BASENAME)) { |
|
160 | 160 | |
161 | - switch_to_blog( $blog_id ); |
|
161 | + switch_to_blog($blog_id); |
|
162 | 162 | give_install(); |
163 | 163 | restore_current_blog(); |
164 | 164 | |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | |
167 | 167 | } |
168 | 168 | |
169 | -add_action( 'wpmu_new_blog', 'give_on_create_blog', 10, 6 ); |
|
169 | +add_action('wpmu_new_blog', 'give_on_create_blog', 10, 6); |
|
170 | 170 | |
171 | 171 | |
172 | 172 | /** |
@@ -179,13 +179,13 @@ discard block |
||
179 | 179 | * |
180 | 180 | * @return array The tables to drop. |
181 | 181 | */ |
182 | -function give_wpmu_drop_tables( $tables, $blog_id ) { |
|
182 | +function give_wpmu_drop_tables($tables, $blog_id) { |
|
183 | 183 | |
184 | - switch_to_blog( $blog_id ); |
|
184 | + switch_to_blog($blog_id); |
|
185 | 185 | $donors_db = new Give_DB_Donors(); |
186 | 186 | $donor_meta_db = new Give_DB_Donor_Meta(); |
187 | 187 | |
188 | - if ( $donors_db->installed() ) { |
|
188 | + if ($donors_db->installed()) { |
|
189 | 189 | $tables[] = $donors_db->table_name; |
190 | 190 | $tables[] = $donor_meta_db->table_name; |
191 | 191 | } |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | |
196 | 196 | } |
197 | 197 | |
198 | -add_filter( 'wpmu_drop_tables', 'give_wpmu_drop_tables', 10, 2 ); |
|
198 | +add_filter('wpmu_drop_tables', 'give_wpmu_drop_tables', 10, 2); |
|
199 | 199 | |
200 | 200 | /** |
201 | 201 | * Post-installation |
@@ -207,16 +207,16 @@ discard block |
||
207 | 207 | */ |
208 | 208 | function give_after_install() { |
209 | 209 | |
210 | - if ( ! is_admin() ) { |
|
210 | + if ( ! is_admin()) { |
|
211 | 211 | return; |
212 | 212 | } |
213 | 213 | |
214 | - $give_options = Give_Cache::get( '_give_installed', true ); |
|
215 | - $give_table_check = get_option( '_give_table_check', false ); |
|
214 | + $give_options = Give_Cache::get('_give_installed', true); |
|
215 | + $give_table_check = get_option('_give_table_check', false); |
|
216 | 216 | |
217 | - if ( false === $give_table_check || current_time( 'timestamp' ) > $give_table_check ) { |
|
217 | + if (false === $give_table_check || current_time('timestamp') > $give_table_check) { |
|
218 | 218 | |
219 | - if ( ! @Give()->donor_meta->installed() ) { |
|
219 | + if ( ! @Give()->donor_meta->installed()) { |
|
220 | 220 | |
221 | 221 | // Create the donor meta database. |
222 | 222 | // (this ensures it creates it on multisite instances where it is network activated). |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | |
225 | 225 | } |
226 | 226 | |
227 | - if ( ! @Give()->donors->installed() ) { |
|
227 | + if ( ! @Give()->donors->installed()) { |
|
228 | 228 | // Create the donor database. |
229 | 229 | // (this ensures it creates it on multisite instances where it is network activated). |
230 | 230 | @Give()->donors->create_table(); |
@@ -236,22 +236,22 @@ discard block |
||
236 | 236 | * |
237 | 237 | * @param array $give_options Give plugin options. |
238 | 238 | */ |
239 | - do_action( 'give_after_install', $give_options ); |
|
239 | + do_action('give_after_install', $give_options); |
|
240 | 240 | } |
241 | 241 | |
242 | - update_option( '_give_table_check', ( current_time( 'timestamp' ) + WEEK_IN_SECONDS ) ); |
|
242 | + update_option('_give_table_check', (current_time('timestamp') + WEEK_IN_SECONDS)); |
|
243 | 243 | |
244 | 244 | } |
245 | 245 | |
246 | 246 | // Delete the transient |
247 | - if ( false !== $give_options ) { |
|
248 | - Give_Cache::delete( Give_Cache::get_key( '_give_installed' ) ); |
|
247 | + if (false !== $give_options) { |
|
248 | + Give_Cache::delete(Give_Cache::get_key('_give_installed')); |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | |
252 | 252 | } |
253 | 253 | |
254 | -add_action( 'admin_init', 'give_after_install' ); |
|
254 | +add_action('admin_init', 'give_after_install'); |
|
255 | 255 | |
256 | 256 | |
257 | 257 | /** |
@@ -266,11 +266,11 @@ discard block |
||
266 | 266 | |
267 | 267 | global $wp_roles; |
268 | 268 | |
269 | - if ( ! is_object( $wp_roles ) ) { |
|
269 | + if ( ! is_object($wp_roles)) { |
|
270 | 270 | return; |
271 | 271 | } |
272 | 272 | |
273 | - if ( ! array_key_exists( 'give_manager', $wp_roles->roles ) ) { |
|
273 | + if ( ! array_key_exists('give_manager', $wp_roles->roles)) { |
|
274 | 274 | |
275 | 275 | // Create Give plugin roles |
276 | 276 | $roles = new Give_Roles(); |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | |
282 | 282 | } |
283 | 283 | |
284 | -add_action( 'admin_init', 'give_install_roles_on_network' ); |
|
284 | +add_action('admin_init', 'give_install_roles_on_network'); |
|
285 | 285 | |
286 | 286 | /** |
287 | 287 | * Default core setting values. |
@@ -317,14 +317,14 @@ discard block |
||
317 | 317 | 'uninstall_on_delete' => 'disabled', |
318 | 318 | 'the_content_filter' => 'enabled', |
319 | 319 | 'scripts_footer' => 'disabled', |
320 | - 'agree_to_terms_label' => __( 'Agree to Terms?', 'give' ), |
|
320 | + 'agree_to_terms_label' => __('Agree to Terms?', 'give'), |
|
321 | 321 | 'agreement_text' => give_get_default_agreement_text(), |
322 | 322 | |
323 | 323 | // Paypal IPN verification. |
324 | 324 | 'paypal_verification' => 'enabled', |
325 | 325 | |
326 | 326 | // Default is manual gateway. |
327 | - 'gateways' => array( 'manual' => 1, 'offline' => 1 ), |
|
327 | + 'gateways' => array('manual' => 1, 'offline' => 1), |
|
328 | 328 | 'default_gateway' => 'manual', |
329 | 329 | |
330 | 330 | // Offline gateway setup. |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | */ |
350 | 350 | function give_get_default_agreement_text() { |
351 | 351 | |
352 | - $org_name = get_bloginfo( 'name' ); |
|
352 | + $org_name = get_bloginfo('name'); |
|
353 | 353 | |
354 | 354 | $agreement = sprintf( |
355 | 355 | '<p>Acceptance of any contribution, gift or grant is at the discretion of the %1$s. The %1$s will not accept any gift unless it can be used or expended consistently with the purpose and mission of the %1$s.</p> |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | $org_name |
364 | 364 | ); |
365 | 365 | |
366 | - return apply_filters( 'give_get_default_agreement_text', $agreement, $org_name ); |
|
366 | + return apply_filters('give_get_default_agreement_text', $agreement, $org_name); |
|
367 | 367 | } |
368 | 368 | |
369 | 369 | |
@@ -372,22 +372,22 @@ discard block |
||
372 | 372 | * |
373 | 373 | * @since 1.8.11 |
374 | 374 | */ |
375 | -function give_create_pages(){ |
|
375 | +function give_create_pages() { |
|
376 | 376 | |
377 | 377 | // Bailout if pages already created. |
378 | - if( get_option( 'give_install_pages_created') ) { |
|
378 | + if (get_option('give_install_pages_created')) { |
|
379 | 379 | return false; |
380 | 380 | } |
381 | 381 | |
382 | 382 | $options = array(); |
383 | 383 | |
384 | 384 | // Checks if the Success Page option exists AND that the page exists. |
385 | - if ( ! get_post( give_get_option( 'success_page' ) ) ) { |
|
385 | + if ( ! get_post(give_get_option('success_page'))) { |
|
386 | 386 | |
387 | 387 | // Donation Confirmation (Success) Page |
388 | 388 | $success = wp_insert_post( |
389 | 389 | array( |
390 | - 'post_title' => esc_html__( 'Donation Confirmation', 'give' ), |
|
390 | + 'post_title' => esc_html__('Donation Confirmation', 'give'), |
|
391 | 391 | 'post_content' => '[give_receipt]', |
392 | 392 | 'post_status' => 'publish', |
393 | 393 | 'post_author' => 1, |
@@ -401,13 +401,13 @@ discard block |
||
401 | 401 | } |
402 | 402 | |
403 | 403 | // Checks if the Failure Page option exists AND that the page exists. |
404 | - if ( ! get_post( give_get_option( 'failure_page' ) ) ) { |
|
404 | + if ( ! get_post(give_get_option('failure_page'))) { |
|
405 | 405 | |
406 | 406 | // Failed Donation Page |
407 | 407 | $failed = wp_insert_post( |
408 | 408 | array( |
409 | - 'post_title' => esc_html__( 'Donation Failed', 'give' ), |
|
410 | - 'post_content' => esc_html__( 'We\'re sorry, your donation failed to process. Please try again or contact site support.', 'give' ), |
|
409 | + 'post_title' => esc_html__('Donation Failed', 'give'), |
|
410 | + 'post_content' => esc_html__('We\'re sorry, your donation failed to process. Please try again or contact site support.', 'give'), |
|
411 | 411 | 'post_status' => 'publish', |
412 | 412 | 'post_author' => 1, |
413 | 413 | 'post_type' => 'page', |
@@ -419,11 +419,11 @@ discard block |
||
419 | 419 | } |
420 | 420 | |
421 | 421 | // Checks if the History Page option exists AND that the page exists. |
422 | - if ( ! get_post( give_get_option( 'history_page' ) ) ) { |
|
422 | + if ( ! get_post(give_get_option('history_page'))) { |
|
423 | 423 | // Donation History Page |
424 | 424 | $history = wp_insert_post( |
425 | 425 | array( |
426 | - 'post_title' => esc_html__( 'Donation History', 'give' ), |
|
426 | + 'post_title' => esc_html__('Donation History', 'give'), |
|
427 | 427 | 'post_content' => '[donation_history]', |
428 | 428 | 'post_status' => 'publish', |
429 | 429 | 'post_author' => 1, |
@@ -435,10 +435,10 @@ discard block |
||
435 | 435 | $options['history_page'] = $history; |
436 | 436 | } |
437 | 437 | |
438 | - if( ! empty( $options ) ) { |
|
439 | - update_option( 'give_settings', array_merge( give_get_settings(), $options ) ); |
|
438 | + if ( ! empty($options)) { |
|
439 | + update_option('give_settings', array_merge(give_get_settings(), $options)); |
|
440 | 440 | } |
441 | 441 | |
442 | - add_option( 'give_install_pages_created', 1, '', 'no' ); |
|
442 | + add_option('give_install_pages_created', 1, '', 'no'); |
|
443 | 443 | } |
444 | -add_action( 'admin_init', 'give_create_pages', -1 ); |
|
444 | +add_action('admin_init', 'give_create_pages', -1); |
@@ -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 | |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @since 1.0 |
32 | 32 | */ |
33 | - do_action( 'give_pre_process_donation' ); |
|
33 | + do_action('give_pre_process_donation'); |
|
34 | 34 | |
35 | 35 | // Validate the form $_POST data |
36 | 36 | $valid_data = give_donation_form_validate_fields(); |
@@ -45,26 +45,26 @@ discard block |
||
45 | 45 | * @param bool|array $valid_data Validate fields. |
46 | 46 | * @param array $_POST Array of variables passed via the HTTP POST. |
47 | 47 | */ |
48 | - do_action( 'give_checkout_error_checks', $valid_data, $_POST ); |
|
48 | + do_action('give_checkout_error_checks', $valid_data, $_POST); |
|
49 | 49 | |
50 | - $is_ajax = isset( $_POST['give_ajax'] ); |
|
50 | + $is_ajax = isset($_POST['give_ajax']); |
|
51 | 51 | |
52 | 52 | // Process the login form |
53 | - if ( isset( $_POST['give_login_submit'] ) ) { |
|
53 | + if (isset($_POST['give_login_submit'])) { |
|
54 | 54 | give_process_form_login(); |
55 | 55 | } |
56 | 56 | |
57 | 57 | // Validate the user |
58 | - $user = give_get_donation_form_user( $valid_data ); |
|
58 | + $user = give_get_donation_form_user($valid_data); |
|
59 | 59 | |
60 | - if ( false === $valid_data || give_get_errors() || ! $user ) { |
|
61 | - if ( $is_ajax ) { |
|
60 | + if (false === $valid_data || give_get_errors() || ! $user) { |
|
61 | + if ($is_ajax) { |
|
62 | 62 | /** |
63 | 63 | * Fires when AJAX sends back errors from the donation form. |
64 | 64 | * |
65 | 65 | * @since 1.0 |
66 | 66 | */ |
67 | - do_action( 'give_ajax_donation_errors' ); |
|
67 | + do_action('give_ajax_donation_errors'); |
|
68 | 68 | give_die(); |
69 | 69 | } else { |
70 | 70 | return false; |
@@ -72,17 +72,17 @@ discard block |
||
72 | 72 | } |
73 | 73 | |
74 | 74 | // If AJAX send back success to proceed with form submission |
75 | - if ( $is_ajax ) { |
|
75 | + if ($is_ajax) { |
|
76 | 76 | echo 'success'; |
77 | 77 | give_die(); |
78 | 78 | } |
79 | 79 | |
80 | 80 | // After AJAX: Setup session if not using php_sessions |
81 | - if ( ! Give()->session->use_php_sessions() ) { |
|
81 | + if ( ! Give()->session->use_php_sessions()) { |
|
82 | 82 | // Double-check that set_cookie is publicly accessible; |
83 | 83 | // we're using a slightly modified class-wp-sessions.php |
84 | - $session_reflection = new ReflectionMethod( 'WP_Session', 'set_cookie' ); |
|
85 | - if ( $session_reflection->isPublic() ) { |
|
84 | + $session_reflection = new ReflectionMethod('WP_Session', 'set_cookie'); |
|
85 | + if ($session_reflection->isPublic()) { |
|
86 | 86 | // Manually set the cookie. |
87 | 87 | Give()->session->init()->set_cookie(); |
88 | 88 | } |
@@ -97,20 +97,19 @@ discard block |
||
97 | 97 | 'address' => $user['address'], |
98 | 98 | ); |
99 | 99 | |
100 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
100 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
101 | 101 | |
102 | - $price = isset( $_POST['give-amount'] ) ? |
|
103 | - (float) apply_filters( 'give_donation_total', give_maybe_sanitize_amount( $_POST['give-amount'] ) ) : |
|
104 | - '0.00'; |
|
105 | - $purchase_key = strtolower( md5( $user['user_email'] . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'give', true ) ) ); |
|
102 | + $price = isset($_POST['give-amount']) ? |
|
103 | + (float) apply_filters('give_donation_total', give_maybe_sanitize_amount($_POST['give-amount'])) : '0.00'; |
|
104 | + $purchase_key = strtolower(md5($user['user_email'].date('Y-m-d H:i:s').$auth_key.uniqid('give', true))); |
|
106 | 105 | |
107 | 106 | // Setup donation information |
108 | 107 | $donation_data = array( |
109 | 108 | 'price' => $price, |
110 | 109 | 'purchase_key' => $purchase_key, |
111 | 110 | 'user_email' => $user['user_email'], |
112 | - 'date' => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ), |
|
113 | - 'user_info' => stripslashes_deep( $user_info ), |
|
111 | + 'date' => date('Y-m-d H:i:s', current_time('timestamp')), |
|
112 | + 'user_info' => stripslashes_deep($user_info), |
|
114 | 113 | 'post_data' => $_POST, |
115 | 114 | 'gateway' => $valid_data['gateway'], |
116 | 115 | 'card_info' => $valid_data['cc_info'], |
@@ -130,10 +129,10 @@ discard block |
||
130 | 129 | * @param array $user_info Array containing basic user information. |
131 | 130 | * @param bool|array $valid_data Validate fields. |
132 | 131 | */ |
133 | - do_action( 'give_checkout_before_gateway', $_POST, $user_info, $valid_data ); |
|
132 | + do_action('give_checkout_before_gateway', $_POST, $user_info, $valid_data); |
|
134 | 133 | |
135 | 134 | // Sanity check for price |
136 | - if ( ! $donation_data['price'] ) { |
|
135 | + if ( ! $donation_data['price']) { |
|
137 | 136 | // Revert to manual |
138 | 137 | $donation_data['gateway'] = 'manual'; |
139 | 138 | $_POST['give-gateway'] = 'manual'; |
@@ -144,27 +143,27 @@ discard block |
||
144 | 143 | * |
145 | 144 | * @since 1.7 |
146 | 145 | */ |
147 | - $donation_data = apply_filters( 'give_donation_data_before_gateway', $donation_data, $valid_data ); |
|
146 | + $donation_data = apply_filters('give_donation_data_before_gateway', $donation_data, $valid_data); |
|
148 | 147 | |
149 | 148 | // Setup the data we're storing in the donation session |
150 | 149 | $session_data = $donation_data; |
151 | 150 | |
152 | 151 | // Make sure credit card numbers are never stored in sessions |
153 | - unset( $session_data['card_info']['card_number'] ); |
|
154 | - unset( $session_data['post_data']['card_number'] ); |
|
152 | + unset($session_data['card_info']['card_number']); |
|
153 | + unset($session_data['post_data']['card_number']); |
|
155 | 154 | |
156 | 155 | // Used for showing data to non logged-in users after donation, and for other plugins needing donation data. |
157 | - give_set_purchase_session( $session_data ); |
|
156 | + give_set_purchase_session($session_data); |
|
158 | 157 | |
159 | 158 | // Send info to the gateway for payment processing |
160 | - give_send_to_gateway( $donation_data['gateway'], $donation_data ); |
|
159 | + give_send_to_gateway($donation_data['gateway'], $donation_data); |
|
161 | 160 | give_die(); |
162 | 161 | |
163 | 162 | } |
164 | 163 | |
165 | -add_action( 'give_purchase', 'give_process_donation_form' ); |
|
166 | -add_action( 'wp_ajax_give_process_donation', 'give_process_donation_form' ); |
|
167 | -add_action( 'wp_ajax_nopriv_give_process_donation', 'give_process_donation_form' ); |
|
164 | +add_action('give_purchase', 'give_process_donation_form'); |
|
165 | +add_action('wp_ajax_give_process_donation', 'give_process_donation_form'); |
|
166 | +add_action('wp_ajax_nopriv_give_process_donation', 'give_process_donation_form'); |
|
168 | 167 | |
169 | 168 | |
170 | 169 | /** |
@@ -177,29 +176,29 @@ discard block |
||
177 | 176 | * |
178 | 177 | * @return void |
179 | 178 | */ |
180 | -function give_check_logged_in_user_for_existing_email( $valid_data, $post ) { |
|
179 | +function give_check_logged_in_user_for_existing_email($valid_data, $post) { |
|
181 | 180 | |
182 | 181 | // Verify that the email address belongs to this customer. |
183 | - if ( is_user_logged_in() ) { |
|
182 | + if (is_user_logged_in()) { |
|
184 | 183 | |
185 | - $submitted_email = $valid_data['logged_in_user']['user_email']; |
|
186 | - $customer = new Give_Donor( get_current_user_id(), true ); |
|
184 | + $submitted_email = $valid_data['logged_in_user']['user_email']; |
|
185 | + $customer = new Give_Donor(get_current_user_id(), true); |
|
187 | 186 | |
188 | 187 | // If this email address is not registered with this customer, see if it belongs to any other customer |
189 | 188 | if ( |
190 | 189 | $submitted_email !== $customer->email |
191 | - && ( is_array( $customer->emails ) && ! in_array( $submitted_email, $customer->emails ) ) |
|
190 | + && (is_array($customer->emails) && ! in_array($submitted_email, $customer->emails)) |
|
192 | 191 | ) { |
193 | - $found_customer = new Give_Donor( $submitted_email ); |
|
192 | + $found_customer = new Give_Donor($submitted_email); |
|
194 | 193 | |
195 | - if ( $found_customer->id > 0 ) { |
|
196 | - give_set_error( 'give-customer-email-exists', sprintf( __( 'You are logged in as %1$s, and are submitting a donation as %2$s, which is an existing donor. To ensure that the email address is tied to the correct donor, please submit this donation from a logged-out browser, or choose another email address.' ,'give' ), $customer->email, $submitted_email ) ); |
|
194 | + if ($found_customer->id > 0) { |
|
195 | + give_set_error('give-customer-email-exists', sprintf(__('You are logged in as %1$s, and are submitting a donation as %2$s, which is an existing donor. To ensure that the email address is tied to the correct donor, please submit this donation from a logged-out browser, or choose another email address.', 'give'), $customer->email, $submitted_email)); |
|
197 | 196 | } |
198 | 197 | } |
199 | 198 | } |
200 | 199 | } |
201 | 200 | |
202 | -add_action( 'give_checkout_error_checks', 'give_check_logged_in_user_for_existing_email', 10, 2 ); |
|
201 | +add_action('give_checkout_error_checks', 'give_check_logged_in_user_for_existing_email', 10, 2); |
|
203 | 202 | |
204 | 203 | /** |
205 | 204 | * Process the checkout login form |
@@ -209,49 +208,49 @@ discard block |
||
209 | 208 | * @return void |
210 | 209 | */ |
211 | 210 | function give_process_form_login() { |
212 | - $is_ajax = isset( $_POST['give_ajax'] ); |
|
211 | + $is_ajax = isset($_POST['give_ajax']); |
|
213 | 212 | |
214 | 213 | $user_data = give_donation_form_validate_user_login(); |
215 | 214 | |
216 | - if ( give_get_errors() || $user_data['user_id'] < 1 ) { |
|
217 | - if ( $is_ajax ) { |
|
215 | + if (give_get_errors() || $user_data['user_id'] < 1) { |
|
216 | + if ($is_ajax) { |
|
218 | 217 | /** |
219 | 218 | * Fires when AJAX sends back errors from the donation form. |
220 | 219 | * |
221 | 220 | * @since 1.0 |
222 | 221 | */ |
223 | 222 | ob_start(); |
224 | - do_action( 'give_ajax_donation_errors' ); |
|
223 | + do_action('give_ajax_donation_errors'); |
|
225 | 224 | $message = ob_get_contents(); |
226 | 225 | ob_end_clean(); |
227 | - wp_send_json_error( $message ); |
|
226 | + wp_send_json_error($message); |
|
228 | 227 | } else { |
229 | - wp_redirect( $_SERVER['HTTP_REFERER'] ); |
|
228 | + wp_redirect($_SERVER['HTTP_REFERER']); |
|
230 | 229 | exit; |
231 | 230 | } |
232 | 231 | } |
233 | 232 | |
234 | - give_log_user_in( $user_data['user_id'], $user_data['user_login'], $user_data['user_pass'] ); |
|
233 | + give_log_user_in($user_data['user_id'], $user_data['user_login'], $user_data['user_pass']); |
|
235 | 234 | |
236 | - if ( $is_ajax ) { |
|
235 | + if ($is_ajax) { |
|
237 | 236 | $message = Give()->notices->print_frontend_notice( |
238 | 237 | sprintf( |
239 | 238 | /* translators: %s: user first name */ |
240 | - esc_html__( 'Welcome %s! You have successfully logged into your account.', 'give' ), |
|
241 | - ( ! empty( $user_data['user_first'] ) ) ? $user_data['user_first'] : $user_data['user_login'] |
|
239 | + esc_html__('Welcome %s! You have successfully logged into your account.', 'give'), |
|
240 | + ( ! empty($user_data['user_first'])) ? $user_data['user_first'] : $user_data['user_login'] |
|
242 | 241 | ), |
243 | 242 | false, |
244 | 243 | 'success' |
245 | 244 | ); |
246 | 245 | |
247 | - wp_send_json_success( $message ); |
|
246 | + wp_send_json_success($message); |
|
248 | 247 | } else { |
249 | - wp_redirect( $_SERVER['HTTP_REFERER'] ); |
|
248 | + wp_redirect($_SERVER['HTTP_REFERER']); |
|
250 | 249 | } |
251 | 250 | } |
252 | 251 | |
253 | -add_action( 'wp_ajax_give_process_donation_login', 'give_process_form_login' ); |
|
254 | -add_action( 'wp_ajax_nopriv_give_process_donation_login', 'give_process_form_login' ); |
|
252 | +add_action('wp_ajax_give_process_donation_login', 'give_process_form_login'); |
|
253 | +add_action('wp_ajax_nopriv_give_process_donation_login', 'give_process_form_login'); |
|
255 | 254 | |
256 | 255 | /** |
257 | 256 | * Donation Form Validate Fields. |
@@ -263,55 +262,55 @@ discard block |
||
263 | 262 | function give_donation_form_validate_fields() { |
264 | 263 | |
265 | 264 | // Check if there is $_POST |
266 | - if ( empty( $_POST ) ) { |
|
265 | + if (empty($_POST)) { |
|
267 | 266 | return false; |
268 | 267 | } |
269 | 268 | |
270 | - $form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : ''; |
|
269 | + $form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : ''; |
|
271 | 270 | |
272 | 271 | // Start an array to collect valid data |
273 | 272 | $valid_data = array( |
274 | 273 | 'gateway' => give_donation_form_validate_gateway(), // Gateway fallback (amount is validated here) |
275 | - 'need_new_user' => false, // New user flag |
|
276 | - 'need_user_login' => false, // Login user flag |
|
277 | - 'logged_user_data' => array(), // Logged user collected data |
|
278 | - 'new_user_data' => array(), // New user collected data |
|
279 | - 'login_user_data' => array(), // Login user collected data |
|
280 | - 'guest_user_data' => array(), // Guest user collected data |
|
281 | - 'cc_info' => give_donation_form_validate_cc(),// Credit card info |
|
274 | + 'need_new_user' => false, // New user flag |
|
275 | + 'need_user_login' => false, // Login user flag |
|
276 | + 'logged_user_data' => array(), // Logged user collected data |
|
277 | + 'new_user_data' => array(), // New user collected data |
|
278 | + 'login_user_data' => array(), // Login user collected data |
|
279 | + 'guest_user_data' => array(), // Guest user collected data |
|
280 | + 'cc_info' => give_donation_form_validate_cc(), // Credit card info |
|
282 | 281 | ); |
283 | 282 | |
284 | 283 | // Validate Honeypot First |
285 | - if ( ! empty( $_POST['give-honeypot'] ) ) { |
|
286 | - give_set_error( 'invalid_honeypot', esc_html__( 'Honeypot field detected. Go away bad bot!', 'give' ) ); |
|
284 | + if ( ! empty($_POST['give-honeypot'])) { |
|
285 | + give_set_error('invalid_honeypot', esc_html__('Honeypot field detected. Go away bad bot!', 'give')); |
|
287 | 286 | } |
288 | 287 | |
289 | 288 | // Validate agree to terms |
290 | - if ( give_is_terms_enabled( $form_id ) ) { |
|
289 | + if (give_is_terms_enabled($form_id)) { |
|
291 | 290 | give_donation_form_validate_agree_to_terms(); |
292 | 291 | } |
293 | 292 | |
294 | 293 | // Stop processing donor registration, if donor registration is optional and donor can do guest checkout. |
295 | 294 | // If registration form username field is empty that means donor do not want to registration instead want guest checkout. |
296 | 295 | if ( |
297 | - ! give_logged_in_only( $form_id ) |
|
298 | - && isset( $_POST['give-purchase-var'] ) |
|
296 | + ! give_logged_in_only($form_id) |
|
297 | + && isset($_POST['give-purchase-var']) |
|
299 | 298 | && $_POST['give-purchase-var'] == 'needs-to-register' |
300 | - && empty( $_POST['give_user_login'] ) |
|
299 | + && empty($_POST['give_user_login']) |
|
301 | 300 | ) { |
302 | - unset( $_POST['give-purchase-var'] ); |
|
301 | + unset($_POST['give-purchase-var']); |
|
303 | 302 | } |
304 | 303 | |
305 | - if ( is_user_logged_in() ) { |
|
304 | + if (is_user_logged_in()) { |
|
306 | 305 | // Collect logged in user data. |
307 | 306 | $valid_data['logged_in_user'] = give_donation_form_validate_logged_in_user(); |
308 | - } elseif ( isset( $_POST['give-purchase-var'] ) && $_POST['give-purchase-var'] == 'needs-to-register' ) { |
|
307 | + } elseif (isset($_POST['give-purchase-var']) && $_POST['give-purchase-var'] == 'needs-to-register') { |
|
309 | 308 | // Set new user registration as required. |
310 | 309 | $valid_data['need_new_user'] = true; |
311 | 310 | // Validate new user data. |
312 | 311 | $valid_data['new_user_data'] = give_donation_form_validate_new_user(); |
313 | 312 | // Check if login validation is needed. |
314 | - } elseif ( isset( $_POST['give-purchase-var'] ) && $_POST['give-purchase-var'] == 'needs-to-login' ) { |
|
313 | + } elseif (isset($_POST['give-purchase-var']) && $_POST['give-purchase-var'] == 'needs-to-login') { |
|
315 | 314 | // Set user login as required. |
316 | 315 | $valid_data['need_user_login'] = true; |
317 | 316 | // Validate users login info. |
@@ -336,41 +335,41 @@ discard block |
||
336 | 335 | */ |
337 | 336 | function give_donation_form_validate_gateway() { |
338 | 337 | |
339 | - $form_id = isset( $_REQUEST['give-form-id'] ) ? $_REQUEST['give-form-id'] : 0; |
|
340 | - $amount = isset( $_REQUEST['give-amount'] ) ? give_maybe_sanitize_amount( $_REQUEST['give-amount'] ) : 0; |
|
341 | - $gateway = give_get_default_gateway( $form_id ); |
|
338 | + $form_id = isset($_REQUEST['give-form-id']) ? $_REQUEST['give-form-id'] : 0; |
|
339 | + $amount = isset($_REQUEST['give-amount']) ? give_maybe_sanitize_amount($_REQUEST['give-amount']) : 0; |
|
340 | + $gateway = give_get_default_gateway($form_id); |
|
342 | 341 | |
343 | 342 | // Check if a gateway value is present. |
344 | - if ( ! empty( $_REQUEST['give-gateway'] ) ) { |
|
343 | + if ( ! empty($_REQUEST['give-gateway'])) { |
|
345 | 344 | |
346 | - $gateway = sanitize_text_field( $_REQUEST['give-gateway'] ); |
|
345 | + $gateway = sanitize_text_field($_REQUEST['give-gateway']); |
|
347 | 346 | |
348 | 347 | // Is amount being donated in LIVE mode 0.00? If so, error: |
349 | - if ( $amount == 0 && ! give_is_test_mode() ) { |
|
348 | + if ($amount == 0 && ! give_is_test_mode()) { |
|
350 | 349 | |
351 | - give_set_error( 'invalid_donation_amount', __( 'Please insert a valid donation amount.', 'give' ) ); |
|
350 | + give_set_error('invalid_donation_amount', __('Please insert a valid donation amount.', 'give')); |
|
352 | 351 | |
353 | 352 | } // End if(). |
354 | - elseif ( ! give_verify_minimum_price() ) { |
|
353 | + elseif ( ! give_verify_minimum_price()) { |
|
355 | 354 | // translators: %s: minimum donation amount. |
356 | 355 | give_set_error( |
357 | 356 | 'invalid_donation_minimum', |
358 | 357 | sprintf( |
359 | 358 | /* translators: %s: minimum donation amount */ |
360 | - __( 'This form has a minimum donation amount of %s.', 'give' ), |
|
361 | - give_currency_filter( give_format_amount( give_get_form_minimum_price( $form_id ), array( 'sanitize' => false ) ) ) |
|
359 | + __('This form has a minimum donation amount of %s.', 'give'), |
|
360 | + give_currency_filter(give_format_amount(give_get_form_minimum_price($form_id), array('sanitize' => false))) |
|
362 | 361 | ) |
363 | 362 | ); |
364 | 363 | |
365 | 364 | } //Is this test mode zero donation? Let it through but set to manual gateway. |
366 | - elseif ( $amount == 0 && give_is_test_mode() ) { |
|
365 | + elseif ($amount == 0 && give_is_test_mode()) { |
|
367 | 366 | |
368 | 367 | $gateway = 'manual'; |
369 | 368 | |
370 | 369 | } //Check if this gateway is active. |
371 | - elseif ( ! give_is_gateway_active( $gateway ) ) { |
|
370 | + elseif ( ! give_is_gateway_active($gateway)) { |
|
372 | 371 | |
373 | - give_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled.', 'give' ) ); |
|
372 | + give_set_error('invalid_gateway', __('The selected payment gateway is not enabled.', 'give')); |
|
374 | 373 | |
375 | 374 | } |
376 | 375 | } |
@@ -388,21 +387,21 @@ discard block |
||
388 | 387 | */ |
389 | 388 | function give_verify_minimum_price() { |
390 | 389 | |
391 | - $amount = give_maybe_sanitize_amount( $_REQUEST['give-amount'] ); |
|
392 | - $form_id = isset( $_REQUEST['give-form-id'] ) ? $_REQUEST['give-form-id'] : 0; |
|
393 | - $price_id = isset( $_REQUEST['give-price-id'] ) ? $_REQUEST['give-price-id'] : null; |
|
394 | - $variable_prices = give_has_variable_prices( $form_id ); |
|
390 | + $amount = give_maybe_sanitize_amount($_REQUEST['give-amount']); |
|
391 | + $form_id = isset($_REQUEST['give-form-id']) ? $_REQUEST['give-form-id'] : 0; |
|
392 | + $price_id = isset($_REQUEST['give-price-id']) ? $_REQUEST['give-price-id'] : null; |
|
393 | + $variable_prices = give_has_variable_prices($form_id); |
|
395 | 394 | |
396 | - if ( $variable_prices && in_array( $price_id, give_get_variable_price_ids( $form_id ) ) ) { |
|
395 | + if ($variable_prices && in_array($price_id, give_get_variable_price_ids($form_id))) { |
|
397 | 396 | |
398 | - $price_level_amount = give_get_price_option_amount( $form_id, $price_id ); |
|
397 | + $price_level_amount = give_get_price_option_amount($form_id, $price_id); |
|
399 | 398 | |
400 | - if ( $price_level_amount == $amount ) { |
|
399 | + if ($price_level_amount == $amount) { |
|
401 | 400 | return true; |
402 | 401 | } |
403 | 402 | } |
404 | 403 | |
405 | - if ( give_get_form_minimum_price( $form_id ) > $amount ) { |
|
404 | + if (give_get_form_minimum_price($form_id) > $amount) { |
|
406 | 405 | return false; |
407 | 406 | } |
408 | 407 | |
@@ -418,9 +417,9 @@ discard block |
||
418 | 417 | */ |
419 | 418 | function give_donation_form_validate_agree_to_terms() { |
420 | 419 | // Validate agree to terms. |
421 | - if ( ! isset( $_POST['give_agree_to_terms'] ) || $_POST['give_agree_to_terms'] != 1 ) { |
|
420 | + if ( ! isset($_POST['give_agree_to_terms']) || $_POST['give_agree_to_terms'] != 1) { |
|
422 | 421 | // User did not agree. |
423 | - give_set_error( 'agree_to_terms', apply_filters( 'give_agree_to_terms_text', __( 'You must agree to the terms and conditions.', 'give' ) ) ); |
|
422 | + give_set_error('agree_to_terms', apply_filters('give_agree_to_terms_text', __('You must agree to the terms and conditions.', 'give'))); |
|
424 | 423 | } |
425 | 424 | } |
426 | 425 | |
@@ -434,59 +433,59 @@ discard block |
||
434 | 433 | * |
435 | 434 | * @return array |
436 | 435 | */ |
437 | -function give_get_required_fields( $form_id ) { |
|
436 | +function give_get_required_fields($form_id) { |
|
438 | 437 | |
439 | - $payment_mode = give_get_chosen_gateway( $form_id ); |
|
438 | + $payment_mode = give_get_chosen_gateway($form_id); |
|
440 | 439 | |
441 | 440 | $required_fields = array( |
442 | 441 | 'give_email' => array( |
443 | 442 | 'error_id' => 'invalid_email', |
444 | - 'error_message' => __( 'Please enter a valid email address.', 'give' ), |
|
443 | + 'error_message' => __('Please enter a valid email address.', 'give'), |
|
445 | 444 | ), |
446 | 445 | 'give_first' => array( |
447 | 446 | 'error_id' => 'invalid_first_name', |
448 | - 'error_message' => __( 'Please enter your first name.', 'give' ), |
|
447 | + 'error_message' => __('Please enter your first name.', 'give'), |
|
449 | 448 | ), |
450 | 449 | ); |
451 | 450 | |
452 | - $require_address = give_require_billing_address( $payment_mode ); |
|
451 | + $require_address = give_require_billing_address($payment_mode); |
|
453 | 452 | |
454 | - if ( $require_address ) { |
|
455 | - $required_fields['card_address'] = array( |
|
453 | + if ($require_address) { |
|
454 | + $required_fields['card_address'] = array( |
|
456 | 455 | 'error_id' => 'invalid_card_address', |
457 | - 'error_message' => __( 'Please enter your primary billing address.', 'give' ), |
|
456 | + 'error_message' => __('Please enter your primary billing address.', 'give'), |
|
458 | 457 | ); |
459 | - $required_fields['card_zip'] = array( |
|
458 | + $required_fields['card_zip'] = array( |
|
460 | 459 | 'error_id' => 'invalid_zip_code', |
461 | - 'error_message' => __( 'Please enter your zip / postal code.', 'give' ), |
|
460 | + 'error_message' => __('Please enter your zip / postal code.', 'give'), |
|
462 | 461 | ); |
463 | - $required_fields['card_city'] = array( |
|
462 | + $required_fields['card_city'] = array( |
|
464 | 463 | 'error_id' => 'invalid_city', |
465 | - 'error_message' => __( 'Please enter your billing city.', 'give' ), |
|
464 | + 'error_message' => __('Please enter your billing city.', 'give'), |
|
466 | 465 | ); |
467 | 466 | $required_fields['billing_country'] = array( |
468 | 467 | 'error_id' => 'invalid_country', |
469 | - 'error_message' => __( 'Please select your billing country.', 'give' ), |
|
468 | + 'error_message' => __('Please select your billing country.', 'give'), |
|
470 | 469 | ); |
471 | 470 | |
472 | 471 | |
473 | - $required_fields['card_state'] = array( |
|
472 | + $required_fields['card_state'] = array( |
|
474 | 473 | 'error_id' => 'invalid_state', |
475 | - 'error_message' => __( 'Please enter billing state / province / County.', 'give' ), |
|
474 | + 'error_message' => __('Please enter billing state / province / County.', 'give'), |
|
476 | 475 | ); |
477 | 476 | |
478 | 477 | // Check if billing country alredy exists. |
479 | - if ( ! empty( $_POST['billing_country'] ) ) { |
|
478 | + if ( ! empty($_POST['billing_country'])) { |
|
480 | 479 | // Get the value from $_POST. |
481 | - $country = sanitize_text_field( $_POST['billing_country'] ); |
|
480 | + $country = sanitize_text_field($_POST['billing_country']); |
|
482 | 481 | |
483 | 482 | // Get the country list that does not required any states init. |
484 | 483 | $states_country = give_states_not_required_country_list(); |
485 | 484 | |
486 | 485 | // Check if states is empty or not. |
487 | - if ( array_key_exists( $country, $states_country ) ) { |
|
486 | + if (array_key_exists($country, $states_country)) { |
|
488 | 487 | // If states is empty remove the required feilds of state in billing cart. |
489 | - unset( $required_fields['card_state'] ); |
|
488 | + unset($required_fields['card_state']); |
|
490 | 489 | } |
491 | 490 | } |
492 | 491 | } |
@@ -496,7 +495,7 @@ discard block |
||
496 | 495 | * |
497 | 496 | * @since 1.7 |
498 | 497 | */ |
499 | - $required_fields = apply_filters( 'give_donation_form_required_fields', $required_fields, $form_id ); |
|
498 | + $required_fields = apply_filters('give_donation_form_required_fields', $required_fields, $form_id); |
|
500 | 499 | |
501 | 500 | return $required_fields; |
502 | 501 | |
@@ -511,16 +510,16 @@ discard block |
||
511 | 510 | * |
512 | 511 | * @return bool |
513 | 512 | */ |
514 | -function give_require_billing_address( $payment_mode ) { |
|
513 | +function give_require_billing_address($payment_mode) { |
|
515 | 514 | |
516 | 515 | $return = false; |
517 | 516 | |
518 | - if ( isset( $_POST['billing_country'] ) || did_action( "give_{$payment_mode}_cc_form" ) || did_action( 'give_cc_form' ) ) { |
|
517 | + if (isset($_POST['billing_country']) || did_action("give_{$payment_mode}_cc_form") || did_action('give_cc_form')) { |
|
519 | 518 | $return = true; |
520 | 519 | } |
521 | 520 | |
522 | 521 | // Let payment gateways and other extensions determine if address fields should be required. |
523 | - return apply_filters( 'give_require_billing_address', $return ); |
|
522 | + return apply_filters('give_require_billing_address', $return); |
|
524 | 523 | |
525 | 524 | } |
526 | 525 | |
@@ -534,42 +533,42 @@ discard block |
||
534 | 533 | function give_donation_form_validate_logged_in_user() { |
535 | 534 | global $user_ID; |
536 | 535 | |
537 | - $form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : ''; |
|
536 | + $form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : ''; |
|
538 | 537 | |
539 | 538 | // Start empty array to collect valid user data. |
540 | 539 | $valid_user_data = array( |
541 | 540 | // Assume there will be errors. |
542 | - 'user_id' => - 1, |
|
541 | + 'user_id' => -1, |
|
543 | 542 | ); |
544 | 543 | |
545 | 544 | // Verify there is a user_ID. |
546 | - if ( $user_ID > 0 ) { |
|
545 | + if ($user_ID > 0) { |
|
547 | 546 | // Get the logged in user data. |
548 | - $user_data = get_userdata( $user_ID ); |
|
547 | + $user_data = get_userdata($user_ID); |
|
549 | 548 | |
550 | 549 | // Loop through required fields and show error messages. |
551 | - foreach ( give_get_required_fields( $form_id ) as $field_name => $value ) { |
|
552 | - if ( in_array( $value, give_get_required_fields( $form_id ) ) && empty( $_POST[ $field_name ] ) ) { |
|
553 | - give_set_error( $value['error_id'], $value['error_message'] ); |
|
550 | + foreach (give_get_required_fields($form_id) as $field_name => $value) { |
|
551 | + if (in_array($value, give_get_required_fields($form_id)) && empty($_POST[$field_name])) { |
|
552 | + give_set_error($value['error_id'], $value['error_message']); |
|
554 | 553 | } |
555 | 554 | } |
556 | 555 | |
557 | 556 | // Verify data. |
558 | - if ( $user_data ) { |
|
557 | + if ($user_data) { |
|
559 | 558 | // Collected logged in user data. |
560 | 559 | $valid_user_data = array( |
561 | 560 | 'user_id' => $user_ID, |
562 | - 'user_email' => isset( $_POST['give_email'] ) ? sanitize_email( $_POST['give_email'] ) : $user_data->user_email, |
|
563 | - 'user_first' => isset( $_POST['give_first'] ) && ! empty( $_POST['give_first'] ) ? sanitize_text_field( $_POST['give_first'] ) : $user_data->first_name, |
|
564 | - 'user_last' => isset( $_POST['give_last'] ) && ! empty( $_POST['give_last'] ) ? sanitize_text_field( $_POST['give_last'] ) : $user_data->last_name, |
|
561 | + 'user_email' => isset($_POST['give_email']) ? sanitize_email($_POST['give_email']) : $user_data->user_email, |
|
562 | + 'user_first' => isset($_POST['give_first']) && ! empty($_POST['give_first']) ? sanitize_text_field($_POST['give_first']) : $user_data->first_name, |
|
563 | + 'user_last' => isset($_POST['give_last']) && ! empty($_POST['give_last']) ? sanitize_text_field($_POST['give_last']) : $user_data->last_name, |
|
565 | 564 | ); |
566 | 565 | |
567 | - if ( ! is_email( $valid_user_data['user_email'] ) ) { |
|
568 | - give_set_error( 'email_invalid', esc_html__( 'Invalid email.', 'give' ) ); |
|
566 | + if ( ! is_email($valid_user_data['user_email'])) { |
|
567 | + give_set_error('email_invalid', esc_html__('Invalid email.', 'give')); |
|
569 | 568 | } |
570 | 569 | } else { |
571 | 570 | // Set invalid user error. |
572 | - give_set_error( 'invalid_user', esc_html__( 'The user information is invalid.', 'give' ) ); |
|
571 | + give_set_error('invalid_user', esc_html__('The user information is invalid.', 'give')); |
|
573 | 572 | } |
574 | 573 | } |
575 | 574 | |
@@ -588,7 +587,7 @@ discard block |
||
588 | 587 | // Default user data. |
589 | 588 | $default_user_data = array( |
590 | 589 | 'give-form-id' => '', |
591 | - 'user_id' => - 1, // Assume there will be errors. |
|
590 | + 'user_id' => -1, // Assume there will be errors. |
|
592 | 591 | 'user_first' => '', |
593 | 592 | 'user_last' => '', |
594 | 593 | 'give_user_login' => false, |
@@ -598,14 +597,14 @@ discard block |
||
598 | 597 | ); |
599 | 598 | |
600 | 599 | // Get user data. |
601 | - $user_data = wp_parse_args( array_map( 'trim', give_clean( $_POST ) ), $default_user_data ); |
|
600 | + $user_data = wp_parse_args(array_map('trim', give_clean($_POST)), $default_user_data); |
|
602 | 601 | $registering_new_user = false; |
603 | - $form_id = absint( $user_data['give-form-id'] ); |
|
602 | + $form_id = absint($user_data['give-form-id']); |
|
604 | 603 | |
605 | 604 | // Start an empty array to collect valid user data. |
606 | 605 | $valid_user_data = array( |
607 | 606 | // Assume there will be errors. |
608 | - 'user_id' => - 1, |
|
607 | + 'user_id' => -1, |
|
609 | 608 | |
610 | 609 | // Get first name. |
611 | 610 | 'user_first' => $user_data['give_first'], |
@@ -615,25 +614,25 @@ discard block |
||
615 | 614 | ); |
616 | 615 | |
617 | 616 | // Loop through required fields and show error messages. |
618 | - foreach ( give_get_required_fields( $form_id ) as $field_name => $value ) { |
|
619 | - if ( in_array( $value, give_get_required_fields( $form_id ) ) && empty( $_POST[ $field_name ] ) ) { |
|
620 | - give_set_error( $value['error_id'], $value['error_message'] ); |
|
617 | + foreach (give_get_required_fields($form_id) as $field_name => $value) { |
|
618 | + if (in_array($value, give_get_required_fields($form_id)) && empty($_POST[$field_name])) { |
|
619 | + give_set_error($value['error_id'], $value['error_message']); |
|
621 | 620 | } |
622 | 621 | } |
623 | 622 | |
624 | 623 | // Check if we have an username to register. |
625 | - if ( give_validate_username( $user_data['give_user_login'] ) ) { |
|
624 | + if (give_validate_username($user_data['give_user_login'])) { |
|
626 | 625 | $registering_new_user = true; |
627 | 626 | $valid_user_data['user_login'] = $user_data['give_user_login']; |
628 | 627 | } |
629 | 628 | |
630 | 629 | // Check if we have an email to verify. |
631 | - if ( give_validate_user_email( $user_data['give_email'], $registering_new_user ) ) { |
|
630 | + if (give_validate_user_email($user_data['give_email'], $registering_new_user)) { |
|
632 | 631 | $valid_user_data['user_email'] = $user_data['give_email']; |
633 | 632 | } |
634 | 633 | |
635 | 634 | // Check password. |
636 | - if ( give_validate_user_password( $user_data['give_user_pass'], $user_data['give_user_pass_confirm'], $registering_new_user ) ) { |
|
635 | + if (give_validate_user_password($user_data['give_user_pass'], $user_data['give_user_pass_confirm'], $registering_new_user)) { |
|
637 | 636 | // All is good to go. |
638 | 637 | $valid_user_data['user_pass'] = $user_data['give_user_pass']; |
639 | 638 | } |
@@ -653,36 +652,36 @@ discard block |
||
653 | 652 | // Start an array to collect valid user data. |
654 | 653 | $valid_user_data = array( |
655 | 654 | // Assume there will be errors. |
656 | - 'user_id' => - 1, |
|
655 | + 'user_id' => -1, |
|
657 | 656 | ); |
658 | 657 | |
659 | 658 | // Username. |
660 | - if ( ! isset( $_POST['give_user_login'] ) || $_POST['give_user_login'] == '' ) { |
|
661 | - give_set_error( 'must_log_in', __( 'You must register or login to complete your donation.', 'give' ) ); |
|
659 | + if ( ! isset($_POST['give_user_login']) || $_POST['give_user_login'] == '') { |
|
660 | + give_set_error('must_log_in', __('You must register or login to complete your donation.', 'give')); |
|
662 | 661 | |
663 | 662 | return $valid_user_data; |
664 | 663 | } |
665 | 664 | |
666 | 665 | // Get the user by login. |
667 | - $user_data = get_user_by( 'login', strip_tags( $_POST['give_user_login'] ) ); |
|
666 | + $user_data = get_user_by('login', strip_tags($_POST['give_user_login'])); |
|
668 | 667 | |
669 | 668 | // Check if user exists. |
670 | - if ( $user_data ) { |
|
669 | + if ($user_data) { |
|
671 | 670 | // Get password. |
672 | - $user_pass = isset( $_POST['give_user_pass'] ) ? $_POST['give_user_pass'] : false; |
|
671 | + $user_pass = isset($_POST['give_user_pass']) ? $_POST['give_user_pass'] : false; |
|
673 | 672 | |
674 | 673 | // Check user_pass. |
675 | - if ( $user_pass ) { |
|
674 | + if ($user_pass) { |
|
676 | 675 | // Check if password is valid. |
677 | - if ( ! wp_check_password( $user_pass, $user_data->user_pass, $user_data->ID ) ) { |
|
676 | + if ( ! wp_check_password($user_pass, $user_data->user_pass, $user_data->ID)) { |
|
678 | 677 | // Incorrect password. |
679 | 678 | give_set_error( |
680 | 679 | 'password_incorrect', |
681 | 680 | sprintf( |
682 | 681 | '%1$s <a href="%2$s">%3$s</a>', |
683 | - __( 'The password you entered is incorrect.', 'give' ), |
|
684 | - wp_lostpassword_url( "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]" ), |
|
685 | - __( 'Reset Password', 'give' ) |
|
682 | + __('The password you entered is incorrect.', 'give'), |
|
683 | + wp_lostpassword_url("http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"), |
|
684 | + __('Reset Password', 'give') |
|
686 | 685 | ) |
687 | 686 | ); |
688 | 687 | // All is correct. |
@@ -699,11 +698,11 @@ discard block |
||
699 | 698 | } |
700 | 699 | } else { |
701 | 700 | // Empty password. |
702 | - give_set_error( 'password_empty', __( 'Enter a password.', 'give' ) ); |
|
701 | + give_set_error('password_empty', __('Enter a password.', 'give')); |
|
703 | 702 | } |
704 | 703 | } else { |
705 | 704 | // No username. |
706 | - give_set_error( 'username_incorrect', __( 'The username you entered does not exist.', 'give' ) ); |
|
705 | + give_set_error('username_incorrect', __('The username you entered does not exist.', 'give')); |
|
707 | 706 | }// End if(). |
708 | 707 | |
709 | 708 | return $valid_user_data; |
@@ -718,7 +717,7 @@ discard block |
||
718 | 717 | */ |
719 | 718 | function give_donation_form_validate_guest_user() { |
720 | 719 | |
721 | - $form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : ''; |
|
720 | + $form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : ''; |
|
722 | 721 | |
723 | 722 | // Start an array to collect valid user data. |
724 | 723 | $valid_user_data = array( |
@@ -727,38 +726,38 @@ discard block |
||
727 | 726 | ); |
728 | 727 | |
729 | 728 | // Show error message if user must be logged in. |
730 | - if ( give_logged_in_only( $form_id ) ) { |
|
731 | - give_set_error( 'logged_in_only', __( 'You must be logged in to donate.', 'give' ) ); |
|
729 | + if (give_logged_in_only($form_id)) { |
|
730 | + give_set_error('logged_in_only', __('You must be logged in to donate.', 'give')); |
|
732 | 731 | } |
733 | 732 | |
734 | 733 | // Get the guest email. |
735 | - $guest_email = isset( $_POST['give_email'] ) ? $_POST['give_email'] : false; |
|
734 | + $guest_email = isset($_POST['give_email']) ? $_POST['give_email'] : false; |
|
736 | 735 | |
737 | 736 | // Check email. |
738 | - if ( $guest_email && strlen( $guest_email ) > 0 ) { |
|
737 | + if ($guest_email && strlen($guest_email) > 0) { |
|
739 | 738 | // Validate email. |
740 | - if ( ! is_email( $guest_email ) ) { |
|
739 | + if ( ! is_email($guest_email)) { |
|
741 | 740 | // Invalid email. |
742 | - give_set_error( 'email_invalid', __( 'Invalid email.', 'give' ) ); |
|
741 | + give_set_error('email_invalid', __('Invalid email.', 'give')); |
|
743 | 742 | } else { |
744 | 743 | // All is good to go. |
745 | 744 | $valid_user_data['user_email'] = $guest_email; |
746 | 745 | |
747 | 746 | // Get user_id from donor if exist. |
748 | - $donor = new Give_Donor( $guest_email ); |
|
749 | - if ( $donor->id && $donor->user_id ) { |
|
747 | + $donor = new Give_Donor($guest_email); |
|
748 | + if ($donor->id && $donor->user_id) { |
|
750 | 749 | $valid_user_data['user_id'] = $donor->user_id; |
751 | 750 | } |
752 | 751 | } |
753 | 752 | } else { |
754 | 753 | // No email. |
755 | - give_set_error( 'email_empty', __( 'Enter an email.', 'give' ) ); |
|
754 | + give_set_error('email_empty', __('Enter an email.', 'give')); |
|
756 | 755 | } |
757 | 756 | |
758 | 757 | // Loop through required fields and show error messages. |
759 | - foreach ( give_get_required_fields( $form_id ) as $field_name => $value ) { |
|
760 | - if ( in_array( $value, give_get_required_fields( $form_id ) ) && empty( $_POST[ $field_name ] ) ) { |
|
761 | - give_set_error( $value['error_id'], $value['error_message'] ); |
|
758 | + foreach (give_get_required_fields($form_id) as $field_name => $value) { |
|
759 | + if (in_array($value, give_get_required_fields($form_id)) && empty($_POST[$field_name])) { |
|
760 | + give_set_error($value['error_id'], $value['error_message']); |
|
762 | 761 | } |
763 | 762 | } |
764 | 763 | |
@@ -774,36 +773,36 @@ discard block |
||
774 | 773 | * @since 1.0 |
775 | 774 | * @return integer |
776 | 775 | */ |
777 | -function give_register_and_login_new_user( $user_data = array() ) { |
|
776 | +function give_register_and_login_new_user($user_data = array()) { |
|
778 | 777 | // Verify the array. |
779 | - if ( empty( $user_data ) ) { |
|
780 | - return - 1; |
|
778 | + if (empty($user_data)) { |
|
779 | + return -1; |
|
781 | 780 | } |
782 | 781 | |
783 | - if ( give_get_errors() ) { |
|
784 | - return - 1; |
|
782 | + if (give_get_errors()) { |
|
783 | + return -1; |
|
785 | 784 | } |
786 | 785 | |
787 | - $user_args = apply_filters( 'give_insert_user_args', array( |
|
788 | - 'user_login' => isset( $user_data['user_login'] ) ? $user_data['user_login'] : '', |
|
789 | - 'user_pass' => isset( $user_data['user_pass'] ) ? $user_data['user_pass'] : '', |
|
790 | - 'user_email' => isset( $user_data['user_email'] ) ? $user_data['user_email'] : '', |
|
791 | - 'first_name' => isset( $user_data['user_first'] ) ? $user_data['user_first'] : '', |
|
792 | - 'last_name' => isset( $user_data['user_last'] ) ? $user_data['user_last'] : '', |
|
793 | - 'user_registered' => date( 'Y-m-d H:i:s' ), |
|
794 | - 'role' => get_option( 'default_role' ), |
|
795 | - ), $user_data ); |
|
786 | + $user_args = apply_filters('give_insert_user_args', array( |
|
787 | + 'user_login' => isset($user_data['user_login']) ? $user_data['user_login'] : '', |
|
788 | + 'user_pass' => isset($user_data['user_pass']) ? $user_data['user_pass'] : '', |
|
789 | + 'user_email' => isset($user_data['user_email']) ? $user_data['user_email'] : '', |
|
790 | + 'first_name' => isset($user_data['user_first']) ? $user_data['user_first'] : '', |
|
791 | + 'last_name' => isset($user_data['user_last']) ? $user_data['user_last'] : '', |
|
792 | + 'user_registered' => date('Y-m-d H:i:s'), |
|
793 | + 'role' => get_option('default_role'), |
|
794 | + ), $user_data); |
|
796 | 795 | |
797 | 796 | // Insert new user. |
798 | - $user_id = wp_insert_user( $user_args ); |
|
797 | + $user_id = wp_insert_user($user_args); |
|
799 | 798 | |
800 | 799 | // Validate inserted user. |
801 | - if ( is_wp_error( $user_id ) ) { |
|
802 | - return - 1; |
|
800 | + if (is_wp_error($user_id)) { |
|
801 | + return -1; |
|
803 | 802 | } |
804 | 803 | |
805 | 804 | // Allow themes and plugins to filter the user data. |
806 | - $user_data = apply_filters( 'give_insert_user_data', $user_data, $user_args ); |
|
805 | + $user_data = apply_filters('give_insert_user_data', $user_data, $user_args); |
|
807 | 806 | |
808 | 807 | /** |
809 | 808 | * Fires after inserting user. |
@@ -813,10 +812,10 @@ discard block |
||
813 | 812 | * @param int $user_id User id. |
814 | 813 | * @param array $user_data Array containing user data. |
815 | 814 | */ |
816 | - do_action( 'give_insert_user', $user_id, $user_data ); |
|
815 | + do_action('give_insert_user', $user_id, $user_data); |
|
817 | 816 | |
818 | 817 | // Login new user. |
819 | - give_log_user_in( $user_id, $user_data['user_login'], $user_data['user_pass'] ); |
|
818 | + give_log_user_in($user_id, $user_data['user_login'], $user_data['user_pass']); |
|
820 | 819 | |
821 | 820 | // Return user id. |
822 | 821 | return $user_id; |
@@ -831,27 +830,27 @@ discard block |
||
831 | 830 | * @since 1.0 |
832 | 831 | * @return array|bool |
833 | 832 | */ |
834 | -function give_get_donation_form_user( $valid_data = array() ) { |
|
833 | +function give_get_donation_form_user($valid_data = array()) { |
|
835 | 834 | |
836 | 835 | // Initialize user. |
837 | 836 | $user = false; |
838 | - $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
837 | + $is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
839 | 838 | |
840 | - if ( $is_ajax ) { |
|
839 | + if ($is_ajax) { |
|
841 | 840 | // Do not create or login the user during the ajax submission (check for errors only). |
842 | 841 | return true; |
843 | - } elseif ( is_user_logged_in() ) { |
|
842 | + } elseif (is_user_logged_in()) { |
|
844 | 843 | // Set the valid user as the logged in collected data. |
845 | 844 | $user = $valid_data['logged_in_user']; |
846 | - } elseif ( $valid_data['need_new_user'] === true || $valid_data['need_user_login'] === true ) { |
|
845 | + } elseif ($valid_data['need_new_user'] === true || $valid_data['need_user_login'] === true) { |
|
847 | 846 | // New user registration. |
848 | - if ( $valid_data['need_new_user'] === true ) { |
|
847 | + if ($valid_data['need_new_user'] === true) { |
|
849 | 848 | // Set user. |
850 | 849 | $user = $valid_data['new_user_data']; |
851 | 850 | // Register and login new user. |
852 | - $user['user_id'] = give_register_and_login_new_user( $user ); |
|
851 | + $user['user_id'] = give_register_and_login_new_user($user); |
|
853 | 852 | // User login |
854 | - } elseif ( $valid_data['need_user_login'] === true && ! $is_ajax ) { |
|
853 | + } elseif ($valid_data['need_user_login'] === true && ! $is_ajax) { |
|
855 | 854 | |
856 | 855 | /** |
857 | 856 | * The login form is now processed in the give_process_donation_login() function. |
@@ -863,48 +862,48 @@ discard block |
||
863 | 862 | // Set user. |
864 | 863 | $user = $valid_data['login_user_data']; |
865 | 864 | // Login user. |
866 | - give_log_user_in( $user['user_id'], $user['user_login'], $user['user_pass'] ); |
|
865 | + give_log_user_in($user['user_id'], $user['user_login'], $user['user_pass']); |
|
867 | 866 | } |
868 | 867 | } |
869 | 868 | |
870 | 869 | // Check guest checkout. |
871 | - if ( false === $user && false === give_logged_in_only( $_POST['give-form-id'] ) ) { |
|
870 | + if (false === $user && false === give_logged_in_only($_POST['give-form-id'])) { |
|
872 | 871 | // Set user |
873 | 872 | $user = $valid_data['guest_user_data']; |
874 | 873 | } |
875 | 874 | |
876 | 875 | // Verify we have an user. |
877 | - if ( false === $user || empty( $user ) ) { |
|
876 | + if (false === $user || empty($user)) { |
|
878 | 877 | // Return false. |
879 | 878 | return false; |
880 | 879 | } |
881 | 880 | |
882 | 881 | // Get user first name. |
883 | - if ( ! isset( $user['user_first'] ) || strlen( trim( $user['user_first'] ) ) < 1 ) { |
|
884 | - $user['user_first'] = isset( $_POST['give_first'] ) ? strip_tags( trim( $_POST['give_first'] ) ) : ''; |
|
882 | + if ( ! isset($user['user_first']) || strlen(trim($user['user_first'])) < 1) { |
|
883 | + $user['user_first'] = isset($_POST['give_first']) ? strip_tags(trim($_POST['give_first'])) : ''; |
|
885 | 884 | } |
886 | 885 | |
887 | 886 | // Get user last name. |
888 | - if ( ! isset( $user['user_last'] ) || strlen( trim( $user['user_last'] ) ) < 1 ) { |
|
889 | - $user['user_last'] = isset( $_POST['give_last'] ) ? strip_tags( trim( $_POST['give_last'] ) ) : ''; |
|
887 | + if ( ! isset($user['user_last']) || strlen(trim($user['user_last'])) < 1) { |
|
888 | + $user['user_last'] = isset($_POST['give_last']) ? strip_tags(trim($_POST['give_last'])) : ''; |
|
890 | 889 | } |
891 | 890 | |
892 | 891 | // Get the user's billing address details. |
893 | 892 | $user['address'] = array(); |
894 | - $user['address']['line1'] = ! empty( $_POST['card_address'] ) ? sanitize_text_field( $_POST['card_address'] ) : false; |
|
895 | - $user['address']['line2'] = ! empty( $_POST['card_address_2'] ) ? sanitize_text_field( $_POST['card_address_2'] ) : false; |
|
896 | - $user['address']['city'] = ! empty( $_POST['card_city'] ) ? sanitize_text_field( $_POST['card_city'] ) : false; |
|
897 | - $user['address']['state'] = ! empty( $_POST['card_state'] ) ? sanitize_text_field( $_POST['card_state'] ) : false; |
|
898 | - $user['address']['country'] = ! empty( $_POST['billing_country'] ) ? sanitize_text_field( $_POST['billing_country'] ) : false; |
|
899 | - $user['address']['zip'] = ! empty( $_POST['card_zip'] ) ? sanitize_text_field( $_POST['card_zip'] ) : false; |
|
900 | - |
|
901 | - if ( empty( $user['address']['country'] ) ) { |
|
893 | + $user['address']['line1'] = ! empty($_POST['card_address']) ? sanitize_text_field($_POST['card_address']) : false; |
|
894 | + $user['address']['line2'] = ! empty($_POST['card_address_2']) ? sanitize_text_field($_POST['card_address_2']) : false; |
|
895 | + $user['address']['city'] = ! empty($_POST['card_city']) ? sanitize_text_field($_POST['card_city']) : false; |
|
896 | + $user['address']['state'] = ! empty($_POST['card_state']) ? sanitize_text_field($_POST['card_state']) : false; |
|
897 | + $user['address']['country'] = ! empty($_POST['billing_country']) ? sanitize_text_field($_POST['billing_country']) : false; |
|
898 | + $user['address']['zip'] = ! empty($_POST['card_zip']) ? sanitize_text_field($_POST['card_zip']) : false; |
|
899 | + |
|
900 | + if (empty($user['address']['country'])) { |
|
902 | 901 | $user['address'] = false; |
903 | 902 | } // End if(). |
904 | 903 | |
905 | - if ( ! empty( $user['user_id'] ) && $user['user_id'] > 0 && ! empty( $user['address'] ) ) { |
|
904 | + if ( ! empty($user['user_id']) && $user['user_id'] > 0 && ! empty($user['address'])) { |
|
906 | 905 | // Store the address in the user's meta so the donation form can be pre-populated with it on return donation. |
907 | - update_user_meta( $user['user_id'], '_give_user_address', $user['address'] ); |
|
906 | + update_user_meta($user['user_id'], '_give_user_address', $user['address']); |
|
908 | 907 | } |
909 | 908 | |
910 | 909 | // Return valid user. |
@@ -923,16 +922,16 @@ discard block |
||
923 | 922 | $card_data = give_get_donation_cc_info(); |
924 | 923 | |
925 | 924 | // Validate the card zip. |
926 | - if ( ! empty( $card_data['card_zip'] ) ) { |
|
927 | - if ( ! give_donation_form_validate_cc_zip( $card_data['card_zip'], $card_data['card_country'] ) ) { |
|
928 | - give_set_error( 'invalid_cc_zip', __( 'The zip / postal code you entered for your billing address is invalid.', 'give' ) ); |
|
925 | + if ( ! empty($card_data['card_zip'])) { |
|
926 | + if ( ! give_donation_form_validate_cc_zip($card_data['card_zip'], $card_data['card_country'])) { |
|
927 | + give_set_error('invalid_cc_zip', __('The zip / postal code you entered for your billing address is invalid.', 'give')); |
|
929 | 928 | } |
930 | 929 | } |
931 | 930 | |
932 | 931 | // Ensure no spaces. |
933 | - if ( ! empty( $card_data['card_number'] ) ) { |
|
934 | - $card_data['card_number'] = str_replace( '+', '', $card_data['card_number'] ); // no "+" signs |
|
935 | - $card_data['card_number'] = str_replace( ' ', '', $card_data['card_number'] ); // No spaces |
|
932 | + if ( ! empty($card_data['card_number'])) { |
|
933 | + $card_data['card_number'] = str_replace('+', '', $card_data['card_number']); // no "+" signs |
|
934 | + $card_data['card_number'] = str_replace(' ', '', $card_data['card_number']); // No spaces |
|
936 | 935 | } |
937 | 936 | |
938 | 937 | // This should validate card numbers at some point too. |
@@ -949,17 +948,17 @@ discard block |
||
949 | 948 | function give_get_donation_cc_info() { |
950 | 949 | |
951 | 950 | $cc_info = array(); |
952 | - $cc_info['card_name'] = isset( $_POST['card_name'] ) ? sanitize_text_field( $_POST['card_name'] ) : ''; |
|
953 | - $cc_info['card_number'] = isset( $_POST['card_number'] ) ? sanitize_text_field( $_POST['card_number'] ) : ''; |
|
954 | - $cc_info['card_cvc'] = isset( $_POST['card_cvc'] ) ? sanitize_text_field( $_POST['card_cvc'] ) : ''; |
|
955 | - $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] ) ? sanitize_text_field( $_POST['card_exp_month'] ) : ''; |
|
956 | - $cc_info['card_exp_year'] = isset( $_POST['card_exp_year'] ) ? sanitize_text_field( $_POST['card_exp_year'] ) : ''; |
|
957 | - $cc_info['card_address'] = isset( $_POST['card_address'] ) ? sanitize_text_field( $_POST['card_address'] ) : ''; |
|
958 | - $cc_info['card_address_2'] = isset( $_POST['card_address_2'] ) ? sanitize_text_field( $_POST['card_address_2'] ) : ''; |
|
959 | - $cc_info['card_city'] = isset( $_POST['card_city'] ) ? sanitize_text_field( $_POST['card_city'] ) : ''; |
|
960 | - $cc_info['card_state'] = isset( $_POST['card_state'] ) ? sanitize_text_field( $_POST['card_state'] ) : ''; |
|
961 | - $cc_info['card_country'] = isset( $_POST['billing_country'] ) ? sanitize_text_field( $_POST['billing_country'] ) : ''; |
|
962 | - $cc_info['card_zip'] = isset( $_POST['card_zip'] ) ? sanitize_text_field( $_POST['card_zip'] ) : ''; |
|
951 | + $cc_info['card_name'] = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : ''; |
|
952 | + $cc_info['card_number'] = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : ''; |
|
953 | + $cc_info['card_cvc'] = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : ''; |
|
954 | + $cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : ''; |
|
955 | + $cc_info['card_exp_year'] = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : ''; |
|
956 | + $cc_info['card_address'] = isset($_POST['card_address']) ? sanitize_text_field($_POST['card_address']) : ''; |
|
957 | + $cc_info['card_address_2'] = isset($_POST['card_address_2']) ? sanitize_text_field($_POST['card_address_2']) : ''; |
|
958 | + $cc_info['card_city'] = isset($_POST['card_city']) ? sanitize_text_field($_POST['card_city']) : ''; |
|
959 | + $cc_info['card_state'] = isset($_POST['card_state']) ? sanitize_text_field($_POST['card_state']) : ''; |
|
960 | + $cc_info['card_country'] = isset($_POST['billing_country']) ? sanitize_text_field($_POST['billing_country']) : ''; |
|
961 | + $cc_info['card_zip'] = isset($_POST['card_zip']) ? sanitize_text_field($_POST['card_zip']) : ''; |
|
963 | 962 | |
964 | 963 | // Return cc info. |
965 | 964 | return $cc_info; |
@@ -975,14 +974,14 @@ discard block |
||
975 | 974 | * |
976 | 975 | * @return bool|mixed |
977 | 976 | */ |
978 | -function give_donation_form_validate_cc_zip( $zip = 0, $country_code = '' ) { |
|
977 | +function give_donation_form_validate_cc_zip($zip = 0, $country_code = '') { |
|
979 | 978 | $ret = false; |
980 | 979 | |
981 | - if ( empty( $zip ) || empty( $country_code ) ) { |
|
980 | + if (empty($zip) || empty($country_code)) { |
|
982 | 981 | return $ret; |
983 | 982 | } |
984 | 983 | |
985 | - $country_code = strtoupper( $country_code ); |
|
984 | + $country_code = strtoupper($country_code); |
|
986 | 985 | |
987 | 986 | $zip_regex = array( |
988 | 987 | 'AD' => 'AD\d{3}', |
@@ -1142,11 +1141,11 @@ discard block |
||
1142 | 1141 | 'ZM' => '\d{5}', |
1143 | 1142 | ); |
1144 | 1143 | |
1145 | - if ( ! isset( $zip_regex[ $country_code ] ) || preg_match( '/' . $zip_regex[ $country_code ] . '/i', $zip ) ) { |
|
1144 | + if ( ! isset($zip_regex[$country_code]) || preg_match('/'.$zip_regex[$country_code].'/i', $zip)) { |
|
1146 | 1145 | $ret = true; |
1147 | 1146 | } |
1148 | 1147 | |
1149 | - return apply_filters( 'give_is_zip_valid', $ret, $zip, $country_code ); |
|
1148 | + return apply_filters('give_is_zip_valid', $ret, $zip, $country_code); |
|
1150 | 1149 | } |
1151 | 1150 | |
1152 | 1151 | |
@@ -1160,33 +1159,33 @@ discard block |
||
1160 | 1159 | * |
1161 | 1160 | * @return bool |
1162 | 1161 | */ |
1163 | -function give_validate_multi_donation_form_level( $valid_data, $data ) { |
|
1162 | +function give_validate_multi_donation_form_level($valid_data, $data) { |
|
1164 | 1163 | /* @var Give_Donate_Form $form */ |
1165 | - $form = new Give_Donate_Form( $data['give-form-id'] ); |
|
1164 | + $form = new Give_Donate_Form($data['give-form-id']); |
|
1166 | 1165 | |
1167 | 1166 | $donation_level_matched = false; |
1168 | 1167 | |
1169 | - if ( $form->is_multi_type_donation_form() ) { |
|
1168 | + if ($form->is_multi_type_donation_form()) { |
|
1170 | 1169 | |
1171 | 1170 | // Bailout. |
1172 | - if ( ! ( $variable_prices = $form->get_prices() ) ) { |
|
1171 | + if ( ! ($variable_prices = $form->get_prices())) { |
|
1173 | 1172 | return false; |
1174 | 1173 | } |
1175 | 1174 | |
1176 | 1175 | // Sanitize donation amount. |
1177 | - $data['give-amount'] = give_maybe_sanitize_amount( $data['give-amount'] ); |
|
1176 | + $data['give-amount'] = give_maybe_sanitize_amount($data['give-amount']); |
|
1178 | 1177 | |
1179 | - if ( $data['give-amount'] === give_maybe_sanitize_amount( give_get_price_option_amount( $data['give-form-id'], $data['give-price-id'] ) ) ) { |
|
1178 | + if ($data['give-amount'] === give_maybe_sanitize_amount(give_get_price_option_amount($data['give-form-id'], $data['give-price-id']))) { |
|
1180 | 1179 | return true; |
1181 | 1180 | } |
1182 | 1181 | |
1183 | 1182 | // Find correct donation level from all donation levels. |
1184 | - foreach ( $variable_prices as $variable_price ) { |
|
1183 | + foreach ($variable_prices as $variable_price) { |
|
1185 | 1184 | // Sanitize level amount. |
1186 | - $variable_price['_give_amount'] = give_maybe_sanitize_amount( $variable_price['_give_amount'] ); |
|
1185 | + $variable_price['_give_amount'] = give_maybe_sanitize_amount($variable_price['_give_amount']); |
|
1187 | 1186 | |
1188 | 1187 | // Set first match donation level ID. |
1189 | - if ( $data['give-amount'] === $variable_price['_give_amount'] ) { |
|
1188 | + if ($data['give-amount'] === $variable_price['_give_amount']) { |
|
1190 | 1189 | $_POST['give-price-id'] = $variable_price['_give_id']['level_id']; |
1191 | 1190 | $donation_level_matched = true; |
1192 | 1191 | break; |
@@ -1197,19 +1196,19 @@ discard block |
||
1197 | 1196 | // If yes then set price id to custom if amount is greater then custom minimum amount (if any). |
1198 | 1197 | if ( |
1199 | 1198 | ! $donation_level_matched |
1200 | - && ( give_is_setting_enabled( give_get_meta( $data['give-form-id'], '_give_custom_amount', true ) ) ) |
|
1199 | + && (give_is_setting_enabled(give_get_meta($data['give-form-id'], '_give_custom_amount', true))) |
|
1201 | 1200 | ) { |
1202 | 1201 | // Sanitize custom minimum amount. |
1203 | - $custom_minimum_amount = give_maybe_sanitize_amount( give_get_meta( $data['give-form-id'], '_give_custom_amount_minimum', true ) ); |
|
1202 | + $custom_minimum_amount = give_maybe_sanitize_amount(give_get_meta($data['give-form-id'], '_give_custom_amount_minimum', true)); |
|
1204 | 1203 | |
1205 | - if ( $data['give-amount'] >= $custom_minimum_amount ) { |
|
1204 | + if ($data['give-amount'] >= $custom_minimum_amount) { |
|
1206 | 1205 | $_POST['give-price-id'] = 'custom'; |
1207 | 1206 | $donation_level_matched = true; |
1208 | 1207 | } |
1209 | 1208 | } |
1210 | 1209 | }// End if(). |
1211 | 1210 | |
1212 | - return ( $donation_level_matched ? true : false ); |
|
1211 | + return ($donation_level_matched ? true : false); |
|
1213 | 1212 | } |
1214 | 1213 | |
1215 | -add_action( 'give_checkout_error_checks', 'give_validate_multi_donation_form_level', 10, 2 ); |
|
1214 | +add_action('give_checkout_error_checks', 'give_validate_multi_donation_form_level', 10, 2); |
@@ -10,13 +10,13 @@ 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 | |
17 | 17 | // Load WP_List_Table if not loaded |
18 | -if ( ! class_exists( 'WP_List_Table' ) ) { |
|
19 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
18 | +if ( ! class_exists('WP_List_Table')) { |
|
19 | + require_once ABSPATH.'wp-admin/includes/class-wp-list-table.php'; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -56,13 +56,13 @@ discard block |
||
56 | 56 | global $status, $page; |
57 | 57 | |
58 | 58 | // Set parent defaults |
59 | - parent::__construct( array( |
|
60 | - 'singular' => give_get_forms_label_singular(), // Singular name of the listed records. |
|
61 | - 'plural' => give_get_forms_label_plural(), // Plural name of the listed records. |
|
59 | + parent::__construct(array( |
|
60 | + 'singular' => give_get_forms_label_singular(), // Singular name of the listed records. |
|
61 | + 'plural' => give_get_forms_label_plural(), // Plural name of the listed records. |
|
62 | 62 | 'ajax' => false // Does this table support ajax? |
63 | - ) ); |
|
63 | + )); |
|
64 | 64 | |
65 | - add_action( 'give_report_view_actions', array( $this, 'category_filter' ) ); |
|
65 | + add_action('give_report_view_actions', array($this, 'category_filter')); |
|
66 | 66 | $this->query(); |
67 | 67 | |
68 | 68 | } |
@@ -78,32 +78,32 @@ discard block |
||
78 | 78 | * |
79 | 79 | * @return string Column Name |
80 | 80 | */ |
81 | - public function column_default( $item, $column_name ) { |
|
82 | - switch ( $column_name ) { |
|
81 | + public function column_default($item, $column_name) { |
|
82 | + switch ($column_name) { |
|
83 | 83 | case 'title': |
84 | - $title = empty( $item['title'] ) ? sprintf( __( 'Untitled (#%s)', 'give' ), $item['ID'] ) : $item['title']; |
|
84 | + $title = empty($item['title']) ? sprintf(__('Untitled (#%s)', 'give'), $item['ID']) : $item['title']; |
|
85 | 85 | |
86 | 86 | return sprintf( |
87 | 87 | '<a href="%s">%s</a>', |
88 | - get_edit_post_link( $item['ID'] ), |
|
88 | + get_edit_post_link($item['ID']), |
|
89 | 89 | $title |
90 | 90 | ); |
91 | 91 | case 'sales': |
92 | 92 | return sprintf( |
93 | 93 | '<a href="%s">%s</a>', |
94 | - admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&form_id=' . urlencode( $item['ID'] ) ), |
|
94 | + admin_url('edit.php?post_type=give_forms&page=give-payment-history&form_id='.urlencode($item['ID'])), |
|
95 | 95 | $item['sales'] |
96 | 96 | ); |
97 | 97 | case 'earnings' : |
98 | - return give_currency_filter( give_format_amount( $item[ $column_name ], array( 'sanitize' => false ) ) ); |
|
98 | + return give_currency_filter(give_format_amount($item[$column_name], array('sanitize' => false))); |
|
99 | 99 | case 'average_sales' : |
100 | - return round( $item[ $column_name ] ); |
|
100 | + return round($item[$column_name]); |
|
101 | 101 | case 'average_earnings' : |
102 | - return give_currency_filter( give_format_amount( $item[ $column_name ], array( 'sanitize' => false ) ) ); |
|
102 | + return give_currency_filter(give_format_amount($item[$column_name], array('sanitize' => false))); |
|
103 | 103 | case 'details' : |
104 | - return '<a href="' . admin_url( 'edit.php?post_type=give_forms&page=give-reports&tab=forms&form-id=' . $item['ID'] ) . '">' . esc_html__( 'View Detailed Report', 'give' ) . '</a>'; |
|
104 | + return '<a href="'.admin_url('edit.php?post_type=give_forms&page=give-reports&tab=forms&form-id='.$item['ID']).'">'.esc_html__('View Detailed Report', 'give').'</a>'; |
|
105 | 105 | default: |
106 | - return $item[ $column_name ]; |
|
106 | + return $item[$column_name]; |
|
107 | 107 | } |
108 | 108 | } |
109 | 109 | |
@@ -117,12 +117,12 @@ discard block |
||
117 | 117 | */ |
118 | 118 | public function get_columns() { |
119 | 119 | $columns = array( |
120 | - 'title' => esc_html__( 'Form', 'give' ), |
|
121 | - 'sales' => esc_html__( 'Donations', 'give' ), |
|
122 | - 'earnings' => esc_html__( 'Income', 'give' ), |
|
123 | - 'average_sales' => esc_html__( 'Monthly Average Donations', 'give' ), |
|
124 | - 'average_earnings' => esc_html__( 'Monthly Average Income', 'give' ), |
|
125 | - 'details' => esc_html__( 'Detailed Report', 'give' ) |
|
120 | + 'title' => esc_html__('Form', 'give'), |
|
121 | + 'sales' => esc_html__('Donations', 'give'), |
|
122 | + 'earnings' => esc_html__('Income', 'give'), |
|
123 | + 'average_sales' => esc_html__('Monthly Average Donations', 'give'), |
|
124 | + 'average_earnings' => esc_html__('Monthly Average Income', 'give'), |
|
125 | + 'details' => esc_html__('Detailed Report', 'give') |
|
126 | 126 | ); |
127 | 127 | |
128 | 128 | return $columns; |
@@ -138,9 +138,9 @@ discard block |
||
138 | 138 | */ |
139 | 139 | public function get_sortable_columns() { |
140 | 140 | return array( |
141 | - 'title' => array( 'title', true ), |
|
142 | - 'sales' => array( 'sales', false ), |
|
143 | - 'earnings' => array( 'earnings', false ), |
|
141 | + 'title' => array('title', true), |
|
142 | + 'sales' => array('sales', false), |
|
143 | + 'earnings' => array('earnings', false), |
|
144 | 144 | ); |
145 | 145 | } |
146 | 146 | |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | * @return int Current page number |
154 | 154 | */ |
155 | 155 | public function get_paged() { |
156 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
156 | + return isset($_GET['paged']) ? absint($_GET['paged']) : 1; |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | * @return int Category ID |
166 | 166 | */ |
167 | 167 | public function get_category() { |
168 | - return isset( $_GET['category'] ) ? absint( $_GET['category'] ) : 0; |
|
168 | + return isset($_GET['category']) ? absint($_GET['category']) : 0; |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | * |
177 | 177 | * @return void |
178 | 178 | */ |
179 | - public function bulk_actions( $which = '' ) { |
|
179 | + public function bulk_actions($which = '') { |
|
180 | 180 | |
181 | 181 | } |
182 | 182 | |
@@ -188,27 +188,27 @@ discard block |
||
188 | 188 | * |
189 | 189 | * @param string $which |
190 | 190 | */ |
191 | - protected function display_tablenav( $which ) { |
|
191 | + protected function display_tablenav($which) { |
|
192 | 192 | |
193 | - if ( 'top' === $which ) { |
|
194 | - wp_nonce_field( 'bulk-' . $this->_args['plural'] ); |
|
193 | + if ('top' === $which) { |
|
194 | + wp_nonce_field('bulk-'.$this->_args['plural']); |
|
195 | 195 | } |
196 | 196 | ?> |
197 | - <div class="tablenav give-clearfix <?php echo esc_attr( $which ); ?>"> |
|
197 | + <div class="tablenav give-clearfix <?php echo esc_attr($which); ?>"> |
|
198 | 198 | |
199 | - <?php if ( 'top' === $which ) { ?> |
|
199 | + <?php if ('top' === $which) { ?> |
|
200 | 200 | <h3 class="alignleft reports-earnings-title"> |
201 | - <span><?php esc_html_e( 'Donation Forms Report', 'give' ); ?></span> |
|
201 | + <span><?php esc_html_e('Donation Forms Report', 'give'); ?></span> |
|
202 | 202 | </h3> |
203 | 203 | <?php } ?> |
204 | 204 | |
205 | 205 | <div class="alignright tablenav-right"> |
206 | 206 | <div class="actions bulkactions"> |
207 | - <?php $this->bulk_actions( $which ); ?> |
|
207 | + <?php $this->bulk_actions($which); ?> |
|
208 | 208 | </div> |
209 | 209 | <?php |
210 | - $this->extra_tablenav( $which ); |
|
211 | - $this->pagination( $which ); |
|
210 | + $this->extra_tablenav($which); |
|
211 | + $this->pagination($which); |
|
212 | 212 | ?> |
213 | 213 | </div> |
214 | 214 | |
@@ -228,9 +228,9 @@ discard block |
||
228 | 228 | */ |
229 | 229 | public function category_filter() { |
230 | 230 | |
231 | - $categories = get_terms( 'form_category' ); |
|
232 | - if ( $categories && ! is_wp_error( $categories ) ) { |
|
233 | - echo Give()->html->category_dropdown( 'category', $this->get_category() ); |
|
231 | + $categories = get_terms('form_category'); |
|
232 | + if ($categories && ! is_wp_error($categories)) { |
|
233 | + echo Give()->html->category_dropdown('category', $this->get_category()); |
|
234 | 234 | } |
235 | 235 | } |
236 | 236 | |
@@ -244,8 +244,8 @@ discard block |
||
244 | 244 | */ |
245 | 245 | public function query() { |
246 | 246 | |
247 | - $orderby = isset( $_GET['orderby'] ) ? $_GET['orderby'] : 'title'; |
|
248 | - $order = isset( $_GET['order'] ) ? $_GET['order'] : 'DESC'; |
|
247 | + $orderby = isset($_GET['orderby']) ? $_GET['orderby'] : 'title'; |
|
248 | + $order = isset($_GET['order']) ? $_GET['order'] : 'DESC'; |
|
249 | 249 | $category = $this->get_category(); |
250 | 250 | |
251 | 251 | $args = array( |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | 'suppress_filters' => true |
259 | 259 | ); |
260 | 260 | |
261 | - if ( ! empty( $category ) ) { |
|
261 | + if ( ! empty($category)) { |
|
262 | 262 | $args['tax_query'] = array( |
263 | 263 | array( |
264 | 264 | 'taxonomy' => 'form_category', |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | ); |
268 | 268 | } |
269 | 269 | |
270 | - switch ( $orderby ) : |
|
270 | + switch ($orderby) : |
|
271 | 271 | case 'title' : |
272 | 272 | $args['orderby'] = 'title'; |
273 | 273 | break; |
@@ -283,9 +283,9 @@ discard block |
||
283 | 283 | break; |
284 | 284 | endswitch; |
285 | 285 | |
286 | - $args = apply_filters( 'give_form_reports_prepare_items_args', $args, $this ); |
|
286 | + $args = apply_filters('give_form_reports_prepare_items_args', $args, $this); |
|
287 | 287 | |
288 | - $this->donation_forms = new WP_Query( $args ); |
|
288 | + $this->donation_forms = new WP_Query($args); |
|
289 | 289 | |
290 | 290 | // Store total number of donation forms count. |
291 | 291 | $this->count = $this->donation_forms->found_posts; |
@@ -305,15 +305,15 @@ discard block |
||
305 | 305 | |
306 | 306 | $give_forms = $this->donation_forms->posts; |
307 | 307 | |
308 | - if ( $give_forms ) { |
|
309 | - foreach ( $give_forms as $form ) { |
|
308 | + if ($give_forms) { |
|
309 | + foreach ($give_forms as $form) { |
|
310 | 310 | $reports_data[] = array( |
311 | 311 | 'ID' => $form, |
312 | - 'title' => get_the_title( $form ), |
|
313 | - 'sales' => give_get_form_sales_stats( $form ), |
|
314 | - 'earnings' => give_get_form_earnings_stats( $form ), |
|
315 | - 'average_sales' => give_get_average_monthly_form_sales( $form ), |
|
316 | - 'average_earnings' => give_get_average_monthly_form_earnings( $form ) |
|
312 | + 'title' => get_the_title($form), |
|
313 | + 'sales' => give_get_form_sales_stats($form), |
|
314 | + 'earnings' => give_get_form_earnings_stats($form), |
|
315 | + 'average_sales' => give_get_average_monthly_form_sales($form), |
|
316 | + 'average_earnings' => give_get_average_monthly_form_earnings($form) |
|
317 | 317 | ); |
318 | 318 | } |
319 | 319 | } |
@@ -338,14 +338,14 @@ discard block |
||
338 | 338 | $columns = $this->get_columns(); |
339 | 339 | $hidden = array(); // No hidden columns |
340 | 340 | $sortable = $this->get_sortable_columns(); |
341 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
341 | + $this->_column_headers = array($columns, $hidden, $sortable); |
|
342 | 342 | $this->items = $this->reports_data(); |
343 | 343 | $total_items = $this->count; |
344 | 344 | |
345 | - $this->set_pagination_args( array( |
|
345 | + $this->set_pagination_args(array( |
|
346 | 346 | 'total_items' => $total_items, |
347 | 347 | 'per_page' => $this->per_page, |
348 | - 'total_pages' => ceil( $total_items / $this->per_page ) |
|
348 | + 'total_pages' => ceil($total_items / $this->per_page) |
|
349 | 349 | ) |
350 | 350 | ); |
351 | 351 | } |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -20,10 +20,10 @@ discard block |
||
20 | 20 | * @since 1.5 |
21 | 21 | */ |
22 | 22 | function give_register_batch_recount_export_classes() { |
23 | - add_action( 'give_batch_export_class_include', 'give_include_batch_export_class', 10, 1 ); |
|
23 | + add_action('give_batch_export_class_include', 'give_include_batch_export_class', 10, 1); |
|
24 | 24 | } |
25 | 25 | |
26 | -add_action( 'give_register_batch_exporter', 'give_register_batch_recount_export_classes', 10 ); |
|
26 | +add_action('give_register_batch_exporter', 'give_register_batch_recount_export_classes', 10); |
|
27 | 27 | |
28 | 28 | |
29 | 29 | /** |
@@ -35,35 +35,35 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @return void |
37 | 37 | */ |
38 | -function give_include_batch_export_class( $class ) { |
|
39 | - switch ( $class ) { |
|
38 | +function give_include_batch_export_class($class) { |
|
39 | + switch ($class) { |
|
40 | 40 | |
41 | 41 | case 'Give_Tools_Delete_Donors': |
42 | - require_once GIVE_PLUGIN_DIR . 'includes/admin/tools/data/class-give-tools-delete-test-donors.php'; |
|
42 | + require_once GIVE_PLUGIN_DIR.'includes/admin/tools/data/class-give-tools-delete-test-donors.php'; |
|
43 | 43 | break; |
44 | 44 | |
45 | 45 | case 'Give_Tools_Delete_Test_Transactions': |
46 | - require_once GIVE_PLUGIN_DIR . 'includes/admin/tools/data/class-give-tools-delete-test-transactions.php'; |
|
46 | + require_once GIVE_PLUGIN_DIR.'includes/admin/tools/data/class-give-tools-delete-test-transactions.php'; |
|
47 | 47 | break; |
48 | 48 | |
49 | 49 | case 'Give_Tools_Recount_Donor_Stats': |
50 | - require_once GIVE_PLUGIN_DIR . 'includes/admin/tools/data/class-give-tools-recount-donor-stats.php'; |
|
50 | + require_once GIVE_PLUGIN_DIR.'includes/admin/tools/data/class-give-tools-recount-donor-stats.php'; |
|
51 | 51 | break; |
52 | 52 | |
53 | 53 | case 'Give_Tools_Reset_Stats': |
54 | - require_once GIVE_PLUGIN_DIR . 'includes/admin/tools/data/class-give-tools-reset-stats.php'; |
|
54 | + require_once GIVE_PLUGIN_DIR.'includes/admin/tools/data/class-give-tools-reset-stats.php'; |
|
55 | 55 | break; |
56 | 56 | |
57 | 57 | case 'Give_Tools_Recount_All_Stats': |
58 | - require_once GIVE_PLUGIN_DIR . 'includes/admin/tools/data/class-give-tools-recount-all-stats.php'; |
|
58 | + require_once GIVE_PLUGIN_DIR.'includes/admin/tools/data/class-give-tools-recount-all-stats.php'; |
|
59 | 59 | break; |
60 | 60 | |
61 | 61 | case 'Give_Tools_Recount_Form_Stats': |
62 | - require_once GIVE_PLUGIN_DIR . 'includes/admin/tools/data/class-give-tools-recount-form-stats.php'; |
|
62 | + require_once GIVE_PLUGIN_DIR.'includes/admin/tools/data/class-give-tools-recount-form-stats.php'; |
|
63 | 63 | break; |
64 | 64 | |
65 | 65 | case 'Give_Tools_Recount_Income': |
66 | - require_once GIVE_PLUGIN_DIR . 'includes/admin/tools/data/class-give-tools-recount-income.php'; |
|
66 | + require_once GIVE_PLUGIN_DIR.'includes/admin/tools/data/class-give-tools-recount-income.php'; |
|
67 | 67 | break; |
68 | 68 | } |
69 | 69 | } |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | */ |
12 | 12 | |
13 | 13 | // Exit if accessed directly. |
14 | -if ( ! defined( 'ABSPATH' ) ) { |
|
14 | +if ( ! defined('ABSPATH')) { |
|
15 | 15 | exit; |
16 | 16 | } |
17 | 17 | |
@@ -59,58 +59,58 @@ discard block |
||
59 | 59 | * @return bool |
60 | 60 | */ |
61 | 61 | public function get_data() { |
62 | - $accepted_statuses = apply_filters( 'give_recount_accepted_statuses', array( 'publish' ) ); |
|
62 | + $accepted_statuses = apply_filters('give_recount_accepted_statuses', array('publish')); |
|
63 | 63 | |
64 | - if ( $this->step == 1 ) { |
|
65 | - $this->delete_data( 'give_temp_recount_form_stats' ); |
|
64 | + if ($this->step == 1) { |
|
65 | + $this->delete_data('give_temp_recount_form_stats'); |
|
66 | 66 | } |
67 | 67 | |
68 | - $totals = $this->get_stored_data( 'give_temp_recount_form_stats' ); |
|
68 | + $totals = $this->get_stored_data('give_temp_recount_form_stats'); |
|
69 | 69 | |
70 | - if ( false === $totals ) { |
|
70 | + if (false === $totals) { |
|
71 | 71 | $totals = array( |
72 | 72 | 'earnings' => (float) 0, |
73 | 73 | 'sales' => 0, |
74 | 74 | ); |
75 | - $this->store_data( 'give_temp_recount_form_stats', $totals ); |
|
75 | + $this->store_data('give_temp_recount_form_stats', $totals); |
|
76 | 76 | } |
77 | 77 | |
78 | - $args = apply_filters( 'give_recount_form_stats_args', array( |
|
78 | + $args = apply_filters('give_recount_form_stats_args', array( |
|
79 | 79 | 'give_forms' => $this->form_id, |
80 | 80 | 'number' => $this->per_step, |
81 | 81 | 'status' => $accepted_statuses, |
82 | 82 | 'paged' => $this->step, |
83 | 83 | 'fields' => 'ids', |
84 | - ) ); |
|
84 | + )); |
|
85 | 85 | |
86 | - $payments = new Give_Payments_Query( $args ); |
|
86 | + $payments = new Give_Payments_Query($args); |
|
87 | 87 | $payments = $payments->get_payments(); |
88 | 88 | |
89 | - if ( $payments ) { |
|
90 | - foreach ( $payments as $payment ) { |
|
89 | + if ($payments) { |
|
90 | + foreach ($payments as $payment) { |
|
91 | 91 | //Ensure acceptible status only |
92 | - if ( ! in_array( $payment->post_status, $accepted_statuses ) ) { |
|
92 | + if ( ! in_array($payment->post_status, $accepted_statuses)) { |
|
93 | 93 | continue; |
94 | 94 | } |
95 | 95 | |
96 | 96 | //Ensure only payments for this form are counted |
97 | - if ( $payment->form_id != $this->form_id ) { |
|
97 | + if ($payment->form_id != $this->form_id) { |
|
98 | 98 | continue; |
99 | 99 | } |
100 | 100 | |
101 | - $totals['sales'] ++; |
|
101 | + $totals['sales']++; |
|
102 | 102 | $totals['earnings'] += $payment->total; |
103 | 103 | |
104 | 104 | } |
105 | 105 | |
106 | - $this->store_data( 'give_temp_recount_form_stats', $totals ); |
|
106 | + $this->store_data('give_temp_recount_form_stats', $totals); |
|
107 | 107 | |
108 | 108 | return true; |
109 | 109 | } |
110 | 110 | |
111 | 111 | |
112 | - give_update_meta( $this->form_id, '_give_form_sales', $totals['sales'] ); |
|
113 | - give_update_meta( $this->form_id, '_give_form_earnings', give_sanitize_amount_for_db( $totals['earnings'] ) ); |
|
112 | + give_update_meta($this->form_id, '_give_form_sales', $totals['sales']); |
|
113 | + give_update_meta($this->form_id, '_give_form_earnings', give_sanitize_amount_for_db($totals['earnings'])); |
|
114 | 114 | |
115 | 115 | return false; |
116 | 116 | } |
@@ -122,35 +122,35 @@ discard block |
||
122 | 122 | * @return int |
123 | 123 | */ |
124 | 124 | public function get_percentage_complete() { |
125 | - if ( $this->step == 1 ) { |
|
126 | - $this->delete_data( 'give_recount_total_' . $this->form_id ); |
|
125 | + if ($this->step == 1) { |
|
126 | + $this->delete_data('give_recount_total_'.$this->form_id); |
|
127 | 127 | } |
128 | 128 | |
129 | - $accepted_statuses = apply_filters( 'give_recount_accepted_statuses', array( 'publish' ) ); |
|
130 | - $total = $this->get_stored_data( 'give_recount_total_' . $this->form_id ); |
|
129 | + $accepted_statuses = apply_filters('give_recount_accepted_statuses', array('publish')); |
|
130 | + $total = $this->get_stored_data('give_recount_total_'.$this->form_id); |
|
131 | 131 | |
132 | - if ( false === $total ) { |
|
132 | + if (false === $total) { |
|
133 | 133 | $total = 0; |
134 | - $args = apply_filters( 'give_recount_form_stats_total_args', array( |
|
134 | + $args = apply_filters('give_recount_form_stats_total_args', array( |
|
135 | 135 | 'give_forms' => $this->form_id, |
136 | - 'number' => - 1, |
|
136 | + 'number' => -1, |
|
137 | 137 | 'status' => $accepted_statuses, |
138 | 138 | 'fields' => 'ids', |
139 | - ) ); |
|
139 | + )); |
|
140 | 140 | |
141 | - $payments = new Give_Payments_Query( $args ); |
|
142 | - $total = count( $payments->get_payments() ); |
|
143 | - $this->store_data( 'give_recount_total_' . $this->form_id, $total ); |
|
141 | + $payments = new Give_Payments_Query($args); |
|
142 | + $total = count($payments->get_payments()); |
|
143 | + $this->store_data('give_recount_total_'.$this->form_id, $total); |
|
144 | 144 | |
145 | 145 | } |
146 | 146 | |
147 | 147 | $percentage = 100; |
148 | 148 | |
149 | - if ( $total > 0 ) { |
|
150 | - $percentage = ( ( $this->per_step * $this->step ) / $total ) * 100; |
|
149 | + if ($total > 0) { |
|
150 | + $percentage = (($this->per_step * $this->step) / $total) * 100; |
|
151 | 151 | } |
152 | 152 | |
153 | - if ( $percentage > 100 ) { |
|
153 | + if ($percentage > 100) { |
|
154 | 154 | $percentage = 100; |
155 | 155 | } |
156 | 156 | |
@@ -164,8 +164,8 @@ discard block |
||
164 | 164 | * |
165 | 165 | * @param array $request The Form Data passed into the batch processing |
166 | 166 | */ |
167 | - public function set_properties( $request ) { |
|
168 | - $this->form_id = isset( $request['form_id'] ) ? sanitize_text_field( $request['form_id'] ) : false; |
|
167 | + public function set_properties($request) { |
|
168 | + $this->form_id = isset($request['form_id']) ? sanitize_text_field($request['form_id']) : false; |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
@@ -176,31 +176,31 @@ discard block |
||
176 | 176 | */ |
177 | 177 | public function process_step() { |
178 | 178 | |
179 | - if ( ! $this->can_export() ) { |
|
180 | - wp_die( esc_html__( 'You do not have permission to recount stats.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
179 | + if ( ! $this->can_export()) { |
|
180 | + wp_die(esc_html__('You do not have permission to recount stats.', 'give'), esc_html__('Error', 'give'), array('response' => 403)); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | $had_data = $this->get_data(); |
184 | 184 | |
185 | - if ( $had_data ) { |
|
185 | + if ($had_data) { |
|
186 | 186 | $this->done = false; |
187 | 187 | |
188 | 188 | return true; |
189 | 189 | } else { |
190 | - $this->delete_data( 'give_recount_total_' . $this->form_id ); |
|
191 | - $this->delete_data( 'give_temp_recount_form_stats' ); |
|
190 | + $this->delete_data('give_recount_total_'.$this->form_id); |
|
191 | + $this->delete_data('give_temp_recount_form_stats'); |
|
192 | 192 | $this->done = true; |
193 | - $this->message = sprintf( esc_html__( 'Donation counts and income amount statistics successfully recounted for "%s".', 'give' ), get_the_title( $this->form_id ) ); |
|
193 | + $this->message = sprintf(esc_html__('Donation counts and income amount statistics successfully recounted for "%s".', 'give'), get_the_title($this->form_id)); |
|
194 | 194 | |
195 | 195 | return false; |
196 | 196 | } |
197 | 197 | } |
198 | 198 | |
199 | 199 | public function headers() { |
200 | - ignore_user_abort( true ); |
|
200 | + ignore_user_abort(true); |
|
201 | 201 | |
202 | - if ( ! give_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) { |
|
203 | - set_time_limit( 0 ); |
|
202 | + if ( ! give_is_func_disabled('set_time_limit') && ! ini_get('safe_mode')) { |
|
203 | + set_time_limit(0); |
|
204 | 204 | } |
205 | 205 | } |
206 | 206 | |
@@ -228,11 +228,11 @@ discard block |
||
228 | 228 | * |
229 | 229 | * @return mixed Returns the data from the database |
230 | 230 | */ |
231 | - private function get_stored_data( $key ) { |
|
231 | + private function get_stored_data($key) { |
|
232 | 232 | global $wpdb; |
233 | - $value = $wpdb->get_var( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = '%s'", $key ) ); |
|
233 | + $value = $wpdb->get_var($wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = '%s'", $key)); |
|
234 | 234 | |
235 | - return empty( $value ) ? false : maybe_unserialize( $value ); |
|
235 | + return empty($value) ? false : maybe_unserialize($value); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | /** |
@@ -245,10 +245,10 @@ discard block |
||
245 | 245 | * |
246 | 246 | * @return void |
247 | 247 | */ |
248 | - private function store_data( $key, $value ) { |
|
248 | + private function store_data($key, $value) { |
|
249 | 249 | global $wpdb; |
250 | 250 | |
251 | - $value = maybe_serialize( $value ); |
|
251 | + $value = maybe_serialize($value); |
|
252 | 252 | |
253 | 253 | $data = array( |
254 | 254 | 'option_name' => $key, |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | '%s', |
263 | 263 | ); |
264 | 264 | |
265 | - $wpdb->replace( $wpdb->options, $data, $formats ); |
|
265 | + $wpdb->replace($wpdb->options, $data, $formats); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | /** |
@@ -274,9 +274,9 @@ discard block |
||
274 | 274 | * |
275 | 275 | * @return void |
276 | 276 | */ |
277 | - private function delete_data( $key ) { |
|
277 | + private function delete_data($key) { |
|
278 | 278 | global $wpdb; |
279 | - $wpdb->delete( $wpdb->options, array( 'option_name' => $key ) ); |
|
279 | + $wpdb->delete($wpdb->options, array('option_name' => $key)); |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | } |
283 | 283 | \ No newline at end of file |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | */ |
12 | 12 | |
13 | 13 | // Exit if accessed directly. |
14 | -if (! defined('ABSPATH') ) { |
|
14 | +if ( ! defined('ABSPATH')) { |
|
15 | 15 | exit; |
16 | 16 | } |
17 | 17 | |
@@ -80,104 +80,102 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public function get_data() { |
82 | 82 | |
83 | - $totals = $this->get_stored_data( 'give_temp_recount_all_stats' ); |
|
84 | - $payment_items = $this->get_stored_data( 'give_temp_payment_items' ); |
|
85 | - $processed_payments = $this->get_stored_data( 'give_temp_processed_payments' ); |
|
86 | - $accepted_statuses = apply_filters( 'give_recount_accepted_statuses', array( 'publish' ) ); |
|
83 | + $totals = $this->get_stored_data('give_temp_recount_all_stats'); |
|
84 | + $payment_items = $this->get_stored_data('give_temp_payment_items'); |
|
85 | + $processed_payments = $this->get_stored_data('give_temp_processed_payments'); |
|
86 | + $accepted_statuses = apply_filters('give_recount_accepted_statuses', array('publish')); |
|
87 | 87 | |
88 | - if ( false === $totals ) { |
|
88 | + if (false === $totals) { |
|
89 | 89 | $totals = array(); |
90 | 90 | } |
91 | 91 | |
92 | - if ( false === $payment_items ) { |
|
92 | + if (false === $payment_items) { |
|
93 | 93 | $payment_items = array(); |
94 | 94 | } |
95 | 95 | |
96 | - if ( false === $processed_payments ) { |
|
96 | + if (false === $processed_payments) { |
|
97 | 97 | $processed_payments = array(); |
98 | 98 | } |
99 | 99 | |
100 | - $all_forms = $this->get_stored_data( 'give_temp_form_ids' ); |
|
100 | + $all_forms = $this->get_stored_data('give_temp_form_ids'); |
|
101 | 101 | |
102 | - $payments = $this->get_stored_data( 'give_temp_all_payments_data' ); |
|
102 | + $payments = $this->get_stored_data('give_temp_all_payments_data'); |
|
103 | 103 | |
104 | - if( false === $payments ) { |
|
105 | - $args = apply_filters( 'give_recount_form_stats_args', array( |
|
104 | + if (false === $payments) { |
|
105 | + $args = apply_filters('give_recount_form_stats_args', array( |
|
106 | 106 | 'post_parent__in' => $all_forms, |
107 | 107 | 'number' => $this->per_step, |
108 | 108 | 'status' => 'publish', |
109 | 109 | 'paged' => $this->step, |
110 | 110 | 'output' => 'payments', |
111 | - ) ); |
|
111 | + )); |
|
112 | 112 | |
113 | - $payments_query = new Give_Payments_Query( $args ); |
|
113 | + $payments_query = new Give_Payments_Query($args); |
|
114 | 114 | $payments = $payments_query->get_payments(); |
115 | 115 | } |
116 | 116 | |
117 | - if ( $payments ) { |
|
117 | + if ($payments) { |
|
118 | 118 | |
119 | 119 | //Loop through payments |
120 | - foreach ( $payments as $payment ) { |
|
120 | + foreach ($payments as $payment) { |
|
121 | 121 | |
122 | 122 | // Prevent payments that have all ready been retrieved from a previous sales log from counting again. |
123 | - if ( in_array( $payment->ID, $processed_payments ) ) { |
|
123 | + if (in_array($payment->ID, $processed_payments)) { |
|
124 | 124 | continue; |
125 | 125 | } |
126 | 126 | |
127 | 127 | // Verify accepted status |
128 | - if ( ! in_array( $payment->post_status, $accepted_statuses ) ) { |
|
128 | + if ( ! in_array($payment->post_status, $accepted_statuses)) { |
|
129 | 129 | $processed_payments[] = $payment->ID; |
130 | 130 | continue; |
131 | 131 | } |
132 | 132 | |
133 | - $payment_item = $payment_items[ $payment->ID ]; |
|
133 | + $payment_item = $payment_items[$payment->ID]; |
|
134 | 134 | |
135 | - $form_id = isset( $payment_item['id'] ) ? $payment_item['id'] : ''; |
|
135 | + $form_id = isset($payment_item['id']) ? $payment_item['id'] : ''; |
|
136 | 136 | |
137 | 137 | //Must have a form ID |
138 | - if ( empty( $form_id ) ) { |
|
138 | + if (empty($form_id)) { |
|
139 | 139 | continue; |
140 | 140 | } |
141 | 141 | |
142 | 142 | //Form ID must be within $all_forms array to be validated |
143 | - if ( ! in_array( $form_id, $all_forms ) ) { |
|
143 | + if ( ! in_array($form_id, $all_forms)) { |
|
144 | 144 | continue; |
145 | 145 | } |
146 | 146 | |
147 | 147 | // Set Sales count |
148 | - $totals[ $form_id ]['sales'] = isset( $totals[ $form_id ]['sales'] ) ? |
|
149 | - ++ $totals[ $form_id ]['sales'] : |
|
150 | - 1; |
|
148 | + $totals[$form_id]['sales'] = isset($totals[$form_id]['sales']) ? |
|
149 | + ++$totals[$form_id]['sales'] : 1; |
|
151 | 150 | |
152 | 151 | // Set Total Earnings |
153 | - $totals[ $form_id ]['earnings'] = isset( $totals[ $form_id ]['earnings'] ) ? |
|
154 | - ( $totals[ $form_id ]['earnings'] + $payment_item['price'] ) : |
|
155 | - $payment_item['price']; |
|
152 | + $totals[$form_id]['earnings'] = isset($totals[$form_id]['earnings']) ? |
|
153 | + ($totals[$form_id]['earnings'] + $payment_item['price']) : $payment_item['price']; |
|
156 | 154 | |
157 | 155 | $processed_payments[] = $payment->ID; |
158 | 156 | } |
159 | 157 | |
160 | 158 | // Get the list of form ids which does not contain any payment record. |
161 | - $remaining_form_ids = array_diff( $all_forms, array_keys($totals) ); |
|
162 | - foreach( $remaining_form_ids as $form_id) { |
|
159 | + $remaining_form_ids = array_diff($all_forms, array_keys($totals)); |
|
160 | + foreach ($remaining_form_ids as $form_id) { |
|
163 | 161 | //If array key doesn't exist, create it |
164 | - if ( ! array_key_exists( $form_id, $totals ) ) { |
|
165 | - $totals[ $form_id ] = array( |
|
162 | + if ( ! array_key_exists($form_id, $totals)) { |
|
163 | + $totals[$form_id] = array( |
|
166 | 164 | 'sales' => (int) 0, |
167 | 165 | 'earnings' => (float) 0, |
168 | 166 | ); |
169 | 167 | } |
170 | 168 | } |
171 | 169 | |
172 | - $this->store_data( 'give_temp_processed_payments', $processed_payments ); |
|
173 | - $this->store_data( 'give_temp_recount_all_stats', $totals ); |
|
170 | + $this->store_data('give_temp_processed_payments', $processed_payments); |
|
171 | + $this->store_data('give_temp_recount_all_stats', $totals); |
|
174 | 172 | |
175 | 173 | return true; |
176 | 174 | } |
177 | 175 | |
178 | - foreach ( $totals as $key => $stats ) { |
|
179 | - give_update_meta( $key, '_give_form_sales', $stats['sales'] ); |
|
180 | - give_update_meta( $key, '_give_form_earnings', give_sanitize_amount_for_db( $stats['earnings'] ) ); |
|
176 | + foreach ($totals as $key => $stats) { |
|
177 | + give_update_meta($key, '_give_form_sales', $stats['sales']); |
|
178 | + give_update_meta($key, '_give_form_earnings', give_sanitize_amount_for_db($stats['earnings'])); |
|
181 | 179 | } |
182 | 180 | |
183 | 181 | return false; |
@@ -192,20 +190,20 @@ discard block |
||
192 | 190 | */ |
193 | 191 | public function get_percentage_complete() { |
194 | 192 | |
195 | - $total = $this->get_stored_data( 'give_recount_all_total' ); |
|
193 | + $total = $this->get_stored_data('give_recount_all_total'); |
|
196 | 194 | |
197 | - if ( false === $total ) { |
|
195 | + if (false === $total) { |
|
198 | 196 | $this->pre_fetch(); |
199 | - $total = $this->get_stored_data( 'give_recount_all_total' ); |
|
197 | + $total = $this->get_stored_data('give_recount_all_total'); |
|
200 | 198 | } |
201 | 199 | |
202 | 200 | $percentage = 100; |
203 | 201 | |
204 | - if ( $total > 0 ) { |
|
205 | - $percentage = ( ( $this->per_step * $this->step ) / $total ) * 100; |
|
202 | + if ($total > 0) { |
|
203 | + $percentage = (($this->per_step * $this->step) / $total) * 100; |
|
206 | 204 | } |
207 | 205 | |
208 | - if ( $percentage > 100 ) { |
|
206 | + if ($percentage > 100) { |
|
209 | 207 | $percentage = 100; |
210 | 208 | } |
211 | 209 | |
@@ -219,8 +217,8 @@ discard block |
||
219 | 217 | * |
220 | 218 | * @param array $request The Form Data passed into the batch processing |
221 | 219 | */ |
222 | - public function set_properties( $request ) { |
|
223 | - $this->form_id = isset( $request['form_id'] ) ? sanitize_text_field( $request['form_id'] ) : false; |
|
220 | + public function set_properties($request) { |
|
221 | + $this->form_id = isset($request['form_id']) ? sanitize_text_field($request['form_id']) : false; |
|
224 | 222 | } |
225 | 223 | |
226 | 224 | /** |
@@ -231,35 +229,35 @@ discard block |
||
231 | 229 | */ |
232 | 230 | public function process_step() { |
233 | 231 | |
234 | - if ( ! $this->can_export() ) { |
|
235 | - wp_die( esc_html__( 'You do not have permission to recount stats.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
232 | + if ( ! $this->can_export()) { |
|
233 | + wp_die(esc_html__('You do not have permission to recount stats.', 'give'), esc_html__('Error', 'give'), array('response' => 403)); |
|
236 | 234 | } |
237 | 235 | |
238 | 236 | $had_data = $this->get_data(); |
239 | 237 | |
240 | - if ( $had_data ) { |
|
238 | + if ($had_data) { |
|
241 | 239 | $this->done = false; |
242 | 240 | |
243 | 241 | return true; |
244 | 242 | } else { |
245 | - $this->delete_data( 'give_recount_total_' . $this->form_id ); |
|
246 | - $this->delete_data( 'give_recount_all_total' ); |
|
247 | - $this->delete_data( 'give_temp_recount_all_stats' ); |
|
248 | - $this->delete_data( 'give_temp_payment_items' ); |
|
249 | - $this->delete_data( 'give_temp_form_ids' ); |
|
250 | - $this->delete_data( 'give_temp_processed_payments' ); |
|
243 | + $this->delete_data('give_recount_total_'.$this->form_id); |
|
244 | + $this->delete_data('give_recount_all_total'); |
|
245 | + $this->delete_data('give_temp_recount_all_stats'); |
|
246 | + $this->delete_data('give_temp_payment_items'); |
|
247 | + $this->delete_data('give_temp_form_ids'); |
|
248 | + $this->delete_data('give_temp_processed_payments'); |
|
251 | 249 | $this->done = true; |
252 | - $this->message = esc_html__( 'Donation form income amounts and donation counts stats successfully recounted.', 'give' ); |
|
250 | + $this->message = esc_html__('Donation form income amounts and donation counts stats successfully recounted.', 'give'); |
|
253 | 251 | |
254 | 252 | return false; |
255 | 253 | } |
256 | 254 | } |
257 | 255 | |
258 | 256 | public function headers() { |
259 | - ignore_user_abort( true ); |
|
257 | + ignore_user_abort(true); |
|
260 | 258 | |
261 | - if ( ! give_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) { |
|
262 | - set_time_limit( 0 ); |
|
259 | + if ( ! give_is_func_disabled('set_time_limit') && ! ini_get('safe_mode')) { |
|
260 | + set_time_limit(0); |
|
263 | 261 | } |
264 | 262 | } |
265 | 263 | |
@@ -286,69 +284,69 @@ discard block |
||
286 | 284 | */ |
287 | 285 | public function pre_fetch() { |
288 | 286 | |
289 | - if ( $this->step == 1 ) { |
|
290 | - $this->delete_data( 'give_temp_recount_all_total' ); |
|
291 | - $this->delete_data( 'give_temp_recount_all_stats' ); |
|
292 | - $this->delete_data( 'give_temp_payment_items' ); |
|
293 | - $this->delete_data( 'give_temp_processed_payments' ); |
|
294 | - $this->delete_data( 'give_temp_all_payments_data' ); |
|
287 | + if ($this->step == 1) { |
|
288 | + $this->delete_data('give_temp_recount_all_total'); |
|
289 | + $this->delete_data('give_temp_recount_all_stats'); |
|
290 | + $this->delete_data('give_temp_payment_items'); |
|
291 | + $this->delete_data('give_temp_processed_payments'); |
|
292 | + $this->delete_data('give_temp_all_payments_data'); |
|
295 | 293 | } |
296 | 294 | |
297 | - $accepted_statuses = apply_filters( 'give_recount_accepted_statuses', array( 'publish' ) ); |
|
298 | - $total = $this->get_stored_data( 'give_temp_recount_all_total' ); |
|
295 | + $accepted_statuses = apply_filters('give_recount_accepted_statuses', array('publish')); |
|
296 | + $total = $this->get_stored_data('give_temp_recount_all_total'); |
|
299 | 297 | |
300 | - if ( false === $total ) { |
|
298 | + if (false === $total) { |
|
301 | 299 | $total = 0; |
302 | - $payment_items = $this->get_stored_data( 'give_temp_payment_items' ); |
|
300 | + $payment_items = $this->get_stored_data('give_temp_payment_items'); |
|
303 | 301 | |
304 | - if ( false === $payment_items ) { |
|
302 | + if (false === $payment_items) { |
|
305 | 303 | $payment_items = array(); |
306 | - $this->store_data( 'give_temp_payment_items', $payment_items ); |
|
304 | + $this->store_data('give_temp_payment_items', $payment_items); |
|
307 | 305 | } |
308 | 306 | |
309 | 307 | $args = array( |
310 | 308 | 'post_status' => 'publish', |
311 | 309 | 'post_type' => 'give_forms', |
312 | - 'posts_per_page' => - 1, |
|
310 | + 'posts_per_page' => -1, |
|
313 | 311 | 'fields' => 'ids', |
314 | 312 | ); |
315 | 313 | |
316 | - $all_forms = get_posts( $args ); |
|
317 | - $this->store_data( 'give_temp_form_ids', $all_forms ); |
|
314 | + $all_forms = get_posts($args); |
|
315 | + $this->store_data('give_temp_form_ids', $all_forms); |
|
318 | 316 | |
319 | - $args = apply_filters( 'give_recount_form_stats_total_args', array( |
|
317 | + $args = apply_filters('give_recount_form_stats_total_args', array( |
|
320 | 318 | 'post_parent__in' => $all_forms, |
321 | 319 | 'number' => $this->per_step, |
322 | 320 | 'status' => 'publish', |
323 | 321 | 'page' => $this->step, |
324 | 322 | 'output' => 'payments', |
325 | - ) ); |
|
323 | + )); |
|
326 | 324 | |
327 | - $payments_query = new Give_Payments_Query( $args ); |
|
325 | + $payments_query = new Give_Payments_Query($args); |
|
328 | 326 | $payments = $payments_query->get_payments(); |
329 | - $total = wp_count_posts( 'give_payment' )->publish; |
|
327 | + $total = wp_count_posts('give_payment')->publish; |
|
330 | 328 | |
331 | - $this->store_data( 'give_temp_all_payments_data', $payments ); |
|
329 | + $this->store_data('give_temp_all_payments_data', $payments); |
|
332 | 330 | |
333 | - if ( $payments ) { |
|
331 | + if ($payments) { |
|
334 | 332 | |
335 | - foreach ( $payments as $payment ) { |
|
333 | + foreach ($payments as $payment) { |
|
336 | 334 | |
337 | - $payment = new Give_Payment( $payment->ID ); |
|
335 | + $payment = new Give_Payment($payment->ID); |
|
338 | 336 | $form_id = $payment->form_id; |
339 | 337 | |
340 | 338 | //If for some reason somehow the form_ID isn't set check payment meta |
341 | - if ( empty( $payment->form_id ) ) { |
|
339 | + if (empty($payment->form_id)) { |
|
342 | 340 | $payment_meta = $payment->get_meta(); |
343 | - $form_id = isset( $payment_meta['form_id'] ) ? $payment_meta['form_id'] : 0; |
|
341 | + $form_id = isset($payment_meta['form_id']) ? $payment_meta['form_id'] : 0; |
|
344 | 342 | } |
345 | 343 | |
346 | - if ( ! in_array( $payment->post_status, $accepted_statuses ) ) { |
|
344 | + if ( ! in_array($payment->post_status, $accepted_statuses)) { |
|
347 | 345 | continue; |
348 | 346 | } |
349 | 347 | |
350 | - if ( ! array_key_exists( $payment->ID, $payment_items ) ) { |
|
351 | - $payment_items[ $payment->ID ] = array( |
|
348 | + if ( ! array_key_exists($payment->ID, $payment_items)) { |
|
349 | + $payment_items[$payment->ID] = array( |
|
352 | 350 | 'id' => $form_id, |
353 | 351 | 'payment_id' => $payment->ID, |
354 | 352 | 'price' => $payment->total |
@@ -359,8 +357,8 @@ discard block |
||
359 | 357 | |
360 | 358 | } |
361 | 359 | |
362 | - $this->store_data( 'give_temp_payment_items', $payment_items ); |
|
363 | - $this->store_data( 'give_recount_all_total', $total ); |
|
360 | + $this->store_data('give_temp_payment_items', $payment_items); |
|
361 | + $this->store_data('give_recount_all_total', $total); |
|
364 | 362 | } |
365 | 363 | |
366 | 364 | } |
@@ -374,11 +372,11 @@ discard block |
||
374 | 372 | * |
375 | 373 | * @return mixed Returns the data from the database |
376 | 374 | */ |
377 | - private function get_stored_data( $key ) { |
|
375 | + private function get_stored_data($key) { |
|
378 | 376 | global $wpdb; |
379 | - $value = $wpdb->get_var( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = '%s'", $key ) ); |
|
377 | + $value = $wpdb->get_var($wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = '%s'", $key)); |
|
380 | 378 | |
381 | - return empty( $value ) ? false : maybe_unserialize( $value ); |
|
379 | + return empty($value) ? false : maybe_unserialize($value); |
|
382 | 380 | } |
383 | 381 | |
384 | 382 | /** |
@@ -391,10 +389,10 @@ discard block |
||
391 | 389 | * |
392 | 390 | * @return void |
393 | 391 | */ |
394 | - private function store_data( $key, $value ) { |
|
392 | + private function store_data($key, $value) { |
|
395 | 393 | global $wpdb; |
396 | 394 | |
397 | - $value = maybe_serialize( $value ); |
|
395 | + $value = maybe_serialize($value); |
|
398 | 396 | |
399 | 397 | $data = array( |
400 | 398 | 'option_name' => $key, |
@@ -408,7 +406,7 @@ discard block |
||
408 | 406 | '%s', |
409 | 407 | ); |
410 | 408 | |
411 | - $wpdb->replace( $wpdb->options, $data, $formats ); |
|
409 | + $wpdb->replace($wpdb->options, $data, $formats); |
|
412 | 410 | } |
413 | 411 | |
414 | 412 | /** |
@@ -420,9 +418,9 @@ discard block |
||
420 | 418 | * |
421 | 419 | * @return void |
422 | 420 | */ |
423 | - private function delete_data( $key ) { |
|
421 | + private function delete_data($key) { |
|
424 | 422 | global $wpdb; |
425 | - $wpdb->delete( $wpdb->options, array( 'option_name' => $key ) ); |
|
423 | + $wpdb->delete($wpdb->options, array('option_name' => $key)); |
|
426 | 424 | } |
427 | 425 | |
428 | 426 | } |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | */ |
12 | 12 | |
13 | 13 | // Exit if accessed directly. |
14 | -if ( ! defined( 'ABSPATH' ) ) { |
|
14 | +if ( ! defined('ABSPATH')) { |
|
15 | 15 | exit; |
16 | 16 | } |
17 | 17 | |
@@ -53,40 +53,40 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public function get_data() { |
55 | 55 | |
56 | - $donor = new Give_Donor( $this->customer_id ); |
|
57 | - $payments = $this->get_stored_data( 'give_recount_donor_payments_' . $donor->id ); |
|
56 | + $donor = new Give_Donor($this->customer_id); |
|
57 | + $payments = $this->get_stored_data('give_recount_donor_payments_'.$donor->id); |
|
58 | 58 | |
59 | - $offset = ( $this->step - 1 ) * $this->per_step; |
|
60 | - $step_items = array_slice( $payments, $offset, $this->per_step ); |
|
59 | + $offset = ($this->step - 1) * $this->per_step; |
|
60 | + $step_items = array_slice($payments, $offset, $this->per_step); |
|
61 | 61 | |
62 | - if ( count( $step_items ) > 0 ) { |
|
63 | - $pending_total = (float) $this->get_stored_data( 'give_stats_donor_pending_total' . $donor->id ); |
|
62 | + if (count($step_items) > 0) { |
|
63 | + $pending_total = (float) $this->get_stored_data('give_stats_donor_pending_total'.$donor->id); |
|
64 | 64 | $step_total = 0; |
65 | 65 | |
66 | - $found_payment_ids = $this->get_stored_data( 'give_stats_found_payments_' . $donor->id ); |
|
66 | + $found_payment_ids = $this->get_stored_data('give_stats_found_payments_'.$donor->id); |
|
67 | 67 | |
68 | - foreach ( $step_items as $payment ) { |
|
69 | - $payment = get_post( $payment->ID ); |
|
68 | + foreach ($step_items as $payment) { |
|
69 | + $payment = get_post($payment->ID); |
|
70 | 70 | |
71 | - if ( is_null( $payment ) || is_wp_error( $payment ) || 'give_payment' !== $payment->post_type ) { |
|
71 | + if (is_null($payment) || is_wp_error($payment) || 'give_payment' !== $payment->post_type) { |
|
72 | 72 | |
73 | - $missing_payments = $this->get_stored_data( 'give_stats_missing_payments' . $donor->id ); |
|
73 | + $missing_payments = $this->get_stored_data('give_stats_missing_payments'.$donor->id); |
|
74 | 74 | $missing_payments[] = $payment->ID; |
75 | - $this->store_data( 'give_stats_missing_payments' . $donor->id, $missing_payments ); |
|
75 | + $this->store_data('give_stats_missing_payments'.$donor->id, $missing_payments); |
|
76 | 76 | |
77 | 77 | continue; |
78 | 78 | } |
79 | 79 | |
80 | 80 | $should_process_payment = 'publish' == $payment->post_status ? true : false; |
81 | - $should_process_payment = apply_filters( 'give_donor_recount_should_process_donation', $should_process_payment, $payment ); |
|
81 | + $should_process_payment = apply_filters('give_donor_recount_should_process_donation', $should_process_payment, $payment); |
|
82 | 82 | |
83 | - if ( true === $should_process_payment ) { |
|
83 | + if (true === $should_process_payment) { |
|
84 | 84 | |
85 | 85 | $found_payment_ids[] = $payment->ID; |
86 | 86 | |
87 | - if ( apply_filters( 'give_donor_recount_should_increase_value', true, $payment ) ) { |
|
88 | - $payment_amount = give_get_payment_amount( $payment->ID ); |
|
89 | - $step_total += $payment_amount; |
|
87 | + if (apply_filters('give_donor_recount_should_increase_value', true, $payment)) { |
|
88 | + $payment_amount = give_get_payment_amount($payment->ID); |
|
89 | + $step_total += $payment_amount; |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | } |
@@ -94,8 +94,8 @@ discard block |
||
94 | 94 | } |
95 | 95 | |
96 | 96 | $updated_total = $pending_total + $step_total; |
97 | - $this->store_data( 'give_stats_donor_pending_total' . $donor->id, $updated_total ); |
|
98 | - $this->store_data( 'give_stats_found_payments_' . $donor->id, $found_payment_ids ); |
|
97 | + $this->store_data('give_stats_donor_pending_total'.$donor->id, $updated_total); |
|
98 | + $this->store_data('give_stats_found_payments_'.$donor->id, $found_payment_ids); |
|
99 | 99 | |
100 | 100 | return true; |
101 | 101 | } |
@@ -112,16 +112,16 @@ discard block |
||
112 | 112 | */ |
113 | 113 | public function get_percentage_complete() { |
114 | 114 | |
115 | - $payments = $this->get_stored_data( 'give_recount_donor_payments_' . $this->customer_id ); |
|
116 | - $total = count( $payments ); |
|
115 | + $payments = $this->get_stored_data('give_recount_donor_payments_'.$this->customer_id); |
|
116 | + $total = count($payments); |
|
117 | 117 | |
118 | 118 | $percentage = 100; |
119 | 119 | |
120 | - if ( $total > 0 ) { |
|
121 | - $percentage = ( ( $this->per_step * $this->step ) / $total ) * 100; |
|
120 | + if ($total > 0) { |
|
121 | + $percentage = (($this->per_step * $this->step) / $total) * 100; |
|
122 | 122 | } |
123 | 123 | |
124 | - if ( $percentage > 100 ) { |
|
124 | + if ($percentage > 100) { |
|
125 | 125 | $percentage = 100; |
126 | 126 | } |
127 | 127 | |
@@ -135,8 +135,8 @@ discard block |
||
135 | 135 | * |
136 | 136 | * @param array $request The Form Data passed into the batch processing |
137 | 137 | */ |
138 | - public function set_properties( $request ) { |
|
139 | - $this->customer_id = isset( $request['customer_id'] ) ? sanitize_text_field( $request['customer_id'] ) : false; |
|
138 | + public function set_properties($request) { |
|
139 | + $this->customer_id = isset($request['customer_id']) ? sanitize_text_field($request['customer_id']) : false; |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
@@ -147,63 +147,63 @@ discard block |
||
147 | 147 | */ |
148 | 148 | public function process_step() { |
149 | 149 | |
150 | - if ( ! $this->can_export() ) { |
|
151 | - wp_die( esc_html__( 'You do not have permission to recount stats.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
150 | + if ( ! $this->can_export()) { |
|
151 | + wp_die(esc_html__('You do not have permission to recount stats.', 'give'), esc_html__('Error', 'give'), array('response' => 403)); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | $had_data = $this->get_data(); |
155 | 155 | |
156 | - if ( $had_data ) { |
|
156 | + if ($had_data) { |
|
157 | 157 | $this->done = false; |
158 | 158 | |
159 | 159 | return true; |
160 | 160 | } else { |
161 | - $donor = new Give_Donor( $this->customer_id ); |
|
162 | - $payment_ids = get_option( 'give_stats_found_payments_' . $donor->id, array() ); |
|
163 | - $this->delete_data( 'give_stats_found_payments_' . $donor->id ); |
|
161 | + $donor = new Give_Donor($this->customer_id); |
|
162 | + $payment_ids = get_option('give_stats_found_payments_'.$donor->id, array()); |
|
163 | + $this->delete_data('give_stats_found_payments_'.$donor->id); |
|
164 | 164 | |
165 | - $removed_payments = array_unique( get_option( 'give_stats_missing_payments' . $donor->id, array() ) ); |
|
165 | + $removed_payments = array_unique(get_option('give_stats_missing_payments'.$donor->id, array())); |
|
166 | 166 | |
167 | 167 | // Find non-existing payments (deleted) and total up the donation count |
168 | 168 | $purchase_count = 0; |
169 | - foreach ( $payment_ids as $key => $payment_id ) { |
|
170 | - if ( in_array( $payment_id, $removed_payments ) ) { |
|
171 | - unset( $payment_ids[ $key ] ); |
|
169 | + foreach ($payment_ids as $key => $payment_id) { |
|
170 | + if (in_array($payment_id, $removed_payments)) { |
|
171 | + unset($payment_ids[$key]); |
|
172 | 172 | continue; |
173 | 173 | } |
174 | 174 | |
175 | - $payment = get_post( $payment_id ); |
|
176 | - if ( apply_filters( 'give_donor_recount_should_increase_count', true, $payment ) ) { |
|
177 | - $purchase_count ++; |
|
175 | + $payment = get_post($payment_id); |
|
176 | + if (apply_filters('give_donor_recount_should_increase_count', true, $payment)) { |
|
177 | + $purchase_count++; |
|
178 | 178 | } |
179 | 179 | } |
180 | 180 | |
181 | - $this->delete_data( 'give_stats_missing_payments' . $donor->id ); |
|
181 | + $this->delete_data('give_stats_missing_payments'.$donor->id); |
|
182 | 182 | |
183 | - $pending_total = $this->get_stored_data( 'give_stats_donor_pending_total' . $donor->id ); |
|
184 | - $this->delete_data( 'give_stats_donor_pending_total' . $donor->id ); |
|
185 | - $this->delete_data( 'give_recount_donor_stats_' . $donor->id ); |
|
186 | - $this->delete_data( 'give_recount_donor_payments_' . $this->customer_id ); |
|
183 | + $pending_total = $this->get_stored_data('give_stats_donor_pending_total'.$donor->id); |
|
184 | + $this->delete_data('give_stats_donor_pending_total'.$donor->id); |
|
185 | + $this->delete_data('give_recount_donor_stats_'.$donor->id); |
|
186 | + $this->delete_data('give_recount_donor_payments_'.$this->customer_id); |
|
187 | 187 | |
188 | - $payment_ids = implode( ',', $payment_ids ); |
|
189 | - $donor->update( array( |
|
188 | + $payment_ids = implode(',', $payment_ids); |
|
189 | + $donor->update(array( |
|
190 | 190 | 'payment_ids' => $payment_ids, |
191 | 191 | 'purchase_count' => $purchase_count, |
192 | 192 | 'purchase_value' => $pending_total, |
193 | - ) ); |
|
193 | + )); |
|
194 | 194 | |
195 | 195 | $this->done = true; |
196 | - $this->message = esc_html__( 'Donor stats have been successfully recounted.', 'give' ); |
|
196 | + $this->message = esc_html__('Donor stats have been successfully recounted.', 'give'); |
|
197 | 197 | |
198 | 198 | return false; |
199 | 199 | } |
200 | 200 | } |
201 | 201 | |
202 | 202 | public function headers() { |
203 | - ignore_user_abort( true ); |
|
203 | + ignore_user_abort(true); |
|
204 | 204 | |
205 | - if ( ! give_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) { |
|
206 | - set_time_limit( 0 ); |
|
205 | + if ( ! give_is_func_disabled('set_time_limit') && ! ini_get('safe_mode')) { |
|
206 | + set_time_limit(0); |
|
207 | 207 | } |
208 | 208 | } |
209 | 209 | |
@@ -230,26 +230,26 @@ discard block |
||
230 | 230 | * @return void |
231 | 231 | */ |
232 | 232 | public function pre_fetch() { |
233 | - if ( $this->step === 1 ) { |
|
234 | - $allowed_payment_status = apply_filters( 'give_recount_donors_donation_statuses', give_get_payment_status_keys() ); |
|
233 | + if ($this->step === 1) { |
|
234 | + $allowed_payment_status = apply_filters('give_recount_donors_donation_statuses', give_get_payment_status_keys()); |
|
235 | 235 | |
236 | 236 | // Before we start, let's zero out the customer's data |
237 | - $donor = new Give_Donor( $this->customer_id ); |
|
238 | - $donor->update( array( 'purchase_value' => give_format_amount( 0, array( 'sanitize' => false ) ), 'purchase_count' => 0 ) ); |
|
237 | + $donor = new Give_Donor($this->customer_id); |
|
238 | + $donor->update(array('purchase_value' => give_format_amount(0, array('sanitize' => false)), 'purchase_count' => 0)); |
|
239 | 239 | |
240 | - $attached_payment_ids = explode( ',', $donor->payment_ids ); |
|
240 | + $attached_payment_ids = explode(',', $donor->payment_ids); |
|
241 | 241 | |
242 | 242 | $attached_args = array( |
243 | 243 | 'post__in' => $attached_payment_ids, |
244 | - 'number' => - 1, |
|
244 | + 'number' => -1, |
|
245 | 245 | 'status' => $allowed_payment_status, |
246 | 246 | ); |
247 | 247 | |
248 | - $attached_payments = give_get_payments( $attached_args ); |
|
248 | + $attached_payments = give_get_payments($attached_args); |
|
249 | 249 | |
250 | 250 | $unattached_args = array( |
251 | 251 | 'post__not_in' => $attached_payment_ids, |
252 | - 'number' => - 1, |
|
252 | + 'number' => -1, |
|
253 | 253 | 'status' => $allowed_payment_status, |
254 | 254 | 'meta_query' => array( |
255 | 255 | array( |
@@ -259,11 +259,11 @@ discard block |
||
259 | 259 | ), |
260 | 260 | ); |
261 | 261 | |
262 | - $unattached_payments = give_get_payments( $unattached_args ); |
|
262 | + $unattached_payments = give_get_payments($unattached_args); |
|
263 | 263 | |
264 | - $payments = array_merge( $attached_payments, $unattached_payments ); |
|
264 | + $payments = array_merge($attached_payments, $unattached_payments); |
|
265 | 265 | |
266 | - $this->store_data( 'give_recount_donor_payments_' . $donor->id, $payments ); |
|
266 | + $this->store_data('give_recount_donor_payments_'.$donor->id, $payments); |
|
267 | 267 | } |
268 | 268 | } |
269 | 269 | |
@@ -276,11 +276,11 @@ discard block |
||
276 | 276 | * |
277 | 277 | * @return mixed Returns the data from the database |
278 | 278 | */ |
279 | - private function get_stored_data( $key ) { |
|
279 | + private function get_stored_data($key) { |
|
280 | 280 | global $wpdb; |
281 | - $value = $wpdb->get_var( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = '%s'", $key ) ); |
|
281 | + $value = $wpdb->get_var($wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = '%s'", $key)); |
|
282 | 282 | |
283 | - return empty( $value ) ? false : maybe_unserialize( $value ); |
|
283 | + return empty($value) ? false : maybe_unserialize($value); |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | /** |
@@ -293,10 +293,10 @@ discard block |
||
293 | 293 | * |
294 | 294 | * @return void |
295 | 295 | */ |
296 | - private function store_data( $key, $value ) { |
|
296 | + private function store_data($key, $value) { |
|
297 | 297 | global $wpdb; |
298 | 298 | |
299 | - $value = maybe_serialize( $value ); |
|
299 | + $value = maybe_serialize($value); |
|
300 | 300 | |
301 | 301 | $data = array( |
302 | 302 | 'option_name' => $key, |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | '%s', |
311 | 311 | ); |
312 | 312 | |
313 | - $wpdb->replace( $wpdb->options, $data, $formats ); |
|
313 | + $wpdb->replace($wpdb->options, $data, $formats); |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | /** |
@@ -322,9 +322,9 @@ discard block |
||
322 | 322 | * |
323 | 323 | * @return void |
324 | 324 | */ |
325 | - private function delete_data( $key ) { |
|
325 | + private function delete_data($key) { |
|
326 | 326 | global $wpdb; |
327 | - $wpdb->delete( $wpdb->options, array( 'option_name' => $key ) ); |
|
327 | + $wpdb->delete($wpdb->options, array('option_name' => $key)); |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | } |