Completed
Push — issues/611 ( fedd92...b4e0cb )
by Ravinder
20:08
created

Give_Email_Notification   C

Complexity

Total Complexity 69

Size/Duplication

Total Lines 768
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 6

Importance

Changes 0
Metric Value
dl 0
loc 768
rs 5
c 0
b 0
f 0
wmc 69
lcom 2
cbo 6

23 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 3 1
A get_instance() 0 8 3
D load() 0 36 8
B setup_filters() 0 45 3
A add_section() 0 5 1
A hide_section() 0 5 1
A add_setting_fields() 0 7 2
A get_setting_fields() 0 3 1
A add_metabox_setting_field() 0 10 1
A get_extra_setting_fields() 0 3 1
A get_recipient() 0 21 3
A get_notification_status() 0 17 2
A get_email_subject() 0 22 1
A get_email_message() 0 20 1
A get_email_content_type() 0 20 1
A get_email_template() 0 20 1
C get_allowed_email_tags() 0 39 11
A get_preview_email_recipient() 0 15 1
A get_email_attachments() 0 8 1
B send_preview_email() 0 28 3
B send_email_notification() 0 59 5
D preview_email_template_tags() 0 81 16
A setup_email_data() 0 2 1

How to fix   Complexity   

Complex Class

Complex classes like Give_Email_Notification often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Give_Email_Notification, and based on these observations, apply Extract Interface, too.

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
			'has_preview'                  => true,
54
			'has_preview_header'           => true,
55
			'preview_email_tags_values'    => array(),
56
			'email_tag_context'            => 'all',
57
			'form_metabox_setting'         => true,
58
			'content_type'                 => '',
59
			'email_template'               => '',
60
			'default_email_subject'        => '',
61
			'default_email_message'        => '',
62
		);
63
64
		/**
65
		 * @var     string $recipient_email Donor email.
66
		 * @access  protected
67
		 * @since   2.0
68
		 */
69
		protected $recipient_email = '';
70
71
72
		/**
73
		 * Setup email notification.
74
		 *
75
		 * @since 2.0
76
		 */
77
		public function init() {
78
79
		}
80
81
82
		/**
83
		 * Get instance.
84
		 *
85
		 * @since  2.0
86
		 * @access public
87
		 * @return Give_Email_Notification
88
		 */
89
		public static function get_instance() {
90
			$class = get_called_class();
91
			if ( ! array_key_exists( $class, self::$singleton ) || is_null( self::$singleton[ $class ] ) ) {
92
				self::$singleton[ $class ] = new $class();
93
			}
94
95
			return self::$singleton[ $class ];
96
		}
97
98
		/**
99
		 * Setup action and filters.
100
		 *
101
		 * @access  public
102
		 * @since   2.0
103
		 *
104
		 * @param array $config
105
		 */
106
		public function load( $config ) {
107
			// Set notification configuration.
108
			$this->config = wp_parse_args( $config, $this->config );
109
110
			// Set email preview header status.
111
			$this->config['has_preview_header'] = $this->config['has_preview'] && $this->config['has_preview_header'] ? true : false;
112
113
			// Set email content type
114
			$this->config['content_type'] = empty( $this->config['content_type'] ) || ! in_array( $this->config['content_type'], array( 'text/html', 'text/plain', ) )
115
				? Give()->emails->get_content_type()
116
				: $this->config['content_type'];
117
			$this->config['content_type'] = give_get_option( "{$this->config['id']}_email_content_type", $this->config['content_type'] );
118
119
			// Set email template type.
120
			$this->config['email_template'] = empty( $this->config['email_template'] )
121
				? give_get_option( 'email_template' )
122
				: $this->config['email_template'];
123
124
			// Set recipient group name.
125
			$this->config['recipient_group_name'] = empty( $this->config['recipient_group_name'] )
126
				? ( ! Give_Email_Notification_Util::has_recipient_field( $this ) ? __( 'Donor', 'give' ) : '' )
127
				: $this->config['recipient_group_name'];
128
129
			/**
130
			 *  Filter the notification config.
131
			 *
132
			 * @since 2.0
133
			 *
134
			 * @param                         array                   Give_Email_Notification::config
135
			 * @param Give_Email_Notification $this
136
			 */
137
			$this->config = apply_filters( 'give_email_api_notification_config', $this->config, $this );
138
139
			// Setup filters.
140
			$this->setup_filters();
141
		}
