PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.0.7
GiveWP – Donation Plugin and Fundraising Platform v2.0.7
4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / admin / emails / class-email-notifications.php
give / includes / admin / emails Last commit date
abstract-email-notification.php 7 years ago ajax-handler.php 7 years ago backward-compatibility.php 7 years ago class-donation-receipt-email.php 7 years ago class-donor-register-email.php 7 years ago class-email-access-email.php 7 years ago class-email-notification-table.php 7 years ago class-email-notification-util.php 7 years ago class-email-notifications.php 7 years ago class-email-setting-field.php 7 years ago class-new-donation-email.php 7 years ago class-new-donor-register-email.php 7 years ago class-new-offline-donation-email.php 7 years ago class-offline-donation-instruction-email.php 7 years ago filters.php 7 years ago
class-email-notifications.php
448 lines
1 <?php
2 /**
3 * Email Notification
4 *
5 * This class handles all email notification settings.
6 *
7 * @package Give
8 * @subpackage Classes/Emails
9 * @copyright Copyright (c) 2016, WordImpress
10 * @license https://opensource.org/licenses/gpl-license GNU Public License
11 * @since 2.0
12 */
13
14 /**
15 * Class Give_Email_Notifications
16 */
17 class Give_Email_Notifications {
18 /**
19 * Instance.
20 *
21 * @since 2.0
22 * @access static
23 * @var
24 */
25 static private $instance;
26
27 /**
28 * Array of email notifications.
29 *
30 * @since 2.0
31 * @access private
32 * @var array
33 */
34 private $emails = array();
35
36 /**
37 * Singleton pattern.
38 *
39 * @since 2.0
40 * @access private
41 * Give_Payumoney_API constructor.
42 */
43 private function __construct() {
44 }
45
46
47 /**
48 * Get instance.
49 *
50 * @since 2.0
51 * @access static
52 * @return static
53 */
54 static function get_instance() {
55 if ( null === static::$instance ) {
56 self::$instance = new static();
57 }
58
59 return self::$instance;
60 }
61
62 /**
63 * Setup dependencies
64 *
65 * @since 2.0
66 */
67 public function init() {
68 // Load files.
69 require_once GIVE_PLUGIN_DIR . 'includes/admin/emails/ajax-handler.php';
70 require_once GIVE_PLUGIN_DIR . 'includes/admin/emails/class-email-setting-field.php';
71 require_once GIVE_PLUGIN_DIR . 'includes/admin/emails/filters.php';
72
73 // Load email notifications.
74 $this->add_emails_notifications();
75
76 add_filter( 'give_metabox_form_data_settings', array( $this, 'add_metabox_setting_fields' ), 10, 2 );
77 add_action( 'init', array( $this, 'preview_email' ) );
78 add_action( 'init', array( $this, 'send_preview_email' ) );
79 add_action( 'init', array( $this, 'validate_settings' ) );
80
81 /* @var Give_Email_Notification $email */
82 foreach ( $this->get_email_notifications() as $email ) {
83 // Setup email section.
84 if( Give_Email_Notification_Util::is_show_on_emails_setting_page( $email ) ) {
85 add_filter( 'give_get_sections_emails', array( $email, 'add_section' ) );
86 add_filter( "give_hide_section_{$email->config['id']}_on_emails_page", array( $email, 'hide_section' ) );
87 }
88
89 // Setup email preview.
90 if ( Give_Email_Notification_Util::is_email_preview_has_header( $email ) ) {
91 add_action( "give_{$email->config['id']}_email_preview", array( $this, 'email_preview_header' ) );
92 add_filter( "give_{$email->config['id']}_email_preview_data", array( $this, 'email_preview_data' ) );
93 add_filter( "give_{$email->config['id']}_email_preview_message", array( $this, 'email_preview_message' ), 1, 2 );
94 }
95 }
96 }
97
98
99 /**
100 * Add setting to metabox.
101 *
102 * @since 2.0
103 * @access public
104 *
105 * @param array $settings
106 * @param int $post_id
107 *
108 * @return array
109 */
110 public function add_metabox_setting_fields( $settings, $post_id ) {
111 $emails = $this->get_email_notifications();
112
113 // Bailout.
114 if ( empty( $emails ) ) {
115 return $settings;
116 }
117
118 // Email notification setting.
119 $settings['email_notification_options'] = array(
120 'id' => 'email_notification_options',
121 'title' => __( 'Email Notifications', 'give' ),
122 'icon-html' => '<span class="dashicons dashicons-email-alt"></span>',
123 'fields' => array(
124 array(
125 'name' => __( 'Email Options', 'give' ),
126 'description' => __( '', 'give' ),
127 'id' => '_give_email_options',
128 'type' => 'radio_inline',
129 'default' => 'global',
130 'options' => array(
131 'global' => __( 'Global Options' ),
132 'enabled' => __( 'Customize', 'give' ),
133 ),
134 ),
135 array(
136 'id' => '_give_email_template',
137 'name' => esc_html__( 'Email Template', 'give' ),
138 'desc' => esc_html__( 'Choose your template from the available registered template types.', 'give' ),
139 'type' => 'select',
140 'default' => 'default',
141 'options' => give_get_email_templates(),
142 ),
143 array(
144 'id' => '_give_email_logo',
145 'name' => esc_html__( 'Logo', 'give' ),
146 'desc' => esc_html__( 'Upload or choose a logo to be displayed at the top of the donation receipt emails. Displayed on HTML emails only.', 'give' ),
147 'type' => 'file',
148 ),
149 array(
150 'id' => '_give_from_name',
151 'name' => esc_html__( 'From Name', 'give' ),
152 'desc' => esc_html__( 'The name which appears in the "From" field in all Give donation emails.', 'give' ),
153 'default' => get_bloginfo( 'name' ),
154 'type' => 'text',
155 ),
156 array(
157 'id' => '_give_from_email',
158 'name' => esc_html__( 'From Email', 'give' ),
159 'desc' => esc_html__( 'Email address from which all Give emails are sent from. This will act as the "from" and "reply-to" email address.', 'give' ),
160 'default' => get_bloginfo( 'admin_email' ),
161 'type' => 'text',
162 ),
163 array(
164 'name' => 'email_notification_docs',
165 'type' => 'docs_link',
166 'url' => 'http://docs.givewp.com/email-notification',
167 'title' => __( 'Email Notification', 'give' ),
168 ),
169 ),
170
171 /**
172 * Filter the email notification settings.
173 *
174 * @since 2.0
175 */
176 'sub-fields' => apply_filters( 'give_email_notification_options_metabox_fields', array(), $post_id ),
177 );
178
179 return $settings;
180 }
181
182 /**
183 * Add email notifications
184 *
185 * @since 2.0
186 * @access private
187 */
188 private function add_emails_notifications() {
189 $this->emails = array(
190 include GIVE_PLUGIN_DIR . 'includes/admin/emails/class-new-donation-email.php',
191 include GIVE_PLUGIN_DIR . 'includes/admin/emails/class-donation-receipt-email.php',
192 include GIVE_PLUGIN_DIR . 'includes/admin/emails/class-new-offline-donation-email.php',
193 include GIVE_PLUGIN_DIR . 'includes/admin/emails/class-offline-donation-instruction-email.php',
194 include GIVE_PLUGIN_DIR . 'includes/admin/emails/class-new-donor-register-email.php',
195 include GIVE_PLUGIN_DIR . 'includes/admin/emails/class-donor-register-email.php',
196 include GIVE_PLUGIN_DIR . 'includes/admin/emails/class-email-access-email.php',
197 );
198
199 /**
200 * Filter the email notifications.
201 *
202 * @since 2.0
203 */
204 $this->emails = apply_filters( 'give_email_notifications', $this->emails, $this );
205
206 // Bailout.
207 if ( empty( $this->emails ) ) {
208 return;
209 }
210
211 // Initiate email notifications.
212 foreach ( $this->emails as $email ) {
213 $email->init();
214 }
215 }
216
217
218 /**
219 * Get list of email notifications.
220 *
221 * @since 2.0
222 * @access public
223 * @return array
224 */
225 public function get_email_notifications() {
226 return $this->emails;
227 }
228
229
230 /**
231 * Displays the email preview
232 *
233 * @since 2.0
234 * @access public
235 * @return bool|null
236 */
237 public function preview_email() {
238 // Bailout.
239 if ( ! Give_Email_Notification_Util::can_preview_email() ) {
240 return false;
241 }
242
243 // Security check.
244 give_validate_nonce( $_GET['_wpnonce'], 'give-preview-email' );
245
246 // Get email type.
247 $email_type = isset( $_GET['email_type'] ) ? esc_attr( $_GET['email_type'] ) : '';
248
249 /* @var Give_Email_Notification $email */
250 foreach ( $this->get_email_notifications() as $email ) {
251 if ( $email_type !== $email->config['id'] ) {
252 continue;
253 }
254
255 // Set form id.
256 $form_id = empty( $_GET['form_id'] ) ? null : absint( $_GET['form_id'] );
257
258 // Call setup email data to apply filter and other thing to email.
259 $email->setup_email_data();
260
261 // Decode message.
262 $email_message = $email->preview_email_template_tags( $email->get_email_message( $form_id ) );
263
264 // Set email template.
265 Give()->emails->html = true;
266 Give()->emails->__set( 'template', $email->get_email_template( $form_id ) );
267
268 if ( 'text/plain' === $email->config['content_type'] ) {
269 // Give()->emails->__set( 'html', false );
270 Give()->emails->__set( 'template', 'none' );
271 }
272
273 if ( $email_message = Give()->emails->build_email( $email_message ) ) {
274
275 /**
276 * Filter the email preview data
277 *
278 * @since 2.0
279 *
280 * @param array
281 */
282 $email_preview_data = apply_filters( "give_{$email_type}_email_preview_data", array() );
283
284 /**
285 * Fire the give_{$email_type}_email_preview action
286 *
287 * @since 2.0
288 */
289 do_action( "give_{$email_type}_email_preview", $email );
290
291 /**
292 * Filter the email message
293 *
294 * @since 2.0
295 *
296 * @param string $email_message
297 * @param array $email_preview_data
298 * @param Give_Email_Notification $email
299 */
300 echo apply_filters( "give_{$email_type}_email_preview_message", $email_message, $email_preview_data, $email );
301
302 exit();
303 }
304 }// End foreach().
305 }
306
307
308 /**
309 * Add header to donation receipt email preview
310 *
311 * @since 2.0
312 * @access public
313 *
314 * @param Give_Email_Notification $email
315 */
316 public function email_preview_header( $email ) {
317 /**
318 * Filter the all email preview headers.
319 *
320 * @since 2.0
321 *
322 * @param Give_Email_Notification $email
323 */
324 $email_preview_header = apply_filters( 'give_email_preview_header', give_get_preview_email_header(), $email );
325
326 echo $email_preview_header;
327 }
328
329 /**
330 * Add email preview data
331 *
332 * @since 2.0
333 * @access public
334 *
335 * @param array $email_preview_data
336 *
337 * @return array
338 */
339 public function email_preview_data( $email_preview_data ) {
340 $email_preview_data['payment_id'] = absint( give_check_variable( give_clean( $_GET ), 'isset', 0, 'preview_id' ) );
341 $email_preview_data['user_id'] = absint( give_check_variable( give_clean( $_GET ), 'isset', 0, 'user_id' ) );
342
343 return $email_preview_data;
344 }
345
346 /**
347 * Replace email template tags.
348 *
349 * @since 2.0
350 * @access public
351 *
352 * @param string $email_message
353 * @param array $email_preview_data
354 *
355 * @return string
356 */
357 public function email_preview_message( $email_message, $email_preview_data ) {
358 if (
359 ! empty( $email_preview_data['payment_id'] )
360 || ! empty( $email_preview_data['user_id'] )
361 ) {
362 $email_message = give_do_email_tags( $email_message, $email_preview_data );
363 }
364
365 return $email_message;
366 }
367
368 /**
369 * Displays the email preview
370 *
371 * @since 2.0
372 * @access public
373 * @return bool|null
374 */
375 public function send_preview_email() {
376 // Bailout.
377 if ( ! Give_Email_Notification_Util::can_send_preview_email() ) {
378 return false;
379 }
380
381 // Security check.
382 give_validate_nonce( $_GET['_wpnonce'], 'give-send-preview-email' );
383
384 // Get email type.
385 $email_type = give_check_variable( give_clean( $_GET ), 'isset', '', 'email_type' );
386
387 /* @var Give_Email_Notification $email */
388 foreach ( $this->get_email_notifications() as $email ) {
389 if ( $email_type === $email->config['id'] && Give_Email_Notification_Util::is_email_preview( $email ) ) {
390 $email->send_preview_email();
391 break;
392 }
393 }
394
395 // Remove the test email query arg.
396 wp_redirect( remove_query_arg( 'give_action' ) );
397 exit;
398 }
399
400
401 /**
402 * Load Give_Email_Notifications
403 *
404 * @since 2.0
405 * @access public
406 */
407 public function load() {
408 add_action( 'init', array( $this, 'init' ), -1 );
409 }
410
411
412 /**
413 * Verify email setting before saving
414 *
415 * @since 2.0
416 * @access public
417 */
418 public function validate_settings() {
419 // Bailout.
420 if (
421 ! Give_Admin_Settings::is_saving_settings() ||
422 'emails' !== give_get_current_setting_tab() ||
423 ! isset( $_GET['section'] )
424 ) {
425 return;
426 }
427
428 // Get email type.
429 $email_type = give_get_current_setting_section();
430
431 if ( ! empty( $_POST["{$email_type}_recipient"] ) ) {
432 $_POST["{$email_type}_recipient"] = array_unique( array_filter( $_POST["{$email_type}_recipient"] ) );
433 }
434 }
435 }
436
437 // Helper class.
438 require_once GIVE_PLUGIN_DIR . 'includes/admin/emails/abstract-email-notification.php';
439 require_once GIVE_PLUGIN_DIR . 'includes/admin/emails/class-email-notification-util.php';
440
441 // Add backward compatibility.
442 require_once GIVE_PLUGIN_DIR . 'includes/admin/emails/backward-compatibility.php';
443
444 /**
445 * Initialize functionality.
446 */
447 Give_Email_Notifications::get_instance()->load();
448