PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.13.1
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.13.1
1.8.13.1 1.8.13 1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 All 212 releases
← All changes | includes/users/class-charitable-user.php +42 -15 1.7.0.11 → 1.8.13.1 View file →
@@ -9,12 +9,12 @@
9 9 * get the "fundraiser" role.
10 10 *
11 11 * @package Charitable/Classes/Charitable_User
12 12 * @author David Bisset
13 - * @copyright Copyright (c) 2022, WP Charitable LLC
13 + * @copyright Copyright (c) 2023, WP Charitable LLC
14 14 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
15 15 * @since 1.0.0
16 - * @version 1.6.44
16 + * @version 1.8.9.1
17 17 */
18 18
19 19 // Exit if accessed directly.
20 20 if ( ! defined( 'ABSPATH' ) ) {
@@ -89,9 +89,9 @@
89 89 * @param string $name Optional. User's username.
90 90 * @param int $blog_id Optional Blog ID, defaults to current blog.
91 91 * @return void
92 92 */
93 - public function __construct( $id = 0, $name = '', $blog_id = '' ) {
93 + public function __construct( $id = 0, $name = '', $blog_id = '' ) { // phpcs:ignore
94 94 parent::__construct( $id, $name, $blog_id );
95 95 }
96 96
97 97 /**
@@ -479,9 +479,10 @@
479 479
480 480 /**
481 481 * Return the total amount donated by the donor.
482 482 *
483 - * @since 1.0.0
483 + * @since 1.0.0
484 + * @version 1.8.1
484 485 *
485 486 * @param int $campaign_id Optional. If set, returns total donated to this particular campaign.
486 487 * @return float
487 488 */
@@ -503,11 +504,15 @@
503 504 );
504 505
505 506 $query = new Charitable_Donor_Query( $args );
506 507
507 - $amount = $query->current()->amount;
508 + if ( is_object( $query->current() ) ) { // test to see if it's an object.
508 509
509 - wp_cache_set( $this->get_donor_id(), $amount, 'charitable_donor_total_donation_amount_' . $campaign_id );
510 + $amount = $query->current()->amount;
511 +
512 + wp_cache_set( $this->get_donor_id(), $amount, 'charitable_donor_total_donation_amount_' . $campaign_id );
513 +
514 + }
510 515 }
511 516
512 517 return (float) $amount;
513 518 }
@@ -520,8 +525,9 @@
520 525 *
521 526 * @since 1.0.0
522 527 *
523 528 * @param int $size The length and width of the avatar.
529 + * @param int $donor_id Optional. The donor ID.
524 530 * @return string
525 531 */
526 532 public function get_avatar( $size = 100, $donor_id = false ) {
527 533 /**If you use this filter, return an attachment ID. */
@@ -605,8 +611,9 @@
605 611 /**
606 612 * Checks whether the user has any current campaigns (i.e. non-expired).
607 613 *
608 614 * @since 1.0.0
615 + * @version 1.8.9.1
609 616 *
610 617 * @param array $args Query arguments.
611 618 * @return WP_Query
612 619 */
@@ -616,9 +623,9 @@
616 623 'meta_query' => array(
617 624 'relation' => 'OR',
618 625 array(
619 626 'key' => '_campaign_end_date',
620 - 'value' => date( 'Y-m-d H:i:s' ),
627 + 'value' => date( 'Y-m-d H:i:s' ), // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
621 628 'compare' => '>=',
622 629 'type' => 'datetime',
623 630 ),
624 631 array(
@@ -753,8 +760,9 @@
753 760 /**
754 761 * Insert a new donor with submitted values.
755 762 *
756 763 * @since 1.4.0
764 + * @version 1.8.1.15
757 765 *
758 766 * @param array $submitted The submitted values.
759 767 * @param array $keys The keys of fields that are to be updated.
760 768 * @return int
@@ -760,8 +768,15 @@
760 768 * @return int
761 769 */
762 770 public static function create_profile( $submitted = array(), $keys = array() ) {
763 771 $user = new Charitable_User();
772 +
773 + // Ensure that an ID isn't being submitted.
774 + // Adding here but this function might be deprecated or not in use (outside of tests).
775 + if ( array_key_exists( 'ID', $submitted ) ) {
776 + unset( $submitted['ID'] );
777 + }
778 +
764 779 $user_id = $user->update_profile( $submitted, $keys );
765 780 return new Charitable_User( $user_id );
766 781 }
767 782
@@ -775,9 +790,9 @@
775 790 * @return int
776 791 */
777 792 public function update_profile( $submitted = array(), $keys = array() ) {
778 793 if ( empty( $submitted ) ) {
779 - $submitted = $_POST;
794 + $submitted = $_POST; // phpcs:ignore
780 795 }
781 796
782 797 if ( empty( $keys ) ) {
783 798 $keys = array_keys( $submitted );
@@ -825,9 +840,9 @@
825 840
826 841 foreach ( $donor_fields as $field ) {
827 842 if ( array_key_exists( $field, $submitted ) ) {
828 843 $value = $submitted[ $field ];
829 - } elseif ( 'contact_consent' == $field ) {
844 + } elseif ( 'contact_consent' === $field ) {
830 845 $value = 0;
831 846 } else {
832 847 $value = '';
833 848 }
@@ -840,10 +855,21 @@
840 855 } else {
841 856 $donor_id = $this->get_donor_id();
842 857 }
843 858
844 - /* Clear out the cache */
845 - wp_cache_delete( $donor_id, 'donors' );
859 + /*
860 + * Clear out the cache.
861 + *
862 + * Only when there is actually an ID. get_donor_id() returns false for a donor who does not
863 + * exist yet, which is the normal path into the insert() below - and the `if ( $donor_id )`
864 + * immediately after this already accounts for that. Passing false as a cache key trips
865 + * WP 6.1+'s "Cache key must be an integer or a non-empty string" _doing_it_wrong notice on
866 + * every new-donor save. Deleting the key false was a no-op regardless, so guarding it
867 + * changes no behaviour.
868 + */
869 + if ( $donor_id ) {
870 + wp_cache_delete( $donor_id, 'donors' );
871 + }
846 872
847 873 if ( $donor_id ) {
848 874 charitable_get_table( 'donors' )->update( $donor_id, $donor_data );
849 875
@@ -877,8 +903,10 @@
877 903 $values['ID'] = $this->ID;
878 904 }
879 905
880 906 foreach ( $core_fields as $field ) {
907 + if ( $field === 'role' ) {
908 + continue; }
881 909 $values[ $field ] = $submitted[ $field ];
882 910 }
883 911
884 912 /* Set the user's display name based on their name. */
@@ -888,9 +916,9 @@
888 916 $values['display_name'] = $display_name;
889 917 }
890 918
891 919 /* Insert the user */
892 - if ( 0 == $this->ID ) {
920 + if ( 0 === $this->ID ) {
893 921
894 922 if ( ! isset( $values['user_pass'] ) || strlen( $values['user_pass'] ) == 0 ) {
895 923 charitable_get_notices()->add_error( '<strong>ERROR:</strong> Password field is required.' );
896 924 return false;
@@ -915,9 +943,9 @@
915 943 }
916 944
917 945 $this->init( self::get_data_by( 'id', $user_id ) );
918 946
919 - $signon = Charitable_User::signon( $values['user_login'], $values['user_pass'] );
947 + $signon = self::signon( $values['user_login'], $values['user_pass'] );
920 948
921 949 if ( is_wp_error( $signon ) ) {
922 950 charitable_get_notices()->add_errors_from_wp_error( $signon );
923 951 return false;
@@ -978,9 +1006,9 @@
978 1006 $meta_value = sanitize_meta( $meta_key, $submitted[ $field ], 'user' );
979 1007
980 1008 update_user_meta( $this->ID, $meta_key, $meta_value );
981 1009
982 - $updated++;
1010 + ++$updated;
983 1011 }
984 1012 }
985 1013
986 1014 return $updated;
@@ -1118,8 +1146,7 @@
1118 1146 'donor_country',
1119 1147 )
1120 1148 );
1121 1149 }
1122 -
1123 1150 }
1124 1151
1125 1152 endif;