142
143
144
		/**
145
		 * Setup filters.
146
		 *
147
		 * @since  2.0
148
		 * @access public
149
		 */
150
		private function setup_filters() {
151
			// Apply filter only for current email notification section.
152
			if ( give_get_current_setting_section() === $this->config['id'] ) {
153
				// Initialize email context for email notification.
154
				$this->config['email_tag_context'] = apply_filters(
155
					"give_{$this->config['id']}_email_tag_context",
156
					$this->config['email_tag_context'],
157
					$this
158
				);
159
			}
160
161
			// Setup setting fields.
162
			add_filter( 'give_get_settings_emails', array( $this, 'add_setting_fields' ), 10, 2 );
163
164
			if ( $this->config['form_metabox_setting'] ) {
165
				add_filter(
166
					'give_email_notification_options_metabox_fields',
167
					array( $this, 'add_metabox_setting_field' ),
168
					10,
169
					2
170
				);
171
			}
172
173
			/**
174
			 * Filter the default email subject.
175
			 *
176
			 * @since 2.0
177
			 */
178
			$this->config['default_email_subject'] = apply_filters(
179
				"give_{$this->config['id']}_get_default_email_subject",
180
				$this->config['default_email_subject'],
181
				$this
182
			);
183
184
			/**
185
			 * Filter the default email message.
186
			 *
187
			 * @since 2.0
188
			 */
189
			$this->config['default_email_message'] = apply_filters(
190
				"give_{$this->config['id']}_get_default_email_message",
191
				$this->config['default_email_message'],
192
				$this
193
			);
194
		}
195
196
		/**
197
		 * Add sections.
198
		 *
199
		 * @since 2.0
200
		 *
201
		 * @param array $sections
202
		 *
203
		 * @return array
204
		 */
205
		public function add_section( $sections ) {
206
			$sections[ $this->config['id'] ] = $this->config['label'];
207
208
			return $sections;
209
		}
210
211
		/**
212
		 * Add sections.
213
		 *
214
		 * @since 2.0
215
		 *
216
		 * @param bool $hide_section
217
		 *
218
		 * @return bool
219
		 */
220
		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...
221
			$hide_section = true;
222
223
			return $hide_section;
224
		}
225
226
		/**
227
		 * Register email settings.
228
		 *
229
		 * @since  2.0
230
		 * @access public
231
		 *
232
		 * @param   array $settings
233
		 *
234
		 * @return  array
235
		 */
236
		public function add_setting_fields( $settings ) {
237
			if ( $this->config['id'] === give_get_current_setting_section() ) {
238
				$settings = $this->get_setting_fields();
239
			}
240
241
			return $settings;
242
		}
243
244
245
		/**
246
		 * Get setting fields
247
		 *
248
		 * @since  2.0
249
		 * @access public
250
		 *
251
		 * @param int $form_id
252
		 *
253
		 * @return array
254
		 */
255
		public function get_setting_fields( $form_id = null ) {
256
			return Give_Email_Setting_Field::get_setting_fields( $this, $form_id );
257
		}
258
259
260
		/**
261
		 * Register email settings to form metabox.
262
		 *
263
		 * @since  2.0
264
		 * @access public
265
		 *
266
		 * @param array $settings
267
		 * @param int   $form_id
268
		 *
269
		 * @return array
270
		 */
271
		public function add_metabox_setting_field( $settings, $form_id ) {
272
273
			$settings[] = array(
274
				'id'     => $this->config['id'],
275
				'title'  => $this->config['label'],
276
				'fields' => $this->get_setting_fields( $form_id ),
277
			);
278
279
			return $settings;
280
		}
281
282
283
		/**
284
		 * Get extra setting field.
285
		 *
286
		 * @since  2.0
287
		 * @access public
288
		 *
289
		 * @param int $form_id
290
		 *
291
		 * @return array
292
		 */
293
		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...
294
			return array();
295
		}
296
297
298
		/**
299
		 * Get recipient(s).
300
		 *
301
		 * Note: in case of admin notification this fx will return array of emails otherwise empty string or email of donor.
302
		 *
303
		 * @since  2.0
304
		 * @access public
305
		 *
306
		 * @param int $form_id
307
		 *
308
		 * @return string|array
309
		 */
