Completed
Push — issues/611 ( d18391...30996d )
by Ravinder
44:11 queued 24:21
created

Give_Email_Notification::get_instance()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 2
nop 0
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 27 and the first side effect is on line 16.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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
// 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
		/**
39
		 * Array of notification settings.
40
		 *
41
		 * @since  2.0
42
		 * @access public
43
		 * @var array
44
		 */
45
		public $config = array(
46
			'id'                           => '',
47
			'label'                        => '',
48
			'description'                  => '',
49
			'has_recipient_field'          => false,
50
			'recipient_group_name'         => '',
51
			'notification_status'          => 'disabled',
52
			'notification_status_editable' => true,
53
			'notices'                      => array(),
54
			'content_type_editable'        => true,
55
			'has_preview'                  => true,
56
			'has_preview_header'           => true,
57
			'preview_email_tags_values'    => array(),
58
			'email_tag_context'            => 'all',
59
			'form_metabox_setting'         => true,
60
			'content_type'                 => '',
61
			'email_template'               => '',
62
			'default_email_subject'        => '',
63
			'default_email_message'        => '',
64
		);
65
66
		/**
67
		 * @var     string $recipient_email Donor email.
68
		 * @access  protected
69
		 * @since   2.0
70
		 */
71
		protected $recipient_email = '';
72
73
74
		/**
75
		 * Setup email notification.
76
		 *
77
		 * @since 2.0
78
		 */
79
		public function init() {
80
81
		}
82
83
84
		/**
85
		 * Get instance.
86
		 *
87
		 * @since  2.0
88
		 * @access public
89
		 * @return Give_Email_Notification
90
		 */
91
		public static function get_instance() {
92
			$class = get_called_class();
93
			if ( ! array_key_exists( $class, self::$singleton ) || is_null( self::$singleton[ $class ] ) ) {
94
				self::$singleton[ $class ] = new $class();
95
			}
96
97
			return self::$singleton[ $class ];
98
		}
99
100
		/**
101
		 * Setup action and filters.
102
		 *
103
		 * @access  public
104
		 * @since   2.0
105
		 *
106
		 * @param array $config
107
		 */
108
		public function load( $config ) {
109
			// Set notification configuration.
110
			$this->config = wp_parse_args( $config, $this->config );
111
112
			// Set email preview header status.
113
			$this->config['has_preview_header'] = $this->config['has_preview'] && $this->config['has_preview_header'] ? true : false;
114
115
			// Set email content type
116
			$this->config['content_type'] = empty( $this->config['content_type'] ) || ! in_array( $this->config['content_type'], array(
117
				'text/html',
118
				'text/plain',
119
			) )
120
				? Give()->emails->get_content_type()
121
				: $this->config['content_type'];
122
			$this->config['content_type'] = give_get_option( "{$this->config['id']}_email_content_type", $this->config['content_type'] );
123
124
			// Set email template type.
125
			$this->config['email_template'] = empty( $this->config['email_template'] )
126
				? give_get_option( 'email_template' )
127
				: $this->config['email_template'];
128
129
			// Set recipient group name.
130
			$this->config['recipient_group_name'] = empty( $this->config['recipient_group_name'] )
131
				? ( ! Give_Email_Notification_Util::has_recipient_field( $this ) ? __( 'Donor', 'give' ) : '' )
132
				: $this->config['recipient_group_name'];
133
134
			// Non notification status editable notice.
135
			$this->config['notices']['non-notification-status-editable'] = empty( $this->config['notices']['non-notification-status-editable'] )
136
				? __( 'You can not edit this notification directly. This will be enable or disable automatically on basis of plugin settings.', 'give' )
137
				: $this->config['notices']['non-notification-status-editable'];
138
139
			/**
140
			 *  Filter the notification config.
141
			 *
142
			 * @since 2.0
143
			 *
144
			 * @param                         array                   Give_Email_Notification::config
145
			 * @param Give_Email_Notification $this
146
			 */
147
			$this->config = apply_filters( 'give_email_api_notification_config', $this->config, $this );
148
149
			// Setup filters.
150
			$this->setup_filters();
151
		}
152
153
154
		/**
155
		 * Setup filters.
156
		 *
157
		 * @since  2.0
158
		 * @access public
159
		 */
