PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.7.0.7
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.7.0.7
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
charitable / includes / emails / class-charitable-email-donation-receipt.php

class-charitable-email-donation-receipt.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.7.0.7, at includes/emails/class-charitable-email-donation-receipt.php

258 lines 6.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class that models the donation receipt email.
4 *
5 * @package Charitable/Classes/Charitable_Email_Donation_Receipt
6 * @author David Bisset
7 * @copyright Copyright (c) 2022, WP Charitable LLC
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 1.0.0
10 * @version 1.0.0
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 if ( ! class_exists( 'Charitable_Email_Donation_Receipt' ) ) :
18
19 /**
20 * Donation Receipt Email
21 *
22 * @since 1.0.0
23 */
24 class Charitable_Email_Donation_Receipt extends Charitable_Email {
25
26 /** Email ID */
27 const ID = 'donation_receipt';
28
29 /**
30 * Array of supported object types (campaigns, donations, donors, etc).
31 *
32 * @since 1.0.0
33 *
34 * @var string[]
35 */
36 protected $object_types = array( 'donation' );
37
38 /**
39 * Instantiate the email class, defining its key values.
40 *
41 * @since 1.0.0
42 *
43 * @param array $objects an array containing a donation object.
44 */
45 public function __construct( $objects = array() ) {
46 parent::__construct( $objects );
47
48 $this->name = apply_filters( 'charitable_email_donation_receipt_name', __( 'Donor: Donation Receipt', 'charitable' ) );
49 }
50
51 /**
52 * Returns the current email's ID.
53 *
54 * @since 1.0.3
55 *
56 * @return string
57 */
58 public static function get_email_id() {
59 return self::ID;
60 }
61
62 /**
63 * Static method that is fired right after a donation is completed, sending the donation receipt.
64 *
65 * @since 1.0.0
66 *
67 * @param int $donation_id The donation ID.
68 * @return boolean
69 */
70 public static function send_with_donation_id( $donation_id ) {
71 if ( ! charitable_get_helper( 'emails' )->is_enabled_email( self::get_email_id() ) ) {
72 return false;
73 }
74
75 if ( ! charitable_is_approved_status( get_post_status( $donation_id ) ) ) {
76 return false;
77 }
78
79 $donation = charitable_get_donation( $donation_id );
80
81 if ( ! is_object( $donation ) || 0 == count( $donation->get_campaign_donations() ) ) {
82 return false;
83 }
84
85 if ( ! $donation->has_valid_email() ) {
86 return false;
87 }
88
89 if ( ! apply_filters( 'charitable_send_' . self::get_email_id(), true, $donation ) ) {
90 return false;
91 }
92
93 $email = new self(
94 array(
95 'donation' => $donation,
96 )
97 );
98
99 /**
100 * Don't resend the email.
101 */
102 if ( $email->is_sent_already( $donation_id ) ) {
103 return false;
104 }
105
106 $sent = $email->send();
107
108 /**
109 * Log that the email was sent.
110 */
111 if ( apply_filters( 'charitable_log_email_send', true, self::get_email_id(), $email ) ) {
112 $email->log( $donation_id, $sent );
113 }
114
115 return $sent;
116 }
117
118 /**
119 * Resend an email.
120 *
121 * @since 1.5.0
122 *
123 * @param int $object_id An object ID.
124 * @param array $args Mixed set of arguments.
125 * @return boolean
126 */
127 public static function resend( $object_id, $args = array() ) {
128 $donation = charitable_get_donation( $object_id );
129
130 if ( ! is_object( $donation ) || 0 == count( $donation->get_campaign_donations() ) ) {
131 return false;
132 }
133
134 $email = new Charitable_Email_Donation_Receipt( array(
135 'donation' => $donation,
136 ) );
137
138 $success = $email->send();
139
140 /**
141 * Log that the email was sent.
142 */
143 if ( apply_filters( 'charitable_log_email_send', true, self::get_email_id(), $email ) ) {
144 $email->log( $object_id, $success );
145 }
146
147 return $success;
148 }
149
150 /**
151 * Checks whether an email can be resent.
152 *
153 * @since 1.5.0
154 *
155 * @param int $object_id An object ID.
156 * @param array $args Mixed set of arguments.
157 * @return boolean
158 */
159 public static function can_be_resent( $object_id, $args = array() ) {
160 $donation = charitable_get_donation( $object_id );
161 $resendable = is_object( $donation )
162 && $donation->has_valid_email()
163 && charitable_is_approved_status( $donation->get_status() );
164
165 /**
166 * Filter whether the email can be resent.
167 *
168 * @since 1.6.0
169 *
170 * @param boolean $resendable Whether the email can be resent.
171 * @param int $object_id The donation ID.
172 * @param array $args Mixed set of arguments.
173 */
174 return apply_filters( 'charitable_can_resend_donation_receipt_email', $resendable, $object_id, $args );
175 }
176
177 /**
178 * Return the recipient for the email.
179 *
180 * @since 1.0.0
181 *
182 * @return string
183 */
184 public function get_recipient() {
185 if ( ! is_a( $this->donation, 'Charitable_Donation' ) ) {
186 return '';
187 }
188
189 /**
190 * Deprecated hook. Use charitable_email_donation_receipt_recipient instead.
191 *
192 * @deprecated 1.9.0
193 *
194 * @since 1.0.0
195 * @since 1.6.0 Deprecated
196 *
197 * @param string $email_address Recipient email address.
198 * @param Charitable_Email_Donation_Receipt $email Instance of `Charitable_Email_Donation_Receipt`.
199 */
200 $email_address = apply_filters( 'charitable_email_donation_receipt_receipient', $this->donation->get_donor()->get_email(), $this );
201
202 /**
203 * Filter the recipient for the donation receipt email.
204 *
205 * @since 1.6.0
206 *
207 * @param string $email_address Recipient email address.
208 * @param Charitable_Email_Donation_Receipt $email Instance of `Charitable_Email_Donation_Receipt`.
209 */
210 return apply_filters( 'charitable_email_donation_receipt_recipient', $email_address, $this );
211 }
212
213 /**
214 * Return the default subject line for the email.
215 *
216 * @since 1.0.0
217 *
218 * @return string
219 */
220 protected function get_default_subject() {
221 return apply_filters( 'charitable_email_donation_receipt_default_subject', __( 'Thank you for your donation', 'charitable' ), $this );
222 }
223
224 /**
225 * Return the default headline for the email.
226 *
227 * @since 1.0.0
228 *
229 * @return string
230 */
231 protected function get_default_headline() {
232 return apply_filters( 'charitable_email_donation_receipt_default_headline', __( 'Your Donation Receipt', 'charitable' ), $this );
233 }
234
235 /**
236 * Return the default body for the email.
237 *
238 * @since 1.0.0
239 *
240 * @return string
241 */
242 protected function get_default_body() {
243 ob_start();
244 ?>
245 <p><?php _e( 'Dear [charitable_email show=donor_first_name],', 'charitable' ); ?></p>
246 <p><?php _e( 'Thank you so much for your generous donation.', 'charitable' ); ?></p>
247 <p><strong><?php _e( 'Your Receipt', 'charitable' ); ?></strong><br />
248 [charitable_email show=donation_summary]</p>
249 <p><?php _e( 'With thanks, [charitable_email show=site_name]', 'charitable' ); ?></p>
250 <?php
251 $body = ob_get_clean();
252
253 return apply_filters( 'charitable_email_donation_receipt_default_body', $body, $this );
254 }
255 }
256
257 endif;
258