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-campaign-end.php

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

232 lines 5.4 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 campaign end email.
4 *
5 * @version 1.1.0
6 * @package Charitable/Classes/Charitable_Email_Campaign_End
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_Campaign_End' ) ) :
17
18 /**
19 * Campaign End Email
20 *
21 * @since 1.1.0
22 */
23 class Charitable_Email_Campaign_End extends Charitable_Email {
24
25 /** Email ID */
26 const ID = 'campaign_end';
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 * Array of supported object types (campaigns, donations, donors, etc).
39 *
40 * @since 1.1.0
41 *
42 * @var string[]
43 */
44 protected $object_types = array( 'campaign' );
45
46 /**
47 * Instantiate the email class, defining its key values.
48 *
49 * @since 1.1.0
50 *
51 * @param mixed[] $objects Set of objects, including an instance of `Charitable_Campaign`.
52 */
53 public function __construct( $objects = array() ) {
54 parent::__construct( $objects );
55
56 /**
57 * Filter the email name.
58 *
59 * @since 1.1.0
60 *
61 * @param string $body The headline.
62 * @param Charitable_Email_Campaign_End $email The email object.
63 */
64 $this->name = apply_filters( 'charitable_email_campaign_end_name', __( 'Admin: Campaign Ended Notification', 'charitable' ) );
65 }
66
67 /**
68 * Returns the current email's ID.
69 *
70 * @since 1.1.0
71 *
72 * @return string
73 */
74 public static function get_email_id() {
75 return self::ID;
76 }
77
78 /**
79 * Static method that is fired within 24 hours after a campaign is finished.
80 *
81 * @since 1.1.0
82 *
83 * @param int $campaign_id The campaign we're sending an email for.
84 * @return boolean
85 */
86 public static function send_with_campaign_id( $campaign_id ) {
87 if ( ! charitable_get_helper( 'emails' )->is_enabled_email( self::get_email_id() ) ) {
88 return false;
89 }
90
91 $email = new Charitable_Email_Campaign_End(
92 array(
93 'campaign' => new Charitable_Campaign( $campaign_id ),
94 )
95 );
96
97 /**
98 * Don't resend the email.
99 */
100 if ( $email->is_sent_already( $campaign_id ) ) {
101 return false;
102 }
103
104 /**
105 * Check whether the campaign expired in the last 24 hours.
106 */
107 if ( ! $email->is_time_to_send() ) {
108 return false;
109 }
110
111 $sent = $email->send();
112
113 /**
114 * Log that the email was sent.
115 */
116 if ( apply_filters( 'charitable_log_email_send', true, self::get_email_id(), $email ) ) {
117 $email->log( $campaign_id, $sent );
118 }
119
120 return true;
121 }
122
123 /**
124 * Returns whether it is time to send the email.
125 *
126 * This returns true if the campaign has expired in the last 24 hours.
127 *
128 * @since 1.3.2
129 *
130 * @return boolean
131 */
132 public function is_time_to_send() {
133 $time_since_ended = $this->get_campaign()->get_time_since_ended();
134 return $time_since_ended > 0 && $time_since_ended <= 86400;
135 }
136
137 /**
138 * Return the default recipient for the email.
139 *
140 * @since 1.1.0
141 *
142 * @return string
143 */
144 protected function get_default_recipient() {
145 return get_option( 'admin_email' );
146 }
147
148 /**
149 * Return the default subject line for the email.
150 *
151 * @since 1.1.0
152 *
153 * @return string
154 */
155 protected function get_default_subject() {
156 return __( 'A campaign has finished', 'charitable' );
157 }
158
159 /**
160 * Return the default headline for the email.
161 *
162 * @since 1.1.0
163 *
164 * @return string
165 */
166 protected function get_default_headline() {
167 /**
168 * Filter the default headline.
169 *
170 * @since 1.1.0
171 *
172 * @param string $body The headline.
173 * @param Charitable_Email_Campaign_End $email The email object.
174 */
175 return apply_filters( 'charitable_email_campaign_end_default_headline', __( 'Campaign has ended', 'charitable' ), $this );
176 }
177
178 /**
179 * Return the default body for the email.
180 *
181 * @since 1.1.0
182 *
183 * @return string
184 */
185 protected function get_default_body() {
186 ob_start();
187 ?>
188 <p>
189 <?php
190 sprintf(
191 /* translators: %1$s: campaign title; %2$s: campaign creator; %3$s: campaign end date */
192 __( '%1$s by %2$s finished on %3$s.', 'charitable' ),
193 '[charitable_email show=campaign_title]',
194 '[charitable_email show=campaign_creator]',
195 '[charitable_email show=campaign_end_date]'
196 );
197 ?>
198 </p>
199 <p>[charitable_email show=campaign_achieved_goal success="<?php esc_html_e( 'The campaign achieved its fundraising goal.', 'charitable' ); ?>" failure="<?php esc_html_e( 'The campaign did not reach its fundraising goal.', 'charitable' ); ?>"]</p>
200 <table>
201 <tbody>
202 <tr>
203 <th><?php esc_html_e( 'Amount raised', 'charitable' ); ?></th>
204 <td>[charitable_email show=campaign_donated_amount]</td>
205 </tr>
206 <tr>
207 <th><?php esc_html_e( 'Number of donors', 'charitable' ); ?></th>
208 <td>[charitable_email show=campaign_donor_count]</td>
209 </tr>
210 <tr>
211 <th><?php esc_html_e( 'Fundraising goal', 'charitable' ); ?></th>
212 <td>[charitable_email show=campaign_goal]</td>
213 </tr>
214 </tbody>
215 </table>
216 <?php
217 $body = ob_get_clean();
218
219 /**
220 * Filter the body content.
221 *
222 * @since 1.1.0
223 *
224 * @param string $body The body content.
225 * @param Charitable_Email_Campaign_End $email The email object.
226 */
227 return apply_filters( 'charitable_email_campaign_end_default_body', $body, $this );
228 }
229 }
230
231 endif;
232