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

230 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) 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_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( array(
92 'campaign' => new Charitable_Campaign( $campaign_id ),
93 ) );
94
95 /**
96 * Don't resend the email.
97 */
98 if ( $email->is_sent_already( $campaign_id ) ) {
99 return false;
100 }
101
102 /**
103 * Check whether the campaign expired in the last 24 hours.
104 */
105 if ( ! $email->is_time_to_send() ) {
106 return false;
107 }
108
109 $sent = $email->send();
110
111 /**
112 * Log that the email was sent.
113 */
114 if ( apply_filters( 'charitable_log_email_send', true, self::get_email_id(), $email ) ) {
115 $email->log( $campaign_id, $sent );
116 }
117
118 return true;
119 }
120
121 /**
122 * Returns whether it is time to send the email.
123 *
124 * This returns true if the campaign has expired in the last 24 hours.
125 *
126 * @since 1.3.2
127 *
128 * @return boolean
129 */
130 public function is_time_to_send() {
131 $time_since_ended = $this->get_campaign()->get_time_since_ended();
132 return $time_since_ended > 0 && $time_since_ended <= 86400;
133 }
134
135 /**
136 * Return the default recipient for the email.
137 *
138 * @since 1.1.0
139 *
140 * @return string
141 */
142 protected function get_default_recipient() {
143 return get_option( 'admin_email' );
144 }
145
146 /**
147 * Return the default subject line for the email.
148 *
149 * @since 1.1.0
150 *
151 * @return string
152 */
153 protected function get_default_subject() {
154 return __( 'A campaign has finished', 'charitable' );
155 }
156
157 /**
158 * Return the default headline for the email.
159 *
160 * @since 1.1.0
161 *
162 * @return string
163 */
164 protected function get_default_headline() {
165 /**
166 * Filter the default headline.
167 *
168 * @since 1.1.0
169 *
170 * @param string $body The headline.
171 * @param Charitable_Email_Campaign_End $email The email object.
172 */
173 return apply_filters( 'charitable_email_campaign_end_default_headline', __( 'Campaign has ended', 'charitable' ), $this );
174 }
175
176 /**
177 * Return the default body for the email.
178 *
179 * @since 1.1.0
180 *
181 * @return string
182 */
183 protected function get_default_body() {
184 ob_start();
185 ?>
186 <p>
187 <?php
188 sprintf(
189 /* translators: %1$s: campaign title; %2$s: campaign creator; %3$s: campaign end date */
190 __( '%1$s by %2$s finished on %3$s.', 'charitable' ),
191 '[charitable_email show=campaign_title]',
192 '[charitable_email show=campaign_creator]',
193 '[charitable_email show=campaign_end_date]'
194 );
195 ?>
196 </p>
197 <p>[charitable_email show=campaign_achieved_goal success="<?php _e( 'The campaign achieved its fundraising goal.', 'charitable' ); ?>" failure="<?php _e( 'The campaign did not reach its fundraising goal.', 'charitable' ); ?>"]</p>
198 <table>
199 <tbody>
200 <tr>
201 <th><?php _e( 'Amount raised', 'charitable' ); ?></th>
202 <td>[charitable_email show=campaign_donated_amount]</td>
203 </tr>
204 <tr>
205 <th><?php _e( 'Number of donors', 'charitable' ); ?></th>
206 <td>[charitable_email show=campaign_donor_count]</td>
207 </tr>
208 <tr>
209 <th><?php _e( 'Fundraising goal', 'charitable' ); ?></th>
210 <td>[charitable_email show=campaign_goal]</td>
211 </tr>
212 </tbody>
213 </table>
214 <?php
215 $body = ob_get_clean();
216
217 /**
218 * Filter the body content.
219 *
220 * @since 1.1.0
221 *
222 * @param string $body The body content.
223 * @param Charitable_Email_Campaign_End $email The email object.
224 */
225 return apply_filters( 'charitable_email_campaign_end_default_body', $body, $this );
226 }
227 }
228
229 endif;
230