PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.13
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.13
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 +43 -24 1.7.0.9 → 1.8.13 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,25 +525,18 @@
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. */
528 - // get_user_meta( $user_id, 'avatar', true )
534 +
529 535 $avatar_attachment_id = get_user_meta( $this->ID, 'avatar', true );
530 536
531 - // print_r( $this );
532 -
533 - // echo 'avatar_attachment_id: ' . $avatar_attachment_id; exit;
534 -
535 537 $avatar_attachment_id = apply_filters( 'charitable_user_avatar', $avatar_attachment_id, $this );
536 538
537 - // echo 'user id being passed in is ' . $donor_id . ' and the user id from this class is '.$this->ID.' and right now the attachment id is ' . $avatar_attachment_id;
538 -
539 - // echo '------';
540 -
541 539 /* If we don't have an attachment ID, display the gravatar. */
542 540 if ( ! $avatar_attachment_id ) {
543 541 return get_avatar( $this->ID, $size );
544 542 }
@@ -613,8 +611,9 @@
613 611 /**
614 612 * Checks whether the user has any current campaigns (i.e. non-expired).
615 613 *
616 614 * @since 1.0.0
615 + * @version 1.8.9.1
617 616 *
618 617 * @param array $args Query arguments.
619 618 * @return WP_Query
620 619 */
@@ -624,9 +623,9 @@
624 623 'meta_query' => array(
625 624 'relation' => 'OR',
626 625 array(
627 626 'key' => '_campaign_end_date',
628 - 'value' => date( 'Y-m-d H:i:s' ),
627 + 'value' => date( 'Y-m-d H:i:s' ), // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
629 628 'compare' => '>=',
630 629 'type' => 'datetime',
631 630 ),
632 631 array(
@@ -761,8 +760,9 @@
761 760 /**
762 761 * Insert a new donor with submitted values.
763 762 *
764 763 * @since 1.4.0
764 + * @version 1.8.1.15
765 765 *
766 766 * @param array $submitted The submitted values.
767 767 * @param array $keys The keys of fields that are to be updated.
768 768 * @return int
@@ -768,8 +768,15 @@
768 768 * @return int
769 769 */
770 770 public static function create_profile( $submitted = array(), $keys = array() ) {
771 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 +
772 779 $user_id = $user->update_profile( $submitted, $keys );
773 780 return new Charitable_User( $user_id );
774 781 }
775 782
@@ -783,9 +790,9 @@
783 790 * @return int
784 791 */
785 792 public function update_profile( $submitted = array(), $keys = array() ) {
786 793 if ( empty( $submitted ) ) {
787 - $submitted = $_POST;
794 + $submitted = $_POST; // phpcs:ignore
788 795 }
789 796
790 797 if ( empty( $keys ) ) {
791 798 $keys = array_keys( $submitted );
@@ -833,9 +840,9 @@
833 840
834 841 foreach ( $donor_fields as $field ) {
835 842 if ( array_key_exists( $field, $submitted ) ) {
836 843 $value = $submitted[ $field ];
837 - } elseif ( 'contact_consent' == $field ) {
844 + } elseif ( 'contact_consent' === $field ) {
838 845 $value = 0;
839 846 } else {
840 847 $value = '';
841 848 }
@@ -848,10 +855,21 @@
848 855 } else {
849 856 $donor_id = $this->get_donor_id();
850 857 }
851 858
852 - /* Clear out the cache */
853 - 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 + }
854 872
855 873 if ( $donor_id ) {
856 874 charitable_get_table( 'donors' )->update( $donor_id, $donor_data );
857 875
@@ -885,8 +903,10 @@
885 903 $values['ID'] = $this->ID;
886 904 }
887 905
888 906 foreach ( $core_fields as $field ) {
907 + if ( $field === 'role' ) {
908 + continue; }
889 909 $values[ $field ] = $submitted[ $field ];
890 910 }
891 911
892 912 /* Set the user's display name based on their name. */
@@ -896,9 +916,9 @@
896 916 $values['display_name'] = $display_name;
897 917 }
898 918
899 919 /* Insert the user */
900 - if ( 0 == $this->ID ) {
920 + if ( 0 === $this->ID ) {
901 921
902 922 if ( ! isset( $values['user_pass'] ) || strlen( $values['user_pass'] ) == 0 ) {
903 923 charitable_get_notices()->add_error( '<strong>ERROR:</strong> Password field is required.' );
904 924 return false;
@@ -923,9 +943,9 @@
923 943 }
924 944
925 945 $this->init( self::get_data_by( 'id', $user_id ) );
926 946
927 - $signon = Charitable_User::signon( $values['user_login'], $values['user_pass'] );
947 + $signon = self::signon( $values['user_login'], $values['user_pass'] );
928 948
929 949 if ( is_wp_error( $signon ) ) {
930 950 charitable_get_notices()->add_errors_from_wp_error( $signon );
931 951 return false;
@@ -986,9 +1006,9 @@
986 1006 $meta_value = sanitize_meta( $meta_key, $submitted[ $field ], 'user' );
987 1007
988 1008 update_user_meta( $this->ID, $meta_key, $meta_value );
989 1009
990 - $updated++;
1010 + ++$updated;
991 1011 }
992 1012 }
993 1013
994 1014 return $updated;
@@ -1126,8 +1146,7 @@
1126 1146 'donor_country',
1127 1147 )
1128 1148 );
1129 1149 }
1130 -
1131 1150 }
1132 1151
1133 1152 endif;