PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.17.0
GiveWP – Donation Plugin and Fundraising Platform v4.17.0
4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 All 256 releases
← All changes | includes/payments/backward-compatibility.php +47 -44 2.3.0 → 4.17.0 View file →
@@ -4,9 +4,9 @@
4 4 *
5 5 * @since 2.0
6 6 *
7 7 * @param $object_id
8 - * @param array $meta_value
8 + * @param array $meta_value
9 9 *
10 10 * @return void
11 11 */
12 12 function _give_20_bc_split_and_save_give_payment_meta( $object_id, $meta_value ) {
@@ -84,9 +84,9 @@
84 84 *
85 85 * @since 2.0
86 86 *
87 87 * @param $object_id
88 - * @param array $meta_value
88 + * @param array $meta_value
89 89 *
90 90 * @return array
91 91 */
92 92 function _give_20_bc_give_payment_meta_value( $object_id, $meta_value ) {
@@ -210,16 +210,23 @@
210 210 * @return mixed
211 211 */
212 212 function _give_20_bc_saving_old_payment_meta( $check, $object_id, $meta_key, $meta_value, $prev_value ) {
213 213 // Bailout.
214 + if ( 'give_payment' !== get_post_type( $object_id ) ) {
215 + return $check;
216 + }
217 +
218 + // Bailout.
214 219 if (
215 - 'give_payment' !== get_post_type( $object_id ) ||
216 - ! in_array( $meta_key, array(
217 - '_give_payment_meta',
218 - '_give_payment_user_email',
219 - '_give_payment_customer_id',
220 - 'give_payment_user_ip',
221 - ) )
220 + ! in_array(
221 + $meta_key,
222 + array(
223 + '_give_payment_meta',
224 + '_give_payment_user_email',
225 + '_give_payment_customer_id',
226 + 'give_payment_user_ip',
227 + )
228 + )
222 229 ) {
223 230 return $check;
224 231 }
225 232
@@ -256,8 +263,12 @@
256 263 */
257 264 function _give_20_bc_get_old_payment_meta( $check, $object_id, $meta_key, $single ) {
258 265 global $wpdb;
259 266
267 + // Early exit.
268 + if ( 'give_payment' !== get_post_type( $object_id ) ) {
269 + return $check;
270 + }
260 271 // Deprecated meta keys.
261 272 $old_meta_keys = array(
262 273 '_give_payment_customer_id',
263 274 '_give_payment_user_email',
@@ -269,12 +280,9 @@
269 280 $old_meta_keys[] = '_give_payment_meta';
270 281 }
271 282
272 283 // Bailout.
273 - if (
274 - 'give_payment' !== get_post_type( $object_id ) ||
275 - ! in_array( $meta_key, $old_meta_keys )
276 - ) {
284 + if ( ! in_array( $meta_key, $old_meta_keys ) ) {
277 285 return $check;
278 286 }
279 287
280 288 $cache_key = "{$meta_key}_{$object_id}";
@@ -356,14 +364,15 @@
356 364 *
357 365 * @return mixed
358 366 */
359 367 function _give_20_bc_get_new_payment_meta( $check, $object_id, $meta_key, $single ) {
360 - // Bailout: do not apply backward compatibility if upgrade done.
361 - if ( give_has_upgrade_completed( 'v20_upgrades_payment_metadata' ) ) {
368 + global $wpdb;
369 +
370 + // Early exit.
371 + if ( 'give_payment' !== get_post_type( $object_id ) ) {
362 372 return $check;
363 373 }
364 374
365 - global $wpdb;
366 375 $new_meta_keys = array(
367 376 '_give_payment_donor_id',
368 377 '_give_payment_donor_email',
369 378 '_give_payment_donor_ip',
@@ -383,9 +392,8 @@
383 392 remove_filter( 'get_post_metadata', '_give_20_bc_get_new_payment_meta' );
384 393
385 394 // Bailout.
386 395 if (
387 - 'give_payment' !== get_post_type( $object_id ) ||
388 396 ! in_array( $meta_key, $new_meta_keys ) ||
389 397 metadata_exists( 'post', $object_id, $meta_key )
390 398 ) {
391 399 add_filter( 'get_post_metadata', '_give_20_bc_get_new_payment_meta', 10, 5 );
@@ -395,9 +403,9 @@
395 403
396 404 add_filter( 'get_post_metadata', '_give_20_bc_get_new_payment_meta', 10, 5 );
397 405
398 406 $cache_key = "{$meta_key}_{$object_id}";
399 - $check = Give_Cache::get_db_query( $cache_key );
407 + $check = Give_Cache::get_db_query( $cache_key );
400 408
401 409 if ( is_null( $check ) ) {
402 410 switch ( $meta_key ) {
403 411
@@ -512,13 +520,15 @@
512 520 if ( ! $single ) {
513 521 $check = array( $check );
514 522 }
515 523
516 -
517 524 return $check;
518 525 }
519 526
520 -add_filter( 'get_post_metadata', '_give_20_bc_get_new_payment_meta', 10, 5 );
527 +// Apply filter only if upgrade does not complete yet.
528 +if ( ! give_has_upgrade_completed( 'v20_upgrades_payment_metadata' ) ) {
529 + add_filter( 'get_post_metadata', '_give_20_bc_get_new_payment_meta', 10, 5 );
530 +}
521 531
522 532
523 533 /**
524 534 * Add support for old payment meta keys.
@@ -529,13 +539,8 @@
529 539 *
530 540 * @return void
531 541 */
532 542 function _give_20_bc_support_deprecated_meta_key_query( $query ) {
533 - // Bailout.
534 - if ( give_has_upgrade_completed( 'v20_upgrades_payment_metadata' ) ) {
535 - return;
536 - }
537 -
538 543 $new_meta_keys = array(
539 544 '_give_payment_customer_id' => '_give_payment_donor_id',
540 545 '_give_payment_user_email' => '_give_payment_donor_email',
541 546 // '_give_payment_user_ip' => '_give_payment_donor_ip',
@@ -545,9 +550,8 @@
545 550
546 551 // Set meta keys.
547 552 $meta_keys = array();
548 553
549 -
550 554 // Bailout.
551 555 if ( ! empty( $query->query_vars['meta_key'] ) ) {
552 556 if ( in_array( $query->query_vars['meta_key'], $new_meta_keys ) ) {
553 557 $meta_keys = $deprecated_meta_keys;
@@ -613,11 +617,13 @@
613 617 }
614 618 }
615 619 }
616 620
617 -add_action( 'pre_get_posts', '_give_20_bc_support_deprecated_meta_key_query' );
621 +// Apply filter only if upgrade does not complete.
622 +if ( ! give_has_upgrade_completed( 'v20_upgrades_payment_metadata' ) ) {
623 + add_action( 'pre_get_posts', '_give_20_bc_support_deprecated_meta_key_query' );
624 +}
618 625
619 -
620 626 /**
621 627 * Save payment backward compatibility.
622 628 * Note: some addon still can use user_info in set payment meta
623 629 * we will use this info to set first name, last name and address of donor
@@ -627,13 +633,8 @@
627 633 * @param Give_Payment $payment
628 634 * @param string $key
629 635 */
630 636 function _give_20_bc_payment_save( $payment, $key ) {
631 - // Bailout.
632 - if ( ! give_has_upgrade_completed( 'v20_upgrades_payment_metadata' ) ) {
633 - return;
634 - }
635 -
636 637 switch ( $key ) {
637 638 case 'user_info':
638 639 if ( empty( $payment->user_info ) ) {
639 640 // Bailout.
@@ -642,21 +643,18 @@
642 643 // Check if value serialize.
643 644 $payment->user_info = maybe_unserialize( $payment->user_info );
644 645 }
645 646
646 -
647 647 // Save first name.
648 648 if ( isset( $payment->user_info['first_name'] ) ) {
649 649 $payment->update_meta( '_give_donor_billing_first_name', $payment->user_info['first_name'] );
650 650 }
651 651
652 -
653 652 // Save last name.
654 653 if ( isset( $payment->user_info['last_name'] ) ) {
655 654 $payment->update_meta( '_give_donor_billing_last_name', $payment->user_info['last_name'] );
656 655 }
657 656
658 -
659 657 // Save address.
660 658 if ( ! empty( $payment->user_info['address'] ) ) {
661 659 foreach ( $payment->user_info['address'] as $address_name => $address ) {
662 660 switch ( $address_name ) {
@@ -677,14 +675,19 @@
677 675 break;
678 676 }
679 677 }
680 678
681 -add_action( 'give_payment_save', '_give_20_bc_payment_save', 10, 2 );
682 679
680 +// Apply filter only if upgrade complete.
681 +if ( give_has_upgrade_completed( 'v20_upgrades_payment_metadata' ) ) {
682 + add_action( 'give_payment_save', '_give_20_bc_payment_save', 10, 2 );
683 +}
683 684
685 +
684 686 /**
685 687 * Delete pre upgrade cache for donations.
686 688 *
689 + * @since 4.9.0 rename function - PHP 8 compatibility
687 690 * @since 2.0
688 691 *
689 692 * @param $check
690 693 * @param $object_id
@@ -690,13 +693,10 @@
690 693 * @param $object_id
691 694 *
692 695 * @return mixed
693 696 */
694 -function __give_20_bc_flush_cache( $check, $object_id ) {
695 - if (
696 - ! give_has_upgrade_completed( 'v20_move_metadata_into_new_table' ) &&
697 - 'give_payment' === get_post_type( $object_id )
698 - ) {
697 +function give_20_bc_flush_cache( $check, $object_id ) {
698 + if ( 'give_payment' === get_post_type( $object_id ) ) {
699 699 Give_Cache::delete_group( $object_id, 'give-donations' );
700 700 }
701 701
702 702 return $check;
@@ -701,6 +701,9 @@
701 701
702 702 return $check;
703 703 }
704 704
705 -add_action( 'update_post_metadata', '__give_20_bc_flush_cache', 9999, 2 );
706 -add_action( 'add_post_metadata', '__give_20_bc_flush_cache', 9999, 2 );
705 +// Apply only if upgrade does not complete.
706 +if ( ! give_has_upgrade_completed( 'v20_move_metadata_into_new_table' ) ) {
707 + add_action( 'update_post_metadata', 'give_20_bc_flush_cache', 9999, 2 );
708 + add_action( 'add_post_metadata', 'give_20_bc_flush_cache', 9999, 2 );
709 +}