160
		private function setup_filters() {
161
			// Apply filter only for current email notification section.
162
			if ( give_get_current_setting_section() === $this->config['id'] ) {
163
				// Initialize email context for email notification.
164
				$this->config['email_tag_context'] = apply_filters(
165
					"give_{$this->config['id']}_email_tag_context",
166
					$this->config['email_tag_context'],
167
					$this
168
				);
169
			}
170
171
			// Setup setting fields.
172
			add_filter( 'give_get_settings_emails', array( $this, 'add_setting_fields' ), 10, 2 );
173
174
			if ( $this->config['form_metabox_setting'] ) {
175
				add_filter(
176
					'give_email_notification_options_metabox_fields',
177
					array( $this, 'add_metabox_setting_field' ),
178
					10,
179
					2
180
				);
181
			}
182
183
			/**
184
			 * Filter the default email subject.
185
			 *
186
			 * @since 2.0
187
			 */
188
			$this->config['default_email_subject'] = apply_filters(
189
				"give_{$this->config['id']}_get_default_email_subject",
190
				$this->config['default_email_subject'],
191
				$this
192
			);
193
194
			/**
195
			 * Filter the default email message.
196
			 *
197
			 * @since 2.0
198
			 */
199
			$this->config['default_email_message'] = apply_filters(
200
				"give_{$this->config['id']}_get_default_email_message",
201
				$this->config['default_email_message'],
202
				$this
203
			);
204
		}
205
206
		/**
207
		 * Add sections.
208
		 *
209
		 * @since 2.0
210
		 *
211
		 * @param array $sections
212
		 *
213
		 * @return array
214
		 */
215
		public function add_section( $sections ) {
216
			$sections[ $this->config['id'] ] = $this->config['label'];
217
218
			return $sections;
219
		}
220
221
		/**
222
		 * Add sections.
223
		 *
224
		 * @since 2.0
225
		 *
226
		 * @param bool $hide_section
227
		 *
228
		 * @return bool
229
		 */
230
		public function hide_section( $hide_section ) {
0 ignored issues
show
Unused Code introduced by
The parameter $hide_section is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
231
			$hide_section = true;
232
233
			return $hide_section;
234
		}
235
236
		/**
237
		 * Register email settings.
238
		 *
239
		 * @since  2.0
240
		 * @access public
241
		 *
242
		 * @param   array $settings
243
		 *
244
		 * @return  array
245
		 */
246
		public function add_setting_fields( $settings ) {
247
			if ( $this->config['id'] === give_get_current_setting_section() ) {
248
				$settings = $this->get_setting_fields();
249
			}
250
251
			return $settings;
252
		}
253
254
255
		/**
256
		 * Get setting fields
257
		 *
258
		 * @since  2.0
259
		 * @access public
260
		 *
261
		 * @param int $form_id
262
		 *
263
		 * @return array
264
		 */
265
		public function get_setting_fields( $form_id = null ) {
266
			return Give_Email_Setting_Field::get_setting_fields( $this, $form_id );
267
		}
268
269
270
		/**
271
		 * Register email settings to form metabox.
272
		 *
273
		 * @since  2.0
274
		 * @access public
275
		 *
276
		 * @param array $settings
277
		 * @param int   $form_id
278
		 *
279
		 * @return array
280
		 */
281
		public function add_metabox_setting_field( $settings, $form_id ) {
282
283
			$settings[] = array(
284
				'id'     => $this->config['id'],
285
				'title'  => $this->config['label'],
286
				'fields' => $this->get_setting_fields( $form_id ),
287
			);
288
289
			return $settings;
290
		}
291
292
293
		/**
294
		 * Get extra setting field.
295
		 *
296
		 * @since  2.0
297
		 * @access public
298
		 *
299
		 * @param int $form_id
300
		 *
301
		 * @return array
302
		 */
303
		public function get_extra_setting_fields( $form_id = null ) {
0 ignored issues
show
Unused Code introduced by
The parameter $form_id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
304
			return array();
305
		}
306
307
308
		/**
309
		 * Get recipient(s).
310
		 *
311
		 * Note: in case of admin notification this fx will return array of emails otherwise empty string or email of donor.
312
		 *
313
		 * @since  2.0
314
		 * @access public
315
		 *
316
		 * @param int $form_id
317
		 *
318
		 * @return string|array
319
		 */
