| @@ -1,13 +1,14 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * Donor model. |
| 4 | 4 | * |
| 5 | - * @package Charitable/Classes/Charitable_Donor | |
| 6 | - * @version 1.0.0 | |
| 7 | - * @author Eric Daams | |
| 8 | - * @copyright Copyright (c) 2018, Studio 164a | |
| 9 | - * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License | |
| 5 | + * @package Charitable/Classes/Charitable_Donor | |
| 6 | + * @author David Bisset | |
| 7 | + * @copyright Copyright (c) 2023, WP Charitable LLC | |
| 8 | + * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License | |
| 9 | + * @since 1.0.0 | |
| 10 | + * @version 1.6.54 | |
| 10 | 11 | */ |
| 11 | 12 | |
| 12 | 13 | // Exit if accessed directly. |
| 13 | 14 | if ( ! defined( 'ABSPATH' ) ) { |
| @@ -20,9 +21,9 @@ | ||
| 20 | 21 | * Charitable_Donor |
| 21 | 22 | * |
| 22 | 23 | * @since 1.0.0 |
| 23 | 24 | * |
| 24 | - * @property int $user_id | |
| 25 | + * @property int $donor_id | |
| 25 | 26 | * @property string $first_name |
| 26 | 27 | * @property string $last_name |
| 27 | 28 | * @property string $email |
| 28 | 29 | * @property string $date_joined |
| @@ -85,8 +86,17 @@ | ||
| 85 | 86 | */ |
| 86 | 87 | protected $last_donation; |
| 87 | 88 | |
| 88 | 89 | /** |
| 90 | + * Whether the donor is anonymous. | |
| 91 | + * | |
| 92 | + * @since 1.8.3.1 | |
| 93 | + * | |
| 94 | + * @var boolean | |
| 95 | + */ | |
| 96 | + public $is_anonymous; | |
| 97 | + | |
| 98 | + /** | |
| 89 | 99 | * Donor meta. |
| 90 | 100 | * |
| 91 | 101 | * @since 1.4.0 |
| 92 | 102 | * |
| @@ -133,8 +143,12 @@ | ||
| 133 | 143 | if ( isset( $this->data->$key ) ) { |
| 134 | 144 | return $this->data->$key; |
| 135 | 145 | } |
| 136 | 146 | |
| 147 | + if ( method_exists( $this, 'get_' . $key ) ) { | |
| 148 | + return call_user_func( array( $this, 'get_' . $key ) ); | |
| 149 | + } | |
| 150 | + | |
| 137 | 151 | return $this->get_user()->$key; |
| 138 | 152 | } |
| 139 | 153 | |
| 140 | 154 | /** |
| @@ -201,8 +215,22 @@ | ||
| 201 | 215 | return $this->get_user()->get_donations(); |
| 202 | 216 | } |
| 203 | 217 | |
| 204 | 218 | /** |
| 219 | + * Return whether contact consent has been given. | |
| 220 | + * | |
| 221 | + * @since 1.6.54 | |
| 222 | + * | |
| 223 | + * @return boolean|null If contact consent has been explicitly given or | |
| 224 | + * not given, returns a boolean. If the donor has | |
| 225 | + * never been presented with the opt-in checkbox, | |
| 226 | + * this will return null. | |
| 227 | + */ | |
| 228 | + public function get_contact_consent() { | |
| 229 | + return $this->data->contact_consent; | |
| 230 | + } | |
| 231 | + | |
| 232 | + /** | |
| 205 | 233 | * Attach a user ID to the donor record. |
| 206 | 234 | * |
| 207 | 235 | * @since 1.5.0 |
| 208 | 236 | * |
| @@ -306,12 +334,14 @@ | ||
| 306 | 334 | * @return Charitable_Donation|null Null if no donation was found. A `Charitable_Donation` instance otherwise. |
| 307 | 335 | */ |
| 308 | 336 | public function get_last_donation() { |
| 309 | 337 | if ( ! isset( $this->last_donation ) ) { |
| 310 | - $donation = new Charitable_Donations_Query( array( | |
| 311 | - 'number' => 1, | |
| 312 | - 'donor_id' => $this->donor_id, | |
| 313 | - ) ); | |
| 338 | + $donation = new Charitable_Donations_Query( | |
| 339 | + array( | |
| 340 | + 'number' => 1, | |
| 341 | + 'donor_id' => $this->donor_id, | |
| 342 | + ) | |
| 343 | + ); | |
| 314 | 344 | |
| 315 | 345 | $this->last_donation = $donation->count() ? $donation->current() : null; |
| 316 | 346 | } |
| 317 | 347 | |
| @@ -325,9 +355,13 @@ | ||
| 325 | 355 | * |
| 326 | 356 | * @return string |
| 327 | 357 | */ |
| 328 | 358 | public function get_name() { |
| 329 | - $name = trim( sprintf( '%s %s', $this->get_donor_meta( 'first_name' ), $this->get_donor_meta( 'last_name' ) ) ); | |
| 359 | + $name = esc_html( | |
| 360 | + trim( | |
| 361 | + sprintf( '%s %s', $this->get_donor_meta( 'first_name' ), $this->get_donor_meta( 'last_name' ) ) | |
| 362 | + ) | |
| 363 | + ); | |
| 330 | 364 | |
| 331 | 365 | /** |
| 332 | 366 | * Filter the donor name. |
| 333 | 367 | * |
| @@ -381,8 +415,9 @@ | ||
| 381 | 415 | * as a square image, so this is used for both height and width. |
| 382 | 416 | * @return string |
| 383 | 417 | */ |
| 384 | 418 | public function get_avatar( $size = 100 ) { |
| 419 | + | |
| 385 | 420 | /** |
| 386 | 421 | * Filter the donor avatar. |
| 387 | 422 | * |
| 388 | 423 | * @since 1.2.0 |