PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.3.4
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.3.4
1.2.72 1.2.71 1.2.70 1.2.69 1.2.68 1.2.67 1.2.66 1.2.65 1.2.64 1.2.63 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.23 All 172 releases
userswp / includes / class-emails.php

class-emails.php in UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP 1.2.3.4, at includes/class-emails.php

721 lines 22.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Mails related functions
4 *
5 * All UsersWP related mails are sent via this class.
6 *
7 * @since 1.0.0
8 * @author GeoDirectory Team <info@wpgeodirectory.com>
9 */
10 class UsersWP_Mails {
11
12 /**
13 * Constructor.
14 */
15 public function __construct() {
16
17 add_action( 'uwp_email_header', array( $this, 'email_header' ), 10, 5 );
18 add_action( 'uwp_email_footer', array( $this, 'email_footer' ), 10, 4 );
19 add_action( 'wp_new_user_notification_email', array( $this, 'wp_new_user_notification_email' ), 10, 2 );
20 add_action( 'wp_new_user_notification_email_admin', array( $this, 'wp_new_user_notification_email_admin' ), 10, 2 );
21
22 }
23
24 /**
25 * Get the email logo.
26 *
27 * @since 1.2.1.2
28 *
29 * @return string Logo url.
30 */
31 public static function get_email_logo( $size = 'full' ) {
32 $attachment_id = uwp_get_option( 'email_logo' );
33
34 $email_logo = '';
35 if ( ! empty( $attachment_id ) ) {
36 $email_logo = wp_get_attachment_image( $attachment_id, $size );
37 }
38
39 return apply_filters( 'uwp_get_email_logo', $email_logo, $attachment_id, $size );
40 }
41
42 /**
43 * The default email footer text.
44 *
45 * @since 1.2.1.2
46 *
47 * @return string
48 */
49 public static function email_header_text(){
50 $header_text = self::get_email_logo();
51
52 if ( empty( $header_text ) ) {
53 $header_text = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
54 }
55
56 return apply_filters( 'uwp_email_header_text', $header_text );
57 }
58
59 /**
60 * Get the email header template.
61 *
62 * @since 1.2.1.2
63 *
64 * @param string $email_heading
65 * @param string $email_name
66 * @param array $email_vars
67 * @param bool $plain_text
68 * @param bool $sent_to_admin
69 */
70 public static function email_header( $email_heading = '', $email_name = '', $email_vars = array(), $plain_text = false, $sent_to_admin = false ) {
71 if ( ! $plain_text ) {
72 $header_text = self::email_header_text();
73 $header_text = $header_text ? wpautop( wp_kses_post( wptexturize( $header_text ) ) ) : '';
74
75 uwp_get_template( 'emails/uwp-email-header.php', array(
76 'email_heading' => $email_heading,
77 'email_name' => $email_name,
78 'email_vars' => $email_vars,
79 'plain_text' => $plain_text,
80 'header_text' => $header_text,
81 'sent_to_admin' => $sent_to_admin
82 ) );
83 }
84 }
85
86 /**
87 * The default email footer text.
88 *
89 * @since 1.2.1.2
90 * @return string
91 */
92 public static function email_footer_text(){
93 $footer_text = uwp_get_option( 'email_footer_text' );
94
95 if ( empty( $footer_text ) ) {
96 $footer_text = wp_sprintf( __( '%s - Powered by UsersWP', 'userswp' ), get_bloginfo( 'name', 'display' ) );
97 }
98
99 return apply_filters( 'uwp_email_footer_text', $footer_text );
100 }
101
102 /**
103 * Get the email footer template.
104 *
105 * @since 1.2.1.2
106 *
107 * @param string $email_name
108 * @param array $email_vars
109 * @param bool $plain_text
110 * @param bool $sent_to_admin
111 */
112 public static function email_footer( $email_name = '', $email_vars = array(), $plain_text = false, $sent_to_admin = false ) {
113 if ( ! $plain_text ) {
114 $footer_text = self::email_footer_text();
115 $footer_text = $footer_text ? wpautop( wp_kses_post( wptexturize( $footer_text ) ) ) : '';
116
117 uwp_get_template( 'emails/uwp-email-footer.php', array(
118 'email_name' => $email_name,
119 'email_vars' => $email_vars,
120 'email_heading' => '',
121 'plain_text' => $plain_text,
122 'footer_text' => $footer_text,
123 'sent_to_admin' => $sent_to_admin
124 ) );
125 }
126 }
127
128 /**
129 * Get the email message wraped in the header and footer.
130 *
131 * @since 1.2.1.2
132 *
133 * @param string $message Message.
134 * @param string $email_name Optional. Email name. Default null.
135 * @param array $email_vars Optional. Email vars. Default array.
136 * @param string $email_heading Optional. Email header. Default null.
137 * @param bool $plain_text Optional. Plain text. Default false.
138 * @param bool $sent_to_admin Optional. Send to admin. Default false.
139 *
140 * @return string $message.
141 */
142 public static function email_wrap_message( $message, $email_name = '', $email_vars = array(), $email_heading = '', $plain_text = false, $sent_to_admin = false ) {
143 // Buffer
144 ob_start();
145
146 if ( $plain_text ) {
147 echo wp_strip_all_tags( $message );
148 } else {
149 do_action( 'uwp_email_header', $email_heading, $email_name, $email_vars, $plain_text, $sent_to_admin );
150
151 echo wpautop( wptexturize( $message ) );
152
153 do_action( 'uwp_email_footer', $email_name, $email_vars, $plain_text, $sent_to_admin );
154 }
155
156 // Get contents
157 $message = ob_get_clean();
158
159 return $message;
160 }
161
162 /**
163 * Check if the email is enabled for the email type.
164 *
165 * @since 1.2.1.2
166 *
167 * @param string $email_name Email name.
168 * @param string $default Optional. Default option value. Default null.
169 * @param bool $is_admin Optional. Admin email. Default false.
170 *
171 * @return string
172 */
173 public static function is_email_enabled( $email_name, $default = '', $is_admin = false ) {
174 if($is_admin){
175 $key = $email_name . '_email_admin';
176 } else {
177 $key = $email_name . '_email';
178 }
179
180 switch ( $email_name ) {
181 // TODO add some cases
182 default:
183 $active = uwp_get_option( $key , $default);
184 $active = $active === 'yes' || $active == '1' ? true : false;
185 break;
186 }
187
188 return apply_filters( 'uwp_email_is_enabled', $active, $email_name );
189 }
190
191 /**
192 * Get the email subject by type.
193 *
194 * @since 1.2.1.2
195 *
196 * @param string $email_name Optional. Email name. Default null.
197 * @param array $email_vars Optional. Email vars. Default array.
198 * @param bool $is_admin Optional. Admin email. Default false.
199 *
200 * @return string
201 */
202 public static function get_subject( $email_name = '', $email_vars = array(), $is_admin = false ) {
203 if($is_admin){
204 $key = $email_name . '_email_subject_admin';
205 } else {
206 $key = $email_name . '_email_subject';
207 }
208
209 switch ( $email_name ) {
210 // TODO some custom options
211 default:
212 $subject = uwp_get_option( $key );
213 break;
214
215 }
216
217 // Get the default text is empty
218 if(!$subject && method_exists('UsersWP_Defaults', $key)){
219 $subject = UsersWP_Defaults::$key();
220 }
221
222 if ( !$subject ) {
223 // Used to override subject for specific email type
224 $subject = apply_filters( 'uwp_'.$key, $subject, $email_name, $email_vars );
225 }
226
227 $subject = self::replace_variables( __( $subject, 'userswp' ), $email_name, $email_vars );
228
229 return apply_filters( 'uwp_email_subject', $subject, $email_name, $email_vars );
230 }
231
232 /**
233 * Get the email content by type.
234 *
235 * @since 1.2.1.2
236 *
237 * @param string $email_name Optional. Email name. Default null.
238 * @param array $email_vars Optional. Email vars. Default array.
239 * @param bool $is_admin Optional. Admin email. Default false.
240 *
241 * @return string
242 */
243 public static function get_content( $email_name = '', $email_vars = array(), $is_admin = false ) {
244 if($is_admin){
245 $key = $email_name . '_email_content_admin';
246 } else {
247 $key = $email_name . '_email_content';
248 }
249
250 switch ( $email_name ) {
251 // TODO some custom options
252 default:
253 $content = uwp_get_option( $key );
254 break;
255 }
256
257 // Get the default text is empty
258 if(!$content && method_exists('UsersWP_Defaults', $key)){
259 $content = UsersWP_Defaults::$key();
260 }
261
262 if ( !$content ) {
263 // Used to override content for specific email type
264 $content = apply_filters( 'uwp_'.$key, $content, $email_name, $email_vars );
265 }
266
267 $content = self::replace_variables( __( $content, 'userswp' ), $email_name, $email_vars );
268
269 return apply_filters( 'uwp_email_content', $content, $email_name, $email_vars );
270 }
271
272 /**
273 * Replace variables in the email text.
274 *
275 * @since 1.2.1.2
276 *
277 * @param string $content Content.
278 * @param string $email_name Optional. Email name. Default null.
279 * @param array $email_vars Optional. Email vars. Default array.
280 *
281 * @return mixed
282 */
283 public static function replace_variables( $content, $email_name = '', $email_vars = array() ) {
284 $site_url = home_url();
285 $blogname = uwp_get_blogname();
286 $email_from_name = self::get_mail_from_name();
287 $login_url = wp_login_url( false ); // 'false' to prevent adding redirect_to to login url.
288 $timestamp = current_time( 'timestamp' );
289 $date = date_i18n( get_option( 'date_format' ), $timestamp );
290 $time = date_i18n( get_option( 'time_format' ), $timestamp );
291 $date_time = $date . ' ' . $time;
292
293 $replace_array = array(
294 '[#blogname#]' => $blogname,
295 '[#site_url#]' => esc_url( $site_url ),
296 '[#site_name_url#]' => '<a href="' . esc_url( $site_url ) . '">' . $site_url . '</a>',
297 '[#site_link#]' => '<a href="' . esc_url( $site_url ) . '">' . $blogname . '</a>',
298 '[#site_name#]' => esc_attr( $email_from_name ),
299 '[#login_url#]' => esc_url( $login_url ),
300 '[#login_link#]' => '<a href="' . esc_url( $login_url ) . '">' . __( 'Login', 'userswp' ) . '</a>',
301 '[#current_date#]' => date_i18n( 'Y-m-d H:i:s', $timestamp ),
302 '[#date#]' => $date,
303 '[#time#]' => $time,
304 '[#date_time#]' => $date_time,
305 '[#from_name#]' => esc_attr( self::get_mail_from_name() ),
306 '[#from_email#]' => sanitize_email( self::get_mail_from() ),
307 );
308
309 $user_id = ! empty( $email_vars['user_id'] ) ? $email_vars['user_id'] : null;
310 if ( !empty( $user_id ) && $user_id > 0 ) {
311 $user_data = get_userdata($user_id);
312 $profile_link = uwp_build_profile_tab_url($user_id);
313 $replace_array = array_merge(
314 $replace_array,
315 array(
316 '[#to_name#]' => esc_attr( $user_data->display_name ),
317 '[#user_login#]' => esc_attr( $user_data->user_login ),
318 '[#user_name#]' => esc_attr( $user_data->display_name ),
319 '[#username#]' => esc_attr( $user_data->user_login ),
320 '[#user_email#]' => sanitize_email( $user_data->user_email ),
321 '[#profile_link#]' => esc_url( $profile_link ),
322 )
323 );
324 }
325
326 $replace_array = apply_filters( 'uwp_email_format_text', $replace_array, $content, $user_id );
327
328 foreach ( $email_vars as $key => $value ) {
329 if ( is_scalar( $value ) ) {
330 $replace_array[ '[#' . $key . '#]' ] = $value ;
331 }
332 }
333
334 $replace_array = apply_filters( 'uwp_email_wild_cards', $replace_array, $content, $email_name, $email_vars );
335
336 foreach ( $replace_array as $key => $value ) {
337 $content = str_replace( $key, $value, $content );
338 }
339
340 return apply_filters( 'uwp_email_content_replace', $content, $email_name, $email_vars );
341 }
342
343 /**
344 * Returns email headers
345 *
346 * @since 1.2.1.2
347 *
348 * @param string $email_name Email name.
349 * @param array $email_vars Optional. Email vars. Default array.
350 * @param string $from_email Optional. From email. Default null.
351 * @param string $from_name Optional. From name. Default null.
352 *
353 * @return string
354 */
355 public static function get_headers( $email_name, $email_vars = array(), $from_email = '', $from_name = '' ) {
356 $from_email = ! empty( $from_email ) ? $from_email : self::get_mail_from();
357 $from_name = ! empty( $from_name ) ? $from_name : self::get_mail_from_name();
358 $reply_to = ! empty( $email_vars['reply_to'] ) ? $email_vars['reply_to'] : $from_email;
359
360 $headers = "From: " . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n";
361 $headers .= "Reply-To: " . $reply_to . "\r\n";
362 $headers .= "Content-Type: " . self::get_content_type() . "; charset=\"" . get_option( 'blog_charset' ) . "\"\r\n";
363
364 return apply_filters( 'uwp_email_headers', $headers, $email_name, $email_vars, $from_email, $from_name );
365 }
366
367 /**
368 * Get the from name for outgoing emails.
369 *
370 * @since 1.2.1.2
371 *
372 * @return string Site name.
373 */
374 public static function get_mail_from_name() {
375 $mail_from_name = uwp_get_option( 'email_name' );
376
377 if ( ! $mail_from_name ) {
378 $mail_from_name = get_bloginfo('name');
379 }
380
381 return apply_filters( 'uwp_get_mail_from_name', stripslashes( $mail_from_name ) );
382 }
383
384 /**
385 * Get the from address for outgoing emails.
386 *
387 * @since 1.2.1.2
388 *
389 * @return string The email ID.
390 */
391 public static function get_mail_from() {
392 $mail_from = uwp_get_option( 'email_address' );
393
394 if ( ! $mail_from ) {
395 $sitename = strtolower( $_SERVER['SERVER_NAME'] );
396 if ( substr( $sitename, 0, 4 ) == 'www.' ) {
397 $sitename = substr( $sitename, 4 );
398 }
399
400 $mail_from = 'wordpress@' . $sitename;
401 }
402
403 return apply_filters( 'uwp_get_mail_from', $mail_from );
404 }
405
406 /**
407 * Get the content type of the email html or plain.
408 *
409 * @since 1.2.1.2
410 *
411 * @param string $content_type Optional. Content type. Default text/html.
412 * @param string $email_type Optional. Email type. Default null.
413 *
414 * @return string $content_type
415 */
416 public static function get_content_type( $content_type = 'text/html', $email_type = '' ) {
417 if ( empty( $email_type ) ) {
418 $email_type = self::get_email_type();
419 }
420
421 switch ( $email_type ) {
422 case 'plain' :
423 $content_type = 'text/plain';
424 break;
425 case 'multipart' :
426 $content_type = 'multipart/alternative';
427 break;
428 }
429
430 return $content_type;
431 }
432
433 /**
434 * Get the email type from settings, html/plain.
435 *
436 * @since 1.2.1.2
437 *
438 * @return string
439 */
440 public static function get_email_type() {
441 $email_type = uwp_get_option( 'email_type' );
442
443 if ( empty( $email_type ) ) {
444 $email_type = 'html';
445 }
446
447 return apply_filters( 'uwp_get_email_type', $email_type );
448 }
449
450 /**
451 * Get the email attachments per type.
452 *
453 * @since 1.2.1.2
454 *
455 * @param string $email_name Optional. Email name. Default null.
456 * @param array $email_vars Optional. Email vars. Default array.
457 * @param bool $is_admin Optional. Admin email. Default false.
458 *
459 * @return array $attachments
460 */
461 public static function get_attachments( $email_name = '', $email_vars = array(), $is_admin = false ) {
462 $attachments = array();
463
464 return apply_filters( 'uwp_email_attachments', $attachments, $email_name, $email_vars, $is_admin );
465 }
466
467 /**
468 * Style the body of the email content.
469 *
470 * @since 1.2.1.2
471 *
472 * @param string $content Email content.
473 * @param string $email_name Optional. Email name. Default null.
474 * @param array $email_vars Optional. Email vars. Default array.
475 *
476 * @return string $content.
477 */
478 public static function style_body( $content, $email_name = '', $email_vars = array() ) {
479 // make sure we only inline CSS for html emails
480 if ( in_array( self::get_email_type(), array( 'html', 'multipart' ) ) && class_exists( 'DOMDocument' ) ) {
481 // include css inliner
482 if ( ! class_exists( 'Emogrifier' ) ) {
483 include_once( USERSWP_PATH . 'includes/libraries/class-emogrifier.php' );
484 }
485
486 ob_start();
487 uwp_get_template( 'emails/uwp-email-styles.php', array(
488 'email_name' => $email_name,
489 'email_vars' => $email_vars
490 ) );
491 $css = apply_filters( 'uwp_email_styles', ob_get_clean() );
492
493 // apply CSS styles inline for picky email clients
494 try {
495 $emogrifier = new Emogrifier( $content, $css );
496 $content = $emogrifier->emogrify();
497 } catch ( Exception $e ) {
498 uwp_error_log( $e->getMessage() );
499 }
500 }
501
502 return $content;
503 }
504
505 /**
506 * Function to send email.
507 *
508 * @since 1.2.1.3
509 *
510 * @param string $to To email address.
511 * @param string $subject Email subject.
512 * @param string $message Email message.
513 * @param string $headers Email Headers.
514 * @param array $attachments Optional. Email attachments. Default array.
515 *
516 * @return bool
517 */
518 public static function uwp_mail( $to, $subject, $message, $headers, $attachments = array() ) {
519 add_filter( 'wp_mail_from', array( __CLASS__, 'get_mail_from' ) );
520 add_filter( 'wp_mail_from_name', array( __CLASS__, 'get_mail_from_name' ) );
521 add_filter( 'wp_mail_content_type', array( __CLASS__, 'get_content_type' ) );
522
523 $message = self::style_body( $message );
524 $message = apply_filters( 'uwp_mail_content', $message);
525
526 $sent = wp_mail( $to, $subject, $message, $headers, $attachments );
527
528 if ( ! $sent ) {
529 $log_message = wp_sprintf( __( "Email from UsersWP failed to send.\nTime: %s\nTo: %s\nSubject: %s\nError: %s\n\n", 'userswp' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), ( is_array( $to ) ? implode( ', ', $to ) : $to ), $subject );
530 uwp_error_log( $log_message);
531 }
532
533 remove_filter( 'wp_mail_from', array( __CLASS__, 'get_mail_from' ) );
534 remove_filter( 'wp_mail_from_name', array( __CLASS__, 'get_mail_from_name' ) );
535 remove_filter( 'wp_mail_content_type', array( __CLASS__, 'get_content_type' ) );
536
537 return $sent;
538 }
539
540 /**
541 * Function to send email for default UWP emails.
542 *
543 * @since 1.2.1.3
544 *
545 * @param string $to To email address.
546 * @param string $email_name Email name.
547 * @param array $email_vars Optional. Email vars. Default null.
548 * @param bool $is_admin Optional. Admin email. Default false.
549 *
550 * @return bool
551 */
552 public static function send( $to, $email_name, $email_vars = array(), $is_admin = false ) {
553
554 if ( !self::is_email_enabled( $email_name, '', $is_admin ) ) {
555 return false;
556 }
557
558 $to = apply_filters( 'uwp_send_email_to', $to, $email_name, $email_vars, $is_admin );
559
560 if(empty($to)){
561 return false;
562 }
563
564 // Switch language to user language.
565 do_action( 'wpml_switch_language_for_email', $to );
566
567 $subject = self::get_subject( $email_name, $email_vars, $is_admin );
568 $message_body = self::get_content( $email_name, $email_vars, $is_admin );
569 $headers = self::get_headers( $email_name, $email_vars, $is_admin );
570 $attachments = self::get_attachments( $email_name, $email_vars, $is_admin );
571
572 $plain_text = self::get_email_type() != 'html' ? true : false;
573 $template = $plain_text ? 'emails/plain/uwp-email-' . $email_name . '.php' : 'emails/uwp-email-' . $email_name . '.php';
574
575 $content = uwp_get_template_html( $template, array(
576 'email_name' => $email_name,
577 'email_vars' => $email_vars,
578 'email_heading' => '',
579 'sent_to_admin' => $is_admin,
580 'plain_text' => $plain_text,
581 'message_body' => $message_body,
582 ) );
583
584 do_action( 'uwp_before_'.$email_name.'_email', $email_name, $email_vars );
585
586 $sent = self::uwp_mail($to, $subject, $content, $headers, $attachments);
587
588 do_action( 'uwp_after_'.$email_name.'_email', $email_name, $email_vars );
589
590 // Switch language back.
591 do_action( 'wpml_restore_language_from_email' );
592
593 return $sent;
594 }
595
596 public function wp_new_user_notification_email($wp_new_user_notification_email, $user){
597
598 $email_name = 'wp_new_user_notification';
599 $is_admin = false;
600 if ( !self::is_email_enabled( $email_name, '', $is_admin ) ) {
601 return $wp_new_user_notification_email;
602 }
603
604 $key = get_password_reset_key( $user );
605 if ( is_wp_error( $key ) ) {
606 return $wp_new_user_notification_email;
607 }
608
609 $email_vars = array(
610 'user_id' => $user->ID
611 );
612
613 $to = apply_filters( 'uwp_send_email_to', $user->user_email, $email_name, $email_vars, $is_admin);
614
615 // Switch language to user language.
616 do_action( 'wpml_switch_language_for_email', $to );
617
618 $subject = self::get_subject( $email_name, $email_vars, $is_admin );
619 $subject = !empty($subject) ? $subject : UsersWP_Defaults::wp_new_user_notification_email_subject();
620 $headers = self::get_headers( $email_name, $email_vars, $is_admin );
621 $message = self::get_content( $email_name, $email_vars, $is_admin );
622 $message = !empty($message) ? $message : UsersWP_Defaults::wp_new_user_notification_email_content();
623
624 $reset_page = uwp_get_page_id( 'reset_page', false );
625 if ( $reset_page ) {
626 $reset_link = add_query_arg( array(
627 'key' => $key,
628 'login' => rawurlencode( $user->user_login ),
629 ), get_permalink( $reset_page ) );
630 $reset_link = "<a href='" . $reset_link . "' target='_blank'>" . $reset_link . "</a>";
631 } else {
632 $reset_link = home_url( "reset?key=$key&login=" . rawurlencode( $user->user_login ), 'login' );
633 $reset_link = "<a href='" .$reset_link. "' target='_blank'>" . $reset_link . "</a>";
634 }
635
636 $message = str_replace( '[#reset_link#]', $reset_link, $message );
637
638 $plain_text = self::get_email_type() != 'html' ? true : false;
639 $template = $plain_text ? 'emails/plain/uwp-email-' . $email_name . '.php' : 'emails/uwp-email-' . $email_name . '.php';
640
641 $content = uwp_get_template_html( $template, array(
642 'email_name' => $email_name,
643 'email_vars' => $email_vars,
644 'email_heading' => '',
645 'sent_to_admin' => $is_admin,
646 'plain_text' => $plain_text,
647 'message_body' => $message,
648 ) );
649
650 $content = self::style_body( $content );
651 $content = apply_filters( 'uwp_mail_content', $content);
652
653 // Switch language back.
654 do_action( 'wpml_restore_language_from_email' );
655
656 $wp_new_user_notification_email = array(
657 'to' => $to,
658 'subject' => $subject,
659 'message' => $content,
660 'headers' => $headers,
661 );
662
663 return $wp_new_user_notification_email;
664
665 }
666
667 public function wp_new_user_notification_email_admin($wp_new_user_notification_email_admin, $user){
668
669 $email_name = 'wp_new_user_notification';
670 $is_admin = true;
671 if ( !self::is_email_enabled( $email_name, '', $is_admin ) ) {
672 return $wp_new_user_notification_email_admin;
673 }
674
675 $email_vars = array(
676 'user_id' => $user->ID
677 );
678
679 $to = apply_filters( 'uwp_send_email_to', get_option( 'admin_email' ), $email_name, $email_vars, $is_admin);
680
681 // Switch language to user language.
682 do_action( 'wpml_switch_language_for_email', $to );
683
684 $subject = self::get_subject( $email_name, $email_vars, $is_admin );
685 $subject = !empty($subject) ? $subject : UsersWP_Defaults::wp_new_user_notification_email_subject_admin();
686 $headers = self::get_headers( $email_name, $email_vars, $is_admin );
687 $message = self::get_content( $email_name, $email_vars, $is_admin );
688 $message = !empty($message) ? $message : UsersWP_Defaults::wp_new_user_notification_email_content_admin();
689
690 $plain_text = self::get_email_type() != 'html' ? true : false;
691 $template = $plain_text ? 'emails/plain/uwp-email-' . $email_name . '.php' : 'emails/uwp-email-' . $email_name . '.php';
692
693 $content = uwp_get_template_html( $template, array(
694 'email_name' => $email_name,
695 'email_vars' => $email_vars,
696 'email_heading' => '',
697 'sent_to_admin' => $is_admin,
698 'plain_text' => $plain_text,
699 'message_body' => $message,
700 ) );
701
702 $content = self::style_body( $content );
703 $content = apply_filters( 'uwp_mail_content', $content);
704
705 // Switch language back.
706 do_action( 'wpml_restore_language_from_email' );
707
708 $wp_new_user_notification_email = array(
709 'to' => $to,
710 'subject' => $subject,
711 'message' => $content,
712 'headers' => $headers,
713 );
714
715 return $wp_new_user_notification_email;
716
717 }
718
719 }
720
721 new UsersWP_Mails();