| @@ -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,14 +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 | - public function get_avatar( $size = 100 ) { | |
| 532 | + public function get_avatar( $size = 100, $donor_id = false ) { | |
| 527 | 533 | /**If you use this filter, return an attachment ID. */ |
| 528 | - $avatar_attachment_id = apply_filters( 'charitable_user_avatar', false, $this ); | |
| 529 | 534 | |
| 535 | + $avatar_attachment_id = get_user_meta( $this->ID, 'avatar', true ); | |
| 536 | + | |
| 537 | + $avatar_attachment_id = apply_filters( 'charitable_user_avatar', $avatar_attachment_id, $this ); | |
| 538 | + | |
| 530 | 539 | /* If we don't have an attachment ID, display the gravatar. */ |
| 531 | 540 | if ( ! $avatar_attachment_id ) { |
| 532 | 541 | return get_avatar( $this->ID, $size ); |
| 533 | 542 | } |
| @@ -602,8 +611,9 @@ | ||
| 602 | 611 | /** |
| 603 | 612 | * Checks whether the user has any current campaigns (i.e. non-expired). |
| 604 | 613 | * |
| 605 | 614 | * @since 1.0.0 |
| 615 | + * @version 1.8.9.1 | |
| 606 | 616 | * |
| 607 | 617 | * @param array $args Query arguments. |
| 608 | 618 | * @return WP_Query |
| 609 | 619 | */ |
| @@ -613,9 +623,9 @@ | ||
| 613 | 623 | 'meta_query' => array( |
| 614 | 624 | 'relation' => 'OR', |
| 615 | 625 | array( |
| 616 | 626 | 'key' => '_campaign_end_date', |
| 617 | - 'value' => date( 'Y-m-d H:i:s' ), | |
| 627 | + 'value' => date( 'Y-m-d H:i:s' ), // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date | |
| 618 | 628 | 'compare' => '>=', |
| 619 | 629 | 'type' => 'datetime', |
| 620 | 630 | ), |
| 621 | 631 | array( |
| @@ -750,8 +760,9 @@ | ||
| 750 | 760 | /** |
| 751 | 761 | * Insert a new donor with submitted values. |
| 752 | 762 | * |
| 753 | 763 | * @since 1.4.0 |
| 764 | + * @version 1.8.1.15 | |
| 754 | 765 | * |
| 755 | 766 | * @param array $submitted The submitted values. |
| 756 | 767 | * @param array $keys The keys of fields that are to be updated. |
| 757 | 768 | * @return int |
| @@ -757,8 +768,15 @@ | ||
| 757 | 768 | * @return int |
| 758 | 769 | */ |
| 759 | 770 | public static function create_profile( $submitted = array(), $keys = array() ) { |
| 760 | 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 | + | |
| 761 | 779 | $user_id = $user->update_profile( $submitted, $keys ); |
| 762 | 780 | return new Charitable_User( $user_id ); |
| 763 | 781 | } |
| 764 | 782 | |
| @@ -772,9 +790,9 @@ | ||
| 772 | 790 | * @return int |
| 773 | 791 | */ |
| 774 | 792 | public function update_profile( $submitted = array(), $keys = array() ) { |
| 775 | 793 | if ( empty( $submitted ) ) { |
| 776 | - $submitted = $_POST; | |
| 794 | + $submitted = $_POST; // phpcs:ignore | |
| 777 | 795 | } |
| 778 | 796 | |
| 779 | 797 | if ( empty( $keys ) ) { |
| 780 | 798 | $keys = array_keys( $submitted ); |
| @@ -822,9 +840,9 @@ | ||
| 822 | 840 | |
| 823 | 841 | foreach ( $donor_fields as $field ) { |
| 824 | 842 | if ( array_key_exists( $field, $submitted ) ) { |
| 825 | 843 | $value = $submitted[ $field ]; |
| 826 | - } elseif ( 'contact_consent' == $field ) { | |
| 844 | + } elseif ( 'contact_consent' === $field ) { | |
| 827 | 845 | $value = 0; |
| 828 | 846 | } else { |
| 829 | 847 | $value = ''; |
| 830 | 848 | } |
| @@ -837,10 +855,21 @@ | ||
| 837 | 855 | } else { |
| 838 | 856 | $donor_id = $this->get_donor_id(); |
| 839 | 857 | } |
| 840 | 858 | |
| 841 | - /* Clear out the cache */ | |
| 842 | - 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 | + } | |
| 843 | 872 | |
| 844 | 873 | if ( $donor_id ) { |
| 845 | 874 | charitable_get_table( 'donors' )->update( $donor_id, $donor_data ); |
| 846 | 875 | |
| @@ -874,8 +903,10 @@ | ||
| 874 | 903 | $values['ID'] = $this->ID; |
| 875 | 904 | } |
| 876 | 905 | |
| 877 | 906 | foreach ( $core_fields as $field ) { |
| 907 | + if ( $field === 'role' ) { | |
| 908 | + continue; } | |
| 878 | 909 | $values[ $field ] = $submitted[ $field ]; |
| 879 | 910 | } |
| 880 | 911 | |
| 881 | 912 | /* Set the user's display name based on their name. */ |
| @@ -885,9 +916,9 @@ | ||
| 885 | 916 | $values['display_name'] = $display_name; |
| 886 | 917 | } |
| 887 | 918 | |
| 888 | 919 | /* Insert the user */ |
| 889 | - if ( 0 == $this->ID ) { | |
| 920 | + if ( 0 === $this->ID ) { | |
| 890 | 921 | |
| 891 | 922 | if ( ! isset( $values['user_pass'] ) || strlen( $values['user_pass'] ) == 0 ) { |
| 892 | 923 | charitable_get_notices()->add_error( '<strong>ERROR:</strong> Password field is required.' ); |
| 893 | 924 | return false; |
| @@ -912,9 +943,9 @@ | ||
| 912 | 943 | } |
| 913 | 944 | |
| 914 | 945 | $this->init( self::get_data_by( 'id', $user_id ) ); |
| 915 | 946 | |
| 916 | - $signon = Charitable_User::signon( $values['user_login'], $values['user_pass'] ); | |
| 947 | + $signon = self::signon( $values['user_login'], $values['user_pass'] ); | |
| 917 | 948 | |
| 918 | 949 | if ( is_wp_error( $signon ) ) { |
| 919 | 950 | charitable_get_notices()->add_errors_from_wp_error( $signon ); |
| 920 | 951 | return false; |
| @@ -975,9 +1006,9 @@ | ||
| 975 | 1006 | $meta_value = sanitize_meta( $meta_key, $submitted[ $field ], 'user' ); |
| 976 | 1007 | |
| 977 | 1008 | update_user_meta( $this->ID, $meta_key, $meta_value ); |
| 978 | 1009 | |
| 979 | - $updated++; | |
| 1010 | + ++$updated; | |
| 980 | 1011 | } |
| 981 | 1012 | } |
| 982 | 1013 | |
| 983 | 1014 | return $updated; |
| @@ -1115,8 +1146,7 @@ | ||
| 1115 | 1146 | 'donor_country', |
| 1116 | 1147 | ) |
| 1117 | 1148 | ); |
| 1118 | 1149 | } |
| 1119 | - | |
| 1120 | 1150 | } |
| 1121 | 1151 | |
| 1122 | 1152 | endif; |