Completed
Push — master ( c7decf...185c12 )
by Jamie
11s
created

FrmNotification::hook_emails_to_action()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
// TODO: change class name to FrmEmailController by 08/2017 or later
4
class FrmNotification {
5
	public function __construct() {
6
		if ( ! defined( 'ABSPATH' ) ) {
7
			die( 'You are not allowed to call this page directly.' );
8
		}
9
10
		self::hook_emails_to_action();
11
	}
12
13
	/**
14
	 * Trigger an email action
15
	 *
16
	 * @param object $action
17
	 * @param object $entry
18
	 * @param object $form
19
	 */
20
	public static function trigger_email( $action, $entry, $form ) {
21
		$email = new FrmEmail( $action, $entry, $form );
22
23
		if ( ! $email->should_send() ) {
24
			return;
25
		}
26
27
		$sent = $email->send();
28
29
		if ( $sent ) {
30
			self::print_recipients( $email->package_atts() );
31
		}
32
	}
33
34
	/**
35
	 * Remove the trigger_email function from the frm_trigger_email_action hook
36
	 *
37
	 * @since 2.03.04
38
	 */
39
	public static function stop_emails() {
40
		remove_action( 'frm_trigger_email_action', 'FrmNotification::trigger_email', 10 );
41
	}
42
43
	/**
44
	 * Hook the trigger_email function to frm_trigger_email_action action
45
	 *
46
	 * @since 2.03.04
47
	 */
48
	public static function hook_emails_to_action() {
49
		add_action( 'frm_trigger_email_action', 'FrmNotification::trigger_email', 10, 3 );
50
	}
51
52
	/**
53
	 * Print the recipients
54
	 *
55
	 * @since 2.03.04
56
	 *
57
	 * @param array $atts
58
	 */
59
	private static function print_recipients( $atts ) {
60
		if ( apply_filters( 'frm_echo_emails', false ) ) {
61
62
			$sent_to = array_merge( (array) $atts['to_email'], (array) $atts['cc'], (array) $atts['bcc'] );
63
			$sent_to = array_filter( $sent_to );
64
65
			$temp = str_replace( '<', '&lt;', $sent_to );
66
			echo ' ' . FrmAppHelper::kses( implode( ', ', (array) $temp ) );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'FrmAppHelper'
Loading history...
67
		}
68
	}
69
70
	/**
71
	 * @deprecated 2.03.04
72
	 */
73
	public static function remove_mandrill_br() {
74
		_deprecated_function( __FUNCTION__, '2.03.04', 'FrmEmailHelper::remove_mandrill_br' );
75
		return FrmEmailHelper::remove_mandrill_br();
76
	}
77
78
	/**
79
	 * @deprecated 2.03.04
80
	 */
81
	public static function send_email() {
82
		_deprecated_function( __FUNCTION__, '2.03.04', 'FrmEmail::send' );
83
	}
84
}
85