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

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