320
		public function get_recipient( $form_id = null ) {
321
			if ( empty( $this->recipient_email ) && $this->config['has_recipient_field'] ) {
322
				$this->recipient_email = Give_Email_Notification_Util::get_value( $this, "{$this->config['id']}_recipient", $form_id );
323
			}
324
325
			/**
326
			 * Filter the recipients
327
			 *
328
			 * @since 2.0
329
			 */
330
			return apply_filters(
331
				"give_{$this->config['id']}_get_recipients",
332
				give_check_variable(
333
					$this->recipient_email,
334
					'empty',
335
					Give()->emails->get_from_address()
336
				),
337
				$this,
338
				$form_id
339
			);
340
		}
341
342
		/**
343
		 * Get notification status.
344
		 *
345
		 * @since  2.0
346
		 * @access public
347
		 *
348
		 * @param int $form_id
349
		 *
350
		 * @return bool
351
		 */
352
		public function get_notification_status( $form_id = null ) {
353
			$notification_status = empty( $form_id )
354
				? give_get_option( "{$this->config['id']}_notification", $this->config['notification_status'] )
355
				: get_post_meta( $form_id, "{$this->config['id']}_notification", true );
356
357
			/**
358
			 * Filter the notification status.
359
			 *
360
			 * @since 1.8
361
			 */
362
			return apply_filters(
363
				"give_{$this->config['id']}_get_notification_status",
364
				$notification_status,
365
				$this,
366
				$form_id
367
			);
368
		}
369
370
		/**
371
		 * Get email subject.
372
		 *
373
		 * @since  2.0
374
		 * @access public
375
		 *
376
		 * @param int $form_id
377
		 *
378
		 * @return string
379
		 */
380
		function get_email_subject( $form_id = null ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
381
			$subject = wp_strip_all_tags(
382
				Give_Email_Notification_Util::get_value(
383
					$this,
384
					"{$this->config['id']}_email_subject",
385
					$form_id,
386
					$this->config['default_email_subject']
387
				)
388
			);
389
390
			/**
391
			 * Filter the subject.
392
			 *
393
			 * @since 2.0
394
			 */
395
			return apply_filters(
396
				"give_{$this->config['id']}_get_email_subject",
397
				$subject,
398
				$this,
399
				$form_id
400
			);
401
		}
402
403
		/**
404
		 * Get email message.
405
		 *
406
		 * @since  2.0
407
		 * @access public
408
		 *
409
		 * @param int $form_id
410
		 *
411
		 * @return string
412
		 */
413
		public function get_email_message( $form_id = null ) {
414
			$message = Give_Email_Notification_Util::get_value(
415
				$this,
416
				"{$this->config['id']}_email_message",
417
				$form_id,
418
				$this->config['default_email_message']
419
			);
420
421
			/**
422
			 * Filter the message.
423
			 *
424
			 * @since 2.0
425
			 */
426
			return apply_filters(
427
				"give_{$this->config['id']}_get_email_message",
428
				$message,
429
				$this,
430
				$form_id
431
			);
432
		}
433
434
435
		/**
436
		 * Get email content type.
437
		 *
438
		 * @since  2.0
439
		 * @access public
440
		 *
441
		 * @param $form_id
442
		 *
443
		 * @return string
444
		 */
445
		public function get_email_content_type( $form_id ) {
446
			$content_type = Give_Email_Notification_Util::get_value(
447
				$this,
448
				"{$this->config['id']}_email_content_type",
449
				$form_id,
450
				$this->config['content_type']
451
			);
452
453
			/**
454
			 * Filter the email content type.
455
			 *
456
			 * @since 2.0
457
			 */
458
			return apply_filters(
459
				"give_{$this->config['id']}_get_email_content_type",
460
				$content_type,
461
				$this,
462
				$form_id
463
			);
464
		}
465
466
		/**
467
		 * Get email template.
468
		 *
469
		 * @since  2.0
470
		 * @access public
471
		 *
472
		 * @param $form_id
473
		 *
474
		 * @return string
475
		 */
