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

253 lines 5.9 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) 2022, 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( array(
146 'donation' => $donation,
147 ) );
148
149 $success = $email->send();
150
151 /**
152 * Log that the email was sent.
153 */
154 if ( apply_filters( 'charitable_log_email_send', true, self::get_email_id(), $email ) ) {
155 $email->log( $object_id, $success );
156 }
157
158 return $success;
159 }
160
161 /**
162 * Checks whether an email can be resent.
163 *
164 * @since 1.5.0
165 *
166 * @param int $object_id An object ID.
167 * @param array $args Mixed set of arguments.
168 * @return boolean
169 */
170 public static function can_be_resent( $object_id, $args = array() ) {
171 $resendable = charitable_is_approved_status( get_post_status( $object_id ) );
172
173 /**
174 * Filter whether the email can be resent.
175 *
176 * @since 1.6.0
177 *
178 * @param boolean $resendable Whether the email can be resent.
179 * @param int $object_id The donation ID.
180 * @param array $args Mixed set of arguments.
181 */
182 return apply_filters( 'charitable_can_resend_new_donation_email', $resendable, $object_id, $args );
183 }
184
185 /**
186 * Return the default recipient for the email.
187 *
188 * @since 1.0.0
189 *
190 * @return string
191 */
192 protected function get_default_recipient() {
193 return get_option( 'admin_email' );
194 }
195
196 /**
197 * Return the default subject line for the email.
198 *
199 * @since 1.0.0
200 *
201 * @return string
202 */
203 protected function get_default_subject() {
204 return __( 'You have received a new donation', 'charitable' );
205 }
206
207 /**
208 * Return the default headline for the email.
209 *
210 * @since 1.0.0
211 *
212 * @return string
213 */
214 protected function get_default_headline() {
215 /**
216 * Filter the default email headline.
217 *
218 * @since 1.0.0
219 *
220 * @param string $headline Default headline.
221 * @param Charitable_Email_New_Donation $email The email object.
222 */
223 return apply_filters( 'charitable_email_donation_receipt_default_headline', __( 'New Donation', 'charitable' ), $this );
224 }
225
226 /**
227 * Return the default body for the email.
228 *
229 * @since 1.0.0
230 *
231 * @return string
232 */
233 protected function get_default_body() {
234 ob_start();
235 ?>
236 <p><?php _e( '[charitable_email show=donor] has just made a donation!', 'charitable' ) ?></p>
237 <p><strong>Summary</strong><br />
238 [charitable_email show=donation_summary]</p>
239 <?php
240 /**
241 * Filter the default body content.
242 *
243 * @since 1.0.0
244 *
245 * @param string $body Default email body content.
246 * @param Charitable_Email_New_Donation $email The email object.
247 */
248 return apply_filters( 'charitable_email_new_donation_default_body', ob_get_clean(), $this );
249 }
250 }
251
252 endif;
253