Recently, we’ve noticed that there are multiple functions to handle the donor deletion process. This can lead to developer confusion as to which is the correct method to delete a donor. In Give
2.2.0 we have refactored the code to make the process for single and multiple donor deletions much more clear.
As a part of the improvement, we’ve created a new, unique, and singular method to handle the donor deletion process and delete its related donations.
Function and its parameters
give_delete_donor_and_related_donation( $donor, $args );
$donor (int/object)– You can pass a Donor ID or a Donor object (an instance of Give_Donor)
$args (array)– Currently, we can only pass
delete_donationas an argument which must be a boolean value. Defaults to
false. There likely will be additional arguments added in the future as needed.
While using the function,
give_delete_donor_and_related_donation you’ll be able to get three different return values:
0– Incorrect Donor ID or Donor doesn’t exist.
1– The donor is deleted but not the related donations.
2– Both the donor and their related donations are deleted.
How to use?
There are two different ways you can use the function to delete donor and its related donations:
Delete Donor only
give_delete_donor_and_related_donation( $donor );
Delete Donor as well as their related donations
give_delete_donor_and_related_donation( $donor, array( 'delete_donation' => true ) );
Let us know in the comments if you’ve any questions related to the functionality of this new function.