476
		public function get_email_template( $form_id ) {
477
			$content_type = Give_Email_Notification_Util::get_value(
478
				$this,
479
				"{$this->config['id']}_email_template",
480
				$form_id,
481
				$this->config['email_template']
482
			);
483
484
			/**
485
			 * Filter the email template.
486
			 *
487
			 * @since 2.0
488
			 */
489
			return apply_filters(
490
				"give_{$this->config['id']}_get_email_template",
491
				$content_type,
492
				$this,
493
				$form_id
494
			);
495
		}
496
497
498
		/**
499
		 * Get allowed email tags for current email notification.
500
		 *
501
		 * @since  2.0
502
		 * @access private
503
		 *
504
		 * @param bool $formatted
505
		 *
506
		 * @return array
0 ignored issues
show
Documentation introduced by
Should the return type not be string|array?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
507
		 */
508
		public function get_allowed_email_tags( $formatted = false ) {
509
			// Get all email tags.
510
			$email_tags = Give()->email_tags->get_tags();
511
512
			// Skip if all email template tags context setup exit.
513
			if ( $this->config['email_tag_context'] && 'all' !== $this->config['email_tag_context'] ) {
514
				if ( is_array( $this->config['email_tag_context'] ) ) {
515
					foreach ( $email_tags as $index => $email_tag ) {
516
						if ( in_array( $email_tag['context'], $this->config['email_tag_context'] ) ) {
517
							continue;
518
						}
519
520
						unset( $email_tags[ $index ] );
521
					}
522
				} else {
523
					foreach ( $email_tags as $index => $email_tag ) {
524
						if ( $this->config['email_tag_context'] === $email_tag['context'] ) {
525
							continue;
526
						}
527
528
						unset( $email_tags[ $index ] );
529
					}
530
				}
531
			}
532
533
			if ( count( $email_tags ) && $formatted ) : ob_start() ?>
534
				<div class="give-email-tags-wrap">
535
					<?php foreach ( $email_tags as $email_tag ) : ?>
536
						<span class="give_<?php echo $email_tag['tag']; ?>_tag">
537
							<code>{<?php echo $email_tag['tag']; ?>}</code> - <?php echo $email_tag['description']; ?>
538
						</span>
539
					<?php endforeach; ?>
540
				</div>
541
				<?php
542
				$email_tags = ob_get_clean();
543
			endif;
544
545
			return $email_tags;
546
		}
547
548
		/**
549
		 * Get preview email recipients.
550
		 *
551
		 * @since  2.0
552
		 * @access public
553
		 *
554
		 * @param int $form_id
555
		 *
556
		 * @return array|string
557
		 */
558
		public function get_preview_email_recipient( $form_id = null ) {
559
			$recipients = $this->get_recipient( $form_id );
560
561
			/**
562
			 * Filter the preview email recipients.
563
			 *
564
			 * @since 2.0
565
			 *
566
			 * @param string|array            $recipients List of recipients.
567
			 * @param Give_Email_Notification $this
568
			 */
569
			$recipients = apply_filters( 'give_get_preview_email_recipient', $recipients, $this, $form_id );
570
571
			return $recipients;
572
		}
573
574
		/**
575
		 * Get the recipient attachments.
576
		 *
577
		 * @since  2.0
578
		 * @access public
579
		 *
580
		 * @param int $form_id
581
		 *
582
		 * @return array
583
		 */
584
		public function get_email_attachments( $form_id = null ) {
585
			/**
586
			 * Filter the attachment.
587
			 *
588
			 * @since 2.0
589
			 */
590
			return apply_filters( "give_{$this->config['id']}_get_email_attachments", array(), $this, $form_id );
591
		}
592
593
594
		/**
595
		 * Send preview email.
596
		 *
597
		 * @since  2.0
598
		 * @access public
599
		 */
