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( '<', '<', $sent_to ); |
66
|
|
|
echo ' ' . FrmAppHelper::kses( implode( ', ', (array) $temp ) ); |
|
|
|
|
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
|
|
|
|