Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Give_Donor often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Give_Donor, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 24 | class Give_Donor { |
||
| 25 | |||
| 26 | /** |
||
| 27 | * The donor ID |
||
| 28 | * |
||
| 29 | * @since 1.0 |
||
| 30 | * @access public |
||
| 31 | * |
||
| 32 | * @var int |
||
| 33 | */ |
||
| 34 | public $id = 0; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * The donor's donation count. |
||
| 38 | * |
||
| 39 | * @since 1.0 |
||
| 40 | * @access public |
||
| 41 | * |
||
| 42 | * @var int |
||
| 43 | */ |
||
| 44 | public $purchase_count = 0; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * The donor's lifetime value. |
||
| 48 | * |
||
| 49 | * @since 1.0 |
||
| 50 | * @access public |
||
| 51 | * |
||
| 52 | * @var int |
||
| 53 | */ |
||
| 54 | public $purchase_value = 0; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * The donor's email. |
||
| 58 | * |
||
| 59 | * @since 1.0 |
||
| 60 | * @access public |
||
| 61 | * |
||
| 62 | * @var string |
||
| 63 | */ |
||
| 64 | public $email; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * The donor's emails. |
||
| 68 | * |
||
| 69 | * @since 1.7 |
||
| 70 | * @access public |
||
| 71 | * |
||
| 72 | * @var array |
||
| 73 | */ |
||
| 74 | public $emails; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * The donor's name. |
||
| 78 | * |
||
| 79 | * @since 1.0 |
||
| 80 | * @access public |
||
| 81 | * |
||
| 82 | * @var string |
||
| 83 | */ |
||
| 84 | public $name; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * The donor creation date. |
||
| 88 | * |
||
| 89 | * @since 1.0 |
||
| 90 | * @access public |
||
| 91 | * |
||
| 92 | * @var string |
||
| 93 | */ |
||
| 94 | public $date_created; |
||
| 95 | |||
| 96 | /** |
||
| 97 | * The payment IDs associated with the donor. |
||
| 98 | * |
||
| 99 | * @since 1.0 |
||
| 100 | * @access public |
||
| 101 | * |
||
| 102 | * @var string |
||
| 103 | */ |
||
| 104 | public $payment_ids; |
||
| 105 | |||
| 106 | /** |
||
| 107 | * The user ID associated with the donor. |
||
| 108 | * |
||
| 109 | * @since 1.0 |
||
| 110 | * @access public |
||
| 111 | * |
||
| 112 | * @var int |
||
| 113 | */ |
||
| 114 | public $user_id; |
||
| 115 | |||
| 116 | /** |
||
| 117 | * Donor notes saved by admins. |
||
| 118 | * |
||
| 119 | * @since 1.0 |
||
| 120 | * @access public |
||
| 121 | * |
||
| 122 | * @var string |
||
| 123 | */ |
||
| 124 | public $notes; |
||
| 125 | |||
| 126 | /** |
||
| 127 | * The Database Abstraction |
||
| 128 | * |
||
| 129 | * @since 1.0 |
||
| 130 | * @access protected |
||
| 131 | * |
||
| 132 | * @var Give_DB_Donors |
||
| 133 | */ |
||
| 134 | protected $db; |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Give_Donor constructor. |
||
| 138 | * |
||
| 139 | * @param bool $_id_or_email |
||
| 140 | * @param bool $by_user_id |
||
| 141 | */ |
||
| 142 | public function __construct( $_id_or_email = false, $by_user_id = false ) { |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Setup Donor |
||
| 173 | * |
||
| 174 | * Set donor variables. |
||
| 175 | * |
||
| 176 | * @since 1.0 |
||
| 177 | * @access private |
||
| 178 | * |
||
| 179 | * @param object $donor The Donor Object. |
||
| 180 | * |
||
| 181 | * @return bool If the setup was successful or not. |
||
| 182 | */ |
||
| 183 | private function setup_donor( $donor ) { |
||
| 216 | |||
| 217 | /** |
||
| 218 | * Magic __get function to dispatch a call to retrieve a private property. |
||
| 219 | * |
||
| 220 | * @since 1.0 |
||
| 221 | * @access public |
||
| 222 | * @param $key |
||
| 223 | * |
||
| 224 | * @return mixed|\WP_Error |
||
| 225 | */ |
||
| 226 | View Code Duplication | public function __get( $key ) { |
|
| 227 | |||
| 228 | if ( method_exists( $this, 'get_' . $key ) ) { |
||
| 229 | |||
| 230 | return call_user_func( array( $this, 'get_' . $key ) ); |
||
| 231 | |||
| 232 | } else { |
||
| 233 | |||
| 234 | /* translators: %s: property key */ |
||
| 235 | return new WP_Error( 'give-donor-invalid-property', sprintf( esc_html__( 'Can\'t get property %s.', 'give' ), $key ) ); |
||
| 236 | |||
| 237 | } |
||
| 238 | |||
| 239 | } |
||
| 240 | |||
| 241 | /** |
||
| 242 | * Creates a donor. |
||
| 243 | * |
||
| 244 | * @since 1.0 |
||
| 245 | * @access public |
||
| 246 | * |
||
| 247 | * @param array $data Array of attributes for a donor. |
||
| 248 | * |
||
| 249 | * @return bool|int False if not a valid creation, donor ID if user is found or valid creation. |
||
| 250 | */ |
||
| 251 | public function create( $data = array() ) { |
||
| 252 | |||
| 253 | if ( $this->id != 0 || empty( $data ) ) { |
||
| 254 | return false; |
||
| 255 | } |
||
| 256 | |||
| 257 | $defaults = array( |
||
| 258 | 'payment_ids' => '', |
||
| 259 | ); |
||
| 260 | |||
| 261 | $args = wp_parse_args( $data, $defaults ); |
||
| 262 | $args = $this->sanitize_columns( $args ); |
||
| 263 | |||
| 264 | if ( empty( $args['email'] ) || ! is_email( $args['email'] ) ) { |
||
| 265 | return false; |
||
| 266 | } |
||
| 267 | |||
| 268 | View Code Duplication | if ( ! empty( $args['payment_ids'] ) && is_array( $args['payment_ids'] ) ) { |
|
| 269 | $args['payment_ids'] = implode( ',', array_unique( array_values( $args['payment_ids'] ) ) ); |
||
| 270 | } |
||
| 271 | |||
| 272 | /** |
||
| 273 | * Fires before creating donors. |
||
| 274 | * |
||
| 275 | * @since 1.0 |
||
| 276 | * |
||
| 277 | * @param array $args Donor attributes. |
||
| 278 | */ |
||
| 279 | do_action( 'give_donor_pre_create', $args ); |
||
| 280 | |||
| 281 | $created = false; |
||
| 282 | |||
| 283 | // The DB class 'add' implies an update if the donor being asked to be created already exists |
||
| 284 | View Code Duplication | if ( $this->db->add( $data ) ) { |
|
| 285 | |||
| 286 | // We've successfully added/updated the donor, reset the class vars with the new data |
||
| 287 | $donor = $this->db->get_donor_by( 'email', $args['email'] ); |
||
| 288 | |||
| 289 | // Setup the donor data with the values from DB |
||
| 290 | $this->setup_donor( $donor ); |
||
| 291 | |||
| 292 | $created = $this->id; |
||
| 293 | } |
||
| 294 | |||
| 295 | /** |
||
| 296 | * Fires after creating donors. |
||
| 297 | * |
||
| 298 | * @since 1.0 |
||
| 299 | * |
||
| 300 | * @param bool|int $created False if not a valid creation, donor ID if user is found or valid creation. |
||
| 301 | * @param array $args Customer attributes. |
||
| 302 | */ |
||
| 303 | do_action( 'give_donor_post_create', $created, $args ); |
||
| 304 | |||
| 305 | return $created; |
||
| 306 | |||
| 307 | } |
||
| 308 | |||
| 309 | /** |
||
| 310 | * Updates a donor record. |
||
| 311 | * |
||
| 312 | * @since 1.0 |
||
| 313 | * @access public |
||
| 314 | * |
||
| 315 | * @param array $data Array of data attributes for a donor (checked via whitelist). |
||
| 316 | * |
||
| 317 | * @return bool If the update was successful or not. |
||
| 318 | */ |
||
| 319 | public function update( $data = array() ) { |
||
| 320 | |||
| 321 | if ( empty( $data ) ) { |
||
| 322 | return false; |
||
| 323 | } |
||
| 324 | |||
| 325 | $data = $this->sanitize_columns( $data ); |
||
| 326 | |||
| 327 | /** |
||
| 328 | * Fires before updating donors. |
||
| 329 | * |
||
| 330 | * @since 1.0 |
||
| 331 | * |
||
| 332 | * @param int $donor_id Donor id. |
||
| 333 | * @param array $data Donor attributes. |
||
| 334 | */ |
||
| 335 | do_action( 'give_donor_pre_update', $this->id, $data ); |
||
| 336 | |||
| 337 | $updated = false; |
||
| 338 | |||
| 339 | View Code Duplication | if ( $this->db->update( $this->id, $data ) ) { |
|
| 340 | |||
| 341 | $donor = $this->db->get_donor_by( 'id', $this->id ); |
||
| 342 | $this->setup_donor( $donor ); |
||
| 343 | |||
| 344 | $updated = true; |
||
| 345 | } |
||
| 346 | |||
| 347 | /** |
||
| 348 | * Fires after updating donors. |
||
| 349 | * |
||
| 350 | * @since 1.0 |
||
| 351 | * |
||
| 352 | * @param bool $updated If the update was successful or not. |
||
| 353 | * @param int $donor_id Donor id. |
||
| 354 | * @param array $data Donor attributes. |
||
| 355 | */ |
||
| 356 | do_action( 'give_donor_post_update', $updated, $this->id, $data ); |
||
| 357 | |||
| 358 | return $updated; |
||
| 359 | } |
||
| 360 | |||
| 361 | /** |
||
| 362 | * Attach Payment |
||
| 363 | * |
||
| 364 | * Attach payment to the donor then triggers increasing stats. |
||
| 365 | * |
||
| 366 | * @since 1.0 |
||
| 367 | * @access public |
||
| 368 | * |
||
| 369 | * @param int $payment_id The payment ID to attach to the donor. |
||
| 370 | * @param bool $update_stats For backwards compatibility, if we should increase the stats or not. |
||
| 371 | * |
||
| 372 | * @return bool If the attachment was successfully. |
||
| 373 | */ |
||
| 374 | public function attach_payment( $payment_id = 0, $update_stats = true ) { |
||
| 375 | |||
| 376 | if ( empty( $payment_id ) ) { |
||
| 377 | return false; |
||
| 378 | } |
||
| 379 | |||
| 380 | if ( empty( $this->payment_ids ) ) { |
||
| 381 | |||
| 382 | $new_payment_ids = $payment_id; |
||
| 383 | |||
| 384 | } else { |
||
| 385 | |||
| 386 | $payment_ids = array_map( 'absint', explode( ',', $this->payment_ids ) ); |
||
| 387 | |||
| 388 | if ( in_array( $payment_id, $payment_ids ) ) { |
||
| 389 | $update_stats = false; |
||
| 390 | } |
||
| 391 | |||
| 392 | $payment_ids[] = $payment_id; |
||
| 393 | |||
| 394 | $new_payment_ids = implode( ',', array_unique( array_values( $payment_ids ) ) ); |
||
| 395 | |||
| 396 | } |
||
| 397 | |||
| 398 | /** |
||
| 399 | * Fires before attaching payments to customers. |
||
| 400 | * |
||
| 401 | * @since 1.0 |
||
| 402 | * |
||
| 403 | * @param int $payment_id Payment id. |
||
| 404 | * @param int $donor_id Customer id. |
||
| 405 | */ |
||
| 406 | do_action( 'give_donor_pre_attach_payment', $payment_id, $this->id ); |
||
| 407 | |||
| 408 | $payment_added = $this->update( array( 'payment_ids' => $new_payment_ids ) ); |
||
| 409 | |||
| 410 | View Code Duplication | if ( $payment_added ) { |
|
| 411 | |||
| 412 | $this->payment_ids = $new_payment_ids; |
||
| 413 | |||
| 414 | // We added this payment successfully, increment the stats |
||
| 415 | if ( $update_stats ) { |
||
| 416 | $payment_amount = give_get_payment_amount( $payment_id ); |
||
| 417 | |||
| 418 | if ( ! empty( $payment_amount ) ) { |
||
| 419 | $this->increase_value( $payment_amount ); |
||
| 420 | } |
||
| 421 | |||
| 422 | $this->increase_purchase_count(); |
||
| 423 | } |
||
| 424 | } |
||
| 425 | |||
| 426 | /** |
||
| 427 | * Fires after attaching payments to the donor. |
||
| 428 | * |
||
| 429 | * @since 1.0 |
||
| 430 | * |
||
| 431 | * @param bool $payment_added If the attachment was successfully. |
||
| 432 | * @param int $payment_id Payment id. |
||
| 433 | * @param int $donor_id Donor id. |
||
| 434 | */ |
||
| 435 | do_action( 'give_donor_post_attach_payment', $payment_added, $payment_id, $this->id ); |
||
| 436 | |||
| 437 | return $payment_added; |
||
| 438 | } |
||
| 439 | |||
| 440 | /** |
||
| 441 | * Remove Payment |
||
| 442 | * |
||
| 443 | * Remove a payment from this donor, then triggers reducing stats. |
||
| 444 | * |
||
| 445 | * @since 1.0 |
||
| 446 | * @access public |
||
| 447 | * |
||
| 448 | * @param int $payment_id The Payment ID to remove. |
||
| 449 | * @param bool $update_stats For backwards compatibility, if we should increase the stats or not. |
||
| 450 | * |
||
| 451 | * @return boolean If the removal was successful. |
||
| 452 | */ |
||
| 453 | public function remove_payment( $payment_id = 0, $update_stats = true ) { |
||
| 454 | |||
| 455 | if ( empty( $payment_id ) ) { |
||
| 456 | return false; |
||
| 457 | } |
||
| 458 | |||
| 459 | $payment = new Give_Payment( $payment_id ); |
||
| 460 | |||
| 461 | if ( 'publish' !== $payment->status && 'revoked' !== $payment->status ) { |
||
| 462 | $update_stats = false; |
||
| 463 | } |
||
| 464 | |||
| 465 | $new_payment_ids = ''; |
||
| 466 | |||
| 467 | if ( ! empty( $this->payment_ids ) ) { |
||
| 468 | |||
| 469 | $payment_ids = array_map( 'absint', explode( ',', $this->payment_ids ) ); |
||
| 470 | |||
| 471 | $pos = array_search( $payment_id, $payment_ids ); |
||
| 472 | if ( false === $pos ) { |
||
| 473 | return false; |
||
| 474 | } |
||
| 475 | |||
| 476 | unset( $payment_ids[ $pos ] ); |
||
| 477 | $payment_ids = array_filter( $payment_ids ); |
||
| 478 | |||
| 479 | $new_payment_ids = implode( ',', array_unique( array_values( $payment_ids ) ) ); |
||
| 480 | |||
| 481 | } |
||
| 482 | |||
| 483 | /** |
||
| 484 | * Fires before removing payments from customers. |
||
| 485 | * |
||
| 486 | * @since 1.0 |
||
| 487 | * |
||
| 488 | * @param int $payment_id Payment id. |
||
| 489 | * @param int $donor_id Customer id. |
||
| 490 | */ |
||
| 491 | do_action( 'give_donor_pre_remove_payment', $payment_id, $this->id ); |
||
| 492 | |||
| 493 | $payment_removed = $this->update( array( 'payment_ids' => $new_payment_ids ) ); |
||
| 494 | |||
| 495 | View Code Duplication | if ( $payment_removed ) { |
|
| 496 | |||
| 497 | $this->payment_ids = $new_payment_ids; |
||
| 498 | |||
| 499 | if ( $update_stats ) { |
||
| 500 | // We removed this payment successfully, decrement the stats |
||
| 501 | $payment_amount = give_get_payment_amount( $payment_id ); |
||
| 502 | |||
| 503 | if ( ! empty( $payment_amount ) ) { |
||
| 504 | $this->decrease_value( $payment_amount ); |
||
| 505 | } |
||
| 506 | |||
| 507 | $this->decrease_donation_count(); |
||
| 508 | } |
||
| 509 | } |
||
| 510 | |||
| 511 | /** |
||
| 512 | * Fires after removing payments from donors. |
||
| 513 | * |
||
| 514 | * @since 1.0 |
||
| 515 | * |
||
| 516 | * @param bool $payment_removed If the removal was successfully. |
||
| 517 | * @param int $payment_id Payment id. |
||
| 518 | * @param int $donor_id Donor id. |
||
| 519 | */ |
||
| 520 | do_action( 'give_donor_post_remove_payment', $payment_removed, $payment_id, $this->id ); |
||
| 521 | |||
| 522 | return $payment_removed; |
||
| 523 | |||
| 524 | } |
||
| 525 | |||
| 526 | /** |
||
| 527 | * Increase the donation count of a donor. |
||
| 528 | * |
||
| 529 | * @since 1.0 |
||
| 530 | * @access public |
||
| 531 | * |
||
| 532 | * @param int $count The number to increase by. |
||
| 533 | * |
||
| 534 | * @return int The donation count. |
||
| 535 | */ |
||
| 536 | public function increase_purchase_count( $count = 1 ) { |
||
| 572 | |||
| 573 | /** |
||
| 574 | * Decrease the donor donation count. |
||
| 575 | * |
||
| 576 | * @since 1.0 |
||
| 577 | * @access public |
||
| 578 | * |
||
| 579 | * @param int $count The amount to decrease by. |
||
| 580 | * |
||
| 581 | * @return mixed If successful, the new count, otherwise false. |
||
| 582 | */ |
||
| 583 | public function decrease_donation_count( $count = 1 ) { |
||
| 623 | |||
| 624 | /** |
||
| 625 | * Increase the donor's lifetime value. |
||
| 626 | * |
||
| 627 | * @since 1.0 |
||
| 628 | * @access public |
||
| 629 | * |
||
| 630 | * @param float $value The value to increase by. |
||
| 631 | * |
||
| 632 | * @return mixed If successful, the new value, otherwise false. |
||
| 633 | */ |
||
| 634 | public function increase_value( $value = 0.00 ) { |
||
| 665 | |||
| 666 | /** |
||
| 667 | * Decrease a donor's lifetime value. |
||
| 668 | * |
||
| 669 | * @since 1.0 |
||
| 670 | * @access public |
||
| 671 | * |
||
| 672 | * @param float $value The value to decrease by. |
||
| 673 | * |
||
| 674 | * @return mixed If successful, the new value, otherwise false. |
||
| 675 | */ |
||
| 676 | public function decrease_value( $value = 0.00 ) { |
||
| 711 | |||
| 712 | /** |
||
| 713 | * Decrease/Increase a donor's lifetime value. |
||
| 714 | * |
||
| 715 | * This function will update donation stat on basis of current amount and new amount donation difference. |
||
| 716 | * Difference value can positive or negative. Negative value will decrease user donation stat while positive value increase donation stat. |
||
| 717 | * |
||
| 718 | * @since 1.0 |
||
| 719 | * @access public |
||
| 720 | * |
||
| 721 | * @param float $curr_amount Current Donation amount. |
||
| 722 | * @param float $new_amount New (changed) Donation amount. |
||
| 723 | * |
||
| 724 | * @return mixed If successful, the new donation stat value, otherwise false. |
||
| 725 | */ |
||
| 726 | public function update_donation_value( $curr_amount, $new_amount ) { |
||
| 749 | |||
| 750 | /** |
||
| 751 | * Get the parsed notes for a donor as an array. |
||
| 752 | * |
||
| 753 | * @since 1.0 |
||
| 754 | * @access public |
||
| 755 | * |
||
| 756 | * @param int $length The number of notes to get. |
||
| 757 | * @param int $paged What note to start at. |
||
| 758 | * |
||
| 759 | * @return array The notes requested. |
||
| 760 | */ |
||
| 761 | public function get_notes( $length = 20, $paged = 1 ) { |
||
| 774 | |||
| 775 | /** |
||
| 776 | * Get the total number of notes we have after parsing. |
||
| 777 | * |
||
| 778 | * @since 1.0 |
||
| 779 | * @access public |
||
| 780 | * |
||
| 781 | * @return int The number of notes for the donor. |
||
| 782 | */ |
||
| 783 | public function get_notes_count() { |
||
| 791 | |||
| 792 | /** |
||
| 793 | * Add a note for the donor. |
||
| 794 | * |
||
| 795 | * @since 1.0 |
||
| 796 | * @access public |
||
| 797 | * |
||
| 798 | * @param string $note The note to add. Default is empty. |
||
| 799 | * |
||
| 800 | * @return string|boolean The new note if added successfully, false otherwise. |
||
| 801 | */ |
||
| 802 | public function add_note( $note = '' ) { |
||
| 850 | |||
| 851 | /** |
||
| 852 | * Get the notes column for the donor |
||
| 853 | * |
||
| 854 | * @since 1.0 |
||
| 855 | * @access private |
||
| 856 | * |
||
| 857 | * @return string The Notes for the donor, non-parsed. |
||
| 858 | */ |
||
| 859 | private function get_raw_notes() { |
||
| 866 | |||
| 867 | /** |
||
| 868 | * Retrieve a meta field for a donor. |
||
| 869 | * |
||
| 870 | * @since 1.6 |
||
| 871 | * @access public |
||
| 872 | * |
||
| 873 | * @param string $meta_key The meta key to retrieve. Default is empty. |
||
| 874 | * @param bool $single Whether to return a single value. Default is true. |
||
| 875 | * |
||
| 876 | * @return mixed Will be an array if $single is false. Will be value of meta data field if $single is true. |
||
| 877 | */ |
||
| 878 | public function get_meta( $meta_key = '', $single = true ) { |
||
| 881 | |||
| 882 | /** |
||
| 883 | * Add a meta data field to a donor. |
||
| 884 | * |
||
| 885 | * @since 1.6 |
||
| 886 | * @access public |
||
| 887 | * |
||
| 888 | * @param string $meta_key Metadata name. Default is empty. |
||
| 889 | * @param mixed $meta_value Metadata value. |
||
| 890 | * @param bool $unique Optional. Whether the same key should not be added. Default is false. |
||
| 891 | * |
||
| 892 | * @return bool False for failure. True for success. |
||
| 893 | */ |
||
| 894 | public function add_meta( $meta_key = '', $meta_value, $unique = false ) { |
||
| 897 | |||
| 898 | /** |
||
| 899 | * Update a meta field based on donor ID. |
||
| 900 | * |
||
| 901 | * @since 1.6 |
||
| 902 | * @access public |
||
| 903 | * |
||
| 904 | * @param string $meta_key Metadata key. Default is empty. |
||
| 905 | * @param mixed $meta_value Metadata value. |
||
| 906 | * @param mixed $prev_value Optional. Previous value to check before removing. Default is empty. |
||
| 907 | * |
||
| 908 | * @return bool False on failure, true if success. |
||
| 909 | */ |
||
| 910 | public function update_meta( $meta_key = '', $meta_value, $prev_value = '' ) { |
||
| 913 | |||
| 914 | /** |
||
| 915 | * Remove metadata matching criteria from a donor. |
||
| 916 | * |
||
| 917 | * @since 1.6 |
||
| 918 | * @access public |
||
| 919 | * |
||
| 920 | * @param string $meta_key Metadata name. Default is empty. |
||
| 921 | * @param mixed $meta_value Optional. Metadata value. Default is empty. |
||
| 922 | * |
||
| 923 | * @return bool False for failure. True for success. |
||
| 924 | */ |
||
| 925 | public function delete_meta( $meta_key = '', $meta_value = '' ) { |
||
| 928 | |||
| 929 | /** |
||
| 930 | * Sanitize the data for update/create |
||
| 931 | * |
||
| 932 | * @since 1.0 |
||
| 933 | * @access private |
||
| 934 | * |
||
| 935 | * @param array $data The data to sanitize. |
||
| 936 | * |
||
| 937 | * @return array The sanitized data, based off column defaults. |
||
| 938 | */ |
||
| 939 | private function sanitize_columns( $data ) { |
||
| 991 | |||
| 992 | /** |
||
| 993 | * Attach an email to the donor |
||
| 994 | * |
||
| 995 | * @since 1.7 |
||
| 996 | * @access public |
||
| 997 | * |
||
| 998 | * @param string $email The email address to attach to the donor |
||
| 999 | * @param bool $primary Allows setting the email added as the primary |
||
| 1000 | * |
||
| 1001 | * @return bool If the email was added successfully |
||
| 1002 | */ |
||
| 1003 | public function add_email( $email = '', $primary = false ) { |
||
| 1034 | |||
| 1035 | /** |
||
| 1036 | * Remove an email from the donor. |
||
| 1037 | * |
||
| 1038 | * @since 1.7 |
||
| 1039 | * @access public |
||
| 1040 | * |
||
| 1041 | * @param string $email The email address to remove from the donor. |
||
| 1042 | * |
||
| 1043 | * @return bool If the email was removed successfully. |
||
| 1044 | */ |
||
| 1045 | public function remove_email( $email = '' ) { |
||
| 1058 | |||
| 1059 | /** |
||
| 1060 | * Set an email address as the donor's primary email. |
||
| 1061 | * |
||
| 1062 | * This will move the donor's previous primary email to an additional email. |
||
| 1063 | * |
||
| 1064 | * @since 1.7 |
||
| 1065 | * @access public |
||
| 1066 | * |
||
| 1067 | * @param string $new_primary_email The email address to remove from the donor. |
||
| 1068 | * |
||
| 1069 | * @return bool If the email was set as primary successfully. |
||
| 1070 | */ |
||
| 1071 | public function set_primary_email( $new_primary_email = '' ) { |
||
| 1106 | } |
||
| 1107 |