| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
die( 'You are not allowed to call this page directly.' ); |
| 4 |
} |
| 5 |
|
| 6 |
class FrmNotification { |
| 7 |
public function __construct() { |
| 8 |
self::hook_emails_to_action(); |
| 9 |
} |
| 10 |
|
| 11 |
/** |
| 12 |
* Trigger an email action |
| 13 |
* |
| 14 |
* @param object $action |
| 15 |
* @param object $entry |
| 16 |
* @param object $form |
| 17 |
* |
| 18 |
* @return void |
| 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 |
* @return void |
| 40 |
*/ |
| 41 |
public static function stop_emails() { |
| 42 |
remove_action( 'frm_trigger_email_action', 'FrmNotification::trigger_email', 10 ); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Hook the trigger_email function to frm_trigger_email_action action |
| 47 |
* |
| 48 |
* @since 2.03.04 |
| 49 |
* |
| 50 |
* @return void |
| 51 |
*/ |
| 52 |
public static function hook_emails_to_action() { |
| 53 |
add_action( 'frm_trigger_email_action', 'FrmNotification::trigger_email', 10, 3 ); |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Print the recipients |
| 58 |
* |
| 59 |
* @since 2.03.04 |
| 60 |
* |
| 61 |
* @param array $atts |
| 62 |
* |
| 63 |
* @return void |
| 64 |
*/ |
| 65 |
private static function print_recipients( $atts ) { |
| 66 |
if ( ! apply_filters( 'frm_echo_emails', false ) ) { |
| 67 |
return; |
| 68 |
} |
| 69 |
|
| 70 |
$sent_to = array_merge( (array) $atts['to_email'], (array) $atts['cc'], (array) $atts['bcc'] ); |
| 71 |
$sent_to = array_filter( $sent_to ); |
| 72 |
$temp = str_replace( '<', '<', $sent_to ); |
| 73 |
echo ' '; |
| 74 |
FrmAppHelper::kses_echo( implode( ', ', $temp ) ); |
| 75 |
} |
| 76 |
} |
| 77 |
|