PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.13
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.13
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-new-donation.php

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

281 lines 6.7 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 new donation email.
4 *
5 * @version 1.0.0
6 * @package Charitable/Classes/Charitable_Email_New_Donation
7 * @author David Bisset
8 * @copyright Copyright (c) 2023, WP Charitable LLC
9 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
10 */
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15
16 if ( ! class_exists( 'Charitable_Email_New_Donation' ) ) :
17
18 /**
19 * New Donation Email
20 *
21 * @since 1.0.0
22 */
23 class Charitable_Email_New_Donation extends Charitable_Email {
24
25 /** Email ID */
26 const ID = 'new_donation';
27
28 /**
29 * Whether the email allows you to define the email recipients.
30 *
31 * @since 1.1.0
32 *
33 * @var boolean
34 */
35 protected $has_recipient_field = true;
36
37 /**
38 * Object types supported by this email.
39 *
40 * @since 1.0.0
41 *
42 * @var string[] Array of supported object types (campaigns, donations, donors, etc).
43 */
44 protected $object_types = array( 'donation' );
45
46 /**
47 * Instantiate the email class, defining its key values.
48 *
49 * @since 1.0.0
50 *
51 * @param mixed[] $objects Array containing a Charitable_Donation object.
52 */
53 public function __construct( $objects = array() ) {
54 parent::__construct( $objects );
55
56 /**
57 * Customize the name of the donation notification.
58 *
59 * @since 1.0.0
60 *
61 * @param string $name
62 */
63 $this->name = apply_filters( 'charitable_email_new_donation_name', __( 'Admin: New Donation Notification', 'charitable' ) );
64 }
65
66 /**
67 * Returns the current email's ID.
68 *
69 * @since 1.0.3
70 *
71 * @return string
72 */
73 public static function get_email_id() {
74 return self::ID;
75 }
76
77 /**
78 * Static method that triggers the sending of this email. Sends the receipt with the donation is marked complete.
79 *
80 * @since 1.0.0
81 *
82 * @param int $donation_id The ID of the donation that we're sending an email about.
83 * @return boolean
84 */
85 public static function send_with_donation_id( $donation_id ) {
86 if ( ! charitable_get_helper( 'emails' )->is_enabled_email( self::get_email_id() ) ) {
87 return false;
88 }
89
90 if ( ! charitable_is_approved_status( get_post_status( $donation_id ) ) ) {
91 return false;
92 }
93
94 $donation = charitable_get_donation( $donation_id );
95
96 if ( ! is_object( $donation ) || 0 == count( $donation->get_campaign_donations() ) ) {
97 return false;
98 }
99
100 if ( ! apply_filters( 'charitable_send_' . self::get_email_id(), true, $donation ) ) {
101 return false;
102 }
103
104 $email = new self(
105 array(
106 'donation' => $donation,
107 )
108 );
109
110 /**
111 * Don't resend the email.
112 */
113 if ( $email->is_sent_already( $donation_id ) ) {
114 return false;
115 }
116
117 $sent = $email->send();
118
119 /**
120 * Log that the email was sent.
121 */
122 if ( apply_filters( 'charitable_log_email_send', true, self::get_email_id(), $email ) ) {
123 $email->log( $donation_id, $sent );
124 }
125
126 return $sent;
127 }
128
129 /**
130 * Resend the email.
131 *
132 * @since 1.5.0
133 *
134 * @param int $object_id An object ID.
135 * @param array $args Mixed set of arguments.
136 * @return boolean
137 */
138 public static function resend( $object_id, $args = array() ) {
139 $donation = charitable_get_donation( $object_id );
140
141 if ( ! is_object( $donation ) || 0 == count( $donation->get_campaign_donations() ) ) {
142 return false;
143 }
144
145 $email = new Charitable_Email_New_Donation(
146 array(
147 'donation' => $donation,
148 )
149 );
150
151 $success = $email->send();
152
153 /**
154 * Log that the email was sent.
155 */
156 if ( apply_filters( 'charitable_log_email_send', true, self::get_email_id(), $email ) ) {
157 $email->log( $object_id, $success );
158 }
159
160 return $success;
161 }
162
163 /**
164 * Checks whether an email can be resent.
165 *
166 * @since 1.5.0
167 *
168 * @param int $object_id An object ID.
169 * @param array $args Mixed set of arguments.
170 * @return boolean
171 */
172 public static function can_be_resent( $object_id, $args = array() ) {
173 $resendable = charitable_is_approved_status( get_post_status( $object_id ) );
174
175 /**
176 * Filter whether the email can be resent.
177 *
178 * @since 1.6.0
179 *
180 * @param boolean $resendable Whether the email can be resent.
181 * @param int $object_id The donation ID.
182 * @param array $args Mixed set of arguments.
183 */
184 return apply_filters( 'charitable_can_resend_new_donation_email', $resendable, $object_id, $args );
185 }
186
187 /**
188 * Return the default recipient for the email.
189 *
190 * @since 1.0.0
191 *
192 * @return string
193 */
194 protected function get_default_recipient() {
195 return get_option( 'admin_email' );
196 }
197
198 /**
199 * Return the default subject line for the email.
200 *
201 * @since 1.0.0
202 *
203 * @return string
204 */
205 protected function get_default_subject() {
206 return __( 'You have received a new donation', 'charitable' );
207 }
208
209 /**
210 * Return the default headline for the email.
211 *
212 * @since 1.0.0
213 *
214 * @return string
215 */
216 protected function get_default_headline() {
217 /**
218 * Filter the default email headline.
219 *
220 * @since 1.0.0
221 *
222 * @param string $headline Default headline.
223 * @param Charitable_Email_New_Donation $email The email object.
224 */
225 return apply_filters( 'charitable_email_donation_receipt_default_headline', __( 'New Donation', 'charitable' ), $this );
226 }
227
228 /**
229 * Return the default body for the email.
230 *
231 * @since 1.0.0
232 *
233 * @return string
234 */
235 protected function get_default_body() {
236 ob_start();
237 ?>
238 <p><?php esc_html_e( '[charitable_email show=donor] has just made a donation!', 'charitable' ); ?></p>
239 <p><strong>Summary</strong><br />
240 [charitable_email show=donation_summary]</p>
241 <?php
242 /**
243 * Filter the default body content.
244 *
245 * @since 1.0.0
246 *
247 * @param string $body Default email body content.
248 * @param Charitable_Email_New_Donation $email The email object.
249 */
250 return apply_filters( 'charitable_email_new_donation_default_body', ob_get_clean(), $this );
251 }
252
253 /**
254 * Get from address for email.
255 * For this particular email, we allow a reply-to address of the person who made the donation.
256 *
257 * @since 1.8.6
258 *
259 * @return string
260 */
261 public function get_from_address( $email_id = '' ) {
262
263 $email_settings = array();
264
265 if ( 'offline_donation_notification' === $email_id ) {
266 $email_settings = charitable_get_option( 'emails_offline_donation_notification' );
267 } elseif ( 'new_donation' === $email_id ) {
268 $email_settings = charitable_get_option( 'emails_new_donation' );
269 }
270
271 if ( '' !== $email_id && isset( $email_settings['reply_to_donor'] ) && $email_settings['reply_to_donor'] ) {
272 return $this->get_donation()->get_donor()->get_email();
273 }
274
275 return charitable_get_option( 'email_from_email', get_option( 'admin_email' ) );
276 }
277
278 }
279
280 endif;
281