Files
ultimatemember/core/um-mail.php
T

133 lines
3.2 KiB
PHP
Raw Normal View History

2014-12-15 22:38:07 +02:00
<?php
class UM_Mail {
function __construct() {
2015-01-28 17:16:04 +02:00
add_filter('mandrill_nl2br', array(&$this, 'mandrill_nl2br') );
}
2014-12-15 22:38:07 +02:00
2015-01-28 17:16:04 +02:00
/***
*** @mandrill compatibility
***/
2015-02-10 02:05:27 +02:00
function mandrill_nl2br($nl2br, $message = '') {
2015-01-28 17:16:04 +02:00
// text emails
2015-03-01 00:44:04 +02:00
if ( !um_get_option('email_html') ) {
$nl2br = true;
}
2015-01-28 17:16:04 +02:00
return $nl2br;
2014-12-15 22:38:07 +02:00
}
2015-03-01 00:44:04 +02:00
/***
*** @check If template exists
***/
function email_template( $template ) {
if ( file_exists( get_stylesheet_directory() . '/ultimate-member/templates/email/' . $template . '.html' ) ) {
return get_stylesheet_directory() . '/ultimate-member/templates/email/' . $template . '.html';
}
if ( file_exists( um_path . 'templates/email/' . $template . '.html' ) ) {
return um_url . 'templates/email/' . $template . '.html';
}
return false;
}
2014-12-15 22:38:07 +02:00
/***
*** @sends an email to any user
***/
function send( $email, $template=null, $args = array() ) {
if ( !$template ) return;
if ( um_get_option( $template . '_on' ) != 1 ) return;
if ( !is_email( $email ) ) return;
$this->attachments = null;
$this->headers = 'From: '. um_get_option('mail_from') .' <'. um_get_option('mail_from_addr') .'>' . "\r\n";
$this->subject = um_get_option( $template . '_sub' );
$this->subject = $this->convert_tags( $this->subject );
2015-03-01 00:44:04 +02:00
// HTML e-mail
if ( um_get_option('email_html') && $this->email_template( $template ) ) {
$this->message = file_get_contents( $this->email_template( $template ) );
} else {
$this->message = um_get_option( $template );
}
2014-12-15 22:38:07 +02:00
2015-03-01 00:44:04 +02:00
// Convert tags in body
2014-12-15 22:38:07 +02:00
$this->message = $this->convert_tags( $this->message );
2015-03-01 00:44:04 +02:00
// Send mail
add_filter( 'wp_mail_content_type', array(&$this, 'set_content_type') );
2014-12-15 22:38:07 +02:00
wp_mail( $email, $this->subject, $this->message, $this->headers, $this->attachments );
2015-03-01 00:44:04 +02:00
remove_filter( 'wp_mail_content_type', array(&$this, 'set_content_type') );
}
/***
*** @maybe sending HTML emails
***/
function set_content_type( $content_type ) {
if ( um_get_option('email_html') )
return 'text/html';
return 'text/plain';
2014-12-15 22:38:07 +02:00
}
/***
*** @convert template tags in email template
***/
function convert_tags( $content ) {
$search = array(
'{display_name}',
2015-02-01 01:30:04 +02:00
'{first_name}',
'{last_name}',
'{gender}',
2015-01-22 02:10:26 +02:00
'{username}',
'{email}',
'{password}',
'{login_url}',
2014-12-15 22:38:07 +02:00
'{site_name}',
2015-03-01 00:44:04 +02:00
'{site_url}',
2014-12-15 22:38:07 +02:00
'{account_activation_link}',
2014-12-22 01:45:24 +02:00
'{password_reset_link}',
2014-12-15 22:38:07 +02:00
'{admin_email}',
'{user_profile_link}',
2015-03-01 00:44:04 +02:00
'{user_account_link}',
2015-01-22 02:10:26 +02:00
'{submitted_registration}',
2015-03-01 00:44:04 +02:00
'{user_avatar_url}',
2014-12-15 22:38:07 +02:00
);
$search = apply_filters('um_template_tags_patterns_hook', $search);
$replace = array(
um_user('display_name'),
2015-02-01 01:30:04 +02:00
um_user('first_name'),
um_user('last_name'),
um_user('gender'),
2015-01-22 02:10:26 +02:00
um_user('user_login'),
um_user('user_email'),
um_user('_um_cool_but_hard_to_guess_plain_pw'),
um_get_core_page('login'),
2014-12-15 22:38:07 +02:00
um_get_option('site_name'),
2015-03-01 00:44:04 +02:00
get_bloginfo('url'),
2014-12-15 22:38:07 +02:00
um_user('account_activation_link'),
2014-12-22 01:45:24 +02:00
um_user('password_reset_link'),
2014-12-15 22:38:07 +02:00
um_admin_email(),
um_user_profile_url(),
2015-03-01 00:44:04 +02:00
um_get_core_page('account'),
2015-01-22 02:10:26 +02:00
um_user_submitted_registration(),
2015-03-01 00:44:04 +02:00
um_get_user_avatar_url(),
2014-12-15 22:38:07 +02:00
);
$replace = apply_filters('um_template_tags_replaces_hook', $replace);
$content = str_replace($search, $replace, $content);
return $content;
}
}