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-offline-donation-notification.php

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

236 lines 6.0 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 offline donation email.
4 *
5 * @version 1.5.0
6 * @package Charitable/Classes/Charitable_Email_Offline_Donation_Notification
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_Offline_Donation_Notification' ) && class_exists( 'Charitable_Email_New_Donation' ) ) {
17
18 /**
19 * New Offline Donation Email
20 *
21 * @since 1.5.0
22 */
23 class Charitable_Email_Offline_Donation_Notification extends Charitable_Email_New_Donation {
24
25 /** Email ID */
26 const ID = 'offline_donation_notification';
27
28 /**
29 * Array of supported object types (campaigns, donations, donors, etc).
30 *
31 * @var string[]
32 */
33 protected $object_types = array( 'donation' );
34
35 /**
36 * Create email object.
37 *
38 * @since 1.5.0
39 *
40 * @param mixed[] $objects Array of objects to pass to the email.
41 */
42 public function __construct( $objects = array() ) {
43 parent::__construct( $objects );
44
45 /**
46 * Customize the name of the offline donation notification.
47 *
48 * @since 1.5.0
49 *
50 * @param string $name
51 */
52 $this->name = apply_filters( 'charitable_email_offline_donation_notification_name', __( 'Admin: New Offline Donation Notification', 'charitable' ) );
53 }
54
55 /**
56 * Returns the current email's ID.
57 *
58 * @since 1.5.0
59 *
60 * @return string
61 */
62 public static function get_email_id() {
63 return self::ID;
64 }
65
66 /**
67 * Send the email.
68 *
69 * @since 1.5.0
70 *
71 * @param int $donation_id The donation ID we're sending an email about.
72 * @return boolean
73 */
74 public static function send_with_donation_id( $donation_id ) {
75 /* Verify that the email is enabled. */
76 if ( ! charitable_get_helper( 'emails' )->is_enabled_email( self::get_email_id() ) ) {
77 return false;
78 }
79
80 /* If the donation is not pending, stop here. */
81 if ( 'charitable-pending' != get_post_status( $donation_id ) ) {
82 return false;
83 }
84
85 /* If the donation was not made with the offline payment option, stop here. */
86 if ( 'offline' != get_post_meta( $donation_id, 'donation_gateway', true ) ) {
87 return false;
88 }
89
90 if ( ! apply_filters( 'charitable_send_' . self::get_email_id(), true, $donation_id ) ) {
91 return false;
92 }
93
94 /* All three of those checks passed, so proceed with sending the email. */
95 $email = new Charitable_Email_Offline_Donation_Notification(
96 array(
97 'donation' => new Charitable_Donation( $donation_id ),
98 )
99 );
100
101 /**
102 * Don't resend the email.
103 */
104 if ( $email->is_sent_already( $donation_id ) ) {
105 return false;
106 }
107
108 $sent = $email->send();
109
110 /**
111 * Log that the email was sent.
112 */
113 if ( apply_filters( 'charitable_log_email_send', true, self::get_email_id(), $email ) ) {
114 $email->log( $donation_id, $sent );
115 }
116
117 return true;
118 }
119
120 /**
121 * Resend the email.
122 *
123 * @since 1.5.0
124 *
125 * @param int $object_id An object ID.
126 * @param array $args Mixed set of arguments.
127 * @return boolean
128 */
129 public static function resend( $object_id, $args = array() ) {
130 $donation = charitable_get_donation( $object_id );
131
132 if ( ! is_object( $donation ) || 0 == count( $donation->get_campaign_donations() ) ) {
133 return false;
134 }
135
136 $email = new Charitable_Email_Offline_Donation_Notification(
137 array(
138 'donation' => $donation,
139 )
140 );
141
142 $success = $email->send();
143
144 /**
145 * Log that the email was sent.
146 */
147 if ( apply_filters( 'charitable_log_email_send', true, self::get_email_id(), $email ) ) {
148 $email->log( $object_id, $success );
149 }
150
151 return $success;
152 }
153
154 /**
155 * Checks whether an email can be resent.
156 *
157 * @since 1.5.0
158 *
159 * @param int $object_id An object ID.
160 * @param array $args Mixed set of arguments.
161 * @return boolean
162 */
163 public static function can_be_resent( $object_id, $args = array() ) {
164 $resendable = 'charitable-pending' == get_post_status( $object_id )
165 && 'offline' == get_post_meta( $object_id, 'donation_gateway', true );
166
167 /**
168 * Filter whether the email can be resent.
169 *
170 * @since 1.6.0
171 *
172 * @param boolean $resendable Whether the email can be resent.
173 * @param int $object_id The donation ID.
174 * @param array $args Mixed set of arguments.
175 */
176 return apply_filters( 'charitable_can_resend_offline_donation_notification_email', $resendable, $object_id, $args );
177 }
178
179
180 /**
181 * Return the default subject line for the email.
182 *
183 * @since 1.5.0
184 *
185 * @return string
186 */
187 protected function get_default_subject() {
188 return __( 'You have received a new offline donation', 'charitable' );
189 }
190
191 /**
192 * Return the default headline for the email.
193 *
194 * @since 1.5.0
195 *
196 * @return string
197 */
198 protected function get_default_headline() {
199 /**
200 * Filter the default headline.
201 *
202 * @since 1.5.0
203 *
204 * @param string $headline The default headline.
205 * @param Charitable_Email $email The Charitable_Email object.
206 */
207 return apply_filters( 'charitable_email_offline_donation_notification_default_headline', __( 'New Offline Donation', 'charitable' ), $this );
208 }
209
210 /**
211 * Return the default body for the email.
212 *
213 * @since 1.5.0
214 *
215 * @return string
216 */
217 protected function get_default_body() {
218 ob_start();
219 ?>
220 <p><?php esc_html_e( '[charitable_email show=donor] ([charitable_email show=donor_email]) has just made an offline donation!', 'charitable' ); ?></p>
221 <p><strong><?php esc_html_e( 'Summary', 'charitable' ); ?></strong></p>
222 <p>[charitable_email show=donation_summary]</p>
223 <?php
224 /**
225 * Filter the default body content.
226 *
227 * @since 1.5.0
228 *
229 * @param string $body The body content.
230 * @param Charitable_Email $email The Charitable_Email object.
231 */
232 return apply_filters( 'charitable_email_offline_donation_notification_default_body', ob_get_clean(), $this );
233 }
234 }
235 }
236