PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.7.2
GiveWP – Donation Plugin and Fundraising Platform v2.7.2
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 / abstract-email-notification.php
give / includes / admin / emails Last commit date
abstract-email-notification.php 6 years ago ajax-handler.php 6 years ago backward-compatibility.php 6 years ago class-donation-receipt-email.php 6 years ago class-donor-note-email.php 6 years ago class-donor-register-email.php 6 years ago class-email-access-email.php 6 years ago class-email-notification-table.php 6 years ago class-email-notification-util.php 6 years ago class-email-notifications.php 6 years ago class-email-setting-field.php 6 years ago class-new-donation-email.php 6 years ago class-new-donor-register-email.php 6 years ago class-new-offline-donation-email.php 6 years ago class-offline-donation-instruction-email.php 6 years ago filters.php 6 years ago
abstract-email-notification.php
1015 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, GiveWP
10 * @license https://opensource.org/licenses/gpl-license GNU Public License
11 * @since 2.0
12 */
13
14 // Exit if access directly.
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit;
17 }
18
19 if ( ! class_exists( 'Give_Email_Notification' ) ) :
20
21 /**
22 * Give_Email_Notification
23 *
24 * @abstract
25 * @since 2.0
26 */
27 abstract class Give_Email_Notification {
28 /**
29 * Array of instances
30 *
31 * @since 2.0
32 * @access private
33 * @var array
34 */
35 private static $singleton = array();
36
37 /**
38 * Array of notification settings.
39 *
40 * @since 2.0
41 * @access public
42 * @var array
43 */
44 public $config = array(
45 'id' => '',
46 'label' => '',
47 'description' => '',
48 'has_recipient_field' => false,
49 'recipient_group_name' => '',
50 'notification_status' => 'disabled',
51 'notification_status_editable' => true,
52 'notices' => array(),
53 'content_type_editable' => true,
54 'has_preview' => true,
55 'has_preview_header' => true,
56 'preview_email_tags_values' => array(),
57 'email_tag_context' => 'all',
58 'form_metabox_setting' => true,
59 'content_type' => '',
60 'email_template' => '',
61 'default_email_subject' => '',
62 'default_email_message' => '',
63 'default_email_header' => '',
64 // This setting page will appear under core setting.
65 'show_on_emails_setting_page' => true,
66 'form_metabox_id' => 'give_email_notification_options_metabox_fields',
67 );
68
69 /**
70 * @var string $recipient_email Donor email.
71 * @access protected
72 * @since 2.0
73 */
74 protected $recipient_email = '';
75
76
77 /**
78 * Setup email notification.
79 *
80 * @since 2.0
81 */
82 public function init() {
83
84 }
85
86
87 /**
88 * Get instance.
89 *
90 * @since 2.0
91 * @access public
92 *
93 * @param string $email_notification_id
94 *
95 * @return Give_Email_Notification
96 */
97 public static function get_instance( $email_notification_id = '' ) {
98 $class = '';
99
100 if ( ! empty( $email_notification_id ) ) {
101 /* @var Give_Email_Notification $class */
102 foreach ( self::$singleton as $class ) {
103 if ( $email_notification_id === $class->config['id'] ) {
104 $class = get_class( $class );
105 break;
106 }
107 }
108 } else {
109 $class = get_called_class();
110 }
111
112 if ( ! empty( $class ) && ( ! array_key_exists( $class, self::$singleton ) || is_null( self::$singleton[ $class ] ) ) ) {
113 self::$singleton[ $class ] = new $class();
114 }
115
116 return ( isset( self::$singleton[ $class ] ) ? self::$singleton[ $class ] : null );
117 }
118
119 /**
120 * Setup action and filters.
121 *
122 * @access public
123 * @since 2.0
124 *
125 * @param array $config
126 */
127 public function load( $config ) {
128 // Set notification configuration.
129 $this->config = wp_parse_args( $config, $this->config );
130
131 // Set email preview header status.
132 $this->config['has_preview_header'] = $this->config['has_preview'] && $this->config['has_preview_header'] ? true : false;
133
134 // Set email content type
135 $this->config['content_type'] = empty( $this->config['content_type'] ) || ! in_array(
136 $this->config['content_type'],
137 array(
138 'text/html',
139 'text/plain',
140 )
141 )
142 ? Give()->emails->get_content_type()
143 : $this->config['content_type'];
144 $this->config['content_type'] = give_get_option( Give_Email_Setting_Field::get_prefix( $this ) . 'email_content_type', $this->config['content_type'] );
145
146 // Set email template type.
147 $this->config['email_template'] = empty( $this->config['email_template'] )
148 ? give_get_option( 'email_template' )
149 : $this->config['email_template'];
150
151 // Set recipient group name.
152 $this->config['recipient_group_name'] = empty( $this->config['recipient_group_name'] )
153 ? ( ! Give_Email_Notification_Util::has_recipient_field( $this ) ? __( 'Donor', 'give' ) : '' )
154 : $this->config['recipient_group_name'];
155
156 // Non notification status editable notice.
157 $this->config['notices']['non-notification-status-editable'] = empty( $this->config['notices']['non-notification-status-editable'] )
158 ? __( 'You can not edit notification status from here.', 'give' )
159 : $this->config['notices']['non-notification-status-editable'];
160
161 /**
162 * Filter the notification config.
163 *
164 * @since 2.0
165 *
166 * @param array Give_Email_Notification::config
167 * @param Give_Email_Notification $this
168 */
169 $this->config = apply_filters( 'give_email_api_notification_config', $this->config, $this );
170
171 // Setup filters.
172 $this->setup_filters();
173 }
174
175
176 /**
177 * Setup filters.
178 *
179 * @since 2.0
180 * @access public
181 */
182 private function setup_filters() {
183 // Do not setup filters if not admin.
184 if ( ! is_admin() ) {
185 return;
186 }
187
188 // Apply filter only for current email notification section.
189 if ( isset( $_GET['section'] ) && give_get_current_setting_section() === $this->config['id'] ) {
190 // Initialize email context for email notification.
191 $this->config['email_tag_context'] = apply_filters(
192 "give_{$this->config['id']}_email_tag_context",
193 $this->config['email_tag_context'],
194 $this
195 );
196 }
197
198 // Setup setting fields.
199 if ( $this->config['show_on_emails_setting_page'] ) {
200 add_filter( 'give_get_settings_emails', array( $this, 'add_setting_fields' ), 10, 2 );
201 }
202
203 if ( $this->config['form_metabox_setting'] && ! empty( $this->config['form_metabox_id'] ) ) {
204 add_filter(
205 $this->config['form_metabox_id'],
206 array( $this, 'add_metabox_setting_field' ),
207 10,
208 2
209 );
210 }
211
212 if ( $this->config['has_recipient_field'] ) {
213 add_action(
214 "give_save__give_{$this->config['id']}_recipient",
215 array( $this, 'validate_form_recipient_field_value' ),
216 10,
217 3
218 );
219 }
220
221 /**
222 * Filter the default email subject.
223 *
224 * @since 2.0
225 */
226 $this->config['default_email_subject'] = apply_filters(
227 "give_{$this->config['id']}_get_default_email_subject",
228 $this->config['default_email_subject'],
229 $this
230 );
231
232 /**
233 * Filter the default email message.
234 *
235 * @since 2.0
236 */
237 $this->config['default_email_message'] = apply_filters(
238 "give_{$this->config['id']}_get_default_email_message",
239 $this->config['default_email_message'],
240 $this
241 );
242
243 /**
244 * Filter the default email header.
245 *
246 * @since 2.1.3
247 */
248 $this->config['default_email_header'] = apply_filters(
249 "give_{$this->config['id']}_get_default_email_header",
250 $this->config['default_email_header'],
251 $this
252 );
253 }
254
255 /**
256 * Add sections.
257 *
258 * @since 2.0
259 *
260 * @param array $sections
261 *
262 * @return array
263 */
264 public function add_section( $sections ) {
265 $sections[ $this->config['id'] ] = $this->config['label'];
266
267 return $sections;
268 }
269
270 /**
271 * Add sections.
272 *
273 * @since 2.0
274 *
275 * @param bool $hide_section
276 *
277 * @return bool
278 */
279 public function hide_section( $hide_section ) {
280 $hide_section = true;
281
282 return $hide_section;
283 }
284
285 /**
286 * Register email settings.
287 *
288 * @since 2.0
289 * @access public
290 *
291 * @param array $settings
292 *
293 * @return array
294 */
295 public function add_setting_fields( $settings ) {
296 if ( $this->config['id'] === give_get_current_setting_section() ) {
297 $settings = $this->get_setting_fields();
298 }
299
300 return $settings;
301 }
302
303
304 /**
305 * Get setting fields
306 *
307 * @since 2.0
308 * @access public
309 *
310 * @param int $form_id
311 *
312 * @return array
313 */
314 public function get_setting_fields( $form_id = null ) {
315 return Give_Email_Setting_Field::get_setting_fields( $this, $form_id );
316 }
317
318
319 /**
320 * Register email settings to form metabox.
321 *
322 * @since 2.0
323 * @access public
324 *
325 * @param array $settings
326 * @param int $form_id
327 *
328 * @return array
329 */
330 public function add_metabox_setting_field( $settings, $form_id ) {
331
332 if ( Give_Email_Notification_Util::is_email_notification_active( $this ) ) {
333 $settings[] = array(
334 'id' => $this->config['id'],
335 'title' => $this->config['label'],
336 'fields' => $this->get_setting_fields( $form_id ),
337 );
338 }
339
340 return $settings;
341 }
342
343
344 /**
345 * Get extra setting field.
346 *
347 * @since 2.0
348 * @access public
349 *
350 * @param int $form_id
351 *
352 * @return array
353 */
354 public function get_extra_setting_fields( $form_id = null ) {
355 return array();
356 }
357
358
359 /**
360 * Get recipient(s).
361 *
362 * Note: in case of admin notification this fx will return array of emails otherwise empty string or email of donor.
363 *
364 * @since 2.0
365 * @access public
366 *
367 * @param int $form_id
368 *
369 * @return string|array
370 */
371 public function get_recipient( $form_id = null ) {
372 if ( empty( $this->recipient_email ) && $this->config['has_recipient_field'] ) {
373 $this->recipient_email = Give_Email_Notification_Util::get_value(
374 $this,
375 Give_Email_Setting_Field::get_prefix( $this, $form_id ) . 'recipient',
376 $form_id
377 );
378
379 /**
380 * Filter the admin notice emails.
381 *
382 * @since 1.0
383 * @deprecated 2.0
384 */
385 $this->recipient_email = apply_filters( 'give_admin_notice_emails', $this->recipient_email, $this, $form_id );
386 }
387
388 /**
389 * Filter the recipients
390 *
391 * @since 2.0
392 */
393 return apply_filters(
394 "give_{$this->config['id']}_get_recipients",
395 give_check_variable(
396 $this->recipient_email,
397 'empty',
398 Give()->emails->get_from_address()
399 ),
400 $this,
401 $form_id
402 );
403 }
404
405 /**
406 * Get notification status.
407 *
408 * @since 2.0
409 * @access public
410 *
411 * @param int $form_id
412 *
413 * @return bool
414 */
415 public function get_notification_status( $form_id = null ) {
416 $notification_status = empty( $form_id )
417 ? give_get_option( "{$this->config['id']}_notification", $this->config['notification_status'] )
418 : give_get_meta( $form_id, Give_Email_Setting_Field::get_prefix( $this, $form_id ) . 'notification', true, 'global' );
419
420 /**
421 * Filter the notification status.
422 *
423 * @since 1.8
424 */
425 return apply_filters(
426 "give_{$this->config['id']}_get_notification_status",
427 $notification_status,
428 $this,
429 $form_id
430 );
431 }
432
433 /**
434 * Get email subject.
435 *
436 * @since 2.0
437 * @access public
438 *
439 * @param int $form_id
440 *
441 * @return string
442 */
443 function get_email_subject( $form_id = null ) {
444 $subject = wp_strip_all_tags(
445 Give_Email_Notification_Util::get_value(
446 $this,
447 Give_Email_Setting_Field::get_prefix( $this, $form_id ) . 'email_subject',
448 $form_id,
449 $this->config['default_email_subject']
450 )
451 );
452
453 /**
454 * Filter the subject.
455 *
456 * @since 2.0
457 */
458 return apply_filters(
459 "give_{$this->config['id']}_get_email_subject",
460 $subject,
461 $this,
462 $form_id
463 );
464 }
465
466 /**
467 * Get email message.
468 *
469 * @since 2.0
470 * @access public
471 *
472 * @param int $form_id
473 *
474 * @return string
475 */
476 public function get_email_message( $form_id = null ) {
477 $message = Give_Email_Notification_Util::get_value(
478 $this,
479 Give_Email_Setting_Field::get_prefix( $this, $form_id ) . 'email_message',
480 $form_id,
481 $this->config['default_email_message']
482 );
483
484 /**
485 * Filter the message.
486 *
487 * @since 2.0
488 */
489 return apply_filters(
490 "give_{$this->config['id']}_get_email_message",
491 $message,
492 $this,
493 $form_id
494 );
495 }
496
497 /**
498 * Get email header.
499 *
500 * @param int $form_id The Form ID.
501 *
502 * @since 2.1.3
503 *
504 * @return string
505 */
506 public function get_email_header( $form_id = null ) {
507 $header = Give_Email_Notification_Util::get_value(
508 $this,
509 Give_Email_Setting_Field::get_prefix( $this, $form_id ) . 'email_header',
510 $form_id,
511 $this->config['default_email_header']
512 );
513
514 /**
515 * Filter the header.
516 *
517 * @since 2.1.3
518 */
519 return apply_filters(
520 "give_{$this->config['id']}_get_email_header",
521 $header,
522 $this,
523 $form_id
524 );
525 }
526
527 /**
528 * Get email content type.
529 *
530 * @since 2.0
531 * @access public
532 *
533 * @param $form_id
534 *
535 * @return string
536 */
537 public function get_email_content_type( $form_id ) {
538 $content_type = Give_Email_Notification_Util::get_value(
539 $this,
540 Give_Email_Setting_Field::get_prefix( $this, $form_id ) . 'email_content_type',
541 $form_id,
542 $this->config['content_type']
543 );
544
545 /**
546 * Filter the email content type.
547 *
548 * @since 2.0
549 */
550 return apply_filters(
551 "give_{$this->config['id']}_get_email_content_type",
552 $content_type,
553 $this,
554 $form_id
555 );
556 }
557
558 /**
559 * Get email template.
560 *
561 * @since 2.0
562 * @access public
563 *
564 * @param $form_id
565 *
566 * @return string
567 */
568 public function get_email_template( $form_id ) {
569 $email_template = give_get_meta( $form_id, '_give_email_template', true );
570 $email_template = Give_Email_Notification_Util::get_value(
571 $this,
572 Give_Email_Setting_Field::get_prefix( $this, $form_id ) . 'email_template',
573 $form_id,
574 ! empty( $email_template ) && Give_Email_Notification_Util::can_use_form_email_options( $this, $form_id ) ?
575 $email_template :
576 $this->config['email_template']
577 );
578
579 /**
580 * Filter the email template.
581 *
582 * @since 2.0
583 */
584 return apply_filters(
585 "give_{$this->config['id']}_get_email_template",
586 $email_template,
587 $this,
588 $form_id
589 );
590 }
591
592
593 /**
594 * Get allowed email tags for current email notification.
595 *
596 * @since 2.0
597 * @access private
598 *
599 * @param bool $formatted
600 *
601 * @return array
602 */
603 public function get_allowed_email_tags( $formatted = false ) {
604 // Get all email tags.
605 $email_tags = Give()->email_tags->get_tags();
606
607 // Skip if all email template tags context setup exit.
608 if ( $this->config['email_tag_context'] && 'all' !== $this->config['email_tag_context'] ) {
609 $email_context = (array) $this->config['email_tag_context'];
610
611 foreach ( $email_tags as $index => $email_tag ) {
612 if ( in_array( $email_tag['context'], $email_context ) ) {
613 continue;
614 }
615
616 unset( $email_tags[ $index ] );
617 }
618 }
619
620 /**
621 * Disallow tags on Email Notifications which don't have a
622 * recipient and if the tag's is_admin property is set to true.
623 */
624 if ( false === $this->config['has_recipient_field'] ) {
625 foreach ( $email_tags as $index => $email_tag ) {
626 if ( true === $email_tag['is_admin'] ) {
627 unset( $email_tags[ $index ] );
628 }
629 }
630 }
631
632 if ( count( $email_tags ) && $formatted ) :
633 ob_start() ?>
634 <ul class="give-email-tags-wrap">
635 <?php foreach ( $email_tags as $email_tag ) : ?>
636 <li class="give_<?php echo $email_tag['tag']; ?>_tag">
637 <code>{<?php echo $email_tag['tag']; ?>}</code> - <?php echo $email_tag['desc']; ?>
638 </li>
639 <?php endforeach; ?>
640 </ul>
641 <?php
642 $email_tags = ob_get_clean();
643 endif;
644
645 return $email_tags;
646 }
647
648 /**
649 * Get preview email recipients.
650 *
651 * @since 2.0
652 * @access public
653 *
654 * @param int $form_id
655 *
656 * @return array|string
657 */
658 public function get_preview_email_recipient( $form_id = null ) {
659 $recipients = $this->get_recipient( $form_id );
660
661 /**
662 * Filter the preview email recipients.
663 *
664 * @since 2.0
665 *
666 * @param string|array $recipients List of recipients.
667 * @param Give_Email_Notification $this
668 */
669 $recipients = apply_filters( 'give_get_preview_email_recipient', $recipients, $this, $form_id );
670
671 return $recipients;
672 }
673
674 /**
675 * Get the recipient attachments.
676 *
677 * @since 2.0
678 * @access public
679 *
680 * @param int $form_id
681 *
682 * @return array
683 */
684 public function get_email_attachments( $form_id = null ) {
685 /**
686 * Filter the attachment.
687 *
688 * @since 2.0
689 */
690 return apply_filters( "give_{$this->config['id']}_get_email_attachments", array(), $this, $form_id );
691 }
692
693
694 /**
695 * Send preview email.
696 *
697 * @since 2.0
698 * @access public
699 *
700 * @param bool $send Flag to check if send email or not.
701 *
702 * @return bool
703 */
704 public function send_preview_email( $send = true ) {
705 // Get form id
706 $form_id = ! empty( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : null;
707
708 // setup email data.
709 $this->setup_email_data();
710
711 $attachments = $this->get_email_attachments();
712 $message = $this->preview_email_template_tags( $this->get_email_message( $form_id ) );
713 $subject = $this->preview_email_template_tags( $this->get_email_subject( $form_id ) );
714 $content_type = $this->get_email_content_type( $form_id );
715
716 // Setup email content type.
717 Give()->emails->__set( 'content_type', $content_type );
718 Give()->emails->__set( 'html', true );
719
720 // Setup email template
721 Give()->emails->__set( 'template', $this->get_email_template( $form_id ) );
722
723 // Set email header.
724 Give()->emails->__set( 'heading', $this->preview_email_template_tags( $this->get_email_header( $form_id ) ) );
725
726 // Format plain content type email.
727 if ( 'text/plain' === $content_type ) {
728 Give()->emails->__set( 'html', false );
729 Give()->emails->__set( 'template', 'none' );
730 $message = strip_tags( $message );
731 }
732
733 if ( Give_Email_Notification_Util::can_use_form_email_options( $this, $form_id ) ) {
734 Give()->emails->form_id = $form_id;
735 Give()->emails->from_name = give_get_meta( $form_id, '_give_from_name', true );
736 Give()->emails->from_address = give_get_meta( $form_id, '_give_from_email', true );
737 }
738
739 return $send
740 ? Give()->emails->send( $this->get_preview_email_recipient( $form_id ), $subject, $message, $attachments )
741 : false;
742 }
743
744
745 /**
746 * Send email notification.
747 *
748 * Note: To render email tags in all context certain parameters are necessary for core (includes/emails/class-give-emails):
749 * 1. payment_id
750 * 2. user_id
751 * 3. form_id
752 * 4. donor_id
753 * 5. for third party email tags you can pass necessary param along above parameters other value replace by empty string.
754 *
755 * @since 2.0
756 * @access public
757 *
758 * @param array $email_tag_args Arguments which helps to decode email template tags.
759 *
760 * @return bool
761 */
762 public function send_email_notification( $email_tag_args = array() ) {
763 /**
764 * Fire the filter
765 *
766 * @since 2.2.3
767 */
768 if ( apply_filters( 'give_is_stop_email_notification', false, $this ) ) {
769 return false;
770 }
771
772 // Add email content type email tags.
773 $email_tag_args['email_content_type'] = $this->config['content_type'];
774
775 /**
776 * Filter the email tag args
777 *
778 * @since 2.0
779 */
780 $email_tag_args = apply_filters( "give_{$this->config['id']}_email_tag_args", $email_tag_args, $this );
781
782 // Get form id.
783 $form_id = ! empty( $email_tag_args['form_id'] )
784 ? absint( $email_tag_args['form_id'] )
785 : ( ! empty( $email_tag_args['payment_id'] ) ? give_get_payment_form_id( $email_tag_args['payment_id'] ) : null );
786
787 // Do not send email if notification is disabled.
788 if ( ! Give_Email_Notification_Util::is_email_notification_active( $this, $form_id ) ) {
789 return false;
790 }
791
792 /**
793 * Fire action after before email send.
794 *
795 * @since 2.0
796 */
797 do_action( "give_{$this->config['id']}_email_send_before", $this, $form_id );
798
799 $attachments = $this->get_email_attachments();
800 $message = give_do_email_tags( $this->get_email_message( $form_id ), $email_tag_args );
801 $subject = give_do_email_tags( $this->get_email_subject( $form_id ), $email_tag_args );
802 $content_type = $this->get_email_content_type( $form_id );
803
804 // Setup email content type.
805 Give()->emails->__set( 'content_type', $content_type );
806 Give()->emails->__set( 'html', true );
807
808 // Set email template.
809 Give()->emails->__set( 'template', $this->get_email_template( $form_id ) );
810
811 // Set email header.
812 Give()->emails->__set( 'heading', give_do_email_tags( $this->get_email_header( $form_id ), $email_tag_args ) );
813
814 if ( 'text/plain' === $content_type ) {
815 Give()->emails->__set( 'html', false );
816 Give()->emails->__set( 'template', 'none' );
817 $message = strip_tags( $message );
818 }
819
820 if ( Give_Email_Notification_Util::can_use_form_email_options( $this, $form_id ) ) {
821 Give()->emails->form_id = $form_id;
822 Give()->emails->from_name = give_get_meta( $form_id, '_give_from_name', true );
823 Give()->emails->from_address = give_get_meta( $form_id, '_give_from_email', true );
824 }
825
826 // Send email.
827 $email_status = Give()->emails->send( $this->get_recipient( $form_id ), $subject, $message, $attachments );
828
829 /**
830 * Fire action after after email send.
831 *
832 * @since 2.0
833 */
834 do_action( "give_{$this->config['id']}_email_send_after", $email_status, $this, $form_id );
835
836 return $email_status;
837 }
838
839
840 /**
841 * Decode preview email template tags.
842 *
843 * @since 2.0
844 *
845 * @param string $message Email Template Message.
846 *
847 * @return string
848 */
849 public function preview_email_template_tags( $message ) {
850
851 $get_data = give_clean( filter_input_array( INPUT_GET ) );
852
853 // Set Payment.
854 $payment_id = give_check_variable( $get_data, 'isset_empty', 0, 'preview_id' );
855 $payment = $payment_id ? new Give_Payment( $payment_id ) : new stdClass();
856
857 // Set donor.
858 $user_id = $payment_id
859 ? $payment->user_id
860 : give_check_variable( $get_data, 'isset_empty', 0, 'user_id' );
861 $user_id = $user_id ? $user_id : wp_get_current_user()->ID;
862
863 $receipt_link_url = give_get_receipt_url( $payment_id );
864 $receipt_link = give_get_receipt_link( $payment_id );
865
866 // Set default values for tags.
867 $this->config['preview_email_tags_values'] = wp_parse_args(
868 $this->config['preview_email_tags_values'],
869 array(
870 'name' => give_email_tag_first_name(
871 array(
872 'payment_id' => $payment_id,
873 'user_id' => $user_id,
874 )
875 ),
876 'fullname' => give_email_tag_fullname(
877 array(
878 'payment_id' => $payment_id,
879 'user_id' => $user_id,
880 )
881 ),
882 'username' => give_email_tag_username(
883 array(
884 'payment_id' => $payment_id,
885 'user_id' => $user_id,
886 )
887 ),
888 'user_email' => give_email_tag_user_email(
889 array(
890 'payment_id' => $payment_id,
891 'user_id' => $user_id,
892 )
893 ),
894 'payment_total' => $payment_id ? give_email_tag_payment_total( array( 'payment_id' => $payment_id ) ) : give_currency_filter( '10.50' ),
895 'amount' => $payment_id ? give_email_tag_amount( array( 'payment_id' => $payment_id ) ) : give_currency_filter( '10.50' ),
896 'price' => $payment_id ? give_email_tag_price( array( 'payment_id' => $payment_id ) ) : give_currency_filter( '10.50' ),
897 'payment_method' => $payment_id ? give_email_tag_payment_method( array( 'payment_id' => $payment_id ) ) : __( 'PayPal', 'give' ),
898 'payment_id' => $payment_id ? $payment_id : rand( 2000, 2050 ),
899 'receipt_link_url' => $receipt_link_url,
900 'receipt_link' => $receipt_link,
901 'date' => $payment_id ? date( give_date_format(), strtotime( $payment->date ) ) : date( give_date_format(), current_time( 'timestamp' ) ),
902 'donation' => $payment_id ? give_email_tag_donation( array( 'payment_id' => $payment_id ) ) : esc_html__( 'Sample Donation Form Title', 'give' ),
903 'form_title' => $payment_id ? give_email_tag_form_title( array( 'payment_id' => $payment_id ) ) : esc_html__( 'Sample Donation Form Title - Sample Donation Level', 'give' ),
904 'sitename' => $payment_id ? give_email_tag_sitename( array( 'payment_id' => $payment_id ) ) : get_bloginfo( 'name' ),
905 'billing_address' => $payment_id ? give_email_tag_billing_address( array( 'payment_id' => $payment_id ) ) : '',
906 'email_access_link' => sprintf(
907 '<a href="%1$s">%2$s</a>',
908 add_query_arg(
909 array(
910 'give_nl' => uniqid(),
911 ),
912 give_get_history_page_uri()
913 ),
914 __( 'View your donation history &raquo;', 'give' )
915 ),
916 'donation_history_link' => sprintf(
917 '<a href="%1$s">%2$s</a>',
918 add_query_arg(
919 array(
920 'give_nl' => uniqid(),
921 ),
922 give_get_history_page_uri()
923 ),
924 __( 'View your donation history &raquo;', 'give' )
925 ),
926 'reset_password_link' => $user_id ? give_email_tag_reset_password_link( array( 'user_id' => $user_id ), $payment_id ) : '',
927 'site_url' => sprintf(
928 '<a href="%1$s">%2$s</a>',
929 get_bloginfo( 'url' ),
930 get_bloginfo( 'url' )
931 ),
932 'admin_email' => give_email_admin_email(),
933 'offline_mailing_address' => give_email_offline_mailing_address(),
934 'donor_comment' => $payment_id ? give_email_donor_comment( array( 'payment_id' => $payment_id ) ) : esc_html__( 'Sample Donor Comment', 'give' ),
935 )
936 );
937
938 // Decode tags.
939 foreach ( $this->config['preview_email_tags_values'] as $preview_tag => $value ) {
940 if ( isset( $this->config['preview_email_tags_values'][ $preview_tag ] ) ) {
941 $message = str_replace( "{{$preview_tag}}", $this->config['preview_email_tags_values'][ $preview_tag ], $message );
942 }
943 }
944
945 return apply_filters( 'give_email_preview_template_tags', $message );
946 }
947
948 /**
949 * Setup email data
950 *
951 * @since 2.0
952 */
953 public function setup_email_data() {
954 }
955
956
957 /**
958 * Validate email form setting
959 *
960 * Note: internal use only
961 *
962 * @since 2.0
963 * @access public
964 *
965 * @param $form_meta_key
966 * @param $form_meta_value
967 * @param $post_id
968 */
969 public function validate_form_recipient_field_value( $form_meta_key, $form_meta_value, $post_id ) {
970 // Get valid emails.
971 $new_form_meta_value = array_filter(
972 $form_meta_value,
973 function ( $value ) {
974 return ! empty( $value['email'] ) && is_email( $value['email'] );
975 }
976 );
977
978 // Remove duplicate emails from array.
979 $email_arr = array();
980 foreach ( $new_form_meta_value as $index => $email ) {
981 if ( in_array( $email['email'], $email_arr ) ) {
982 unset( $new_form_meta_value[ $index ] );
983 continue;
984 }
985
986 $email_arr[] = $email['email'];
987 }
988
989 $update = false;
990
991 if ( empty( $new_form_meta_value ) ) {
992 // Set default recipient.
993 $form_meta_value = array(
994 array(
995 'email' => get_bloginfo( 'admin_email' ),
996 ),
997 );
998
999 $update = true;
1000
1001 } elseif ( count( $new_form_meta_value ) !== count( $form_meta_value ) ) {
1002 // Filter recipient emails.
1003 $form_meta_value = $new_form_meta_value;
1004
1005 $update = true;
1006 }
1007
1008 if ( $update ) {
1009 give_update_meta( $post_id, $form_meta_key, $form_meta_value );
1010 }
1011 }
1012 }
1013
1014 endif; // End class_exists check
1015