@@ -10,11 +10,11 @@ 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 | -if ( ! class_exists( 'Give_License' ) ) : |
|
17 | +if ( ! class_exists('Give_License')) : |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * Give_License Class |
@@ -143,27 +143,27 @@ discard block |
||
143 | 143 | * @param string $_checkout_url |
144 | 144 | * @param string $_account_url |
145 | 145 | */ |
146 | - public function __construct( $_file, $_item_name, $_version, $_author, $_optname = null, $_api_url = null, $_checkout_url = null, $_account_url = null ) { |
|
146 | + public function __construct($_file, $_item_name, $_version, $_author, $_optname = null, $_api_url = null, $_checkout_url = null, $_account_url = null) { |
|
147 | 147 | |
148 | 148 | $give_options = give_get_settings(); |
149 | 149 | |
150 | 150 | $this->file = $_file; |
151 | 151 | $this->item_name = $_item_name; |
152 | - $this->item_shortname = 'give_' . preg_replace( '/[^a-zA-Z0-9_\s]/', '', str_replace( ' ', '_', strtolower( $this->item_name ) ) ); |
|
152 | + $this->item_shortname = 'give_'.preg_replace('/[^a-zA-Z0-9_\s]/', '', str_replace(' ', '_', strtolower($this->item_name))); |
|
153 | 153 | $this->version = $_version; |
154 | - $this->license = isset( $give_options[ $this->item_shortname . '_license_key' ] ) ? trim( $give_options[ $this->item_shortname . '_license_key' ] ) : ''; |
|
155 | - $this->license_data = get_option( $this->item_shortname . '_license_active' ); |
|
154 | + $this->license = isset($give_options[$this->item_shortname.'_license_key']) ? trim($give_options[$this->item_shortname.'_license_key']) : ''; |
|
155 | + $this->license_data = get_option($this->item_shortname.'_license_active'); |
|
156 | 156 | $this->author = $_author; |
157 | - $this->api_url = is_null( $_api_url ) ? $this->api_url : $_api_url; |
|
158 | - $this->checkout_url = is_null( $_checkout_url ) ? $this->checkout_url : $_checkout_url; |
|
159 | - $this->account_url = is_null( $_account_url ) ? $this->account_url : $_account_url; |
|
157 | + $this->api_url = is_null($_api_url) ? $this->api_url : $_api_url; |
|
158 | + $this->checkout_url = is_null($_checkout_url) ? $this->checkout_url : $_checkout_url; |
|
159 | + $this->account_url = is_null($_account_url) ? $this->account_url : $_account_url; |
|
160 | 160 | $this->auto_updater_obj = null; |
161 | 161 | |
162 | 162 | // Add Setting for Give Add-on activation status. |
163 | - $is_addon_activated = get_option( 'give_is_addon_activated' ); |
|
164 | - if ( ! $is_addon_activated && is_object( $this ) && sizeof( $this ) > 0 ) { |
|
165 | - update_option( 'give_is_addon_activated', true ); |
|
166 | - Give_Cache::set( 'give_cache_hide_license_notice_after_activation', true, DAY_IN_SECONDS ); |
|
163 | + $is_addon_activated = get_option('give_is_addon_activated'); |
|
164 | + if ( ! $is_addon_activated && is_object($this) && sizeof($this) > 0) { |
|
165 | + update_option('give_is_addon_activated', true); |
|
166 | + Give_Cache::set('give_cache_hide_license_notice_after_activation', true, DAY_IN_SECONDS); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | // Setup hooks |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | */ |
185 | 185 | private function includes() { |
186 | 186 | |
187 | - if ( ! class_exists( 'EDD_SL_Plugin_Updater' ) ) { |
|
187 | + if ( ! class_exists('EDD_SL_Plugin_Updater')) { |
|
188 | 188 | require_once 'admin/EDD_SL_Plugin_Updater.php'; |
189 | 189 | } |
190 | 190 | } |
@@ -202,30 +202,30 @@ discard block |
||
202 | 202 | private function hooks() { |
203 | 203 | |
204 | 204 | // Register settings. |
205 | - add_filter( 'give_settings_licenses', array( $this, 'settings' ), 1 ); |
|
205 | + add_filter('give_settings_licenses', array($this, 'settings'), 1); |
|
206 | 206 | |
207 | 207 | // Activate license key on settings save. |
208 | - add_action( 'admin_init', array( $this, 'activate_license' ) ); |
|
208 | + add_action('admin_init', array($this, 'activate_license')); |
|
209 | 209 | |
210 | 210 | // Deactivate license key. |
211 | - add_action( 'admin_init', array( $this, 'deactivate_license' ) ); |
|
211 | + add_action('admin_init', array($this, 'deactivate_license')); |
|
212 | 212 | |
213 | 213 | // Updater. |
214 | - add_action( 'admin_init', array( $this, 'auto_updater' ), 0 ); |
|
215 | - add_action( 'admin_notices', array( $this, 'notices' ) ); |
|
214 | + add_action('admin_init', array($this, 'auto_updater'), 0); |
|
215 | + add_action('admin_notices', array($this, 'notices')); |
|
216 | 216 | |
217 | 217 | // Check license weekly. |
218 | - Give_Cron::add_weekly_event( array( $this, 'weekly_license_check' ) ); |
|
219 | - add_action( 'give_validate_license_when_site_migrated', array( $this, 'weekly_license_check' ) ); |
|
218 | + Give_Cron::add_weekly_event(array($this, 'weekly_license_check')); |
|
219 | + add_action('give_validate_license_when_site_migrated', array($this, 'weekly_license_check')); |
|
220 | 220 | |
221 | 221 | // Check subscription weekly. |
222 | - Give_Cron::add_weekly_event( array( $this, 'weekly_subscription_check' ) ); |
|
223 | - add_action( 'give_validate_license_when_site_migrated', array( $this, 'weekly_subscription_check' ) ); |
|
222 | + Give_Cron::add_weekly_event(array($this, 'weekly_subscription_check')); |
|
223 | + add_action('give_validate_license_when_site_migrated', array($this, 'weekly_subscription_check')); |
|
224 | 224 | |
225 | 225 | // Show addon notice on plugin page. |
226 | - $plugin_name = explode( 'plugins/', $this->file ); |
|
227 | - $plugin_name = end( $plugin_name ); |
|
228 | - add_action( "after_plugin_row_{$plugin_name}", array( $this, 'plugin_page_notices' ), 10, 3 ); |
|
226 | + $plugin_name = explode('plugins/', $this->file); |
|
227 | + $plugin_name = end($plugin_name); |
|
228 | + add_action("after_plugin_row_{$plugin_name}", array($this, 'plugin_page_notices'), 10, 3); |
|
229 | 229 | |
230 | 230 | } |
231 | 231 | |
@@ -265,16 +265,16 @@ discard block |
||
265 | 265 | * |
266 | 266 | * @return array License settings. |
267 | 267 | */ |
268 | - public function settings( $settings ) { |
|
268 | + public function settings($settings) { |
|
269 | 269 | |
270 | 270 | $give_license_settings = array( |
271 | 271 | array( |
272 | 272 | 'name' => $this->item_name, |
273 | - 'id' => $this->item_shortname . '_license_key', |
|
273 | + 'id' => $this->item_shortname.'_license_key', |
|
274 | 274 | 'desc' => '', |
275 | 275 | 'type' => 'license_key', |
276 | 276 | 'options' => array( |
277 | - 'license' => get_option( $this->item_shortname . '_license_active' ), |
|
277 | + 'license' => get_option($this->item_shortname.'_license_active'), |
|
278 | 278 | 'shortname' => $this->item_shortname, |
279 | 279 | 'item_name' => $this->item_name, |
280 | 280 | 'api_url' => $this->api_url, |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | ), |
286 | 286 | ); |
287 | 287 | |
288 | - return array_merge( $settings, $give_license_settings ); |
|
288 | + return array_merge($settings, $give_license_settings); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | /** |
@@ -300,18 +300,18 @@ discard block |
||
300 | 300 | * |
301 | 301 | * @return array License settings content. |
302 | 302 | */ |
303 | - public function license_settings_content( $settings ) { |
|
303 | + public function license_settings_content($settings) { |
|
304 | 304 | |
305 | 305 | $give_license_settings = array( |
306 | 306 | array( |
307 | - 'name' => __( 'Add-on Licenses', 'give' ), |
|
307 | + 'name' => __('Add-on Licenses', 'give'), |
|
308 | 308 | 'desc' => '<hr>', |
309 | 309 | 'type' => 'give_title', |
310 | 310 | 'id' => 'give_title', |
311 | 311 | ), |
312 | 312 | ); |
313 | 313 | |
314 | - return array_merge( $settings, $give_license_settings ); |
|
314 | + return array_merge($settings, $give_license_settings); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
@@ -326,65 +326,65 @@ discard block |
||
326 | 326 | */ |
327 | 327 | public function activate_license() { |
328 | 328 | // Bailout. |
329 | - if ( ! $this->__is_user_can_edit_license() ) { |
|
329 | + if ( ! $this->__is_user_can_edit_license()) { |
|
330 | 330 | return; |
331 | 331 | } |
332 | 332 | |
333 | 333 | // Allow third party addon developers to handle license activation. |
334 | - if ( $this->__is_third_party_addon() ) { |
|
335 | - do_action( 'give_activate_license', $this ); |
|
334 | + if ($this->__is_third_party_addon()) { |
|
335 | + do_action('give_activate_license', $this); |
|
336 | 336 | |
337 | 337 | return; |
338 | 338 | } |
339 | 339 | |
340 | 340 | // Do not simultaneously activate add-ons if the user want to deactivate a specific add-on. |
341 | - foreach ( $_POST as $key => $value ) { |
|
342 | - if ( false !== strpos( $key, 'license_key_deactivate' ) ) { |
|
341 | + foreach ($_POST as $key => $value) { |
|
342 | + if (false !== strpos($key, 'license_key_deactivate')) { |
|
343 | 343 | // Don't activate a key when deactivating a different key |
344 | 344 | return; |
345 | 345 | } |
346 | 346 | } |
347 | 347 | |
348 | 348 | // Delete previous license setting if a empty license key submitted. |
349 | - if ( empty( $_POST["{$this->item_shortname}_license_key"] ) ) { |
|
349 | + if (empty($_POST["{$this->item_shortname}_license_key"])) { |
|
350 | 350 | $this->unset_license(); |
351 | 351 | |
352 | 352 | return; |
353 | 353 | } |
354 | 354 | |
355 | 355 | // Check if plugin previously installed. |
356 | - if ( $this->is_valid_license() ) { |
|
356 | + if ($this->is_valid_license()) { |
|
357 | 357 | return; |
358 | 358 | } |
359 | 359 | |
360 | 360 | // Get license key. |
361 | - $this->license = sanitize_text_field( $_POST[ $this->item_shortname . '_license_key' ] ); |
|
361 | + $this->license = sanitize_text_field($_POST[$this->item_shortname.'_license_key']); |
|
362 | 362 | |
363 | 363 | // Delete previous license key from subscription if previously added. |
364 | 364 | $this->__remove_license_key_from_subscriptions(); |
365 | 365 | |
366 | 366 | // Make sure there are no api errors. |
367 | - if ( ! ( $license_data = $this->get_license_info( 'activate_license' ) ) ) { |
|
367 | + if ( ! ($license_data = $this->get_license_info('activate_license'))) { |
|
368 | 368 | return; |
369 | 369 | } |
370 | 370 | |
371 | 371 | // Make sure license is valid. |
372 | 372 | // return because admin will want to activate license again. |
373 | - if ( ! $this->is_license( $license_data ) ) { |
|
373 | + if ( ! $this->is_license($license_data)) { |
|
374 | 374 | // Add license key. |
375 | - give_update_option( "{$this->item_shortname}_license_key", $this->license ); |
|
375 | + give_update_option("{$this->item_shortname}_license_key", $this->license); |
|
376 | 376 | |
377 | 377 | return; |
378 | 378 | } |
379 | 379 | |
380 | 380 | // Tell WordPress to look for updates. |
381 | - set_site_transient( 'update_plugins', null ); |
|
381 | + set_site_transient('update_plugins', null); |
|
382 | 382 | |
383 | 383 | // Add license data. |
384 | - update_option( "{$this->item_shortname}_license_active", $license_data ); |
|
384 | + update_option("{$this->item_shortname}_license_active", $license_data); |
|
385 | 385 | |
386 | 386 | // Add license key. |
387 | - give_update_option( "{$this->item_shortname}_license_key", $this->license ); |
|
387 | + give_update_option("{$this->item_shortname}_license_key", $this->license); |
|
388 | 388 | |
389 | 389 | // Check subscription for license key and store this to db (if any). |
390 | 390 | $this->__single_subscription_check(); |
@@ -402,27 +402,27 @@ discard block |
||
402 | 402 | */ |
403 | 403 | public function deactivate_license() { |
404 | 404 | // Bailout. |
405 | - if ( ! $this->__is_user_can_edit_license() ) { |
|
405 | + if ( ! $this->__is_user_can_edit_license()) { |
|
406 | 406 | return; |
407 | 407 | } |
408 | 408 | |
409 | 409 | // Allow third party add-on developers to handle license deactivation. |
410 | - if ( $this->__is_third_party_addon() ) { |
|
411 | - do_action( 'give_deactivate_license', $this ); |
|
410 | + if ($this->__is_third_party_addon()) { |
|
411 | + do_action('give_deactivate_license', $this); |
|
412 | 412 | |
413 | 413 | return; |
414 | 414 | } |
415 | 415 | |
416 | 416 | // Run on deactivate button press. |
417 | - if ( isset( $_POST[ $this->item_shortname . '_license_key_deactivate' ] ) ) { |
|
417 | + if (isset($_POST[$this->item_shortname.'_license_key_deactivate'])) { |
|
418 | 418 | |
419 | 419 | // Make sure there are no api errors. |
420 | - if ( ! ( $license_data = $this->get_license_info( 'deactivate_license' ) ) ) { |
|
420 | + if ( ! ($license_data = $this->get_license_info('deactivate_license'))) { |
|
421 | 421 | return; |
422 | 422 | } |
423 | 423 | |
424 | 424 | // Ensure deactivated successfully. |
425 | - if ( isset( $license_data->success ) ) { |
|
425 | + if (isset($license_data->success)) { |
|
426 | 426 | $this->unset_license(); |
427 | 427 | } |
428 | 428 | }// End if(). |
@@ -439,30 +439,30 @@ discard block |
||
439 | 439 | public function weekly_license_check() { |
440 | 440 | |
441 | 441 | if ( |
442 | - ! empty( $_POST['give_settings'] ) || |
|
443 | - empty( $this->license ) |
|
442 | + ! empty($_POST['give_settings']) || |
|
443 | + empty($this->license) |
|
444 | 444 | ) { |
445 | 445 | return; |
446 | 446 | } |
447 | 447 | |
448 | 448 | // Allow third party add-on developers to handle their license check. |
449 | - if ( $this->__is_third_party_addon() ) { |
|
450 | - do_action( 'give_weekly_license_check', $this ); |
|
449 | + if ($this->__is_third_party_addon()) { |
|
450 | + do_action('give_weekly_license_check', $this); |
|
451 | 451 | |
452 | 452 | return; |
453 | 453 | } |
454 | 454 | |
455 | 455 | // Make sure there are no api errors. |
456 | - if ( ! ( $license_data = $this->get_license_info( 'check_license' ) ) ) { |
|
456 | + if ( ! ($license_data = $this->get_license_info('check_license'))) { |
|
457 | 457 | return; |
458 | 458 | } |
459 | 459 | |
460 | 460 | // Bailout. |
461 | - if ( ! $this->is_license( $license_data ) ) { |
|
461 | + if ( ! $this->is_license($license_data)) { |
|
462 | 462 | return; |
463 | 463 | } |
464 | 464 | |
465 | - update_option( $this->item_shortname . '_license_active', $license_data ); |
|
465 | + update_option($this->item_shortname.'_license_active', $license_data); |
|
466 | 466 | |
467 | 467 | return; |
468 | 468 | } |
@@ -478,21 +478,21 @@ discard block |
||
478 | 478 | public function weekly_subscription_check() { |
479 | 479 | // Bailout. |
480 | 480 | if ( |
481 | - ! empty( $_POST['give_settings'] ) || |
|
482 | - empty( $this->license ) |
|
481 | + ! empty($_POST['give_settings']) || |
|
482 | + empty($this->license) |
|
483 | 483 | ) { |
484 | 484 | return; |
485 | 485 | } |
486 | 486 | |
487 | 487 | // Remove old subscription data. |
488 | - if ( absint( get_option( '_give_subscriptions_edit_last', true ) ) < current_time( 'timestamp', 1 ) ) { |
|
489 | - delete_option( 'give_subscriptions' ); |
|
490 | - update_option( '_give_subscriptions_edit_last', strtotime( '+ 1 day', current_time( 'timestamp', 1 ) ) ); |
|
488 | + if (absint(get_option('_give_subscriptions_edit_last', true)) < current_time('timestamp', 1)) { |
|
489 | + delete_option('give_subscriptions'); |
|
490 | + update_option('_give_subscriptions_edit_last', strtotime('+ 1 day', current_time('timestamp', 1))); |
|
491 | 491 | } |
492 | 492 | |
493 | 493 | // Allow third party add-on developers to handle their subscription check. |
494 | - if ( $this->__is_third_party_addon() ) { |
|
495 | - do_action( 'give_weekly_subscription_check', $this ); |
|
494 | + if ($this->__is_third_party_addon()) { |
|
495 | + do_action('give_weekly_subscription_check', $this); |
|
496 | 496 | |
497 | 497 | return; |
498 | 498 | } |
@@ -509,7 +509,7 @@ discard block |
||
509 | 509 | * @return void |
510 | 510 | */ |
511 | 511 | private function __single_subscription_check() { |
512 | - if ( empty( $this->license ) ) { |
|
512 | + if (empty($this->license)) { |
|
513 | 513 | return; |
514 | 514 | } |
515 | 515 | |
@@ -520,29 +520,29 @@ discard block |
||
520 | 520 | * By default edd software licensing api does not have api to check subscription. |
521 | 521 | * This is a custom feature to check subscriptions. |
522 | 522 | */ |
523 | - if ( ! ( $subscription_data = $this->get_license_info( 'check_subscription', true ) ) ) { |
|
523 | + if ( ! ($subscription_data = $this->get_license_info('check_subscription', true))) { |
|
524 | 524 | return; |
525 | 525 | } |
526 | 526 | |
527 | 527 | |
528 | - if ( ! empty( $subscription_data['success'] ) && absint( $subscription_data['success'] ) ) { |
|
529 | - $subscriptions = get_option( 'give_subscriptions', array() ); |
|
528 | + if ( ! empty($subscription_data['success']) && absint($subscription_data['success'])) { |
|
529 | + $subscriptions = get_option('give_subscriptions', array()); |
|
530 | 530 | |
531 | 531 | // Update subscription data only if subscription does not exist already. |
532 | - $subscriptions[ $subscription_data['id'] ] = $subscription_data; |
|
532 | + $subscriptions[$subscription_data['id']] = $subscription_data; |
|
533 | 533 | |
534 | 534 | |
535 | 535 | // Initiate default set of license for subscription. |
536 | - if ( ! isset( $subscriptions[ $subscription_data['id'] ]['licenses'] ) ) { |
|
537 | - $subscriptions[ $subscription_data['id'] ]['licenses'] = array(); |
|
536 | + if ( ! isset($subscriptions[$subscription_data['id']]['licenses'])) { |
|
537 | + $subscriptions[$subscription_data['id']]['licenses'] = array(); |
|
538 | 538 | } |
539 | 539 | |
540 | 540 | // Store licenses for subscription. |
541 | - if ( ! in_array( $this->license, $subscriptions[ $subscription_data['id'] ]['licenses'] ) ) { |
|
542 | - $subscriptions[ $subscription_data['id'] ]['licenses'][] = $this->license; |
|
541 | + if ( ! in_array($this->license, $subscriptions[$subscription_data['id']]['licenses'])) { |
|
542 | + $subscriptions[$subscription_data['id']]['licenses'][] = $this->license; |
|
543 | 543 | } |
544 | 544 | |
545 | - update_option( 'give_subscriptions', $subscriptions ); |
|
545 | + update_option('give_subscriptions', $subscriptions); |
|
546 | 546 | } |
547 | 547 | } |
548 | 548 | |
@@ -556,12 +556,12 @@ discard block |
||
556 | 556 | */ |
557 | 557 | public function notices() { |
558 | 558 | |
559 | - if ( ! current_user_can( 'manage_give_settings' ) ) { |
|
559 | + if ( ! current_user_can('manage_give_settings')) { |
|
560 | 560 | return; |
561 | 561 | } |
562 | 562 | |
563 | 563 | // Do not show licenses notices on license tab. |
564 | - if ( 'licenses' === give_get_current_setting_tab() ) { |
|
564 | + if ('licenses' === give_get_current_setting_tab()) { |
|
565 | 565 | return; |
566 | 566 | } |
567 | 567 | |
@@ -570,118 +570,118 @@ discard block |
||
570 | 570 | static $addon_license_key_in_subscriptions; |
571 | 571 | |
572 | 572 | // Set default value. |
573 | - $addon_license_key_in_subscriptions = ! empty( $addon_license_key_in_subscriptions ) ? $addon_license_key_in_subscriptions : array(); |
|
573 | + $addon_license_key_in_subscriptions = ! empty($addon_license_key_in_subscriptions) ? $addon_license_key_in_subscriptions : array(); |
|
574 | 574 | $messages = array(); |
575 | 575 | |
576 | 576 | // Check whether admin has Give Add-on activated since 24 hours? |
577 | - $is_license_notice_hidden = Give_Cache::get( 'give_cache_hide_license_notice_after_activation' ); |
|
577 | + $is_license_notice_hidden = Give_Cache::get('give_cache_hide_license_notice_after_activation'); |
|
578 | 578 | |
579 | 579 | // Display Invalid License notice, if its more than 24 hours since first Give Add-on activation. |
580 | 580 | if ( |
581 | - empty( $this->license ) |
|
582 | - && empty( $showed_invalid_message ) |
|
583 | - && ( false === $is_license_notice_hidden ) |
|
581 | + empty($this->license) |
|
582 | + && empty($showed_invalid_message) |
|
583 | + && (false === $is_license_notice_hidden) |
|
584 | 584 | ) { |
585 | 585 | |
586 | - Give()->notices->register_notice( array( |
|
586 | + Give()->notices->register_notice(array( |
|
587 | 587 | 'id' => 'give-invalid-license', |
588 | 588 | 'type' => 'error', |
589 | 589 | 'description' => sprintf( |
590 | - __( 'You have invalid or expired license keys for one or more Give Add-ons. Please go to the <a href="%s">licenses page</a> to correct this issue.', 'give' ), |
|
591 | - admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=licenses' ) |
|
590 | + __('You have invalid or expired license keys for one or more Give Add-ons. Please go to the <a href="%s">licenses page</a> to correct this issue.', 'give'), |
|
591 | + admin_url('edit.php?post_type=give_forms&page=give-settings&tab=licenses') |
|
592 | 592 | ), |
593 | 593 | 'dismissible_type' => 'user', |
594 | 594 | 'dismiss_interval' => 'shortly', |
595 | - ) ); |
|
595 | + )); |
|
596 | 596 | |
597 | 597 | $showed_invalid_message = true; |
598 | 598 | |
599 | 599 | } |
600 | 600 | |
601 | 601 | // Get subscriptions. |
602 | - $subscriptions = get_option( 'give_subscriptions' ); |
|
602 | + $subscriptions = get_option('give_subscriptions'); |
|
603 | 603 | |
604 | 604 | // Show subscription messages. |
605 | - if ( ! empty( $subscriptions ) && ! $showed_subscriptions_message ) { |
|
605 | + if ( ! empty($subscriptions) && ! $showed_subscriptions_message) { |
|
606 | 606 | |
607 | - foreach ( $subscriptions as $subscription ) { |
|
607 | + foreach ($subscriptions as $subscription) { |
|
608 | 608 | // Subscription expires timestamp. |
609 | - $subscription_expires = strtotime( $subscription['expires'] ); |
|
609 | + $subscription_expires = strtotime($subscription['expires']); |
|
610 | 610 | |
611 | 611 | // Start showing subscriptions message before one week of renewal date. |
612 | - if ( strtotime( '- 7 days', $subscription_expires ) > current_time( 'timestamp', 1 ) ) { |
|
612 | + if (strtotime('- 7 days', $subscription_expires) > current_time('timestamp', 1)) { |
|
613 | 613 | continue; |
614 | 614 | } |
615 | 615 | |
616 | 616 | // Check if subscription message already exist in messages. |
617 | - if ( array_key_exists( $subscription['id'], $messages ) ) { |
|
617 | + if (array_key_exists($subscription['id'], $messages)) { |
|
618 | 618 | continue; |
619 | 619 | } |
620 | 620 | |
621 | 621 | // Check if license already expired. |
622 | - if ( strtotime( $subscription['expires'] ) < current_time( 'timestamp', 1 ) ) { |
|
623 | - Give()->notices->register_notice( array( |
|
622 | + if (strtotime($subscription['expires']) < current_time('timestamp', 1)) { |
|
623 | + Give()->notices->register_notice(array( |
|
624 | 624 | 'id' => "give-expired-subscription-{$subscription['id']}", |
625 | 625 | 'type' => 'error', |
626 | 626 | 'description' => sprintf( |
627 | - __( 'Your Give add-on license expired for payment <a href="%1$s" target="_blank">#%2$d</a>. <a href="%3$s" target="_blank">Click to renew an existing license</a> or %4$s.', 'give' ), |
|
628 | - urldecode( $subscription['invoice_url'] ), |
|
627 | + __('Your Give add-on license expired for payment <a href="%1$s" target="_blank">#%2$d</a>. <a href="%3$s" target="_blank">Click to renew an existing license</a> or %4$s.', 'give'), |
|
628 | + urldecode($subscription['invoice_url']), |
|
629 | 629 | $subscription['payment_id'], |
630 | 630 | "{$this->checkout_url}?edd_license_key={$subscription['license_key']}&utm_campaign=admin&utm_source=licenses&utm_medium=expired", |
631 | - Give()->notices->get_dismiss_link( array( |
|
632 | - 'title' => __( 'Click here if already renewed', 'give' ), |
|
631 | + Give()->notices->get_dismiss_link(array( |
|
632 | + 'title' => __('Click here if already renewed', 'give'), |
|
633 | 633 | 'dismissible_type' => 'user', |
634 | 634 | 'dismiss_interval' => 'permanent', |
635 | - ) ) |
|
635 | + )) |
|
636 | 636 | ), |
637 | 637 | 'dismissible_type' => 'user', |
638 | 638 | 'dismiss_interval' => 'shortly', |
639 | - ) ); |
|
639 | + )); |
|
640 | 640 | } else { |
641 | - Give()->notices->register_notice( array( |
|
641 | + Give()->notices->register_notice(array( |
|
642 | 642 | 'id' => "give-expires-subscription-{$subscription['id']}", |
643 | 643 | 'type' => 'error', |
644 | 644 | 'description' => sprintf( |
645 | - __( 'Your Give add-on license will expire in %1$s for payment <a href="%2$s" target="_blank">#%3$d</a>. <a href="%4$s" target="_blank">Click to renew an existing license</a> or %5$s.', 'give' ), |
|
646 | - human_time_diff( current_time( 'timestamp', 1 ), strtotime( $subscription['expires'] ) ), |
|
647 | - urldecode( $subscription['invoice_url'] ), |
|
645 | + __('Your Give add-on license will expire in %1$s for payment <a href="%2$s" target="_blank">#%3$d</a>. <a href="%4$s" target="_blank">Click to renew an existing license</a> or %5$s.', 'give'), |
|
646 | + human_time_diff(current_time('timestamp', 1), strtotime($subscription['expires'])), |
|
647 | + urldecode($subscription['invoice_url']), |
|
648 | 648 | $subscription['payment_id'], |
649 | 649 | "{$this->checkout_url}?edd_license_key={$subscription['license_key']}&utm_campaign=admin&utm_source=licenses&utm_medium=expired", |
650 | - Give()->notices->get_dismiss_link( array( |
|
651 | - 'title' => __( 'Click here if already renewed', 'give' ), |
|
650 | + Give()->notices->get_dismiss_link(array( |
|
651 | + 'title' => __('Click here if already renewed', 'give'), |
|
652 | 652 | 'dismissible_type' => 'user', |
653 | 653 | 'dismiss_interval' => 'permanent', |
654 | - ) ) |
|
654 | + )) |
|
655 | 655 | ), |
656 | 656 | 'dismissible_type' => 'user', |
657 | 657 | 'dismiss_interval' => 'shortly', |
658 | - ) ); |
|
658 | + )); |
|
659 | 659 | } |
660 | 660 | |
661 | 661 | // Stop validation for these license keys. |
662 | - $addon_license_key_in_subscriptions = array_merge( $addon_license_key_in_subscriptions, $subscription['licenses'] ); |
|
662 | + $addon_license_key_in_subscriptions = array_merge($addon_license_key_in_subscriptions, $subscription['licenses']); |
|
663 | 663 | }// End foreach(). |
664 | 664 | $showed_subscriptions_message = true; |
665 | 665 | }// End if(). |
666 | 666 | |
667 | 667 | // Show Non Subscription Give Add-on messages. |
668 | 668 | if ( |
669 | - ! in_array( $this->license, $addon_license_key_in_subscriptions ) |
|
670 | - && ! empty( $this->license ) |
|
671 | - && empty( $showed_invalid_message ) |
|
669 | + ! in_array($this->license, $addon_license_key_in_subscriptions) |
|
670 | + && ! empty($this->license) |
|
671 | + && empty($showed_invalid_message) |
|
672 | 672 | && ! $this->is_valid_license() |
673 | 673 | ) { |
674 | 674 | |
675 | - Give()->notices->register_notice( array( |
|
675 | + Give()->notices->register_notice(array( |
|
676 | 676 | 'id' => 'give-invalid-license', |
677 | 677 | 'type' => 'error', |
678 | 678 | 'description' => sprintf( |
679 | - __( 'You have invalid or expired license keys for one or more Give Add-ons. Please go to the <a href="%s">licenses page</a> to correct this issue.', 'give' ), |
|
680 | - admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=licenses' ) |
|
679 | + __('You have invalid or expired license keys for one or more Give Add-ons. Please go to the <a href="%s">licenses page</a> to correct this issue.', 'give'), |
|
680 | + admin_url('edit.php?post_type=give_forms&page=give-settings&tab=licenses') |
|
681 | 681 | ), |
682 | 682 | 'dismissible_type' => 'user', |
683 | 683 | 'dismiss_interval' => 'shortly', |
684 | - ) ); |
|
684 | + )); |
|
685 | 685 | |
686 | 686 | $showed_invalid_message = true; |
687 | 687 | |
@@ -698,10 +698,10 @@ discard block |
||
698 | 698 | * |
699 | 699 | * @return bool |
700 | 700 | */ |
701 | - public function is_valid_license( $licence_data = null ) { |
|
702 | - $license_data = empty( $licence_data ) ? $this->license_data : $licence_data; |
|
701 | + public function is_valid_license($licence_data = null) { |
|
702 | + $license_data = empty($licence_data) ? $this->license_data : $licence_data; |
|
703 | 703 | |
704 | - if ( apply_filters( 'give_is_valid_license', ( $this->is_license( $license_data ) && 'valid' === $license_data->license ) ) ) { |
|
704 | + if (apply_filters('give_is_valid_license', ($this->is_license($license_data) && 'valid' === $license_data->license))) { |
|
705 | 705 | return true; |
706 | 706 | } |
707 | 707 | |
@@ -719,10 +719,10 @@ discard block |
||
719 | 719 | * |
720 | 720 | * @return bool |
721 | 721 | */ |
722 | - public function is_license( $licence_data = null ) { |
|
723 | - $license_data = empty( $licence_data ) ? $this->license_data : $licence_data; |
|
722 | + public function is_license($licence_data = null) { |
|
723 | + $license_data = empty($licence_data) ? $this->license_data : $licence_data; |
|
724 | 724 | |
725 | - if ( apply_filters( 'give_is_license', ( is_object( $license_data ) && ! empty( $license_data ) && property_exists( $license_data, 'license' ) ) ) ) { |
|
725 | + if (apply_filters('give_is_license', (is_object($license_data) && ! empty($license_data) && property_exists($license_data, 'license')))) { |
|
726 | 726 | return true; |
727 | 727 | } |
728 | 728 | |
@@ -738,7 +738,7 @@ discard block |
||
738 | 738 | * @return bool |
739 | 739 | */ |
740 | 740 | private function __is_third_party_addon() { |
741 | - return ( false === strpos( $this->api_url, 'givewp.com/' ) ); |
|
741 | + return (false === strpos($this->api_url, 'givewp.com/')); |
|
742 | 742 | } |
743 | 743 | |
744 | 744 | /** |
@@ -753,25 +753,25 @@ discard block |
||
753 | 753 | * @return bool |
754 | 754 | */ |
755 | 755 | private function __remove_license_key_from_subscriptions() { |
756 | - $subscriptions = get_option( 'give_subscriptions', array() ); |
|
756 | + $subscriptions = get_option('give_subscriptions', array()); |
|
757 | 757 | |
758 | 758 | // Bailout. |
759 | - if ( empty( $this->license ) ) { |
|
759 | + if (empty($this->license)) { |
|
760 | 760 | return false; |
761 | 761 | } |
762 | 762 | |
763 | - if ( ! empty( $subscriptions ) ) { |
|
764 | - foreach ( $subscriptions as $subscription_id => $subscription ) { |
|
765 | - $license_index = array_search( $this->license, $subscription['licenses'] ); |
|
766 | - if ( false !== $license_index ) { |
|
763 | + if ( ! empty($subscriptions)) { |
|
764 | + foreach ($subscriptions as $subscription_id => $subscription) { |
|
765 | + $license_index = array_search($this->license, $subscription['licenses']); |
|
766 | + if (false !== $license_index) { |
|
767 | 767 | // Remove license key. |
768 | - unset( $subscriptions[ $subscription_id ]['licenses'][ $license_index ] ); |
|
768 | + unset($subscriptions[$subscription_id]['licenses'][$license_index]); |
|
769 | 769 | |
770 | 770 | // Rearrange license keys. |
771 | - $subscriptions[ $subscription_id ]['licenses'] = array_values( $subscriptions[ $subscription_id ]['licenses'] ); |
|
771 | + $subscriptions[$subscription_id]['licenses'] = array_values($subscriptions[$subscription_id]['licenses']); |
|
772 | 772 | |
773 | 773 | // Update subscription information. |
774 | - update_option( 'give_subscriptions', $subscriptions ); |
|
774 | + update_option('give_subscriptions', $subscriptions); |
|
775 | 775 | break; |
776 | 776 | } |
777 | 777 | } |
@@ -785,17 +785,17 @@ discard block |
||
785 | 785 | * |
786 | 786 | * @return bool |
787 | 787 | */ |
788 | - public function plugin_page_notices( $plugin_file, $plugin_data, $status ) { |
|
788 | + public function plugin_page_notices($plugin_file, $plugin_data, $status) { |
|
789 | 789 | // Bailout. |
790 | - if ( $this->is_valid_license() ) { |
|
790 | + if ($this->is_valid_license()) { |
|
791 | 791 | return false; |
792 | 792 | } |
793 | 793 | |
794 | 794 | $update_notice_wrap = '<tr class="give-addon-notice-tr active"><td colspan="3" class="colspanchange"><div class="notice inline notice-warning notice-alt give-invalid-license"><p><span class="dashicons dashicons-info"></span> %s</p></div></td></tr>'; |
795 | 795 | $message = $this->license_state_message(); |
796 | 796 | |
797 | - if ( ! empty( $message['message'] ) ) { |
|
798 | - echo sprintf( $update_notice_wrap, $message['message'] ); |
|
797 | + if ( ! empty($message['message'])) { |
|
798 | + echo sprintf($update_notice_wrap, $message['message']); |
|
799 | 799 | } |
800 | 800 | } |
801 | 801 | |
@@ -810,11 +810,11 @@ discard block |
||
810 | 810 | public function license_state_message() { |
811 | 811 | $message_data = array(); |
812 | 812 | |
813 | - if ( ! $this->is_valid_license() ) { |
|
813 | + if ( ! $this->is_valid_license()) { |
|
814 | 814 | |
815 | 815 | $message_data['message'] = sprintf( |
816 | 816 | 'Please <a href="%1$s">activate your license</a> to receive updates and support for the %2$s add-on.', |
817 | - esc_url( admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=licenses' ) ), |
|
817 | + esc_url(admin_url('edit.php?post_type=give_forms&page=give-settings&tab=licenses')), |
|
818 | 818 | $this->item_name |
819 | 819 | ); |
820 | 820 | } |
@@ -833,7 +833,7 @@ discard block |
||
833 | 833 | // Bailout. |
834 | 834 | if ( |
835 | 835 | ! Give_Admin_Settings::verify_nonce() || |
836 | - ! current_user_can( 'manage_give_settings' ) || |
|
836 | + ! current_user_can('manage_give_settings') || |
|
837 | 837 | 'licenses' !== give_get_current_setting_tab() |
838 | 838 | ) { |
839 | 839 | return false; |
@@ -841,10 +841,10 @@ discard block |
||
841 | 841 | |
842 | 842 | // Security check. |
843 | 843 | if ( |
844 | - isset( $_POST[ $this->item_shortname . '_license_key-nonce' ] ) && |
|
845 | - ! wp_verify_nonce( $_REQUEST[ $this->item_shortname . '_license_key-nonce' ], $this->item_shortname . '_license_key-nonce' ) |
|
844 | + isset($_POST[$this->item_shortname.'_license_key-nonce']) && |
|
845 | + ! wp_verify_nonce($_REQUEST[$this->item_shortname.'_license_key-nonce'], $this->item_shortname.'_license_key-nonce') |
|
846 | 846 | ) { |
847 | - wp_die( __( 'Nonce verification failed.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
847 | + wp_die(__('Nonce verification failed.', 'give'), __('Error', 'give'), array('response' => 403)); |
|
848 | 848 | } |
849 | 849 | |
850 | 850 | return true; |
@@ -862,8 +862,8 @@ discard block |
||
862 | 862 | * |
863 | 863 | * @return mixed |
864 | 864 | */ |
865 | - public function get_license_info( $edd_action = '', $response_in_array = false ) { |
|
866 | - if ( empty( $edd_action ) ) { |
|
865 | + public function get_license_info($edd_action = '', $response_in_array = false) { |
|
866 | + if (empty($edd_action)) { |
|
867 | 867 | return false; |
868 | 868 | } |
869 | 869 | |
@@ -871,7 +871,7 @@ discard block |
||
871 | 871 | $api_params = array( |
872 | 872 | 'edd_action' => $edd_action, // never change from "edd_" to "give_"! |
873 | 873 | 'license' => $this->license, |
874 | - 'item_name' => urlencode( $this->item_name ), |
|
874 | + 'item_name' => urlencode($this->item_name), |
|
875 | 875 | 'url' => home_url(), |
876 | 876 | ); |
877 | 877 | |
@@ -886,11 +886,11 @@ discard block |
||
886 | 886 | ); |
887 | 887 | |
888 | 888 | // Make sure there are no errors. |
889 | - if ( is_wp_error( $response ) ) { |
|
889 | + if (is_wp_error($response)) { |
|
890 | 890 | return false; |
891 | 891 | } |
892 | 892 | |
893 | - return json_decode( wp_remote_retrieve_body( $response ), $response_in_array ); |
|
893 | + return json_decode(wp_remote_retrieve_body($response), $response_in_array); |
|
894 | 894 | } |
895 | 895 | |
896 | 896 | |
@@ -905,8 +905,8 @@ discard block |
||
905 | 905 | $this->__remove_license_key_from_subscriptions(); |
906 | 906 | |
907 | 907 | // Remove license from database. |
908 | - delete_option( "{$this->item_shortname}_license_active" ); |
|
909 | - give_delete_option( "{$this->item_shortname}_license_key" ); |
|
908 | + delete_option("{$this->item_shortname}_license_active"); |
|
909 | + give_delete_option("{$this->item_shortname}_license_key"); |
|
910 | 910 | |
911 | 911 | // Unset license param. |
912 | 912 | $this->license = ''; |
@@ -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,21 +97,20 @@ 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 ), |
|
114 | - 'post_data' => give_clean( $_POST ), |
|
111 | + 'date' => date('Y-m-d H:i:s', current_time('timestamp')), |
|
112 | + 'user_info' => stripslashes_deep($user_info), |
|
113 | + 'post_data' => give_clean($_POST), |
|
115 | 114 | 'gateway' => $valid_data['gateway'], |
116 | 115 | 'card_info' => $valid_data['cc_info'], |
117 | 116 | ); |
@@ -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', give_clean( $_POST ), $user_info, $valid_data ); |
|
132 | + do_action('give_checkout_before_gateway', give_clean($_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 | 184 | $submitted_email = $valid_data['logged_in_user']['user_email']; |
186 | - $donor = new Give_Donor( get_current_user_id(), true ); |
|
185 | + $donor = 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 !== $donor->email |
191 | - && ( is_array( $donor->emails ) && ! in_array( $submitted_email, $donor->emails ) ) |
|
190 | + && (is_array($donor->emails) && ! in_array($submitted_email, $donor->emails)) |
|
192 | 191 | ) { |
193 | - $found_donor = new Give_Donor( $submitted_email ); |
|
192 | + $found_donor = new Give_Donor($submitted_email); |
|
194 | 193 | |
195 | - if ( $found_donor->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' ), $donor->email, $submitted_email ) ); |
|
194 | + if ($found_donor->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'), $donor->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,63 +262,63 @@ 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 = ! empty( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : ''; |
|
269 | + $form_id = ! empty($_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 | // Check spam detect. |
290 | - if ( isset( $_POST['action'] ) |
|
291 | - && give_is_setting_enabled( give_get_option( 'akismet_spam_protection' ) ) |
|
289 | + if (isset($_POST['action']) |
|
290 | + && give_is_setting_enabled(give_get_option('akismet_spam_protection')) |
|
292 | 291 | && give_is_spam_donation() |
293 | 292 | ) { |
294 | - give_set_error( 'invalid_donation', __( 'This donation has been flagged as spam. Please try again.', 'give' ) ); |
|
293 | + give_set_error('invalid_donation', __('This donation has been flagged as spam. Please try again.', 'give')); |
|
295 | 294 | } |
296 | 295 | |
297 | 296 | // Validate agree to terms. |
298 | - if ( give_is_terms_enabled( $form_id ) ) { |
|
297 | + if (give_is_terms_enabled($form_id)) { |
|
299 | 298 | give_donation_form_validate_agree_to_terms(); |
300 | 299 | } |
301 | 300 | |
302 | 301 | // Stop processing donor registration, if donor registration is optional and donor can do guest checkout. |
303 | 302 | // If registration form username field is empty that means donor do not want to registration instead want guest checkout. |
304 | 303 | if ( |
305 | - ! give_logged_in_only( $form_id ) |
|
306 | - && isset( $_POST['give-purchase-var'] ) |
|
304 | + ! give_logged_in_only($form_id) |
|
305 | + && isset($_POST['give-purchase-var']) |
|
307 | 306 | && $_POST['give-purchase-var'] == 'needs-to-register' |
308 | - && empty( $_POST['give_user_login'] ) |
|
307 | + && empty($_POST['give_user_login']) |
|
309 | 308 | ) { |
310 | - unset( $_POST['give-purchase-var'] ); |
|
309 | + unset($_POST['give-purchase-var']); |
|
311 | 310 | } |
312 | 311 | |
313 | - if ( is_user_logged_in() ) { |
|
312 | + if (is_user_logged_in()) { |
|
314 | 313 | // Collect logged in user data. |
315 | 314 | $valid_data['logged_in_user'] = give_donation_form_validate_logged_in_user(); |
316 | - } elseif ( isset( $_POST['give-purchase-var'] ) && $_POST['give-purchase-var'] == 'needs-to-register' ) { |
|
315 | + } elseif (isset($_POST['give-purchase-var']) && $_POST['give-purchase-var'] == 'needs-to-register') { |
|
317 | 316 | // Set new user registration as required. |
318 | 317 | $valid_data['need_new_user'] = true; |
319 | 318 | // Validate new user data. |
320 | 319 | $valid_data['new_user_data'] = give_donation_form_validate_new_user(); |
321 | 320 | // Check if login validation is needed. |
322 | - } elseif ( isset( $_POST['give-purchase-var'] ) && $_POST['give-purchase-var'] == 'needs-to-login' ) { |
|
321 | + } elseif (isset($_POST['give-purchase-var']) && $_POST['give-purchase-var'] == 'needs-to-login') { |
|
323 | 322 | // Set user login as required. |
324 | 323 | $valid_data['need_user_login'] = true; |
325 | 324 | // Validate users login info. |
@@ -343,14 +342,14 @@ discard block |
||
343 | 342 | function give_is_spam_donation() { |
344 | 343 | $spam = false; |
345 | 344 | |
346 | - $user_agent = (string) isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : ''; |
|
345 | + $user_agent = (string) isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; |
|
347 | 346 | |
348 | - if ( strlen( $user_agent ) < 2 ) { |
|
347 | + if (strlen($user_agent) < 2) { |
|
349 | 348 | $spam = true; |
350 | 349 | } |
351 | 350 | |
352 | 351 | // Allow developer to customized Akismet spam detect API call and it's response. |
353 | - return apply_filters( 'give_spam', $spam ); |
|
352 | + return apply_filters('give_spam', $spam); |
|
354 | 353 | } |
355 | 354 | |
356 | 355 | /** |
@@ -364,41 +363,41 @@ discard block |
||
364 | 363 | */ |
365 | 364 | function give_donation_form_validate_gateway() { |
366 | 365 | |
367 | - $form_id = isset( $_REQUEST['give-form-id'] ) ? $_REQUEST['give-form-id'] : 0; |
|
368 | - $amount = isset( $_REQUEST['give-amount'] ) ? give_maybe_sanitize_amount( $_REQUEST['give-amount'] ) : 0; |
|
369 | - $gateway = give_get_default_gateway( $form_id ); |
|
366 | + $form_id = isset($_REQUEST['give-form-id']) ? $_REQUEST['give-form-id'] : 0; |
|
367 | + $amount = isset($_REQUEST['give-amount']) ? give_maybe_sanitize_amount($_REQUEST['give-amount']) : 0; |
|
368 | + $gateway = give_get_default_gateway($form_id); |
|
370 | 369 | |
371 | 370 | // Check if a gateway value is present. |
372 | - if ( ! empty( $_REQUEST['give-gateway'] ) ) { |
|
371 | + if ( ! empty($_REQUEST['give-gateway'])) { |
|
373 | 372 | |
374 | - $gateway = sanitize_text_field( $_REQUEST['give-gateway'] ); |
|
373 | + $gateway = sanitize_text_field($_REQUEST['give-gateway']); |
|
375 | 374 | |
376 | 375 | // Is amount being donated in LIVE mode 0.00? If so, error: |
377 | - if ( $amount == 0 && ! give_is_test_mode() ) { |
|
376 | + if ($amount == 0 && ! give_is_test_mode()) { |
|
378 | 377 | |
379 | - give_set_error( 'invalid_donation_amount', __( 'Please insert a valid donation amount.', 'give' ) ); |
|
378 | + give_set_error('invalid_donation_amount', __('Please insert a valid donation amount.', 'give')); |
|
380 | 379 | |
381 | 380 | } // End if(). |
382 | - elseif ( ! give_verify_minimum_price() ) { |
|
381 | + elseif ( ! give_verify_minimum_price()) { |
|
383 | 382 | // translators: %s: minimum donation amount. |
384 | 383 | give_set_error( |
385 | 384 | 'invalid_donation_minimum', |
386 | 385 | sprintf( |
387 | 386 | /* translators: %s: minimum donation amount */ |
388 | - __( 'This form has a minimum donation amount of %s.', 'give' ), |
|
389 | - give_currency_filter( give_format_amount( give_get_form_minimum_price( $form_id ), array( 'sanitize' => false ) ) ) |
|
387 | + __('This form has a minimum donation amount of %s.', 'give'), |
|
388 | + give_currency_filter(give_format_amount(give_get_form_minimum_price($form_id), array('sanitize' => false))) |
|
390 | 389 | ) |
391 | 390 | ); |
392 | 391 | |
393 | 392 | } //Is this test mode zero donation? Let it through but set to manual gateway. |
394 | - elseif ( $amount == 0 && give_is_test_mode() ) { |
|
393 | + elseif ($amount == 0 && give_is_test_mode()) { |
|
395 | 394 | |
396 | 395 | $gateway = 'manual'; |
397 | 396 | |
398 | 397 | } //Check if this gateway is active. |
399 | - elseif ( ! give_is_gateway_active( $gateway ) ) { |
|
398 | + elseif ( ! give_is_gateway_active($gateway)) { |
|
400 | 399 | |
401 | - give_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled.', 'give' ) ); |
|
400 | + give_set_error('invalid_gateway', __('The selected payment gateway is not enabled.', 'give')); |
|
402 | 401 | |
403 | 402 | } |
404 | 403 | } |
@@ -416,21 +415,21 @@ discard block |
||
416 | 415 | */ |
417 | 416 | function give_verify_minimum_price() { |
418 | 417 | |
419 | - $amount = give_maybe_sanitize_amount( $_REQUEST['give-amount'] ); |
|
420 | - $form_id = isset( $_REQUEST['give-form-id'] ) ? $_REQUEST['give-form-id'] : 0; |
|
421 | - $price_id = isset( $_REQUEST['give-price-id'] ) ? $_REQUEST['give-price-id'] : null; |
|
422 | - $variable_prices = give_has_variable_prices( $form_id ); |
|
418 | + $amount = give_maybe_sanitize_amount($_REQUEST['give-amount']); |
|
419 | + $form_id = isset($_REQUEST['give-form-id']) ? $_REQUEST['give-form-id'] : 0; |
|
420 | + $price_id = isset($_REQUEST['give-price-id']) ? $_REQUEST['give-price-id'] : null; |
|
421 | + $variable_prices = give_has_variable_prices($form_id); |
|
423 | 422 | |
424 | - if ( $variable_prices && in_array( $price_id, give_get_variable_price_ids( $form_id ) ) ) { |
|
423 | + if ($variable_prices && in_array($price_id, give_get_variable_price_ids($form_id))) { |
|
425 | 424 | |
426 | - $price_level_amount = give_get_price_option_amount( $form_id, $price_id ); |
|
425 | + $price_level_amount = give_get_price_option_amount($form_id, $price_id); |
|
427 | 426 | |
428 | - if ( $price_level_amount == $amount ) { |
|
427 | + if ($price_level_amount == $amount) { |
|
429 | 428 | return true; |
430 | 429 | } |
431 | 430 | } |
432 | 431 | |
433 | - if ( give_get_form_minimum_price( $form_id ) > $amount ) { |
|
432 | + if (give_get_form_minimum_price($form_id) > $amount) { |
|
434 | 433 | return false; |
435 | 434 | } |
436 | 435 | |
@@ -446,9 +445,9 @@ discard block |
||
446 | 445 | */ |
447 | 446 | function give_donation_form_validate_agree_to_terms() { |
448 | 447 | // Validate agree to terms. |
449 | - if ( ! isset( $_POST['give_agree_to_terms'] ) || $_POST['give_agree_to_terms'] != 1 ) { |
|
448 | + if ( ! isset($_POST['give_agree_to_terms']) || $_POST['give_agree_to_terms'] != 1) { |
|
450 | 449 | // User did not agree. |
451 | - give_set_error( 'agree_to_terms', apply_filters( 'give_agree_to_terms_text', __( 'You must agree to the terms and conditions.', 'give' ) ) ); |
|
450 | + give_set_error('agree_to_terms', apply_filters('give_agree_to_terms_text', __('You must agree to the terms and conditions.', 'give'))); |
|
452 | 451 | } |
453 | 452 | } |
454 | 453 | |
@@ -462,59 +461,59 @@ discard block |
||
462 | 461 | * |
463 | 462 | * @return array |
464 | 463 | */ |
465 | -function give_get_required_fields( $form_id ) { |
|
464 | +function give_get_required_fields($form_id) { |
|
466 | 465 | |
467 | - $payment_mode = give_get_chosen_gateway( $form_id ); |
|
466 | + $payment_mode = give_get_chosen_gateway($form_id); |
|
468 | 467 | |
469 | 468 | $required_fields = array( |
470 | 469 | 'give_email' => array( |
471 | 470 | 'error_id' => 'invalid_email', |
472 | - 'error_message' => __( 'Please enter a valid email address.', 'give' ), |
|
471 | + 'error_message' => __('Please enter a valid email address.', 'give'), |
|
473 | 472 | ), |
474 | 473 | 'give_first' => array( |
475 | 474 | 'error_id' => 'invalid_first_name', |
476 | - 'error_message' => __( 'Please enter your first name.', 'give' ), |
|
475 | + 'error_message' => __('Please enter your first name.', 'give'), |
|
477 | 476 | ), |
478 | 477 | ); |
479 | 478 | |
480 | - $require_address = give_require_billing_address( $payment_mode ); |
|
479 | + $require_address = give_require_billing_address($payment_mode); |
|
481 | 480 | |
482 | - if ( $require_address ) { |
|
483 | - $required_fields['card_address'] = array( |
|
481 | + if ($require_address) { |
|
482 | + $required_fields['card_address'] = array( |
|
484 | 483 | 'error_id' => 'invalid_card_address', |
485 | - 'error_message' => __( 'Please enter your primary billing address.', 'give' ), |
|
484 | + 'error_message' => __('Please enter your primary billing address.', 'give'), |
|
486 | 485 | ); |
487 | - $required_fields['card_zip'] = array( |
|
486 | + $required_fields['card_zip'] = array( |
|
488 | 487 | 'error_id' => 'invalid_zip_code', |
489 | - 'error_message' => __( 'Please enter your zip / postal code.', 'give' ), |
|
488 | + 'error_message' => __('Please enter your zip / postal code.', 'give'), |
|
490 | 489 | ); |
491 | - $required_fields['card_city'] = array( |
|
490 | + $required_fields['card_city'] = array( |
|
492 | 491 | 'error_id' => 'invalid_city', |
493 | - 'error_message' => __( 'Please enter your billing city.', 'give' ), |
|
492 | + 'error_message' => __('Please enter your billing city.', 'give'), |
|
494 | 493 | ); |
495 | 494 | $required_fields['billing_country'] = array( |
496 | 495 | 'error_id' => 'invalid_country', |
497 | - 'error_message' => __( 'Please select your billing country.', 'give' ), |
|
496 | + 'error_message' => __('Please select your billing country.', 'give'), |
|
498 | 497 | ); |
499 | 498 | |
500 | 499 | |
501 | 500 | $required_fields['card_state'] = array( |
502 | 501 | 'error_id' => 'invalid_state', |
503 | - 'error_message' => __( 'Please enter billing state / province / County.', 'give' ), |
|
502 | + 'error_message' => __('Please enter billing state / province / County.', 'give'), |
|
504 | 503 | ); |
505 | 504 | |
506 | 505 | // Check if billing country alredy exists. |
507 | - if ( ! empty( $_POST['billing_country'] ) ) { |
|
506 | + if ( ! empty($_POST['billing_country'])) { |
|
508 | 507 | // Get the value from $_POST. |
509 | - $country = sanitize_text_field( $_POST['billing_country'] ); |
|
508 | + $country = sanitize_text_field($_POST['billing_country']); |
|
510 | 509 | |
511 | 510 | // Get the country list that does not required any states init. |
512 | 511 | $states_country = give_states_not_required_country_list(); |
513 | 512 | |
514 | 513 | // Check if states is empty or not. |
515 | - if ( array_key_exists( $country, $states_country ) ) { |
|
514 | + if (array_key_exists($country, $states_country)) { |
|
516 | 515 | // If states is empty remove the required feilds of state in billing cart. |
517 | - unset( $required_fields['card_state'] ); |
|
516 | + unset($required_fields['card_state']); |
|
518 | 517 | } |
519 | 518 | } |
520 | 519 | } |
@@ -524,7 +523,7 @@ discard block |
||
524 | 523 | * |
525 | 524 | * @since 1.7 |
526 | 525 | */ |
527 | - $required_fields = apply_filters( 'give_donation_form_required_fields', $required_fields, $form_id ); |
|
526 | + $required_fields = apply_filters('give_donation_form_required_fields', $required_fields, $form_id); |
|
528 | 527 | |
529 | 528 | return $required_fields; |
530 | 529 | |
@@ -539,16 +538,16 @@ discard block |
||
539 | 538 | * |
540 | 539 | * @return bool |
541 | 540 | */ |
542 | -function give_require_billing_address( $payment_mode ) { |
|
541 | +function give_require_billing_address($payment_mode) { |
|
543 | 542 | |
544 | 543 | $return = false; |
545 | 544 | |
546 | - if ( isset( $_POST['billing_country'] ) || did_action( "give_{$payment_mode}_cc_form" ) || did_action( 'give_cc_form' ) ) { |
|
545 | + if (isset($_POST['billing_country']) || did_action("give_{$payment_mode}_cc_form") || did_action('give_cc_form')) { |
|
547 | 546 | $return = true; |
548 | 547 | } |
549 | 548 | |
550 | 549 | // Let payment gateways and other extensions determine if address fields should be required. |
551 | - return apply_filters( 'give_require_billing_address', $return ); |
|
550 | + return apply_filters('give_require_billing_address', $return); |
|
552 | 551 | |
553 | 552 | } |
554 | 553 | |
@@ -562,42 +561,42 @@ discard block |
||
562 | 561 | function give_donation_form_validate_logged_in_user() { |
563 | 562 | global $user_ID; |
564 | 563 | |
565 | - $form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : ''; |
|
564 | + $form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : ''; |
|
566 | 565 | |
567 | 566 | // Start empty array to collect valid user data. |
568 | 567 | $valid_user_data = array( |
569 | 568 | // Assume there will be errors. |
570 | - 'user_id' => - 1, |
|
569 | + 'user_id' => -1, |
|
571 | 570 | ); |
572 | 571 | |
573 | 572 | // Verify there is a user_ID. |
574 | - if ( $user_ID > 0 ) { |
|
573 | + if ($user_ID > 0) { |
|
575 | 574 | // Get the logged in user data. |
576 | - $user_data = get_userdata( $user_ID ); |
|
575 | + $user_data = get_userdata($user_ID); |
|
577 | 576 | |
578 | 577 | // Loop through required fields and show error messages. |
579 | - foreach ( give_get_required_fields( $form_id ) as $field_name => $value ) { |
|
580 | - if ( in_array( $value, give_get_required_fields( $form_id ) ) && empty( $_POST[ $field_name ] ) ) { |
|
581 | - give_set_error( $value['error_id'], $value['error_message'] ); |
|
578 | + foreach (give_get_required_fields($form_id) as $field_name => $value) { |
|
579 | + if (in_array($value, give_get_required_fields($form_id)) && empty($_POST[$field_name])) { |
|
580 | + give_set_error($value['error_id'], $value['error_message']); |
|
582 | 581 | } |
583 | 582 | } |
584 | 583 | |
585 | 584 | // Verify data. |
586 | - if ( $user_data ) { |
|
585 | + if ($user_data) { |
|
587 | 586 | // Collected logged in user data. |
588 | 587 | $valid_user_data = array( |
589 | 588 | 'user_id' => $user_ID, |
590 | - 'user_email' => isset( $_POST['give_email'] ) ? sanitize_email( $_POST['give_email'] ) : $user_data->user_email, |
|
591 | - 'user_first' => isset( $_POST['give_first'] ) && ! empty( $_POST['give_first'] ) ? sanitize_text_field( $_POST['give_first'] ) : $user_data->first_name, |
|
592 | - 'user_last' => isset( $_POST['give_last'] ) && ! empty( $_POST['give_last'] ) ? sanitize_text_field( $_POST['give_last'] ) : $user_data->last_name, |
|
589 | + 'user_email' => isset($_POST['give_email']) ? sanitize_email($_POST['give_email']) : $user_data->user_email, |
|
590 | + 'user_first' => isset($_POST['give_first']) && ! empty($_POST['give_first']) ? sanitize_text_field($_POST['give_first']) : $user_data->first_name, |
|
591 | + 'user_last' => isset($_POST['give_last']) && ! empty($_POST['give_last']) ? sanitize_text_field($_POST['give_last']) : $user_data->last_name, |
|
593 | 592 | ); |
594 | 593 | |
595 | - if ( ! is_email( $valid_user_data['user_email'] ) ) { |
|
596 | - give_set_error( 'email_invalid', esc_html__( 'Invalid email.', 'give' ) ); |
|
594 | + if ( ! is_email($valid_user_data['user_email'])) { |
|
595 | + give_set_error('email_invalid', esc_html__('Invalid email.', 'give')); |
|
597 | 596 | } |
598 | 597 | } else { |
599 | 598 | // Set invalid user error. |
600 | - give_set_error( 'invalid_user', esc_html__( 'The user information is invalid.', 'give' ) ); |
|
599 | + give_set_error('invalid_user', esc_html__('The user information is invalid.', 'give')); |
|
601 | 600 | } |
602 | 601 | } |
603 | 602 | |
@@ -616,7 +615,7 @@ discard block |
||
616 | 615 | // Default user data. |
617 | 616 | $default_user_data = array( |
618 | 617 | 'give-form-id' => '', |
619 | - 'user_id' => - 1, // Assume there will be errors. |
|
618 | + 'user_id' => -1, // Assume there will be errors. |
|
620 | 619 | 'user_first' => '', |
621 | 620 | 'user_last' => '', |
622 | 621 | 'give_user_login' => false, |
@@ -626,14 +625,14 @@ discard block |
||
626 | 625 | ); |
627 | 626 | |
628 | 627 | // Get user data. |
629 | - $user_data = wp_parse_args( give_clean( $_POST ), $default_user_data ); |
|
628 | + $user_data = wp_parse_args(give_clean($_POST), $default_user_data); |
|
630 | 629 | $registering_new_user = false; |
631 | - $form_id = absint( $user_data['give-form-id'] ); |
|
630 | + $form_id = absint($user_data['give-form-id']); |
|
632 | 631 | |
633 | 632 | // Start an empty array to collect valid user data. |
634 | 633 | $valid_user_data = array( |
635 | 634 | // Assume there will be errors. |
636 | - 'user_id' => - 1, |
|
635 | + 'user_id' => -1, |
|
637 | 636 | |
638 | 637 | // Get first name. |
639 | 638 | 'user_first' => $user_data['give_first'], |
@@ -643,25 +642,25 @@ discard block |
||
643 | 642 | ); |
644 | 643 | |
645 | 644 | // Loop through required fields and show error messages. |
646 | - foreach ( give_get_required_fields( $form_id ) as $field_name => $value ) { |
|
647 | - if ( in_array( $value, give_get_required_fields( $form_id ) ) && empty( $_POST[ $field_name ] ) ) { |
|
648 | - give_set_error( $value['error_id'], $value['error_message'] ); |
|
645 | + foreach (give_get_required_fields($form_id) as $field_name => $value) { |
|
646 | + if (in_array($value, give_get_required_fields($form_id)) && empty($_POST[$field_name])) { |
|
647 | + give_set_error($value['error_id'], $value['error_message']); |
|
649 | 648 | } |
650 | 649 | } |
651 | 650 | |
652 | 651 | // Check if we have an username to register. |
653 | - if ( give_validate_username( $user_data['give_user_login'] ) ) { |
|
652 | + if (give_validate_username($user_data['give_user_login'])) { |
|
654 | 653 | $registering_new_user = true; |
655 | 654 | $valid_user_data['user_login'] = $user_data['give_user_login']; |
656 | 655 | } |
657 | 656 | |
658 | 657 | // Check if we have an email to verify. |
659 | - if ( give_validate_user_email( $user_data['give_email'], $registering_new_user ) ) { |
|
658 | + if (give_validate_user_email($user_data['give_email'], $registering_new_user)) { |
|
660 | 659 | $valid_user_data['user_email'] = $user_data['give_email']; |
661 | 660 | } |
662 | 661 | |
663 | 662 | // Check password. |
664 | - if ( give_validate_user_password( $user_data['give_user_pass'], $user_data['give_user_pass_confirm'], $registering_new_user ) ) { |
|
663 | + if (give_validate_user_password($user_data['give_user_pass'], $user_data['give_user_pass_confirm'], $registering_new_user)) { |
|
665 | 664 | // All is good to go. |
666 | 665 | $valid_user_data['user_pass'] = $user_data['give_user_pass']; |
667 | 666 | } |
@@ -681,36 +680,36 @@ discard block |
||
681 | 680 | // Start an array to collect valid user data. |
682 | 681 | $valid_user_data = array( |
683 | 682 | // Assume there will be errors. |
684 | - 'user_id' => - 1, |
|
683 | + 'user_id' => -1, |
|
685 | 684 | ); |
686 | 685 | |
687 | 686 | // Username. |
688 | - if ( ! isset( $_POST['give_user_login'] ) || $_POST['give_user_login'] == '' ) { |
|
689 | - give_set_error( 'must_log_in', __( 'You must register or login to complete your donation.', 'give' ) ); |
|
687 | + if ( ! isset($_POST['give_user_login']) || $_POST['give_user_login'] == '') { |
|
688 | + give_set_error('must_log_in', __('You must register or login to complete your donation.', 'give')); |
|
690 | 689 | |
691 | 690 | return $valid_user_data; |
692 | 691 | } |
693 | 692 | |
694 | 693 | // Get the user by login. |
695 | - $user_data = get_user_by( 'login', strip_tags( $_POST['give_user_login'] ) ); |
|
694 | + $user_data = get_user_by('login', strip_tags($_POST['give_user_login'])); |
|
696 | 695 | |
697 | 696 | // Check if user exists. |
698 | - if ( $user_data ) { |
|
697 | + if ($user_data) { |
|
699 | 698 | // Get password. |
700 | - $user_pass = isset( $_POST['give_user_pass'] ) ? $_POST['give_user_pass'] : false; |
|
699 | + $user_pass = isset($_POST['give_user_pass']) ? $_POST['give_user_pass'] : false; |
|
701 | 700 | |
702 | 701 | // Check user_pass. |
703 | - if ( $user_pass ) { |
|
702 | + if ($user_pass) { |
|
704 | 703 | // Check if password is valid. |
705 | - if ( ! wp_check_password( $user_pass, $user_data->user_pass, $user_data->ID ) ) { |
|
704 | + if ( ! wp_check_password($user_pass, $user_data->user_pass, $user_data->ID)) { |
|
706 | 705 | // Incorrect password. |
707 | 706 | give_set_error( |
708 | 707 | 'password_incorrect', |
709 | 708 | sprintf( |
710 | 709 | '%1$s <a href="%2$s">%3$s</a>', |
711 | - __( 'The password you entered is incorrect.', 'give' ), |
|
712 | - wp_lostpassword_url( "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]" ), |
|
713 | - __( 'Reset Password', 'give' ) |
|
710 | + __('The password you entered is incorrect.', 'give'), |
|
711 | + wp_lostpassword_url("http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"), |
|
712 | + __('Reset Password', 'give') |
|
714 | 713 | ) |
715 | 714 | ); |
716 | 715 | // All is correct. |
@@ -728,11 +727,11 @@ discard block |
||
728 | 727 | } |
729 | 728 | } else { |
730 | 729 | // Empty password. |
731 | - give_set_error( 'password_empty', __( 'Enter a password.', 'give' ) ); |
|
730 | + give_set_error('password_empty', __('Enter a password.', 'give')); |
|
732 | 731 | } |
733 | 732 | } else { |
734 | 733 | // No username. |
735 | - give_set_error( 'username_incorrect', __( 'The username you entered does not exist.', 'give' ) ); |
|
734 | + give_set_error('username_incorrect', __('The username you entered does not exist.', 'give')); |
|
736 | 735 | }// End if(). |
737 | 736 | |
738 | 737 | return $valid_user_data; |
@@ -747,7 +746,7 @@ discard block |
||
747 | 746 | */ |
748 | 747 | function give_donation_form_validate_guest_user() { |
749 | 748 | |
750 | - $form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : ''; |
|
749 | + $form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : ''; |
|
751 | 750 | |
752 | 751 | // Start an array to collect valid user data. |
753 | 752 | $valid_user_data = array( |
@@ -756,38 +755,38 @@ discard block |
||
756 | 755 | ); |
757 | 756 | |
758 | 757 | // Show error message if user must be logged in. |
759 | - if ( give_logged_in_only( $form_id ) ) { |
|
760 | - give_set_error( 'logged_in_only', __( 'You must be logged in to donate.', 'give' ) ); |
|
758 | + if (give_logged_in_only($form_id)) { |
|
759 | + give_set_error('logged_in_only', __('You must be logged in to donate.', 'give')); |
|
761 | 760 | } |
762 | 761 | |
763 | 762 | // Get the guest email. |
764 | - $guest_email = isset( $_POST['give_email'] ) ? $_POST['give_email'] : false; |
|
763 | + $guest_email = isset($_POST['give_email']) ? $_POST['give_email'] : false; |
|
765 | 764 | |
766 | 765 | // Check email. |
767 | - if ( $guest_email && strlen( $guest_email ) > 0 ) { |
|
766 | + if ($guest_email && strlen($guest_email) > 0) { |
|
768 | 767 | // Validate email. |
769 | - if ( ! is_email( $guest_email ) ) { |
|
768 | + if ( ! is_email($guest_email)) { |
|
770 | 769 | // Invalid email. |
771 | - give_set_error( 'email_invalid', __( 'Invalid email.', 'give' ) ); |
|
770 | + give_set_error('email_invalid', __('Invalid email.', 'give')); |
|
772 | 771 | } else { |
773 | 772 | // All is good to go. |
774 | 773 | $valid_user_data['user_email'] = $guest_email; |
775 | 774 | |
776 | 775 | // Get user_id from donor if exist. |
777 | - $donor = new Give_Donor( $guest_email ); |
|
778 | - if ( $donor->id && $donor->user_id ) { |
|
776 | + $donor = new Give_Donor($guest_email); |
|
777 | + if ($donor->id && $donor->user_id) { |
|
779 | 778 | $valid_user_data['user_id'] = $donor->user_id; |
780 | 779 | } |
781 | 780 | } |
782 | 781 | } else { |
783 | 782 | // No email. |
784 | - give_set_error( 'email_empty', __( 'Enter an email.', 'give' ) ); |
|
783 | + give_set_error('email_empty', __('Enter an email.', 'give')); |
|
785 | 784 | } |
786 | 785 | |
787 | 786 | // Loop through required fields and show error messages. |
788 | - foreach ( give_get_required_fields( $form_id ) as $field_name => $value ) { |
|
789 | - if ( in_array( $value, give_get_required_fields( $form_id ) ) && empty( $_POST[ $field_name ] ) ) { |
|
790 | - give_set_error( $value['error_id'], $value['error_message'] ); |
|
787 | + foreach (give_get_required_fields($form_id) as $field_name => $value) { |
|
788 | + if (in_array($value, give_get_required_fields($form_id)) && empty($_POST[$field_name])) { |
|
789 | + give_set_error($value['error_id'], $value['error_message']); |
|
791 | 790 | } |
792 | 791 | } |
793 | 792 | |
@@ -803,36 +802,36 @@ discard block |
||
803 | 802 | * @since 1.0 |
804 | 803 | * @return integer |
805 | 804 | */ |
806 | -function give_register_and_login_new_user( $user_data = array() ) { |
|
805 | +function give_register_and_login_new_user($user_data = array()) { |
|
807 | 806 | // Verify the array. |
808 | - if ( empty( $user_data ) ) { |
|
809 | - return - 1; |
|
807 | + if (empty($user_data)) { |
|
808 | + return -1; |
|
810 | 809 | } |
811 | 810 | |
812 | - if ( give_get_errors() ) { |
|
813 | - return - 1; |
|
811 | + if (give_get_errors()) { |
|
812 | + return -1; |
|
814 | 813 | } |
815 | 814 | |
816 | - $user_args = apply_filters( 'give_insert_user_args', array( |
|
817 | - 'user_login' => isset( $user_data['user_login'] ) ? $user_data['user_login'] : '', |
|
818 | - 'user_pass' => isset( $user_data['user_pass'] ) ? $user_data['user_pass'] : '', |
|
819 | - 'user_email' => isset( $user_data['user_email'] ) ? $user_data['user_email'] : '', |
|
820 | - 'first_name' => isset( $user_data['user_first'] ) ? $user_data['user_first'] : '', |
|
821 | - 'last_name' => isset( $user_data['user_last'] ) ? $user_data['user_last'] : '', |
|
822 | - 'user_registered' => date( 'Y-m-d H:i:s' ), |
|
823 | - 'role' => give_get_option( 'donor_default_user_role', 'give_donor' ), |
|
824 | - ), $user_data ); |
|
815 | + $user_args = apply_filters('give_insert_user_args', array( |
|
816 | + 'user_login' => isset($user_data['user_login']) ? $user_data['user_login'] : '', |
|
817 | + 'user_pass' => isset($user_data['user_pass']) ? $user_data['user_pass'] : '', |
|
818 | + 'user_email' => isset($user_data['user_email']) ? $user_data['user_email'] : '', |
|
819 | + 'first_name' => isset($user_data['user_first']) ? $user_data['user_first'] : '', |
|
820 | + 'last_name' => isset($user_data['user_last']) ? $user_data['user_last'] : '', |
|
821 | + 'user_registered' => date('Y-m-d H:i:s'), |
|
822 | + 'role' => give_get_option('donor_default_user_role', 'give_donor'), |
|
823 | + ), $user_data); |
|
825 | 824 | |
826 | 825 | // Insert new user. |
827 | - $user_id = wp_insert_user( $user_args ); |
|
826 | + $user_id = wp_insert_user($user_args); |
|
828 | 827 | |
829 | 828 | // Validate inserted user. |
830 | - if ( is_wp_error( $user_id ) ) { |
|
831 | - return - 1; |
|
829 | + if (is_wp_error($user_id)) { |
|
830 | + return -1; |
|
832 | 831 | } |
833 | 832 | |
834 | 833 | // Allow themes and plugins to filter the user data. |
835 | - $user_data = apply_filters( 'give_insert_user_data', $user_data, $user_args ); |
|
834 | + $user_data = apply_filters('give_insert_user_data', $user_data, $user_args); |
|
836 | 835 | |
837 | 836 | /** |
838 | 837 | * Fires after inserting user. |
@@ -842,7 +841,7 @@ discard block |
||
842 | 841 | * @param int $user_id User id. |
843 | 842 | * @param array $user_data Array containing user data. |
844 | 843 | */ |
845 | - do_action( 'give_insert_user', $user_id, $user_data ); |
|
844 | + do_action('give_insert_user', $user_id, $user_data); |
|
846 | 845 | |
847 | 846 | /** |
848 | 847 | * Filter allow user to alter if user when to login or not when user is register for the first time. |
@@ -851,9 +850,9 @@ discard block |
||
851 | 850 | * |
852 | 851 | * return bool True if login with registration and False if only want to register. |
853 | 852 | */ |
854 | - if ( true === (bool) apply_filters( 'give_log_user_in_on_register', true ) ) { |
|
853 | + if (true === (bool) apply_filters('give_log_user_in_on_register', true)) { |
|
855 | 854 | // Login new user. |
856 | - give_log_user_in( $user_id, $user_data['user_login'], $user_data['user_pass'] ); |
|
855 | + give_log_user_in($user_id, $user_data['user_login'], $user_data['user_pass']); |
|
857 | 856 | } |
858 | 857 | |
859 | 858 | // Return user id. |
@@ -869,27 +868,27 @@ discard block |
||
869 | 868 | * @since 1.0 |
870 | 869 | * @return array|bool |
871 | 870 | */ |
872 | -function give_get_donation_form_user( $valid_data = array() ) { |
|
871 | +function give_get_donation_form_user($valid_data = array()) { |
|
873 | 872 | |
874 | 873 | // Initialize user. |
875 | 874 | $user = false; |
876 | - $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
875 | + $is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
877 | 876 | |
878 | - if ( $is_ajax ) { |
|
877 | + if ($is_ajax) { |
|
879 | 878 | // Do not create or login the user during the ajax submission (check for errors only). |
880 | 879 | return true; |
881 | - } elseif ( is_user_logged_in() ) { |
|
880 | + } elseif (is_user_logged_in()) { |
|
882 | 881 | // Set the valid user as the logged in collected data. |
883 | 882 | $user = $valid_data['logged_in_user']; |
884 | - } elseif ( $valid_data['need_new_user'] === true || $valid_data['need_user_login'] === true ) { |
|
883 | + } elseif ($valid_data['need_new_user'] === true || $valid_data['need_user_login'] === true) { |
|
885 | 884 | // New user registration. |
886 | - if ( $valid_data['need_new_user'] === true ) { |
|
885 | + if ($valid_data['need_new_user'] === true) { |
|
887 | 886 | // Set user. |
888 | 887 | $user = $valid_data['new_user_data']; |
889 | 888 | // Register and login new user. |
890 | - $user['user_id'] = give_register_and_login_new_user( $user ); |
|
889 | + $user['user_id'] = give_register_and_login_new_user($user); |
|
891 | 890 | // User login |
892 | - } elseif ( $valid_data['need_user_login'] === true && ! $is_ajax ) { |
|
891 | + } elseif ($valid_data['need_user_login'] === true && ! $is_ajax) { |
|
893 | 892 | |
894 | 893 | /** |
895 | 894 | * The login form is now processed in the give_process_donation_login() function. |
@@ -901,48 +900,48 @@ discard block |
||
901 | 900 | // Set user. |
902 | 901 | $user = $valid_data['login_user_data']; |
903 | 902 | // Login user. |
904 | - give_log_user_in( $user['user_id'], $user['user_login'], $user['user_pass'] ); |
|
903 | + give_log_user_in($user['user_id'], $user['user_login'], $user['user_pass']); |
|
905 | 904 | } |
906 | 905 | } |
907 | 906 | |
908 | 907 | // Check guest checkout. |
909 | - if ( false === $user && false === give_logged_in_only( $_POST['give-form-id'] ) ) { |
|
908 | + if (false === $user && false === give_logged_in_only($_POST['give-form-id'])) { |
|
910 | 909 | // Set user |
911 | 910 | $user = $valid_data['guest_user_data']; |
912 | 911 | } |
913 | 912 | |
914 | 913 | // Verify we have an user. |
915 | - if ( false === $user || empty( $user ) ) { |
|
914 | + if (false === $user || empty($user)) { |
|
916 | 915 | // Return false. |
917 | 916 | return false; |
918 | 917 | } |
919 | 918 | |
920 | 919 | // Get user first name. |
921 | - if ( ! isset( $user['user_first'] ) || strlen( trim( $user['user_first'] ) ) < 1 ) { |
|
922 | - $user['user_first'] = isset( $_POST['give_first'] ) ? strip_tags( trim( $_POST['give_first'] ) ) : ''; |
|
920 | + if ( ! isset($user['user_first']) || strlen(trim($user['user_first'])) < 1) { |
|
921 | + $user['user_first'] = isset($_POST['give_first']) ? strip_tags(trim($_POST['give_first'])) : ''; |
|
923 | 922 | } |
924 | 923 | |
925 | 924 | // Get user last name. |
926 | - if ( ! isset( $user['user_last'] ) || strlen( trim( $user['user_last'] ) ) < 1 ) { |
|
927 | - $user['user_last'] = isset( $_POST['give_last'] ) ? strip_tags( trim( $_POST['give_last'] ) ) : ''; |
|
925 | + if ( ! isset($user['user_last']) || strlen(trim($user['user_last'])) < 1) { |
|
926 | + $user['user_last'] = isset($_POST['give_last']) ? strip_tags(trim($_POST['give_last'])) : ''; |
|
928 | 927 | } |
929 | 928 | |
930 | 929 | // Get the user's billing address details. |
931 | 930 | $user['address'] = array(); |
932 | - $user['address']['line1'] = ! empty( $_POST['card_address'] ) ? give_clean( $_POST['card_address'] ) : false; |
|
933 | - $user['address']['line2'] = ! empty( $_POST['card_address_2'] ) ? give_clean( $_POST['card_address_2'] ) : false; |
|
934 | - $user['address']['city'] = ! empty( $_POST['card_city'] ) ? give_clean( $_POST['card_city'] ) : false; |
|
935 | - $user['address']['state'] = ! empty( $_POST['card_state'] ) ? give_clean( $_POST['card_state'] ) : false; |
|
936 | - $user['address']['zip'] = ! empty( $_POST['card_zip'] ) ? give_clean( $_POST['card_zip'] ) : false; |
|
937 | - $user['address']['country'] = ! empty( $_POST['billing_country'] ) ? give_clean( $_POST['billing_country'] ) : false; |
|
938 | - |
|
939 | - if ( empty( $user['address']['country'] ) ) { |
|
931 | + $user['address']['line1'] = ! empty($_POST['card_address']) ? give_clean($_POST['card_address']) : false; |
|
932 | + $user['address']['line2'] = ! empty($_POST['card_address_2']) ? give_clean($_POST['card_address_2']) : false; |
|
933 | + $user['address']['city'] = ! empty($_POST['card_city']) ? give_clean($_POST['card_city']) : false; |
|
934 | + $user['address']['state'] = ! empty($_POST['card_state']) ? give_clean($_POST['card_state']) : false; |
|
935 | + $user['address']['zip'] = ! empty($_POST['card_zip']) ? give_clean($_POST['card_zip']) : false; |
|
936 | + $user['address']['country'] = ! empty($_POST['billing_country']) ? give_clean($_POST['billing_country']) : false; |
|
937 | + |
|
938 | + if (empty($user['address']['country'])) { |
|
940 | 939 | $user['address'] = false; |
941 | 940 | } // End if(). |
942 | 941 | |
943 | - if ( ! empty( $user['user_id'] ) && $user['user_id'] > 0 && ! empty( $user['address'] ) ) { |
|
942 | + if ( ! empty($user['user_id']) && $user['user_id'] > 0 && ! empty($user['address'])) { |
|
944 | 943 | // Store the address in the user's meta so the donation form can be pre-populated with it on return donation. |
945 | - update_user_meta( $user['user_id'], '_give_user_address', $user['address'] ); |
|
944 | + update_user_meta($user['user_id'], '_give_user_address', $user['address']); |
|
946 | 945 | } |
947 | 946 | |
948 | 947 | // Return valid user. |
@@ -961,16 +960,16 @@ discard block |
||
961 | 960 | $card_data = give_get_donation_cc_info(); |
962 | 961 | |
963 | 962 | // Validate the card zip. |
964 | - if ( ! empty( $card_data['card_zip'] ) ) { |
|
965 | - if ( ! give_donation_form_validate_cc_zip( $card_data['card_zip'], $card_data['card_country'] ) ) { |
|
966 | - give_set_error( 'invalid_cc_zip', __( 'The zip / postal code you entered for your billing address is invalid.', 'give' ) ); |
|
963 | + if ( ! empty($card_data['card_zip'])) { |
|
964 | + if ( ! give_donation_form_validate_cc_zip($card_data['card_zip'], $card_data['card_country'])) { |
|
965 | + give_set_error('invalid_cc_zip', __('The zip / postal code you entered for your billing address is invalid.', 'give')); |
|
967 | 966 | } |
968 | 967 | } |
969 | 968 | |
970 | 969 | // Ensure no spaces. |
971 | - if ( ! empty( $card_data['card_number'] ) ) { |
|
972 | - $card_data['card_number'] = str_replace( '+', '', $card_data['card_number'] ); // no "+" signs |
|
973 | - $card_data['card_number'] = str_replace( ' ', '', $card_data['card_number'] ); // No spaces |
|
970 | + if ( ! empty($card_data['card_number'])) { |
|
971 | + $card_data['card_number'] = str_replace('+', '', $card_data['card_number']); // no "+" signs |
|
972 | + $card_data['card_number'] = str_replace(' ', '', $card_data['card_number']); // No spaces |
|
974 | 973 | } |
975 | 974 | |
976 | 975 | // This should validate card numbers at some point too. |
@@ -987,17 +986,17 @@ discard block |
||
987 | 986 | function give_get_donation_cc_info() { |
988 | 987 | |
989 | 988 | $cc_info = array(); |
990 | - $cc_info['card_name'] = isset( $_POST['card_name'] ) ? sanitize_text_field( $_POST['card_name'] ) : ''; |
|
991 | - $cc_info['card_number'] = isset( $_POST['card_number'] ) ? sanitize_text_field( $_POST['card_number'] ) : ''; |
|
992 | - $cc_info['card_cvc'] = isset( $_POST['card_cvc'] ) ? sanitize_text_field( $_POST['card_cvc'] ) : ''; |
|
993 | - $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] ) ? sanitize_text_field( $_POST['card_exp_month'] ) : ''; |
|
994 | - $cc_info['card_exp_year'] = isset( $_POST['card_exp_year'] ) ? sanitize_text_field( $_POST['card_exp_year'] ) : ''; |
|
995 | - $cc_info['card_address'] = isset( $_POST['card_address'] ) ? sanitize_text_field( $_POST['card_address'] ) : ''; |
|
996 | - $cc_info['card_address_2'] = isset( $_POST['card_address_2'] ) ? sanitize_text_field( $_POST['card_address_2'] ) : ''; |
|
997 | - $cc_info['card_city'] = isset( $_POST['card_city'] ) ? sanitize_text_field( $_POST['card_city'] ) : ''; |
|
998 | - $cc_info['card_state'] = isset( $_POST['card_state'] ) ? sanitize_text_field( $_POST['card_state'] ) : ''; |
|
999 | - $cc_info['card_country'] = isset( $_POST['billing_country'] ) ? sanitize_text_field( $_POST['billing_country'] ) : ''; |
|
1000 | - $cc_info['card_zip'] = isset( $_POST['card_zip'] ) ? sanitize_text_field( $_POST['card_zip'] ) : ''; |
|
989 | + $cc_info['card_name'] = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : ''; |
|
990 | + $cc_info['card_number'] = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : ''; |
|
991 | + $cc_info['card_cvc'] = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : ''; |
|
992 | + $cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : ''; |
|
993 | + $cc_info['card_exp_year'] = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : ''; |
|
994 | + $cc_info['card_address'] = isset($_POST['card_address']) ? sanitize_text_field($_POST['card_address']) : ''; |
|
995 | + $cc_info['card_address_2'] = isset($_POST['card_address_2']) ? sanitize_text_field($_POST['card_address_2']) : ''; |
|
996 | + $cc_info['card_city'] = isset($_POST['card_city']) ? sanitize_text_field($_POST['card_city']) : ''; |
|
997 | + $cc_info['card_state'] = isset($_POST['card_state']) ? sanitize_text_field($_POST['card_state']) : ''; |
|
998 | + $cc_info['card_country'] = isset($_POST['billing_country']) ? sanitize_text_field($_POST['billing_country']) : ''; |
|
999 | + $cc_info['card_zip'] = isset($_POST['card_zip']) ? sanitize_text_field($_POST['card_zip']) : ''; |
|
1001 | 1000 | |
1002 | 1001 | // Return cc info. |
1003 | 1002 | return $cc_info; |
@@ -1013,14 +1012,14 @@ discard block |
||
1013 | 1012 | * |
1014 | 1013 | * @return bool|mixed |
1015 | 1014 | */ |
1016 | -function give_donation_form_validate_cc_zip( $zip = 0, $country_code = '' ) { |
|
1015 | +function give_donation_form_validate_cc_zip($zip = 0, $country_code = '') { |
|
1017 | 1016 | $ret = false; |
1018 | 1017 | |
1019 | - if ( empty( $zip ) || empty( $country_code ) ) { |
|
1018 | + if (empty($zip) || empty($country_code)) { |
|
1020 | 1019 | return $ret; |
1021 | 1020 | } |
1022 | 1021 | |
1023 | - $country_code = strtoupper( $country_code ); |
|
1022 | + $country_code = strtoupper($country_code); |
|
1024 | 1023 | |
1025 | 1024 | $zip_regex = array( |
1026 | 1025 | 'AD' => 'AD\d{3}', |
@@ -1180,11 +1179,11 @@ discard block |
||
1180 | 1179 | 'ZM' => '\d{5}', |
1181 | 1180 | ); |
1182 | 1181 | |
1183 | - if ( ! isset( $zip_regex[ $country_code ] ) || preg_match( '/' . $zip_regex[ $country_code ] . '/i', $zip ) ) { |
|
1182 | + if ( ! isset($zip_regex[$country_code]) || preg_match('/'.$zip_regex[$country_code].'/i', $zip)) { |
|
1184 | 1183 | $ret = true; |
1185 | 1184 | } |
1186 | 1185 | |
1187 | - return apply_filters( 'give_is_zip_valid', $ret, $zip, $country_code ); |
|
1186 | + return apply_filters('give_is_zip_valid', $ret, $zip, $country_code); |
|
1188 | 1187 | } |
1189 | 1188 | |
1190 | 1189 | |
@@ -1198,33 +1197,33 @@ discard block |
||
1198 | 1197 | * |
1199 | 1198 | * @return bool |
1200 | 1199 | */ |
1201 | -function give_validate_multi_donation_form_level( $valid_data, $data ) { |
|
1200 | +function give_validate_multi_donation_form_level($valid_data, $data) { |
|
1202 | 1201 | /* @var Give_Donate_Form $form */ |
1203 | - $form = new Give_Donate_Form( $data['give-form-id'] ); |
|
1202 | + $form = new Give_Donate_Form($data['give-form-id']); |
|
1204 | 1203 | |
1205 | 1204 | $donation_level_matched = false; |
1206 | 1205 | |
1207 | - if ( $form->is_multi_type_donation_form() ) { |
|
1206 | + if ($form->is_multi_type_donation_form()) { |
|
1208 | 1207 | |
1209 | 1208 | // Bailout. |
1210 | - if ( ! ( $variable_prices = $form->get_prices() ) ) { |
|
1209 | + if ( ! ($variable_prices = $form->get_prices())) { |
|
1211 | 1210 | return false; |
1212 | 1211 | } |
1213 | 1212 | |
1214 | 1213 | // Sanitize donation amount. |
1215 | - $data['give-amount'] = give_maybe_sanitize_amount( $data['give-amount'] ); |
|
1214 | + $data['give-amount'] = give_maybe_sanitize_amount($data['give-amount']); |
|
1216 | 1215 | |
1217 | - if ( $data['give-amount'] === give_maybe_sanitize_amount( give_get_price_option_amount( $data['give-form-id'], $data['give-price-id'] ) ) ) { |
|
1216 | + if ($data['give-amount'] === give_maybe_sanitize_amount(give_get_price_option_amount($data['give-form-id'], $data['give-price-id']))) { |
|
1218 | 1217 | return true; |
1219 | 1218 | } |
1220 | 1219 | |
1221 | 1220 | // Find correct donation level from all donation levels. |
1222 | - foreach ( $variable_prices as $variable_price ) { |
|
1221 | + foreach ($variable_prices as $variable_price) { |
|
1223 | 1222 | // Sanitize level amount. |
1224 | - $variable_price['_give_amount'] = give_maybe_sanitize_amount( $variable_price['_give_amount'] ); |
|
1223 | + $variable_price['_give_amount'] = give_maybe_sanitize_amount($variable_price['_give_amount']); |
|
1225 | 1224 | |
1226 | 1225 | // Set first match donation level ID. |
1227 | - if ( $data['give-amount'] === $variable_price['_give_amount'] ) { |
|
1226 | + if ($data['give-amount'] === $variable_price['_give_amount']) { |
|
1228 | 1227 | $_POST['give-price-id'] = $variable_price['_give_id']['level_id']; |
1229 | 1228 | $donation_level_matched = true; |
1230 | 1229 | break; |
@@ -1235,19 +1234,19 @@ discard block |
||
1235 | 1234 | // If yes then set price id to custom if amount is greater then custom minimum amount (if any). |
1236 | 1235 | if ( |
1237 | 1236 | ! $donation_level_matched |
1238 | - && ( give_is_setting_enabled( give_get_meta( $data['give-form-id'], '_give_custom_amount', true ) ) ) |
|
1237 | + && (give_is_setting_enabled(give_get_meta($data['give-form-id'], '_give_custom_amount', true))) |
|
1239 | 1238 | ) { |
1240 | 1239 | // Sanitize custom minimum amount. |
1241 | - $custom_minimum_amount = give_maybe_sanitize_amount( give_get_meta( $data['give-form-id'], '_give_custom_amount_minimum', true ) ); |
|
1240 | + $custom_minimum_amount = give_maybe_sanitize_amount(give_get_meta($data['give-form-id'], '_give_custom_amount_minimum', true)); |
|
1242 | 1241 | |
1243 | - if ( $data['give-amount'] >= $custom_minimum_amount ) { |
|
1242 | + if ($data['give-amount'] >= $custom_minimum_amount) { |
|
1244 | 1243 | $_POST['give-price-id'] = 'custom'; |
1245 | 1244 | $donation_level_matched = true; |
1246 | 1245 | } |
1247 | 1246 | } |
1248 | 1247 | }// End if(). |
1249 | 1248 | |
1250 | - return ( $donation_level_matched ? true : false ); |
|
1249 | + return ($donation_level_matched ? true : false); |
|
1251 | 1250 | } |
1252 | 1251 | |
1253 | -add_action( 'give_checkout_error_checks', 'give_validate_multi_donation_form_level', 10, 2 ); |
|
1252 | +add_action('give_checkout_error_checks', 'give_validate_multi_donation_form_level', 10, 2); |
@@ -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 | |
@@ -38,17 +38,17 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @return float|int Total amount of donations based on the passed arguments. |
40 | 40 | */ |
41 | - public function get_sales( $form_id = 0, $start_date = false, $end_date = false, $status = 'publish' ) { |
|
41 | + public function get_sales($form_id = 0, $start_date = false, $end_date = false, $status = 'publish') { |
|
42 | 42 | |
43 | - $this->setup_dates( $start_date, $end_date ); |
|
43 | + $this->setup_dates($start_date, $end_date); |
|
44 | 44 | |
45 | 45 | // Make sure start date is valid |
46 | - if ( is_wp_error( $this->start_date ) ) { |
|
46 | + if (is_wp_error($this->start_date)) { |
|
47 | 47 | return $this->start_date; |
48 | 48 | } |
49 | 49 | |
50 | 50 | // Make sure end date is valid |
51 | - if ( is_wp_error( $this->end_date ) ) { |
|
51 | + if (is_wp_error($this->end_date)) { |
|
52 | 52 | return $this->end_date; |
53 | 53 | } |
54 | 54 | |
@@ -57,18 +57,18 @@ discard block |
||
57 | 57 | 'start_date' => $this->start_date, |
58 | 58 | 'end_date' => $this->end_date, |
59 | 59 | 'fields' => 'ids', |
60 | - 'number' => - 1, |
|
60 | + 'number' => -1, |
|
61 | 61 | ); |
62 | 62 | |
63 | - if ( ! empty( $form_id ) ) { |
|
63 | + if ( ! empty($form_id)) { |
|
64 | 64 | $args['give_forms'] = $form_id; |
65 | 65 | } |
66 | 66 | |
67 | 67 | /* @var Give_Payments_Query $payments */ |
68 | - $payments = new Give_Payments_Query( $args ); |
|
68 | + $payments = new Give_Payments_Query($args); |
|
69 | 69 | $payments = $payments->get_payments(); |
70 | 70 | |
71 | - return count( $payments ); |
|
71 | + return count($payments); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | |
@@ -85,16 +85,16 @@ discard block |
||
85 | 85 | * |
86 | 86 | * @return float|int Total amount of donations based on the passed arguments. |
87 | 87 | */ |
88 | - public function get_earnings( $form_id = 0, $start_date = false, $end_date = false, $gateway_id = false ) { |
|
89 | - $this->setup_dates( $start_date, $end_date ); |
|
88 | + public function get_earnings($form_id = 0, $start_date = false, $end_date = false, $gateway_id = false) { |
|
89 | + $this->setup_dates($start_date, $end_date); |
|
90 | 90 | |
91 | 91 | // Make sure start date is valid |
92 | - if ( is_wp_error( $this->start_date ) ) { |
|
92 | + if (is_wp_error($this->start_date)) { |
|
93 | 93 | return $this->start_date; |
94 | 94 | } |
95 | 95 | |
96 | 96 | // Make sure end date is valid |
97 | - if ( is_wp_error( $this->end_date ) ) { |
|
97 | + if (is_wp_error($this->end_date)) { |
|
98 | 98 | return $this->end_date; |
99 | 99 | } |
100 | 100 | |
@@ -104,12 +104,12 @@ discard block |
||
104 | 104 | 'start_date' => $this->start_date, |
105 | 105 | 'end_date' => $this->end_date, |
106 | 106 | 'fields' => 'ids', |
107 | - 'number' => - 1, |
|
107 | + 'number' => -1, |
|
108 | 108 | ); |
109 | 109 | |
110 | 110 | |
111 | 111 | // Filter by Gateway ID meta_key |
112 | - if ( $gateway_id ) { |
|
112 | + if ($gateway_id) { |
|
113 | 113 | $args['meta_query'][] = array( |
114 | 114 | 'key' => '_give_payment_gateway', |
115 | 115 | 'value' => $gateway_id, |
@@ -117,43 +117,43 @@ discard block |
||
117 | 117 | } |
118 | 118 | |
119 | 119 | // Filter by Gateway ID meta_key |
120 | - if ( $form_id ) { |
|
120 | + if ($form_id) { |
|
121 | 121 | $args['meta_query'][] = array( |
122 | 122 | 'key' => '_give_payment_form_id', |
123 | 123 | 'value' => $form_id, |
124 | 124 | ); |
125 | 125 | } |
126 | 126 | |
127 | - if ( ! empty( $args['meta_query'] ) && 1 < count( $args['meta_query'] ) ) { |
|
127 | + if ( ! empty($args['meta_query']) && 1 < count($args['meta_query'])) { |
|
128 | 128 | $args['meta_query']['relation'] = 'AND'; |
129 | 129 | } |
130 | 130 | |
131 | - $args = apply_filters( 'give_stats_earnings_args', $args ); |
|
132 | - $key = Give_Cache::get_key( 'give_stats', $args ); |
|
131 | + $args = apply_filters('give_stats_earnings_args', $args); |
|
132 | + $key = Give_Cache::get_key('give_stats', $args); |
|
133 | 133 | |
134 | 134 | //Set transient for faster stats |
135 | - $earnings = Give_Cache::get( $key ); |
|
135 | + $earnings = Give_Cache::get($key); |
|
136 | 136 | |
137 | - if ( false === $earnings ) { |
|
137 | + if (false === $earnings) { |
|
138 | 138 | |
139 | 139 | $this->timestamp = false; |
140 | - $payments = new Give_Payments_Query( $args ); |
|
140 | + $payments = new Give_Payments_Query($args); |
|
141 | 141 | $payments = $payments->get_payments(); |
142 | 142 | $earnings = 0; |
143 | 143 | |
144 | - if ( ! empty( $payments ) ) { |
|
145 | - foreach ( $payments as $payment ) { |
|
146 | - $earnings += give_get_payment_amount( $payment->ID ); |
|
144 | + if ( ! empty($payments)) { |
|
145 | + foreach ($payments as $payment) { |
|
146 | + $earnings += give_get_payment_amount($payment->ID); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | } |
150 | 150 | |
151 | 151 | // Cache the results for one hour |
152 | - Give_Cache::set( $key, give_sanitize_amount_for_db( $earnings ), 60 * 60 ); |
|
152 | + Give_Cache::set($key, give_sanitize_amount_for_db($earnings), 60 * 60); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | //return earnings |
156 | - return round( $earnings, give_get_price_decimals( $form_id ) ); |
|
156 | + return round($earnings, give_get_price_decimals($form_id)); |
|
157 | 157 | |
158 | 158 | } |
159 | 159 | |
@@ -170,17 +170,17 @@ discard block |
||
170 | 170 | * |
171 | 171 | * @return float|int Total amount of donations based on the passed arguments. |
172 | 172 | */ |
173 | - public function get_earnings_cache_key( $form_id = 0, $start_date = false, $end_date = false, $gateway_id = false ) { |
|
173 | + public function get_earnings_cache_key($form_id = 0, $start_date = false, $end_date = false, $gateway_id = false) { |
|
174 | 174 | |
175 | - $this->setup_dates( $start_date, $end_date ); |
|
175 | + $this->setup_dates($start_date, $end_date); |
|
176 | 176 | |
177 | 177 | // Make sure start date is valid |
178 | - if ( is_wp_error( $this->start_date ) ) { |
|
178 | + if (is_wp_error($this->start_date)) { |
|
179 | 179 | return $this->start_date; |
180 | 180 | } |
181 | 181 | |
182 | 182 | // Make sure end date is valid |
183 | - if ( is_wp_error( $this->end_date ) ) { |
|
183 | + if (is_wp_error($this->end_date)) { |
|
184 | 184 | return $this->end_date; |
185 | 185 | } |
186 | 186 | |
@@ -190,12 +190,12 @@ discard block |
||
190 | 190 | 'start_date' => $this->start_date, |
191 | 191 | 'end_date' => $this->end_date, |
192 | 192 | 'fields' => 'ids', |
193 | - 'number' => - 1, |
|
193 | + 'number' => -1, |
|
194 | 194 | ); |
195 | 195 | |
196 | 196 | |
197 | 197 | // Filter by Gateway ID meta_key |
198 | - if ( $gateway_id ) { |
|
198 | + if ($gateway_id) { |
|
199 | 199 | $args['meta_query'][] = array( |
200 | 200 | 'key' => '_give_payment_gateway', |
201 | 201 | 'value' => $gateway_id, |
@@ -203,19 +203,19 @@ discard block |
||
203 | 203 | } |
204 | 204 | |
205 | 205 | // Filter by Gateway ID meta_key |
206 | - if ( $form_id ) { |
|
206 | + if ($form_id) { |
|
207 | 207 | $args['meta_query'][] = array( |
208 | 208 | 'key' => '_give_payment_form_id', |
209 | 209 | 'value' => $form_id, |
210 | 210 | ); |
211 | 211 | } |
212 | 212 | |
213 | - if ( ! empty( $args['meta_query'] ) && 1 < count( $args['meta_query'] ) ) { |
|
213 | + if ( ! empty($args['meta_query']) && 1 < count($args['meta_query'])) { |
|
214 | 214 | $args['meta_query']['relation'] = 'AND'; |
215 | 215 | } |
216 | 216 | |
217 | - $args = apply_filters( 'give_stats_earnings_args', $args ); |
|
218 | - $key = Give_Cache::get_key( 'give_stats', $args ); |
|
217 | + $args = apply_filters('give_stats_earnings_args', $args); |
|
218 | + $key = Give_Cache::get_key('give_stats', $args); |
|
219 | 219 | |
220 | 220 | //return earnings |
221 | 221 | return $key; |
@@ -232,16 +232,16 @@ discard block |
||
232 | 232 | * |
233 | 233 | * @return array Best selling forms |
234 | 234 | */ |
235 | - public function get_best_selling( $number = 10 ) { |
|
235 | + public function get_best_selling($number = 10) { |
|
236 | 236 | |
237 | 237 | global $wpdb; |
238 | 238 | |
239 | - $give_forms = $wpdb->get_results( $wpdb->prepare( |
|
239 | + $give_forms = $wpdb->get_results($wpdb->prepare( |
|
240 | 240 | "SELECT post_id as form_id, max(meta_value) as sales |
241 | 241 | FROM $wpdb->postmeta WHERE meta_key='_give_form_sales' AND meta_value > 0 |
242 | 242 | GROUP BY meta_value+0 |
243 | 243 | DESC LIMIT %d;", $number |
244 | - ) ); |
|
244 | + )); |
|
245 | 245 | |
246 | 246 | return $give_forms; |
247 | 247 | } |
@@ -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 | |
@@ -392,13 +392,13 @@ discard block |
||
392 | 392 | * |
393 | 393 | * @return mixed void|false |
394 | 394 | */ |
395 | - public function __construct( $payment_id = false ) { |
|
395 | + public function __construct($payment_id = false) { |
|
396 | 396 | |
397 | - if ( empty( $payment_id ) ) { |
|
397 | + if (empty($payment_id)) { |
|
398 | 398 | return false; |
399 | 399 | } |
400 | 400 | |
401 | - $this->setup_payment( $payment_id ); |
|
401 | + $this->setup_payment($payment_id); |
|
402 | 402 | } |
403 | 403 | |
404 | 404 | /** |
@@ -411,11 +411,11 @@ discard block |
||
411 | 411 | * |
412 | 412 | * @return mixed The value. |
413 | 413 | */ |
414 | - public function __get( $key ) { |
|
414 | + public function __get($key) { |
|
415 | 415 | |
416 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
416 | + if (method_exists($this, 'get_'.$key)) { |
|
417 | 417 | |
418 | - $value = call_user_func( array( $this, 'get_' . $key ) ); |
|
418 | + $value = call_user_func(array($this, 'get_'.$key)); |
|
419 | 419 | |
420 | 420 | } else { |
421 | 421 | |
@@ -437,18 +437,18 @@ discard block |
||
437 | 437 | * @param string $key The property name |
438 | 438 | * @param mixed $value The value of the property |
439 | 439 | */ |
440 | - public function __set( $key, $value ) { |
|
441 | - $ignore = array( '_ID' ); |
|
440 | + public function __set($key, $value) { |
|
441 | + $ignore = array('_ID'); |
|
442 | 442 | |
443 | - if ( 'status' === $key ) { |
|
443 | + if ('status' === $key) { |
|
444 | 444 | $this->old_status = $this->status; |
445 | 445 | } |
446 | 446 | |
447 | - if ( ! in_array( $key, $ignore ) ) { |
|
448 | - $this->pending[ $key ] = $value; |
|
447 | + if ( ! in_array($key, $ignore)) { |
|
448 | + $this->pending[$key] = $value; |
|
449 | 449 | } |
450 | 450 | |
451 | - if ( '_ID' !== $key ) { |
|
451 | + if ('_ID' !== $key) { |
|
452 | 452 | $this->$key = $value; |
453 | 453 | } |
454 | 454 | } |
@@ -463,9 +463,9 @@ discard block |
||
463 | 463 | * |
464 | 464 | * @return boolean|null If the item is set or not |
465 | 465 | */ |
466 | - public function __isset( $name ) { |
|
467 | - if ( property_exists( $this, $name ) ) { |
|
468 | - return false === empty( $this->$name ); |
|
466 | + public function __isset($name) { |
|
467 | + if (property_exists($this, $name)) { |
|
468 | + return false === empty($this->$name); |
|
469 | 469 | } else { |
470 | 470 | return null; |
471 | 471 | } |
@@ -481,20 +481,20 @@ discard block |
||
481 | 481 | * |
482 | 482 | * @return bool If the setup was successful or not |
483 | 483 | */ |
484 | - private function setup_payment( $payment_id ) { |
|
484 | + private function setup_payment($payment_id) { |
|
485 | 485 | $this->pending = array(); |
486 | 486 | |
487 | - if ( empty( $payment_id ) ) { |
|
487 | + if (empty($payment_id)) { |
|
488 | 488 | return false; |
489 | 489 | } |
490 | 490 | |
491 | - $payment = get_post( $payment_id ); |
|
491 | + $payment = get_post($payment_id); |
|
492 | 492 | |
493 | - if ( ! $payment || is_wp_error( $payment ) ) { |
|
493 | + if ( ! $payment || is_wp_error($payment)) { |
|
494 | 494 | return false; |
495 | 495 | } |
496 | 496 | |
497 | - if ( 'give_payment' !== $payment->post_type ) { |
|
497 | + if ('give_payment' !== $payment->post_type) { |
|
498 | 498 | return false; |
499 | 499 | } |
500 | 500 | |
@@ -508,13 +508,13 @@ discard block |
||
508 | 508 | * @param Give_Payment $this Payment object. |
509 | 509 | * @param int $payment_id The ID of the payment. |
510 | 510 | */ |
511 | - do_action( 'give_pre_setup_payment', $this, $payment_id ); |
|
511 | + do_action('give_pre_setup_payment', $this, $payment_id); |
|
512 | 512 | |
513 | 513 | // Primary Identifier. |
514 | - $this->ID = absint( $payment_id ); |
|
514 | + $this->ID = absint($payment_id); |
|
515 | 515 | |
516 | 516 | // Protected ID that can never be changed. |
517 | - $this->_ID = absint( $payment_id ); |
|
517 | + $this->_ID = absint($payment_id); |
|
518 | 518 | |
519 | 519 | // We have a payment, get the generic payment_meta item to reduce calls to it. |
520 | 520 | $this->payment_meta = $this->get_meta(); |
@@ -530,7 +530,7 @@ discard block |
||
530 | 530 | $this->parent_payment = $payment->post_parent; |
531 | 531 | |
532 | 532 | $all_payment_statuses = give_get_payment_statuses(); |
533 | - $this->status_nicename = array_key_exists( $this->status, $all_payment_statuses ) ? $all_payment_statuses[ $this->status ] : ucfirst( $this->status ); |
|
533 | + $this->status_nicename = array_key_exists($this->status, $all_payment_statuses) ? $all_payment_statuses[$this->status] : ucfirst($this->status); |
|
534 | 534 | |
535 | 535 | // Currency Based. |
536 | 536 | $this->total = $this->setup_total(); |
@@ -568,7 +568,7 @@ discard block |
||
568 | 568 | * @param Give_Payment $this Payment object. |
569 | 569 | * @param int $payment_id The ID of the payment. |
570 | 570 | */ |
571 | - do_action( 'give_setup_payment', $this, $payment_id ); |
|
571 | + do_action('give_setup_payment', $this, $payment_id); |
|
572 | 572 | |
573 | 573 | return true; |
574 | 574 | } |
@@ -586,8 +586,8 @@ discard block |
||
586 | 586 | * |
587 | 587 | * @return void |
588 | 588 | */ |
589 | - public function update_payment_setup( $payment_id ) { |
|
590 | - $this->setup_payment( $payment_id ); |
|
589 | + public function update_payment_setup($payment_id) { |
|
590 | + $this->setup_payment($payment_id); |
|
591 | 591 | } |
592 | 592 | |
593 | 593 | /** |
@@ -602,24 +602,24 @@ discard block |
||
602 | 602 | |
603 | 603 | // Construct the payment title. |
604 | 604 | $payment_title = ''; |
605 | - if ( ! empty( $this->first_name ) && ! empty( $this->last_name ) ) { |
|
606 | - $payment_title = $this->first_name . ' ' . $this->last_name; |
|
607 | - } elseif ( ! empty( $this->first_name ) && empty( $this->last_name ) ) { |
|
605 | + if ( ! empty($this->first_name) && ! empty($this->last_name)) { |
|
606 | + $payment_title = $this->first_name.' '.$this->last_name; |
|
607 | + } elseif ( ! empty($this->first_name) && empty($this->last_name)) { |
|
608 | 608 | $payment_title = $this->first_name; |
609 | - } elseif ( ! empty( $this->email ) && is_email( $this->email ) ) { |
|
609 | + } elseif ( ! empty($this->email) && is_email($this->email)) { |
|
610 | 610 | $payment_title = $this->email; |
611 | 611 | } |
612 | 612 | |
613 | 613 | // Set Key. |
614 | - if ( empty( $this->key ) ) { |
|
614 | + if (empty($this->key)) { |
|
615 | 615 | |
616 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
617 | - $this->key = strtolower( md5( $this->email . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'give', true ) ) ); // Unique key |
|
616 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
617 | + $this->key = strtolower(md5($this->email.date('Y-m-d H:i:s').$auth_key.uniqid('give', true))); // Unique key |
|
618 | 618 | $this->pending['key'] = $this->key; |
619 | 619 | } |
620 | 620 | |
621 | 621 | // Set IP. |
622 | - if ( empty( $this->ip ) ) { |
|
622 | + if (empty($this->ip)) { |
|
623 | 623 | |
624 | 624 | $this->ip = give_get_ip(); |
625 | 625 | $this->pending['ip'] = $this->ip; |
@@ -646,19 +646,19 @@ discard block |
||
646 | 646 | 'status' => $this->status, |
647 | 647 | ); |
648 | 648 | |
649 | - $args = apply_filters( 'give_insert_payment_args', array( |
|
649 | + $args = apply_filters('give_insert_payment_args', array( |
|
650 | 650 | 'post_title' => $payment_title, |
651 | 651 | 'post_status' => $this->status, |
652 | 652 | 'post_type' => 'give_payment', |
653 | - 'post_date' => ! empty( $this->date ) ? $this->date : null, |
|
654 | - 'post_date_gmt' => ! empty( $this->date ) ? get_gmt_from_date( $this->date ) : null, |
|
653 | + 'post_date' => ! empty($this->date) ? $this->date : null, |
|
654 | + 'post_date_gmt' => ! empty($this->date) ? get_gmt_from_date($this->date) : null, |
|
655 | 655 | 'post_parent' => $this->parent_payment, |
656 | - ), $payment_data ); |
|
656 | + ), $payment_data); |
|
657 | 657 | |
658 | 658 | // Create a blank payment |
659 | - $payment_id = wp_insert_post( $args ); |
|
659 | + $payment_id = wp_insert_post($args); |
|
660 | 660 | |
661 | - if ( ! empty( $payment_id ) ) { |
|
661 | + if ( ! empty($payment_id)) { |
|
662 | 662 | |
663 | 663 | $this->ID = $payment_id; |
664 | 664 | $this->_ID = $payment_id; |
@@ -670,40 +670,40 @@ discard block |
||
670 | 670 | * |
671 | 671 | * @since 1.8.13 |
672 | 672 | */ |
673 | - $donor = apply_filters( 'give_update_donor_information', $donor, $payment_id, $payment_data, $args ); |
|
673 | + $donor = apply_filters('give_update_donor_information', $donor, $payment_id, $payment_data, $args); |
|
674 | 674 | |
675 | - if ( did_action( 'give_pre_process_donation' ) && is_user_logged_in() ) { |
|
676 | - $donor = new Give_Donor( get_current_user_id(), true ); |
|
675 | + if (did_action('give_pre_process_donation') && is_user_logged_in()) { |
|
676 | + $donor = new Give_Donor(get_current_user_id(), true); |
|
677 | 677 | |
678 | 678 | // Donor is logged in but used a different email to purchase with so assign to their donor record. |
679 | - if ( ! empty( $donor->id ) && $this->email !== $donor->email ) { |
|
680 | - $donor->add_email( $this->email ); |
|
679 | + if ( ! empty($donor->id) && $this->email !== $donor->email) { |
|
680 | + $donor->add_email($this->email); |
|
681 | 681 | } |
682 | 682 | } |
683 | 683 | |
684 | - if ( empty( $donor->id ) ) { |
|
685 | - $donor = new Give_Donor( $this->email ); |
|
684 | + if (empty($donor->id)) { |
|
685 | + $donor = new Give_Donor($this->email); |
|
686 | 686 | } |
687 | 687 | |
688 | - if ( empty( $donor->id ) ) { |
|
688 | + if (empty($donor->id)) { |
|
689 | 689 | |
690 | 690 | $donor_data = array( |
691 | - 'name' => ! is_email( $payment_title ) ? $this->first_name . ' ' . $this->last_name : '', |
|
691 | + 'name' => ! is_email($payment_title) ? $this->first_name.' '.$this->last_name : '', |
|
692 | 692 | 'email' => $this->email, |
693 | 693 | 'user_id' => $this->user_id, |
694 | 694 | ); |
695 | 695 | |
696 | - $donor->create( $donor_data ); |
|
696 | + $donor->create($donor_data); |
|
697 | 697 | |
698 | 698 | } |
699 | 699 | |
700 | 700 | $this->customer_id = $donor->id; |
701 | 701 | $this->pending['customer_id'] = $this->customer_id; |
702 | - $donor->attach_payment( $this->ID, false ); |
|
702 | + $donor->attach_payment($this->ID, false); |
|
703 | 703 | |
704 | - $this->payment_meta = apply_filters( 'give_payment_meta', $this->payment_meta, $payment_data ); |
|
704 | + $this->payment_meta = apply_filters('give_payment_meta', $this->payment_meta, $payment_data); |
|
705 | 705 | |
706 | - $this->update_meta( '_give_payment_meta', $this->payment_meta ); |
|
706 | + $this->update_meta('_give_payment_meta', $this->payment_meta); |
|
707 | 707 | $this->new = true; |
708 | 708 | }// End if(). |
709 | 709 | |
@@ -725,11 +725,11 @@ discard block |
||
725 | 725 | $saved = false; |
726 | 726 | |
727 | 727 | // Must have an ID. |
728 | - if ( empty( $this->ID ) ) { |
|
728 | + if (empty($this->ID)) { |
|
729 | 729 | |
730 | 730 | $payment_id = $this->insert_payment(); |
731 | 731 | |
732 | - if ( false === $payment_id ) { |
|
732 | + if (false === $payment_id) { |
|
733 | 733 | $saved = false; |
734 | 734 | } else { |
735 | 735 | $this->ID = $payment_id; |
@@ -737,42 +737,42 @@ discard block |
||
737 | 737 | } |
738 | 738 | |
739 | 739 | // Set ID if not matching. |
740 | - if ( $this->ID !== $this->_ID ) { |
|
740 | + if ($this->ID !== $this->_ID) { |
|
741 | 741 | $this->ID = $this->_ID; |
742 | 742 | } |
743 | 743 | |
744 | 744 | // If we have something pending, let's save it. |
745 | - if ( ! empty( $this->pending ) ) { |
|
745 | + if ( ! empty($this->pending)) { |
|
746 | 746 | |
747 | 747 | $total_increase = 0; |
748 | 748 | $total_decrease = 0; |
749 | 749 | |
750 | - foreach ( $this->pending as $key => $value ) { |
|
750 | + foreach ($this->pending as $key => $value) { |
|
751 | 751 | |
752 | - switch ( $key ) { |
|
752 | + switch ($key) { |
|
753 | 753 | |
754 | 754 | case 'donations': |
755 | 755 | // Update totals for pending donations. |
756 | - foreach ( $this->pending[ $key ] as $item ) { |
|
756 | + foreach ($this->pending[$key] as $item) { |
|
757 | 757 | |
758 | - $quantity = isset( $item['quantity'] ) ? $item['quantity'] : 1; |
|
759 | - $price_id = isset( $item['price_id'] ) ? $item['price_id'] : 0; |
|
758 | + $quantity = isset($item['quantity']) ? $item['quantity'] : 1; |
|
759 | + $price_id = isset($item['price_id']) ? $item['price_id'] : 0; |
|
760 | 760 | |
761 | - switch ( $item['action'] ) { |
|
761 | + switch ($item['action']) { |
|
762 | 762 | |
763 | 763 | case 'add': |
764 | 764 | |
765 | 765 | $price = $item['price']; |
766 | 766 | |
767 | - if ( 'publish' === $this->status || 'complete' === $this->status ) { |
|
767 | + if ('publish' === $this->status || 'complete' === $this->status) { |
|
768 | 768 | |
769 | 769 | // Add donation to logs. |
770 | - $log_date = date_i18n( 'Y-m-d G:i:s', current_time( 'timestamp' ) ); |
|
771 | - give_record_donation_in_log( $item['id'], $this->ID, $price_id, $log_date ); |
|
770 | + $log_date = date_i18n('Y-m-d G:i:s', current_time('timestamp')); |
|
771 | + give_record_donation_in_log($item['id'], $this->ID, $price_id, $log_date); |
|
772 | 772 | |
773 | - $form = new Give_Donate_Form( $item['id'] ); |
|
774 | - $form->increase_sales( $quantity ); |
|
775 | - $form->increase_earnings( $price ); |
|
773 | + $form = new Give_Donate_Form($item['id']); |
|
774 | + $form->increase_sales($quantity); |
|
775 | + $form->increase_earnings($price); |
|
776 | 776 | |
777 | 777 | $total_increase += $price; |
778 | 778 | } |
@@ -797,15 +797,15 @@ discard block |
||
797 | 797 | ), |
798 | 798 | ); |
799 | 799 | |
800 | - $found_logs = get_posts( $log_args ); |
|
801 | - foreach ( $found_logs as $log ) { |
|
802 | - wp_delete_post( $log->ID, true ); |
|
800 | + $found_logs = get_posts($log_args); |
|
801 | + foreach ($found_logs as $log) { |
|
802 | + wp_delete_post($log->ID, true); |
|
803 | 803 | } |
804 | 804 | |
805 | - if ( 'publish' === $this->status || 'complete' === $this->status ) { |
|
806 | - $form = new Give_Donate_Form( $item['id'] ); |
|
807 | - $form->decrease_sales( $quantity ); |
|
808 | - $form->decrease_earnings( $item['amount'] ); |
|
805 | + if ('publish' === $this->status || 'complete' === $this->status) { |
|
806 | + $form = new Give_Donate_Form($item['id']); |
|
807 | + $form->decrease_sales($quantity); |
|
808 | + $form->decrease_earnings($item['amount']); |
|
809 | 809 | |
810 | 810 | $total_decrease += $item['amount']; |
811 | 811 | } |
@@ -816,44 +816,44 @@ discard block |
||
816 | 816 | break; |
817 | 817 | |
818 | 818 | case 'status': |
819 | - $this->update_status( $this->status ); |
|
819 | + $this->update_status($this->status); |
|
820 | 820 | break; |
821 | 821 | |
822 | 822 | case 'gateway': |
823 | - $this->update_meta( '_give_payment_gateway', $this->gateway ); |
|
823 | + $this->update_meta('_give_payment_gateway', $this->gateway); |
|
824 | 824 | break; |
825 | 825 | |
826 | 826 | case 'mode': |
827 | - $this->update_meta( '_give_payment_mode', $this->mode ); |
|
827 | + $this->update_meta('_give_payment_mode', $this->mode); |
|
828 | 828 | break; |
829 | 829 | |
830 | 830 | case 'transaction_id': |
831 | - $this->update_meta( '_give_payment_transaction_id', $this->transaction_id ); |
|
831 | + $this->update_meta('_give_payment_transaction_id', $this->transaction_id); |
|
832 | 832 | break; |
833 | 833 | |
834 | 834 | case 'ip': |
835 | - $this->update_meta( '_give_payment_user_ip', $this->ip ); |
|
835 | + $this->update_meta('_give_payment_user_ip', $this->ip); |
|
836 | 836 | break; |
837 | 837 | |
838 | 838 | case 'customer_id': |
839 | - $this->update_meta( '_give_payment_customer_id', $this->customer_id ); |
|
839 | + $this->update_meta('_give_payment_customer_id', $this->customer_id); |
|
840 | 840 | break; |
841 | 841 | |
842 | 842 | case 'user_id': |
843 | - $this->update_meta( '_give_payment_user_id', $this->user_id ); |
|
843 | + $this->update_meta('_give_payment_user_id', $this->user_id); |
|
844 | 844 | $this->user_info['id'] = $this->user_id; |
845 | 845 | break; |
846 | 846 | |
847 | 847 | case 'form_title': |
848 | - $this->update_meta( '_give_payment_form_title', $this->form_title ); |
|
848 | + $this->update_meta('_give_payment_form_title', $this->form_title); |
|
849 | 849 | break; |
850 | 850 | |
851 | 851 | case 'form_id': |
852 | - $this->update_meta( '_give_payment_form_id', $this->form_id ); |
|
852 | + $this->update_meta('_give_payment_form_id', $this->form_id); |
|
853 | 853 | break; |
854 | 854 | |
855 | 855 | case 'price_id': |
856 | - $this->update_meta( '_give_payment_price_id', $this->price_id ); |
|
856 | + $this->update_meta('_give_payment_price_id', $this->price_id); |
|
857 | 857 | break; |
858 | 858 | |
859 | 859 | case 'first_name': |
@@ -869,15 +869,15 @@ discard block |
||
869 | 869 | break; |
870 | 870 | |
871 | 871 | case 'email': |
872 | - $this->update_meta( '_give_payment_user_email', $this->email ); |
|
872 | + $this->update_meta('_give_payment_user_email', $this->email); |
|
873 | 873 | break; |
874 | 874 | |
875 | 875 | case 'key': |
876 | - $this->update_meta( '_give_payment_purchase_key', $this->key ); |
|
876 | + $this->update_meta('_give_payment_purchase_key', $this->key); |
|
877 | 877 | break; |
878 | 878 | |
879 | 879 | case 'number': |
880 | - $this->update_meta( '_give_payment_number', $this->number ); |
|
880 | + $this->update_meta('_give_payment_number', $this->number); |
|
881 | 881 | break; |
882 | 882 | |
883 | 883 | case 'date': |
@@ -887,11 +887,11 @@ discard block |
||
887 | 887 | 'edit_date' => true, |
888 | 888 | ); |
889 | 889 | |
890 | - wp_update_post( $args ); |
|
890 | + wp_update_post($args); |
|
891 | 891 | break; |
892 | 892 | |
893 | 893 | case 'completed_date': |
894 | - $this->update_meta( '_give_completed_date', $this->completed_date ); |
|
894 | + $this->update_meta('_give_completed_date', $this->completed_date); |
|
895 | 895 | break; |
896 | 896 | |
897 | 897 | case 'parent_payment': |
@@ -900,7 +900,7 @@ discard block |
||
900 | 900 | 'post_parent' => $this->parent_payment, |
901 | 901 | ); |
902 | 902 | |
903 | - wp_update_post( $args ); |
|
903 | + wp_update_post($args); |
|
904 | 904 | break; |
905 | 905 | |
906 | 906 | default: |
@@ -911,33 +911,33 @@ discard block |
||
911 | 911 | * |
912 | 912 | * @param Give_Payment $this Payment object. |
913 | 913 | */ |
914 | - do_action( 'give_payment_save', $this, $key ); |
|
914 | + do_action('give_payment_save', $this, $key); |
|
915 | 915 | break; |
916 | 916 | }// End switch(). |
917 | 917 | }// End foreach(). |
918 | 918 | |
919 | - if ( 'pending' !== $this->status ) { |
|
919 | + if ('pending' !== $this->status) { |
|
920 | 920 | |
921 | - $donor = new Give_Donor( $this->customer_id ); |
|
921 | + $donor = new Give_Donor($this->customer_id); |
|
922 | 922 | |
923 | 923 | $total_change = $total_increase - $total_decrease; |
924 | - if ( $total_change < 0 ) { |
|
924 | + if ($total_change < 0) { |
|
925 | 925 | |
926 | - $total_change = - ( $total_change ); |
|
926 | + $total_change = - ($total_change); |
|
927 | 927 | // Decrease the donor's donation stats. |
928 | - $donor->decrease_value( $total_change ); |
|
929 | - give_decrease_total_earnings( $total_change ); |
|
928 | + $donor->decrease_value($total_change); |
|
929 | + give_decrease_total_earnings($total_change); |
|
930 | 930 | |
931 | - } elseif ( $total_change > 0 ) { |
|
931 | + } elseif ($total_change > 0) { |
|
932 | 932 | |
933 | 933 | // Increase the donor's donation stats. |
934 | - $donor->increase_value( $total_change ); |
|
935 | - give_increase_total_earnings( $total_change ); |
|
934 | + $donor->increase_value($total_change); |
|
935 | + give_increase_total_earnings($total_change); |
|
936 | 936 | |
937 | 937 | } |
938 | 938 | } |
939 | 939 | |
940 | - $this->update_meta( '_give_payment_total', give_sanitize_amount_for_db( $this->total ) ); |
|
940 | + $this->update_meta('_give_payment_total', give_sanitize_amount_for_db($this->total)); |
|
941 | 941 | |
942 | 942 | $new_meta = array( |
943 | 943 | 'form_title' => $this->form_title, |
@@ -948,12 +948,12 @@ discard block |
||
948 | 948 | ); |
949 | 949 | |
950 | 950 | $meta = $this->get_meta(); |
951 | - $merged_meta = array_merge( $meta, $new_meta ); |
|
951 | + $merged_meta = array_merge($meta, $new_meta); |
|
952 | 952 | |
953 | 953 | // Only save the payment meta if it's changed. |
954 | - if ( md5( serialize( $meta ) ) !== md5( serialize( $merged_meta ) ) ) { |
|
955 | - $updated = $this->update_meta( '_give_payment_meta', $merged_meta ); |
|
956 | - if ( false !== $updated ) { |
|
954 | + if (md5(serialize($meta)) !== md5(serialize($merged_meta))) { |
|
955 | + $updated = $this->update_meta('_give_payment_meta', $merged_meta); |
|
956 | + if (false !== $updated) { |
|
957 | 957 | $saved = true; |
958 | 958 | } |
959 | 959 | } |
@@ -962,8 +962,8 @@ discard block |
||
962 | 962 | $saved = true; |
963 | 963 | }// End if(). |
964 | 964 | |
965 | - if ( true === $saved ) { |
|
966 | - $this->setup_payment( $this->ID ); |
|
965 | + if (true === $saved) { |
|
966 | + $this->setup_payment($this->ID); |
|
967 | 967 | } |
968 | 968 | |
969 | 969 | return $saved; |
@@ -981,12 +981,12 @@ discard block |
||
981 | 981 | * |
982 | 982 | * @return bool True when successful, false otherwise |
983 | 983 | */ |
984 | - public function add_donation( $form_id = 0, $args = array(), $options = array() ) { |
|
984 | + public function add_donation($form_id = 0, $args = array(), $options = array()) { |
|
985 | 985 | |
986 | - $donation = new Give_Donate_Form( $form_id ); |
|
986 | + $donation = new Give_Donate_Form($form_id); |
|
987 | 987 | |
988 | 988 | // Bail if this post isn't a give donation form. |
989 | - if ( ! $donation || $donation->post_type !== 'give_forms' ) { |
|
989 | + if ( ! $donation || $donation->post_type !== 'give_forms') { |
|
990 | 990 | return false; |
991 | 991 | } |
992 | 992 | |
@@ -996,59 +996,59 @@ discard block |
||
996 | 996 | 'price_id' => false, |
997 | 997 | ); |
998 | 998 | |
999 | - $args = wp_parse_args( apply_filters( 'give_payment_add_donation_args', $args, $donation->ID ), $defaults ); |
|
999 | + $args = wp_parse_args(apply_filters('give_payment_add_donation_args', $args, $donation->ID), $defaults); |
|
1000 | 1000 | |
1001 | 1001 | // Allow overriding the price. |
1002 | - if ( false !== $args['price'] ) { |
|
1002 | + if (false !== $args['price']) { |
|
1003 | 1003 | $donation_amount = $args['price']; |
1004 | 1004 | } else { |
1005 | 1005 | |
1006 | 1006 | // Deal with variable pricing. |
1007 | - if ( give_has_variable_prices( $donation->ID ) ) { |
|
1008 | - $prices = give_get_meta( $form_id, '_give_donation_levels', true ); |
|
1007 | + if (give_has_variable_prices($donation->ID)) { |
|
1008 | + $prices = give_get_meta($form_id, '_give_donation_levels', true); |
|
1009 | 1009 | $donation_amount = ''; |
1010 | 1010 | // Loop through prices. |
1011 | - foreach ( $prices as $price ) { |
|
1011 | + foreach ($prices as $price) { |
|
1012 | 1012 | // Find a match between price_id and level_id. |
1013 | 1013 | // First verify array keys exists THEN make the match. |
1014 | - if ( ( isset( $args['price_id'] ) && isset( $price['_give_id']['level_id'] ) ) |
|
1014 | + if ((isset($args['price_id']) && isset($price['_give_id']['level_id'])) |
|
1015 | 1015 | && $args['price_id'] == $price['_give_id']['level_id'] |
1016 | 1016 | ) { |
1017 | 1017 | $donation_amount = $price['_give_amount']; |
1018 | 1018 | } |
1019 | 1019 | } |
1020 | 1020 | // Fallback to the lowest price point. |
1021 | - if ( $donation_amount == '' ) { |
|
1022 | - $donation_amount = give_get_lowest_price_option( $donation->ID ); |
|
1023 | - $args['price_id'] = give_get_lowest_price_id( $donation->ID ); |
|
1021 | + if ($donation_amount == '') { |
|
1022 | + $donation_amount = give_get_lowest_price_option($donation->ID); |
|
1023 | + $args['price_id'] = give_get_lowest_price_id($donation->ID); |
|
1024 | 1024 | } |
1025 | 1025 | } else { |
1026 | 1026 | // Simple form price. |
1027 | - $donation_amount = give_get_form_price( $donation->ID ); |
|
1027 | + $donation_amount = give_get_form_price($donation->ID); |
|
1028 | 1028 | } |
1029 | 1029 | } |
1030 | 1030 | |
1031 | 1031 | // Sanitizing the price here so we don't have a dozen calls later. |
1032 | - $donation_amount = give_maybe_sanitize_amount( $donation_amount ); |
|
1033 | - $total = round( $donation_amount, give_get_price_decimals( $this->ID ) ); |
|
1032 | + $donation_amount = give_maybe_sanitize_amount($donation_amount); |
|
1033 | + $total = round($donation_amount, give_get_price_decimals($this->ID)); |
|
1034 | 1034 | |
1035 | 1035 | // Add Options. |
1036 | 1036 | $default_options = array(); |
1037 | - if ( false !== $args['price_id'] ) { |
|
1037 | + if (false !== $args['price_id']) { |
|
1038 | 1038 | $default_options['price_id'] = (int) $args['price_id']; |
1039 | 1039 | } |
1040 | - $options = wp_parse_args( $options, $default_options ); |
|
1040 | + $options = wp_parse_args($options, $default_options); |
|
1041 | 1041 | |
1042 | 1042 | // Do not allow totals to go negative. |
1043 | - if ( $total < 0 ) { |
|
1043 | + if ($total < 0) { |
|
1044 | 1044 | $total = 0; |
1045 | 1045 | } |
1046 | 1046 | |
1047 | 1047 | $donation = array( |
1048 | 1048 | 'name' => $donation->post_title, |
1049 | 1049 | 'id' => $donation->ID, |
1050 | - 'price' => round( $total, give_get_price_decimals( $this->ID ) ), |
|
1051 | - 'subtotal' => round( $total, give_get_price_decimals( $this->ID ) ), |
|
1050 | + 'price' => round($total, give_get_price_decimals($this->ID)), |
|
1051 | + 'subtotal' => round($total, give_get_price_decimals($this->ID)), |
|
1052 | 1052 | 'price_id' => $args['price_id'], |
1053 | 1053 | 'action' => 'add', |
1054 | 1054 | 'options' => $options, |
@@ -1056,7 +1056,7 @@ discard block |
||
1056 | 1056 | |
1057 | 1057 | $this->pending['donations'][] = $donation; |
1058 | 1058 | |
1059 | - $this->increase_subtotal( $total ); |
|
1059 | + $this->increase_subtotal($total); |
|
1060 | 1060 | |
1061 | 1061 | return true; |
1062 | 1062 | |
@@ -1073,7 +1073,7 @@ discard block |
||
1073 | 1073 | * |
1074 | 1074 | * @return bool If the item was removed or not |
1075 | 1075 | */ |
1076 | - public function remove_donation( $form_id, $args = array() ) { |
|
1076 | + public function remove_donation($form_id, $args = array()) { |
|
1077 | 1077 | |
1078 | 1078 | // Set some defaults. |
1079 | 1079 | $defaults = array( |
@@ -1081,12 +1081,12 @@ discard block |
||
1081 | 1081 | 'price' => false, |
1082 | 1082 | 'price_id' => false, |
1083 | 1083 | ); |
1084 | - $args = wp_parse_args( $args, $defaults ); |
|
1084 | + $args = wp_parse_args($args, $defaults); |
|
1085 | 1085 | |
1086 | - $form = new Give_Donate_Form( $form_id ); |
|
1086 | + $form = new Give_Donate_Form($form_id); |
|
1087 | 1087 | |
1088 | 1088 | // Bail if this post isn't a valid give donation form. |
1089 | - if ( ! $form || $form->post_type !== 'give_forms' ) { |
|
1089 | + if ( ! $form || $form->post_type !== 'give_forms') { |
|
1090 | 1090 | return false; |
1091 | 1091 | } |
1092 | 1092 | |
@@ -1099,7 +1099,7 @@ discard block |
||
1099 | 1099 | |
1100 | 1100 | $this->pending['donations'][] = $pending_args; |
1101 | 1101 | |
1102 | - $this->decrease_subtotal( $this->total ); |
|
1102 | + $this->decrease_subtotal($this->total); |
|
1103 | 1103 | |
1104 | 1104 | return true; |
1105 | 1105 | } |
@@ -1115,13 +1115,13 @@ discard block |
||
1115 | 1115 | * |
1116 | 1116 | * @return bool If the note was specified or not |
1117 | 1117 | */ |
1118 | - public function add_note( $note = false ) { |
|
1118 | + public function add_note($note = false) { |
|
1119 | 1119 | // Bail if no note specified. |
1120 | - if ( ! $note ) { |
|
1120 | + if ( ! $note) { |
|
1121 | 1121 | return false; |
1122 | 1122 | } |
1123 | 1123 | |
1124 | - give_insert_payment_note( $this->ID, $note ); |
|
1124 | + give_insert_payment_note($this->ID, $note); |
|
1125 | 1125 | } |
1126 | 1126 | |
1127 | 1127 | /** |
@@ -1134,8 +1134,8 @@ discard block |
||
1134 | 1134 | * |
1135 | 1135 | * @return void |
1136 | 1136 | */ |
1137 | - private function increase_subtotal( $amount = 0.00 ) { |
|
1138 | - $amount = (float) $amount; |
|
1137 | + private function increase_subtotal($amount = 0.00) { |
|
1138 | + $amount = (float) $amount; |
|
1139 | 1139 | $this->subtotal += $amount; |
1140 | 1140 | |
1141 | 1141 | $this->recalculate_total(); |
@@ -1151,11 +1151,11 @@ discard block |
||
1151 | 1151 | * |
1152 | 1152 | * @return void |
1153 | 1153 | */ |
1154 | - private function decrease_subtotal( $amount = 0.00 ) { |
|
1155 | - $amount = (float) $amount; |
|
1154 | + private function decrease_subtotal($amount = 0.00) { |
|
1155 | + $amount = (float) $amount; |
|
1156 | 1156 | $this->subtotal -= $amount; |
1157 | 1157 | |
1158 | - if ( $this->subtotal < 0 ) { |
|
1158 | + if ($this->subtotal < 0) { |
|
1159 | 1159 | $this->subtotal = 0; |
1160 | 1160 | } |
1161 | 1161 | |
@@ -1184,24 +1184,24 @@ discard block |
||
1184 | 1184 | * |
1185 | 1185 | * @return bool $updated Returns if the status was successfully updated. |
1186 | 1186 | */ |
1187 | - public function update_status( $status = false ) { |
|
1187 | + public function update_status($status = false) { |
|
1188 | 1188 | |
1189 | 1189 | // standardize the 'complete(d)' status. |
1190 | - if ( $status == 'completed' || $status == 'complete' ) { |
|
1190 | + if ($status == 'completed' || $status == 'complete') { |
|
1191 | 1191 | $status = 'publish'; |
1192 | 1192 | } |
1193 | 1193 | |
1194 | - $old_status = ! empty( $this->old_status ) ? $this->old_status : false; |
|
1194 | + $old_status = ! empty($this->old_status) ? $this->old_status : false; |
|
1195 | 1195 | |
1196 | - if ( $old_status === $status ) { |
|
1196 | + if ($old_status === $status) { |
|
1197 | 1197 | return false; // Don't permit status changes that aren't changes. |
1198 | 1198 | } |
1199 | 1199 | |
1200 | - $do_change = apply_filters( 'give_should_update_payment_status', true, $this->ID, $status, $old_status ); |
|
1200 | + $do_change = apply_filters('give_should_update_payment_status', true, $this->ID, $status, $old_status); |
|
1201 | 1201 | |
1202 | 1202 | $updated = false; |
1203 | 1203 | |
1204 | - if ( $do_change ) { |
|
1204 | + if ($do_change) { |
|
1205 | 1205 | |
1206 | 1206 | /** |
1207 | 1207 | * Fires before changing payment status. |
@@ -1212,21 +1212,21 @@ discard block |
||
1212 | 1212 | * @param string $status The new status. |
1213 | 1213 | * @param string $old_status The old status. |
1214 | 1214 | */ |
1215 | - do_action( 'give_before_payment_status_change', $this->ID, $status, $old_status ); |
|
1215 | + do_action('give_before_payment_status_change', $this->ID, $status, $old_status); |
|
1216 | 1216 | |
1217 | 1217 | $update_fields = array( |
1218 | 1218 | 'ID' => $this->ID, |
1219 | 1219 | 'post_status' => $status, |
1220 | - 'edit_date' => current_time( 'mysql' ), |
|
1220 | + 'edit_date' => current_time('mysql'), |
|
1221 | 1221 | ); |
1222 | 1222 | |
1223 | - $updated = wp_update_post( apply_filters( 'give_update_payment_status_fields', $update_fields ) ); |
|
1223 | + $updated = wp_update_post(apply_filters('give_update_payment_status_fields', $update_fields)); |
|
1224 | 1224 | |
1225 | 1225 | $all_payment_statuses = give_get_payment_statuses(); |
1226 | - $this->status_nicename = array_key_exists( $status, $all_payment_statuses ) ? $all_payment_statuses[ $status ] : ucfirst( $status ); |
|
1226 | + $this->status_nicename = array_key_exists($status, $all_payment_statuses) ? $all_payment_statuses[$status] : ucfirst($status); |
|
1227 | 1227 | |
1228 | 1228 | // Process any specific status functions. |
1229 | - switch ( $status ) { |
|
1229 | + switch ($status) { |
|
1230 | 1230 | case 'refunded': |
1231 | 1231 | $this->process_refund(); |
1232 | 1232 | break; |
@@ -1253,7 +1253,7 @@ discard block |
||
1253 | 1253 | * @param string $status The new status. |
1254 | 1254 | * @param string $old_status The old status. |
1255 | 1255 | */ |
1256 | - do_action( 'give_update_payment_status', $this->ID, $status, $old_status ); |
|
1256 | + do_action('give_update_payment_status', $this->ID, $status, $old_status); |
|
1257 | 1257 | |
1258 | 1258 | }// End if(). |
1259 | 1259 | |
@@ -1288,41 +1288,41 @@ discard block |
||
1288 | 1288 | * |
1289 | 1289 | * @return mixed The value from the post meta |
1290 | 1290 | */ |
1291 | - public function get_meta( $meta_key = '_give_payment_meta', $single = true ) { |
|
1291 | + public function get_meta($meta_key = '_give_payment_meta', $single = true) { |
|
1292 | 1292 | |
1293 | - $meta = give_get_meta( $this->ID, $meta_key, $single ); |
|
1293 | + $meta = give_get_meta($this->ID, $meta_key, $single); |
|
1294 | 1294 | |
1295 | - if ( $meta_key === '_give_payment_meta' ) { |
|
1295 | + if ($meta_key === '_give_payment_meta') { |
|
1296 | 1296 | $meta = (array) $meta; |
1297 | 1297 | |
1298 | - if ( empty( $meta['key'] ) ) { |
|
1298 | + if (empty($meta['key'])) { |
|
1299 | 1299 | $meta['key'] = $this->setup_payment_key(); |
1300 | 1300 | } |
1301 | 1301 | |
1302 | - if ( empty( $meta['form_title'] ) ) { |
|
1302 | + if (empty($meta['form_title'])) { |
|
1303 | 1303 | $meta['form_title'] = $this->setup_form_title(); |
1304 | 1304 | } |
1305 | 1305 | |
1306 | - if ( empty( $meta['email'] ) ) { |
|
1306 | + if (empty($meta['email'])) { |
|
1307 | 1307 | $meta['email'] = $this->setup_email(); |
1308 | 1308 | } |
1309 | 1309 | |
1310 | - if ( empty( $meta['date'] ) ) { |
|
1311 | - $meta['date'] = get_post_field( 'post_date', $this->ID ); |
|
1310 | + if (empty($meta['date'])) { |
|
1311 | + $meta['date'] = get_post_field('post_date', $this->ID); |
|
1312 | 1312 | } |
1313 | 1313 | } |
1314 | 1314 | |
1315 | - $meta = apply_filters( "give_get_payment_meta_{$meta_key}", $meta, $this->ID ); |
|
1315 | + $meta = apply_filters("give_get_payment_meta_{$meta_key}", $meta, $this->ID); |
|
1316 | 1316 | |
1317 | 1317 | // Security check. |
1318 | - if ( is_serialized( $meta ) ) { |
|
1319 | - preg_match( '/[oO]\s*:\s*\d+\s*:\s*"\s*(?!(?i)(stdClass))/', $meta, $matches ); |
|
1320 | - if ( ! empty( $matches ) ) { |
|
1318 | + if (is_serialized($meta)) { |
|
1319 | + preg_match('/[oO]\s*:\s*\d+\s*:\s*"\s*(?!(?i)(stdClass))/', $meta, $matches); |
|
1320 | + if ( ! empty($matches)) { |
|
1321 | 1321 | $meta = array(); |
1322 | 1322 | } |
1323 | 1323 | } |
1324 | 1324 | |
1325 | - return apply_filters( 'give_get_payment_meta', $meta, $this->ID, $meta_key ); |
|
1325 | + return apply_filters('give_get_payment_meta', $meta, $this->ID, $meta_key); |
|
1326 | 1326 | } |
1327 | 1327 | |
1328 | 1328 | /** |
@@ -1337,23 +1337,23 @@ discard block |
||
1337 | 1337 | * |
1338 | 1338 | * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure |
1339 | 1339 | */ |
1340 | - public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
1341 | - if ( empty( $meta_key ) ) { |
|
1340 | + public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') { |
|
1341 | + if (empty($meta_key)) { |
|
1342 | 1342 | return false; |
1343 | 1343 | } |
1344 | 1344 | |
1345 | - if ( $meta_key == 'key' || $meta_key == 'date' ) { |
|
1345 | + if ($meta_key == 'key' || $meta_key == 'date') { |
|
1346 | 1346 | |
1347 | 1347 | $current_meta = $this->get_meta(); |
1348 | - $current_meta[ $meta_key ] = $meta_value; |
|
1348 | + $current_meta[$meta_key] = $meta_value; |
|
1349 | 1349 | |
1350 | 1350 | $meta_key = '_give_payment_meta'; |
1351 | 1351 | $meta_value = $current_meta; |
1352 | 1352 | |
1353 | - } elseif ( $meta_key == 'email' || $meta_key == '_give_payment_user_email' ) { |
|
1353 | + } elseif ($meta_key == 'email' || $meta_key == '_give_payment_user_email') { |
|
1354 | 1354 | |
1355 | - $meta_value = apply_filters( "give_update_payment_meta_{$meta_key}", $meta_value, $this->ID ); |
|
1356 | - give_update_meta( $this->ID, '_give_payment_user_email', $meta_value ); |
|
1355 | + $meta_value = apply_filters("give_update_payment_meta_{$meta_key}", $meta_value, $this->ID); |
|
1356 | + give_update_meta($this->ID, '_give_payment_user_email', $meta_value); |
|
1357 | 1357 | |
1358 | 1358 | $current_meta = $this->get_meta(); |
1359 | 1359 | $current_meta['user_info']['email'] = $meta_value; |
@@ -1363,9 +1363,9 @@ discard block |
||
1363 | 1363 | |
1364 | 1364 | } |
1365 | 1365 | |
1366 | - $meta_value = apply_filters( "give_update_payment_meta_{$meta_key}", $meta_value, $this->ID ); |
|
1366 | + $meta_value = apply_filters("give_update_payment_meta_{$meta_key}", $meta_value, $this->ID); |
|
1367 | 1367 | |
1368 | - return give_update_meta( $this->ID, $meta_key, $meta_value, $prev_value ); |
|
1368 | + return give_update_meta($this->ID, $meta_key, $meta_value, $prev_value); |
|
1369 | 1369 | } |
1370 | 1370 | |
1371 | 1371 | /** |
@@ -1380,14 +1380,14 @@ discard block |
||
1380 | 1380 | $process_refund = true; |
1381 | 1381 | |
1382 | 1382 | // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented. |
1383 | - if ( 'publish' != $this->old_status || 'refunded' != $this->status ) { |
|
1383 | + if ('publish' != $this->old_status || 'refunded' != $this->status) { |
|
1384 | 1384 | $process_refund = false; |
1385 | 1385 | } |
1386 | 1386 | |
1387 | 1387 | // Allow extensions to filter for their own payment types, Example: Recurring Payments. |
1388 | - $process_refund = apply_filters( 'give_should_process_refund', $process_refund, $this ); |
|
1388 | + $process_refund = apply_filters('give_should_process_refund', $process_refund, $this); |
|
1389 | 1389 | |
1390 | - if ( false === $process_refund ) { |
|
1390 | + if (false === $process_refund) { |
|
1391 | 1391 | return; |
1392 | 1392 | } |
1393 | 1393 | |
@@ -1398,13 +1398,13 @@ discard block |
||
1398 | 1398 | * |
1399 | 1399 | * @param Give_Payment $this Payment object. |
1400 | 1400 | */ |
1401 | - do_action( 'give_pre_refund_payment', $this ); |
|
1401 | + do_action('give_pre_refund_payment', $this); |
|
1402 | 1402 | |
1403 | - $decrease_earnings = apply_filters( 'give_decrease_store_earnings_on_refund', true, $this ); |
|
1404 | - $decrease_customer_value = apply_filters( 'give_decrease_customer_value_on_refund', true, $this ); |
|
1405 | - $decrease_purchase_count = apply_filters( 'give_decrease_customer_purchase_count_on_refund', true, $this ); |
|
1403 | + $decrease_earnings = apply_filters('give_decrease_store_earnings_on_refund', true, $this); |
|
1404 | + $decrease_customer_value = apply_filters('give_decrease_customer_value_on_refund', true, $this); |
|
1405 | + $decrease_purchase_count = apply_filters('give_decrease_customer_purchase_count_on_refund', true, $this); |
|
1406 | 1406 | |
1407 | - $this->maybe_alter_stats( $decrease_earnings, $decrease_customer_value, $decrease_purchase_count ); |
|
1407 | + $this->maybe_alter_stats($decrease_earnings, $decrease_customer_value, $decrease_purchase_count); |
|
1408 | 1408 | $this->delete_sales_logs(); |
1409 | 1409 | |
1410 | 1410 | // @todo: Refresh only range related stat cache |
@@ -1417,7 +1417,7 @@ discard block |
||
1417 | 1417 | * |
1418 | 1418 | * @param Give_Payment $this Payment object. |
1419 | 1419 | */ |
1420 | - do_action( 'give_post_refund_payment', $this ); |
|
1420 | + do_action('give_post_refund_payment', $this); |
|
1421 | 1421 | } |
1422 | 1422 | |
1423 | 1423 | /** |
@@ -1444,26 +1444,26 @@ discard block |
||
1444 | 1444 | $process_pending = true; |
1445 | 1445 | |
1446 | 1446 | // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented. |
1447 | - if ( 'publish' != $this->old_status || 'pending' != $this->status ) { |
|
1447 | + if ('publish' != $this->old_status || 'pending' != $this->status) { |
|
1448 | 1448 | $process_pending = false; |
1449 | 1449 | } |
1450 | 1450 | |
1451 | 1451 | // Allow extensions to filter for their own payment types, Example: Recurring Payments. |
1452 | - $process_pending = apply_filters( 'give_should_process_pending', $process_pending, $this ); |
|
1452 | + $process_pending = apply_filters('give_should_process_pending', $process_pending, $this); |
|
1453 | 1453 | |
1454 | - if ( false === $process_pending ) { |
|
1454 | + if (false === $process_pending) { |
|
1455 | 1455 | return; |
1456 | 1456 | } |
1457 | 1457 | |
1458 | - $decrease_earnings = apply_filters( 'give_decrease_earnings_on_pending', true, $this ); |
|
1459 | - $decrease_donor_value = apply_filters( 'give_decrease_donor_value_on_pending', true, $this ); |
|
1460 | - $decrease_donation_count = apply_filters( 'give_decrease_donors_donation_count_on_pending', true, $this ); |
|
1458 | + $decrease_earnings = apply_filters('give_decrease_earnings_on_pending', true, $this); |
|
1459 | + $decrease_donor_value = apply_filters('give_decrease_donor_value_on_pending', true, $this); |
|
1460 | + $decrease_donation_count = apply_filters('give_decrease_donors_donation_count_on_pending', true, $this); |
|
1461 | 1461 | |
1462 | - $this->maybe_alter_stats( $decrease_earnings, $decrease_donor_value, $decrease_donation_count ); |
|
1462 | + $this->maybe_alter_stats($decrease_earnings, $decrease_donor_value, $decrease_donation_count); |
|
1463 | 1463 | $this->delete_sales_logs(); |
1464 | 1464 | |
1465 | 1465 | $this->completed_date = false; |
1466 | - $this->update_meta( '_give_completed_date', '' ); |
|
1466 | + $this->update_meta('_give_completed_date', ''); |
|
1467 | 1467 | |
1468 | 1468 | // @todo: Refresh only range related stat cache |
1469 | 1469 | give_delete_donation_stats(); |
@@ -1481,26 +1481,26 @@ discard block |
||
1481 | 1481 | $process_cancelled = true; |
1482 | 1482 | |
1483 | 1483 | // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented. |
1484 | - if ( 'publish' != $this->old_status || 'cancelled' != $this->status ) { |
|
1484 | + if ('publish' != $this->old_status || 'cancelled' != $this->status) { |
|
1485 | 1485 | $process_cancelled = false; |
1486 | 1486 | } |
1487 | 1487 | |
1488 | 1488 | // Allow extensions to filter for their own payment types, Example: Recurring Payments. |
1489 | - $process_cancelled = apply_filters( 'give_should_process_cancelled', $process_cancelled, $this ); |
|
1489 | + $process_cancelled = apply_filters('give_should_process_cancelled', $process_cancelled, $this); |
|
1490 | 1490 | |
1491 | - if ( false === $process_cancelled ) { |
|
1491 | + if (false === $process_cancelled) { |
|
1492 | 1492 | return; |
1493 | 1493 | } |
1494 | 1494 | |
1495 | - $decrease_earnings = apply_filters( 'give_decrease_earnings_on_cancelled', true, $this ); |
|
1496 | - $decrease_donor_value = apply_filters( 'give_decrease_donor_value_on_cancelled', true, $this ); |
|
1497 | - $decrease_donation_count = apply_filters( 'give_decrease_donors_donation_count_on_cancelled', true, $this ); |
|
1495 | + $decrease_earnings = apply_filters('give_decrease_earnings_on_cancelled', true, $this); |
|
1496 | + $decrease_donor_value = apply_filters('give_decrease_donor_value_on_cancelled', true, $this); |
|
1497 | + $decrease_donation_count = apply_filters('give_decrease_donors_donation_count_on_cancelled', true, $this); |
|
1498 | 1498 | |
1499 | - $this->maybe_alter_stats( $decrease_earnings, $decrease_donor_value, $decrease_donation_count ); |
|
1499 | + $this->maybe_alter_stats($decrease_earnings, $decrease_donor_value, $decrease_donation_count); |
|
1500 | 1500 | $this->delete_sales_logs(); |
1501 | 1501 | |
1502 | 1502 | $this->completed_date = false; |
1503 | - $this->update_meta( '_give_completed_date', '' ); |
|
1503 | + $this->update_meta('_give_completed_date', ''); |
|
1504 | 1504 | |
1505 | 1505 | // @todo: Refresh only range related stat cache |
1506 | 1506 | give_delete_donation_stats(); |
@@ -1516,26 +1516,26 @@ discard block |
||
1516 | 1516 | $process_revoked = true; |
1517 | 1517 | |
1518 | 1518 | // If the payment was not in publish, don't decrement stats as they were never incremented. |
1519 | - if ( 'publish' != $this->old_status || 'revoked' != $this->status ) { |
|
1519 | + if ('publish' != $this->old_status || 'revoked' != $this->status) { |
|
1520 | 1520 | $process_revoked = false; |
1521 | 1521 | } |
1522 | 1522 | |
1523 | 1523 | // Allow extensions to filter for their own payment types, Example: Recurring Payments. |
1524 | - $process_revoked = apply_filters( 'give_should_process_revoked', $process_revoked, $this ); |
|
1524 | + $process_revoked = apply_filters('give_should_process_revoked', $process_revoked, $this); |
|
1525 | 1525 | |
1526 | - if ( false === $process_revoked ) { |
|
1526 | + if (false === $process_revoked) { |
|
1527 | 1527 | return; |
1528 | 1528 | } |
1529 | 1529 | |
1530 | - $decrease_earnings = apply_filters( 'give_decrease_earnings_on_revoked', true, $this ); |
|
1531 | - $decrease_donor_value = apply_filters( 'give_decrease_donor_value_on_revoked', true, $this ); |
|
1532 | - $decrease_donation_count = apply_filters( 'give_decrease_donors_donation_count_on_revoked', true, $this ); |
|
1530 | + $decrease_earnings = apply_filters('give_decrease_earnings_on_revoked', true, $this); |
|
1531 | + $decrease_donor_value = apply_filters('give_decrease_donor_value_on_revoked', true, $this); |
|
1532 | + $decrease_donation_count = apply_filters('give_decrease_donors_donation_count_on_revoked', true, $this); |
|
1533 | 1533 | |
1534 | - $this->maybe_alter_stats( $decrease_earnings, $decrease_donor_value, $decrease_donation_count ); |
|
1534 | + $this->maybe_alter_stats($decrease_earnings, $decrease_donor_value, $decrease_donation_count); |
|
1535 | 1535 | $this->delete_sales_logs(); |
1536 | 1536 | |
1537 | 1537 | $this->completed_date = false; |
1538 | - $this->update_meta( '_give_completed_date', '' ); |
|
1538 | + $this->update_meta('_give_completed_date', ''); |
|
1539 | 1539 | |
1540 | 1540 | // @todo: Refresh only range related stat cache |
1541 | 1541 | give_delete_donation_stats(); |
@@ -1553,25 +1553,25 @@ discard block |
||
1553 | 1553 | * |
1554 | 1554 | * @return void |
1555 | 1555 | */ |
1556 | - private function maybe_alter_stats( $alter_store_earnings, $alter_customer_value, $alter_customer_purchase_count ) { |
|
1556 | + private function maybe_alter_stats($alter_store_earnings, $alter_customer_value, $alter_customer_purchase_count) { |
|
1557 | 1557 | |
1558 | - give_undo_donation( $this->ID ); |
|
1558 | + give_undo_donation($this->ID); |
|
1559 | 1559 | |
1560 | 1560 | // Decrease store earnings. |
1561 | - if ( true === $alter_store_earnings ) { |
|
1562 | - give_decrease_total_earnings( $this->total ); |
|
1561 | + if (true === $alter_store_earnings) { |
|
1562 | + give_decrease_total_earnings($this->total); |
|
1563 | 1563 | } |
1564 | 1564 | |
1565 | 1565 | // Decrement the stats for the donor. |
1566 | - if ( ! empty( $this->customer_id ) ) { |
|
1566 | + if ( ! empty($this->customer_id)) { |
|
1567 | 1567 | |
1568 | - $donor = new Give_Donor( $this->customer_id ); |
|
1568 | + $donor = new Give_Donor($this->customer_id); |
|
1569 | 1569 | |
1570 | - if ( true === $alter_customer_value ) { |
|
1571 | - $donor->decrease_value( $this->total ); |
|
1570 | + if (true === $alter_customer_value) { |
|
1571 | + $donor->decrease_value($this->total); |
|
1572 | 1572 | } |
1573 | 1573 | |
1574 | - if ( true === $alter_customer_purchase_count ) { |
|
1574 | + if (true === $alter_customer_purchase_count) { |
|
1575 | 1575 | $donor->decrease_donation_count(); |
1576 | 1576 | } |
1577 | 1577 | } |
@@ -1620,13 +1620,13 @@ discard block |
||
1620 | 1620 | * @return string The date the payment was completed |
1621 | 1621 | */ |
1622 | 1622 | private function setup_completed_date() { |
1623 | - $payment = get_post( $this->ID ); |
|
1623 | + $payment = get_post($this->ID); |
|
1624 | 1624 | |
1625 | - if ( 'pending' == $payment->post_status || 'preapproved' == $payment->post_status ) { |
|
1625 | + if ('pending' == $payment->post_status || 'preapproved' == $payment->post_status) { |
|
1626 | 1626 | return false; // This payment was never completed. |
1627 | 1627 | } |
1628 | 1628 | |
1629 | - $date = ( $date = $this->get_meta( '_give_completed_date', true ) ) ? $date : $payment->modified_date; |
|
1629 | + $date = ($date = $this->get_meta('_give_completed_date', true)) ? $date : $payment->modified_date; |
|
1630 | 1630 | |
1631 | 1631 | return $date; |
1632 | 1632 | } |
@@ -1640,7 +1640,7 @@ discard block |
||
1640 | 1640 | * @return string The payment mode |
1641 | 1641 | */ |
1642 | 1642 | private function setup_mode() { |
1643 | - return $this->get_meta( '_give_payment_mode' ); |
|
1643 | + return $this->get_meta('_give_payment_mode'); |
|
1644 | 1644 | } |
1645 | 1645 | |
1646 | 1646 | /** |
@@ -1652,7 +1652,7 @@ discard block |
||
1652 | 1652 | * @return bool The payment import |
1653 | 1653 | */ |
1654 | 1654 | private function setup_import() { |
1655 | - return (bool) $this->get_meta( '_give_payment_import' ); |
|
1655 | + return (bool) $this->get_meta('_give_payment_import'); |
|
1656 | 1656 | } |
1657 | 1657 | |
1658 | 1658 | /** |
@@ -1664,18 +1664,18 @@ discard block |
||
1664 | 1664 | * @return float The payment total |
1665 | 1665 | */ |
1666 | 1666 | private function setup_total() { |
1667 | - $amount = $this->get_meta( '_give_payment_total', true ); |
|
1667 | + $amount = $this->get_meta('_give_payment_total', true); |
|
1668 | 1668 | |
1669 | - if ( empty( $amount ) && '0.00' != $amount ) { |
|
1670 | - $meta = $this->get_meta( '_give_payment_meta', true ); |
|
1671 | - $meta = maybe_unserialize( $meta ); |
|
1669 | + if (empty($amount) && '0.00' != $amount) { |
|
1670 | + $meta = $this->get_meta('_give_payment_meta', true); |
|
1671 | + $meta = maybe_unserialize($meta); |
|
1672 | 1672 | |
1673 | - if ( isset( $meta['amount'] ) ) { |
|
1673 | + if (isset($meta['amount'])) { |
|
1674 | 1674 | $amount = $meta['amount']; |
1675 | 1675 | } |
1676 | 1676 | } |
1677 | 1677 | |
1678 | - return round( (float) $amount, give_get_price_decimals( $this->ID ) ); |
|
1678 | + return round((float) $amount, give_get_price_decimals($this->ID)); |
|
1679 | 1679 | } |
1680 | 1680 | |
1681 | 1681 | /** |
@@ -1701,7 +1701,7 @@ discard block |
||
1701 | 1701 | * @return string The currency for the payment |
1702 | 1702 | */ |
1703 | 1703 | private function setup_currency() { |
1704 | - $currency = ! empty( $this->payment_meta['currency'] ) ? $this->payment_meta['currency'] : apply_filters( 'give_payment_currency_default', give_get_currency( $this->form_id, $this ), $this ); |
|
1704 | + $currency = ! empty($this->payment_meta['currency']) ? $this->payment_meta['currency'] : apply_filters('give_payment_currency_default', give_get_currency($this->form_id, $this), $this); |
|
1705 | 1705 | |
1706 | 1706 | return $currency; |
1707 | 1707 | } |
@@ -1715,7 +1715,7 @@ discard block |
||
1715 | 1715 | * @return string The gateway |
1716 | 1716 | */ |
1717 | 1717 | private function setup_gateway() { |
1718 | - $gateway = $this->get_meta( '_give_payment_gateway', true ); |
|
1718 | + $gateway = $this->get_meta('_give_payment_gateway', true); |
|
1719 | 1719 | |
1720 | 1720 | return $gateway; |
1721 | 1721 | } |
@@ -1729,11 +1729,11 @@ discard block |
||
1729 | 1729 | * @return string The donation ID |
1730 | 1730 | */ |
1731 | 1731 | private function setup_transaction_id() { |
1732 | - $transaction_id = $this->get_meta( '_give_payment_transaction_id', true ); |
|
1732 | + $transaction_id = $this->get_meta('_give_payment_transaction_id', true); |
|
1733 | 1733 | |
1734 | - if ( empty( $transaction_id ) ) { |
|
1734 | + if (empty($transaction_id)) { |
|
1735 | 1735 | $gateway = $this->gateway; |
1736 | - $transaction_id = apply_filters( "give_get_payment_transaction_id-{$gateway}", $this->ID ); |
|
1736 | + $transaction_id = apply_filters("give_get_payment_transaction_id-{$gateway}", $this->ID); |
|
1737 | 1737 | } |
1738 | 1738 | |
1739 | 1739 | return $transaction_id; |
@@ -1748,7 +1748,7 @@ discard block |
||
1748 | 1748 | * @return string The IP address for the payment |
1749 | 1749 | */ |
1750 | 1750 | private function setup_ip() { |
1751 | - $ip = $this->get_meta( '_give_payment_user_ip', true ); |
|
1751 | + $ip = $this->get_meta('_give_payment_user_ip', true); |
|
1752 | 1752 | |
1753 | 1753 | return $ip; |
1754 | 1754 | } |
@@ -1762,7 +1762,7 @@ discard block |
||
1762 | 1762 | * @return int The Donor ID. |
1763 | 1763 | */ |
1764 | 1764 | private function setup_donor_id() { |
1765 | - $customer_id = $this->get_meta( '_give_payment_customer_id', true ); |
|
1765 | + $customer_id = $this->get_meta('_give_payment_customer_id', true); |
|
1766 | 1766 | |
1767 | 1767 | return $customer_id; |
1768 | 1768 | } |
@@ -1776,7 +1776,7 @@ discard block |
||
1776 | 1776 | * @return int The User ID |
1777 | 1777 | */ |
1778 | 1778 | private function setup_user_id() { |
1779 | - $user_id = $this->get_meta( '_give_payment_user_id', true ); |
|
1779 | + $user_id = $this->get_meta('_give_payment_user_id', true); |
|
1780 | 1780 | |
1781 | 1781 | return $user_id; |
1782 | 1782 | } |
@@ -1790,10 +1790,10 @@ discard block |
||
1790 | 1790 | * @return string The email address for the payment. |
1791 | 1791 | */ |
1792 | 1792 | private function setup_email() { |
1793 | - $email = $this->get_meta( '_give_payment_user_email', true ); |
|
1793 | + $email = $this->get_meta('_give_payment_user_email', true); |
|
1794 | 1794 | |
1795 | - if ( empty( $email ) && $this->customer_id ) { |
|
1796 | - $email = Give()->donors->get_column( 'email', $this->customer_id ); |
|
1795 | + if (empty($email) && $this->customer_id) { |
|
1796 | + $email = Give()->donors->get_column('email', $this->customer_id); |
|
1797 | 1797 | } |
1798 | 1798 | |
1799 | 1799 | return $email; |
@@ -1813,23 +1813,23 @@ discard block |
||
1813 | 1813 | 'last_name' => $this->last_name, |
1814 | 1814 | ); |
1815 | 1815 | |
1816 | - $user_info = isset( $this->payment_meta['user_info'] ) ? $this->payment_meta['user_info'] : array(); |
|
1816 | + $user_info = isset($this->payment_meta['user_info']) ? $this->payment_meta['user_info'] : array(); |
|
1817 | 1817 | |
1818 | - if ( is_serialized( $user_info ) ) { |
|
1819 | - preg_match( '/[oO]\s*:\s*\d+\s*:\s*"\s*(?!(?i)(stdClass))/', $user_info, $matches ); |
|
1820 | - if ( ! empty( $matches ) ) { |
|
1818 | + if (is_serialized($user_info)) { |
|
1819 | + preg_match('/[oO]\s*:\s*\d+\s*:\s*"\s*(?!(?i)(stdClass))/', $user_info, $matches); |
|
1820 | + if ( ! empty($matches)) { |
|
1821 | 1821 | $user_info = array(); |
1822 | 1822 | } |
1823 | 1823 | } |
1824 | 1824 | |
1825 | - $user_info = wp_parse_args( $user_info, $defaults ); |
|
1825 | + $user_info = wp_parse_args($user_info, $defaults); |
|
1826 | 1826 | |
1827 | - if ( empty( $user_info ) ) { |
|
1827 | + if (empty($user_info)) { |
|
1828 | 1828 | // Get the donor, but only if it's been created. |
1829 | - $donor = new Give_Donor( $this->customer_id ); |
|
1829 | + $donor = new Give_Donor($this->customer_id); |
|
1830 | 1830 | |
1831 | - if ( $donor->id > 0 ) { |
|
1832 | - $name = explode( ' ', $donor->name, 2 ); |
|
1831 | + if ($donor->id > 0) { |
|
1832 | + $name = explode(' ', $donor->name, 2); |
|
1833 | 1833 | $user_info = array( |
1834 | 1834 | 'first_name' => $name[0], |
1835 | 1835 | 'last_name' => $name[1], |
@@ -1839,29 +1839,29 @@ discard block |
||
1839 | 1839 | } |
1840 | 1840 | } else { |
1841 | 1841 | // Get the donor, but only if it's been created. |
1842 | - $donor = new Give_Donor( $this->customer_id ); |
|
1843 | - if ( $donor->id > 0 ) { |
|
1844 | - foreach ( $user_info as $key => $value ) { |
|
1845 | - if ( ! empty( $value ) ) { |
|
1842 | + $donor = new Give_Donor($this->customer_id); |
|
1843 | + if ($donor->id > 0) { |
|
1844 | + foreach ($user_info as $key => $value) { |
|
1845 | + if ( ! empty($value)) { |
|
1846 | 1846 | continue; |
1847 | 1847 | } |
1848 | 1848 | |
1849 | - switch ( $key ) { |
|
1849 | + switch ($key) { |
|
1850 | 1850 | case 'first_name': |
1851 | - $name = explode( ' ', $donor->name, 2 ); |
|
1851 | + $name = explode(' ', $donor->name, 2); |
|
1852 | 1852 | |
1853 | - $user_info[ $key ] = $name[0]; |
|
1853 | + $user_info[$key] = $name[0]; |
|
1854 | 1854 | break; |
1855 | 1855 | |
1856 | 1856 | case 'last_name': |
1857 | - $name = explode( ' ', $donor->name, 2 ); |
|
1858 | - $last_name = ! empty( $name[1] ) ? $name[1] : ''; |
|
1857 | + $name = explode(' ', $donor->name, 2); |
|
1858 | + $last_name = ! empty($name[1]) ? $name[1] : ''; |
|
1859 | 1859 | |
1860 | - $user_info[ $key ] = $last_name; |
|
1860 | + $user_info[$key] = $last_name; |
|
1861 | 1861 | break; |
1862 | 1862 | |
1863 | 1863 | case 'email': |
1864 | - $user_info[ $key ] = $donor->email; |
|
1864 | + $user_info[$key] = $donor->email; |
|
1865 | 1865 | break; |
1866 | 1866 | } |
1867 | 1867 | } |
@@ -1882,7 +1882,7 @@ discard block |
||
1882 | 1882 | */ |
1883 | 1883 | private function setup_address() { |
1884 | 1884 | |
1885 | - $address = ! empty( $this->payment_meta['user_info']['address'] ) ? $this->payment_meta['user_info']['address'] : array( |
|
1885 | + $address = ! empty($this->payment_meta['user_info']['address']) ? $this->payment_meta['user_info']['address'] : array( |
|
1886 | 1886 | 'line1' => '', |
1887 | 1887 | 'line2' => '', |
1888 | 1888 | 'city' => '', |
@@ -1904,7 +1904,7 @@ discard block |
||
1904 | 1904 | */ |
1905 | 1905 | private function setup_form_title() { |
1906 | 1906 | |
1907 | - $form_id = $this->get_meta( '_give_payment_form_title', true ); |
|
1907 | + $form_id = $this->get_meta('_give_payment_form_title', true); |
|
1908 | 1908 | |
1909 | 1909 | return $form_id; |
1910 | 1910 | } |
@@ -1919,7 +1919,7 @@ discard block |
||
1919 | 1919 | */ |
1920 | 1920 | private function setup_form_id() { |
1921 | 1921 | |
1922 | - $form_id = $this->get_meta( '_give_payment_form_id', true ); |
|
1922 | + $form_id = $this->get_meta('_give_payment_form_id', true); |
|
1923 | 1923 | |
1924 | 1924 | return $form_id; |
1925 | 1925 | } |
@@ -1933,7 +1933,7 @@ discard block |
||
1933 | 1933 | * @return int The Form Price ID. |
1934 | 1934 | */ |
1935 | 1935 | private function setup_price_id() { |
1936 | - $price_id = $this->get_meta( '_give_payment_price_id', true ); |
|
1936 | + $price_id = $this->get_meta('_give_payment_price_id', true); |
|
1937 | 1937 | |
1938 | 1938 | return $price_id; |
1939 | 1939 | } |
@@ -1947,7 +1947,7 @@ discard block |
||
1947 | 1947 | * @return string The Payment Key. |
1948 | 1948 | */ |
1949 | 1949 | private function setup_payment_key() { |
1950 | - $key = $this->get_meta( '_give_payment_purchase_key', true ); |
|
1950 | + $key = $this->get_meta('_give_payment_purchase_key', true); |
|
1951 | 1951 | |
1952 | 1952 | return $key; |
1953 | 1953 | } |
@@ -1963,11 +1963,11 @@ discard block |
||
1963 | 1963 | private function setup_payment_number() { |
1964 | 1964 | $number = $this->ID; |
1965 | 1965 | |
1966 | - if ( give_get_option( 'enable_sequential' ) ) { |
|
1966 | + if (give_get_option('enable_sequential')) { |
|
1967 | 1967 | |
1968 | - $number = $this->get_meta( '_give_payment_number', true ); |
|
1968 | + $number = $this->get_meta('_give_payment_number', true); |
|
1969 | 1969 | |
1970 | - if ( ! $number ) { |
|
1970 | + if ( ! $number) { |
|
1971 | 1971 | |
1972 | 1972 | $number = $this->ID; |
1973 | 1973 | |
@@ -1985,7 +1985,7 @@ discard block |
||
1985 | 1985 | * @return array The payment object as an array. |
1986 | 1986 | */ |
1987 | 1987 | public function array_convert() { |
1988 | - return get_object_vars( $this ); |
|
1988 | + return get_object_vars($this); |
|
1989 | 1989 | } |
1990 | 1990 | |
1991 | 1991 | |
@@ -1998,7 +1998,7 @@ discard block |
||
1998 | 1998 | * @return bool |
1999 | 1999 | */ |
2000 | 2000 | public function is_completed() { |
2001 | - return ( 'publish' === $this->status && $this->completed_date ); |
|
2001 | + return ('publish' === $this->status && $this->completed_date); |
|
2002 | 2002 | } |
2003 | 2003 | |
2004 | 2004 | /** |
@@ -2010,7 +2010,7 @@ discard block |
||
2010 | 2010 | * @return string Date payment was completed. |
2011 | 2011 | */ |
2012 | 2012 | private function get_completed_date() { |
2013 | - return apply_filters( 'give_payment_completed_date', $this->completed_date, $this->ID, $this ); |
|
2013 | + return apply_filters('give_payment_completed_date', $this->completed_date, $this->ID, $this); |
|
2014 | 2014 | } |
2015 | 2015 | |
2016 | 2016 | /** |
@@ -2022,7 +2022,7 @@ discard block |
||
2022 | 2022 | * @return float Payment subtotal. |
2023 | 2023 | */ |
2024 | 2024 | private function get_subtotal() { |
2025 | - return apply_filters( 'give_get_payment_subtotal', $this->subtotal, $this->ID, $this ); |
|
2025 | + return apply_filters('give_get_payment_subtotal', $this->subtotal, $this->ID, $this); |
|
2026 | 2026 | } |
2027 | 2027 | |
2028 | 2028 | /** |
@@ -2034,7 +2034,7 @@ discard block |
||
2034 | 2034 | * @return string Payment currency code. |
2035 | 2035 | */ |
2036 | 2036 | private function get_currency() { |
2037 | - return apply_filters( 'give_payment_currency_code', $this->currency, $this->ID, $this ); |
|
2037 | + return apply_filters('give_payment_currency_code', $this->currency, $this->ID, $this); |
|
2038 | 2038 | } |
2039 | 2039 | |
2040 | 2040 | /** |
@@ -2046,7 +2046,7 @@ discard block |
||
2046 | 2046 | * @return string Gateway used. |
2047 | 2047 | */ |
2048 | 2048 | private function get_gateway() { |
2049 | - return apply_filters( 'give_payment_gateway', $this->gateway, $this->ID, $this ); |
|
2049 | + return apply_filters('give_payment_gateway', $this->gateway, $this->ID, $this); |
|
2050 | 2050 | } |
2051 | 2051 | |
2052 | 2052 | /** |
@@ -2058,7 +2058,7 @@ discard block |
||
2058 | 2058 | * @return string Donation ID from merchant processor. |
2059 | 2059 | */ |
2060 | 2060 | private function get_transaction_id() { |
2061 | - return apply_filters( 'give_get_payment_transaction_id', $this->transaction_id, $this->ID, $this ); |
|
2061 | + return apply_filters('give_get_payment_transaction_id', $this->transaction_id, $this->ID, $this); |
|
2062 | 2062 | } |
2063 | 2063 | |
2064 | 2064 | /** |
@@ -2070,7 +2070,7 @@ discard block |
||
2070 | 2070 | * @return string Payment IP address |
2071 | 2071 | */ |
2072 | 2072 | private function get_ip() { |
2073 | - return apply_filters( 'give_payment_user_ip', $this->ip, $this->ID, $this ); |
|
2073 | + return apply_filters('give_payment_user_ip', $this->ip, $this->ID, $this); |
|
2074 | 2074 | } |
2075 | 2075 | |
2076 | 2076 | /** |
@@ -2082,7 +2082,7 @@ discard block |
||
2082 | 2082 | * @return int Payment donor ID. |
2083 | 2083 | */ |
2084 | 2084 | private function get_donor_id() { |
2085 | - return apply_filters( 'give_payment_customer_id', $this->customer_id, $this->ID, $this ); |
|
2085 | + return apply_filters('give_payment_customer_id', $this->customer_id, $this->ID, $this); |
|
2086 | 2086 | } |
2087 | 2087 | |
2088 | 2088 | /** |
@@ -2094,7 +2094,7 @@ discard block |
||
2094 | 2094 | * @return int Payment user ID. |
2095 | 2095 | */ |
2096 | 2096 | private function get_user_id() { |
2097 | - return apply_filters( 'give_payment_user_id', $this->user_id, $this->ID, $this ); |
|
2097 | + return apply_filters('give_payment_user_id', $this->user_id, $this->ID, $this); |
|
2098 | 2098 | } |
2099 | 2099 | |
2100 | 2100 | /** |
@@ -2106,7 +2106,7 @@ discard block |
||
2106 | 2106 | * @return string Payment donor email. |
2107 | 2107 | */ |
2108 | 2108 | private function get_email() { |
2109 | - return apply_filters( 'give_payment_user_email', $this->email, $this->ID, $this ); |
|
2109 | + return apply_filters('give_payment_user_email', $this->email, $this->ID, $this); |
|
2110 | 2110 | } |
2111 | 2111 | |
2112 | 2112 | /** |
@@ -2118,7 +2118,7 @@ discard block |
||
2118 | 2118 | * @return array Payment user info. |
2119 | 2119 | */ |
2120 | 2120 | private function get_user_info() { |
2121 | - return apply_filters( 'give_payment_meta_user_info', $this->user_info, $this->ID, $this ); |
|
2121 | + return apply_filters('give_payment_meta_user_info', $this->user_info, $this->ID, $this); |
|
2122 | 2122 | } |
2123 | 2123 | |
2124 | 2124 | /** |
@@ -2130,7 +2130,7 @@ discard block |
||
2130 | 2130 | * @return array Payment billing address. |
2131 | 2131 | */ |
2132 | 2132 | private function get_address() { |
2133 | - return apply_filters( 'give_payment_address', $this->address, $this->ID, $this ); |
|
2133 | + return apply_filters('give_payment_address', $this->address, $this->ID, $this); |
|
2134 | 2134 | } |
2135 | 2135 | |
2136 | 2136 | /** |
@@ -2142,7 +2142,7 @@ discard block |
||
2142 | 2142 | * @return string Payment key. |
2143 | 2143 | */ |
2144 | 2144 | private function get_key() { |
2145 | - return apply_filters( 'give_payment_key', $this->key, $this->ID, $this ); |
|
2145 | + return apply_filters('give_payment_key', $this->key, $this->ID, $this); |
|
2146 | 2146 | } |
2147 | 2147 | |
2148 | 2148 | /** |
@@ -2154,7 +2154,7 @@ discard block |
||
2154 | 2154 | * @return string Payment form id |
2155 | 2155 | */ |
2156 | 2156 | private function get_form_id() { |
2157 | - return apply_filters( 'give_payment_form_id', $this->form_id, $this->ID, $this ); |
|
2157 | + return apply_filters('give_payment_form_id', $this->form_id, $this->ID, $this); |
|
2158 | 2158 | } |
2159 | 2159 | |
2160 | 2160 | /** |
@@ -2166,7 +2166,7 @@ discard block |
||
2166 | 2166 | * @return int|string Payment number |
2167 | 2167 | */ |
2168 | 2168 | private function get_number() { |
2169 | - return apply_filters( 'give_payment_number', $this->number, $this->ID, $this ); |
|
2169 | + return apply_filters('give_payment_number', $this->number, $this->ID, $this); |
|
2170 | 2170 | } |
2171 | 2171 | |
2172 | 2172 | } |
@@ -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 | |
@@ -43,15 +43,15 @@ discard block |
||
43 | 43 | * |
44 | 44 | * @return array $payments Payments retrieved from the database |
45 | 45 | */ |
46 | -function give_get_payments( $args = array() ) { |
|
46 | +function give_get_payments($args = array()) { |
|
47 | 47 | |
48 | 48 | // Fallback to post objects to ensure backwards compatibility. |
49 | - if ( ! isset( $args['output'] ) ) { |
|
49 | + if ( ! isset($args['output'])) { |
|
50 | 50 | $args['output'] = 'posts'; |
51 | 51 | } |
52 | 52 | |
53 | - $args = apply_filters( 'give_get_payments_args', $args ); |
|
54 | - $payments = new Give_Payments_Query( $args ); |
|
53 | + $args = apply_filters('give_get_payments_args', $args); |
|
54 | + $payments = new Give_Payments_Query($args); |
|
55 | 55 | |
56 | 56 | return $payments->get_payments(); |
57 | 57 | } |
@@ -66,48 +66,48 @@ discard block |
||
66 | 66 | * |
67 | 67 | * @return mixed |
68 | 68 | */ |
69 | -function give_get_payment_by( $field = '', $value = '' ) { |
|
69 | +function give_get_payment_by($field = '', $value = '') { |
|
70 | 70 | |
71 | - if ( empty( $field ) || empty( $value ) ) { |
|
71 | + if (empty($field) || empty($value)) { |
|
72 | 72 | return false; |
73 | 73 | } |
74 | 74 | |
75 | - switch ( strtolower( $field ) ) { |
|
75 | + switch (strtolower($field)) { |
|
76 | 76 | |
77 | 77 | case 'id': |
78 | - $payment = new Give_Payment( $value ); |
|
78 | + $payment = new Give_Payment($value); |
|
79 | 79 | $id = $payment->ID; |
80 | 80 | |
81 | - if ( empty( $id ) ) { |
|
81 | + if (empty($id)) { |
|
82 | 82 | return false; |
83 | 83 | } |
84 | 84 | |
85 | 85 | break; |
86 | 86 | |
87 | 87 | case 'key': |
88 | - $payment = give_get_payments( array( |
|
88 | + $payment = give_get_payments(array( |
|
89 | 89 | 'meta_key' => '_give_payment_purchase_key', |
90 | 90 | 'meta_value' => $value, |
91 | 91 | 'posts_per_page' => 1, |
92 | 92 | 'fields' => 'ids', |
93 | - ) ); |
|
93 | + )); |
|
94 | 94 | |
95 | - if ( $payment ) { |
|
96 | - $payment = new Give_Payment( $payment[0] ); |
|
95 | + if ($payment) { |
|
96 | + $payment = new Give_Payment($payment[0]); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | break; |
100 | 100 | |
101 | 101 | case 'payment_number': |
102 | - $payment = give_get_payments( array( |
|
102 | + $payment = give_get_payments(array( |
|
103 | 103 | 'meta_key' => '_give_payment_number', |
104 | 104 | 'meta_value' => $value, |
105 | 105 | 'posts_per_page' => 1, |
106 | 106 | 'fields' => 'ids', |
107 | - ) ); |
|
107 | + )); |
|
108 | 108 | |
109 | - if ( $payment ) { |
|
110 | - $payment = new Give_Payment( $payment[0] ); |
|
109 | + if ($payment) { |
|
110 | + $payment = new Give_Payment($payment[0]); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | break; |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | return false; |
117 | 117 | }// End switch(). |
118 | 118 | |
119 | - if ( $payment ) { |
|
119 | + if ($payment) { |
|
120 | 120 | return $payment; |
121 | 121 | } |
122 | 122 | |
@@ -132,9 +132,9 @@ discard block |
||
132 | 132 | * |
133 | 133 | * @return int|bool Payment ID if payment is inserted, false otherwise. |
134 | 134 | */ |
135 | -function give_insert_payment( $payment_data = array() ) { |
|
135 | +function give_insert_payment($payment_data = array()) { |
|
136 | 136 | |
137 | - if ( empty( $payment_data ) ) { |
|
137 | + if (empty($payment_data)) { |
|
138 | 138 | return false; |
139 | 139 | } |
140 | 140 | |
@@ -145,25 +145,25 @@ discard block |
||
145 | 145 | * |
146 | 146 | * @param array $payment_data Arguments passed. |
147 | 147 | */ |
148 | - $payment_data = apply_filters( 'give_pre_insert_payment', $payment_data ); |
|
148 | + $payment_data = apply_filters('give_pre_insert_payment', $payment_data); |
|
149 | 149 | |
150 | 150 | $payment = new Give_Payment(); |
151 | - $gateway = ! empty( $payment_data['gateway'] ) ? $payment_data['gateway'] : ''; |
|
152 | - $gateway = empty( $gateway ) && isset( $_POST['give-gateway'] ) ? $_POST['give-gateway'] : $gateway; |
|
153 | - $form_id = isset( $payment_data['give_form_id'] ) ? $payment_data['give_form_id'] : 0; |
|
154 | - $price_id = give_get_payment_meta_price_id( $payment_data ); |
|
155 | - $form_title = isset( $payment_data['give_form_title'] ) ? $payment_data['give_form_title'] : get_the_title( $form_id ); |
|
151 | + $gateway = ! empty($payment_data['gateway']) ? $payment_data['gateway'] : ''; |
|
152 | + $gateway = empty($gateway) && isset($_POST['give-gateway']) ? $_POST['give-gateway'] : $gateway; |
|
153 | + $form_id = isset($payment_data['give_form_id']) ? $payment_data['give_form_id'] : 0; |
|
154 | + $price_id = give_get_payment_meta_price_id($payment_data); |
|
155 | + $form_title = isset($payment_data['give_form_title']) ? $payment_data['give_form_title'] : get_the_title($form_id); |
|
156 | 156 | |
157 | 157 | // Set properties. |
158 | 158 | $payment->total = $payment_data['price']; |
159 | - $payment->status = ! empty( $payment_data['status'] ) ? $payment_data['status'] : 'pending'; |
|
160 | - $payment->currency = ! empty( $payment_data['currency'] ) ? $payment_data['currency'] : give_get_currency( $payment_data['give_form_id'], $payment_data ); |
|
159 | + $payment->status = ! empty($payment_data['status']) ? $payment_data['status'] : 'pending'; |
|
160 | + $payment->currency = ! empty($payment_data['currency']) ? $payment_data['currency'] : give_get_currency($payment_data['give_form_id'], $payment_data); |
|
161 | 161 | $payment->user_info = $payment_data['user_info']; |
162 | 162 | $payment->gateway = $gateway; |
163 | 163 | $payment->form_title = $form_title; |
164 | 164 | $payment->form_id = $form_id; |
165 | 165 | $payment->price_id = $price_id; |
166 | - $payment->donor_id = ( ! empty( $payment_data['donor_id'] ) ? $payment_data['donor_id'] : '' ); |
|
166 | + $payment->donor_id = ( ! empty($payment_data['donor_id']) ? $payment_data['donor_id'] : ''); |
|
167 | 167 | $payment->user_id = $payment_data['user_info']['id']; |
168 | 168 | $payment->email = $payment_data['user_email']; |
169 | 169 | $payment->first_name = $payment_data['user_info']['first_name']; |
@@ -171,8 +171,8 @@ discard block |
||
171 | 171 | $payment->email = $payment_data['user_info']['email']; |
172 | 172 | $payment->ip = give_get_ip(); |
173 | 173 | $payment->key = $payment_data['purchase_key']; |
174 | - $payment->mode = ( ! empty( $payment_data['mode'] ) ? (string) $payment_data['mode'] : ( give_is_test_mode() ? 'test' : 'live' ) ); |
|
175 | - $payment->parent_payment = ! empty( $payment_data['parent'] ) ? absint( $payment_data['parent'] ) : ''; |
|
174 | + $payment->mode = ( ! empty($payment_data['mode']) ? (string) $payment_data['mode'] : (give_is_test_mode() ? 'test' : 'live')); |
|
175 | + $payment->parent_payment = ! empty($payment_data['parent']) ? absint($payment_data['parent']) : ''; |
|
176 | 176 | |
177 | 177 | // Add the donation. |
178 | 178 | $args = array( |
@@ -180,19 +180,19 @@ discard block |
||
180 | 180 | 'price_id' => $payment->price_id, |
181 | 181 | ); |
182 | 182 | |
183 | - $payment->add_donation( $payment->form_id, $args ); |
|
183 | + $payment->add_donation($payment->form_id, $args); |
|
184 | 184 | |
185 | 185 | |
186 | 186 | // Set date if present. |
187 | - if ( isset( $payment_data['post_date'] ) ) { |
|
187 | + if (isset($payment_data['post_date'])) { |
|
188 | 188 | $payment->date = $payment_data['post_date']; |
189 | 189 | } |
190 | 190 | |
191 | 191 | // Handle sequential payments. |
192 | - if ( give_get_option( 'enable_sequential' ) ) { |
|
192 | + if (give_get_option('enable_sequential')) { |
|
193 | 193 | $number = give_get_next_payment_number(); |
194 | - $payment->number = give_format_payment_number( $number ); |
|
195 | - update_option( 'give_last_payment_number', $number ); |
|
194 | + $payment->number = give_format_payment_number($number); |
|
195 | + update_option('give_last_payment_number', $number); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | // Save payment. |
@@ -206,10 +206,10 @@ discard block |
||
206 | 206 | * @param int $payment_id The payment ID. |
207 | 207 | * @param array $payment_data Arguments passed. |
208 | 208 | */ |
209 | - do_action( 'give_insert_payment', $payment->ID, $payment_data ); |
|
209 | + do_action('give_insert_payment', $payment->ID, $payment_data); |
|
210 | 210 | |
211 | 211 | // Return payment ID upon success. |
212 | - if ( ! empty( $payment->ID ) ) { |
|
212 | + if ( ! empty($payment->ID)) { |
|
213 | 213 | return $payment->ID; |
214 | 214 | } |
215 | 215 | |
@@ -225,10 +225,10 @@ discard block |
||
225 | 225 | * |
226 | 226 | * @return bool|int |
227 | 227 | */ |
228 | -function give_create_payment( $payment_data ) { |
|
228 | +function give_create_payment($payment_data) { |
|
229 | 229 | |
230 | - $form_id = intval( $payment_data['post_data']['give-form-id'] ); |
|
231 | - $price_id = isset( $payment_data['post_data']['give-price-id'] ) ? $payment_data['post_data']['give-price-id'] : ''; |
|
230 | + $form_id = intval($payment_data['post_data']['give-form-id']); |
|
231 | + $price_id = isset($payment_data['post_data']['give-price-id']) ? $payment_data['post_data']['give-price-id'] : ''; |
|
232 | 232 | |
233 | 233 | // Collect payment data. |
234 | 234 | $insert_payment_data = array( |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | 'date' => $payment_data['date'], |
240 | 240 | 'user_email' => $payment_data['user_email'], |
241 | 241 | 'purchase_key' => $payment_data['purchase_key'], |
242 | - 'currency' => give_get_currency( $form_id, $payment_data ), |
|
242 | + 'currency' => give_get_currency($form_id, $payment_data), |
|
243 | 243 | 'user_info' => $payment_data['user_info'], |
244 | 244 | 'status' => 'pending', |
245 | 245 | 'gateway' => 'paypal', |
@@ -252,10 +252,10 @@ discard block |
||
252 | 252 | * |
253 | 253 | * @param array $insert_payment_data |
254 | 254 | */ |
255 | - $insert_payment_data = apply_filters( 'give_create_payment', $insert_payment_data ); |
|
255 | + $insert_payment_data = apply_filters('give_create_payment', $insert_payment_data); |
|
256 | 256 | |
257 | 257 | // Record the pending payment. |
258 | - return give_insert_payment( $insert_payment_data ); |
|
258 | + return give_insert_payment($insert_payment_data); |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | /** |
@@ -268,12 +268,12 @@ discard block |
||
268 | 268 | * |
269 | 269 | * @return bool |
270 | 270 | */ |
271 | -function give_update_payment_status( $payment_id, $new_status = 'publish' ) { |
|
271 | +function give_update_payment_status($payment_id, $new_status = 'publish') { |
|
272 | 272 | |
273 | 273 | $updated = false; |
274 | - $payment = new Give_Payment( $payment_id ); |
|
274 | + $payment = new Give_Payment($payment_id); |
|
275 | 275 | |
276 | - if ( $payment && $payment->ID > 0 ) { |
|
276 | + if ($payment && $payment->ID > 0) { |
|
277 | 277 | |
278 | 278 | $payment->status = $new_status; |
279 | 279 | $updated = $payment->save(); |
@@ -295,38 +295,38 @@ discard block |
||
295 | 295 | * |
296 | 296 | * @return void |
297 | 297 | */ |
298 | -function give_delete_donation( $payment_id = 0, $update_donor = true ) { |
|
298 | +function give_delete_donation($payment_id = 0, $update_donor = true) { |
|
299 | 299 | global $give_logs; |
300 | 300 | |
301 | - $payment = new Give_Payment( $payment_id ); |
|
302 | - $amount = give_get_payment_amount( $payment_id ); |
|
301 | + $payment = new Give_Payment($payment_id); |
|
302 | + $amount = give_get_payment_amount($payment_id); |
|
303 | 303 | $status = $payment->post_status; |
304 | - $donor_id = give_get_payment_donor_id( $payment_id ); |
|
305 | - $donor = new Give_Donor( $donor_id ); |
|
304 | + $donor_id = give_get_payment_donor_id($payment_id); |
|
305 | + $donor = new Give_Donor($donor_id); |
|
306 | 306 | |
307 | 307 | // Only undo donations that aren't these statuses. |
308 | - $dont_undo_statuses = apply_filters( 'give_undo_donation_statuses', array( |
|
308 | + $dont_undo_statuses = apply_filters('give_undo_donation_statuses', array( |
|
309 | 309 | 'pending', |
310 | 310 | 'cancelled', |
311 | - ) ); |
|
311 | + )); |
|
312 | 312 | |
313 | - if ( ! in_array( $status, $dont_undo_statuses ) ) { |
|
314 | - give_undo_donation( $payment_id ); |
|
313 | + if ( ! in_array($status, $dont_undo_statuses)) { |
|
314 | + give_undo_donation($payment_id); |
|
315 | 315 | } |
316 | 316 | |
317 | - if ( $status == 'publish' ) { |
|
317 | + if ($status == 'publish') { |
|
318 | 318 | |
319 | 319 | // Only decrease earnings if they haven't already been decreased (or were never increased for this payment). |
320 | - give_decrease_total_earnings( $amount ); |
|
320 | + give_decrease_total_earnings($amount); |
|
321 | 321 | |
322 | 322 | // @todo: Refresh only range related stat cache |
323 | 323 | give_delete_donation_stats(); |
324 | 324 | |
325 | - if ( $donor->id && $update_donor ) { |
|
325 | + if ($donor->id && $update_donor) { |
|
326 | 326 | |
327 | 327 | // Decrement the stats for the donor. |
328 | 328 | $donor->decrease_donation_count(); |
329 | - $donor->decrease_value( $amount ); |
|
329 | + $donor->decrease_value($amount); |
|
330 | 330 | |
331 | 331 | } |
332 | 332 | } |
@@ -338,25 +338,25 @@ discard block |
||
338 | 338 | * |
339 | 339 | * @param int $payment_id Payment ID. |
340 | 340 | */ |
341 | - do_action( 'give_payment_delete', $payment_id ); |
|
341 | + do_action('give_payment_delete', $payment_id); |
|
342 | 342 | |
343 | - if ( $donor->id && $update_donor ) { |
|
343 | + if ($donor->id && $update_donor) { |
|
344 | 344 | |
345 | 345 | // Remove the payment ID from the donor. |
346 | - $donor->remove_payment( $payment_id ); |
|
346 | + $donor->remove_payment($payment_id); |
|
347 | 347 | |
348 | 348 | } |
349 | 349 | |
350 | 350 | // Remove the payment. |
351 | - wp_delete_post( $payment_id, true ); |
|
351 | + wp_delete_post($payment_id, true); |
|
352 | 352 | |
353 | 353 | // Remove related sale log entries. |
354 | - $give_logs->delete_logs( null, 'sale', array( |
|
354 | + $give_logs->delete_logs(null, 'sale', array( |
|
355 | 355 | array( |
356 | 356 | 'key' => '_give_log_payment_id', |
357 | 357 | 'value' => $payment_id, |
358 | 358 | ), |
359 | - ) ); |
|
359 | + )); |
|
360 | 360 | |
361 | 361 | /** |
362 | 362 | * Fires after payment deleted. |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | * |
366 | 366 | * @param int $payment_id Payment ID. |
367 | 367 | */ |
368 | - do_action( 'give_payment_deleted', $payment_id ); |
|
368 | + do_action('give_payment_deleted', $payment_id); |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | /** |
@@ -380,20 +380,20 @@ discard block |
||
380 | 380 | * |
381 | 381 | * @return void |
382 | 382 | */ |
383 | -function give_undo_donation( $payment_id ) { |
|
383 | +function give_undo_donation($payment_id) { |
|
384 | 384 | |
385 | - $payment = new Give_Payment( $payment_id ); |
|
385 | + $payment = new Give_Payment($payment_id); |
|
386 | 386 | |
387 | - $maybe_decrease_earnings = apply_filters( 'give_decrease_earnings_on_undo', true, $payment, $payment->form_id ); |
|
388 | - if ( true === $maybe_decrease_earnings ) { |
|
387 | + $maybe_decrease_earnings = apply_filters('give_decrease_earnings_on_undo', true, $payment, $payment->form_id); |
|
388 | + if (true === $maybe_decrease_earnings) { |
|
389 | 389 | // Decrease earnings. |
390 | - give_decrease_earnings( $payment->form_id, $payment->total ); |
|
390 | + give_decrease_earnings($payment->form_id, $payment->total); |
|
391 | 391 | } |
392 | 392 | |
393 | - $maybe_decrease_donations = apply_filters( 'give_decrease_donations_on_undo', true, $payment, $payment->form_id ); |
|
394 | - if ( true === $maybe_decrease_donations ) { |
|
393 | + $maybe_decrease_donations = apply_filters('give_decrease_donations_on_undo', true, $payment, $payment->form_id); |
|
394 | + if (true === $maybe_decrease_donations) { |
|
395 | 395 | // Decrease donation count. |
396 | - give_decrease_donation_count( $payment->form_id ); |
|
396 | + give_decrease_donation_count($payment->form_id); |
|
397 | 397 | } |
398 | 398 | |
399 | 399 | } |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | * |
411 | 411 | * @return object $stats Contains the number of payments per payment status. |
412 | 412 | */ |
413 | -function give_count_payments( $args = array() ) { |
|
413 | +function give_count_payments($args = array()) { |
|
414 | 414 | |
415 | 415 | global $wpdb; |
416 | 416 | |
@@ -422,18 +422,18 @@ discard block |
||
422 | 422 | 'form_id' => null, |
423 | 423 | ); |
424 | 424 | |
425 | - $args = wp_parse_args( $args, $defaults ); |
|
425 | + $args = wp_parse_args($args, $defaults); |
|
426 | 426 | |
427 | 427 | $select = 'SELECT p.post_status,count( * ) AS num_posts'; |
428 | 428 | $join = ''; |
429 | - $where = "WHERE p.post_type = 'give_payment' AND p.post_status IN ('" . implode( "','", give_get_payment_status_keys() ) . "')"; |
|
429 | + $where = "WHERE p.post_type = 'give_payment' AND p.post_status IN ('".implode("','", give_get_payment_status_keys())."')"; |
|
430 | 430 | |
431 | 431 | // Count payments for a specific user. |
432 | - if ( ! empty( $args['user'] ) ) { |
|
432 | + if ( ! empty($args['user'])) { |
|
433 | 433 | |
434 | - if ( is_email( $args['user'] ) ) { |
|
434 | + if (is_email($args['user'])) { |
|
435 | 435 | $field = 'email'; |
436 | - } elseif ( is_numeric( $args['user'] ) ) { |
|
436 | + } elseif (is_numeric($args['user'])) { |
|
437 | 437 | $field = 'id'; |
438 | 438 | } else { |
439 | 439 | $field = ''; |
@@ -441,107 +441,107 @@ discard block |
||
441 | 441 | |
442 | 442 | $join = "LEFT JOIN $wpdb->postmeta m ON (p.ID = m.post_id)"; |
443 | 443 | |
444 | - if ( ! empty( $field ) ) { |
|
444 | + if ( ! empty($field)) { |
|
445 | 445 | $where .= " |
446 | 446 | AND m.meta_key = '_give_payment_user_{$field}' |
447 | 447 | AND m.meta_value = '{$args['user']}'"; |
448 | 448 | } |
449 | - } elseif ( ! empty( $args['donor'] ) ) { |
|
449 | + } elseif ( ! empty($args['donor'])) { |
|
450 | 450 | |
451 | - $join = "LEFT JOIN $wpdb->postmeta m ON (p.ID = m.post_id)"; |
|
451 | + $join = "LEFT JOIN $wpdb->postmeta m ON (p.ID = m.post_id)"; |
|
452 | 452 | $where .= " |
453 | 453 | AND m.meta_key = '_give_payment_customer_id' |
454 | 454 | AND m.meta_value = '{$args['donor']}'"; |
455 | 455 | |
456 | 456 | // Count payments for a search. |
457 | - } elseif ( ! empty( $args['s'] ) ) { |
|
457 | + } elseif ( ! empty($args['s'])) { |
|
458 | 458 | |
459 | - if ( is_email( $args['s'] ) || strlen( $args['s'] ) == 32 ) { |
|
459 | + if (is_email($args['s']) || strlen($args['s']) == 32) { |
|
460 | 460 | |
461 | - if ( is_email( $args['s'] ) ) { |
|
461 | + if (is_email($args['s'])) { |
|
462 | 462 | $field = '_give_payment_user_email'; |
463 | 463 | } else { |
464 | 464 | $field = '_give_payment_purchase_key'; |
465 | 465 | } |
466 | 466 | |
467 | - $join = "LEFT JOIN $wpdb->postmeta m ON (p.ID = m.post_id)"; |
|
468 | - $where .= $wpdb->prepare( ' |
|
467 | + $join = "LEFT JOIN $wpdb->postmeta m ON (p.ID = m.post_id)"; |
|
468 | + $where .= $wpdb->prepare(' |
|
469 | 469 | AND m.meta_key = %s |
470 | - AND m.meta_value = %s', $field, $args['s'] ); |
|
470 | + AND m.meta_value = %s', $field, $args['s']); |
|
471 | 471 | |
472 | - } elseif ( '#' == substr( $args['s'], 0, 1 ) ) { |
|
472 | + } elseif ('#' == substr($args['s'], 0, 1)) { |
|
473 | 473 | |
474 | - $search = str_replace( '#:', '', $args['s'] ); |
|
475 | - $search = str_replace( '#', '', $search ); |
|
474 | + $search = str_replace('#:', '', $args['s']); |
|
475 | + $search = str_replace('#', '', $search); |
|
476 | 476 | |
477 | 477 | $select = 'SELECT p.post_status,count( * ) AS num_posts '; |
478 | 478 | $join = ''; |
479 | - $where = $wpdb->prepare( 'WHERE p.post_type=%s AND p.ID = %d ', 'give_payment', $search ); |
|
479 | + $where = $wpdb->prepare('WHERE p.post_type=%s AND p.ID = %d ', 'give_payment', $search); |
|
480 | 480 | |
481 | - } elseif ( is_numeric( $args['s'] ) ) { |
|
481 | + } elseif (is_numeric($args['s'])) { |
|
482 | 482 | |
483 | - $join = "LEFT JOIN $wpdb->postmeta m ON (p.ID = m.post_id)"; |
|
484 | - $where .= $wpdb->prepare( " |
|
483 | + $join = "LEFT JOIN $wpdb->postmeta m ON (p.ID = m.post_id)"; |
|
484 | + $where .= $wpdb->prepare(" |
|
485 | 485 | AND m.meta_key = '_give_payment_user_id' |
486 | - AND m.meta_value = %d", $args['s'] ); |
|
486 | + AND m.meta_value = %d", $args['s']); |
|
487 | 487 | |
488 | 488 | } else { |
489 | - $search = $wpdb->esc_like( $args['s'] ); |
|
490 | - $search = '%' . $search . '%'; |
|
489 | + $search = $wpdb->esc_like($args['s']); |
|
490 | + $search = '%'.$search.'%'; |
|
491 | 491 | |
492 | - $where .= $wpdb->prepare( 'AND ((p.post_title LIKE %s) OR (p.post_content LIKE %s))', $search, $search ); |
|
492 | + $where .= $wpdb->prepare('AND ((p.post_title LIKE %s) OR (p.post_content LIKE %s))', $search, $search); |
|
493 | 493 | }// End if(). |
494 | 494 | }// End if(). |
495 | 495 | |
496 | - if ( ! empty( $args['form_id'] ) && is_numeric( $args['form_id'] ) ) { |
|
496 | + if ( ! empty($args['form_id']) && is_numeric($args['form_id'])) { |
|
497 | 497 | |
498 | - $join = "LEFT JOIN $wpdb->postmeta m ON (p.ID = m.post_id)"; |
|
499 | - $where .= $wpdb->prepare( ' |
|
498 | + $join = "LEFT JOIN $wpdb->postmeta m ON (p.ID = m.post_id)"; |
|
499 | + $where .= $wpdb->prepare(' |
|
500 | 500 | AND m.meta_key = %s |
501 | - AND m.meta_value = %s', '_give_payment_form_id', $args['form_id'] ); |
|
501 | + AND m.meta_value = %s', '_give_payment_form_id', $args['form_id']); |
|
502 | 502 | } |
503 | 503 | |
504 | 504 | // Limit payments count by date. |
505 | - if ( ! empty( $args['start-date'] ) && false !== strpos( $args['start-date'], '/' ) ) { |
|
505 | + if ( ! empty($args['start-date']) && false !== strpos($args['start-date'], '/')) { |
|
506 | 506 | |
507 | - $date_parts = explode( '/', $args['start-date'] ); |
|
508 | - $month = ! empty( $date_parts[0] ) && is_numeric( $date_parts[0] ) ? $date_parts[0] : 0; |
|
509 | - $day = ! empty( $date_parts[1] ) && is_numeric( $date_parts[1] ) ? $date_parts[1] : 0; |
|
510 | - $year = ! empty( $date_parts[2] ) && is_numeric( $date_parts[2] ) ? $date_parts[2] : 0; |
|
507 | + $date_parts = explode('/', $args['start-date']); |
|
508 | + $month = ! empty($date_parts[0]) && is_numeric($date_parts[0]) ? $date_parts[0] : 0; |
|
509 | + $day = ! empty($date_parts[1]) && is_numeric($date_parts[1]) ? $date_parts[1] : 0; |
|
510 | + $year = ! empty($date_parts[2]) && is_numeric($date_parts[2]) ? $date_parts[2] : 0; |
|
511 | 511 | |
512 | - $is_date = checkdate( $month, $day, $year ); |
|
513 | - if ( false !== $is_date ) { |
|
512 | + $is_date = checkdate($month, $day, $year); |
|
513 | + if (false !== $is_date) { |
|
514 | 514 | |
515 | - $date = new DateTime( $args['start-date'] ); |
|
516 | - $where .= $wpdb->prepare( " AND p.post_date >= '%s'", $date->format( 'Y-m-d' ) ); |
|
515 | + $date = new DateTime($args['start-date']); |
|
516 | + $where .= $wpdb->prepare(" AND p.post_date >= '%s'", $date->format('Y-m-d')); |
|
517 | 517 | |
518 | 518 | } |
519 | 519 | |
520 | 520 | // Fixes an issue with the payments list table counts when no end date is specified (with stats class). |
521 | - if ( empty( $args['end-date'] ) ) { |
|
521 | + if (empty($args['end-date'])) { |
|
522 | 522 | $args['end-date'] = $args['start-date']; |
523 | 523 | } |
524 | 524 | } |
525 | 525 | |
526 | - if ( ! empty( $args['end-date'] ) && false !== strpos( $args['end-date'], '/' ) ) { |
|
526 | + if ( ! empty($args['end-date']) && false !== strpos($args['end-date'], '/')) { |
|
527 | 527 | |
528 | - $date_parts = explode( '/', $args['end-date'] ); |
|
528 | + $date_parts = explode('/', $args['end-date']); |
|
529 | 529 | |
530 | - $month = ! empty( $date_parts[0] ) ? $date_parts[0] : 0; |
|
531 | - $day = ! empty( $date_parts[1] ) ? $date_parts[1] : 0; |
|
532 | - $year = ! empty( $date_parts[2] ) ? $date_parts[2] : 0; |
|
530 | + $month = ! empty($date_parts[0]) ? $date_parts[0] : 0; |
|
531 | + $day = ! empty($date_parts[1]) ? $date_parts[1] : 0; |
|
532 | + $year = ! empty($date_parts[2]) ? $date_parts[2] : 0; |
|
533 | 533 | |
534 | - $is_date = checkdate( $month, $day, $year ); |
|
535 | - if ( false !== $is_date ) { |
|
534 | + $is_date = checkdate($month, $day, $year); |
|
535 | + if (false !== $is_date) { |
|
536 | 536 | |
537 | - $date = new DateTime( $args['end-date'] ); |
|
538 | - $where .= $wpdb->prepare( " AND p.post_date <= '%s'", $date->format( 'Y-m-d' ) ); |
|
537 | + $date = new DateTime($args['end-date']); |
|
538 | + $where .= $wpdb->prepare(" AND p.post_date <= '%s'", $date->format('Y-m-d')); |
|
539 | 539 | |
540 | 540 | } |
541 | 541 | } |
542 | 542 | |
543 | - $where = apply_filters( 'give_count_payments_where', $where ); |
|
544 | - $join = apply_filters( 'give_count_payments_join', $join ); |
|
543 | + $where = apply_filters('give_count_payments_where', $where); |
|
544 | + $join = apply_filters('give_count_payments_join', $join); |
|
545 | 545 | |
546 | 546 | $query = "$select |
547 | 547 | FROM $wpdb->posts p |
@@ -550,36 +550,36 @@ discard block |
||
550 | 550 | GROUP BY p.post_status |
551 | 551 | "; |
552 | 552 | |
553 | - $cache_key = md5( $query ); |
|
553 | + $cache_key = md5($query); |
|
554 | 554 | |
555 | - $count = wp_cache_get( $cache_key, 'counts' ); |
|
556 | - if ( false !== $count ) { |
|
555 | + $count = wp_cache_get($cache_key, 'counts'); |
|
556 | + if (false !== $count) { |
|
557 | 557 | return $count; |
558 | 558 | } |
559 | 559 | |
560 | - $count = $wpdb->get_results( $query, ARRAY_A ); |
|
560 | + $count = $wpdb->get_results($query, ARRAY_A); |
|
561 | 561 | |
562 | 562 | $stats = array(); |
563 | 563 | $statuses = get_post_stati(); |
564 | - if ( isset( $statuses['private'] ) && empty( $args['s'] ) ) { |
|
565 | - unset( $statuses['private'] ); |
|
564 | + if (isset($statuses['private']) && empty($args['s'])) { |
|
565 | + unset($statuses['private']); |
|
566 | 566 | } |
567 | 567 | |
568 | - foreach ( $statuses as $state ) { |
|
569 | - $stats[ $state ] = 0; |
|
568 | + foreach ($statuses as $state) { |
|
569 | + $stats[$state] = 0; |
|
570 | 570 | } |
571 | 571 | |
572 | - foreach ( (array) $count as $row ) { |
|
572 | + foreach ((array) $count as $row) { |
|
573 | 573 | |
574 | - if ( 'private' == $row['post_status'] && empty( $args['s'] ) ) { |
|
574 | + if ('private' == $row['post_status'] && empty($args['s'])) { |
|
575 | 575 | continue; |
576 | 576 | } |
577 | 577 | |
578 | - $stats[ $row['post_status'] ] = $row['num_posts']; |
|
578 | + $stats[$row['post_status']] = $row['num_posts']; |
|
579 | 579 | } |
580 | 580 | |
581 | 581 | $stats = (object) $stats; |
582 | - wp_cache_set( $cache_key, $stats, 'counts' ); |
|
582 | + wp_cache_set($cache_key, $stats, 'counts'); |
|
583 | 583 | |
584 | 584 | return $stats; |
585 | 585 | } |
@@ -594,11 +594,11 @@ discard block |
||
594 | 594 | * |
595 | 595 | * @return bool $exists True if payment exists, false otherwise. |
596 | 596 | */ |
597 | -function give_check_for_existing_payment( $payment_id ) { |
|
597 | +function give_check_for_existing_payment($payment_id) { |
|
598 | 598 | $exists = false; |
599 | - $payment = new Give_Payment( $payment_id ); |
|
599 | + $payment = new Give_Payment($payment_id); |
|
600 | 600 | |
601 | - if ( $payment_id === $payment->ID && 'publish' === $payment->status ) { |
|
601 | + if ($payment_id === $payment->ID && 'publish' === $payment->status) { |
|
602 | 602 | $exists = true; |
603 | 603 | } |
604 | 604 | |
@@ -616,41 +616,41 @@ discard block |
||
616 | 616 | * |
617 | 617 | * @return bool|mixed True if payment status exists, false otherwise. |
618 | 618 | */ |
619 | -function give_get_payment_status( $payment, $return_label = false ) { |
|
619 | +function give_get_payment_status($payment, $return_label = false) { |
|
620 | 620 | |
621 | - if ( is_numeric( $payment ) ) { |
|
621 | + if (is_numeric($payment)) { |
|
622 | 622 | |
623 | - $payment = new Give_Payment( $payment ); |
|
623 | + $payment = new Give_Payment($payment); |
|
624 | 624 | |
625 | - if ( ! $payment->ID > 0 ) { |
|
625 | + if ( ! $payment->ID > 0) { |
|
626 | 626 | return false; |
627 | 627 | } |
628 | 628 | |
629 | 629 | } |
630 | 630 | |
631 | - if ( ! is_object( $payment ) || ! isset( $payment->post_status ) ) { |
|
631 | + if ( ! is_object($payment) || ! isset($payment->post_status)) { |
|
632 | 632 | return false; |
633 | 633 | } |
634 | 634 | |
635 | 635 | $statuses = give_get_payment_statuses(); |
636 | 636 | |
637 | - if ( ! is_array( $statuses ) || empty( $statuses ) ) { |
|
637 | + if ( ! is_array($statuses) || empty($statuses)) { |
|
638 | 638 | return false; |
639 | 639 | } |
640 | 640 | |
641 | 641 | // Get payment object if not already given. |
642 | - $payment = $payment instanceof Give_Payment ? $payment : new Give_Payment( $payment->ID ); |
|
642 | + $payment = $payment instanceof Give_Payment ? $payment : new Give_Payment($payment->ID); |
|
643 | 643 | |
644 | - if ( array_key_exists( $payment->status, $statuses ) ) { |
|
645 | - if ( true === $return_label ) { |
|
644 | + if (array_key_exists($payment->status, $statuses)) { |
|
645 | + if (true === $return_label) { |
|
646 | 646 | // Return translated status label. |
647 | - return $statuses[ $payment->status ]; |
|
647 | + return $statuses[$payment->status]; |
|
648 | 648 | } else { |
649 | 649 | // Account that our 'publish' status is labeled 'Complete' |
650 | 650 | $post_status = 'publish' == $payment->status ? 'Complete' : $payment->post_status; |
651 | 651 | |
652 | 652 | // Make sure we're matching cases, since they matter |
653 | - return array_search( strtolower( $post_status ), array_map( 'strtolower', $statuses ) ); |
|
653 | + return array_search(strtolower($post_status), array_map('strtolower', $statuses)); |
|
654 | 654 | } |
655 | 655 | } |
656 | 656 | |
@@ -666,18 +666,18 @@ discard block |
||
666 | 666 | */ |
667 | 667 | function give_get_payment_statuses() { |
668 | 668 | $payment_statuses = array( |
669 | - 'pending' => __( 'Pending', 'give' ), |
|
670 | - 'publish' => __( 'Complete', 'give' ), |
|
671 | - 'refunded' => __( 'Refunded', 'give' ), |
|
672 | - 'failed' => __( 'Failed', 'give' ), |
|
673 | - 'cancelled' => __( 'Cancelled', 'give' ), |
|
674 | - 'abandoned' => __( 'Abandoned', 'give' ), |
|
675 | - 'preapproval' => __( 'Pre-Approved', 'give' ), |
|
676 | - 'processing' => __( 'Processing', 'give' ), |
|
677 | - 'revoked' => __( 'Revoked', 'give' ), |
|
669 | + 'pending' => __('Pending', 'give'), |
|
670 | + 'publish' => __('Complete', 'give'), |
|
671 | + 'refunded' => __('Refunded', 'give'), |
|
672 | + 'failed' => __('Failed', 'give'), |
|
673 | + 'cancelled' => __('Cancelled', 'give'), |
|
674 | + 'abandoned' => __('Abandoned', 'give'), |
|
675 | + 'preapproval' => __('Pre-Approved', 'give'), |
|
676 | + 'processing' => __('Processing', 'give'), |
|
677 | + 'revoked' => __('Revoked', 'give'), |
|
678 | 678 | ); |
679 | 679 | |
680 | - return apply_filters( 'give_payment_statuses', $payment_statuses ); |
|
680 | + return apply_filters('give_payment_statuses', $payment_statuses); |
|
681 | 681 | } |
682 | 682 | |
683 | 683 | /** |
@@ -690,10 +690,10 @@ discard block |
||
690 | 690 | * @return array $payment_status All the available payment statuses. |
691 | 691 | */ |
692 | 692 | function give_get_payment_status_keys() { |
693 | - $statuses = array_keys( give_get_payment_statuses() ); |
|
694 | - asort( $statuses ); |
|
693 | + $statuses = array_keys(give_get_payment_statuses()); |
|
694 | + asort($statuses); |
|
695 | 695 | |
696 | - return array_values( $statuses ); |
|
696 | + return array_values($statuses); |
|
697 | 697 | } |
698 | 698 | |
699 | 699 | /** |
@@ -708,7 +708,7 @@ discard block |
||
708 | 708 | * |
709 | 709 | * @return int $earnings Earnings |
710 | 710 | */ |
711 | -function give_get_earnings_by_date( $day = null, $month_num, $year = null, $hour = null ) { |
|
711 | +function give_get_earnings_by_date($day = null, $month_num, $year = null, $hour = null) { |
|
712 | 712 | |
713 | 713 | // This is getting deprecated soon. Use Give_Payment_Stats with the get_earnings() method instead. |
714 | 714 | global $wpdb; |
@@ -718,41 +718,41 @@ discard block |
||
718 | 718 | 'nopaging' => true, |
719 | 719 | 'year' => $year, |
720 | 720 | 'monthnum' => $month_num, |
721 | - 'post_status' => array( 'publish' ), |
|
721 | + 'post_status' => array('publish'), |
|
722 | 722 | 'fields' => 'ids', |
723 | 723 | 'update_post_term_cache' => false, |
724 | 724 | ); |
725 | - if ( ! empty( $day ) ) { |
|
725 | + if ( ! empty($day)) { |
|
726 | 726 | $args['day'] = $day; |
727 | 727 | } |
728 | 728 | |
729 | - if ( ! empty( $hour ) ) { |
|
729 | + if ( ! empty($hour)) { |
|
730 | 730 | $args['hour'] = $hour; |
731 | 731 | } |
732 | 732 | |
733 | - $args = apply_filters( 'give_get_earnings_by_date_args', $args ); |
|
734 | - $key = Give_Cache::get_key( 'give_stats', $args ); |
|
733 | + $args = apply_filters('give_get_earnings_by_date_args', $args); |
|
734 | + $key = Give_Cache::get_key('give_stats', $args); |
|
735 | 735 | |
736 | - if ( ! empty( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'], 'give-refresh-reports' ) ) { |
|
736 | + if ( ! empty($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'give-refresh-reports')) { |
|
737 | 737 | $earnings = false; |
738 | 738 | } else { |
739 | - $earnings = Give_Cache::get( $key ); |
|
739 | + $earnings = Give_Cache::get($key); |
|
740 | 740 | } |
741 | 741 | |
742 | - if ( false === $earnings ) { |
|
743 | - $donations = get_posts( $args ); |
|
742 | + if (false === $earnings) { |
|
743 | + $donations = get_posts($args); |
|
744 | 744 | $earnings = 0; |
745 | - if ( $donations ) { |
|
746 | - $donations = implode( ',', $donations ); |
|
745 | + if ($donations) { |
|
746 | + $donations = implode(',', $donations); |
|
747 | 747 | |
748 | - $earnings = $wpdb->get_var( "SELECT SUM(meta_value) FROM $wpdb->postmeta WHERE meta_key = '_give_payment_total' AND post_id IN ({$donations})" ); |
|
748 | + $earnings = $wpdb->get_var("SELECT SUM(meta_value) FROM $wpdb->postmeta WHERE meta_key = '_give_payment_total' AND post_id IN ({$donations})"); |
|
749 | 749 | |
750 | 750 | } |
751 | 751 | // Cache the results for one hour. |
752 | - Give_Cache::set( $key, $earnings, HOUR_IN_SECONDS ); |
|
752 | + Give_Cache::set($key, $earnings, HOUR_IN_SECONDS); |
|
753 | 753 | } |
754 | 754 | |
755 | - return round( $earnings, 2 ); |
|
755 | + return round($earnings, 2); |
|
756 | 756 | } |
757 | 757 | |
758 | 758 | /** |
@@ -767,7 +767,7 @@ discard block |
||
767 | 767 | * |
768 | 768 | * @return int $count Sales |
769 | 769 | */ |
770 | -function give_get_sales_by_date( $day = null, $month_num = null, $year = null, $hour = null ) { |
|
770 | +function give_get_sales_by_date($day = null, $month_num = null, $year = null, $hour = null) { |
|
771 | 771 | |
772 | 772 | // This is getting deprecated soon. Use Give_Payment_Stats with the get_sales() method instead. |
773 | 773 | $args = array( |
@@ -775,14 +775,14 @@ discard block |
||
775 | 775 | 'nopaging' => true, |
776 | 776 | 'year' => $year, |
777 | 777 | 'fields' => 'ids', |
778 | - 'post_status' => array( 'publish' ), |
|
778 | + 'post_status' => array('publish'), |
|
779 | 779 | 'update_post_meta_cache' => false, |
780 | 780 | 'update_post_term_cache' => false, |
781 | 781 | ); |
782 | 782 | |
783 | - $show_free = apply_filters( 'give_sales_by_date_show_free', true, $args ); |
|
783 | + $show_free = apply_filters('give_sales_by_date_show_free', true, $args); |
|
784 | 784 | |
785 | - if ( false === $show_free ) { |
|
785 | + if (false === $show_free) { |
|
786 | 786 | $args['meta_query'] = array( |
787 | 787 | array( |
788 | 788 | 'key' => '_give_payment_total', |
@@ -793,33 +793,33 @@ discard block |
||
793 | 793 | ); |
794 | 794 | } |
795 | 795 | |
796 | - if ( ! empty( $month_num ) ) { |
|
796 | + if ( ! empty($month_num)) { |
|
797 | 797 | $args['monthnum'] = $month_num; |
798 | 798 | } |
799 | 799 | |
800 | - if ( ! empty( $day ) ) { |
|
800 | + if ( ! empty($day)) { |
|
801 | 801 | $args['day'] = $day; |
802 | 802 | } |
803 | 803 | |
804 | - if ( ! empty( $hour ) ) { |
|
804 | + if ( ! empty($hour)) { |
|
805 | 805 | $args['hour'] = $hour; |
806 | 806 | } |
807 | 807 | |
808 | - $args = apply_filters( 'give_get_sales_by_date_args', $args ); |
|
808 | + $args = apply_filters('give_get_sales_by_date_args', $args); |
|
809 | 809 | |
810 | - $key = Give_Cache::get_key( 'give_stats', $args ); |
|
810 | + $key = Give_Cache::get_key('give_stats', $args); |
|
811 | 811 | |
812 | - if ( ! empty( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'], 'give-refresh-reports' ) ) { |
|
812 | + if ( ! empty($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'give-refresh-reports')) { |
|
813 | 813 | $count = false; |
814 | 814 | } else { |
815 | - $count = Give_Cache::get( $key ); |
|
815 | + $count = Give_Cache::get($key); |
|
816 | 816 | } |
817 | 817 | |
818 | - if ( false === $count ) { |
|
819 | - $donations = new WP_Query( $args ); |
|
818 | + if (false === $count) { |
|
819 | + $donations = new WP_Query($args); |
|
820 | 820 | $count = (int) $donations->post_count; |
821 | 821 | // Cache the results for one hour. |
822 | - Give_Cache::set( $key, $count, HOUR_IN_SECONDS ); |
|
822 | + Give_Cache::set($key, $count, HOUR_IN_SECONDS); |
|
823 | 823 | } |
824 | 824 | |
825 | 825 | return $count; |
@@ -834,19 +834,19 @@ discard block |
||
834 | 834 | * |
835 | 835 | * @return bool $ret True if complete, false otherwise. |
836 | 836 | */ |
837 | -function give_is_payment_complete( $payment_id ) { |
|
838 | - $payment = new Give_Payment( $payment_id ); |
|
837 | +function give_is_payment_complete($payment_id) { |
|
838 | + $payment = new Give_Payment($payment_id); |
|
839 | 839 | |
840 | 840 | $ret = false; |
841 | 841 | |
842 | - if ( $payment->ID > 0 ) { |
|
842 | + if ($payment->ID > 0) { |
|
843 | 843 | |
844 | - if ( (int) $payment_id === (int) $payment->ID && 'publish' == $payment->status ) { |
|
844 | + if ((int) $payment_id === (int) $payment->ID && 'publish' == $payment->status) { |
|
845 | 845 | $ret = true; |
846 | 846 | } |
847 | 847 | } |
848 | 848 | |
849 | - return apply_filters( 'give_is_payment_complete', $ret, $payment_id, $payment->post_status ); |
|
849 | + return apply_filters('give_is_payment_complete', $ret, $payment_id, $payment->post_status); |
|
850 | 850 | } |
851 | 851 | |
852 | 852 | /** |
@@ -872,49 +872,49 @@ discard block |
||
872 | 872 | * |
873 | 873 | * @return float $total Total earnings. |
874 | 874 | */ |
875 | -function give_get_total_earnings( $recalculate = false ) { |
|
875 | +function give_get_total_earnings($recalculate = false) { |
|
876 | 876 | |
877 | - $total = get_option( 'give_earnings_total', 0 ); |
|
877 | + $total = get_option('give_earnings_total', 0); |
|
878 | 878 | |
879 | 879 | // Calculate total earnings. |
880 | - if ( ! $total || $recalculate ) { |
|
880 | + if ( ! $total || $recalculate) { |
|
881 | 881 | global $wpdb; |
882 | 882 | |
883 | 883 | $total = (float) 0; |
884 | 884 | |
885 | - $args = apply_filters( 'give_get_total_earnings_args', array( |
|
885 | + $args = apply_filters('give_get_total_earnings_args', array( |
|
886 | 886 | 'offset' => 0, |
887 | - 'number' => - 1, |
|
888 | - 'status' => array( 'publish' ), |
|
887 | + 'number' => -1, |
|
888 | + 'status' => array('publish'), |
|
889 | 889 | 'fields' => 'ids', |
890 | - ) ); |
|
890 | + )); |
|
891 | 891 | |
892 | - $payments = give_get_payments( $args ); |
|
893 | - if ( $payments ) { |
|
892 | + $payments = give_get_payments($args); |
|
893 | + if ($payments) { |
|
894 | 894 | |
895 | 895 | /** |
896 | 896 | * If performing a donation, we need to skip the very last payment in the database, |
897 | 897 | * since it calls give_increase_total_earnings() on completion, |
898 | 898 | * which results in duplicated earnings for the very first donation. |
899 | 899 | */ |
900 | - if ( did_action( 'give_update_payment_status' ) ) { |
|
901 | - array_pop( $payments ); |
|
900 | + if (did_action('give_update_payment_status')) { |
|
901 | + array_pop($payments); |
|
902 | 902 | } |
903 | 903 | |
904 | - if ( ! empty( $payments ) ) { |
|
905 | - $payments = implode( ',', $payments ); |
|
906 | - $total += $wpdb->get_var( "SELECT SUM(meta_value) FROM $wpdb->postmeta WHERE meta_key = '_give_payment_total' AND post_id IN({$payments})" ); |
|
904 | + if ( ! empty($payments)) { |
|
905 | + $payments = implode(',', $payments); |
|
906 | + $total += $wpdb->get_var("SELECT SUM(meta_value) FROM $wpdb->postmeta WHERE meta_key = '_give_payment_total' AND post_id IN({$payments})"); |
|
907 | 907 | } |
908 | 908 | } |
909 | 909 | |
910 | - update_option( 'give_earnings_total', $total, 'no' ); |
|
910 | + update_option('give_earnings_total', $total, 'no'); |
|
911 | 911 | } |
912 | 912 | |
913 | - if ( $total < 0 ) { |
|
913 | + if ($total < 0) { |
|
914 | 914 | $total = 0; // Don't ever show negative earnings. |
915 | 915 | } |
916 | 916 | |
917 | - return apply_filters( 'give_total_earnings', round( $total, give_get_price_decimals() ), $total ); |
|
917 | + return apply_filters('give_total_earnings', round($total, give_get_price_decimals()), $total); |
|
918 | 918 | } |
919 | 919 | |
920 | 920 | /** |
@@ -927,10 +927,10 @@ discard block |
||
927 | 927 | * |
928 | 928 | * @return float $total Total earnings. |
929 | 929 | */ |
930 | -function give_increase_total_earnings( $amount = 0 ) { |
|
930 | +function give_increase_total_earnings($amount = 0) { |
|
931 | 931 | $total = give_get_total_earnings(); |
932 | 932 | $total += $amount; |
933 | - update_option( 'give_earnings_total', $total ); |
|
933 | + update_option('give_earnings_total', $total); |
|
934 | 934 | |
935 | 935 | return $total; |
936 | 936 | } |
@@ -944,13 +944,13 @@ discard block |
||
944 | 944 | * |
945 | 945 | * @return float $total Total earnings. |
946 | 946 | */ |
947 | -function give_decrease_total_earnings( $amount = 0 ) { |
|
947 | +function give_decrease_total_earnings($amount = 0) { |
|
948 | 948 | $total = give_get_total_earnings(); |
949 | 949 | $total -= $amount; |
950 | - if ( $total < 0 ) { |
|
950 | + if ($total < 0) { |
|
951 | 951 | $total = 0; |
952 | 952 | } |
953 | - update_option( 'give_earnings_total', $total ); |
|
953 | + update_option('give_earnings_total', $total); |
|
954 | 954 | |
955 | 955 | return $total; |
956 | 956 | } |
@@ -966,10 +966,10 @@ discard block |
||
966 | 966 | * |
967 | 967 | * @return mixed $meta Payment Meta. |
968 | 968 | */ |
969 | -function give_get_payment_meta( $payment_id = 0, $meta_key = '_give_payment_meta', $single = true ) { |
|
970 | - $payment = new Give_Payment( $payment_id ); |
|
969 | +function give_get_payment_meta($payment_id = 0, $meta_key = '_give_payment_meta', $single = true) { |
|
970 | + $payment = new Give_Payment($payment_id); |
|
971 | 971 | |
972 | - return $payment->get_meta( $meta_key, $single ); |
|
972 | + return $payment->get_meta($meta_key, $single); |
|
973 | 973 | } |
974 | 974 | |
975 | 975 | /** |
@@ -982,10 +982,10 @@ discard block |
||
982 | 982 | * |
983 | 983 | * @return mixed Meta ID if successful, false if unsuccessful. |
984 | 984 | */ |
985 | -function give_update_payment_meta( $payment_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
986 | - $payment = new Give_Payment( $payment_id ); |
|
985 | +function give_update_payment_meta($payment_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') { |
|
986 | + $payment = new Give_Payment($payment_id); |
|
987 | 987 | |
988 | - return $payment->update_meta( $meta_key, $meta_value, $prev_value ); |
|
988 | + return $payment->update_meta($meta_key, $meta_value, $prev_value); |
|
989 | 989 | } |
990 | 990 | |
991 | 991 | /** |
@@ -997,8 +997,8 @@ discard block |
||
997 | 997 | * |
998 | 998 | * @return array $user_info User Info Meta Values. |
999 | 999 | */ |
1000 | -function give_get_payment_meta_user_info( $payment_id ) { |
|
1001 | - $payment = new Give_Payment( $payment_id ); |
|
1000 | +function give_get_payment_meta_user_info($payment_id) { |
|
1001 | + $payment = new Give_Payment($payment_id); |
|
1002 | 1002 | |
1003 | 1003 | return $payment->user_info; |
1004 | 1004 | } |
@@ -1014,8 +1014,8 @@ discard block |
||
1014 | 1014 | * |
1015 | 1015 | * @return int $form_id Form ID. |
1016 | 1016 | */ |
1017 | -function give_get_payment_form_id( $payment_id ) { |
|
1018 | - $payment = new Give_Payment( $payment_id ); |
|
1017 | +function give_get_payment_form_id($payment_id) { |
|
1018 | + $payment = new Give_Payment($payment_id); |
|
1019 | 1019 | |
1020 | 1020 | return $payment->form_id; |
1021 | 1021 | } |
@@ -1029,8 +1029,8 @@ discard block |
||
1029 | 1029 | * |
1030 | 1030 | * @return string $email User email. |
1031 | 1031 | */ |
1032 | -function give_get_payment_user_email( $payment_id ) { |
|
1033 | - $payment = new Give_Payment( $payment_id ); |
|
1032 | +function give_get_payment_user_email($payment_id) { |
|
1033 | + $payment = new Give_Payment($payment_id); |
|
1034 | 1034 | |
1035 | 1035 | return $payment->email; |
1036 | 1036 | } |
@@ -1044,11 +1044,11 @@ discard block |
||
1044 | 1044 | * |
1045 | 1045 | * @return bool $is_guest_payment If the payment is associated with a user (false) or not (true) |
1046 | 1046 | */ |
1047 | -function give_is_guest_payment( $payment_id ) { |
|
1048 | - $payment_user_id = give_get_payment_user_id( $payment_id ); |
|
1049 | - $is_guest_payment = ! empty( $payment_user_id ) && $payment_user_id > 0 ? false : true; |
|
1047 | +function give_is_guest_payment($payment_id) { |
|
1048 | + $payment_user_id = give_get_payment_user_id($payment_id); |
|
1049 | + $is_guest_payment = ! empty($payment_user_id) && $payment_user_id > 0 ? false : true; |
|
1050 | 1050 | |
1051 | - return (bool) apply_filters( 'give_is_guest_payment', $is_guest_payment, $payment_id ); |
|
1051 | + return (bool) apply_filters('give_is_guest_payment', $is_guest_payment, $payment_id); |
|
1052 | 1052 | } |
1053 | 1053 | |
1054 | 1054 | /** |
@@ -1060,8 +1060,8 @@ discard block |
||
1060 | 1060 | * |
1061 | 1061 | * @return int $user_id User ID. |
1062 | 1062 | */ |
1063 | -function give_get_payment_user_id( $payment_id ) { |
|
1064 | - $payment = new Give_Payment( $payment_id ); |
|
1063 | +function give_get_payment_user_id($payment_id) { |
|
1064 | + $payment = new Give_Payment($payment_id); |
|
1065 | 1065 | |
1066 | 1066 | return $payment->user_id; |
1067 | 1067 | } |
@@ -1075,8 +1075,8 @@ discard block |
||
1075 | 1075 | * |
1076 | 1076 | * @return int $payment->customer_id Donor ID. |
1077 | 1077 | */ |
1078 | -function give_get_payment_donor_id( $payment_id ) { |
|
1079 | - $payment = new Give_Payment( $payment_id ); |
|
1078 | +function give_get_payment_donor_id($payment_id) { |
|
1079 | + $payment = new Give_Payment($payment_id); |
|
1080 | 1080 | |
1081 | 1081 | return $payment->customer_id; |
1082 | 1082 | } |
@@ -1090,8 +1090,8 @@ discard block |
||
1090 | 1090 | * |
1091 | 1091 | * @return string $ip User IP. |
1092 | 1092 | */ |
1093 | -function give_get_payment_user_ip( $payment_id ) { |
|
1094 | - $payment = new Give_Payment( $payment_id ); |
|
1093 | +function give_get_payment_user_ip($payment_id) { |
|
1094 | + $payment = new Give_Payment($payment_id); |
|
1095 | 1095 | |
1096 | 1096 | return $payment->ip; |
1097 | 1097 | } |
@@ -1105,8 +1105,8 @@ discard block |
||
1105 | 1105 | * |
1106 | 1106 | * @return string $date The date the payment was completed. |
1107 | 1107 | */ |
1108 | -function give_get_payment_completed_date( $payment_id = 0 ) { |
|
1109 | - $payment = new Give_Payment( $payment_id ); |
|
1108 | +function give_get_payment_completed_date($payment_id = 0) { |
|
1109 | + $payment = new Give_Payment($payment_id); |
|
1110 | 1110 | |
1111 | 1111 | return $payment->completed_date; |
1112 | 1112 | } |
@@ -1120,8 +1120,8 @@ discard block |
||
1120 | 1120 | * |
1121 | 1121 | * @return string $gateway Gateway. |
1122 | 1122 | */ |
1123 | -function give_get_payment_gateway( $payment_id ) { |
|
1124 | - $payment = new Give_Payment( $payment_id ); |
|
1123 | +function give_get_payment_gateway($payment_id) { |
|
1124 | + $payment = new Give_Payment($payment_id); |
|
1125 | 1125 | |
1126 | 1126 | return $payment->gateway; |
1127 | 1127 | } |
@@ -1135,8 +1135,8 @@ discard block |
||
1135 | 1135 | * |
1136 | 1136 | * @return string $currency The currency code. |
1137 | 1137 | */ |
1138 | -function give_get_payment_currency_code( $payment_id = 0 ) { |
|
1139 | - $payment = new Give_Payment( $payment_id ); |
|
1138 | +function give_get_payment_currency_code($payment_id = 0) { |
|
1139 | + $payment = new Give_Payment($payment_id); |
|
1140 | 1140 | |
1141 | 1141 | return $payment->currency; |
1142 | 1142 | } |
@@ -1150,10 +1150,10 @@ discard block |
||
1150 | 1150 | * |
1151 | 1151 | * @return string $currency The currency name. |
1152 | 1152 | */ |
1153 | -function give_get_payment_currency( $payment_id = 0 ) { |
|
1154 | - $currency = give_get_payment_currency_code( $payment_id ); |
|
1153 | +function give_get_payment_currency($payment_id = 0) { |
|
1154 | + $currency = give_get_payment_currency_code($payment_id); |
|
1155 | 1155 | |
1156 | - return apply_filters( 'give_payment_currency', give_get_currency_name( $currency ), $payment_id ); |
|
1156 | + return apply_filters('give_payment_currency', give_get_currency_name($currency), $payment_id); |
|
1157 | 1157 | } |
1158 | 1158 | |
1159 | 1159 | /** |
@@ -1165,8 +1165,8 @@ discard block |
||
1165 | 1165 | * |
1166 | 1166 | * @return string $key Donation key. |
1167 | 1167 | */ |
1168 | -function give_get_payment_key( $payment_id = 0 ) { |
|
1169 | - $payment = new Give_Payment( $payment_id ); |
|
1168 | +function give_get_payment_key($payment_id = 0) { |
|
1169 | + $payment = new Give_Payment($payment_id); |
|
1170 | 1170 | |
1171 | 1171 | return $payment->key; |
1172 | 1172 | } |
@@ -1182,8 +1182,8 @@ discard block |
||
1182 | 1182 | * |
1183 | 1183 | * @return string $number Payment order number. |
1184 | 1184 | */ |
1185 | -function give_get_payment_number( $payment_id = 0 ) { |
|
1186 | - $payment = new Give_Payment( $payment_id ); |
|
1185 | +function give_get_payment_number($payment_id = 0) { |
|
1186 | + $payment = new Give_Payment($payment_id); |
|
1187 | 1187 | |
1188 | 1188 | return $payment->number; |
1189 | 1189 | } |
@@ -1197,23 +1197,23 @@ discard block |
||
1197 | 1197 | * |
1198 | 1198 | * @return string The formatted payment number. |
1199 | 1199 | */ |
1200 | -function give_format_payment_number( $number ) { |
|
1200 | +function give_format_payment_number($number) { |
|
1201 | 1201 | |
1202 | - if ( ! give_get_option( 'enable_sequential' ) ) { |
|
1202 | + if ( ! give_get_option('enable_sequential')) { |
|
1203 | 1203 | return $number; |
1204 | 1204 | } |
1205 | 1205 | |
1206 | - if ( ! is_numeric( $number ) ) { |
|
1206 | + if ( ! is_numeric($number)) { |
|
1207 | 1207 | return $number; |
1208 | 1208 | } |
1209 | 1209 | |
1210 | - $prefix = give_get_option( 'sequential_prefix' ); |
|
1211 | - $number = absint( $number ); |
|
1212 | - $postfix = give_get_option( 'sequential_postfix' ); |
|
1210 | + $prefix = give_get_option('sequential_prefix'); |
|
1211 | + $number = absint($number); |
|
1212 | + $postfix = give_get_option('sequential_postfix'); |
|
1213 | 1213 | |
1214 | - $formatted_number = $prefix . $number . $postfix; |
|
1214 | + $formatted_number = $prefix.$number.$postfix; |
|
1215 | 1215 | |
1216 | - return apply_filters( 'give_format_payment_number', $formatted_number, $prefix, $number, $postfix ); |
|
1216 | + return apply_filters('give_format_payment_number', $formatted_number, $prefix, $number, $postfix); |
|
1217 | 1217 | } |
1218 | 1218 | |
1219 | 1219 | /** |
@@ -1226,17 +1226,17 @@ discard block |
||
1226 | 1226 | */ |
1227 | 1227 | function give_get_next_payment_number() { |
1228 | 1228 | |
1229 | - if ( ! give_get_option( 'enable_sequential' ) ) { |
|
1229 | + if ( ! give_get_option('enable_sequential')) { |
|
1230 | 1230 | return false; |
1231 | 1231 | } |
1232 | 1232 | |
1233 | - $number = get_option( 'give_last_payment_number' ); |
|
1234 | - $start = give_get_option( 'sequential_start', 1 ); |
|
1233 | + $number = get_option('give_last_payment_number'); |
|
1234 | + $start = give_get_option('sequential_start', 1); |
|
1235 | 1235 | $increment_number = true; |
1236 | 1236 | |
1237 | - if ( false !== $number ) { |
|
1237 | + if (false !== $number) { |
|
1238 | 1238 | |
1239 | - if ( empty( $number ) ) { |
|
1239 | + if (empty($number)) { |
|
1240 | 1240 | |
1241 | 1241 | $number = $start; |
1242 | 1242 | $increment_number = false; |
@@ -1245,24 +1245,24 @@ discard block |
||
1245 | 1245 | } else { |
1246 | 1246 | |
1247 | 1247 | // This case handles the first addition of the new option, as well as if it get's deleted for any reason. |
1248 | - $payments = new Give_Payments_Query( array( |
|
1248 | + $payments = new Give_Payments_Query(array( |
|
1249 | 1249 | 'number' => 1, |
1250 | 1250 | 'order' => 'DESC', |
1251 | 1251 | 'orderby' => 'ID', |
1252 | 1252 | 'output' => 'posts', |
1253 | 1253 | 'fields' => 'ids', |
1254 | - ) ); |
|
1254 | + )); |
|
1255 | 1255 | $last_payment = $payments->get_payments(); |
1256 | 1256 | |
1257 | - if ( ! empty( $last_payment ) ) { |
|
1257 | + if ( ! empty($last_payment)) { |
|
1258 | 1258 | |
1259 | - $number = give_get_payment_number( $last_payment[0] ); |
|
1259 | + $number = give_get_payment_number($last_payment[0]); |
|
1260 | 1260 | |
1261 | 1261 | } |
1262 | 1262 | |
1263 | - if ( ! empty( $number ) && $number !== (int) $last_payment[0] ) { |
|
1263 | + if ( ! empty($number) && $number !== (int) $last_payment[0]) { |
|
1264 | 1264 | |
1265 | - $number = give_remove_payment_prefix_postfix( $number ); |
|
1265 | + $number = give_remove_payment_prefix_postfix($number); |
|
1266 | 1266 | |
1267 | 1267 | } else { |
1268 | 1268 | |
@@ -1271,13 +1271,13 @@ discard block |
||
1271 | 1271 | } |
1272 | 1272 | }// End if(). |
1273 | 1273 | |
1274 | - $increment_number = apply_filters( 'give_increment_payment_number', $increment_number, $number ); |
|
1274 | + $increment_number = apply_filters('give_increment_payment_number', $increment_number, $number); |
|
1275 | 1275 | |
1276 | - if ( $increment_number ) { |
|
1277 | - $number ++; |
|
1276 | + if ($increment_number) { |
|
1277 | + $number++; |
|
1278 | 1278 | } |
1279 | 1279 | |
1280 | - return apply_filters( 'give_get_next_payment_number', $number ); |
|
1280 | + return apply_filters('give_get_next_payment_number', $number); |
|
1281 | 1281 | } |
1282 | 1282 | |
1283 | 1283 | /** |
@@ -1289,25 +1289,25 @@ discard block |
||
1289 | 1289 | * |
1290 | 1290 | * @return string The new Payment number without prefix and postfix. |
1291 | 1291 | */ |
1292 | -function give_remove_payment_prefix_postfix( $number ) { |
|
1292 | +function give_remove_payment_prefix_postfix($number) { |
|
1293 | 1293 | |
1294 | - $prefix = give_get_option( 'sequential_prefix' ); |
|
1295 | - $postfix = give_get_option( 'sequential_postfix' ); |
|
1294 | + $prefix = give_get_option('sequential_prefix'); |
|
1295 | + $postfix = give_get_option('sequential_postfix'); |
|
1296 | 1296 | |
1297 | 1297 | // Remove prefix. |
1298 | - $number = preg_replace( '/' . $prefix . '/', '', $number, 1 ); |
|
1298 | + $number = preg_replace('/'.$prefix.'/', '', $number, 1); |
|
1299 | 1299 | |
1300 | 1300 | // Remove the postfix. |
1301 | - $length = strlen( $number ); |
|
1302 | - $postfix_pos = strrpos( $number, $postfix ); |
|
1303 | - if ( false !== $postfix_pos ) { |
|
1304 | - $number = substr_replace( $number, '', $postfix_pos, $length ); |
|
1301 | + $length = strlen($number); |
|
1302 | + $postfix_pos = strrpos($number, $postfix); |
|
1303 | + if (false !== $postfix_pos) { |
|
1304 | + $number = substr_replace($number, '', $postfix_pos, $length); |
|
1305 | 1305 | } |
1306 | 1306 | |
1307 | 1307 | // Ensure it's a whole number. |
1308 | - $number = intval( $number ); |
|
1308 | + $number = intval($number); |
|
1309 | 1309 | |
1310 | - return apply_filters( 'give_remove_payment_prefix_postfix', $number, $prefix, $postfix ); |
|
1310 | + return apply_filters('give_remove_payment_prefix_postfix', $number, $prefix, $postfix); |
|
1311 | 1311 | |
1312 | 1312 | } |
1313 | 1313 | |
@@ -1324,10 +1324,10 @@ discard block |
||
1324 | 1324 | * |
1325 | 1325 | * @return string $amount Fully formatted payment amount. |
1326 | 1326 | */ |
1327 | -function give_payment_amount( $payment_id = 0 ) { |
|
1328 | - $amount = give_get_payment_amount( $payment_id ); |
|
1327 | +function give_payment_amount($payment_id = 0) { |
|
1328 | + $amount = give_get_payment_amount($payment_id); |
|
1329 | 1329 | |
1330 | - return give_currency_filter( give_format_amount( $amount, array( 'sanitize' => false ) ), give_get_payment_currency_code( $payment_id ) ); |
|
1330 | + return give_currency_filter(give_format_amount($amount, array('sanitize' => false)), give_get_payment_currency_code($payment_id)); |
|
1331 | 1331 | } |
1332 | 1332 | |
1333 | 1333 | /** |
@@ -1340,11 +1340,11 @@ discard block |
||
1340 | 1340 | * |
1341 | 1341 | * @return mixed |
1342 | 1342 | */ |
1343 | -function give_get_payment_amount( $payment_id ) { |
|
1343 | +function give_get_payment_amount($payment_id) { |
|
1344 | 1344 | |
1345 | - $payment = new Give_Payment( $payment_id ); |
|
1345 | + $payment = new Give_Payment($payment_id); |
|
1346 | 1346 | |
1347 | - return apply_filters( 'give_payment_amount', floatval( $payment->total ), $payment_id ); |
|
1347 | + return apply_filters('give_payment_amount', floatval($payment->total), $payment_id); |
|
1348 | 1348 | } |
1349 | 1349 | |
1350 | 1350 | /** |
@@ -1361,10 +1361,10 @@ discard block |
||
1361 | 1361 | * |
1362 | 1362 | * @return array Fully formatted payment subtotal. |
1363 | 1363 | */ |
1364 | -function give_payment_subtotal( $payment_id = 0 ) { |
|
1365 | - $subtotal = give_get_payment_subtotal( $payment_id ); |
|
1364 | +function give_payment_subtotal($payment_id = 0) { |
|
1365 | + $subtotal = give_get_payment_subtotal($payment_id); |
|
1366 | 1366 | |
1367 | - return give_currency_filter( give_format_amount( $subtotal, array( 'sanitize' => false ) ), give_get_payment_currency_code( $payment_id ) ); |
|
1367 | + return give_currency_filter(give_format_amount($subtotal, array('sanitize' => false)), give_get_payment_currency_code($payment_id)); |
|
1368 | 1368 | } |
1369 | 1369 | |
1370 | 1370 | /** |
@@ -1378,8 +1378,8 @@ discard block |
||
1378 | 1378 | * |
1379 | 1379 | * @return float $subtotal Subtotal for payment (non formatted). |
1380 | 1380 | */ |
1381 | -function give_get_payment_subtotal( $payment_id = 0 ) { |
|
1382 | - $payment = new Give_Payment( $payment_id ); |
|
1381 | +function give_get_payment_subtotal($payment_id = 0) { |
|
1382 | + $payment = new Give_Payment($payment_id); |
|
1383 | 1383 | |
1384 | 1384 | return $payment->subtotal; |
1385 | 1385 | } |
@@ -1393,8 +1393,8 @@ discard block |
||
1393 | 1393 | * |
1394 | 1394 | * @return string The donation ID. |
1395 | 1395 | */ |
1396 | -function give_get_payment_transaction_id( $payment_id = 0 ) { |
|
1397 | - $payment = new Give_Payment( $payment_id ); |
|
1396 | +function give_get_payment_transaction_id($payment_id = 0) { |
|
1397 | + $payment = new Give_Payment($payment_id); |
|
1398 | 1398 | |
1399 | 1399 | return $payment->transaction_id; |
1400 | 1400 | } |
@@ -1409,15 +1409,15 @@ discard block |
||
1409 | 1409 | * |
1410 | 1410 | * @return bool|mixed |
1411 | 1411 | */ |
1412 | -function give_set_payment_transaction_id( $payment_id = 0, $transaction_id = '' ) { |
|
1412 | +function give_set_payment_transaction_id($payment_id = 0, $transaction_id = '') { |
|
1413 | 1413 | |
1414 | - if ( empty( $payment_id ) || empty( $transaction_id ) ) { |
|
1414 | + if (empty($payment_id) || empty($transaction_id)) { |
|
1415 | 1415 | return false; |
1416 | 1416 | } |
1417 | 1417 | |
1418 | - $transaction_id = apply_filters( 'give_set_payment_transaction_id', $transaction_id, $payment_id ); |
|
1418 | + $transaction_id = apply_filters('give_set_payment_transaction_id', $transaction_id, $payment_id); |
|
1419 | 1419 | |
1420 | - return give_update_payment_meta( $payment_id, '_give_payment_transaction_id', $transaction_id ); |
|
1420 | + return give_update_payment_meta($payment_id, '_give_payment_transaction_id', $transaction_id); |
|
1421 | 1421 | } |
1422 | 1422 | |
1423 | 1423 | /** |
@@ -1430,12 +1430,12 @@ discard block |
||
1430 | 1430 | * |
1431 | 1431 | * @return int $purchase Donation ID. |
1432 | 1432 | */ |
1433 | -function give_get_purchase_id_by_key( $key ) { |
|
1433 | +function give_get_purchase_id_by_key($key) { |
|
1434 | 1434 | global $wpdb; |
1435 | 1435 | |
1436 | - $purchase = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_give_payment_purchase_key' AND meta_value = %s LIMIT 1", $key ) ); |
|
1436 | + $purchase = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_give_payment_purchase_key' AND meta_value = %s LIMIT 1", $key)); |
|
1437 | 1437 | |
1438 | - if ( $purchase != null ) { |
|
1438 | + if ($purchase != null) { |
|
1439 | 1439 | return $purchase; |
1440 | 1440 | } |
1441 | 1441 | |
@@ -1453,12 +1453,12 @@ discard block |
||
1453 | 1453 | * |
1454 | 1454 | * @return int $purchase Donation ID. |
1455 | 1455 | */ |
1456 | -function give_get_purchase_id_by_transaction_id( $key ) { |
|
1456 | +function give_get_purchase_id_by_transaction_id($key) { |
|
1457 | 1457 | global $wpdb; |
1458 | 1458 | |
1459 | - $purchase = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_give_payment_transaction_id' AND meta_value = %s LIMIT 1", $key ) ); |
|
1459 | + $purchase = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_give_payment_transaction_id' AND meta_value = %s LIMIT 1", $key)); |
|
1460 | 1460 | |
1461 | - if ( $purchase != null ) { |
|
1461 | + if ($purchase != null) { |
|
1462 | 1462 | return $purchase; |
1463 | 1463 | } |
1464 | 1464 | |
@@ -1475,23 +1475,23 @@ discard block |
||
1475 | 1475 | * |
1476 | 1476 | * @return array $notes Donation Notes |
1477 | 1477 | */ |
1478 | -function give_get_payment_notes( $payment_id = 0, $search = '' ) { |
|
1478 | +function give_get_payment_notes($payment_id = 0, $search = '') { |
|
1479 | 1479 | |
1480 | - if ( empty( $payment_id ) && empty( $search ) ) { |
|
1480 | + if (empty($payment_id) && empty($search)) { |
|
1481 | 1481 | return false; |
1482 | 1482 | } |
1483 | 1483 | |
1484 | - remove_action( 'pre_get_comments', 'give_hide_payment_notes', 10 ); |
|
1485 | - remove_filter( 'comments_clauses', 'give_hide_payment_notes_pre_41', 10 ); |
|
1484 | + remove_action('pre_get_comments', 'give_hide_payment_notes', 10); |
|
1485 | + remove_filter('comments_clauses', 'give_hide_payment_notes_pre_41', 10); |
|
1486 | 1486 | |
1487 | - $notes = get_comments( array( |
|
1487 | + $notes = get_comments(array( |
|
1488 | 1488 | 'post_id' => $payment_id, |
1489 | 1489 | 'order' => 'ASC', |
1490 | 1490 | 'search' => $search, |
1491 | - ) ); |
|
1491 | + )); |
|
1492 | 1492 | |
1493 | - add_action( 'pre_get_comments', 'give_hide_payment_notes', 10 ); |
|
1494 | - add_filter( 'comments_clauses', 'give_hide_payment_notes_pre_41', 10, 2 ); |
|
1493 | + add_action('pre_get_comments', 'give_hide_payment_notes', 10); |
|
1494 | + add_filter('comments_clauses', 'give_hide_payment_notes_pre_41', 10, 2); |
|
1495 | 1495 | |
1496 | 1496 | return $notes; |
1497 | 1497 | } |
@@ -1507,8 +1507,8 @@ discard block |
||
1507 | 1507 | * |
1508 | 1508 | * @return int The new note ID |
1509 | 1509 | */ |
1510 | -function give_insert_payment_note( $payment_id = 0, $note = '' ) { |
|
1511 | - if ( empty( $payment_id ) ) { |
|
1510 | +function give_insert_payment_note($payment_id = 0, $note = '') { |
|
1511 | + if (empty($payment_id)) { |
|
1512 | 1512 | return false; |
1513 | 1513 | } |
1514 | 1514 | |
@@ -1520,14 +1520,14 @@ discard block |
||
1520 | 1520 | * @param int $payment_id Payment ID. |
1521 | 1521 | * @param string $note The note. |
1522 | 1522 | */ |
1523 | - do_action( 'give_pre_insert_payment_note', $payment_id, $note ); |
|
1523 | + do_action('give_pre_insert_payment_note', $payment_id, $note); |
|
1524 | 1524 | |
1525 | - $note_id = wp_insert_comment( wp_filter_comment( array( |
|
1525 | + $note_id = wp_insert_comment(wp_filter_comment(array( |
|
1526 | 1526 | 'comment_post_ID' => $payment_id, |
1527 | 1527 | 'comment_content' => $note, |
1528 | 1528 | 'user_id' => is_admin() ? get_current_user_id() : 0, |
1529 | - 'comment_date' => current_time( 'mysql' ), |
|
1530 | - 'comment_date_gmt' => current_time( 'mysql', 1 ), |
|
1529 | + 'comment_date' => current_time('mysql'), |
|
1530 | + 'comment_date_gmt' => current_time('mysql', 1), |
|
1531 | 1531 | 'comment_approved' => 1, |
1532 | 1532 | 'comment_parent' => 0, |
1533 | 1533 | 'comment_author' => '', |
@@ -1536,7 +1536,7 @@ discard block |
||
1536 | 1536 | 'comment_author_email' => '', |
1537 | 1537 | 'comment_type' => 'give_payment_note', |
1538 | 1538 | |
1539 | - ) ) ); |
|
1539 | + ))); |
|
1540 | 1540 | |
1541 | 1541 | /** |
1542 | 1542 | * Fires after payment note inserted. |
@@ -1547,7 +1547,7 @@ discard block |
||
1547 | 1547 | * @param int $payment_id Payment ID. |
1548 | 1548 | * @param string $note The note. |
1549 | 1549 | */ |
1550 | - do_action( 'give_insert_payment_note', $note_id, $payment_id, $note ); |
|
1550 | + do_action('give_insert_payment_note', $note_id, $payment_id, $note); |
|
1551 | 1551 | |
1552 | 1552 | return $note_id; |
1553 | 1553 | } |
@@ -1562,8 +1562,8 @@ discard block |
||
1562 | 1562 | * |
1563 | 1563 | * @return bool True on success, false otherwise. |
1564 | 1564 | */ |
1565 | -function give_delete_payment_note( $comment_id = 0, $payment_id = 0 ) { |
|
1566 | - if ( empty( $comment_id ) ) { |
|
1565 | +function give_delete_payment_note($comment_id = 0, $payment_id = 0) { |
|
1566 | + if (empty($comment_id)) { |
|
1567 | 1567 | return false; |
1568 | 1568 | } |
1569 | 1569 | |
@@ -1575,9 +1575,9 @@ discard block |
||
1575 | 1575 | * @param int $comment_id Note ID. |
1576 | 1576 | * @param int $payment_id Payment ID. |
1577 | 1577 | */ |
1578 | - do_action( 'give_pre_delete_payment_note', $comment_id, $payment_id ); |
|
1578 | + do_action('give_pre_delete_payment_note', $comment_id, $payment_id); |
|
1579 | 1579 | |
1580 | - $ret = wp_delete_comment( $comment_id, true ); |
|
1580 | + $ret = wp_delete_comment($comment_id, true); |
|
1581 | 1581 | |
1582 | 1582 | /** |
1583 | 1583 | * Fires after donation note deleted. |
@@ -1587,7 +1587,7 @@ discard block |
||
1587 | 1587 | * @param int $comment_id Note ID. |
1588 | 1588 | * @param int $payment_id Payment ID. |
1589 | 1589 | */ |
1590 | - do_action( 'give_post_delete_payment_note', $comment_id, $payment_id ); |
|
1590 | + do_action('give_post_delete_payment_note', $comment_id, $payment_id); |
|
1591 | 1591 | |
1592 | 1592 | return $ret; |
1593 | 1593 | } |
@@ -1602,32 +1602,32 @@ discard block |
||
1602 | 1602 | * |
1603 | 1603 | * @return string |
1604 | 1604 | */ |
1605 | -function give_get_payment_note_html( $note, $payment_id = 0 ) { |
|
1605 | +function give_get_payment_note_html($note, $payment_id = 0) { |
|
1606 | 1606 | |
1607 | - if ( is_numeric( $note ) ) { |
|
1608 | - $note = get_comment( $note ); |
|
1607 | + if (is_numeric($note)) { |
|
1608 | + $note = get_comment($note); |
|
1609 | 1609 | } |
1610 | 1610 | |
1611 | - if ( ! empty( $note->user_id ) ) { |
|
1612 | - $user = get_userdata( $note->user_id ); |
|
1611 | + if ( ! empty($note->user_id)) { |
|
1612 | + $user = get_userdata($note->user_id); |
|
1613 | 1613 | $user = $user->display_name; |
1614 | 1614 | } else { |
1615 | - $user = esc_html__( 'System', 'give' ); |
|
1615 | + $user = esc_html__('System', 'give'); |
|
1616 | 1616 | } |
1617 | 1617 | |
1618 | - $date_format = give_date_format() . ', ' . get_option( 'time_format' ); |
|
1618 | + $date_format = give_date_format().', '.get_option('time_format'); |
|
1619 | 1619 | |
1620 | - $delete_note_url = wp_nonce_url( add_query_arg( array( |
|
1620 | + $delete_note_url = wp_nonce_url(add_query_arg(array( |
|
1621 | 1621 | 'give-action' => 'delete_payment_note', |
1622 | 1622 | 'note_id' => $note->comment_ID, |
1623 | 1623 | 'payment_id' => $payment_id, |
1624 | - ) ), 'give_delete_payment_note_' . $note->comment_ID ); |
|
1624 | + )), 'give_delete_payment_note_'.$note->comment_ID); |
|
1625 | 1625 | |
1626 | - $note_html = '<div class="give-payment-note" id="give-payment-note-' . $note->comment_ID . '">'; |
|
1626 | + $note_html = '<div class="give-payment-note" id="give-payment-note-'.$note->comment_ID.'">'; |
|
1627 | 1627 | $note_html .= '<p>'; |
1628 | - $note_html .= '<strong>' . $user . '</strong> – <span style="color:#aaa;font-style:italic;">' . date_i18n( $date_format, strtotime( $note->comment_date ) ) . '</span><br/>'; |
|
1628 | + $note_html .= '<strong>'.$user.'</strong> – <span style="color:#aaa;font-style:italic;">'.date_i18n($date_format, strtotime($note->comment_date)).'</span><br/>'; |
|
1629 | 1629 | $note_html .= $note->comment_content; |
1630 | - $note_html .= ' – <a href="' . esc_url( $delete_note_url ) . '" class="give-delete-payment-note" data-note-id="' . absint( $note->comment_ID ) . '" data-payment-id="' . absint( $payment_id ) . '" aria-label="' . esc_attr__( 'Delete this donation note.', 'give' ) . '">' . esc_html__( 'Delete', 'give' ) . '</a>'; |
|
1630 | + $note_html .= ' – <a href="'.esc_url($delete_note_url).'" class="give-delete-payment-note" data-note-id="'.absint($note->comment_ID).'" data-payment-id="'.absint($payment_id).'" aria-label="'.esc_attr__('Delete this donation note.', 'give').'">'.esc_html__('Delete', 'give').'</a>'; |
|
1631 | 1631 | $note_html .= '</p>'; |
1632 | 1632 | $note_html .= '</div>'; |
1633 | 1633 | |
@@ -1645,18 +1645,18 @@ discard block |
||
1645 | 1645 | * |
1646 | 1646 | * @return void |
1647 | 1647 | */ |
1648 | -function give_hide_payment_notes( $query ) { |
|
1649 | - if ( version_compare( floatval( get_bloginfo( 'version' ) ), '4.1', '>=' ) ) { |
|
1650 | - $types = isset( $query->query_vars['type__not_in'] ) ? $query->query_vars['type__not_in'] : array(); |
|
1651 | - if ( ! is_array( $types ) ) { |
|
1652 | - $types = array( $types ); |
|
1648 | +function give_hide_payment_notes($query) { |
|
1649 | + if (version_compare(floatval(get_bloginfo('version')), '4.1', '>=')) { |
|
1650 | + $types = isset($query->query_vars['type__not_in']) ? $query->query_vars['type__not_in'] : array(); |
|
1651 | + if ( ! is_array($types)) { |
|
1652 | + $types = array($types); |
|
1653 | 1653 | } |
1654 | 1654 | $types[] = 'give_payment_note'; |
1655 | 1655 | $query->query_vars['type__not_in'] = $types; |
1656 | 1656 | } |
1657 | 1657 | } |
1658 | 1658 | |
1659 | -add_action( 'pre_get_comments', 'give_hide_payment_notes', 10 ); |
|
1659 | +add_action('pre_get_comments', 'give_hide_payment_notes', 10); |
|
1660 | 1660 | |
1661 | 1661 | /** |
1662 | 1662 | * Exclude notes (comments) on give_payment post type from showing in Recent Comments widgets |
@@ -1668,15 +1668,15 @@ discard block |
||
1668 | 1668 | * |
1669 | 1669 | * @return array $clauses Updated comment clauses. |
1670 | 1670 | */ |
1671 | -function give_hide_payment_notes_pre_41( $clauses, $wp_comment_query ) { |
|
1672 | - if ( version_compare( floatval( get_bloginfo( 'version' ) ), '4.1', '<' ) ) { |
|
1671 | +function give_hide_payment_notes_pre_41($clauses, $wp_comment_query) { |
|
1672 | + if (version_compare(floatval(get_bloginfo('version')), '4.1', '<')) { |
|
1673 | 1673 | $clauses['where'] .= ' AND comment_type != "give_payment_note"'; |
1674 | 1674 | } |
1675 | 1675 | |
1676 | 1676 | return $clauses; |
1677 | 1677 | } |
1678 | 1678 | |
1679 | -add_filter( 'comments_clauses', 'give_hide_payment_notes_pre_41', 10, 2 ); |
|
1679 | +add_filter('comments_clauses', 'give_hide_payment_notes_pre_41', 10, 2); |
|
1680 | 1680 | |
1681 | 1681 | |
1682 | 1682 | /** |
@@ -1689,15 +1689,15 @@ discard block |
||
1689 | 1689 | * |
1690 | 1690 | * @return string $where |
1691 | 1691 | */ |
1692 | -function give_hide_payment_notes_from_feeds( $where, $wp_comment_query ) { |
|
1692 | +function give_hide_payment_notes_from_feeds($where, $wp_comment_query) { |
|
1693 | 1693 | global $wpdb; |
1694 | 1694 | |
1695 | - $where .= $wpdb->prepare( ' AND comment_type != %s', 'give_payment_note' ); |
|
1695 | + $where .= $wpdb->prepare(' AND comment_type != %s', 'give_payment_note'); |
|
1696 | 1696 | |
1697 | 1697 | return $where; |
1698 | 1698 | } |
1699 | 1699 | |
1700 | -add_filter( 'comment_feed_where', 'give_hide_payment_notes_from_feeds', 10, 2 ); |
|
1700 | +add_filter('comment_feed_where', 'give_hide_payment_notes_from_feeds', 10, 2); |
|
1701 | 1701 | |
1702 | 1702 | |
1703 | 1703 | /** |
@@ -1711,32 +1711,32 @@ discard block |
||
1711 | 1711 | * |
1712 | 1712 | * @return array Array of comment counts. |
1713 | 1713 | */ |
1714 | -function give_remove_payment_notes_in_comment_counts( $stats, $post_id ) { |
|
1714 | +function give_remove_payment_notes_in_comment_counts($stats, $post_id) { |
|
1715 | 1715 | global $wpdb, $pagenow; |
1716 | 1716 | |
1717 | - if ( 'index.php' != $pagenow ) { |
|
1717 | + if ('index.php' != $pagenow) { |
|
1718 | 1718 | return $stats; |
1719 | 1719 | } |
1720 | 1720 | |
1721 | 1721 | $post_id = (int) $post_id; |
1722 | 1722 | |
1723 | - if ( apply_filters( 'give_count_payment_notes_in_comments', false ) ) { |
|
1723 | + if (apply_filters('give_count_payment_notes_in_comments', false)) { |
|
1724 | 1724 | return $stats; |
1725 | 1725 | } |
1726 | 1726 | |
1727 | - $stats = wp_cache_get( "comments-{$post_id}", 'counts' ); |
|
1727 | + $stats = wp_cache_get("comments-{$post_id}", 'counts'); |
|
1728 | 1728 | |
1729 | - if ( false !== $stats ) { |
|
1729 | + if (false !== $stats) { |
|
1730 | 1730 | return $stats; |
1731 | 1731 | } |
1732 | 1732 | |
1733 | 1733 | $where = 'WHERE comment_type != "give_payment_note"'; |
1734 | 1734 | |
1735 | - if ( $post_id > 0 ) { |
|
1736 | - $where .= $wpdb->prepare( ' AND comment_post_ID = %d', $post_id ); |
|
1735 | + if ($post_id > 0) { |
|
1736 | + $where .= $wpdb->prepare(' AND comment_post_ID = %d', $post_id); |
|
1737 | 1737 | } |
1738 | 1738 | |
1739 | - $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A ); |
|
1739 | + $count = $wpdb->get_results("SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A); |
|
1740 | 1740 | |
1741 | 1741 | $total = 0; |
1742 | 1742 | $approved = array( |
@@ -1746,30 +1746,30 @@ discard block |
||
1746 | 1746 | 'trash' => 'trash', |
1747 | 1747 | 'post-trashed' => 'post-trashed', |
1748 | 1748 | ); |
1749 | - foreach ( (array) $count as $row ) { |
|
1749 | + foreach ((array) $count as $row) { |
|
1750 | 1750 | // Don't count post-trashed toward totals. |
1751 | - if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) { |
|
1751 | + if ('post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved']) { |
|
1752 | 1752 | $total += $row['num_comments']; |
1753 | 1753 | } |
1754 | - if ( isset( $approved[ $row['comment_approved'] ] ) ) { |
|
1755 | - $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments']; |
|
1754 | + if (isset($approved[$row['comment_approved']])) { |
|
1755 | + $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
|
1756 | 1756 | } |
1757 | 1757 | } |
1758 | 1758 | |
1759 | 1759 | $stats['total_comments'] = $total; |
1760 | - foreach ( $approved as $key ) { |
|
1761 | - if ( empty( $stats[ $key ] ) ) { |
|
1762 | - $stats[ $key ] = 0; |
|
1760 | + foreach ($approved as $key) { |
|
1761 | + if (empty($stats[$key])) { |
|
1762 | + $stats[$key] = 0; |
|
1763 | 1763 | } |
1764 | 1764 | } |
1765 | 1765 | |
1766 | 1766 | $stats = (object) $stats; |
1767 | - wp_cache_set( "comments-{$post_id}", $stats, 'counts' ); |
|
1767 | + wp_cache_set("comments-{$post_id}", $stats, 'counts'); |
|
1768 | 1768 | |
1769 | 1769 | return $stats; |
1770 | 1770 | } |
1771 | 1771 | |
1772 | -add_filter( 'wp_count_comments', 'give_remove_payment_notes_in_comment_counts', 10, 2 ); |
|
1772 | +add_filter('wp_count_comments', 'give_remove_payment_notes_in_comment_counts', 10, 2); |
|
1773 | 1773 | |
1774 | 1774 | |
1775 | 1775 | /** |
@@ -1782,9 +1782,9 @@ discard block |
||
1782 | 1782 | * |
1783 | 1783 | * @return string $where Modified where clause. |
1784 | 1784 | */ |
1785 | -function give_filter_where_older_than_week( $where = '' ) { |
|
1785 | +function give_filter_where_older_than_week($where = '') { |
|
1786 | 1786 | // Payments older than one week. |
1787 | - $start = date( 'Y-m-d', strtotime( '-7 days' ) ); |
|
1787 | + $start = date('Y-m-d', strtotime('-7 days')); |
|
1788 | 1788 | $where .= " AND post_date <= '{$start}'"; |
1789 | 1789 | |
1790 | 1790 | return $where; |
@@ -1804,38 +1804,38 @@ discard block |
||
1804 | 1804 | * |
1805 | 1805 | * @return string $form_title Returns the full title if $only_level is false, otherwise returns the levels title. |
1806 | 1806 | */ |
1807 | -function give_get_payment_form_title( $payment_meta, $only_level = false, $separator = '' ) { |
|
1807 | +function give_get_payment_form_title($payment_meta, $only_level = false, $separator = '') { |
|
1808 | 1808 | |
1809 | - $form_id = isset( $payment_meta['form_id'] ) ? $payment_meta['form_id'] : 0; |
|
1810 | - $price_id = isset( $payment_meta['price_id'] ) ? $payment_meta['price_id'] : null; |
|
1811 | - $form_title = isset( $payment_meta['form_title'] ) ? $payment_meta['form_title'] : ''; |
|
1809 | + $form_id = isset($payment_meta['form_id']) ? $payment_meta['form_id'] : 0; |
|
1810 | + $price_id = isset($payment_meta['price_id']) ? $payment_meta['price_id'] : null; |
|
1811 | + $form_title = isset($payment_meta['form_title']) ? $payment_meta['form_title'] : ''; |
|
1812 | 1812 | |
1813 | - if ( $only_level == true ) { |
|
1813 | + if ($only_level == true) { |
|
1814 | 1814 | $form_title = ''; |
1815 | 1815 | } |
1816 | 1816 | |
1817 | 1817 | // If multi-level, append to the form title. |
1818 | - if ( give_has_variable_prices( $form_id ) ) { |
|
1818 | + if (give_has_variable_prices($form_id)) { |
|
1819 | 1819 | |
1820 | 1820 | // Only add separator if there is a form title. |
1821 | - if ( ! empty( $form_title ) ) { |
|
1822 | - $form_title .= ' ' . $separator . ' '; |
|
1821 | + if ( ! empty($form_title)) { |
|
1822 | + $form_title .= ' '.$separator.' '; |
|
1823 | 1823 | } |
1824 | 1824 | |
1825 | 1825 | $form_title .= '<span class="donation-level-text-wrap">'; |
1826 | 1826 | |
1827 | - if ( $price_id == 'custom' ) { |
|
1828 | - $custom_amount_text = give_get_meta( $form_id, '_give_custom_amount_text', true ); |
|
1829 | - $form_title .= ! empty( $custom_amount_text ) ? $custom_amount_text : __( 'Custom Amount', 'give' ); |
|
1827 | + if ($price_id == 'custom') { |
|
1828 | + $custom_amount_text = give_get_meta($form_id, '_give_custom_amount_text', true); |
|
1829 | + $form_title .= ! empty($custom_amount_text) ? $custom_amount_text : __('Custom Amount', 'give'); |
|
1830 | 1830 | } else { |
1831 | - $form_title .= give_get_price_option_name( $form_id, $price_id ); |
|
1831 | + $form_title .= give_get_price_option_name($form_id, $price_id); |
|
1832 | 1832 | } |
1833 | 1833 | |
1834 | 1834 | $form_title .= '</span>'; |
1835 | 1835 | |
1836 | 1836 | } |
1837 | 1837 | |
1838 | - return apply_filters( 'give_get_payment_form_title', $form_title, $payment_meta ); |
|
1838 | + return apply_filters('give_get_payment_form_title', $form_title, $payment_meta); |
|
1839 | 1839 | |
1840 | 1840 | } |
1841 | 1841 | |
@@ -1849,19 +1849,19 @@ discard block |
||
1849 | 1849 | * |
1850 | 1850 | * @return string $price_id |
1851 | 1851 | */ |
1852 | -function give_get_price_id( $form_id, $price ) { |
|
1852 | +function give_get_price_id($form_id, $price) { |
|
1853 | 1853 | $price_id = null; |
1854 | 1854 | |
1855 | - if ( give_has_variable_prices( $form_id ) ) { |
|
1855 | + if (give_has_variable_prices($form_id)) { |
|
1856 | 1856 | |
1857 | - $levels = give_get_meta( $form_id, '_give_donation_levels', true ); |
|
1857 | + $levels = give_get_meta($form_id, '_give_donation_levels', true); |
|
1858 | 1858 | |
1859 | - foreach ( $levels as $level ) { |
|
1859 | + foreach ($levels as $level) { |
|
1860 | 1860 | |
1861 | - $level_amount = give_maybe_sanitize_amount( $level['_give_amount'] ); |
|
1861 | + $level_amount = give_maybe_sanitize_amount($level['_give_amount']); |
|
1862 | 1862 | |
1863 | 1863 | // Check that this indeed the recurring price. |
1864 | - if ( $level_amount == $price ) { |
|
1864 | + if ($level_amount == $price) { |
|
1865 | 1865 | |
1866 | 1866 | $price_id = $level['_give_id']['level_id']; |
1867 | 1867 | break; |
@@ -1869,13 +1869,13 @@ discard block |
||
1869 | 1869 | } |
1870 | 1870 | } |
1871 | 1871 | |
1872 | - if( is_null( $price_id ) && give_is_custom_price_mode( $form_id ) ) { |
|
1872 | + if (is_null($price_id) && give_is_custom_price_mode($form_id)) { |
|
1873 | 1873 | $price_id = 'custom'; |
1874 | 1874 | } |
1875 | 1875 | } |
1876 | 1876 | |
1877 | 1877 | // Price ID must be numeric or string. |
1878 | - $price_id = ! is_numeric( $price_id ) && ! is_string( $price_id ) ? 0 : $price_id; |
|
1878 | + $price_id = ! is_numeric($price_id) && ! is_string($price_id) ? 0 : $price_id; |
|
1879 | 1879 | |
1880 | 1880 | return $price_id; |
1881 | 1881 | } |
@@ -1893,10 +1893,10 @@ discard block |
||
1893 | 1893 | * |
1894 | 1894 | * @return string |
1895 | 1895 | */ |
1896 | -function give_get_form_dropdown( $args = array(), $echo = false ) { |
|
1897 | - $form_dropdown_html = Give()->html->forms_dropdown( $args ); |
|
1896 | +function give_get_form_dropdown($args = array(), $echo = false) { |
|
1897 | + $form_dropdown_html = Give()->html->forms_dropdown($args); |
|
1898 | 1898 | |
1899 | - if ( ! $echo ) { |
|
1899 | + if ( ! $echo) { |
|
1900 | 1900 | return $form_dropdown_html; |
1901 | 1901 | } |
1902 | 1902 | |
@@ -1913,17 +1913,17 @@ discard block |
||
1913 | 1913 | * |
1914 | 1914 | * @return string|bool |
1915 | 1915 | */ |
1916 | -function give_get_form_variable_price_dropdown( $args = array(), $echo = false ) { |
|
1916 | +function give_get_form_variable_price_dropdown($args = array(), $echo = false) { |
|
1917 | 1917 | |
1918 | 1918 | // Check for give form id. |
1919 | - if ( empty( $args['id'] ) ) { |
|
1919 | + if (empty($args['id'])) { |
|
1920 | 1920 | return false; |
1921 | 1921 | } |
1922 | 1922 | |
1923 | - $form = new Give_Donate_Form( $args['id'] ); |
|
1923 | + $form = new Give_Donate_Form($args['id']); |
|
1924 | 1924 | |
1925 | 1925 | // Check if form has variable prices or not. |
1926 | - if ( ! $form->ID || ! $form->has_variable_prices() ) { |
|
1926 | + if ( ! $form->ID || ! $form->has_variable_prices()) { |
|
1927 | 1927 | return false; |
1928 | 1928 | } |
1929 | 1929 | |
@@ -1931,24 +1931,24 @@ discard block |
||
1931 | 1931 | $variable_price_options = array(); |
1932 | 1932 | |
1933 | 1933 | // Check if multi donation form support custom donation or not. |
1934 | - if ( $form->is_custom_price_mode() ) { |
|
1935 | - $variable_price_options['custom'] = _x( 'Custom', 'custom donation dropdown item', 'give' ); |
|
1934 | + if ($form->is_custom_price_mode()) { |
|
1935 | + $variable_price_options['custom'] = _x('Custom', 'custom donation dropdown item', 'give'); |
|
1936 | 1936 | } |
1937 | 1937 | |
1938 | 1938 | // Get variable price and ID from variable price array. |
1939 | - foreach ( $variable_prices as $variable_price ) { |
|
1940 | - $variable_price_options[ $variable_price['_give_id']['level_id'] ] = ! empty( $variable_price['_give_text'] ) ? $variable_price['_give_text'] : give_currency_filter( give_format_amount( $variable_price['_give_amount'], array( 'sanitize' => false ) ) ); |
|
1939 | + foreach ($variable_prices as $variable_price) { |
|
1940 | + $variable_price_options[$variable_price['_give_id']['level_id']] = ! empty($variable_price['_give_text']) ? $variable_price['_give_text'] : give_currency_filter(give_format_amount($variable_price['_give_amount'], array('sanitize' => false))); |
|
1941 | 1941 | } |
1942 | 1942 | |
1943 | 1943 | // Update options. |
1944 | - $args = array_merge( $args, array( |
|
1944 | + $args = array_merge($args, array( |
|
1945 | 1945 | 'options' => $variable_price_options, |
1946 | - ) ); |
|
1946 | + )); |
|
1947 | 1947 | |
1948 | 1948 | // Generate select html. |
1949 | - $form_dropdown_html = Give()->html->select( $args ); |
|
1949 | + $form_dropdown_html = Give()->html->select($args); |
|
1950 | 1950 | |
1951 | - if ( ! $echo ) { |
|
1951 | + if ( ! $echo) { |
|
1952 | 1952 | return $form_dropdown_html; |
1953 | 1953 | } |
1954 | 1954 | |
@@ -1967,16 +1967,16 @@ discard block |
||
1967 | 1967 | * |
1968 | 1968 | * @return string |
1969 | 1969 | */ |
1970 | -function give_get_payment_meta_price_id( $payment_meta ) { |
|
1970 | +function give_get_payment_meta_price_id($payment_meta) { |
|
1971 | 1971 | |
1972 | - if ( isset( $payment_meta['give_price_id'] ) ) { |
|
1972 | + if (isset($payment_meta['give_price_id'])) { |
|
1973 | 1973 | $price_id = $payment_meta['give_price_id']; |
1974 | - } elseif ( isset( $payment_meta['price_id'] ) ) { |
|
1974 | + } elseif (isset($payment_meta['price_id'])) { |
|
1975 | 1975 | $price_id = $payment_meta['price_id']; |
1976 | 1976 | } else { |
1977 | - $price_id = give_get_price_id( $payment_meta['give_form_id'], $payment_meta['price'] ); |
|
1977 | + $price_id = give_get_price_id($payment_meta['give_form_id'], $payment_meta['price']); |
|
1978 | 1978 | } |
1979 | 1979 | |
1980 | - return apply_filters( 'give_get_payment_meta_price_id', $price_id ); |
|
1980 | + return apply_filters('give_get_payment_meta_price_id', $price_id); |
|
1981 | 1981 | |
1982 | 1982 | } |
@@ -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 | |
@@ -23,33 +23,33 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @return mixed |
25 | 25 | */ |
26 | -function give_get_currency_formatting_settings( $id_or_currency_code = null ) { |
|
26 | +function give_get_currency_formatting_settings($id_or_currency_code = null) { |
|
27 | 27 | $give_options = give_get_settings(); |
28 | 28 | $setting = array(); |
29 | 29 | |
30 | - if ( ! empty( $id_or_currency_code ) ) { |
|
31 | - $currencies = give_get_currencies('all'); |
|
30 | + if ( ! empty($id_or_currency_code)) { |
|
31 | + $currencies = give_get_currencies('all'); |
|
32 | 32 | |
33 | 33 | // Set default formatting setting only if currency not set as global currency. |
34 | 34 | |
35 | - if( is_string( $id_or_currency_code ) && ( $id_or_currency_code !== $give_options['currency'] ) && array_key_exists( $id_or_currency_code, $currencies ) ) { |
|
36 | - $setting = $currencies[ $id_or_currency_code ]['setting']; |
|
37 | - }elseif ( is_numeric( $id_or_currency_code ) && 'give_payment' === get_post_type( $id_or_currency_code ) ) { |
|
38 | - $donation_meta = give_get_meta( $id_or_currency_code, '_give_payment_meta', true ); |
|
35 | + if (is_string($id_or_currency_code) && ($id_or_currency_code !== $give_options['currency']) && array_key_exists($id_or_currency_code, $currencies)) { |
|
36 | + $setting = $currencies[$id_or_currency_code]['setting']; |
|
37 | + }elseif (is_numeric($id_or_currency_code) && 'give_payment' === get_post_type($id_or_currency_code)) { |
|
38 | + $donation_meta = give_get_meta($id_or_currency_code, '_give_payment_meta', true); |
|
39 | 39 | |
40 | 40 | if ( |
41 | - ! empty( $donation_meta['currency'] ) && |
|
41 | + ! empty($donation_meta['currency']) && |
|
42 | 42 | $give_options['currency'] !== $donation_meta['currency'] |
43 | 43 | ) { |
44 | - $setting = $currencies[ $donation_meta['currency'] ]['setting']; |
|
44 | + $setting = $currencies[$donation_meta['currency']]['setting']; |
|
45 | 45 | } |
46 | 46 | } |
47 | 47 | } |
48 | 48 | |
49 | - if ( empty( $setting ) ) { |
|
49 | + if (empty($setting)) { |
|
50 | 50 | // Set thousand separator. |
51 | - $thousand_separator = isset( $give_options['thousands_separator'] ) ? $give_options['thousands_separator'] : ','; |
|
52 | - $thousand_separator = empty( $thousand_separator ) ? ' ' : $thousand_separator; |
|
51 | + $thousand_separator = isset($give_options['thousands_separator']) ? $give_options['thousands_separator'] : ','; |
|
52 | + $thousand_separator = empty($thousand_separator) ? ' ' : $thousand_separator; |
|
53 | 53 | |
54 | 54 | // Set decimal separator. |
55 | 55 | $default_decimal_separators = array( |
@@ -57,17 +57,16 @@ discard block |
||
57 | 57 | ',' => '.', |
58 | 58 | ); |
59 | 59 | |
60 | - $default_decimal_separator = in_array( $thousand_separator, $default_decimal_separators ) ? |
|
61 | - $default_decimal_separators[ $thousand_separator ] : |
|
62 | - '.'; |
|
60 | + $default_decimal_separator = in_array($thousand_separator, $default_decimal_separators) ? |
|
61 | + $default_decimal_separators[$thousand_separator] : '.'; |
|
63 | 62 | |
64 | - $decimal_separator = ! empty( $give_options['decimal_separator'] ) ? $give_options['decimal_separator'] : $default_decimal_separator; |
|
63 | + $decimal_separator = ! empty($give_options['decimal_separator']) ? $give_options['decimal_separator'] : $default_decimal_separator; |
|
65 | 64 | |
66 | 65 | $setting = array( |
67 | - 'currency_position' => give_get_option( 'currency_position', 'before' ), |
|
66 | + 'currency_position' => give_get_option('currency_position', 'before'), |
|
68 | 67 | 'thousands_separator' => $thousand_separator, |
69 | 68 | 'decimal_separator' => $decimal_separator, |
70 | - 'number_decimals' => give_get_option( 'number_decimals', 0 ), |
|
69 | + 'number_decimals' => give_get_option('number_decimals', 0), |
|
71 | 70 | ); |
72 | 71 | } |
73 | 72 | |
@@ -77,7 +76,7 @@ discard block |
||
77 | 76 | * |
78 | 77 | * @since 1.8.15 |
79 | 78 | */ |
80 | - return apply_filters( 'give_get_currency_formatting_settings', $setting, $id_or_currency_code ); |
|
79 | + return apply_filters('give_get_currency_formatting_settings', $setting, $id_or_currency_code); |
|
81 | 80 | } |
82 | 81 | |
83 | 82 | /** |
@@ -89,16 +88,16 @@ discard block |
||
89 | 88 | * |
90 | 89 | * @return mixed |
91 | 90 | */ |
92 | -function give_get_price_decimals( $id_or_currency_code = null ) { |
|
91 | +function give_get_price_decimals($id_or_currency_code = null) { |
|
93 | 92 | // Set currency on basis of donation id. |
94 | - if( empty( $id_or_currency_code ) ){ |
|
93 | + if (empty($id_or_currency_code)) { |
|
95 | 94 | $id_or_currency_code = give_get_currency(); |
96 | 95 | } |
97 | 96 | |
98 | 97 | $number_of_decimals = 0; |
99 | 98 | |
100 | - if( ! give_is_zero_based_currency( $id_or_currency_code ) ){ |
|
101 | - $setting = give_get_currency_formatting_settings( $id_or_currency_code ); |
|
99 | + if ( ! give_is_zero_based_currency($id_or_currency_code)) { |
|
100 | + $setting = give_get_currency_formatting_settings($id_or_currency_code); |
|
102 | 101 | $number_of_decimals = $setting['number_decimals']; |
103 | 102 | } |
104 | 103 | |
@@ -107,7 +106,7 @@ discard block |
||
107 | 106 | * |
108 | 107 | * @since 1.6 |
109 | 108 | */ |
110 | - return apply_filters( 'give_sanitize_amount_decimals', $number_of_decimals, $id_or_currency_code ); |
|
109 | + return apply_filters('give_sanitize_amount_decimals', $number_of_decimals, $id_or_currency_code); |
|
111 | 110 | } |
112 | 111 | |
113 | 112 | /** |
@@ -119,15 +118,15 @@ discard block |
||
119 | 118 | * |
120 | 119 | * @return mixed |
121 | 120 | */ |
122 | -function give_get_price_thousand_separator( $id_or_currency_code = null ) { |
|
123 | - $setting = give_get_currency_formatting_settings( $id_or_currency_code ); |
|
121 | +function give_get_price_thousand_separator($id_or_currency_code = null) { |
|
122 | + $setting = give_get_currency_formatting_settings($id_or_currency_code); |
|
124 | 123 | |
125 | 124 | /** |
126 | 125 | * Filter the thousand separator |
127 | 126 | * |
128 | 127 | * @since 1.6 |
129 | 128 | */ |
130 | - return apply_filters( 'give_get_price_thousand_separator', $setting['thousands_separator'], $id_or_currency_code ); |
|
129 | + return apply_filters('give_get_price_thousand_separator', $setting['thousands_separator'], $id_or_currency_code); |
|
131 | 130 | } |
132 | 131 | |
133 | 132 | /** |
@@ -139,15 +138,15 @@ discard block |
||
139 | 138 | * |
140 | 139 | * @return mixed |
141 | 140 | */ |
142 | -function give_get_price_decimal_separator( $id_or_currency_code = null ) { |
|
143 | - $setting = give_get_currency_formatting_settings( $id_or_currency_code ); |
|
141 | +function give_get_price_decimal_separator($id_or_currency_code = null) { |
|
142 | + $setting = give_get_currency_formatting_settings($id_or_currency_code); |
|
144 | 143 | |
145 | 144 | /** |
146 | 145 | * Filter the thousand separator |
147 | 146 | * |
148 | 147 | * @since 1.6 |
149 | 148 | */ |
150 | - return apply_filters( 'give_get_price_decimal_separator', $setting['decimal_separator'], $id_or_currency_code ); |
|
149 | + return apply_filters('give_get_price_decimal_separator', $setting['decimal_separator'], $id_or_currency_code); |
|
151 | 150 | } |
152 | 151 | |
153 | 152 | |
@@ -160,8 +159,8 @@ discard block |
||
160 | 159 | * |
161 | 160 | * @return string $amount Newly sanitized amount |
162 | 161 | */ |
163 | -function give_sanitize_amount_for_db( $number ) { |
|
164 | - return give_maybe_sanitize_amount( $number, 6 ); |
|
162 | +function give_sanitize_amount_for_db($number) { |
|
163 | + return give_maybe_sanitize_amount($number, 6); |
|
165 | 164 | } |
166 | 165 | |
167 | 166 | /** |
@@ -175,29 +174,29 @@ discard block |
||
175 | 174 | * |
176 | 175 | * @return string $amount Newly sanitized amount |
177 | 176 | */ |
178 | -function give_maybe_sanitize_amount( $number, $dp = false, $trim_zeros = false ) { |
|
177 | +function give_maybe_sanitize_amount($number, $dp = false, $trim_zeros = false) { |
|
179 | 178 | $thousand_separator = give_get_price_thousand_separator(); |
180 | 179 | $decimal_separator = give_get_price_decimal_separator(); |
181 | - $number_decimals = is_bool( $dp ) ? give_get_price_decimals() : $dp; |
|
180 | + $number_decimals = is_bool($dp) ? give_get_price_decimals() : $dp; |
|
182 | 181 | |
183 | 182 | // Explode number by . decimal separator. |
184 | - $number_parts = explode( '.', $number ); |
|
183 | + $number_parts = explode('.', $number); |
|
185 | 184 | |
186 | 185 | /* |
187 | 186 | * Bailout: Quick format number |
188 | 187 | */ |
189 | - if ( empty( $number ) || ( ! is_numeric( $number ) && ! is_string( $number ) ) ) { |
|
188 | + if (empty($number) || ( ! is_numeric($number) && ! is_string($number))) { |
|
190 | 189 | return $number; |
191 | 190 | } |
192 | 191 | |
193 | 192 | // Remove currency symbols from number if any. |
194 | - $number = trim( str_replace( give_currency_symbols( true ), '', $number ) ); |
|
193 | + $number = trim(str_replace(give_currency_symbols(true), '', $number)); |
|
195 | 194 | |
196 | 195 | if ( |
197 | 196 | // Non formatted number. |
198 | 197 | ( |
199 | - ( false === strpos( $number, $thousand_separator ) ) && |
|
200 | - ( false === strpos( $number, $decimal_separator ) ) |
|
198 | + (false === strpos($number, $thousand_separator)) && |
|
199 | + (false === strpos($number, $decimal_separator)) |
|
201 | 200 | ) || |
202 | 201 | |
203 | 202 | // Decimal formatted number. |
@@ -208,35 +207,35 @@ discard block |
||
208 | 207 | ( |
209 | 208 | $number_decimals && |
210 | 209 | '.' === $thousand_separator && |
211 | - false !== strpos( $number, $thousand_separator ) && |
|
212 | - false === strpos( $number, $decimal_separator ) && |
|
213 | - 2 === count( $number_parts ) && |
|
214 | - ( $number_decimals >= strlen( $number_parts[1] ) ) |
|
210 | + false !== strpos($number, $thousand_separator) && |
|
211 | + false === strpos($number, $decimal_separator) && |
|
212 | + 2 === count($number_parts) && |
|
213 | + ($number_decimals >= strlen($number_parts[1])) |
|
215 | 214 | ) |
216 | 215 | ) { |
217 | - return number_format( $number, $number_decimals, '.', '' ); |
|
216 | + return number_format($number, $number_decimals, '.', ''); |
|
218 | 217 | } |
219 | 218 | |
220 | 219 | // Handle thousand separator as '.' |
221 | 220 | // Handle sanitize database values. |
222 | - $is_db_sanitize_val = ( 2 === count( $number_parts ) && |
|
223 | - is_numeric( $number_parts[0] ) && |
|
224 | - is_numeric( $number_parts[1] ) && |
|
225 | - ( 6 === strlen( $number_parts[1] ) ) ); |
|
221 | + $is_db_sanitize_val = (2 === count($number_parts) && |
|
222 | + is_numeric($number_parts[0]) && |
|
223 | + is_numeric($number_parts[1]) && |
|
224 | + (6 === strlen($number_parts[1]))); |
|
226 | 225 | |
227 | - if ( $is_db_sanitize_val ) { |
|
226 | + if ($is_db_sanitize_val) { |
|
228 | 227 | // Sanitize database value. |
229 | - return number_format( $number, $number_decimals, '.', '' ); |
|
228 | + return number_format($number, $number_decimals, '.', ''); |
|
230 | 229 | |
231 | 230 | } elseif ( |
232 | 231 | '.' === $thousand_separator && |
233 | - false !== strpos( $number, $thousand_separator ) |
|
232 | + false !== strpos($number, $thousand_separator) |
|
234 | 233 | ) { |
235 | 234 | // Fix point thousand separator value. |
236 | - $number = str_replace( '.', '', $number ); |
|
235 | + $number = str_replace('.', '', $number); |
|
237 | 236 | } |
238 | 237 | |
239 | - return give_sanitize_amount( $number, $number_decimals, $trim_zeros ); |
|
238 | + return give_sanitize_amount($number, $number_decimals, $trim_zeros); |
|
240 | 239 | } |
241 | 240 | |
242 | 241 | /** |
@@ -254,67 +253,67 @@ discard block |
||
254 | 253 | * |
255 | 254 | * @return string $amount Newly sanitized amount |
256 | 255 | */ |
257 | -function give_sanitize_amount( $number, $dp = false, $trim_zeros = false ) { |
|
256 | +function give_sanitize_amount($number, $dp = false, $trim_zeros = false) { |
|
258 | 257 | |
259 | 258 | // Bailout. |
260 | - if ( empty( $number ) || ( ! is_numeric( $number ) && ! is_string( $number ) ) ) { |
|
259 | + if (empty($number) || ( ! is_numeric($number) && ! is_string($number))) { |
|
261 | 260 | return $number; |
262 | 261 | } |
263 | 262 | |
264 | 263 | // Remove slash from amount. |
265 | 264 | // If thousand or decimal separator is set to ' then in $_POST or $_GET param we will get an escaped number. |
266 | 265 | // To prevent notices and warning remove slash from amount/number. |
267 | - $number = wp_unslash( $number ); |
|
266 | + $number = wp_unslash($number); |
|
268 | 267 | |
269 | 268 | $thousand_separator = give_get_price_thousand_separator(); |
270 | 269 | |
271 | 270 | $locale = localeconv(); |
272 | - $decimals = array( give_get_price_decimal_separator(), $locale['decimal_point'], $locale['mon_decimal_point'] ); |
|
271 | + $decimals = array(give_get_price_decimal_separator(), $locale['decimal_point'], $locale['mon_decimal_point']); |
|
273 | 272 | |
274 | 273 | // Remove locale from string |
275 | - if ( ! is_float( $number ) ) { |
|
276 | - $number = str_replace( $decimals, '.', $number ); |
|
274 | + if ( ! is_float($number)) { |
|
275 | + $number = str_replace($decimals, '.', $number); |
|
277 | 276 | } |
278 | 277 | |
279 | 278 | // Remove thousand amount formatting if amount has. |
280 | 279 | // This condition use to add backward compatibility to version before 1.6, because before version 1.6 we were saving formatted amount to db. |
281 | 280 | // Do not replace thousand separator from price if it is same as decimal separator, because it will be already replace by above code. |
282 | - if ( ! in_array( $thousand_separator, $decimals ) && ( false !== strpos( $number, $thousand_separator ) ) ) { |
|
283 | - $number = str_replace( $thousand_separator, '', $number ); |
|
284 | - } elseif ( in_array( $thousand_separator, $decimals ) ) { |
|
285 | - $number = preg_replace( '/\.(?=.*\.)/', '', $number ); |
|
281 | + if ( ! in_array($thousand_separator, $decimals) && (false !== strpos($number, $thousand_separator))) { |
|
282 | + $number = str_replace($thousand_separator, '', $number); |
|
283 | + } elseif (in_array($thousand_separator, $decimals)) { |
|
284 | + $number = preg_replace('/\.(?=.*\.)/', '', $number); |
|
286 | 285 | } |
287 | 286 | |
288 | 287 | // Remove non numeric entity before decimal separator. |
289 | - $number = preg_replace( '/[^0-9\.]/', '', $number ); |
|
288 | + $number = preg_replace('/[^0-9\.]/', '', $number); |
|
290 | 289 | $default_dp = give_get_price_decimals(); |
291 | 290 | |
292 | 291 | // Reset negative amount to zero. |
293 | - if ( 0 > $number ) { |
|
294 | - $number = number_format( 0, $default_dp, '.' ); |
|
292 | + if (0 > $number) { |
|
293 | + $number = number_format(0, $default_dp, '.'); |
|
295 | 294 | } |
296 | 295 | |
297 | 296 | // If number does not have decimal then add number of decimals to it. |
298 | 297 | if ( |
299 | - false === strpos( $number, '.' ) |
|
300 | - || ( $default_dp > strlen( substr( $number, strpos( $number, '.' ) + 1 ) ) ) |
|
298 | + false === strpos($number, '.') |
|
299 | + || ($default_dp > strlen(substr($number, strpos($number, '.') + 1))) |
|
301 | 300 | ) { |
302 | - $number = number_format( $number, $default_dp, '.', '' ); |
|
301 | + $number = number_format($number, $default_dp, '.', ''); |
|
303 | 302 | } |
304 | 303 | |
305 | 304 | // Format number by custom number of decimals. |
306 | - if ( false !== $dp ) { |
|
307 | - $dp = intval( is_bool( $dp ) ? $default_dp : $dp ); |
|
308 | - $dp = apply_filters( 'give_sanitize_amount_decimals', $dp, $number ); |
|
309 | - $number = number_format( floatval( $number ), $dp, '.', '' ); |
|
305 | + if (false !== $dp) { |
|
306 | + $dp = intval(is_bool($dp) ? $default_dp : $dp); |
|
307 | + $dp = apply_filters('give_sanitize_amount_decimals', $dp, $number); |
|
308 | + $number = number_format(floatval($number), $dp, '.', ''); |
|
310 | 309 | } |
311 | 310 | |
312 | 311 | // Trim zeros. |
313 | - if ( $trim_zeros && strstr( $number, '.' ) ) { |
|
314 | - $number = rtrim( rtrim( $number, '0' ), '.' ); |
|
312 | + if ($trim_zeros && strstr($number, '.')) { |
|
313 | + $number = rtrim(rtrim($number, '0'), '.'); |
|
315 | 314 | } |
316 | 315 | |
317 | - return apply_filters( 'give_sanitize_amount', $number ); |
|
316 | + return apply_filters('give_sanitize_amount', $number); |
|
318 | 317 | } |
319 | 318 | |
320 | 319 | /** |
@@ -327,10 +326,10 @@ discard block |
||
327 | 326 | * |
328 | 327 | * @return string $amount Newly formatted amount or Price Not Available |
329 | 328 | */ |
330 | -function give_format_amount( $amount, $args = array() ) { |
|
329 | +function give_format_amount($amount, $args = array()) { |
|
331 | 330 | // Backward compatibility. |
332 | - if( is_bool( $args ) ) { |
|
333 | - $args = array( 'decimal' => $args ); |
|
331 | + if (is_bool($args)) { |
|
332 | + $args = array('decimal' => $args); |
|
334 | 333 | } |
335 | 334 | |
336 | 335 | $default_args = array( |
@@ -340,62 +339,61 @@ discard block |
||
340 | 339 | 'currency' => '', |
341 | 340 | ); |
342 | 341 | |
343 | - $args = wp_parse_args( $args, $default_args ); |
|
342 | + $args = wp_parse_args($args, $default_args); |
|
344 | 343 | |
345 | 344 | // Set Currency based on donation id, if required. |
346 | - if( $args['donation_id'] && empty( $args['currency'] ) ) { |
|
347 | - $donation_meta = give_get_meta( $args['donation_id'], '_give_payment_meta', true ); |
|
345 | + if ($args['donation_id'] && empty($args['currency'])) { |
|
346 | + $donation_meta = give_get_meta($args['donation_id'], '_give_payment_meta', true); |
|
348 | 347 | $args['currency'] = $donation_meta['currency']; |
349 | 348 | } |
350 | 349 | |
351 | 350 | $formatted = 0; |
352 | - $currency = ! empty( $args['currency'] ) ? $args['currency'] : give_get_currency( $args['donation_id'] ); |
|
353 | - $thousands_sep = give_get_price_thousand_separator( $currency ); |
|
354 | - $decimal_sep = give_get_price_decimal_separator( $currency ); |
|
355 | - $decimals = ! empty( $args['decimal'] ) ? give_get_price_decimals( $currency ) : 0; |
|
351 | + $currency = ! empty($args['currency']) ? $args['currency'] : give_get_currency($args['donation_id']); |
|
352 | + $thousands_sep = give_get_price_thousand_separator($currency); |
|
353 | + $decimal_sep = give_get_price_decimal_separator($currency); |
|
354 | + $decimals = ! empty($args['decimal']) ? give_get_price_decimals($currency) : 0; |
|
356 | 355 | |
357 | - if ( ! empty( $amount ) ) { |
|
356 | + if ( ! empty($amount)) { |
|
358 | 357 | // Sanitize amount before formatting. |
359 | - $amount = ! empty( $args['sanitize'] ) ? |
|
360 | - give_maybe_sanitize_amount( $amount, $decimals ) : |
|
361 | - number_format( $amount, $decimals, '.', '' ); |
|
358 | + $amount = ! empty($args['sanitize']) ? |
|
359 | + give_maybe_sanitize_amount($amount, $decimals) : number_format($amount, $decimals, '.', ''); |
|
362 | 360 | |
363 | - switch ( $currency ) { |
|
361 | + switch ($currency) { |
|
364 | 362 | case 'INR': |
365 | 363 | $decimal_amount = ''; |
366 | 364 | |
367 | 365 | // Extract decimals from amount |
368 | - if ( ( $pos = strpos( $amount, '.' ) ) !== false ) { |
|
369 | - if ( ! empty( $decimals ) ) { |
|
370 | - $decimal_amount = substr( round( substr( $amount, $pos ), $decimals ), 1 ); |
|
371 | - $amount = substr( $amount, 0, $pos ); |
|
372 | - |
|
373 | - if ( ! $decimal_amount ) { |
|
374 | - $decimal_amount = substr( '.0000000000', 0, ( $decimals + 1 ) ); |
|
375 | - } elseif ( ( $decimals + 1 ) > strlen( $decimal_amount ) ) { |
|
376 | - $decimal_amount = substr( "{$decimal_amount}000000000", 0, ( $decimals + 1 ) ); |
|
366 | + if (($pos = strpos($amount, '.')) !== false) { |
|
367 | + if ( ! empty($decimals)) { |
|
368 | + $decimal_amount = substr(round(substr($amount, $pos), $decimals), 1); |
|
369 | + $amount = substr($amount, 0, $pos); |
|
370 | + |
|
371 | + if ( ! $decimal_amount) { |
|
372 | + $decimal_amount = substr('.0000000000', 0, ($decimals + 1)); |
|
373 | + } elseif (($decimals + 1) > strlen($decimal_amount)) { |
|
374 | + $decimal_amount = substr("{$decimal_amount}000000000", 0, ($decimals + 1)); |
|
377 | 375 | } |
378 | 376 | |
379 | 377 | } else { |
380 | - $amount = number_format( $amount, $decimals, $decimal_sep, '' ); |
|
378 | + $amount = number_format($amount, $decimals, $decimal_sep, ''); |
|
381 | 379 | } |
382 | 380 | } |
383 | 381 | |
384 | 382 | // Extract last 3 from amount |
385 | - $result = substr( $amount, - 3 ); |
|
386 | - $amount = substr( $amount, 0, - 3 ); |
|
383 | + $result = substr($amount, - 3); |
|
384 | + $amount = substr($amount, 0, - 3); |
|
387 | 385 | |
388 | 386 | // Apply digits 2 by 2 |
389 | - while ( strlen( $amount ) > 0 ) { |
|
390 | - $result = substr( $amount, - 2 ) . $thousands_sep . $result; |
|
391 | - $amount = substr( $amount, 0, - 2 ); |
|
387 | + while (strlen($amount) > 0) { |
|
388 | + $result = substr($amount, - 2).$thousands_sep.$result; |
|
389 | + $amount = substr($amount, 0, - 2); |
|
392 | 390 | } |
393 | 391 | |
394 | - $formatted = $result . $decimal_amount; |
|
392 | + $formatted = $result.$decimal_amount; |
|
395 | 393 | break; |
396 | 394 | |
397 | 395 | default: |
398 | - $formatted = number_format( $amount, $decimals, $decimal_sep, $thousands_sep ); |
|
396 | + $formatted = number_format($amount, $decimals, $decimal_sep, $thousands_sep); |
|
399 | 397 | } |
400 | 398 | } |
401 | 399 | |
@@ -404,7 +402,7 @@ discard block |
||
404 | 402 | * |
405 | 403 | * @since 1.0 |
406 | 404 | */ |
407 | - return apply_filters( 'give_format_amount', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $currency, $args ); |
|
405 | + return apply_filters('give_format_amount', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $currency, $args); |
|
408 | 406 | } |
409 | 407 | |
410 | 408 | |
@@ -422,14 +420,14 @@ discard block |
||
422 | 420 | * |
423 | 421 | * @return float|string formatted amount number with large number names. |
424 | 422 | */ |
425 | -function give_human_format_large_amount( $amount, $args = array() ) { |
|
423 | +function give_human_format_large_amount($amount, $args = array()) { |
|
426 | 424 | // Bailout. |
427 | - if( empty( $amount ) ) { |
|
425 | + if (empty($amount)) { |
|
428 | 426 | return ''; |
429 | 427 | }; |
430 | 428 | |
431 | 429 | // Set default currency; |
432 | - if( empty( $args['currency'] )) { |
|
430 | + if (empty($args['currency'])) { |
|
433 | 431 | $args['currency'] = give_get_currency(); |
434 | 432 | } |
435 | 433 | |
@@ -437,40 +435,40 @@ discard block |
||
437 | 435 | $thousands_sep = give_get_price_thousand_separator(); |
438 | 436 | |
439 | 437 | // Sanitize amount. |
440 | - $sanitize_amount = give_maybe_sanitize_amount( $amount ); |
|
438 | + $sanitize_amount = give_maybe_sanitize_amount($amount); |
|
441 | 439 | |
442 | 440 | // Explode amount to calculate name of large numbers. |
443 | - $amount_array = explode( $thousands_sep, $amount ); |
|
441 | + $amount_array = explode($thousands_sep, $amount); |
|
444 | 442 | |
445 | 443 | // Calculate amount parts count. |
446 | - $amount_count_parts = count( $amount_array ); |
|
444 | + $amount_count_parts = count($amount_array); |
|
447 | 445 | |
448 | 446 | // Human format amount (default). |
449 | 447 | $human_format_amount = $amount; |
450 | 448 | |
451 | - switch ( $args['currency'] ) { |
|
449 | + switch ($args['currency']) { |
|
452 | 450 | case 'INR': |
453 | 451 | // Calculate large number formatted amount. |
454 | - if ( 4 < $amount_count_parts ) { |
|
455 | - $human_format_amount = sprintf( esc_html__( '%s arab', 'give' ), round( ( $sanitize_amount / 1000000000 ), 2 ) ); |
|
456 | - } elseif ( 3 < $amount_count_parts ) { |
|
457 | - $human_format_amount = sprintf( esc_html__( '%s crore', 'give' ), round( ( $sanitize_amount / 10000000 ), 2 ) ); |
|
458 | - } elseif ( 2 < $amount_count_parts ) { |
|
459 | - $human_format_amount = sprintf( esc_html__( '%s lakh', 'give' ), round( ( $sanitize_amount / 100000 ), 2 ) ); |
|
452 | + if (4 < $amount_count_parts) { |
|
453 | + $human_format_amount = sprintf(esc_html__('%s arab', 'give'), round(($sanitize_amount / 1000000000), 2)); |
|
454 | + } elseif (3 < $amount_count_parts) { |
|
455 | + $human_format_amount = sprintf(esc_html__('%s crore', 'give'), round(($sanitize_amount / 10000000), 2)); |
|
456 | + } elseif (2 < $amount_count_parts) { |
|
457 | + $human_format_amount = sprintf(esc_html__('%s lakh', 'give'), round(($sanitize_amount / 100000), 2)); |
|
460 | 458 | } |
461 | 459 | break; |
462 | 460 | default: |
463 | 461 | // Calculate large number formatted amount. |
464 | - if ( 4 < $amount_count_parts ) { |
|
465 | - $human_format_amount = sprintf( esc_html__( '%s trillion', 'give' ), round( ( $sanitize_amount / 1000000000000 ), 2 ) ); |
|
466 | - } elseif ( 3 < $amount_count_parts ) { |
|
467 | - $human_format_amount = sprintf( esc_html__( '%s billion', 'give' ), round( ( $sanitize_amount / 1000000000 ), 2 ) ); |
|
468 | - } elseif ( 2 < $amount_count_parts ) { |
|
469 | - $human_format_amount = sprintf( esc_html__( '%s million', 'give' ), round( ( $sanitize_amount / 1000000 ), 2 ) ); |
|
462 | + if (4 < $amount_count_parts) { |
|
463 | + $human_format_amount = sprintf(esc_html__('%s trillion', 'give'), round(($sanitize_amount / 1000000000000), 2)); |
|
464 | + } elseif (3 < $amount_count_parts) { |
|
465 | + $human_format_amount = sprintf(esc_html__('%s billion', 'give'), round(($sanitize_amount / 1000000000), 2)); |
|
466 | + } elseif (2 < $amount_count_parts) { |
|
467 | + $human_format_amount = sprintf(esc_html__('%s million', 'give'), round(($sanitize_amount / 1000000), 2)); |
|
470 | 468 | } |
471 | 469 | } |
472 | 470 | |
473 | - return apply_filters( 'give_human_format_large_amount', $human_format_amount, $amount, $sanitize_amount ); |
|
471 | + return apply_filters('give_human_format_large_amount', $human_format_amount, $amount, $sanitize_amount); |
|
474 | 472 | } |
475 | 473 | |
476 | 474 | /** |
@@ -484,17 +482,16 @@ discard block |
||
484 | 482 | * |
485 | 483 | * @return string $amount Newly formatted amount or Price Not Available |
486 | 484 | */ |
487 | -function give_format_decimal( $amount, $dp = false, $sanitize = true ) { |
|
485 | +function give_format_decimal($amount, $dp = false, $sanitize = true) { |
|
488 | 486 | $decimal_separator = give_get_price_decimal_separator(); |
489 | 487 | $formatted_amount = $sanitize ? |
490 | - give_maybe_sanitize_amount( $amount, $dp ) : |
|
491 | - number_format( $amount, ( is_bool( $dp ) ? give_get_price_decimals() : $dp ), '.', '' ); |
|
488 | + give_maybe_sanitize_amount($amount, $dp) : number_format($amount, (is_bool($dp) ? give_get_price_decimals() : $dp), '.', ''); |
|
492 | 489 | |
493 | - if ( false !== strpos( $formatted_amount, '.' ) ) { |
|
494 | - $formatted_amount = str_replace( '.', $decimal_separator, $formatted_amount ); |
|
490 | + if (false !== strpos($formatted_amount, '.')) { |
|
491 | + $formatted_amount = str_replace('.', $decimal_separator, $formatted_amount); |
|
495 | 492 | } |
496 | 493 | |
497 | - return apply_filters( 'give_format_decimal', $formatted_amount, $amount, $decimal_separator ); |
|
494 | + return apply_filters('give_format_decimal', $formatted_amount, $amount, $decimal_separator); |
|
498 | 495 | } |
499 | 496 | |
500 | 497 | /** |
@@ -508,24 +505,24 @@ discard block |
||
508 | 505 | * |
509 | 506 | * @return mixed|string |
510 | 507 | */ |
511 | -function give_currency_filter( $price = '', $currency = '', $decode_currency = false ) { |
|
508 | +function give_currency_filter($price = '', $currency = '', $decode_currency = false) { |
|
512 | 509 | |
513 | - if ( empty( $currency ) || ! array_key_exists( (string) $currency, give_get_currencies() ) ) { |
|
510 | + if (empty($currency) || ! array_key_exists((string) $currency, give_get_currencies())) { |
|
514 | 511 | $currency = give_get_currency(); |
515 | 512 | } |
516 | 513 | |
517 | - $position = give_get_option( 'currency_position', 'before' ); |
|
514 | + $position = give_get_option('currency_position', 'before'); |
|
518 | 515 | |
519 | 516 | $negative = $price < 0; |
520 | 517 | |
521 | - if ( $negative ) { |
|
518 | + if ($negative) { |
|
522 | 519 | // Remove proceeding "-". |
523 | - $price = substr( $price, 1 ); |
|
520 | + $price = substr($price, 1); |
|
524 | 521 | } |
525 | 522 | |
526 | - $symbol = give_currency_symbol( $currency, $decode_currency ); |
|
523 | + $symbol = give_currency_symbol($currency, $decode_currency); |
|
527 | 524 | |
528 | - switch ( $currency ) : |
|
525 | + switch ($currency) : |
|
529 | 526 | case 'GBP' : |
530 | 527 | case 'BRL' : |
531 | 528 | case 'EUR' : |
@@ -554,13 +551,13 @@ discard block |
||
554 | 551 | case 'MAD' : |
555 | 552 | case 'KRW' : |
556 | 553 | case 'ZAR' : |
557 | - $formatted = ( 'before' === $position ? $symbol . $price : $price . $symbol ); |
|
554 | + $formatted = ('before' === $position ? $symbol.$price : $price.$symbol); |
|
558 | 555 | break; |
559 | 556 | case 'NOK' : |
560 | - $formatted = ( 'before' === $position ? $symbol . ' ' . $price : $price . ' ' . $symbol ); |
|
557 | + $formatted = ('before' === $position ? $symbol.' '.$price : $price.' '.$symbol); |
|
561 | 558 | break; |
562 | 559 | default : |
563 | - $formatted = ( 'before' === $position ? $currency . ' ' . $price : $price . ' ' . $currency ); |
|
560 | + $formatted = ('before' === $position ? $currency.' '.$price : $price.' '.$currency); |
|
564 | 561 | break; |
565 | 562 | endswitch; |
566 | 563 | |
@@ -575,11 +572,11 @@ discard block |
||
575 | 572 | * and if currency is USD and currency position is after then |
576 | 573 | * filter name will be give_usd_currency_filter_after |
577 | 574 | */ |
578 | - $formatted = apply_filters( 'give_' . strtolower( $currency ) . "_currency_filter_{$position}", $formatted, $currency, $price ); |
|
575 | + $formatted = apply_filters('give_'.strtolower($currency)."_currency_filter_{$position}", $formatted, $currency, $price); |
|
579 | 576 | |
580 | - if ( $negative ) { |
|
577 | + if ($negative) { |
|
581 | 578 | // Prepend the minus sign before the currency sign. |
582 | - $formatted = '-' . $formatted; |
|
579 | + $formatted = '-'.$formatted; |
|
583 | 580 | } |
584 | 581 | |
585 | 582 | return $formatted; |
@@ -595,7 +592,7 @@ discard block |
||
595 | 592 | * |
596 | 593 | * @return string Date format string |
597 | 594 | */ |
598 | -function give_date_format( $date_context = '' ) { |
|
595 | +function give_date_format($date_context = '') { |
|
599 | 596 | /** |
600 | 597 | * Filter the date context |
601 | 598 | * |
@@ -616,19 +613,19 @@ discard block |
||
616 | 613 | * |
617 | 614 | * } |
618 | 615 | */ |
619 | - $date_format_contexts = apply_filters( 'give_date_format_contexts', array() ); |
|
616 | + $date_format_contexts = apply_filters('give_date_format_contexts', array()); |
|
620 | 617 | |
621 | 618 | // Set date format to default date format. |
622 | - $date_format = get_option( 'date_format' ); |
|
619 | + $date_format = get_option('date_format'); |
|
623 | 620 | |
624 | 621 | // Update date format if we have non empty date format context array and non empty date format string for that context. |
625 | - if ( $date_context && ! empty( $date_format_contexts ) && array_key_exists( $date_context, $date_format_contexts ) ) { |
|
626 | - $date_format = ! empty( $date_format_contexts[ $date_context ] ) |
|
627 | - ? $date_format_contexts[ $date_context ] |
|
622 | + if ($date_context && ! empty($date_format_contexts) && array_key_exists($date_context, $date_format_contexts)) { |
|
623 | + $date_format = ! empty($date_format_contexts[$date_context]) |
|
624 | + ? $date_format_contexts[$date_context] |
|
628 | 625 | : $date_format; |
629 | 626 | } |
630 | 627 | |
631 | - return apply_filters( 'give_date_format', $date_format ); |
|
628 | + return apply_filters('give_date_format', $date_format); |
|
632 | 629 | } |
633 | 630 | |
634 | 631 | /** |
@@ -642,8 +639,8 @@ discard block |
||
642 | 639 | * |
643 | 640 | * @return string |
644 | 641 | */ |
645 | -function give_get_cache_key( $action, $query_args ) { |
|
646 | - return Give_Cache::get_key( $action, $query_args ); |
|
642 | +function give_get_cache_key($action, $query_args) { |
|
643 | + return Give_Cache::get_key($action, $query_args); |
|
647 | 644 | } |
648 | 645 | |
649 | 646 | /** |
@@ -656,11 +653,11 @@ discard block |
||
656 | 653 | * |
657 | 654 | * @return string|array |
658 | 655 | */ |
659 | -function give_clean( $var ) { |
|
660 | - if ( is_array( $var ) ) { |
|
661 | - return array_map( 'give_clean', $var ); |
|
656 | +function give_clean($var) { |
|
657 | + if (is_array($var)) { |
|
658 | + return array_map('give_clean', $var); |
|
662 | 659 | } else { |
663 | - return is_scalar( $var ) ? sanitize_text_field( $var ) : $var; |
|
660 | + return is_scalar($var) ? sanitize_text_field($var) : $var; |
|
664 | 661 | } |
665 | 662 | } |
666 | 663 | |
@@ -673,10 +670,10 @@ discard block |
||
673 | 670 | * |
674 | 671 | * @return int |
675 | 672 | */ |
676 | -function give_let_to_num( $size ) { |
|
677 | - $l = substr( $size, - 1 ); |
|
678 | - $ret = substr( $size, 0, - 1 ); |
|
679 | - switch ( strtoupper( $l ) ) { |
|
673 | +function give_let_to_num($size) { |
|
674 | + $l = substr($size, - 1); |
|
675 | + $ret = substr($size, 0, - 1); |
|
676 | + switch (strtoupper($l)) { |
|
680 | 677 | case 'P': |
681 | 678 | $ret *= 1024; |
682 | 679 | case 'T': |
@@ -701,19 +698,19 @@ discard block |
||
701 | 698 | * @param int $action |
702 | 699 | * @param array $wp_die_args |
703 | 700 | */ |
704 | -function give_validate_nonce( $nonce, $action = - 1, $wp_die_args = array() ) { |
|
701 | +function give_validate_nonce($nonce, $action = - 1, $wp_die_args = array()) { |
|
705 | 702 | |
706 | 703 | $default_wp_die_args = array( |
707 | - 'message' => esc_html__( 'Nonce verification has failed.', 'give' ), |
|
708 | - 'title' => esc_html__( 'Error', 'give' ), |
|
704 | + 'message' => esc_html__('Nonce verification has failed.', 'give'), |
|
705 | + 'title' => esc_html__('Error', 'give'), |
|
709 | 706 | 'args' => array( |
710 | 707 | 'response' => 403, |
711 | 708 | ), |
712 | 709 | ); |
713 | 710 | |
714 | - $wp_die_args = wp_parse_args( $wp_die_args, $default_wp_die_args ); |
|
711 | + $wp_die_args = wp_parse_args($wp_die_args, $default_wp_die_args); |
|
715 | 712 | |
716 | - if ( ! wp_verify_nonce( $nonce, $action ) ) { |
|
713 | + if ( ! wp_verify_nonce($nonce, $action)) { |
|
717 | 714 | wp_die( |
718 | 715 | $wp_die_args['message'], |
719 | 716 | $wp_die_args['title'], |
@@ -735,23 +732,23 @@ discard block |
||
735 | 732 | * |
736 | 733 | * @return mixed |
737 | 734 | */ |
738 | -function give_check_variable( $variable, $conditional = '', $default = false ) { |
|
735 | +function give_check_variable($variable, $conditional = '', $default = false) { |
|
739 | 736 | |
740 | - switch ( $conditional ) { |
|
737 | + switch ($conditional) { |
|
741 | 738 | case 'isset_empty': |
742 | - $variable = ( isset( $variable ) && ! empty( $variable ) ) ? $variable : $default; |
|
739 | + $variable = (isset($variable) && ! empty($variable)) ? $variable : $default; |
|
743 | 740 | break; |
744 | 741 | |
745 | 742 | case 'empty': |
746 | - $variable = ! empty( $variable ) ? $variable : $default; |
|
743 | + $variable = ! empty($variable) ? $variable : $default; |
|
747 | 744 | break; |
748 | 745 | |
749 | 746 | case 'null': |
750 | - $variable = ! is_null( $variable ) ? $variable : $default; |
|
747 | + $variable = ! is_null($variable) ? $variable : $default; |
|
751 | 748 | break; |
752 | 749 | |
753 | 750 | default: |
754 | - $variable = isset( $variable ) ? $variable : $default; |
|
751 | + $variable = isset($variable) ? $variable : $default; |
|
755 | 752 | |
756 | 753 | } |
757 | 754 |
@@ -34,7 +34,7 @@ |
||
34 | 34 | |
35 | 35 | if( is_string( $id_or_currency_code ) && ( $id_or_currency_code !== $give_options['currency'] ) && array_key_exists( $id_or_currency_code, $currencies ) ) { |
36 | 36 | $setting = $currencies[ $id_or_currency_code ]['setting']; |
37 | - }elseif ( is_numeric( $id_or_currency_code ) && 'give_payment' === get_post_type( $id_or_currency_code ) ) { |
|
37 | + } elseif ( is_numeric( $id_or_currency_code ) && 'give_payment' === get_post_type( $id_or_currency_code ) ) { |
|
38 | 38 | $donation_meta = give_get_meta( $id_or_currency_code, '_give_payment_meta', true ); |
39 | 39 | |
40 | 40 | if ( |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly. |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | * @since 1.8.13 |
21 | 21 | */ |
22 | 22 | function give_import_donation_report() { |
23 | - return get_option( 'give_import_donation_report', array() ); |
|
23 | + return get_option('give_import_donation_report', array()); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | |
@@ -29,8 +29,8 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @since 1.8.13 |
31 | 31 | */ |
32 | -function give_import_donation_report_update( $value = array() ) { |
|
33 | - update_option( 'give_import_donation_report', $value ); |
|
32 | +function give_import_donation_report_update($value = array()) { |
|
33 | + update_option('give_import_donation_report', $value); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | * @since 1.8.13 |
41 | 41 | */ |
42 | 42 | function give_import_donation_report_reset() { |
43 | - update_option( 'give_import_donation_report', array() ); |
|
43 | + update_option('give_import_donation_report', array()); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @return array|bool|Give_Donate_Form|int|null|WP_Post |
54 | 54 | */ |
55 | -function give_import_get_form_data_from_csv( $data, $import_setting = array() ) { |
|
55 | +function give_import_get_form_data_from_csv($data, $import_setting = array()) { |
|
56 | 56 | $new_form = false; |
57 | 57 | |
58 | 58 | // Get the import report |
@@ -61,58 +61,58 @@ discard block |
||
61 | 61 | $form = false; |
62 | 62 | $meta = array(); |
63 | 63 | |
64 | - if ( ! empty( $data['form_id'] ) ) { |
|
65 | - $form = new Give_Donate_Form( $data['form_id'] ); |
|
64 | + if ( ! empty($data['form_id'])) { |
|
65 | + $form = new Give_Donate_Form($data['form_id']); |
|
66 | 66 | // Add support to older php version. |
67 | 67 | $form_id = $form->get_ID(); |
68 | - if ( empty( $form_id ) ) { |
|
69 | - $report['duplicate_form'] = ( ! empty( $report['duplicate_form'] ) ? ( absint( $report['duplicate_form'] ) + 1 ) : 1 ); |
|
68 | + if (empty($form_id)) { |
|
69 | + $report['duplicate_form'] = ( ! empty($report['duplicate_form']) ? (absint($report['duplicate_form']) + 1) : 1); |
|
70 | 70 | $form = false; |
71 | 71 | } |
72 | 72 | } |
73 | 73 | |
74 | - if ( false === $form && ! empty( $data['form_title'] ) ) { |
|
75 | - $form = get_page_by_title( $data['form_title'], OBJECT, 'give_forms' ); |
|
74 | + if (false === $form && ! empty($data['form_title'])) { |
|
75 | + $form = get_page_by_title($data['form_title'], OBJECT, 'give_forms'); |
|
76 | 76 | |
77 | - if ( ! empty( $form->ID ) ) { |
|
77 | + if ( ! empty($form->ID)) { |
|
78 | 78 | |
79 | - $report['duplicate_form'] = ( ! empty( $report['duplicate_form'] ) ? ( absint( $report['duplicate_form'] ) + 1 ) : 1 ); |
|
79 | + $report['duplicate_form'] = ( ! empty($report['duplicate_form']) ? (absint($report['duplicate_form']) + 1) : 1); |
|
80 | 80 | |
81 | - $form = new Give_Donate_Form( $form->ID ); |
|
81 | + $form = new Give_Donate_Form($form->ID); |
|
82 | 82 | } else { |
83 | 83 | $form = new Give_Donate_Form(); |
84 | 84 | $args = array( |
85 | 85 | 'post_title' => $data['form_title'], |
86 | 86 | 'post_status' => 'publish', |
87 | 87 | ); |
88 | - $form = $form->create( $args ); |
|
89 | - $report['create_form'] = ( ! empty( $report['create_form'] ) ? ( absint( $report['create_form'] ) + 1 ) : 1 ); |
|
88 | + $form = $form->create($args); |
|
89 | + $report['create_form'] = ( ! empty($report['create_form']) ? (absint($report['create_form']) + 1) : 1); |
|
90 | 90 | $new_form = true; |
91 | 91 | |
92 | 92 | } |
93 | 93 | |
94 | - $form = get_page_by_title( $data['form_title'], OBJECT, 'give_forms' ); |
|
95 | - $form = new Give_Donate_Form( $form->ID ); |
|
94 | + $form = get_page_by_title($data['form_title'], OBJECT, 'give_forms'); |
|
95 | + $form = new Give_Donate_Form($form->ID); |
|
96 | 96 | } |
97 | 97 | |
98 | - if ( ! empty( $form ) && $form->get_ID() ) { |
|
99 | - if ( ! empty( $data['form_level'] ) && 'custom' != (string) strtolower( $data['form_level'] ) ) { |
|
98 | + if ( ! empty($form) && $form->get_ID()) { |
|
99 | + if ( ! empty($data['form_level']) && 'custom' != (string) strtolower($data['form_level'])) { |
|
100 | 100 | $prices = (array) $form->get_prices(); |
101 | 101 | $price_text = array(); |
102 | - foreach ( $prices as $key => $price ) { |
|
103 | - if ( isset( $price['_give_id']['level_id'] ) ) { |
|
104 | - $price_text[ $price['_give_id']['level_id'] ] = ( ! empty( $price['_give_text'] ) ? $price['_give_text'] : '' ); |
|
102 | + foreach ($prices as $key => $price) { |
|
103 | + if (isset($price['_give_id']['level_id'])) { |
|
104 | + $price_text[$price['_give_id']['level_id']] = ( ! empty($price['_give_text']) ? $price['_give_text'] : ''); |
|
105 | 105 | } |
106 | 106 | } |
107 | 107 | |
108 | - if ( ! in_array( $data['form_level'], $price_text ) ) { |
|
108 | + if ( ! in_array($data['form_level'], $price_text)) { |
|
109 | 109 | |
110 | 110 | // For generating unquiet level id. |
111 | 111 | $count = 1; |
112 | - $new_level = count( $prices ) + $count; |
|
113 | - while ( array_key_exists( $new_level, $price_text ) ) { |
|
114 | - $count ++; |
|
115 | - $new_level = count( $prices ) + $count; |
|
112 | + $new_level = count($prices) + $count; |
|
113 | + while (array_key_exists($new_level, $price_text)) { |
|
114 | + $count++; |
|
115 | + $new_level = count($prices) + $count; |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | $multi_level_donations = array( |
@@ -120,57 +120,57 @@ discard block |
||
120 | 120 | '_give_id' => array( |
121 | 121 | 'level_id' => $new_level, |
122 | 122 | ), |
123 | - '_give_amount' => give_sanitize_amount_for_db( $data['amount'] ), |
|
123 | + '_give_amount' => give_sanitize_amount_for_db($data['amount']), |
|
124 | 124 | '_give_text' => $data['form_level'], |
125 | 125 | ), |
126 | 126 | ); |
127 | 127 | |
128 | - $price_text[ $new_level ] = $data['form_level']; |
|
128 | + $price_text[$new_level] = $data['form_level']; |
|
129 | 129 | |
130 | - if ( ! empty( $prices ) && is_array( $prices ) && ! empty( $prices[0] ) ) { |
|
131 | - $prices = wp_parse_args( $multi_level_donations, $prices ); |
|
130 | + if ( ! empty($prices) && is_array($prices) && ! empty($prices[0])) { |
|
131 | + $prices = wp_parse_args($multi_level_donations, $prices); |
|
132 | 132 | |
133 | 133 | // Sort $prices by amount in ascending order. |
134 | - $prices = wp_list_sort( $prices, '_give_amount', 'ASC' ); |
|
134 | + $prices = wp_list_sort($prices, '_give_amount', 'ASC'); |
|
135 | 135 | } else { |
136 | 136 | $prices = $multi_level_donations; |
137 | 137 | } |
138 | 138 | |
139 | 139 | // Unset _give_default key from $prices. |
140 | - foreach ( $prices as $key => $price ) { |
|
141 | - if ( isset( $prices[ $key ]['_give_default'] ) ) { |
|
142 | - unset( $prices[ $key ]['_give_default'] ); |
|
140 | + foreach ($prices as $key => $price) { |
|
141 | + if (isset($prices[$key]['_give_default'])) { |
|
142 | + unset($prices[$key]['_give_default']); |
|
143 | 143 | } |
144 | 144 | } |
145 | 145 | |
146 | 146 | // Set the first $price of the $prices as defalut. |
147 | 147 | $prices[0]['_give_default'] = 'default'; |
148 | 148 | } |
149 | - $form->price_id = array_search( $data['form_level'], $price_text ); |
|
149 | + $form->price_id = array_search($data['form_level'], $price_text); |
|
150 | 150 | |
151 | - $donation_levels_amounts = wp_list_pluck( $prices, '_give_amount' ); |
|
152 | - $min_amount = min( $donation_levels_amounts ); |
|
153 | - $max_amount = max( $donation_levels_amounts ); |
|
151 | + $donation_levels_amounts = wp_list_pluck($prices, '_give_amount'); |
|
152 | + $min_amount = min($donation_levels_amounts); |
|
153 | + $max_amount = max($donation_levels_amounts); |
|
154 | 154 | |
155 | 155 | $meta = array( |
156 | 156 | '_give_levels_minimum_amount' => $min_amount, |
157 | 157 | '_give_levels_maximum_amount' => $max_amount, |
158 | 158 | '_give_price_option' => 'multi', |
159 | - '_give_donation_levels' => array_values( $prices ), |
|
159 | + '_give_donation_levels' => array_values($prices), |
|
160 | 160 | ); |
161 | 161 | } else { |
162 | 162 | $form->price_id = 'custom'; |
163 | 163 | } |
164 | 164 | |
165 | 165 | $defaults = array( |
166 | - '_give_set_price' => give_sanitize_amount_for_db( $data['amount'] ), |
|
166 | + '_give_set_price' => give_sanitize_amount_for_db($data['amount']), |
|
167 | 167 | '_give_price_option' => 'set', |
168 | 168 | ); |
169 | 169 | |
170 | 170 | // If new form is created. |
171 | - if ( ! empty( $new_form ) ) { |
|
171 | + if ( ! empty($new_form)) { |
|
172 | 172 | $new_form = array( |
173 | - '_give_custom_amount_text' => ( ! empty( $data['form_custom_amount_text'] ) ? $data['form_custom_amount_text'] : 'Custom' ), |
|
173 | + '_give_custom_amount_text' => ( ! empty($data['form_custom_amount_text']) ? $data['form_custom_amount_text'] : 'Custom'), |
|
174 | 174 | '_give_logged_in_only' => 'enabled', |
175 | 175 | '_give_custom_amount' => 'enabled', |
176 | 176 | '_give_payment_import' => true, |
@@ -181,18 +181,18 @@ discard block |
||
181 | 181 | '_give_default_gateway' => 'global', |
182 | 182 | '_give_show_register_form' => 'both', |
183 | 183 | ); |
184 | - $defaults = wp_parse_args( $defaults, $new_form ); |
|
184 | + $defaults = wp_parse_args($defaults, $new_form); |
|
185 | 185 | } |
186 | 186 | |
187 | - $meta = wp_parse_args( $meta, $defaults ); |
|
187 | + $meta = wp_parse_args($meta, $defaults); |
|
188 | 188 | |
189 | - foreach ( $meta as $key => $value ) { |
|
190 | - give_update_meta( $form->get_ID(), $key, $value ); |
|
189 | + foreach ($meta as $key => $value) { |
|
190 | + give_update_meta($form->get_ID(), $key, $value); |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | |
194 | 194 | // update the report |
195 | - give_import_donation_report_update( $report ); |
|
195 | + give_import_donation_report_update($report); |
|
196 | 196 | |
197 | 197 | return $form; |
198 | 198 | } |
@@ -206,30 +206,30 @@ discard block |
||
206 | 206 | * |
207 | 207 | * @return bool|false|WP_User |
208 | 208 | */ |
209 | -function give_import_get_user_from_csv( $data, $import_setting = array() ) { |
|
209 | +function give_import_get_user_from_csv($data, $import_setting = array()) { |
|
210 | 210 | $report = give_import_donation_report(); |
211 | 211 | $donor_data = false; |
212 | 212 | $customer_id = false; |
213 | 213 | |
214 | 214 | // check if donor id is not empty |
215 | - if ( ! empty( $data['donor_id'] ) ) { |
|
216 | - $donor_data = new Give_Donor( (int) $data['donor_id'] ); |
|
217 | - if ( ! empty( $donor_data->id ) ) { |
|
218 | - $report['duplicate_donor'] = ( ! empty( $report['duplicate_donor'] ) ? ( absint( $report['duplicate_donor'] ) + 1 ) : 1 ); |
|
215 | + if ( ! empty($data['donor_id'])) { |
|
216 | + $donor_data = new Give_Donor((int) $data['donor_id']); |
|
217 | + if ( ! empty($donor_data->id)) { |
|
218 | + $report['duplicate_donor'] = ( ! empty($report['duplicate_donor']) ? (absint($report['duplicate_donor']) + 1) : 1); |
|
219 | 219 | } |
220 | 220 | } |
221 | 221 | |
222 | - if ( empty( $donor_data->id ) && ! empty( $data['user_id'] ) ) { |
|
222 | + if (empty($donor_data->id) && ! empty($data['user_id'])) { |
|
223 | 223 | $user_id = (int) $data['user_id']; |
224 | - $donor_data = new Give_Donor( $user_id, true ); |
|
224 | + $donor_data = new Give_Donor($user_id, true); |
|
225 | 225 | |
226 | 226 | |
227 | - if ( empty( $donor_data->id ) ) { |
|
228 | - $donor_data = get_user_by( 'id', $user_id ); |
|
229 | - if ( ! empty( $donor_data->ID ) ) { |
|
230 | - $first_name = ( ! empty( $data['first_name'] ) ? $data['first_name'] : $donor_data->user_nicename ); |
|
231 | - $last_name = ( ! empty( $data['last_name'] ) ? $data['last_name'] : ( ( $lastname = get_user_meta( $donor_data->ID, 'last_name', true ) ) ? $lastname : '' ) ); |
|
232 | - $name = $first_name . ' ' . $last_name; |
|
227 | + if (empty($donor_data->id)) { |
|
228 | + $donor_data = get_user_by('id', $user_id); |
|
229 | + if ( ! empty($donor_data->ID)) { |
|
230 | + $first_name = ( ! empty($data['first_name']) ? $data['first_name'] : $donor_data->user_nicename); |
|
231 | + $last_name = ( ! empty($data['last_name']) ? $data['last_name'] : (($lastname = get_user_meta($donor_data->ID, 'last_name', true)) ? $lastname : '')); |
|
232 | + $name = $first_name.' '.$last_name; |
|
233 | 233 | $user_email = $donor_data->user_email; |
234 | 234 | $donor_args = array( |
235 | 235 | 'name' => $name, |
@@ -238,44 +238,44 @@ discard block |
||
238 | 238 | ); |
239 | 239 | |
240 | 240 | $donor_data = new Give_Donor(); |
241 | - $donor_data->create( $donor_args ); |
|
241 | + $donor_data->create($donor_args); |
|
242 | 242 | |
243 | 243 | // Adding notes that donor is being imported from CSV. |
244 | 244 | $current_user = wp_get_current_user(); |
245 | - $donor_data->add_note( esc_html( wp_sprintf( __( 'This donor was imported by %s', 'give' ), $current_user->user_email ) ) ); |
|
245 | + $donor_data->add_note(esc_html(wp_sprintf(__('This donor was imported by %s', 'give'), $current_user->user_email))); |
|
246 | 246 | |
247 | 247 | // Add is used to ensure duplicate emails are not added |
248 | - if ( $user_email != $data['email'] && ! empty( $data['email'] ) ) { |
|
249 | - $donor_data->add_meta( 'additional_email', $data['email'] ); |
|
248 | + if ($user_email != $data['email'] && ! empty($data['email'])) { |
|
249 | + $donor_data->add_meta('additional_email', $data['email']); |
|
250 | 250 | } |
251 | 251 | |
252 | - $report['create_donor'] = ( ! empty( $report['create_donor'] ) ? ( absint( $report['create_donor'] ) + 1 ) : 1 ); |
|
252 | + $report['create_donor'] = ( ! empty($report['create_donor']) ? (absint($report['create_donor']) + 1) : 1); |
|
253 | 253 | } else { |
254 | 254 | } |
255 | 255 | } else { |
256 | 256 | // Add is used to ensure duplicate emails are not added |
257 | - if ( $donor_data->email != $data['email'] ) { |
|
258 | - $donor_data->add_meta( 'additional_email', ( ! empty( $data['email'] ) ? $data['email'] : $donor_data->email ) ); |
|
257 | + if ($donor_data->email != $data['email']) { |
|
258 | + $donor_data->add_meta('additional_email', ( ! empty($data['email']) ? $data['email'] : $donor_data->email)); |
|
259 | 259 | } |
260 | - $report['duplicate_donor'] = ( ! empty( $report['duplicate_donor'] ) ? ( absint( $report['duplicate_donor'] ) + 1 ) : 1 ); |
|
260 | + $report['duplicate_donor'] = ( ! empty($report['duplicate_donor']) ? (absint($report['duplicate_donor']) + 1) : 1); |
|
261 | 261 | } |
262 | 262 | } |
263 | 263 | |
264 | - if ( empty( $donor_data->id ) && ! empty( $data['email'] ) ) { |
|
264 | + if (empty($donor_data->id) && ! empty($data['email'])) { |
|
265 | 265 | |
266 | - $donor_data = new Give_Donor( $data['email'] ); |
|
267 | - if ( empty( $donor_data->id ) ) { |
|
268 | - $donor_data = get_user_by( 'email', $data['email'] ); |
|
266 | + $donor_data = new Give_Donor($data['email']); |
|
267 | + if (empty($donor_data->id)) { |
|
268 | + $donor_data = get_user_by('email', $data['email']); |
|
269 | 269 | |
270 | - if ( empty( $donor_data->ID ) && ! empty( $data['first_name'] ) && ! empty( $data['last_name'] ) && isset( $import_setting['create_user'] ) && 1 === absint( $import_setting['create_user'] ) ) { |
|
271 | - $give_role = (array) give_get_option( 'donor_default_user_role', get_option( 'default_role', ( ( $give_donor = wp_roles()->is_role( 'give_donor' ) ) && ! empty( $give_donor ) ? 'give_donor' : 'subscriber' ) ) ); |
|
270 | + if (empty($donor_data->ID) && ! empty($data['first_name']) && ! empty($data['last_name']) && isset($import_setting['create_user']) && 1 === absint($import_setting['create_user'])) { |
|
271 | + $give_role = (array) give_get_option('donor_default_user_role', get_option('default_role', (($give_donor = wp_roles()->is_role('give_donor')) && ! empty($give_donor) ? 'give_donor' : 'subscriber'))); |
|
272 | 272 | $donor_args = array( |
273 | 273 | 'user_login' => $data['email'], |
274 | 274 | 'user_email' => $data['email'], |
275 | - 'user_registered' => date( 'Y-m-d H:i:s' ), |
|
275 | + 'user_registered' => date('Y-m-d H:i:s'), |
|
276 | 276 | 'user_first' => $data['first_name'], |
277 | 277 | 'user_last' => $data['last_name'], |
278 | - 'user_pass' => wp_generate_password( 8, true ), |
|
278 | + 'user_pass' => wp_generate_password(8, true), |
|
279 | 279 | 'role' => $give_role, |
280 | 280 | ); |
281 | 281 | |
@@ -284,56 +284,56 @@ discard block |
||
284 | 284 | * |
285 | 285 | * @since 1.8.13 |
286 | 286 | */ |
287 | - $donor_args = (array) apply_filters( 'give_import_insert_user_args', $donor_args, $data, $import_setting ); |
|
287 | + $donor_args = (array) apply_filters('give_import_insert_user_args', $donor_args, $data, $import_setting); |
|
288 | 288 | |
289 | 289 | // This action was added to remove the login when using the give register function. |
290 | - add_filter( 'give_log_user_in_on_register', 'give_log_user_in_on_register_callback', 11 ); |
|
291 | - $customer_id = give_register_and_login_new_user( $donor_args ); |
|
292 | - remove_filter( 'give_log_user_in_on_register', 'give_log_user_in_on_register_callback', 11 ); |
|
290 | + add_filter('give_log_user_in_on_register', 'give_log_user_in_on_register_callback', 11); |
|
291 | + $customer_id = give_register_and_login_new_user($donor_args); |
|
292 | + remove_filter('give_log_user_in_on_register', 'give_log_user_in_on_register_callback', 11); |
|
293 | 293 | |
294 | - update_user_meta( $customer_id, '_give_payment_import', true ); |
|
295 | - $donor_data = new Give_Donor( $customer_id, true ); |
|
294 | + update_user_meta($customer_id, '_give_payment_import', true); |
|
295 | + $donor_data = new Give_Donor($customer_id, true); |
|
296 | 296 | } else { |
297 | - $customer_id = ( ! empty( $donor_data->ID ) ? $donor_data->ID : false ); |
|
297 | + $customer_id = ( ! empty($donor_data->ID) ? $donor_data->ID : false); |
|
298 | 298 | } |
299 | 299 | |
300 | - if ( ! empty( $customer_id ) || ( isset( $import_setting['create_user'] ) && 0 === absint( $import_setting['create_user'] ) ) ) { |
|
301 | - $donor_data = new Give_Donor( $customer_id, true ); |
|
300 | + if ( ! empty($customer_id) || (isset($import_setting['create_user']) && 0 === absint($import_setting['create_user']))) { |
|
301 | + $donor_data = new Give_Donor($customer_id, true); |
|
302 | 302 | |
303 | - if ( empty( $donor_data->id ) ) { |
|
303 | + if (empty($donor_data->id)) { |
|
304 | 304 | |
305 | - if ( ! empty( $data['form_id'] ) ) { |
|
306 | - $form = new Give_Donate_Form( $data['form_id'] ); |
|
305 | + if ( ! empty($data['form_id'])) { |
|
306 | + $form = new Give_Donate_Form($data['form_id']); |
|
307 | 307 | } |
308 | 308 | |
309 | - $payment_title = ( isset( $data['form_title'] ) ? $data['form_title'] : ( isset( $form ) ? $form->get_name() : esc_html__( 'New Form', 'give' ) ) ); |
|
309 | + $payment_title = (isset($data['form_title']) ? $data['form_title'] : (isset($form) ? $form->get_name() : esc_html__('New Form', 'give'))); |
|
310 | 310 | $donor_args = array( |
311 | - 'name' => ! is_email( $payment_title ) ? $data['first_name'] . ' ' . $data['last_name'] : '', |
|
311 | + 'name' => ! is_email($payment_title) ? $data['first_name'].' '.$data['last_name'] : '', |
|
312 | 312 | 'email' => $data['email'], |
313 | 313 | ); |
314 | 314 | |
315 | - if ( ! empty( $customer_id ) ) { |
|
315 | + if ( ! empty($customer_id)) { |
|
316 | 316 | $donor_args['user_id'] = $customer_id; |
317 | 317 | } |
318 | 318 | |
319 | - $donor_data->create( $donor_args ); |
|
319 | + $donor_data->create($donor_args); |
|
320 | 320 | |
321 | 321 | // Adding notes that donor is being imported from CSV. |
322 | 322 | $current_user = wp_get_current_user(); |
323 | - $donor_data->add_note( esc_html( wp_sprintf( __( 'This donor was imported by %s', 'give' ), $current_user->user_email ) ) ); |
|
323 | + $donor_data->add_note(esc_html(wp_sprintf(__('This donor was imported by %s', 'give'), $current_user->user_email))); |
|
324 | 324 | |
325 | - $report['create_donor'] = ( ! empty( $report['create_donor'] ) ? ( absint( $report['create_donor'] ) + 1 ) : 1 ); |
|
325 | + $report['create_donor'] = ( ! empty($report['create_donor']) ? (absint($report['create_donor']) + 1) : 1); |
|
326 | 326 | } else { |
327 | - $report['duplicate_donor'] = ( ! empty( $report['duplicate_donor'] ) ? ( absint( $report['duplicate_donor'] ) + 1 ) : 1 ); |
|
327 | + $report['duplicate_donor'] = ( ! empty($report['duplicate_donor']) ? (absint($report['duplicate_donor']) + 1) : 1); |
|
328 | 328 | } |
329 | 329 | } |
330 | 330 | } else { |
331 | - $report['duplicate_donor'] = ( ! empty( $report['duplicate_donor'] ) ? ( absint( $report['duplicate_donor'] ) + 1 ) : 1 ); |
|
331 | + $report['duplicate_donor'] = ( ! empty($report['duplicate_donor']) ? (absint($report['duplicate_donor']) + 1) : 1); |
|
332 | 332 | } |
333 | 333 | } |
334 | 334 | |
335 | 335 | // update the report |
336 | - give_import_donation_report_update( $report ); |
|
336 | + give_import_donation_report_update($report); |
|
337 | 337 | |
338 | 338 | return $donor_data; |
339 | 339 | } |
@@ -351,9 +351,9 @@ discard block |
||
351 | 351 | * |
352 | 352 | * @return array |
353 | 353 | */ |
354 | - return (array) apply_filters( 'give_import_default_options', array( |
|
355 | - '' => __( 'Do not import', 'give' ), |
|
356 | - ) ); |
|
354 | + return (array) apply_filters('give_import_default_options', array( |
|
355 | + '' => __('Do not import', 'give'), |
|
356 | + )); |
|
357 | 357 | } |
358 | 358 | |
359 | 359 | /** |
@@ -369,33 +369,33 @@ discard block |
||
369 | 369 | * |
370 | 370 | * @return array |
371 | 371 | */ |
372 | - return (array) apply_filters( 'give_import_donations_options', array( |
|
373 | - 'id' => __( 'Donation ID', 'give' ), |
|
374 | - 'amount' => __( 'Donation Amount', 'give' ), |
|
375 | - 'post_date' => __( 'Donation Date', 'give' ), |
|
376 | - 'first_name' => __( 'Donor First Name', 'give' ), |
|
377 | - 'last_name' => __( 'Donor Last Name', 'give' ), |
|
378 | - 'line1' => __( 'Address 1', 'give' ), |
|
379 | - 'line2' => __( 'Address 2', 'give' ), |
|
380 | - 'city' => __( 'City', 'give' ), |
|
381 | - 'state' => __( 'State', 'give' ), |
|
372 | + return (array) apply_filters('give_import_donations_options', array( |
|
373 | + 'id' => __('Donation ID', 'give'), |
|
374 | + 'amount' => __('Donation Amount', 'give'), |
|
375 | + 'post_date' => __('Donation Date', 'give'), |
|
376 | + 'first_name' => __('Donor First Name', 'give'), |
|
377 | + 'last_name' => __('Donor Last Name', 'give'), |
|
378 | + 'line1' => __('Address 1', 'give'), |
|
379 | + 'line2' => __('Address 2', 'give'), |
|
380 | + 'city' => __('City', 'give'), |
|
381 | + 'state' => __('State', 'give'), |
|
382 | 382 | 'country' => array( |
383 | - __( 'Country', 'give' ), |
|
384 | - __( 'County', 'give' ), |
|
385 | - __( 'Region', 'give' ), |
|
386 | - __( 'Province', 'give' ), |
|
383 | + __('Country', 'give'), |
|
384 | + __('County', 'give'), |
|
385 | + __('Region', 'give'), |
|
386 | + __('Province', 'give'), |
|
387 | 387 | ), |
388 | 388 | 'zip' => array( |
389 | - __( 'Zip', 'give' ), |
|
390 | - __( 'Postal Code', 'give' ), |
|
389 | + __('Zip', 'give'), |
|
390 | + __('Postal Code', 'give'), |
|
391 | 391 | ), |
392 | - 'email' => __( 'Donor Email', 'give' ), |
|
393 | - 'post_status' => __( 'Donation Status', 'give' ), |
|
394 | - 'gateway' => __( 'Payment Method', 'give' ), |
|
395 | - 'notes' => __( 'Notes', 'give' ), |
|
396 | - 'mode' => __( 'Test Mode', 'give' ), |
|
397 | - 'post_meta' => __( 'Import as Meta', 'give' ), |
|
398 | - ) ); |
|
392 | + 'email' => __('Donor Email', 'give'), |
|
393 | + 'post_status' => __('Donation Status', 'give'), |
|
394 | + 'gateway' => __('Payment Method', 'give'), |
|
395 | + 'notes' => __('Notes', 'give'), |
|
396 | + 'mode' => __('Test Mode', 'give'), |
|
397 | + 'post_meta' => __('Import as Meta', 'give'), |
|
398 | + )); |
|
399 | 399 | } |
400 | 400 | |
401 | 401 | /** |
@@ -411,10 +411,10 @@ discard block |
||
411 | 411 | * |
412 | 412 | * @return array |
413 | 413 | */ |
414 | - return (array) apply_filters( 'give_import_donor_options', array( |
|
415 | - 'donor_id' => __( 'Donor ID', 'give' ), |
|
416 | - 'user_id' => __( 'User ID', 'give' ), |
|
417 | - ) ); |
|
414 | + return (array) apply_filters('give_import_donor_options', array( |
|
415 | + 'donor_id' => __('Donor ID', 'give'), |
|
416 | + 'user_id' => __('User ID', 'give'), |
|
417 | + )); |
|
418 | 418 | } |
419 | 419 | |
420 | 420 | /** |
@@ -430,12 +430,12 @@ discard block |
||
430 | 430 | * |
431 | 431 | * @return array |
432 | 432 | */ |
433 | - return (array) apply_filters( 'give_import_donation_form_options', array( |
|
434 | - 'form_title' => __( 'Donation Form Title', 'give' ), |
|
435 | - 'form_id' => __( 'Donation Form ID', 'give' ), |
|
436 | - 'form_level' => __( 'Donation Level', 'give' ), |
|
437 | - 'form_custom_amount_text' => __( 'Custom Amount Text', 'give' ), |
|
438 | - ) ); |
|
433 | + return (array) apply_filters('give_import_donation_form_options', array( |
|
434 | + 'form_title' => __('Donation Form Title', 'give'), |
|
435 | + 'form_id' => __('Donation Form ID', 'give'), |
|
436 | + 'form_level' => __('Donation Level', 'give'), |
|
437 | + 'form_custom_amount_text' => __('Custom Amount Text', 'give'), |
|
438 | + )); |
|
439 | 439 | } |
440 | 440 | |
441 | 441 | /** |
@@ -448,7 +448,7 @@ discard block |
||
448 | 448 | * |
449 | 449 | * @return array |
450 | 450 | */ |
451 | -function give_get_donation_data_from_csv( $file_id, $start, $end, $delimiter = 'csv' ) { |
|
451 | +function give_get_donation_data_from_csv($file_id, $start, $end, $delimiter = 'csv') { |
|
452 | 452 | /** |
453 | 453 | * Filter to modify delimiter of Import. |
454 | 454 | * |
@@ -457,19 +457,19 @@ discard block |
||
457 | 457 | * |
458 | 458 | * Return string $delimiter. |
459 | 459 | */ |
460 | - $delimiter = (string) apply_filters( 'give_import_delimiter_set', $delimiter ); |
|
460 | + $delimiter = (string) apply_filters('give_import_delimiter_set', $delimiter); |
|
461 | 461 | |
462 | 462 | $raw_data = array(); |
463 | - $file_dir = get_attached_file( $file_id ); |
|
463 | + $file_dir = get_attached_file($file_id); |
|
464 | 464 | $count = 0; |
465 | - if ( false !== ( $handle = fopen( $file_dir, 'r' ) ) ) { |
|
466 | - while ( false !== ( $row = fgetcsv( $handle, 0, $delimiter ) ) ) { |
|
467 | - if ( $count >= $start && $count <= $end ) { |
|
465 | + if (false !== ($handle = fopen($file_dir, 'r'))) { |
|
466 | + while (false !== ($row = fgetcsv($handle, 0, $delimiter))) { |
|
467 | + if ($count >= $start && $count <= $end) { |
|
468 | 468 | $raw_data[] = $row; |
469 | 469 | } |
470 | - $count ++; |
|
470 | + $count++; |
|
471 | 471 | } |
472 | - fclose( $handle ); |
|
472 | + fclose($handle); |
|
473 | 473 | } |
474 | 474 | |
475 | 475 | return $raw_data; |
@@ -485,7 +485,7 @@ discard block |
||
485 | 485 | * |
486 | 486 | * @return bool |
487 | 487 | */ |
488 | -function give_log_user_in_on_register_callback( $value ) { |
|
488 | +function give_log_user_in_on_register_callback($value) { |
|
489 | 489 | return false; |
490 | 490 | } |
491 | 491 | |
@@ -501,22 +501,22 @@ discard block |
||
501 | 501 | * |
502 | 502 | * @return bool |
503 | 503 | */ |
504 | -function give_save_import_donation_to_db( $raw_key, $row_data, $main_key = array(), $import_setting = array() ) { |
|
505 | - $data = array_combine( $raw_key, $row_data ); |
|
504 | +function give_save_import_donation_to_db($raw_key, $row_data, $main_key = array(), $import_setting = array()) { |
|
505 | + $data = array_combine($raw_key, $row_data); |
|
506 | 506 | $price_id = false; |
507 | 507 | $customer_id = 0; |
508 | - $import_setting['create_user'] = ( isset( $import_setting['create_user'] ) ? $import_setting['create_user'] : 1 ); |
|
508 | + $import_setting['create_user'] = (isset($import_setting['create_user']) ? $import_setting['create_user'] : 1); |
|
509 | 509 | |
510 | - $data = (array) apply_filters( 'give_save_import_donation_to_db', $data ); |
|
510 | + $data = (array) apply_filters('give_save_import_donation_to_db', $data); |
|
511 | 511 | |
512 | - $data['amount'] = give_maybe_sanitize_amount( $data['amount'] ); |
|
512 | + $data['amount'] = give_maybe_sanitize_amount($data['amount']); |
|
513 | 513 | |
514 | 514 | // Here come the login function. |
515 | - $donor_data = give_import_get_user_from_csv( $data, $import_setting ); |
|
516 | - if ( ! empty( $donor_data->id ) ) { |
|
517 | - if ( ! empty( $donor_data->user_id ) ) { |
|
515 | + $donor_data = give_import_get_user_from_csv($data, $import_setting); |
|
516 | + if ( ! empty($donor_data->id)) { |
|
517 | + if ( ! empty($donor_data->user_id)) { |
|
518 | 518 | $customer_id = $donor_data->user_id; |
519 | - } elseif ( ! empty( $data['user_id'] ) ) { |
|
519 | + } elseif ( ! empty($data['user_id'])) { |
|
520 | 520 | $customer_id = $data['user_id']; |
521 | 521 | } |
522 | 522 | } else { |
@@ -524,95 +524,95 @@ discard block |
||
524 | 524 | } |
525 | 525 | |
526 | 526 | // get form data or register a form data. |
527 | - $form = give_import_get_form_data_from_csv( $data, $import_setting ); |
|
528 | - if ( false == $form ) { |
|
527 | + $form = give_import_get_form_data_from_csv($data, $import_setting); |
|
528 | + if (false == $form) { |
|
529 | 529 | return false; |
530 | 530 | } else { |
531 | - $price_id = ( ! empty( $form->price_id ) ) ? $form->price_id : false; |
|
531 | + $price_id = ( ! empty($form->price_id)) ? $form->price_id : false; |
|
532 | 532 | } |
533 | 533 | |
534 | 534 | |
535 | 535 | $address = array( |
536 | - 'line1' => ( ! empty( $data['line1'] ) ? give_clean( $data['line1'] ) : '' ), |
|
537 | - 'line2' => ( ! empty( $data['line1'] ) ? give_clean( $data['line2'] ) : '' ), |
|
538 | - 'city' => ( ! empty( $data['line1'] ) ? give_clean( $data['city'] ) : '' ), |
|
539 | - 'zip' => ( ! empty( $data['zip'] ) ? give_clean( $data['zip'] ) : '' ), |
|
540 | - 'state' => ( ! empty( $data['state'] ) ? give_clean( $data['state'] ) : '' ), |
|
541 | - 'country' => ( ! empty( $data['country'] ) ? ( ( $country_code = array_search( $data['country'], give_get_country_list() ) ) ? $country_code : $data['country'] ) : '' ), |
|
536 | + 'line1' => ( ! empty($data['line1']) ? give_clean($data['line1']) : ''), |
|
537 | + 'line2' => ( ! empty($data['line1']) ? give_clean($data['line2']) : ''), |
|
538 | + 'city' => ( ! empty($data['line1']) ? give_clean($data['city']) : ''), |
|
539 | + 'zip' => ( ! empty($data['zip']) ? give_clean($data['zip']) : ''), |
|
540 | + 'state' => ( ! empty($data['state']) ? give_clean($data['state']) : ''), |
|
541 | + 'country' => ( ! empty($data['country']) ? (($country_code = array_search($data['country'], give_get_country_list())) ? $country_code : $data['country']) : ''), |
|
542 | 542 | ); |
543 | 543 | |
544 | 544 | //Create payment_data array |
545 | 545 | $payment_data = array( |
546 | 546 | 'donor_id' => $donor_data->id, |
547 | 547 | 'price' => $data['amount'], |
548 | - 'status' => ( ! empty( $data['post_status'] ) ? $data['post_status'] : 'publish' ), |
|
548 | + 'status' => ( ! empty($data['post_status']) ? $data['post_status'] : 'publish'), |
|
549 | 549 | 'currency' => give_get_currency(), |
550 | 550 | 'user_info' => array( |
551 | 551 | 'id' => $customer_id, |
552 | - 'email' => ( ! empty( $data['email'] ) ? $data['email'] : ( isset( $donor_data->email ) ? $donor_data->email : false ) ), |
|
553 | - 'first_name' => ( ! empty( $data['first_name'] ) ? $data['first_name'] : ( ! empty( $customer_id ) && ( $first_name = get_user_meta( $customer_id, 'first_name', true ) ) ? $first_name : $donor_data->name ) ), |
|
554 | - 'last_name' => ( ! empty( $data['last_name'] ) ? $data['last_name'] : ( ! empty( $customer_id ) && ( $last_name = get_user_meta( $customer_id, 'last_name', true ) ) ? $last_name : $donor_data->name ) ), |
|
552 | + 'email' => ( ! empty($data['email']) ? $data['email'] : (isset($donor_data->email) ? $donor_data->email : false)), |
|
553 | + 'first_name' => ( ! empty($data['first_name']) ? $data['first_name'] : ( ! empty($customer_id) && ($first_name = get_user_meta($customer_id, 'first_name', true)) ? $first_name : $donor_data->name)), |
|
554 | + 'last_name' => ( ! empty($data['last_name']) ? $data['last_name'] : ( ! empty($customer_id) && ($last_name = get_user_meta($customer_id, 'last_name', true)) ? $last_name : $donor_data->name)), |
|
555 | 555 | 'address' => $address, |
556 | 556 | ), |
557 | - 'gateway' => ( ! empty( $data['gateway'] ) && 'offline' != strtolower( $data['gateway'] ) ? strtolower( $data['gateway'] ) : 'manual' ), |
|
558 | - 'give_form_title' => ( ! empty( $data['form_title'] ) ? $data['form_title'] : $form->get_name() ), |
|
557 | + 'gateway' => ( ! empty($data['gateway']) && 'offline' != strtolower($data['gateway']) ? strtolower($data['gateway']) : 'manual'), |
|
558 | + 'give_form_title' => ( ! empty($data['form_title']) ? $data['form_title'] : $form->get_name()), |
|
559 | 559 | 'give_form_id' => (string) $form->get_ID(), |
560 | 560 | 'give_price_id' => $price_id, |
561 | - 'purchase_key' => strtolower( md5( uniqid() ) ), |
|
561 | + 'purchase_key' => strtolower(md5(uniqid())), |
|
562 | 562 | 'user_email' => $data['email'], |
563 | - 'post_date' => ( ! empty( $data['post_date'] ) ? mysql2date( 'Y-m-d H:i:s', $data['post_date'] ) : current_time( 'mysql' ) ), |
|
564 | - 'mode' => ( ! empty( $data['mode'] ) ? ( 'true' == (string) $data['mode'] || 'TRUE' == (string) $data['mode'] ? 'test' : 'live' ) : ( isset( $import_setting['mode'] ) ? ( true == (bool) $import_setting['mode'] ? 'test' : 'live' ) : ( give_is_test_mode() ? 'test' : 'live' ) ) ), |
|
563 | + 'post_date' => ( ! empty($data['post_date']) ? mysql2date('Y-m-d H:i:s', $data['post_date']) : current_time('mysql')), |
|
564 | + 'mode' => ( ! empty($data['mode']) ? ('true' == (string) $data['mode'] || 'TRUE' == (string) $data['mode'] ? 'test' : 'live') : (isset($import_setting['mode']) ? (true == (bool) $import_setting['mode'] ? 'test' : 'live') : (give_is_test_mode() ? 'test' : 'live'))), |
|
565 | 565 | ); |
566 | 566 | |
567 | - $payment_data = apply_filters( 'give_import_before_import_payment', $payment_data, $data, $donor_data, $form ); |
|
567 | + $payment_data = apply_filters('give_import_before_import_payment', $payment_data, $data, $donor_data, $form); |
|
568 | 568 | |
569 | 569 | // Get the report |
570 | 570 | $report = give_import_donation_report(); |
571 | 571 | |
572 | 572 | // Check for duplicate code. |
573 | - if ( true === give_check_import_donation_duplicate( $payment_data, $data, $form, $donor_data ) ) { |
|
574 | - $report['duplicate_donation'] = ( ! empty( $report['duplicate_donation'] ) ? ( absint( $report['duplicate_donation'] ) + 1 ) : 1 ); |
|
573 | + if (true === give_check_import_donation_duplicate($payment_data, $data, $form, $donor_data)) { |
|
574 | + $report['duplicate_donation'] = ( ! empty($report['duplicate_donation']) ? (absint($report['duplicate_donation']) + 1) : 1); |
|
575 | 575 | } else { |
576 | - add_action( 'give_update_payment_status', 'give_donation_import_insert_default_payment_note', 1, 1 ); |
|
577 | - add_filter( 'give_insert_payment_args', 'give_donation_import_give_insert_payment_args', 11, 2 ); |
|
578 | - add_filter( 'give_update_donor_information', 'give_donation_import_update_donor_information', 11, 3 ); |
|
579 | - add_action( 'give_insert_payment', 'give_import_donation_insert_payment', 11, 2 ); |
|
580 | - $payment = give_insert_payment( $payment_data ); |
|
581 | - remove_action( 'give_update_payment_status', 'give_donation_import_insert_default_payment_note', 1 ); |
|
582 | - remove_filter( 'give_insert_payment_args', 'give_donation_import_give_insert_payment_args', 11 ); |
|
583 | - remove_filter( 'give_update_donor_information', 'give_donation_import_update_donor_information', 11 ); |
|
584 | - remove_action( 'give_insert_payment', 'give_import_donation_insert_payment', 11 ); |
|
576 | + add_action('give_update_payment_status', 'give_donation_import_insert_default_payment_note', 1, 1); |
|
577 | + add_filter('give_insert_payment_args', 'give_donation_import_give_insert_payment_args', 11, 2); |
|
578 | + add_filter('give_update_donor_information', 'give_donation_import_update_donor_information', 11, 3); |
|
579 | + add_action('give_insert_payment', 'give_import_donation_insert_payment', 11, 2); |
|
580 | + $payment = give_insert_payment($payment_data); |
|
581 | + remove_action('give_update_payment_status', 'give_donation_import_insert_default_payment_note', 1); |
|
582 | + remove_filter('give_insert_payment_args', 'give_donation_import_give_insert_payment_args', 11); |
|
583 | + remove_filter('give_update_donor_information', 'give_donation_import_update_donor_information', 11); |
|
584 | + remove_action('give_insert_payment', 'give_import_donation_insert_payment', 11); |
|
585 | 585 | |
586 | - if ( $payment ) { |
|
586 | + if ($payment) { |
|
587 | 587 | |
588 | - $report['create_donation'] = ( ! empty( $report['create_donation'] ) ? ( absint( $report['create_donation'] ) + 1 ) : 1 ); |
|
588 | + $report['create_donation'] = ( ! empty($report['create_donation']) ? (absint($report['create_donation']) + 1) : 1); |
|
589 | 589 | |
590 | - update_post_meta( $payment, '_give_payment_import', true ); |
|
590 | + update_post_meta($payment, '_give_payment_import', true); |
|
591 | 591 | |
592 | - if ( ! empty( $import_setting['csv'] ) ) { |
|
593 | - update_post_meta( $payment, '_give_payment_import_id', $import_setting['csv'] ); |
|
592 | + if ( ! empty($import_setting['csv'])) { |
|
593 | + update_post_meta($payment, '_give_payment_import_id', $import_setting['csv']); |
|
594 | 594 | } |
595 | 595 | |
596 | 596 | // Insert Notes. |
597 | - if ( ! empty( $data['notes'] ) ) { |
|
598 | - give_insert_payment_note( $payment, $data['notes'] ); |
|
597 | + if ( ! empty($data['notes'])) { |
|
598 | + give_insert_payment_note($payment, $data['notes']); |
|
599 | 599 | } |
600 | 600 | |
601 | - $meta_exists = array_keys( $raw_key, 'post_meta' ); |
|
602 | - if ( ! empty( $main_key ) && ! empty( $meta_exists ) ) { |
|
603 | - foreach ( $meta_exists as $meta_exist ) { |
|
604 | - if ( ! empty( $main_key[ $meta_exist ] ) && ! empty( $row_data[ $meta_exist ] ) ) { |
|
605 | - update_post_meta( $payment, $main_key[ $meta_exist ], $row_data[ $meta_exist ] ); |
|
601 | + $meta_exists = array_keys($raw_key, 'post_meta'); |
|
602 | + if ( ! empty($main_key) && ! empty($meta_exists)) { |
|
603 | + foreach ($meta_exists as $meta_exist) { |
|
604 | + if ( ! empty($main_key[$meta_exist]) && ! empty($row_data[$meta_exist])) { |
|
605 | + update_post_meta($payment, $main_key[$meta_exist], $row_data[$meta_exist]); |
|
606 | 606 | } |
607 | 607 | } |
608 | 608 | } |
609 | 609 | } else { |
610 | - $report['failed_donation'] = ( ! empty( $report['failed_donation'] ) ? ( absint( $report['failed_donation'] ) + 1 ) : 1 ); |
|
610 | + $report['failed_donation'] = ( ! empty($report['failed_donation']) ? (absint($report['failed_donation']) + 1) : 1); |
|
611 | 611 | } |
612 | 612 | } |
613 | 613 | |
614 | 614 | // update the report |
615 | - give_import_donation_report_update( $report ); |
|
615 | + give_import_donation_report_update($report); |
|
616 | 616 | |
617 | 617 | return true; |
618 | 618 | } |
@@ -628,12 +628,12 @@ discard block |
||
628 | 628 | * |
629 | 629 | * @return Give_Donor |
630 | 630 | */ |
631 | -function give_donation_import_update_donor_information( $donor, $payment_id, $payment_data ) { |
|
631 | +function give_donation_import_update_donor_information($donor, $payment_id, $payment_data) { |
|
632 | 632 | $old_donor = $donor; |
633 | - if ( ! empty( $payment_data['donor_id'] ) ) { |
|
634 | - $donor_id = absint( $payment_data['donor_id'] ); |
|
635 | - $donor = new Give_Donor( $donor_id ); |
|
636 | - if ( ! empty( $donor->id ) ) { |
|
633 | + if ( ! empty($payment_data['donor_id'])) { |
|
634 | + $donor_id = absint($payment_data['donor_id']); |
|
635 | + $donor = new Give_Donor($donor_id); |
|
636 | + if ( ! empty($donor->id)) { |
|
637 | 637 | return $donor; |
638 | 638 | } |
639 | 639 | } |
@@ -646,12 +646,12 @@ discard block |
||
646 | 646 | * |
647 | 647 | * @since 1.8.13 |
648 | 648 | */ |
649 | -function give_import_donation_insert_payment( $payment_id, $payment_data ) { |
|
649 | +function give_import_donation_insert_payment($payment_id, $payment_data) { |
|
650 | 650 | // Update Give Customers purchase_count |
651 | - if ( ! empty( $payment_data['status'] ) && ( 'complete' === (string) $payment_data['status'] || 'publish' === (string) $payment_data['status'] ) ) { |
|
652 | - $donor_id = (int) get_post_meta( $payment_id, '_give_payment_customer_id', true ); |
|
653 | - if ( ! empty( $donor_id ) ) { |
|
654 | - $donor = new Give_Donor( $donor_id ); |
|
651 | + if ( ! empty($payment_data['status']) && ('complete' === (string) $payment_data['status'] || 'publish' === (string) $payment_data['status'])) { |
|
652 | + $donor_id = (int) get_post_meta($payment_id, '_give_payment_customer_id', true); |
|
653 | + if ( ! empty($donor_id)) { |
|
654 | + $donor = new Give_Donor($donor_id); |
|
655 | 655 | $donor->increase_purchase_count(); |
656 | 656 | } |
657 | 657 | } |
@@ -662,8 +662,8 @@ discard block |
||
662 | 662 | * |
663 | 663 | * @since 1.8.13 |
664 | 664 | */ |
665 | -function give_donation_import_give_insert_payment_args( $args, $payment_data ) { |
|
666 | - if ( ! empty( $payment_data['user_info']['id'] ) ) { |
|
665 | +function give_donation_import_give_insert_payment_args($args, $payment_data) { |
|
666 | + if ( ! empty($payment_data['user_info']['id'])) { |
|
667 | 667 | $args['post_author'] = (int) $payment_data['user_info']['id']; |
668 | 668 | } |
669 | 669 | |
@@ -675,11 +675,11 @@ discard block |
||
675 | 675 | * |
676 | 676 | * @since 1.8.13 |
677 | 677 | */ |
678 | -function give_check_import_donation_duplicate( $payment_data, $data, $form, $donor_data ) { |
|
678 | +function give_check_import_donation_duplicate($payment_data, $data, $form, $donor_data) { |
|
679 | 679 | $return = false; |
680 | - if ( ! empty( $data['post_date'] ) ) { |
|
681 | - $post_date = mysql2date( 'Y-m-d-H-i-s', $data['post_date'] ); |
|
682 | - $post_date = explode( '-', $post_date ); |
|
680 | + if ( ! empty($data['post_date'])) { |
|
681 | + $post_date = mysql2date('Y-m-d-H-i-s', $data['post_date']); |
|
682 | + $post_date = explode('-', $post_date); |
|
683 | 683 | $args = array( |
684 | 684 | 'post_type' => 'give_payment', |
685 | 685 | 'cache_results' => false, |
@@ -700,7 +700,7 @@ discard block |
||
700 | 700 | 'meta_query' => array( |
701 | 701 | array( |
702 | 702 | 'key' => '_give_payment_total', |
703 | - 'value' => preg_replace( '/[\$,]/', '', $payment_data['price'] ), |
|
703 | + 'value' => preg_replace('/[\$,]/', '', $payment_data['price']), |
|
704 | 704 | 'compare' => 'LIKE', |
705 | 705 | ), |
706 | 706 | array( |
@@ -717,9 +717,9 @@ discard block |
||
717 | 717 | ), |
718 | 718 | ); |
719 | 719 | |
720 | - $payments = new Give_Payments_Query( $args ); |
|
720 | + $payments = new Give_Payments_Query($args); |
|
721 | 721 | $donations = $payments->get_payments(); |
722 | - if ( ! empty( $donations ) ) { |
|
722 | + if ( ! empty($donations)) { |
|
723 | 723 | return true; |
724 | 724 | } |
725 | 725 | } |
@@ -736,9 +736,9 @@ discard block |
||
736 | 736 | * |
737 | 737 | * @return void |
738 | 738 | */ |
739 | -function give_donation_import_insert_default_payment_note( $payment_id ) { |
|
739 | +function give_donation_import_insert_default_payment_note($payment_id) { |
|
740 | 740 | $current_user = wp_get_current_user(); |
741 | - give_insert_payment_note( $payment_id, esc_html( wp_sprintf( __( 'This donation was imported by %s', 'give' ), $current_user->user_email ) ) ); |
|
741 | + give_insert_payment_note($payment_id, esc_html(wp_sprintf(__('This donation was imported by %s', 'give'), $current_user->user_email))); |
|
742 | 742 | } |
743 | 743 | |
744 | 744 | /** |
@@ -750,14 +750,14 @@ discard block |
||
750 | 750 | * |
751 | 751 | * @return string URL |
752 | 752 | */ |
753 | -function give_import_page_url( $parameter = array() ) { |
|
753 | +function give_import_page_url($parameter = array()) { |
|
754 | 754 | $defalut_query_arg = array( |
755 | 755 | 'post_type' => 'give_forms', |
756 | 756 | 'page' => 'give-tools', |
757 | 757 | 'tab' => 'import', |
758 | 758 | 'importer-type' => 'import_donations', |
759 | 759 | ); |
760 | - $import_query_arg = wp_parse_args( $parameter, $defalut_query_arg ); |
|
760 | + $import_query_arg = wp_parse_args($parameter, $defalut_query_arg); |
|
761 | 761 | |
762 | - return add_query_arg( $import_query_arg, admin_url( 'edit.php' ) ); |
|
762 | + return add_query_arg($import_query_arg, admin_url('edit.php')); |
|
763 | 763 | } |
764 | 764 | \ No newline at end of file |
@@ -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 | /** |
@@ -134,15 +134,15 @@ discard block |
||
134 | 134 | public function __construct() { |
135 | 135 | |
136 | 136 | // Set parent defaults. |
137 | - parent::__construct( array( |
|
138 | - 'singular' => give_get_forms_label_singular(), // Singular name of the listed records. |
|
139 | - 'plural' => give_get_forms_label_plural(), // Plural name of the listed records. |
|
140 | - 'ajax' => false, // Does this table support ajax? |
|
141 | - ) ); |
|
137 | + parent::__construct(array( |
|
138 | + 'singular' => give_get_forms_label_singular(), // Singular name of the listed records. |
|
139 | + 'plural' => give_get_forms_label_plural(), // Plural name of the listed records. |
|
140 | + 'ajax' => false, // Does this table support ajax? |
|
141 | + )); |
|
142 | 142 | |
143 | 143 | $this->process_bulk_action(); |
144 | 144 | $this->get_payment_counts(); |
145 | - $this->base_url = admin_url( 'edit.php?post_type=give_forms&page=give-payment-history' ); |
|
145 | + $this->base_url = admin_url('edit.php?post_type=give_forms&page=give-payment-history'); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
@@ -151,55 +151,55 @@ discard block |
||
151 | 151 | * @return void |
152 | 152 | */ |
153 | 153 | public function advanced_filters() { |
154 | - $start_date = isset( $_GET['start-date'] ) ? sanitize_text_field( $_GET['start-date'] ) : null; |
|
155 | - $end_date = isset( $_GET['end-date'] ) ? sanitize_text_field( $_GET['end-date'] ) : null; |
|
156 | - $status = isset( $_GET['status'] ) ? sanitize_text_field( $_GET['status'] ) : ''; |
|
157 | - $donor = isset( $_GET['donor'] ) ? sanitize_text_field( $_GET['donor'] ) : ''; |
|
158 | - $search = isset( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : ''; |
|
159 | - $form_id = ! empty( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : 0; |
|
154 | + $start_date = isset($_GET['start-date']) ? sanitize_text_field($_GET['start-date']) : null; |
|
155 | + $end_date = isset($_GET['end-date']) ? sanitize_text_field($_GET['end-date']) : null; |
|
156 | + $status = isset($_GET['status']) ? sanitize_text_field($_GET['status']) : ''; |
|
157 | + $donor = isset($_GET['donor']) ? sanitize_text_field($_GET['donor']) : ''; |
|
158 | + $search = isset($_GET['s']) ? sanitize_text_field($_GET['s']) : ''; |
|
159 | + $form_id = ! empty($_GET['form_id']) ? absint($_GET['form_id']) : 0; |
|
160 | 160 | ?> |
161 | 161 | <div id="give-payment-filters" class="give-filters"> |
162 | - <?php $this->search_box( esc_html__( 'Search', 'give' ), 'give-payments' ); ?> |
|
162 | + <?php $this->search_box(esc_html__('Search', 'give'), 'give-payments'); ?> |
|
163 | 163 | <div id="give-payment-date-filters"> |
164 | 164 | <div class="give-filter give-filter-half"> |
165 | 165 | <label for="start-date" |
166 | - class="give-start-date-label"><?php esc_html_e( 'Start Date', 'give' ); ?></label> |
|
166 | + class="give-start-date-label"><?php esc_html_e('Start Date', 'give'); ?></label> |
|
167 | 167 | <input type="text" id="start-date" name="start-date" class="give_datepicker" |
168 | 168 | value="<?php echo $start_date; ?>" placeholder="mm/dd/yyyy" /> |
169 | 169 | </div> |
170 | 170 | <div class="give-filter give-filter-half"> |
171 | - <label for="end-date" class="give-end-date-label"><?php esc_html_e( 'End Date', 'give' ); ?></label> |
|
171 | + <label for="end-date" class="give-end-date-label"><?php esc_html_e('End Date', 'give'); ?></label> |
|
172 | 172 | <input type="text" id="end-date" name="end-date" class="give_datepicker" |
173 | 173 | value="<?php echo $end_date; ?>" placeholder="mm/dd/yyyy" /> |
174 | 174 | </div> |
175 | 175 | </div> |
176 | 176 | <div id="give-payment-form-filter" class="give-filter"> |
177 | 177 | <label for="give-donation-forms-filter" |
178 | - class="give-donation-forms-filter-label"><?php esc_html_e( 'Form', 'give' ); ?></label> |
|
178 | + class="give-donation-forms-filter-label"><?php esc_html_e('Form', 'give'); ?></label> |
|
179 | 179 | <?php |
180 | 180 | // Filter Donations by Donation Forms. |
181 | - echo Give()->html->forms_dropdown( array( |
|
181 | + echo Give()->html->forms_dropdown(array( |
|
182 | 182 | 'name' => 'form_id', |
183 | 183 | 'id' => 'give-donation-forms-filter', |
184 | 184 | 'class' => 'give-donation-forms-filter', |
185 | 185 | 'selected' => $form_id, // Make sure to have $form_id set to 0, if there is no selection. |
186 | 186 | 'chosen' => true, |
187 | - 'number' => - 1, |
|
188 | - ) ); |
|
187 | + 'number' => -1, |
|
188 | + )); |
|
189 | 189 | ?> |
190 | 190 | </div> |
191 | 191 | |
192 | - <?php if ( ! empty( $status ) ) : ?> |
|
193 | - <input type="hidden" name="status" value="<?php echo esc_attr( $status ); ?>" /> |
|
192 | + <?php if ( ! empty($status)) : ?> |
|
193 | + <input type="hidden" name="status" value="<?php echo esc_attr($status); ?>" /> |
|
194 | 194 | <?php endif; ?> |
195 | 195 | |
196 | 196 | <div class="give-filter"> |
197 | - <?php submit_button( __( 'Apply', 'give' ), 'secondary', '', false ); ?> |
|
197 | + <?php submit_button(__('Apply', 'give'), 'secondary', '', false); ?> |
|
198 | 198 | <?php |
199 | 199 | // Clear active filters button. |
200 | - if ( ! empty( $start_date ) || ! empty( $end_date ) || ! empty( $donor ) || ! empty( $search ) || ! empty( $status ) || ! empty( $form_id ) ) : ?> |
|
201 | - <a href="<?php echo admin_url( 'edit.php?post_type=give_forms&page=give-payment-history' ); ?>" |
|
202 | - class="button give-clear-filters-button"><?php esc_html_e( 'Clear Filters', 'give' ); ?></a> |
|
200 | + if ( ! empty($start_date) || ! empty($end_date) || ! empty($donor) || ! empty($search) || ! empty($status) || ! empty($form_id)) : ?> |
|
201 | + <a href="<?php echo admin_url('edit.php?post_type=give_forms&page=give-payment-history'); ?>" |
|
202 | + class="button give-clear-filters-button"><?php esc_html_e('Clear Filters', 'give'); ?></a> |
|
203 | 203 | <?php endif; ?> |
204 | 204 | </div> |
205 | 205 | </div> |
@@ -218,18 +218,18 @@ discard block |
||
218 | 218 | * |
219 | 219 | * @return void |
220 | 220 | */ |
221 | - public function search_box( $text, $input_id ) { |
|
222 | - if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) { |
|
221 | + public function search_box($text, $input_id) { |
|
222 | + if (empty($_REQUEST['s']) && ! $this->has_items()) { |
|
223 | 223 | return; |
224 | 224 | } |
225 | 225 | |
226 | - $input_id = $input_id . '-search-input'; |
|
226 | + $input_id = $input_id.'-search-input'; |
|
227 | 227 | |
228 | - if ( ! empty( $_REQUEST['orderby'] ) ) { |
|
229 | - echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />'; |
|
228 | + if ( ! empty($_REQUEST['orderby'])) { |
|
229 | + echo '<input type="hidden" name="orderby" value="'.esc_attr($_REQUEST['orderby']).'" />'; |
|
230 | 230 | } |
231 | - if ( ! empty( $_REQUEST['order'] ) ) { |
|
232 | - echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />'; |
|
231 | + if ( ! empty($_REQUEST['order'])) { |
|
232 | + echo '<input type="hidden" name="order" value="'.esc_attr($_REQUEST['order']).'" />'; |
|
233 | 233 | } |
234 | 234 | ?> |
235 | 235 | <div class="give-filter give-filter-search" role="search"> |
@@ -241,13 +241,13 @@ discard block |
||
241 | 241 | * |
242 | 242 | * @since 1.7 |
243 | 243 | */ |
244 | - do_action( 'give_payment_history_search' ); |
|
244 | + do_action('give_payment_history_search'); |
|
245 | 245 | ?> |
246 | 246 | <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label> |
247 | 247 | <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" /> |
248 | - <?php submit_button( $text, 'button', false, false, array( |
|
248 | + <?php submit_button($text, 'button', false, false, array( |
|
249 | 249 | 'ID' => 'search-submit', |
250 | - ) ); ?><br /> |
|
250 | + )); ?><br /> |
|
251 | 251 | </div> |
252 | 252 | <?php |
253 | 253 | } |
@@ -261,52 +261,52 @@ discard block |
||
261 | 261 | */ |
262 | 262 | public function get_views() { |
263 | 263 | |
264 | - $current = isset( $_GET['status'] ) ? $_GET['status'] : ''; |
|
264 | + $current = isset($_GET['status']) ? $_GET['status'] : ''; |
|
265 | 265 | $views = array(); |
266 | 266 | $tabs = array( |
267 | 267 | 'all' => array( |
268 | 268 | 'total_count', |
269 | - esc_html__( 'All', 'give' ), |
|
269 | + esc_html__('All', 'give'), |
|
270 | 270 | ), |
271 | 271 | 'publish' => array( |
272 | 272 | 'complete_count', |
273 | - esc_html__( 'Completed', 'give' ), |
|
273 | + esc_html__('Completed', 'give'), |
|
274 | 274 | ), |
275 | 275 | 'pending' => array( |
276 | 276 | 'pending_count', |
277 | - esc_html__( 'Pending', 'give' ), |
|
277 | + esc_html__('Pending', 'give'), |
|
278 | 278 | ), |
279 | 279 | 'processing' => array( |
280 | 280 | 'processing_count', |
281 | - esc_html__( 'Processing', 'give' ), |
|
281 | + esc_html__('Processing', 'give'), |
|
282 | 282 | ), |
283 | 283 | 'refunded' => array( |
284 | 284 | 'refunded_count', |
285 | - esc_html__( 'Refunded', 'give' ), |
|
285 | + esc_html__('Refunded', 'give'), |
|
286 | 286 | ), |
287 | 287 | 'revoked' => array( |
288 | 288 | 'revoked_count', |
289 | - esc_html__( 'Revoked', 'give' ), |
|
289 | + esc_html__('Revoked', 'give'), |
|
290 | 290 | ), |
291 | 291 | 'failed' => array( |
292 | 292 | 'failed_count', |
293 | - esc_html__( 'Failed', 'give' ), |
|
293 | + esc_html__('Failed', 'give'), |
|
294 | 294 | ), |
295 | 295 | 'cancelled' => array( |
296 | 296 | 'cancelled_count', |
297 | - esc_html__( 'Cancelled', 'give' ), |
|
297 | + esc_html__('Cancelled', 'give'), |
|
298 | 298 | ), |
299 | 299 | 'abandoned' => array( |
300 | 300 | 'abandoned_count', |
301 | - esc_html__( 'Abandoned', 'give' ), |
|
301 | + esc_html__('Abandoned', 'give'), |
|
302 | 302 | ), |
303 | 303 | 'preapproval' => array( |
304 | 304 | 'preapproval_count', |
305 | - esc_html__( 'Preapproval Pending', 'give' ), |
|
305 | + esc_html__('Preapproval Pending', 'give'), |
|
306 | 306 | ), |
307 | 307 | ); |
308 | 308 | |
309 | - foreach ( $tabs as $key => $tab ) { |
|
309 | + foreach ($tabs as $key => $tab) { |
|
310 | 310 | $count_key = $tab[0]; |
311 | 311 | $name = $tab[1]; |
312 | 312 | $count = $this->$count_key; |
@@ -321,19 +321,19 @@ discard block |
||
321 | 321 | * @param string $key Current view tab value. |
322 | 322 | * @param int $count Number of donation inside the tab. |
323 | 323 | */ |
324 | - if ( 'all' === $key || $key === $current || apply_filters( 'give_payments_table_show_all_status', 0 < $count, $key, $count ) ) { |
|
324 | + if ('all' === $key || $key === $current || apply_filters('give_payments_table_show_all_status', 0 < $count, $key, $count)) { |
|
325 | 325 | |
326 | - $views[ $key ] = sprintf( |
|
326 | + $views[$key] = sprintf( |
|
327 | 327 | '<a href="%s" %s >%s <span class="count">(%s)</span></a>', |
328 | - esc_url( ( 'all' === (string) $key ) ? remove_query_arg( array( 'status', 'paged' ) ) : add_query_arg( array( 'status' => $key, 'paged' => false ), admin_url( 'edit.php?post_type=give_forms&page=give-payment-history' ) ) ), |
|
329 | - ( ( 'all' === $key && empty( $current ) ) ) ? 'class="current"' : ( $current == $key ) ? 'class="current"' : '', |
|
328 | + esc_url(('all' === (string) $key) ? remove_query_arg(array('status', 'paged')) : add_query_arg(array('status' => $key, 'paged' => false), admin_url('edit.php?post_type=give_forms&page=give-payment-history'))), |
|
329 | + (('all' === $key && empty($current))) ? 'class="current"' : ($current == $key) ? 'class="current"' : '', |
|
330 | 330 | $name, |
331 | 331 | $count |
332 | 332 | ); |
333 | 333 | } |
334 | 334 | } |
335 | 335 | |
336 | - return apply_filters( 'give_payments_table_views', $views ); |
|
336 | + return apply_filters('give_payments_table_views', $views); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | /** |
@@ -346,15 +346,15 @@ discard block |
||
346 | 346 | public function get_columns() { |
347 | 347 | $columns = array( |
348 | 348 | 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text. |
349 | - 'donation' => esc_html__( 'Donation', 'give' ), |
|
350 | - 'donation_form' => esc_html__( 'Donation Form', 'give' ), |
|
351 | - 'status' => esc_html__( 'Status', 'give' ), |
|
352 | - 'date' => esc_html__( 'Date', 'give' ), |
|
353 | - 'amount' => esc_html__( 'Amount', 'give' ), |
|
354 | - 'details' => esc_html__( 'Details', 'give' ), |
|
349 | + 'donation' => esc_html__('Donation', 'give'), |
|
350 | + 'donation_form' => esc_html__('Donation Form', 'give'), |
|
351 | + 'status' => esc_html__('Status', 'give'), |
|
352 | + 'date' => esc_html__('Date', 'give'), |
|
353 | + 'amount' => esc_html__('Amount', 'give'), |
|
354 | + 'details' => esc_html__('Details', 'give'), |
|
355 | 355 | ); |
356 | 356 | |
357 | - return apply_filters( 'give_payments_table_columns', $columns ); |
|
357 | + return apply_filters('give_payments_table_columns', $columns); |
|
358 | 358 | } |
359 | 359 | |
360 | 360 | /** |
@@ -366,14 +366,14 @@ discard block |
||
366 | 366 | */ |
367 | 367 | public function get_sortable_columns() { |
368 | 368 | $columns = array( |
369 | - 'donation' => array( 'ID', true ), |
|
370 | - 'donation_form' => array( 'donation_form', false ), |
|
371 | - 'status' => array( 'status', false ), |
|
372 | - 'amount' => array( 'amount', false ), |
|
373 | - 'date' => array( 'date', false ), |
|
369 | + 'donation' => array('ID', true), |
|
370 | + 'donation_form' => array('donation_form', false), |
|
371 | + 'status' => array('status', false), |
|
372 | + 'amount' => array('amount', false), |
|
373 | + 'date' => array('date', false), |
|
374 | 374 | ); |
375 | 375 | |
376 | - return apply_filters( 'give_payments_table_sortable_columns', $columns ); |
|
376 | + return apply_filters('give_payments_table_sortable_columns', $columns); |
|
377 | 377 | } |
378 | 378 | |
379 | 379 | /** |
@@ -399,55 +399,55 @@ discard block |
||
399 | 399 | * |
400 | 400 | * @return string Column Name |
401 | 401 | */ |
402 | - public function column_default( $payment, $column_name ) { |
|
402 | + public function column_default($payment, $column_name) { |
|
403 | 403 | |
404 | - $single_donation_url = esc_url( add_query_arg( 'id', $payment->ID, admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-payment-details' ) ) ); |
|
405 | - $row_actions = $this->get_row_actions( $payment ); |
|
404 | + $single_donation_url = esc_url(add_query_arg('id', $payment->ID, admin_url('edit.php?post_type=give_forms&page=give-payment-history&view=view-payment-details'))); |
|
405 | + $row_actions = $this->get_row_actions($payment); |
|
406 | 406 | |
407 | - switch ( $column_name ) { |
|
407 | + switch ($column_name) { |
|
408 | 408 | case 'donation' : |
409 | - $value = sprintf( '<a href="%1$s" data-tooltip="%2$s">#%3$s</a> %4$s %5$s<br>', $single_donation_url, sprintf( esc_attr__( 'View Donation #%s', 'give' ), $payment->ID ), $payment->ID, esc_html__( 'by', 'give' ), $this->get_donor( $payment ) ); |
|
410 | - $value .= $this->get_donor_email( $payment ); |
|
411 | - $value .= $this->row_actions( $row_actions ); |
|
409 | + $value = sprintf('<a href="%1$s" data-tooltip="%2$s">#%3$s</a> %4$s %5$s<br>', $single_donation_url, sprintf(esc_attr__('View Donation #%s', 'give'), $payment->ID), $payment->ID, esc_html__('by', 'give'), $this->get_donor($payment)); |
|
410 | + $value .= $this->get_donor_email($payment); |
|
411 | + $value .= $this->row_actions($row_actions); |
|
412 | 412 | break; |
413 | 413 | |
414 | 414 | case 'amount' : |
415 | - $amount = ! empty( $payment->total ) ? $payment->total : 0; |
|
416 | - $value = give_currency_filter( give_format_amount( $amount, array( 'sanitize' => false, 'donation_id' => $payment->ID ) ), give_get_payment_currency_code( $payment->ID ) ); |
|
417 | - $value .= sprintf( '<br><small>%1$s %2$s</small>', __( 'via', 'give' ), give_get_gateway_admin_label( $payment->gateway ) ); |
|
415 | + $amount = ! empty($payment->total) ? $payment->total : 0; |
|
416 | + $value = give_currency_filter(give_format_amount($amount, array('sanitize' => false, 'donation_id' => $payment->ID)), give_get_payment_currency_code($payment->ID)); |
|
417 | + $value .= sprintf('<br><small>%1$s %2$s</small>', __('via', 'give'), give_get_gateway_admin_label($payment->gateway)); |
|
418 | 418 | break; |
419 | 419 | |
420 | 420 | case 'donation_form' : |
421 | - $form_title = empty( $payment->form_title ) ? sprintf( __( 'Untitled (#%s)', 'give' ), $payment->form_id ) : $payment->form_title; |
|
422 | - $value = '<a href="' . admin_url( 'post.php?post=' . $payment->form_id . '&action=edit' ) . '">' . $form_title . '</a>'; |
|
423 | - $level = give_get_payment_form_title( $payment->meta, true ); |
|
421 | + $form_title = empty($payment->form_title) ? sprintf(__('Untitled (#%s)', 'give'), $payment->form_id) : $payment->form_title; |
|
422 | + $value = '<a href="'.admin_url('post.php?post='.$payment->form_id.'&action=edit').'">'.$form_title.'</a>'; |
|
423 | + $level = give_get_payment_form_title($payment->meta, true); |
|
424 | 424 | |
425 | - if ( ! empty( $level ) ) { |
|
425 | + if ( ! empty($level)) { |
|
426 | 426 | $value .= $level; |
427 | 427 | } |
428 | 428 | |
429 | 429 | break; |
430 | 430 | |
431 | 431 | case 'date' : |
432 | - $date = strtotime( $payment->date ); |
|
433 | - $value = date_i18n( give_date_format(), $date ); |
|
432 | + $date = strtotime($payment->date); |
|
433 | + $value = date_i18n(give_date_format(), $date); |
|
434 | 434 | break; |
435 | 435 | |
436 | 436 | case 'status' : |
437 | - $value = $this->get_payment_status( $payment ); |
|
437 | + $value = $this->get_payment_status($payment); |
|
438 | 438 | break; |
439 | 439 | |
440 | 440 | case 'details' : |
441 | - $value = sprintf( '<div class="give-payment-details-link-wrap"><a href="%1$s" class="give-payment-details-link button button-small" data-tooltip="%2$s" aria-label="%2$s"><span class="dashicons dashicons-visibility"></span></a></div>', $single_donation_url, sprintf( esc_attr__( 'View Donation #%s', 'give' ), $payment->ID ) ); |
|
441 | + $value = sprintf('<div class="give-payment-details-link-wrap"><a href="%1$s" class="give-payment-details-link button button-small" data-tooltip="%2$s" aria-label="%2$s"><span class="dashicons dashicons-visibility"></span></a></div>', $single_donation_url, sprintf(esc_attr__('View Donation #%s', 'give'), $payment->ID)); |
|
442 | 442 | break; |
443 | 443 | |
444 | 444 | default: |
445 | - $value = isset( $payment->$column_name ) ? $payment->$column_name : ''; |
|
445 | + $value = isset($payment->$column_name) ? $payment->$column_name : ''; |
|
446 | 446 | break; |
447 | 447 | |
448 | 448 | }// End switch(). |
449 | 449 | |
450 | - return apply_filters( 'give_payments_table_column', $value, $payment->ID, $column_name ); |
|
450 | + return apply_filters('give_payments_table_column', $value, $payment->ID, $column_name); |
|
451 | 451 | } |
452 | 452 | |
453 | 453 | /** |
@@ -460,17 +460,17 @@ discard block |
||
460 | 460 | * |
461 | 461 | * @return string Data shown in the Email column |
462 | 462 | */ |
463 | - public function get_donor_email( $payment ) { |
|
463 | + public function get_donor_email($payment) { |
|
464 | 464 | |
465 | - $email = give_get_payment_user_email( $payment->ID ); |
|
465 | + $email = give_get_payment_user_email($payment->ID); |
|
466 | 466 | |
467 | - if ( empty( $email ) ) { |
|
468 | - $email = esc_html__( '(unknown)', 'give' ); |
|
467 | + if (empty($email)) { |
|
468 | + $email = esc_html__('(unknown)', 'give'); |
|
469 | 469 | } |
470 | 470 | |
471 | - $value = '<a href="mailto:' . $email . '" data-tooltip="' . esc_attr__( 'Email donor', 'give' ) . '">' . $email . '</a>'; |
|
471 | + $value = '<a href="mailto:'.$email.'" data-tooltip="'.esc_attr__('Email donor', 'give').'">'.$email.'</a>'; |
|
472 | 472 | |
473 | - return apply_filters( 'give_payments_table_column', $value, $payment->ID, 'email' ); |
|
473 | + return apply_filters('give_payments_table_column', $value, $payment->ID, 'email'); |
|
474 | 474 | } |
475 | 475 | |
476 | 476 | /** |
@@ -482,32 +482,32 @@ discard block |
||
482 | 482 | * |
483 | 483 | * @return array $actions |
484 | 484 | */ |
485 | - function get_row_actions( $payment ) { |
|
485 | + function get_row_actions($payment) { |
|
486 | 486 | |
487 | 487 | $actions = array(); |
488 | - $email = give_get_payment_user_email( $payment->ID ); |
|
488 | + $email = give_get_payment_user_email($payment->ID); |
|
489 | 489 | |
490 | 490 | // Add search term string back to base URL. |
491 | - $search_terms = ( isset( $_GET['s'] ) ? trim( $_GET['s'] ) : '' ); |
|
492 | - if ( ! empty( $search_terms ) ) { |
|
493 | - $this->base_url = add_query_arg( 's', $search_terms, $this->base_url ); |
|
491 | + $search_terms = (isset($_GET['s']) ? trim($_GET['s']) : ''); |
|
492 | + if ( ! empty($search_terms)) { |
|
493 | + $this->base_url = add_query_arg('s', $search_terms, $this->base_url); |
|
494 | 494 | } |
495 | 495 | |
496 | - if ( give_is_payment_complete( $payment->ID ) && ! empty( $email ) ) { |
|
496 | + if (give_is_payment_complete($payment->ID) && ! empty($email)) { |
|
497 | 497 | |
498 | - $actions['email_links'] = sprintf( '<a class="resend-single-donation-receipt" href="%1$s" aria-label="%2$s">%3$s</a>', wp_nonce_url( add_query_arg( array( |
|
498 | + $actions['email_links'] = sprintf('<a class="resend-single-donation-receipt" href="%1$s" aria-label="%2$s">%3$s</a>', wp_nonce_url(add_query_arg(array( |
|
499 | 499 | 'give-action' => 'email_links', |
500 | 500 | 'purchase_id' => $payment->ID, |
501 | - ), $this->base_url ), 'give_payment_nonce' ), sprintf( esc_attr__( 'Resend Donation %s Receipt', 'give' ), $payment->ID ), esc_html__( 'Resend Receipt', 'give' ) ); |
|
501 | + ), $this->base_url), 'give_payment_nonce'), sprintf(esc_attr__('Resend Donation %s Receipt', 'give'), $payment->ID), esc_html__('Resend Receipt', 'give')); |
|
502 | 502 | |
503 | 503 | } |
504 | 504 | |
505 | - $actions['delete'] = sprintf( '<a class="delete-single-donation" href="%1$s" aria-label="%2$s">%3$s</a>', wp_nonce_url( add_query_arg( array( |
|
505 | + $actions['delete'] = sprintf('<a class="delete-single-donation" href="%1$s" aria-label="%2$s">%3$s</a>', wp_nonce_url(add_query_arg(array( |
|
506 | 506 | 'give-action' => 'delete_payment', |
507 | 507 | 'purchase_id' => $payment->ID, |
508 | - ), $this->base_url ), 'give_donation_nonce' ), sprintf( esc_attr__( 'Delete Donation %s', 'give' ), $payment->ID ), esc_html__( 'Delete', 'give' ) ); |
|
508 | + ), $this->base_url), 'give_donation_nonce'), sprintf(esc_attr__('Delete Donation %s', 'give'), $payment->ID), esc_html__('Delete', 'give')); |
|
509 | 509 | |
510 | - return apply_filters( 'give_payment_row_actions', $actions, $payment ); |
|
510 | + return apply_filters('give_payment_row_actions', $actions, $payment); |
|
511 | 511 | } |
512 | 512 | |
513 | 513 | |
@@ -521,14 +521,14 @@ discard block |
||
521 | 521 | * |
522 | 522 | * @return string Data shown in the Email column |
523 | 523 | */ |
524 | - function get_payment_status( $payment ) { |
|
525 | - $value = '<div class="give-donation-status status-' . sanitize_title( give_get_payment_status( $payment, true ) ) . '"><span class="give-donation-status-icon"></span> ' . give_get_payment_status( $payment, true ) . '</div>'; |
|
526 | - if ( $payment->mode == 'test' ) { |
|
527 | - $value .= ' <span class="give-item-label give-item-label-orange give-test-mode-transactions-label" data-tooltip="' . esc_attr__( 'This donation was made in test mode.', 'give' ) . '">' . esc_html__( 'Test', 'give' ) . '</span>'; |
|
524 | + function get_payment_status($payment) { |
|
525 | + $value = '<div class="give-donation-status status-'.sanitize_title(give_get_payment_status($payment, true)).'"><span class="give-donation-status-icon"></span> '.give_get_payment_status($payment, true).'</div>'; |
|
526 | + if ($payment->mode == 'test') { |
|
527 | + $value .= ' <span class="give-item-label give-item-label-orange give-test-mode-transactions-label" data-tooltip="'.esc_attr__('This donation was made in test mode.', 'give').'">'.esc_html__('Test', 'give').'</span>'; |
|
528 | 528 | } |
529 | 529 | |
530 | - if ( true === $payment->import && true === (bool) apply_filters( 'give_payment_show_importer_label', false ) ) { |
|
531 | - $value .= ' <span class="give-item-label give-item-label-orange give-test-mode-transactions-label" data-tooltip="' . esc_attr__( 'This donation was imported.', 'give' ) . '">' . esc_html__( 'Import', 'give' ) . '</span>'; |
|
530 | + if (true === $payment->import && true === (bool) apply_filters('give_payment_show_importer_label', false)) { |
|
531 | + $value .= ' <span class="give-item-label give-item-label-orange give-test-mode-transactions-label" data-tooltip="'.esc_attr__('This donation was imported.', 'give').'">'.esc_html__('Import', 'give').'</span>'; |
|
532 | 532 | } |
533 | 533 | |
534 | 534 | return $value; |
@@ -544,8 +544,8 @@ discard block |
||
544 | 544 | * |
545 | 545 | * @return string Displays a checkbox. |
546 | 546 | */ |
547 | - public function column_cb( $payment ) { |
|
548 | - return sprintf( '<input type="checkbox" name="%1$s[]" value="%2$s" />', 'payment', $payment->ID ); |
|
547 | + public function column_cb($payment) { |
|
548 | + return sprintf('<input type="checkbox" name="%1$s[]" value="%2$s" />', 'payment', $payment->ID); |
|
549 | 549 | } |
550 | 550 | |
551 | 551 | /** |
@@ -558,8 +558,8 @@ discard block |
||
558 | 558 | * |
559 | 559 | * @return string Displays a checkbox. |
560 | 560 | */ |
561 | - public function get_payment_id( $payment ) { |
|
562 | - return '<span class="give-payment-id">' . give_get_payment_number( $payment->ID ) . '</span>'; |
|
561 | + public function get_payment_id($payment) { |
|
562 | + return '<span class="give-payment-id">'.give_get_payment_number($payment->ID).'</span>'; |
|
563 | 563 | } |
564 | 564 | |
565 | 565 | /** |
@@ -572,32 +572,32 @@ discard block |
||
572 | 572 | * |
573 | 573 | * @return string Data shown in the User column |
574 | 574 | */ |
575 | - public function get_donor( $payment ) { |
|
575 | + public function get_donor($payment) { |
|
576 | 576 | |
577 | - $donor_id = give_get_payment_donor_id( $payment->ID ); |
|
578 | - $donor_billing_name = give_get_donor_name_by( $payment->ID, 'donation' ); |
|
579 | - $donor_name = give_get_donor_name_by( $donor_id, 'donor' ); |
|
577 | + $donor_id = give_get_payment_donor_id($payment->ID); |
|
578 | + $donor_billing_name = give_get_donor_name_by($payment->ID, 'donation'); |
|
579 | + $donor_name = give_get_donor_name_by($donor_id, 'donor'); |
|
580 | 580 | |
581 | 581 | $value = ''; |
582 | - if ( ! empty( $donor_id ) ) { |
|
582 | + if ( ! empty($donor_id)) { |
|
583 | 583 | |
584 | 584 | // Check whether the donor name and WP_User name is same or not. |
585 | - if ( sanitize_title( $donor_billing_name ) != sanitize_title( $donor_name ) ) { |
|
586 | - $value .= $donor_billing_name . ' ('; |
|
585 | + if (sanitize_title($donor_billing_name) != sanitize_title($donor_name)) { |
|
586 | + $value .= $donor_billing_name.' ('; |
|
587 | 587 | } |
588 | 588 | |
589 | - $value .= '<a href="' . esc_url( admin_url( "edit.php?post_type=give_forms&page=give-donors&view=overview&id=$donor_id" ) ) . '">' . $donor_name . '</a>'; |
|
589 | + $value .= '<a href="'.esc_url(admin_url("edit.php?post_type=give_forms&page=give-donors&view=overview&id=$donor_id")).'">'.$donor_name.'</a>'; |
|
590 | 590 | |
591 | 591 | // Check whether the donor name and WP_User name is same or not. |
592 | - if ( sanitize_title( $donor_billing_name ) != sanitize_title( $donor_name ) ) { |
|
592 | + if (sanitize_title($donor_billing_name) != sanitize_title($donor_name)) { |
|
593 | 593 | $value .= ')'; |
594 | 594 | } |
595 | 595 | } else { |
596 | - $email = give_get_payment_user_email( $payment->ID ); |
|
597 | - $value .= '<a href="' . esc_url( admin_url( "edit.php?post_type=give_forms&page=give-payment-history&s=$email" ) ) . '">' . esc_html__( '(donor missing)', 'give' ) . '</a>'; |
|
596 | + $email = give_get_payment_user_email($payment->ID); |
|
597 | + $value .= '<a href="'.esc_url(admin_url("edit.php?post_type=give_forms&page=give-payment-history&s=$email")).'">'.esc_html__('(donor missing)', 'give').'</a>'; |
|
598 | 598 | } |
599 | 599 | |
600 | - return apply_filters( 'give_payments_table_column', $value, $payment->ID, 'donor' ); |
|
600 | + return apply_filters('give_payments_table_column', $value, $payment->ID, 'donor'); |
|
601 | 601 | } |
602 | 602 | |
603 | 603 | /** |
@@ -609,20 +609,20 @@ discard block |
||
609 | 609 | */ |
610 | 610 | public function get_bulk_actions() { |
611 | 611 | $actions = array( |
612 | - 'delete' => __( 'Delete', 'give' ), |
|
613 | - 'set-status-publish' => __( 'Set To Completed', 'give' ), |
|
614 | - 'set-status-pending' => __( 'Set To Pending', 'give' ), |
|
615 | - 'set-status-processing' => __( 'Set To Processing', 'give' ), |
|
616 | - 'set-status-refunded' => __( 'Set To Refunded', 'give' ), |
|
617 | - 'set-status-revoked' => __( 'Set To Revoked', 'give' ), |
|
618 | - 'set-status-failed' => __( 'Set To Failed', 'give' ), |
|
619 | - 'set-status-cancelled' => __( 'Set To Cancelled', 'give' ), |
|
620 | - 'set-status-abandoned' => __( 'Set To Abandoned', 'give' ), |
|
621 | - 'set-status-preapproval' => __( 'Set To Preapproval', 'give' ), |
|
622 | - 'resend-receipt' => __( 'Resend Email Receipts', 'give' ), |
|
612 | + 'delete' => __('Delete', 'give'), |
|
613 | + 'set-status-publish' => __('Set To Completed', 'give'), |
|
614 | + 'set-status-pending' => __('Set To Pending', 'give'), |
|
615 | + 'set-status-processing' => __('Set To Processing', 'give'), |
|
616 | + 'set-status-refunded' => __('Set To Refunded', 'give'), |
|
617 | + 'set-status-revoked' => __('Set To Revoked', 'give'), |
|
618 | + 'set-status-failed' => __('Set To Failed', 'give'), |
|
619 | + 'set-status-cancelled' => __('Set To Cancelled', 'give'), |
|
620 | + 'set-status-abandoned' => __('Set To Abandoned', 'give'), |
|
621 | + 'set-status-preapproval' => __('Set To Preapproval', 'give'), |
|
622 | + 'resend-receipt' => __('Resend Email Receipts', 'give'), |
|
623 | 623 | ); |
624 | 624 | |
625 | - return apply_filters( 'give_payments_table_bulk_actions', $actions ); |
|
625 | + return apply_filters('give_payments_table_bulk_actions', $actions); |
|
626 | 626 | } |
627 | 627 | |
628 | 628 | /** |
@@ -633,63 +633,63 @@ discard block |
||
633 | 633 | * @return void |
634 | 634 | */ |
635 | 635 | public function process_bulk_action() { |
636 | - $ids = isset( $_GET['payment'] ) ? $_GET['payment'] : false; |
|
636 | + $ids = isset($_GET['payment']) ? $_GET['payment'] : false; |
|
637 | 637 | $action = $this->current_action(); |
638 | 638 | |
639 | - if ( ! is_array( $ids ) ) { |
|
640 | - $ids = array( $ids ); |
|
639 | + if ( ! is_array($ids)) { |
|
640 | + $ids = array($ids); |
|
641 | 641 | } |
642 | 642 | |
643 | - if ( empty( $action ) ) { |
|
643 | + if (empty($action)) { |
|
644 | 644 | return; |
645 | 645 | } |
646 | 646 | |
647 | - foreach ( $ids as $id ) { |
|
647 | + foreach ($ids as $id) { |
|
648 | 648 | |
649 | 649 | // Detect when a bulk action is being triggered. |
650 | - switch ( $this->current_action() ) { |
|
650 | + switch ($this->current_action()) { |
|
651 | 651 | |
652 | 652 | case'delete': |
653 | - give_delete_donation( $id ); |
|
653 | + give_delete_donation($id); |
|
654 | 654 | break; |
655 | 655 | |
656 | 656 | case 'set-status-publish': |
657 | - give_update_payment_status( $id, 'publish' ); |
|
657 | + give_update_payment_status($id, 'publish'); |
|
658 | 658 | break; |
659 | 659 | |
660 | 660 | case 'set-status-pending': |
661 | - give_update_payment_status( $id, 'pending' ); |
|
661 | + give_update_payment_status($id, 'pending'); |
|
662 | 662 | break; |
663 | 663 | |
664 | 664 | case 'set-status-processing': |
665 | - give_update_payment_status( $id, 'processing' ); |
|
665 | + give_update_payment_status($id, 'processing'); |
|
666 | 666 | break; |
667 | 667 | |
668 | 668 | case 'set-status-refunded': |
669 | - give_update_payment_status( $id, 'refunded' ); |
|
669 | + give_update_payment_status($id, 'refunded'); |
|
670 | 670 | break; |
671 | 671 | case 'set-status-revoked': |
672 | - give_update_payment_status( $id, 'revoked' ); |
|
672 | + give_update_payment_status($id, 'revoked'); |
|
673 | 673 | break; |
674 | 674 | |
675 | 675 | case 'set-status-failed': |
676 | - give_update_payment_status( $id, 'failed' ); |
|
676 | + give_update_payment_status($id, 'failed'); |
|
677 | 677 | break; |
678 | 678 | |
679 | 679 | case 'set-status-cancelled': |
680 | - give_update_payment_status( $id, 'cancelled' ); |
|
680 | + give_update_payment_status($id, 'cancelled'); |
|
681 | 681 | break; |
682 | 682 | |
683 | 683 | case 'set-status-abandoned': |
684 | - give_update_payment_status( $id, 'abandoned' ); |
|
684 | + give_update_payment_status($id, 'abandoned'); |
|
685 | 685 | break; |
686 | 686 | |
687 | 687 | case 'set-status-preapproval': |
688 | - give_update_payment_status( $id, 'preapproval' ); |
|
688 | + give_update_payment_status($id, 'preapproval'); |
|
689 | 689 | break; |
690 | 690 | |
691 | 691 | case 'resend-receipt': |
692 | - give_email_donation_receipt( $id, false ); |
|
692 | + give_email_donation_receipt($id, false); |
|
693 | 693 | break; |
694 | 694 | }// End switch(). |
695 | 695 | |
@@ -701,7 +701,7 @@ discard block |
||
701 | 701 | * @param int $id The ID of the payment. |
702 | 702 | * @param string $current_action The action that is being triggered. |
703 | 703 | */ |
704 | - do_action( 'give_payments_table_do_bulk_action', $id, $this->current_action() ); |
|
704 | + do_action('give_payments_table_do_bulk_action', $id, $this->current_action()); |
|
705 | 705 | }// End foreach(). |
706 | 706 | |
707 | 707 | } |
@@ -717,31 +717,31 @@ discard block |
||
717 | 717 | |
718 | 718 | $args = array(); |
719 | 719 | |
720 | - if ( isset( $_GET['user'] ) ) { |
|
721 | - $args['user'] = urldecode( $_GET['user'] ); |
|
722 | - } elseif ( isset( $_GET['donor'] ) ) { |
|
723 | - $args['donor'] = absint( $_GET['donor'] ); |
|
724 | - } elseif ( isset( $_GET['s'] ) ) { |
|
725 | - $is_user = strpos( $_GET['s'], strtolower( 'user:' ) ) !== false; |
|
726 | - if ( $is_user ) { |
|
727 | - $args['user'] = absint( trim( str_replace( 'user:', '', strtolower( $_GET['s'] ) ) ) ); |
|
728 | - unset( $args['s'] ); |
|
720 | + if (isset($_GET['user'])) { |
|
721 | + $args['user'] = urldecode($_GET['user']); |
|
722 | + } elseif (isset($_GET['donor'])) { |
|
723 | + $args['donor'] = absint($_GET['donor']); |
|
724 | + } elseif (isset($_GET['s'])) { |
|
725 | + $is_user = strpos($_GET['s'], strtolower('user:')) !== false; |
|
726 | + if ($is_user) { |
|
727 | + $args['user'] = absint(trim(str_replace('user:', '', strtolower($_GET['s'])))); |
|
728 | + unset($args['s']); |
|
729 | 729 | } else { |
730 | - $args['s'] = sanitize_text_field( $_GET['s'] ); |
|
730 | + $args['s'] = sanitize_text_field($_GET['s']); |
|
731 | 731 | } |
732 | 732 | } |
733 | 733 | |
734 | - if ( ! empty( $_GET['start-date'] ) ) { |
|
735 | - $args['start-date'] = urldecode( $_GET['start-date'] ); |
|
734 | + if ( ! empty($_GET['start-date'])) { |
|
735 | + $args['start-date'] = urldecode($_GET['start-date']); |
|
736 | 736 | } |
737 | 737 | |
738 | - if ( ! empty( $_GET['end-date'] ) ) { |
|
739 | - $args['end-date'] = urldecode( $_GET['end-date'] ); |
|
738 | + if ( ! empty($_GET['end-date'])) { |
|
739 | + $args['end-date'] = urldecode($_GET['end-date']); |
|
740 | 740 | } |
741 | 741 | |
742 | - $args['form_id'] = ! empty( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : null; |
|
742 | + $args['form_id'] = ! empty($_GET['form_id']) ? absint($_GET['form_id']) : null; |
|
743 | 743 | |
744 | - $payment_count = give_count_payments( $args ); |
|
744 | + $payment_count = give_count_payments($args); |
|
745 | 745 | $this->complete_count = $payment_count->publish; |
746 | 746 | $this->pending_count = $payment_count->pending; |
747 | 747 | $this->processing_count = $payment_count->processing; |
@@ -752,7 +752,7 @@ discard block |
||
752 | 752 | $this->abandoned_count = $payment_count->abandoned; |
753 | 753 | $this->preapproval_count = $payment_count->preapproval; |
754 | 754 | |
755 | - foreach ( $payment_count as $count ) { |
|
755 | + foreach ($payment_count as $count) { |
|
756 | 756 | $this->total_count += $count; |
757 | 757 | } |
758 | 758 | } |
@@ -767,28 +767,28 @@ discard block |
||
767 | 767 | public function payments_data() { |
768 | 768 | |
769 | 769 | $per_page = $this->per_page; |
770 | - $orderby = isset( $_GET['orderby'] ) ? urldecode( $_GET['orderby'] ) : 'ID'; |
|
771 | - $order = isset( $_GET['order'] ) ? $_GET['order'] : 'DESC'; |
|
772 | - $user = isset( $_GET['user'] ) ? $_GET['user'] : null; |
|
773 | - $donor = isset( $_GET['donor'] ) ? $_GET['donor'] : null; |
|
774 | - $status = isset( $_GET['status'] ) ? $_GET['status'] : give_get_payment_status_keys(); |
|
775 | - $meta_key = isset( $_GET['meta_key'] ) ? $_GET['meta_key'] : null; |
|
776 | - $year = isset( $_GET['year'] ) ? $_GET['year'] : null; |
|
777 | - $month = isset( $_GET['m'] ) ? $_GET['m'] : null; |
|
778 | - $day = isset( $_GET['day'] ) ? $_GET['day'] : null; |
|
779 | - $search = isset( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : null; |
|
780 | - $start_date = isset( $_GET['start-date'] ) ? sanitize_text_field( $_GET['start-date'] ) : null; |
|
781 | - $end_date = isset( $_GET['end-date'] ) ? sanitize_text_field( $_GET['end-date'] ) : $start_date; |
|
782 | - $form_id = ! empty( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : null; |
|
783 | - |
|
784 | - if ( ! empty( $search ) ) { |
|
770 | + $orderby = isset($_GET['orderby']) ? urldecode($_GET['orderby']) : 'ID'; |
|
771 | + $order = isset($_GET['order']) ? $_GET['order'] : 'DESC'; |
|
772 | + $user = isset($_GET['user']) ? $_GET['user'] : null; |
|
773 | + $donor = isset($_GET['donor']) ? $_GET['donor'] : null; |
|
774 | + $status = isset($_GET['status']) ? $_GET['status'] : give_get_payment_status_keys(); |
|
775 | + $meta_key = isset($_GET['meta_key']) ? $_GET['meta_key'] : null; |
|
776 | + $year = isset($_GET['year']) ? $_GET['year'] : null; |
|
777 | + $month = isset($_GET['m']) ? $_GET['m'] : null; |
|
778 | + $day = isset($_GET['day']) ? $_GET['day'] : null; |
|
779 | + $search = isset($_GET['s']) ? sanitize_text_field($_GET['s']) : null; |
|
780 | + $start_date = isset($_GET['start-date']) ? sanitize_text_field($_GET['start-date']) : null; |
|
781 | + $end_date = isset($_GET['end-date']) ? sanitize_text_field($_GET['end-date']) : $start_date; |
|
782 | + $form_id = ! empty($_GET['form_id']) ? absint($_GET['form_id']) : null; |
|
783 | + |
|
784 | + if ( ! empty($search)) { |
|
785 | 785 | $status = 'any'; // Force all payment statuses when searching. |
786 | 786 | } |
787 | 787 | |
788 | 788 | $args = array( |
789 | 789 | 'output' => 'payments', |
790 | 790 | 'number' => $per_page, |
791 | - 'page' => isset( $_GET['paged'] ) ? $_GET['paged'] : null, |
|
791 | + 'page' => isset($_GET['paged']) ? $_GET['paged'] : null, |
|
792 | 792 | 'orderby' => $orderby, |
793 | 793 | 'order' => $order, |
794 | 794 | 'user' => $user, |
@@ -804,12 +804,12 @@ discard block |
||
804 | 804 | 'give_forms' => $form_id, |
805 | 805 | ); |
806 | 806 | |
807 | - if ( is_string( $search ) && false !== strpos( $search, 'txn:' ) ) { |
|
807 | + if (is_string($search) && false !== strpos($search, 'txn:')) { |
|
808 | 808 | $args['search_in_notes'] = true; |
809 | - $args['s'] = trim( str_replace( 'txn:', '', $args['s'] ) ); |
|
809 | + $args['s'] = trim(str_replace('txn:', '', $args['s'])); |
|
810 | 810 | } |
811 | 811 | |
812 | - $p_query = new Give_Payments_Query( $args ); |
|
812 | + $p_query = new Give_Payments_Query($args); |
|
813 | 813 | |
814 | 814 | return $p_query->get_payments(); |
815 | 815 | |
@@ -829,17 +829,17 @@ discard block |
||
829 | 829 | */ |
830 | 830 | public function prepare_items() { |
831 | 831 | |
832 | - wp_reset_vars( array( 'action', 'payment', 'orderby', 'order', 's' ) ); |
|
832 | + wp_reset_vars(array('action', 'payment', 'orderby', 'order', 's')); |
|
833 | 833 | |
834 | 834 | $columns = $this->get_columns(); |
835 | 835 | $hidden = array(); // No hidden columns. |
836 | 836 | $sortable = $this->get_sortable_columns(); |
837 | 837 | $data = $this->payments_data(); |
838 | - $status = isset( $_GET['status'] ) ? $_GET['status'] : 'any'; |
|
838 | + $status = isset($_GET['status']) ? $_GET['status'] : 'any'; |
|
839 | 839 | |
840 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
840 | + $this->_column_headers = array($columns, $hidden, $sortable); |
|
841 | 841 | |
842 | - switch ( $status ) { |
|
842 | + switch ($status) { |
|
843 | 843 | case 'publish': |
844 | 844 | $total_items = $this->complete_count; |
845 | 845 | break; |
@@ -872,20 +872,20 @@ discard block |
||
872 | 872 | break; |
873 | 873 | default: |
874 | 874 | // Retrieve the count of the non-default-Give status. |
875 | - $count = wp_count_posts( 'give_payment' ); |
|
876 | - $total_items = isset( $count->{$status} ) ? $count->{$status} : 0; |
|
875 | + $count = wp_count_posts('give_payment'); |
|
876 | + $total_items = isset($count->{$status} ) ? $count->{$status} : 0; |
|
877 | 877 | break; |
878 | 878 | } |
879 | 879 | |
880 | 880 | $this->items = $data; |
881 | 881 | |
882 | - $this->set_pagination_args( array( |
|
882 | + $this->set_pagination_args(array( |
|
883 | 883 | 'total_items' => $total_items, |
884 | 884 | // We have to calculate the total number of items. |
885 | 885 | 'per_page' => $this->per_page, |
886 | 886 | // We have to determine how many items to show on a page. |
887 | - 'total_pages' => ceil( $total_items / $this->per_page ), |
|
887 | + 'total_pages' => ceil($total_items / $this->per_page), |
|
888 | 888 | // We have to calculate the total number of pages. |
889 | - ) ); |
|
889 | + )); |
|
890 | 890 | } |
891 | 891 | } |
@@ -9,13 +9,13 @@ discard block |
||
9 | 9 | */ |
10 | 10 | |
11 | 11 | // Exit if accessed directly. |
12 | -if ( ! defined( 'ABSPATH' ) ) { |
|
12 | +if ( ! defined('ABSPATH')) { |
|
13 | 13 | exit; |
14 | 14 | } |
15 | 15 | |
16 | 16 | // Load WP_List_Table if not loaded. |
17 | -if ( ! class_exists( 'WP_List_Table' ) ) { |
|
18 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
17 | +if ( ! class_exists('WP_List_Table')) { |
|
18 | + require_once ABSPATH.'wp-admin/includes/class-wp-list-table.php'; |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -44,13 +44,13 @@ discard block |
||
44 | 44 | global $status, $page; |
45 | 45 | |
46 | 46 | // Set parent defaults |
47 | - parent::__construct( array( |
|
48 | - 'singular' => give_get_forms_label_singular(), // Singular name of the listed records |
|
49 | - 'plural' => give_get_forms_label_plural(), // Plural name of the listed records |
|
50 | - 'ajax' => false,// Does this table support ajax? |
|
51 | - ) ); |
|
47 | + parent::__construct(array( |
|
48 | + 'singular' => give_get_forms_label_singular(), // Singular name of the listed records |
|
49 | + 'plural' => give_get_forms_label_plural(), // Plural name of the listed records |
|
50 | + 'ajax' => false, // Does this table support ajax? |
|
51 | + )); |
|
52 | 52 | |
53 | - add_action( 'give_log_view_actions', array( $this, 'give_forms_filter' ) ); |
|
53 | + add_action('give_log_view_actions', array($this, 'give_forms_filter')); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
@@ -64,41 +64,41 @@ discard block |
||
64 | 64 | * |
65 | 65 | * @return string Column Name |
66 | 66 | */ |
67 | - public function column_default( $item, $column_name ) { |
|
67 | + public function column_default($item, $column_name) { |
|
68 | 68 | |
69 | - $payment = give_get_payment_by( 'id', $item['payment_id'] ); |
|
69 | + $payment = give_get_payment_by('id', $item['payment_id']); |
|
70 | 70 | |
71 | - switch ( $column_name ) { |
|
71 | + switch ($column_name) { |
|
72 | 72 | case 'form' : |
73 | - $form_title = get_the_title( $item[ $column_name ] ); |
|
74 | - $form_title = empty( $form_title ) ? sprintf( __( 'Untitled (#%s)', 'give' ), $item[ $column_name ] ) : $form_title; |
|
75 | - return '<a href="' . esc_url( add_query_arg( 'form', $item[ $column_name ] ) ) . '" >' . $form_title . '</a>'; |
|
73 | + $form_title = get_the_title($item[$column_name]); |
|
74 | + $form_title = empty($form_title) ? sprintf(__('Untitled (#%s)', 'give'), $item[$column_name]) : $form_title; |
|
75 | + return '<a href="'.esc_url(add_query_arg('form', $item[$column_name])).'" >'.$form_title.'</a>'; |
|
76 | 76 | |
77 | 77 | case 'donor_id' : |
78 | 78 | return sprintf( |
79 | 79 | '<a href="%s">%s</a>', |
80 | - admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&donor=' . absint( $item['donor_id'] ) ), |
|
80 | + admin_url('edit.php?post_type=give_forms&page=give-payment-history&donor='.absint($item['donor_id'])), |
|
81 | 81 | $item['donor_name'] |
82 | 82 | ); |
83 | 83 | |
84 | 84 | case 'amount' : |
85 | - return give_currency_filter( give_format_amount( $item['amount'], array( 'sanitize' => false, 'donation_id' => $item['payment_id'] ) ), give_get_payment_currency_code( $item['payment_id'] ) ); |
|
85 | + return give_currency_filter(give_format_amount($item['amount'], array('sanitize' => false, 'donation_id' => $item['payment_id'])), give_get_payment_currency_code($item['payment_id'])); |
|
86 | 86 | |
87 | 87 | case 'status' : |
88 | 88 | |
89 | - $value = '<div class="give-donation-status status-' . sanitize_title( give_get_payment_status( $payment, true ) ) . '"><span class="give-donation-status-icon"></span> ' . give_get_payment_status( $payment, true ) . '</div>'; |
|
89 | + $value = '<div class="give-donation-status status-'.sanitize_title(give_get_payment_status($payment, true)).'"><span class="give-donation-status-icon"></span> '.give_get_payment_status($payment, true).'</div>'; |
|
90 | 90 | |
91 | - if ( $payment->mode == 'test' ) { |
|
92 | - $value .= ' <span class="give-item-label give-item-label-orange give-test-mode-transactions-label" data-tooltip="' . esc_attr__( 'This donation was made in test mode.', 'give' ) . '">' . __( 'Test', 'give' ) . '</span>'; |
|
91 | + if ($payment->mode == 'test') { |
|
92 | + $value .= ' <span class="give-item-label give-item-label-orange give-test-mode-transactions-label" data-tooltip="'.esc_attr__('This donation was made in test mode.', 'give').'">'.__('Test', 'give').'</span>'; |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | return $value; |
96 | 96 | |
97 | 97 | case 'payment_id' : |
98 | - return '<a href="' . admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-payment-details&id=' . $item['payment_id'] ) . '">' . give_get_payment_number( $item['payment_id'] ) . '</a>'; |
|
98 | + return '<a href="'.admin_url('edit.php?post_type=give_forms&page=give-payment-history&view=view-payment-details&id='.$item['payment_id']).'">'.give_get_payment_number($item['payment_id']).'</a>'; |
|
99 | 99 | |
100 | 100 | default: |
101 | - return $item[ $column_name ]; |
|
101 | + return $item[$column_name]; |
|
102 | 102 | } |
103 | 103 | } |
104 | 104 | |
@@ -111,13 +111,13 @@ discard block |
||
111 | 111 | */ |
112 | 112 | public function get_columns() { |
113 | 113 | $columns = array( |
114 | - 'ID' => __( 'Log ID', 'give' ), |
|
115 | - 'donor_id' => __( 'Donor', 'give' ), |
|
116 | - 'form' => __( 'Form', 'give' ), |
|
117 | - 'amount' => __( 'Donation Amount', 'give' ), |
|
118 | - 'status' => __( 'Status', 'give' ), |
|
119 | - 'payment_id' => __( 'Donation ID', 'give' ), |
|
120 | - 'date' => __( 'Date', 'give' ), |
|
114 | + 'ID' => __('Log ID', 'give'), |
|
115 | + 'donor_id' => __('Donor', 'give'), |
|
116 | + 'form' => __('Form', 'give'), |
|
117 | + 'amount' => __('Donation Amount', 'give'), |
|
118 | + 'status' => __('Status', 'give'), |
|
119 | + 'payment_id' => __('Donation ID', 'give'), |
|
120 | + 'date' => __('Date', 'give'), |
|
121 | 121 | ); |
122 | 122 | |
123 | 123 | return $columns; |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | * @return int Current page number |
132 | 132 | */ |
133 | 133 | public function get_paged() { |
134 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
134 | + return isset($_GET['paged']) ? absint($_GET['paged']) : 1; |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | * @return mixed int If User ID, string If Email/Login |
143 | 143 | */ |
144 | 144 | public function get_filtered_user() { |
145 | - return isset( $_GET['user'] ) ? absint( $_GET['user'] ) : false; |
|
145 | + return isset($_GET['user']) ? absint($_GET['user']) : false; |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | * @return int Download ID |
154 | 154 | */ |
155 | 155 | public function get_filtered_give_form() { |
156 | - return ! empty( $_GET['form'] ) ? absint( $_GET['form'] ) : false; |
|
156 | + return ! empty($_GET['form']) ? absint($_GET['form']) : false; |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | * @return string|bool string If search is present, false otherwise |
165 | 165 | */ |
166 | 166 | public function get_search() { |
167 | - return ! empty( $_GET['s'] ) ? urldecode( trim( $_GET['s'] ) ) : false; |
|
167 | + return ! empty($_GET['s']) ? urldecode(trim($_GET['s'])) : false; |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | |
@@ -180,20 +180,20 @@ discard block |
||
180 | 180 | * |
181 | 181 | * @param string $which |
182 | 182 | */ |
183 | - protected function display_tablenav( $which ) { |
|
183 | + protected function display_tablenav($which) { |
|
184 | 184 | |
185 | - if ( 'top' === $which ) { |
|
186 | - wp_nonce_field( 'bulk-' . $this->_args['plural'] ); |
|
185 | + if ('top' === $which) { |
|
186 | + wp_nonce_field('bulk-'.$this->_args['plural']); |
|
187 | 187 | } |
188 | 188 | ?> |
189 | - <div class="tablenav <?php echo esc_attr( $which ); ?>"> |
|
189 | + <div class="tablenav <?php echo esc_attr($which); ?>"> |
|
190 | 190 | |
191 | 191 | <div class="alignleft actions bulkactions"> |
192 | - <?php $this->bulk_actions( $which ); ?> |
|
192 | + <?php $this->bulk_actions($which); ?> |
|
193 | 193 | </div> |
194 | 194 | <?php |
195 | - $this->extra_tablenav( $which ); |
|
196 | - $this->pagination( $which ); |
|
195 | + $this->extra_tablenav($which); |
|
196 | + $this->pagination($which); |
|
197 | 197 | ?> |
198 | 198 | |
199 | 199 | <br class="clear"/> |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | |
218 | 218 | $meta_query = array(); |
219 | 219 | |
220 | - if ( $user ) { |
|
220 | + if ($user) { |
|
221 | 221 | // Show only logs from a specific user. |
222 | 222 | $meta_query[] = array( |
223 | 223 | 'key' => '_give_log_user_id', |
@@ -226,8 +226,8 @@ discard block |
||
226 | 226 | } |
227 | 227 | |
228 | 228 | $search = $this->get_search(); |
229 | - if ( $search ) { |
|
230 | - if ( is_email( $search ) ) { |
|
229 | + if ($search) { |
|
230 | + if (is_email($search)) { |
|
231 | 231 | // This is an email search. We use this to ensure it works for guest users and logged-in users. |
232 | 232 | $key = '_give_log_user_info'; |
233 | 233 | $compare = 'LIKE'; |
@@ -236,32 +236,32 @@ discard block |
||
236 | 236 | $key = '_give_log_user_id'; |
237 | 237 | $compare = 'LIKE'; |
238 | 238 | |
239 | - if ( ! is_numeric( $search ) ) { |
|
239 | + if ( ! is_numeric($search)) { |
|
240 | 240 | // Searching for user by username |
241 | - $user = get_user_by( 'login', $search ); |
|
241 | + $user = get_user_by('login', $search); |
|
242 | 242 | |
243 | - if ( $user ) { |
|
243 | + if ($user) { |
|
244 | 244 | // Found one, set meta value to user's ID. |
245 | 245 | $search = $user->ID; |
246 | 246 | } else { |
247 | 247 | // No user found so let's do a real search query. |
248 | - $users = new WP_User_Query( array( |
|
248 | + $users = new WP_User_Query(array( |
|
249 | 249 | 'search' => $search, |
250 | - 'search_columns' => array( 'user_url', 'user_nicename' ), |
|
250 | + 'search_columns' => array('user_url', 'user_nicename'), |
|
251 | 251 | 'number' => 1, |
252 | 252 | 'fields' => 'ids', |
253 | - ) ); |
|
253 | + )); |
|
254 | 254 | |
255 | 255 | $found_user = $users->get_results(); |
256 | 256 | |
257 | - if ( $found_user ) { |
|
257 | + if ($found_user) { |
|
258 | 258 | $search = $found_user[0]; |
259 | 259 | } |
260 | 260 | } |
261 | 261 | } |
262 | 262 | } |
263 | 263 | |
264 | - if ( ! $this->file_search ) { |
|
264 | + if ( ! $this->file_search) { |
|
265 | 265 | // Meta query only works for non file name search. |
266 | 266 | $meta_query[] = array( |
267 | 267 | 'key' => $key, |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | * @since 1.0 |
283 | 283 | * @return void |
284 | 284 | */ |
285 | - function bulk_actions( $which = '' ) { |
|
285 | + function bulk_actions($which = '') { |
|
286 | 286 | give_log_views(); |
287 | 287 | } |
288 | 288 | |
@@ -294,24 +294,24 @@ discard block |
||
294 | 294 | * @return void |
295 | 295 | */ |
296 | 296 | public function give_forms_filter() { |
297 | - $give_forms = get_posts( array( |
|
297 | + $give_forms = get_posts(array( |
|
298 | 298 | 'post_type' => 'give_forms', |
299 | 299 | 'post_status' => 'any', |
300 | - 'posts_per_page' => - 1, |
|
300 | + 'posts_per_page' => -1, |
|
301 | 301 | 'orderby' => 'title', |
302 | 302 | 'order' => 'ASC', |
303 | 303 | 'fields' => 'ids', |
304 | 304 | 'update_post_meta_cache' => false, |
305 | 305 | 'update_post_term_cache' => false, |
306 | - ) ); |
|
306 | + )); |
|
307 | 307 | |
308 | - if ( $give_forms ) { |
|
308 | + if ($give_forms) { |
|
309 | 309 | echo '<select name="form" id="give-log-form-filter">'; |
310 | - echo '<option value="0">' . __( 'All', 'give' ) . '</option>'; |
|
311 | - foreach ( $give_forms as $form ) { |
|
312 | - $form_title = get_the_title( $form ); |
|
313 | - $form_title = empty( $form_title ) ? sprintf( __( 'Untitled (#%s)', 'give' ), $form ) : $form_title; |
|
314 | - echo '<option value="' . $form . '"' . selected( $form, $this->get_filtered_give_form() ) . '>' . esc_html( $form_title ) . '</option>'; |
|
310 | + echo '<option value="0">'.__('All', 'give').'</option>'; |
|
311 | + foreach ($give_forms as $form) { |
|
312 | + $form_title = get_the_title($form); |
|
313 | + $form_title = empty($form_title) ? sprintf(__('Untitled (#%s)', 'give'), $form) : $form_title; |
|
314 | + echo '<option value="'.$form.'"'.selected($form, $this->get_filtered_give_form()).'>'.esc_html($form_title).'</option>'; |
|
315 | 315 | } |
316 | 316 | echo '</select>'; |
317 | 317 | } |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | |
332 | 332 | $logs_data = array(); |
333 | 333 | $paged = $this->get_paged(); |
334 | - $give_form = empty( $_GET['s'] ) ? $this->get_filtered_give_form() : null; |
|
334 | + $give_form = empty($_GET['s']) ? $this->get_filtered_give_form() : null; |
|
335 | 335 | $user = $this->get_filtered_user(); |
336 | 336 | |
337 | 337 | $log_query = array( |
@@ -342,37 +342,37 @@ discard block |
||
342 | 342 | 'posts_per_page' => $this->per_page, |
343 | 343 | ); |
344 | 344 | |
345 | - $cache_key = Give_Cache::get_key( 'get_logs', $log_query ); |
|
345 | + $cache_key = Give_Cache::get_key('get_logs', $log_query); |
|
346 | 346 | |
347 | 347 | // Return result from cache if exist. |
348 | - if ( ! ( $logs_data = Give_Cache::get( $cache_key ) ) ) { |
|
349 | - $logs = $give_logs->get_connected_logs( $log_query ); |
|
348 | + if ( ! ($logs_data = Give_Cache::get($cache_key))) { |
|
349 | + $logs = $give_logs->get_connected_logs($log_query); |
|
350 | 350 | |
351 | - if ( $logs ) { |
|
352 | - foreach ( $logs as $log ) { |
|
353 | - $payment_id = give_get_meta( $log->ID, '_give_log_payment_id', true ); |
|
351 | + if ($logs) { |
|
352 | + foreach ($logs as $log) { |
|
353 | + $payment_id = give_get_meta($log->ID, '_give_log_payment_id', true); |
|
354 | 354 | |
355 | 355 | // Make sure this payment hasn't been deleted. |
356 | - if ( get_post( $payment_id ) ) : |
|
357 | - $user_info = give_get_payment_meta_user_info( $payment_id ); |
|
358 | - $payment_amount = give_get_payment_amount( $payment_id ); |
|
356 | + if (get_post($payment_id)) : |
|
357 | + $user_info = give_get_payment_meta_user_info($payment_id); |
|
358 | + $payment_amount = give_get_payment_amount($payment_id); |
|
359 | 359 | |
360 | 360 | $logs_data[] = array( |
361 | - 'ID' => '<span class="give-item-label give-item-label-gray">' . $log->ID . '</span>', |
|
361 | + 'ID' => '<span class="give-item-label give-item-label-gray">'.$log->ID.'</span>', |
|
362 | 362 | 'payment_id' => $payment_id, |
363 | 363 | 'form' => $log->post_parent, |
364 | 364 | 'amount' => $payment_amount, |
365 | - 'donor_id' => give_get_payment_donor_id( $payment_id ), |
|
366 | - 'donor_name' => trim( "{$user_info['first_name']} {$user_info['last_name']}" ), |
|
367 | - 'date' => get_post_field( 'post_date', $payment_id ), |
|
365 | + 'donor_id' => give_get_payment_donor_id($payment_id), |
|
366 | + 'donor_name' => trim("{$user_info['first_name']} {$user_info['last_name']}"), |
|
367 | + 'date' => get_post_field('post_date', $payment_id), |
|
368 | 368 | ); |
369 | 369 | |
370 | 370 | endif; |
371 | 371 | } |
372 | 372 | |
373 | 373 | // Cache results. |
374 | - if ( ! empty( $logs_data ) ) { |
|
375 | - Give_Cache::set( $cache_key, $logs_data ); |
|
374 | + if ( ! empty($logs_data)) { |
|
375 | + Give_Cache::set($cache_key, $logs_data); |
|
376 | 376 | } |
377 | 377 | } |
378 | 378 | } |
@@ -400,15 +400,15 @@ discard block |
||
400 | 400 | $columns = $this->get_columns(); |
401 | 401 | $hidden = array(); |
402 | 402 | $sortable = $this->get_sortable_columns(); |
403 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
403 | + $this->_column_headers = array($columns, $hidden, $sortable); |
|
404 | 404 | $current_page = $this->get_pagenum(); |
405 | 405 | $this->items = $this->get_logs(); |
406 | - $total_items = $give_logs->get_log_count( $this->get_filtered_give_form(), 'sale', $this->get_meta_query() ); |
|
406 | + $total_items = $give_logs->get_log_count($this->get_filtered_give_form(), 'sale', $this->get_meta_query()); |
|
407 | 407 | |
408 | - $this->set_pagination_args( array( |
|
408 | + $this->set_pagination_args(array( |
|
409 | 409 | 'total_items' => $total_items, |
410 | 410 | 'per_page' => $this->per_page, |
411 | - 'total_pages' => ceil( $total_items / $this->per_page ), |
|
411 | + 'total_pages' => ceil($total_items / $this->per_page), |
|
412 | 412 | ) |
413 | 413 | ); |
414 | 414 | } |