- new Email Templates logic with save template to Theme(Child Theme);

- small fixes;
This commit is contained in:
nikitozzzzzzz
2017-08-29 15:01:29 +03:00
parent f32d37c09e
commit 502231671b
27 changed files with 559 additions and 781 deletions
@@ -139,6 +139,21 @@ textarea.um-forms-field.um-small-field {
.um-form-table.um-third-column .um-forms-line th,
.um-form-table.um-half-column .um-forms-line th,
.um-form-table.um-two-thirds-column .um-forms-line th {
float:left;
width: 100%;
}
.um-form-table.um-third-column .um-forms-line td,
.um-form-table.um-half-column .um-forms-line td,
.um-form-table.um-two-thirds-column .um-forms-line td {
float:left;
width: 100%;
}
.um-form-table.um-third-column .um-forms-line th label,
.um-form-table.um-half-column .um-forms-line th label,
.um-form-table.um-two-thirds-column .um-forms-line th label {
float:left;
width: 100%;
}
}
@@ -213,4 +213,37 @@ th.column-email.column-primary {
.um-small-field {
width:50%;
}
}
/*
.email_template_wrapper .copy_button_overlay {
position:absolute;
top:0;
bottom:0;
width:calc( 100% - 30px );
z-index: 2;
background: rgba( 241, 241, 241, 0.95 );
text-align: center;
padding-top: 30%;
padding-right: 20px;
padding-left: 20px;
}
.email_template_wrapper .copy_button_overlay > span {
color: #444;
margin: 0 0 15px 0;
display: inline-block;
}
.email_template_wrapper.in_theme .copy_button_overlay {
display: none !important;
}
*/
.email_template_wrapper .reset_email_template {
display: none;
}
.email_template_wrapper.in_theme .reset_email_template {
display: block;
}
@@ -1,4 +1,42 @@
jQuery( document ).ready( function() {
/**
* Email templates
*/
/*jQuery( 'body' ).on( 'click', '.copy_email_template', function() {
var obj = jQuery(this);
jQuery.ajax({
url: php_data.copy_email_template,
type: 'POST',
data: { email_key : obj.parents('.email_template_wrapper').data('key') },
success: function(data){
obj.parents('.email_template_wrapper').addClass('in_theme');
},
error: function(data){
alert('Something went wrong');
}
});
});*/
jQuery( 'body' ).on( 'click', '.reset_email_template', function() {
var obj = jQuery(this);
jQuery.ajax({
url: php_data.delete_email_template,
type: 'POST',
data: { email_key : obj.parents('.email_template_wrapper').data('key') },
success: function(data){
obj.parents('.email_template_wrapper').removeClass('in_theme');
},
error: function(data){
alert('Something went wrong');
}
});
});
/**
* Licenses
*/
@@ -169,6 +169,7 @@ if ( ! class_exists( 'Admin_Enqueue' ) ) {
wp_enqueue_script( 'um_admin_settings' );
$localize_data = array(
'delete_email_template' => UM()->get_ajax_route( 'um\core\Mail', 'delete_email_template' ),
'onbeforeunload_text' => __( 'Are sure, maybe some settings not saved', 'ultimate-member' ),
'texts' => array(
'remove' => __( 'Remove', 'ultimate-member' ),
+53
View File
@@ -888,5 +888,58 @@ if ( ! class_exists( 'Admin_Forms' ) ) {
return $html;
}
function render_email_template( $field_data ) {
if ( empty( $field_data['id'] ) )
return false;
$id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id'];
$class = ! empty( $field_data['class'] ) ? $field_data['class'] : '';
$class .= ! empty( $field_data['size'] ) ? $field_data['size'] : 'um-long-field';
$data = array(
'field_id' => $field_data['id']
);
$data_attr = '';
foreach ( $data as $key => $value ) {
$data_attr .= " data-{$key}=\"{$value}\" ";
}
$name = $field_data['id'];
$name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name;
$default = isset( $field_data['default'] ) ? $field_data['default'] : '';
$value = isset( $field_data['value'] ) ? $field_data['value'] : $default;
ob_start(); ?>
<div class="email_template_wrapper <?php echo $field_data['in_theme'] ? 'in_theme' : '' ?>" data-key="<?php echo $field_data['id'] ?>" style="position: relative;">
<!-- <input type="button" class="reset_email_template button" value="--><?php //_e( 'Reset Template to Default', 'ultimate-member' ) ?><!--" />-->
<!--<div class="copy_button_overlay">
<span><?php /*_e( 'Currently UM use default Email Template, you can edit this template after then you copy in to theme', 'ultimate-member' ) */?></span>
<input type="button" class="copy_email_template button" value="<?php /*_e( 'Copy Template to Theme', 'ultimate-member' ) */?>" />
</div>-->
<?php wp_editor( $value,
$id,
array(
'textarea_name' => $name,
'textarea_rows' => 20,
'editor_height' => 425,
'wpautop' => false,
'media_buttons' => false,
'editor_class' => $class
)
); ?>
</div>
<?php $html = ob_get_clean();
return $html;
}
}
}
+36 -162
View File
@@ -40,6 +40,9 @@ if ( ! class_exists( 'Admin_Settings' ) ) {
add_action( 'um_settings_save', array( $this, 'on_settings_save' ) );
add_filter( 'um_change_settings_before_save', array( $this, 'save_email_templates' ) );
//save licenses options
add_action( 'um_settings_before_save', array( $this, 'before_licenses_save' ) );
add_action( 'um_settings_save', array( $this, 'licenses_save' ) );
@@ -1466,7 +1469,7 @@ if ( ! class_exists( 'Admin_Settings' ) ) {
foreach ( $_POST['um_options'] as $key => $value ) {
$edd_action = '';
$license_key = '';
if ( empty( $this->previous_licenses[$key] ) && ! empty( $value ) ) {
if ( empty( $this->previous_licenses[$key] ) && ! empty( $value ) || ( ! empty( $this->previous_licenses[$key] ) && ! empty( $value ) && $this->previous_licenses[$key] != $value ) ) {
$edd_action = 'activate_license';
$license_key = $value;
} elseif ( ! empty( $this->previous_licenses[$key] ) && empty( $value ) ) {
@@ -1567,12 +1570,19 @@ if ( ! class_exists( 'Admin_Settings' ) ) {
if ( empty( $email_key ) || empty( $emails[$email_key] ) )
return $section;
$in_theme = UM()->mail()->template_in_theme( $email_key );
$section_fields = array(
array(
'id' => 'um_email_template',
'type' => 'hidden',
'value' => $email_key,
),
array(
'id' => $email_key . '_on',
'type' => 'checkbox',
'label' => $emails[$email_key]['title'],
'tooltip' => $emails[$email_key]['description'],
'tooltip' => $emails[$email_key]['description'],
'value' => UM()->um_get_option( $email_key . '_on' ),
'default' => UM()->um_get_default( $email_key . '_on' ),
),
@@ -1586,13 +1596,14 @@ if ( ! class_exists( 'Admin_Settings' ) ) {
'default' => UM()->um_get_default( $email_key . '_sub' ),
),
array(
'id' => $email_key,
'type' => 'wp_editor',
'label' => __( 'Message Body','ultimate-member' ),
'conditional' => array( $email_key . '_on', '=', 1 ),
'tooltip' => __('This is the content of the e-mail','ultimate-member'),
'value' => UM()->um_get_option( $email_key ),
'id' => $email_key,
'type' => 'email_template',
'label' => __( 'Message Body','ultimate-member' ),
'conditional' => array( $email_key . '_on', '=', 1 ),
'tooltip' => __('This is the content of the e-mail','ultimate-member'),
'value' => UM()->mail()->get_email_template( $email_key ),
'default' => UM()->um_get_default( $email_key ),
'in_theme' => $in_theme
),
);
@@ -2267,168 +2278,31 @@ Use Only Cookies: <?php echo ini_get( 'session.use_only_cookies' ) ?
}
/**
* Render HTML for settings field
*
* @param $data
* @return string
*/
function render_setting_field( $data ) {
if ( empty( $data['type'] ) )
return '';
function save_email_templates( $settings ) {
$conditional = ! empty( $data['conditional'] ) ? 'data-conditional="' . esc_attr( json_encode( $data['conditional'] ) ) . '"' : '';
if ( empty( $settings['um_email_template'] ) )
return $settings;
$html = '';
if ( $data['type'] != 'hidden' )
$html .= '<tr class="um-settings-line" ' . $conditional . '><th><label for="um_options_' . $data['id'] . '">' . $data['label'] . '</label></th><td>';
$template = $settings['um_email_template'];
$content = stripslashes( $settings[$template] );
$theme_template_path = UM()->mail()->get_template_file( 'theme', $template );
$option_value = UM()->um_get_option( $data['id'] );
$default = ! empty( $data['default'] ) ? $data['default'] : UM()->um_get_default( $data['id'] );
switch ( $data['type'] ) {
case 'hidden':
$value = ! empty( $option_value ) ? $option_value : $default;
if ( empty( $data['is_option'] ) )
$html .= '<input type="hidden" id="' . $data['id'] . '" name="' . $data['id'] . '" value="' . $value . '" />';
else
$html .= '<input type="hidden" id="um_options_' . $data['id'] . '" name="um_options[' . $data['id'] . ']" value="' . $value . '" class="um-option-field" data-field_id="' . $data['id'] . '" />';
break;
case 'text':
$value = ! empty( $option_value ) ? $option_value : $default;
$field_length = ! empty( $data['size'] ) ? $data['size'] : 'um-long-field';
$html .= '<input type="text" id="um_options_' . $data['id'] . '" name="um_options[' . $data['id'] . ']" value="' . $value . '" class="um-option-field ' . $field_length . '" data-field_id="' . $data['id'] . '" />';
break;
case 'multi-text':
$values = ! empty( $option_value ) ? $option_value : $default;
$html .= '<ul class="um-multi-text-list" data-field_id="' . $data['id'] . '">';
if ( ! empty( $values ) ) {
foreach ( $values as $k=>$value ) {
$html .= '<li class="um-multi-text-option-line"><input type="text" id="um_options_' . $data['id'] . '-' . $k . '" name="um_options[' . $data['id'] . '][]" value="' . $value . '" class="um-option-field" data-field_id="' . $data['id'] . '" />
<a href="javascript:void(0);" class="um-option-delete">' . __( 'Remove', 'ultimate-member' ) . '</a></li>';
}
}
$html .= '</ul><a href="javascript:void(0);" class="button button-primary um-multi-text-add-option" data-name="um_options[' . $data['id'] . '][]">' . $data['add_text'] . '</a>';
break;
case 'textarea':
$value = ! empty( $option_value ) ? $option_value : $default;
$field_length = ! empty( $data['size'] ) ? $data['size'] : 'um-long-field';
$html .= '<textarea id="um_options_' . $data['id'] . '" name="um_options[' . $data['id'] . ']" rows="6" class="um-option-field ' . $field_length . '" data-field_id="' . $data['id'] . '">' . $value . '</textarea>';
break;
case 'wp_editor':
$value = ! empty( $option_value ) ? $option_value : $default;
ob_start();
wp_editor( $value,
'um_options_' . $data['id'],
array(
'textarea_name' => 'um_options[' . $data['id'] . ']',
'textarea_rows' => 20,
'editor_height' => 425,
'wpautop' => false,
'media_buttons' => false,
'editor_class' => 'um-option-field'
)
);
$html .= ob_get_clean();
break;
case 'checkbox':
$value = ( '' !== $option_value ) ? $option_value : $default;
$html .= '<input type="hidden" id="um_options_' . $data['id'] . '_hidden" name="um_options[' . $data['id'] . ']" value="0" /><input type="checkbox" ' . checked( $value, true, false ) . ' id="um_options_' . $data['id'] . '" name="um_options[' . $data['id'] . ']" value="1" class="um-option-field" data-field_id="' . $data['id'] . '" />';
break;
case 'multi-checkbox':
$value = ( '' !== $option_value ) ? $option_value : $default;
$columns = ! empty( $data['columns'] ) ? $data['columns'] : 1;
$per_column = ceil( count( $data['options'] ) / $columns );
$html .= '<div class="multi-checkbox-line">';
$current_option = 1;
$iter = 1;
foreach ( $data['options'] as $key=>$option ) {
if ( $current_option == 1 )
$html .= '<div class="multi-checkbox-column" style="width:' . floor( 100/$columns ) . '%;">';
$html .= '<input type="hidden" id="um_options_' . $data['id'] . '_' . $key . '_hidden" name="um_options[' . $data['id'] . '][' . $key . ']" value="0" />
<label><input type="checkbox" ' . checked( $value[$key], true, false ) . ' id="um_options_' . $data['id'] . '" name="um_options[' . $data['id'] . '][' . $key . ']" value="1" class="um-option-field" data-field_id="' . $data['id'] . '" />' . $option . '</label>';
if ( $current_option == $per_column || $iter == count( $data['options'] ) ) {
$current_option = 1;
$html .= '</div>';
} else {
$current_option++;
}
$iter++;
}
$html .= '</div>';
break;
case 'selectbox':
$value = ! empty( $option_value ) ? $option_value : $default;
$html .= '<select ' . ( ! empty( $data['multi'] ) ? 'multiple' : '' ) . ' id="um_options_' . $data['id'] . '" name="um_options[' . $data['id'] . ']' . ( ! empty( $data['multi'] ) ? '[]' : '' ) . '" class="um-option-field" data-field_id="' . $data['id'] . '">';
foreach ( $data['options'] as $key=>$option ) {
if ( ! empty( $data['multi'] ) ) {
$html .= '<option value="' . $key . '" ' . selected( in_array( $key, $value ), true, false ) . '>' . $option . '</option>';
} else {
$html .= '<option value="' . $key . '" ' . selected( $key == $value, true, false ) . '>' . $option . '</option>';
}
}
$html .= '</select>';
break;
case 'media':
$upload_frame_title = ! empty( $data['upload_frame_title'] ) ? $data['upload_frame_title'] : __( 'Select media', 'ultimate-member' );
$value = ! empty( $option_value ) ? $option_value : $default;
$image_id = ! empty( $value['id'] ) ? $value['id'] : '';
$image_width = ! empty( $value['width'] ) ? $value['width'] : '';
$image_height = ! empty( $value['height'] ) ? $value['height'] : '';
$image_thumbnail = ! empty( $value['thumbnail'] ) ? $value['thumbnail'] : '';
$image_url = ! empty( $value['url'] ) ? $value['url'] : '';
$data_default = ! empty( $default ) ? 'data-default="' . esc_attr( $default['url'] ) .'"' : '';
$html .= '<div class="um-media-upload">' .
'<input type="hidden" class="um-media-upload-data-id" name="um_options[' . $data['id'] . '][id]" id="um_options_' . $data['id'] . '_id" value="' . $image_id . '">' .
'<input type="hidden" class="um-media-upload-data-width" name="um_options[' . $data['id'] . '][width]" id="um_options_' . $data['id'] . '_width" value="' . $image_width . '">' .
'<input type="hidden" class="um-media-upload-data-height" name="um_options[' . $data['id'] . '][height]" id="um_options_' . $data['id'] . '_height" value="' . $image_height . '">' .
'<input type="hidden" class="um-media-upload-data-thumbnail" name="um_options[' . $data['id'] . '][thumbnail]" id="um_options_' . $data['id'] . '_thumbnail" value="' . $image_thumbnail . '">' .
'<input type="hidden" class="um-option-field um-media-upload-data-url" name="um_options[' . $data['id'] . '][url]" id="um_options_' . $data['id'] . '_url" value="' . $image_url . '" data-field_id="' . $data['id'] . '" ' . $data_default . '>';
if ( ! isset( $data['preview'] ) || $data['preview'] !== false ) {
$html .= '<img src="' . ( ! empty( $value['url'] ) ? $value['url'] : '' ) . '" alt="" class="icon_preview"><div style="clear:both;"></div>';
}
if ( ! empty( $data['url'] ) ) {
$html .= '<input type="text" class="um-media-upload-url" readonly value="' . $image_url . '" /><div style="clear:both;"></div>';
}
$html .= '<input type="button" class="um-set-image button button-primary" value="' . __( 'Select', 'ultimate-member' ) . '" data-upload_frame="' . $upload_frame_title . '" />
<input type="button" class="um-clear-image button" value="' . __( 'Clear', 'ultimate-member' ) . '" /></div>';
break;
$in_theme = UM()->mail()->template_in_theme( $template );
if ( ! $in_theme ) {
UM()->mail()->copy_email_template( $template );
}
if ( ! empty( $data['description'] ) )
$html .= '<div class="description">' . $data['description'] . '</div>';
$fp = fopen( $theme_template_path, "w" );
$result = fputs( $fp, $content );
fclose( $fp );
$html .= '</td></tr>';
if ( $result !== false ) {
unset( $settings['um_email_template'] );
unset( $settings[$template] );
}
return $html;
return $settings;
}
}
}
+9 -1
View File
@@ -910,7 +910,7 @@ um_remove_option( 'profile_header_icon_hcolor' );
//remove duplicates for UM Pages settings
delete_option( 'um_core_pages' );
global $wpdb;
//UM Roles to WP Roles
//all UM Roles from post type
@@ -1109,6 +1109,9 @@ foreach ( $all_taxonomies as $key => $taxonomy ) {
//for metadata for all UM forms
//"use_global" meta change to "_use_custom_settings"
//also update for forms metadata where "member" or "admin"
$forms = get_posts( array(
'post_type' => 'um_form',
'numberposts' => -1,
@@ -1124,5 +1127,10 @@ foreach ( $forms as $form_id ) {
update_post_meta( $form_id, "_um_{$form_type}_use_custom_settings", $use_custom_settings );
delete_post_meta( $form_id, "_um_{$form_type}_use_globals" );
$role = get_post_meta( $form_id, "_um_{$form_type}_role", true );
if ( $role ) {
update_post_meta( $form_id, "_um_{$form_type}_role", 'um_' . $role );
}
}
}
+2 -2
View File
@@ -66,7 +66,7 @@
'type' => 'textarea',
'name' => '_um_checkmail_message',
'label' => __( 'Personalize the custom message', 'ultimate-member' ),
'value' => ! empty( $role['_um_checkmail_message'] ) ? $role['_um_checkmail_message'] : '',
'value' => ! empty( $role['_um_checkmail_message'] ) ? $role['_um_checkmail_message'] : __('Thank you for registering. Before you can login we need you to activate your account by clicking the activation link in the email we just sent you.','ultimate-member'),
'conditional' => array( '_um_checkmail_action', '=', 'show_message' )
),
array(
@@ -104,7 +104,7 @@
'type' => 'textarea',
'name' => '_um_pending_message',
'label' => __( 'Personalize the custom message', 'ultimate-member' ),
'value' => ! empty( $role['_um_pending_message'] ) ? $role['_um_pending_message'] : '',
'value' => ! empty( $role['_um_pending_message'] ) ? $role['_um_pending_message'] : __('Thank you for applying for membership to our site. We will review your details and send you an email letting you know whether your application has been successful or not.','ultimate-member'),
'conditional' => array( '_um_pending_action', '=', 'show_message' )
),
array(
+238 -85
View File
@@ -7,21 +7,29 @@ if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'Mail' ) ) {
class Mail {
var $email_templates = array();
function __construct() {
add_filter('mandrill_nl2br', array(&$this, 'mandrill_nl2br') );
$this->path_by_slug = apply_filters( 'um_email_templates_path_by_slug', array() );
$this->force_plain_text = '';
//mandrill compatibility
add_filter( 'mandrill_nl2br', array( &$this, 'mandrill_nl2br' ) );
}
/***
*** @mandrill compatibility
***/
function mandrill_nl2br($nl2br, $message = '') {
/**
* Mandrill compatibility
*
* @param $nl2br
* @param string $message
* @return bool
*/
function mandrill_nl2br( $nl2br, $message = '' ) {
// text emails
if ( !um_get_option('email_html') ) {
if ( ! um_get_option( 'email_html' ) ) {
$nl2br = true;
}
@@ -29,103 +37,248 @@ if ( ! class_exists( 'Mail' ) ) {
}
/***
*** @check If template exists
***/
function email_template( $template, $args = array() ) {
$lang = '';
$template_path = false;
if ( function_exists('icl_get_current_language') ) {
if ( icl_get_current_language() != 'en' ) {
$lang = icl_get_current_language() . '/';
}
} else {
/**
* Send Email function
*
* @param string $email
* @param null $template
* @param array $args
*/
function send( $email, $template, $args = array() ) {
$lang = get_locale();
$arr_english_lang = array('en','en_US','en_NZ','en_ZA','en_AU','en_GB');
if( in_array( $lang, $arr_english_lang ) || strpos( $lang , 'en_' ) > -1 || empty( $lang ) || $lang == 0 ){
$lang = '';
} else {
$lang .= '/';
}
}
if ( file_exists( get_stylesheet_directory() . '/ultimate-member/templates/email/' . $lang . $template . '.html' ) ) {
$template_path = get_stylesheet_directory() . '/ultimate-member/templates/email/' . $lang . $template . '.html';
} else {
if ( isset( $args['path'] ) ) {
$path = $args['path'] . $lang;
} else {
$path = um_path . 'templates/email/' . $lang;
}
if ( file_exists( $path . $template . '.html' ) ) {
$template_path = $path . $template . '.html';
}
}
return apply_filters( 'um_email_template_path', $template_path, $template, $args );
}
/***
*** @sends an email to any user
***/
function send( $email, $template=null, $args = array() ) {
if ( !$template ) return;
if ( ! is_email( $email ) ) 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 = um_convert_tags( $this->subject, $args );
$this->subject = um_convert_tags( um_get_option( $template . '_sub' ), $args );
if ( isset( $args['admin'] ) || isset( $args['plain_text'] ) ) {
$this->force_plain_text = 'forced';
}
add_filter( 'wp_mail_content_type', array(&$this, 'set_content_type') );
// HTML e-mail or text
if ( um_get_option('email_html') && $this->email_template( $template, $args ) ) {
$this->message = file_get_contents( $this->email_template( $template, $args ) );
} else {
$this->message = um_get_option( $template );
}
// Convert tags in body
$this->message = um_convert_tags( $this->message, $args );
$this->message = $this->prepare_template( $template, $args );
add_filter( 'wp_mail_content_type', array( &$this, 'set_content_type' ) );
// Send mail
wp_mail( $email, $this->subject, $this->message, $this->headers, $this->attachments );
remove_filter( 'wp_mail_content_type', array(&$this, 'set_content_type') );
// reset globals
$this->force_plain_text = '';
remove_filter( 'wp_mail_content_type', array( &$this, 'set_content_type' ) );
}
/***
*** @maybe sending HTML emails
***/
/**
* @param $slug
* @param $args
* @return bool|string
*/
function get_email_template( $slug, $args = array() ) {
$located = $this->locate_template( $slug );
$located = apply_filters( 'um_email_template_path', $located, $slug, $args );
if ( ! file_exists( $located ) ) {
_doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' );
return false;
}
ob_start();
do_action( 'um_before_email_template_part', $slug, $located, $args );
include( $located );
do_action( 'um_after_email_template_part', $slug, $located, $args );
return ob_get_clean();
}
/**
* Prepare email template to send
*
* @param $slug
* @param $args
* @return mixed|string
*/
function prepare_template( $slug, $args = array() ) {
ob_start(); ?>
<html>
<?php do_action( 'um_before_email_template_body', $slug, $args ); ?>
<body <?php echo apply_filters( 'um_email_template_body_attrs', 'style="background: #f2f2f2;-webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: grayscale;"', $slug ) ?>>
<?php echo $this->get_email_template( $slug, $args ); ?>
</body>
</html>
<?php $message = ob_get_clean();
// Convert tags in email template
return um_convert_tags( $message, $args );
}
/**
* Locate a template and return the path for inclusion.
*
* @access public
* @param string $template_name
* @return string
*/
function locate_template( $template_name ) {
//WPML compatibility and multilingual email templates
$lang = get_locale();
$arr_english_lang = array( 'en', 'en_US', 'en_NZ', 'en_ZA', 'en_AU', 'en_GB' );
if ( in_array( $lang, $arr_english_lang ) || strpos( $lang , 'en_' ) > -1 || empty( $lang ) || $lang == 0 ) {
$lang = '';
} else {
$lang .= '/';
}
// check if there is template at theme folder
$template = locate_template( array(
trailingslashit( 'ultimate-member/email' ) . $lang . $template_name . '.php'
) );
//if there isn't template at theme folder get template file from plugin dir
if ( ! $template ) {
$path = ! empty( $this->path_by_slug[ $template_name ] ) ? $this->path_by_slug[ $template_name ] : um_path . 'templates/email';
$template = trailingslashit( $path ) . $lang . $template_name . '.php';
}
// Return what we found.
return apply_filters( 'um_locate_email_template', $template, $template_name );
}
/**
* Locate a template and return the path for inclusion.
*
* @access public
* @param string $template_name
* @return string
*/
function template_in_theme( $template_name ) {
//WPML compatibility and multilingual email templates
$lang = get_locale();
$arr_english_lang = array( 'en', 'en_US', 'en_NZ', 'en_ZA', 'en_AU', 'en_GB' );
if ( in_array( $lang, $arr_english_lang ) || strpos( $lang , 'en_' ) > -1 || empty( $lang ) || $lang == 0 ) {
$lang = '';
} else {
$lang .= '/';
}
// check if there is template at theme folder
$template = locate_template( array(
trailingslashit( 'ultimate-member/email' ) . $lang . $template_name . '.php'
) );
// Return what we found.
return ! $template ? false : true;
}
/**
* Method returns expected path for template
*
* @access public
* @param string $location
* @param string $template_name
* @return string
*/
function get_template_file( $location, $template_name ) {
$template_path = '';
switch( $location ) {
case 'theme':
$template_path = trailingslashit( get_stylesheet_directory() . '/ultimate-member/email' ) . $template_name . '.php';
break;
case 'plugin':
$path = ! empty( $this->path_by_slug[ $template_name ] ) ? $this->path_by_slug[ $template_name ] : um_path . 'templates/email';
$template_path = trailingslashit( $path ) . $template_name . '.php';
break;
}
//return apply_filters( 'wpc_client_template_location', $template_path, $location, $template_name, $path );
return $template_path;
}
/**
* Set email content type
*
*
* @param $content_type
* @return string
*/
function set_content_type( $content_type ) {
return 'text/html';
/*if ( $this->force_plain_text == 'forced' )
return 'text/plain';
if ( um_get_option( 'email_html' ) )
if ( um_get_option( 'email_html' ) ) {
return 'text/html';
} else {
return 'text/plain';
}
return 'text/plain';*/
}
/**
* Ajax copy template to the theme
*
* @param bool $template
* @return bool
*/
function copy_email_template( $template = false ) {
$in_theme = $this->template_in_theme( $template );
if ( $in_theme ) {
return false;
}
$plugin_template_path = $this->get_template_file( 'plugin', $template );
$theme_template_path = $this->get_template_file( 'theme', $template );
$temp_path = str_replace( trailingslashit( get_stylesheet_directory() ), '', $theme_template_path );
$temp_path = str_replace( '/', DIRECTORY_SEPARATOR, $temp_path );
$folders = explode( DIRECTORY_SEPARATOR, $temp_path );
$folders = array_splice( $folders, 0, count( $folders ) - 1 );
$cur_folder = '';
$theme_dir = trailingslashit( get_stylesheet_directory() );
foreach ( $folders as $folder ) {
$prev_dir = $cur_folder;
$cur_folder .= $folder . DIRECTORY_SEPARATOR;
if ( ! is_dir( $theme_dir . $cur_folder ) && wp_is_writable( $theme_dir . $prev_dir ) ) {
mkdir( $theme_dir . $cur_folder, 0777 );
}
}
if ( copy( $plugin_template_path, $theme_template_path ) ) {
return true;
} else {
return false;
}
}
function delete_email_template() {
$template = $_POST['email_key'];
$in_theme = $this->template_in_theme( $template );
if ( ! $in_theme ) {
wp_send_json_error( new \WP_Error( 'template_in_theme', __( 'Template does not exists in theme', 'ultimate-member' ) ) );
}
$theme_template_path = $this->get_template_file( 'theme', $template );
if ( unlink( $theme_template_path ) ) {
wp_send_json_success();
} else {
wp_send_json_error( new \WP_Error( 'template_not_exists', __( 'Can not remove template from theme', 'ultimate-member' ) ) );
}
}
}
}
+3 -3
View File
@@ -746,9 +746,9 @@ if ( ! class_exists( 'User' ) ) {
*
*
*/
function pending(){
$this->set_status('awaiting_admin_review');
UM()->mail()->send( um_user('user_email'), 'pending_email' );
function pending() {
$this->set_status( 'awaiting_admin_review' );
UM()->mail()->send( um_user( 'user_email' ), 'pending_email' );
}
/**
+3 -1
View File
@@ -84,7 +84,9 @@
*/
add_action('um_post_registration_listener', 'um_post_registration_listener', 10, 2);
function um_post_registration_listener( $user_id, $args ) {
if ( um_user('status') != 'pending' ) {
um_fetch_user( $user_id );
if ( um_user( 'status' ) != 'pending' ) {
UM()->mail()->send( um_admin_email(), 'notification_new_user', array( 'admin' => true ) );
} else {
UM()->mail()->send( um_admin_email(), 'notification_review', array( 'admin' => true ) );
+2 -32
View File
@@ -5,37 +5,6 @@
return 'text/html';
}
function UM_Mail( $user_id_or_email = 1, $subject_line = 'Email Subject', $template, $path = null, $args = array() ) {
if ( absint( $user_id_or_email ) ) {
$user = get_userdata( $user_id_or_email );
$email = $user->user_email;
} else {
$email = $user_id_or_email;
}
$headers = 'From: '. um_get_option('mail_from') .' <'. um_get_option('mail_from_addr') .'>' . "\r\n";
$attachments = null;
if ( file_exists( get_stylesheet_directory() . '/ultimate-member/templates/email/' . get_locale() . '/' . $template . '.html' ) ) {
$path_to_email = get_stylesheet_directory() . '/ultimate-member/templates/email/' . get_locale() . '/' . $template . '.html';
} else if ( file_exists( get_stylesheet_directory() . '/ultimate-member/templates/email/' . $template . '.html' ) ) {
$path_to_email = get_stylesheet_directory() . '/ultimate-member/templates/email/' . $template . '.html';
} else {
$path_to_email = $path . $template . '.html';
}
if ( um_get_option('email_html') ) {
$message = file_get_contents( $path_to_email );
add_filter( 'wp_mail_content_type', 'um_mail_content_type' );
} else {
$message = ( um_get_option('email-' . $template ) ) ? um_get_option('email-' . $template ) : 'Untitled';
}
$message = um_convert_tags( $message, $args );
wp_mail( $email, $subject_line, $message, $headers, $attachments );
}
/***
*** @Trim string by char length
***/
@@ -568,7 +537,8 @@
***/
function um_is_temp_upload( $url ) {
$url = realpath( $url );
if ( filter_var( $url, FILTER_VALIDATE_URL ) === false )
$url = realpath( $url );
if ( ! $url )
return false;