310
		public function get_recipient( $form_id = null ) {
311
			if ( empty( $this->recipient_email ) && $this->config['has_recipient_field'] ) {
312
				$this->recipient_email = Give_Email_Notification_Util::get_value( $this, "{$this->config['id']}_recipient", $form_id );
313
			}
314
315
			/**
316
			 * Filter the recipients
317
			 *
318
			 * @since 2.0
319
			 */
320
			return apply_filters(
321
				"give_{$this->config['id']}_get_recipients",
322
				give_check_variable(
323
					$this->recipient_email,
324
					'empty',
325
					Give()->emails->get_from_address()
326
				),
327
				$this,
328
				$form_id
329
			);
330
		}
331
332
		/**
333
		 * Get notification status.
334
		 *
335
		 * @since  2.0
336
		 * @access public
337
		 *
338
		 * @param int $form_id
339
		 *
340
		 * @return bool
341
		 */
342
		public function get_notification_status( $form_id = null ) {
343
			$notification_status = empty( $form_id )
344
				? give_get_option( "{$this->config['id']}_notification", $this->config['notification_status'] )
345
				: get_post_meta( $form_id,"{$this->config['id']}_notification", true  );
346
347
			/**
348
			 * Filter the notification status.
349
			 *
350
			 * @since 1.8
351
			 */
352
			return apply_filters(
353
				"give_{$this->config['id']}_get_notification_status",
354
				$notification_status,
355
				$this,
356
				$form_id
357
			);
358
		}
359
360
		/**
361
		 * Get email subject.
362
		 *
363
		 * @since  2.0
364
		 * @access public
365
		 *
366
		 * @param int $form_id
367
		 *
368
		 * @return string
369
		 */
370
		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...
371
			$subject = wp_strip_all_tags(
372
				Give_Email_Notification_Util::get_value(
373
					$this,
374
					"{$this->config['id']}_email_subject",
375
					$form_id,
376
					$this->config['default_email_subject']
377
				)
378
			);
379
380
			/**
381
			 * Filter the subject.
382
			 *
383
			 * @since 2.0
384
			 */
385
			return apply_filters(
386
				"give_{$this->config['id']}_get_email_subject",
387
				$subject,
388
				$this,
389
				$form_id
390
			);
391
		}
392
393
		/**
394
		 * Get email message.
395
		 *
396
		 * @since  2.0
397
		 * @access public
398
		 *
399
		 * @param int $form_id
400
		 *
401
		 * @return string
402
		 */
403
		public function get_email_message( $form_id = null ) {
404
			$message = Give_Email_Notification_Util::get_value(
405
				$this,
406
				"{$this->config['id']}_email_message",
407
				$form_id,
408
				$this->config['default_email_message']
409
			);
410
411
			/**
412
			 * Filter the message.
413
			 *
414
			 * @since 2.0
415
			 */
416
			return apply_filters(
417
				"give_{$this->config['id']}_get_email_message",
418
				$message,
419
				$this,
420
				$form_id
421
			);
422
		}
423
424
425
		/**
426
		 * Get email content type.
427
		 *
428
		 * @since 2.0
429
		 * @access public
430
		 *
431
		 * @param $form_id
432
		 *
433
		 * @return string
434
		 */
435
		public function get_email_content_type( $form_id ) {
436
			$content_type = Give_Email_Notification_Util::get_value(
437
				$this,
438
				"{$this->config['id']}_email_content_type",
439
				$form_id,
440
				$this->config['content_type']
441
			);
442
443
			/**
444
			 * Filter the email content type.
445
			 *
446
			 * @since 2.0
447
			 */
448
			return apply_filters(
449
				"give_{$this->config['id']}_get_email_content_type",
450
				$content_type,
451
				$this,
452
				$form_id
453
			);
454
		}
455
456
		/**
457
		 * Get email template.
458
		 *
459
		 * @since 2.0
460
		 * @access public
461
		 *
462
		 * @param $form_id
463
		 *
464
		 * @return string
465
		 */