600
		public function send_preview_email() {
601
			// Get form id
602
			$form_id = ! empty( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : null;
603
604
			// setup email data.
605
			$this->setup_email_data();
606
607
			$attachments  = $this->get_email_attachments();
608
			$message      = $this->preview_email_template_tags( $this->get_email_message( $form_id ) );
609
			$subject      = $this->preview_email_template_tags( $this->get_email_subject( $form_id ) );
610
			$content_type = $this->get_email_content_type( $form_id );
611
612
			// Setup email content type.
613
			Give()->emails->__set( 'content_type', $content_type );
614
			Give()->emails->__set( 'html', true );
615
616
			// Setup email template
617
			Give()->emails->__set( 'template', $this->get_email_template( $form_id ) );
618
619
			// Format plain content type email.
620
			if ( 'text/plain' === $content_type ) {
621
				Give()->emails->__set( 'html', false );
622
				Give()->emails->__set( 'template', 'none' );
623
				$message = strip_tags( $message );
624
			}
625
626
			return Give()->emails->send( $this->get_preview_email_recipient( $form_id ), $subject, $message, $attachments );
627
		}
628
629
630
		/**
631
		 * Send email notification.
632
		 *
633
		 * Note: To render email tags in all context certain parameters are necessary for core (includes/emails/class-give-emails):
634
		 *    1. payment_id
635
		 *    2. user_id
636
		 *    3. form_id
637
		 *    4. donor_id
638
		 *    5. for third party email tags you can pass necessary param along above parameters other value replace by empty string.
639
		 *
640
		 * @since  2.0
641
		 * @access public
642
		 *
643
		 * @param array $email_tag_args Arguments which helps to decode email template tags.
644
		 *
645
		 * @return bool
646
		 */
647
		public function send_email_notification( $email_tag_args = array() ) {
648
			// Add email content type email tags.
649
			$email_tag_args['email_content_type'] = $this->config['content_type'];
650
651
			/**
652
			 * Filter the email tag args
653
			 *
654
			 * @since 2.0
655
			 */
656
			$email_tag_args = apply_filters( "give_{$this->config['id']}_email_tag_args", $email_tag_args, $this );
657
658
			// Get form id.
659
			$form_id = ! empty( $email_tag_args['form_id'] )
660
				? absint( $email_tag_args['form_id'] )
661
				: ( ! empty( $email_tag_args['payment_id'] ) ? give_get_payment_form_id( $email_tag_args['payment_id'] ) : null );
662
663
664
			// Do not send email if notification is disable.
665
			if ( ! Give_Email_Notification_Util::is_email_notification_active( $this, $form_id ) ) {
666
				return false;
667
			}
668
669
			/**
670
			 * Fire action after before email send.
671
			 *
672
			 * @since 2.0
673
			 */
674
			do_action( "give_{$this->config['id']}_email_send_before", $this, $form_id );
675
676
			$attachments  = $this->get_email_attachments();
677
			$message      = give_do_email_tags( $this->get_email_message( $form_id ), $email_tag_args );
678
			$subject      = give_do_email_tags( $this->get_email_subject( $form_id ), $email_tag_args );
679
			$content_type = $this->get_email_content_type( $form_id );
680
681
			// Setup email content type.
682
			Give()->emails->__set( 'content_type', $content_type );
683
			Give()->emails->__set( 'html', true );
684
685
			// Set email template.
686
			Give()->emails->__set( 'template', $this->get_email_template( $form_id ) );
687
688
			if ( 'text/plain' === $content_type ) {
689
				Give()->emails->__set( 'html', false );
690
				Give()->emails->__set( 'template', 'none' );
691
				$message = strip_tags( $message );
692
			}
693
694
			// Send email.
695
			$email_status = Give()->emails->send( $this->get_recipient( $form_id ), $subject, $message, $attachments );
696
697
			/**
698
			 * Fire action after after email send.
699
			 *
700
			 * @since 2.0
701
			 */
702
			do_action( "give_{$this->config['id']}_email_send_after", $email_status, $this, $form_id );
703
704
			return $email_status;
705
		}
706
707
708
		/**
709
		 * Decode preview email template tags.
710
		 *
711
		 * @since 2.0
712
		 *
713
		 * @param string $message
714
		 *
715
		 * @return string
716
		 */
717
		public function preview_email_template_tags( $message ) {
718
			// Set Payment.
719
			$payment_id = give_check_variable( give_clean( $_GET ), 'isset_empty', 0, 'preview_id' );
720
			$payment    = $payment_id ? new Give_Payment( $payment_id ) : new stdClass();
721
722
			// Set donor.
723
			$user_id = $payment_id
724
				? $payment->user_id
725
				: give_check_variable( give_clean( $_GET ), 'isset_empty', 0, 'user_id' );
726
			$user_id = $user_id ? $user_id : wp_get_current_user()->ID;
727
728
			// Set receipt.
729
			$receipt_id = strtolower( md5( uniqid() ) );
730
731
			$receipt_link_url = esc_url( add_query_arg( array(
732
				'payment_key' => $receipt_id,
733
				'give_action' => 'view_receipt',
734
			), home_url() ) );
735
736
			$receipt_link = sprintf(
737
				'<a href="%1$s">%2$s</a>',
738
				$receipt_link_url,
739
				esc_html__( 'View the receipt in your browser &raquo;', 'give' )
740
			);
741
742
			// Set default values for tags.
743
			$this->config['preview_email_tags_values'] = wp_parse_args(
744
				$this->config['preview_email_tags_values'],
745
				array(
746
					'name'              => give_email_tag_first_name( array(
747
						'payment_id' => $payment_id,
748
						'user_id'    => $user_id,
749
					) ),
750
					'fullname'          => give_email_tag_fullname( array(
751
						'payment_id' => $payment_id,
752
						'user_id'    => $user_id,
753
					) ),
754
					'username'          => give_email_tag_username( array(
755
						'payment_id' => $payment_id,
756
						'user_id'    => $user_id,
757
					) ),
758
					'user_email'        => give_email_tag_user_email( array(
759
						'payment_id' => $payment_id,
760
						'user_id'    => $user_id,
761
					) ),
762
					'payment_total'     => $payment_id ? give_email_tag_payment_total( array( 'payment_id' => $payment_id ) ) : give_currency_filter( '10.50' ),
763
					'amount'            => $payment_id ? give_email_tag_amount( array( 'payment_id' => $payment_id ) ) : give_currency_filter( '10.50' ),
764
					'price'             => $payment_id ? give_email_tag_price( array( 'payment_id' => $payment_id ) ) : give_currency_filter( '10.50' ),
765
					'payment_method'    => $payment_id ? give_email_tag_payment_method( array( 'payment_id' => $payment_id ) ) : __( 'PayPal', 'give' ),
766
					'receipt_id'        => $receipt_id,
767
					'payment_id'        => $payment_id ? $payment_id : rand( 2000, 2050 ),
768
					'receipt_link_url'  => $receipt_link_url,
769
					'receipt_link'      => $receipt_link,
770
					'date'              => $payment_id ? date( give_date_format(), strtotime( $payment->date ) ) : date( give_date_format(), current_time( 'timestamp' ) ),
771
					'donation'          => $payment_id ? give_email_tag_donation( array( 'payment_id' => $payment_id ) ) : esc_html__( 'Sample Donation Form Title', 'give' ),
772
					'form_title'        => $payment_id ? give_email_tag_form_title( array( 'payment_id' => $payment_id ) ) : esc_html__( 'Sample Donation Form Title - Sample Donation Level', 'give' ),
773
					'sitename'          => $payment_id ? give_email_tag_sitename( array( 'payment_id' => $payment_id ) ) : get_bloginfo( 'name' ),
774
					'pdf_receipt'       => '<a href="#">Download Receipt</a>',
775
					'billing_address'   => $payment_id ? give_email_tag_billing_address( array( 'payment_id' => $payment_id ) ) : '',
776
					'email_access_link' => sprintf(
777
						'<a href="%1$s">%2$s</a>',
778
						add_query_arg(
779
							array(
780
								'give_nl' => uniqid(),
781
							),
782
							get_permalink( give_get_option( 'history_page' ) )
783
						),
784
						__( 'Access Donation Details &raquo;', 'give' )
785
					),
786
				)
787
			);
788
789
			// Decode tags.
790
			foreach ( $this->config['preview_email_tags_values'] as $preview_tag => $value ) {
791
				if ( isset( $this->config['preview_email_tags_values'][ $preview_tag ] ) ) {
792
					$message = str_replace( "{{$preview_tag}}", $this->config['preview_email_tags_values'][ $preview_tag ], $message );
793
				}
794
			}
795
796
			return apply_filters( 'give_email_preview_template_tags', $message );
797
		}
798
799
		/**
800
		 * Setup email data
801
		 *
802
		 * @since 2.0
803
		 */
804
		public function setup_email_data() {
805
		}
806
	}
807
808
endif; // End class_exists check
809