Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/tutor-pro/classes/Mailer.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
/**
3
+
* A helper class to send e-mail.
4
+
*
5
+
* @package TutorPro
6
+
* @author Themeum <support@themeum.com>
7
+
* @link https://themeum.com
8
+
* @since 2.1.9
9
+
*/
10
+
11
+
namespace TUTOR_PRO;
12
+
13
+
if ( ! defined( 'ABSPATH' ) ) {
14
+
exit;
15
+
}
16
+
17
+
/**
18
+
* Mailer Class
19
+
*
20
+
* @since 2.1.9
21
+
*/
22
+
class Mailer {
23
+
24
+
/**
25
+
* Send e-mail
26
+
*
27
+
* @since 2.1.9
28
+
*
29
+
* @param string|string[] $to single/multiple e-mail address.
30
+
* @param string $subject e-mail subject.
31
+
* @param string $message e-mail body message.
32
+
* @param string|string[] $header set single/multiple additional header.
33
+
* @param string|string[] $attachments single/multiple attachments where each are absolute file path.
34
+
*
35
+
* @return bool|array if single to address it returns bool
36
+
* for multiple address it returns assoc array.
37
+
* ex: array( 'jhon@ex.com' => true, 'adam@ex.com' => false )
38
+
*/
39
+
public static function send_mail( $to, $subject, $message, $header = '', $attachments = array() ) {
40
+
$obj = new self();
41
+
$is_enabled = tutils()->is_addon_enabled( TUTOR_EMAIL()->basename );
42
+
43
+
add_filter( 'wp_mail_content_type', array( $obj, 'get_content_type' ) );
44
+
45
+
if ( $is_enabled ) {
46
+
add_filter( 'wp_mail_from', array( $obj, 'get_from_address' ) );
47
+
add_filter( 'wp_mail_from_name', array( $obj, 'get_from_name' ) );
48
+
}
49
+
50
+
$to_array = is_array( $to ) ? $to : array( $to );
51
+
$return = array();
52
+
foreach ( $to_array as $email ) {
53
+
do_action( 'tutor_pro_before_prepare_email_template_data', $email );
54
+
$return[ $email ] = wp_mail( $email, $subject, $message, $header, $attachments );
55
+
do_action( 'tutor_pro_after_prepare_template_email_data' );
56
+
}
57
+
58
+
remove_filter( 'wp_mail_content_type', array( $obj, 'get_content_type' ) );
59
+
60
+
if ( $is_enabled ) {
61
+
remove_filter( 'wp_mail_from', array( $obj, 'get_from_address' ) );
62
+
remove_filter( 'wp_mail_from_name', array( $obj, 'get_from_name' ) );
63
+
}
64
+
65
+
return is_array( $to ) ? $return : $return[ $to ];
66
+
}
67
+
68
+
/**
69
+
* Prepare HTML e-mail template with replaceable data.
70
+
*
71
+
* @since 2.1.9
72
+
*
73
+
* @param string $template_path e-mail html template path.
74
+
* @param array $data an assoc array contains replaceable key and value.
75
+
*
76
+
* @return string prepared message.
77
+
*/
78
+
public static function prepare_template( string $template_path, array $data = array() ) {
79
+
if ( ! file_exists( $template_path ) || ! tutils()->is_assoc( $data ) ) {
80
+
return '';
81
+
}
82
+
83
+
ob_start();
84
+
include $template_path;
85
+
$string = ob_get_clean();
86
+
87
+
return str_replace( array_keys( $data ), array_values( $data ), $string );
88
+
}
89
+
90
+
/**
91
+
* Get the from name for outgoing emails from tutor.
92
+
*
93
+
* @since 2.1.9
94
+
*
95
+
* @param string $from_email email from e-mail address.
96
+
*
97
+
* @return string
98
+
*/
99
+
public function get_from_address( $from_email ) {
100
+
$email = tutor_utils()->get_option( 'email_from_address' );
101
+
if ( empty( $email ) ) {
102
+
$email = $from_email;
103
+
}
104
+
return sanitize_email( $email );
105
+
}
106
+
107
+
/**
108
+
* Get the from name for outgoing emails from tutor
109
+
*
110
+
* @since 2.1.9
111
+
*
112
+
* @param string $from_name from name of email.
113
+
*
114
+
* @return string
115
+
*/
116
+
public function get_from_name( $from_name ) {
117
+
$name = tutor_utils()->get_option( 'email_from_name' );
118
+
if ( empty( $name ) ) {
119
+
$name = $from_name;
120
+
}
121
+
return wp_specialchars_decode( esc_html( $name ), ENT_QUOTES );
122
+
}
123
+
124
+
/**
125
+
* Filter callback to set email content type.
126
+
*
127
+
* @since 2.1.9
128
+
*
129
+
* @return string
130
+
*/
131
+
public function get_content_type() {
132
+
return 'text/html';
133
+
}
134
+
}
135
+