466
		public function get_email_template( $form_id ) {
467
			$content_type = Give_Email_Notification_Util::get_value(
468
				$this,
469
				"{$this->config['id']}_email_template",
470
				$form_id,
471
				$this->config['email_template']
472
			);
473
474
			/**
475
			 * Filter the email template.
476
			 *
477
			 * @since 2.0
478
			 */
479
			return apply_filters(
480
				"give_{$this->config['id']}_get_email_template",
481
				$content_type,
482
				$this,
483
				$form_id
484
			);
485
		}
486
487
488
		/**
489
		 * Get allowed email tags for current email notification.
490
		 *
491
		 * @since  2.0
492
		 * @access private
493
		 *
494
		 * @param bool $formatted
495
		 *
496
		 * @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...
497
		 */
498
		public function get_allowed_email_tags( $formatted = false ) {
499
			// Get all email tags.
500
			$email_tags = Give()->email_tags->get_tags();
501
502
			// Skip if all email template tags context setup exit.
503
			if ( $this->config['email_tag_context'] && 'all' !== $this->config['email_tag_context'] ) {
504
				if ( is_array( $this->config['email_tag_context'] ) ) {
505
					foreach ( $email_tags as $index => $email_tag ) {
506
						if ( in_array( $email_tag['context'], $this->config['email_tag_context'] ) ) {
507
							continue;
508
						}
509
510
						unset( $email_tags[ $index ] );
511
					}
512
				} else {
513
					foreach ( $email_tags as $index => $email_tag ) {
514
						if ( $this->config['email_tag_context'] === $email_tag['context'] ) {
515
							continue;
516
						}
517
518
						unset( $email_tags[ $index ] );
519
					}
520
				}
521
			}
522
523
			if ( count( $email_tags ) && $formatted ) : ob_start() ?>
524
				<div class="give-email-tags-wrap">
525
					<?php foreach ( $email_tags as $email_tag ) : ?>
526
						<span class="give_<?php echo $email_tag['tag']; ?>_tag">
527
							<code>{<?php echo $email_tag['tag']; ?>}</code> - <?php echo $email_tag['description']; ?>
528
						</span>
529
					<?php endforeach; ?>
530
				</div>
531
				<?php
532
				$email_tags = ob_get_clean();
533
			endif;
534
535
			return $email_tags;
536
		}
537
538
		/**
539
		 * Get preview email recipients.
540
		 *
541
		 * @since  2.0
542
		 * @access public
543
		 *
544
		 * @param int $form_id
545
		 * @return array|string
546
		 */
547
		public function get_preview_email_recipient( $form_id = null ) {
548
			$recipients = $this->get_recipient( $form_id );
549
550
			/**
551
			 * Filter the preview email recipients.
552
			 *
553
			 * @since 2.0
554
			 *
555
			 * @param string|array            $recipients List of recipients.
556
			 * @param Give_Email_Notification $this
557
			 */
558
			$recipients = apply_filters( 'give_get_preview_email_recipient', $recipients, $this, $form_id );
559
560
			return $recipients;
561
		}
562
563
		/**
564
		 * Get the recipient attachments.
565
		 *
566
		 * @since  2.0
567
		 * @access public
568
		 *
569
		 * @param int $form_id
570
		 * @return array
571
		 */
572
		public function get_email_attachments( $form_id = null ) {
573
			/**
574
			 * Filter the attachment.
575
			 *
576
			 * @since 2.0
577
			 */
578
			return apply_filters( "give_{$this->config['id']}_get_email_attachments", array(), $this, $form_id );
579
		}
580
581
582
		/**
583
		 * Send preview email.
584
		 *
585
		 * @since  2.0
586
		 * @access public
587
		 */
588
		public function send_preview_email() {
589
			// Get form id
590
			$form_id = ! empty( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : null;
591
592
			// setup email data.
593
			$this->setup_email_data();
594
595
			$attachments  = $this->get_email_attachments();
596
			$message      = $this->preview_email_template_tags( $this->get_email_message( $form_id ) );
597
			$subject      = $this->preview_email_template_tags( $this->get_email_subject( $form_id ) );
598
			$content_type = $this->get_email_content_type( $form_id );
599
600
			// Setup email content type.
601
			Give()->emails->__set( 'content_type', $content_type );
602
			Give()->emails->__set( 'html', true );
603
604
			// Setup email template
605
			Give()->emails->__set( 'template', $this->get_email_template( $form_id ) );
606
607
			// Format plain content type email.
608
			if ( 'text/plain' === $content_type ) {
609
				Give()->emails->__set( 'html', false );
610
				Give()->emails->__set( 'template', 'none' );
611
				$message = strip_tags( $message );
612
			}
613
614
			return Give()->emails->send( $this->get_preview_email_recipient( $form_id ), $subject, $message, $attachments );
615
		}
616
617
618
		/**
619
		 * Send email notification.
620
		 *
621
		 * Note: To render email tags in all context certain parameters are necessary for core (includes/emails/class-give-emails):
622
		 * 	1. payment_id
623
		 * 	2. user_id
624
		 * 	3. form_id
625
		 * 	4. donor_id
626
		 * 	5. for third party email tags you can pass necessary param along above parameters other value replace by empty string.
627
		 *
628
		 * @since  2.0
629
		 * @access public
630
		 *
631
		 * @param array $email_tag_args Arguments which helps to decode email template tags.
632
		 *
633
		 * @return bool
634
		 */
635
		public function send_email_notification( $email_tag_args = array() ) {
636
			// Add email content type email tags.
637
			$email_tag_args['email_content_type'] = $this->config['content_type'];
638
639
			/**
640
			 * Filter the email tag args
641
			 *
642
			 * @since 2.0
643
			 */
644
			$email_tag_args = apply_filters( "give_{$this->config['id']}_email_tag_args", $email_tag_args, $this );
645
646
			// Get form id.
647
			$form_id = ! empty( $email_tag_args['form_id'] )
648
				? absint( $email_tag_args['form_id'] )
649
				: ( ! empty( $email_tag_args['payment_id'] ) ? give_get_payment_form_id( $email_tag_args['payment_id'] ) : null );
650
651
652
			// Do not send email if notification is disable.
653
			if ( ! Give_Email_Notification_Util::is_email_notification_active( $this, $form_id ) ) {
654
				return false;
655
			}
656
657
			/**
658
			 * Fire action after before email send.
659
			 *
660
			 * @since 2.0
661
			 */
662
			do_action( "give_{$this->config['id']}_email_send_before", $this, $form_id );
663
664
			$attachments  = $this->get_email_attachments();
665
			$message      = give_do_email_tags( $this->get_email_message( $form_id ), $email_tag_args );
666
			$subject      = give_do_email_tags( $this->get_email_subject( $form_id ), $email_tag_args );
667
			$content_type = $this->get_email_content_type( $form_id );
668
669
			// Setup email content type.
670
			Give()->emails->__set( 'content_type', $content_type );
671
			Give()->emails->__set( 'html', true );
672
673
			// Set email template.
674
			Give()->emails->__set( 'template', $this->get_email_template( $form_id ) );
675
676
			if ( 'text/plain' === $content_type ) {
677
				Give()->emails->__set( 'html', false );
678
				Give()->emails->__set( 'template', 'none' );
679
				$message = strip_tags( $message );
680
			}
681
682
			// Send email.
683
			$email_status = Give()->emails->send( $this->get_recipient( $form_id ), $subject, $message, $attachments );
684
685
			/**
686
			 * Fire action after after email send.
687
			 *
688
			 * @since 2.0
689
			 */
690
			do_action( "give_{$this->config['id']}_email_send_after", $email_status, $this, $form_id );
691
692
			return $email_status;
693
		}
694
695
696
		/**
697
		 * Decode preview email template tags.
698
		 *
699
		 * @since 2.0
700
		 *
701
		 * @param string $message
702
		 *
703
		 * @return string
704
		 */
705
		public function preview_email_template_tags( $message ) {
706
			// Set Payment.
707
			$payment_id = give_check_variable( give_clean( $_GET ), 'isset_empty', 0, 'preview_id' );
708
			$payment    = $payment_id ? new Give_Payment( $payment_id ) : new stdClass();
709
710
			// Set donor.
711
			$user_id = $payment_id
712
				? $payment->user_id
713
				: give_check_variable( give_clean( $_GET ), 'isset_empty', 0, 'user_id' );
714
			$user_id = $user_id ? $user_id : wp_get_current_user()->ID;
715
716
			// Set receipt.
717
			$receipt_id = strtolower( md5( uniqid() ) );
718
719
			$receipt_link_url = esc_url( add_query_arg( array(
720
				'payment_key' => $receipt_id,
721
				'give_action' => 'view_receipt',
722
			), home_url() ) );
723
724
			$receipt_link = sprintf(
725
				'<a href="%1$s">%2$s</a>',
726
				$receipt_link_url,
727
				esc_html__( 'View the receipt in your browser &raquo;', 'give' )
728
			);
729
730
			// Set default values for tags.
731
			$this->config['preview_email_tags_values'] = wp_parse_args(
732
				$this->config['preview_email_tags_values'],
733
				array(
734
					'name'              => give_email_tag_first_name( array(
735
						'payment_id' => $payment_id,
736
						'user_id'    => $user_id,
737
					) ),
738
					'fullname'          => give_email_tag_fullname( array(
739
						'payment_id' => $payment_id,
740
						'user_id'    => $user_id,
741
					) ),
742
					'username'          => give_email_tag_username( array(
743
						'payment_id' => $payment_id,
744
						'user_id'    => $user_id,
745
					) ),
746
					'user_email'        => give_email_tag_user_email( array(
747
						'payment_id' => $payment_id,
748
						'user_id'    => $user_id,
749
					) ),
750
					'payment_total'     => $payment_id ? give_email_tag_payment_total( array( 'payment_id' => $payment_id ) ) : give_currency_filter( '10.50' ),
751
					'amount'            => $payment_id ? give_email_tag_amount( array( 'payment_id' => $payment_id ) ) : give_currency_filter( '10.50' ),
752
					'price'             => $payment_id ? give_email_tag_price( array( 'payment_id' => $payment_id ) ) : give_currency_filter( '10.50' ),
753
					'payment_method'    => $payment_id ? give_email_tag_payment_method( array( 'payment_id' => $payment_id ) ) : __( 'PayPal', 'give' ),
754
					'receipt_id'        => $receipt_id,
755
					'payment_id'        => $payment_id ? $payment_id : rand( 2000, 2050 ),
756
					'receipt_link_url'  => $receipt_link_url,
757
					'receipt_link'      => $receipt_link,
758
					'date'              => $payment_id ? date( give_date_format(), strtotime( $payment->date ) ) : date( give_date_format(), current_time( 'timestamp' ) ),
759
					'donation'          => $payment_id ? give_email_tag_donation( array( 'payment_id' => $payment_id ) ) : esc_html__( 'Sample Donation Form Title', 'give' ),
760
					'form_title'        => $payment_id ? give_email_tag_form_title( array( 'payment_id' => $payment_id ) ) : esc_html__( 'Sample Donation Form Title - Sample Donation Level', 'give' ),
761
					'sitename'          => $payment_id ? give_email_tag_sitename( array( 'payment_id' => $payment_id ) ) : get_bloginfo( 'name' ),
762
					'pdf_receipt'       => '<a href="#">Download Receipt</a>',
763
					'billing_address'   => $payment_id ? give_email_tag_billing_address( array( 'payment_id' => $payment_id ) ) : '',
764
					'email_access_link' => sprintf(
765
						'<a href="%1$s">%2$s</a>',
766
						add_query_arg(
767
							array(
768
								'give_nl' => uniqid(),
769
							),
770
							get_permalink( give_get_option( 'history_page' ) )
771
						),
772
						__( 'Access Donation Details &raquo;', 'give' )
773
					),
774
				)
775
			);
776
777
			// Decode tags.
778
			foreach ( $this->config['preview_email_tags_values'] as $preview_tag => $value ) {
779
				if ( isset( $this->config['preview_email_tags_values'][ $preview_tag ] ) ) {
780
					$message = str_replace( "{{$preview_tag}}", $this->config['preview_email_tags_values'][ $preview_tag ], $message );
781
				}
782
			}
783
784
			return apply_filters( 'give_email_preview_template_tags', $message );
785
		}
786
787
		/**
788
		 * Setup email data
789
		 *
790
		 * @since 2.0
791
		 */
792
		public function setup_email_data() {
793
		}
794
	}
795
796
endif; // End class_exists check
797