mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-06-05 15:09:37 +09:00
- fixed email templates for multisite;
- fixed upgrade script to 2.0.x version for multisites;
This commit is contained in:
@@ -240,14 +240,6 @@ th.column-email.column-primary {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
.email_template_wrapper .reset_email_template {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.email_template_wrapper.in_theme .reset_email_template {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
|
|
||||||
.um_setting_ajax_button_response.complete {
|
.um_setting_ajax_button_response.complete {
|
||||||
color:darkgreen;
|
color:darkgreen;
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
|
|||||||
@@ -1,42 +1,4 @@
|
|||||||
jQuery( document ).ready( function() {
|
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
|
* Licenses
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -156,7 +156,6 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) {
|
|||||||
wp_enqueue_script( 'um_admin_settings' );
|
wp_enqueue_script( 'um_admin_settings' );
|
||||||
|
|
||||||
$localize_data = array(
|
$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' ),
|
'onbeforeunload_text' => __( 'Are sure, maybe some settings not saved', 'ultimate-member' ),
|
||||||
'texts' => array(
|
'texts' => array(
|
||||||
'remove' => __( 'Remove', 'ultimate-member' ),
|
'remove' => __( 'Remove', 'ultimate-member' ),
|
||||||
|
|||||||
@@ -1040,11 +1040,6 @@ if ( ! class_exists( 'um\admin\core\Admin_Forms' ) ) {
|
|||||||
ob_start(); ?>
|
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;">
|
<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,
|
<?php wp_editor( $value,
|
||||||
$id,
|
$id,
|
||||||
|
|||||||
@@ -1692,8 +1692,9 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) {
|
|||||||
$email_key = empty( $_GET['email'] ) ? '' : urldecode( $_GET['email'] );
|
$email_key = empty( $_GET['email'] ) ? '' : urldecode( $_GET['email'] );
|
||||||
$emails = UM()->config()->email_notifications;
|
$emails = UM()->config()->email_notifications;
|
||||||
|
|
||||||
if ( empty( $email_key ) || empty( $emails[$email_key] ) )
|
if ( empty( $email_key ) || empty( $emails[ $email_key ] ) ) {
|
||||||
return $section;
|
return $section;
|
||||||
|
}
|
||||||
|
|
||||||
$in_theme = UM()->mail()->template_in_theme( $email_key );
|
$in_theme = UM()->mail()->template_in_theme( $email_key );
|
||||||
|
|
||||||
@@ -1722,7 +1723,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) {
|
|||||||
array(
|
array(
|
||||||
'id' => 'um_email_template',
|
'id' => 'um_email_template',
|
||||||
'type' => 'hidden',
|
'type' => 'hidden',
|
||||||
'value' => $email_key,
|
'value' => $email_key,
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'id' => $email_key . '_on',
|
'id' => $email_key . '_on',
|
||||||
@@ -2535,10 +2536,7 @@ Use Only Cookies: <?php echo ini_get( 'session.use_only_cookies' ) ?
|
|||||||
|
|
||||||
$theme_template_path = UM()->mail()->get_template_file( 'theme', $template );
|
$theme_template_path = UM()->mail()->get_template_file( 'theme', $template );
|
||||||
|
|
||||||
$in_theme = UM()->mail()->template_in_theme( $template );
|
UM()->mail()->copy_email_template( $template );
|
||||||
if ( ! $in_theme ) {
|
|
||||||
UM()->mail()->copy_email_template( $template );
|
|
||||||
}
|
|
||||||
|
|
||||||
$fp = fopen( $theme_template_path, "w" );
|
$fp = fopen( $theme_template_path, "w" );
|
||||||
$result = fputs( $fp, $content );
|
$result = fputs( $fp, $content );
|
||||||
|
|||||||
@@ -1,53 +1,241 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Locate a template and return the path for inclusion.
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param string $template_name
|
||||||
|
* @param bool $html
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function um_upgrade20beta1_template_in_theme( $template_name, $html = false ) {
|
||||||
|
$template_name_file = UM()->mail()->get_template_filename( $template_name );
|
||||||
|
$ext = ! $html ? '.php' : '.html';
|
||||||
|
|
||||||
|
$blog_id = '';
|
||||||
|
if ( ! $html ) {
|
||||||
|
$blog_id = UM()->mail()->get_blog_id();
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if there is template at theme folder
|
||||||
|
$template = locate_template( array(
|
||||||
|
trailingslashit( 'ultimate-member/email' . $blog_id ) . $template_name_file . $ext
|
||||||
|
) );
|
||||||
|
// Return what we found.
|
||||||
|
return ! $template ? false : true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method returns expected path for template
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param string $location
|
||||||
|
* @param string $template_name
|
||||||
|
* @param bool $html
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function um_upgrade20beta1_get_template_file( $location, $template_name, $html = false ) {
|
||||||
|
$template_path = '';
|
||||||
|
$template_name_file = UM()->mail()->get_template_filename( $template_name );
|
||||||
|
$ext = ! $html ? '.php' : '.html';
|
||||||
|
switch( $location ) {
|
||||||
|
case 'theme':
|
||||||
|
|
||||||
|
$blog_id = '';
|
||||||
|
if ( ! $html ) {
|
||||||
|
$blog_id = UM()->mail()->get_blog_id();
|
||||||
|
}
|
||||||
|
|
||||||
|
$template_path = trailingslashit( get_stylesheet_directory() . '/ultimate-member/email' . $blog_id ). $template_name_file . $ext;
|
||||||
|
break;
|
||||||
|
case 'plugin':
|
||||||
|
$path = ! empty( UM()->mail()->path_by_slug[ $template_name ] ) ? UM()->mail()->path_by_slug[ $template_name ] : um_path . 'templates/email';
|
||||||
|
$template_path = trailingslashit( $path ) . $template_name . $ext;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return $template_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ajax copy template to the theme
|
||||||
|
*
|
||||||
|
* @param string $template
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function um_upgrade20beta1_copy_email_template( $template ) {
|
||||||
|
$in_theme = um_upgrade20beta1_template_in_theme( $template );
|
||||||
|
if ( $in_theme ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$plugin_template_path = um_upgrade20beta1_get_template_file( 'plugin', $template );
|
||||||
|
$theme_template_path = um_upgrade20beta1_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 ( file_exists( $plugin_template_path ) && copy( $plugin_template_path, $theme_template_path ) ) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Insert email template content to file
|
||||||
|
*
|
||||||
|
* @param string $path Filepath
|
||||||
|
* @param string $content Email template content
|
||||||
|
*/
|
||||||
|
function um_upgrade20beta1_insert_content( $path, $content ) {
|
||||||
|
$fp = @fopen( $path, "w" );
|
||||||
|
@fputs( $fp, $content );
|
||||||
|
@fclose( $fp );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transferring email templates to new logic
|
* Transferring email templates to new logic
|
||||||
*/
|
*/
|
||||||
$templates_in_theme = 0;
|
function um_upgrade20beta1_email_templates_process() {
|
||||||
|
$templates_in_theme = 0;
|
||||||
|
$emails = UM()->config()->email_notifications;
|
||||||
|
foreach ( $emails as $email_key => $value ) {
|
||||||
|
|
||||||
|
$in_theme = um_upgrade20beta1_template_in_theme( $email_key, true );
|
||||||
|
$theme_template_path = um_upgrade20beta1_get_template_file( 'theme', $email_key );
|
||||||
|
|
||||||
|
if ( ! $in_theme ) {
|
||||||
|
//there isn't HTML email template's file in theme, get from option
|
||||||
|
//this value is correct for each multisite's subsites
|
||||||
|
$setting_value = UM()->options()->get( $email_key );
|
||||||
|
|
||||||
|
$html_email = UM()->options()->get( 'email_html' );
|
||||||
|
if ( $html_email ) {
|
||||||
|
|
||||||
|
if ( ! um_upgrade20beta1_copy_email_template( $email_key ) ) {
|
||||||
|
|
||||||
|
um_upgrade20beta1_insert_content( $theme_template_path, $setting_value );
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
$templates_in_theme++;
|
||||||
|
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
um_upgrade20beta1_insert_content( $theme_template_path, $setting_value );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
//there is HTML email template in a theme's folder
|
||||||
|
$theme_template_path_html = um_upgrade20beta1_get_template_file( 'theme', $email_key, true );
|
||||||
|
|
||||||
|
$setting_value = preg_replace( '/<\/body>|<\/head>|<html>|<\/html>|<body.*?>|<head.*?>/' , '', file_get_contents( $theme_template_path_html ) );
|
||||||
|
|
||||||
|
if ( file_exists( $theme_template_path_html ) ) {
|
||||||
|
|
||||||
|
if ( copy( $theme_template_path_html, $theme_template_path ) ) {
|
||||||
|
|
||||||
|
um_upgrade20beta1_insert_content( $theme_template_path, $setting_value );
|
||||||
|
|
||||||
|
$templates_in_theme++;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$email_html = ( $templates_in_theme > 0 ) ? true : false;
|
||||||
|
UM()->options()->update( 'email_html', $email_html );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ( is_multisite() ) {
|
||||||
|
$start_blog_id = get_current_blog_id();
|
||||||
|
|
||||||
|
$blog_ids = get_sites( array(
|
||||||
|
'fields' => 'ids',
|
||||||
|
) );
|
||||||
|
|
||||||
|
foreach ( $blog_ids as $blog_id ) {
|
||||||
|
switch_to_blog( $blog_id );
|
||||||
|
um_upgrade20beta1_email_templates_process();
|
||||||
|
}
|
||||||
|
|
||||||
|
restore_current_blog();
|
||||||
|
} else {
|
||||||
|
um_upgrade20beta1_email_templates_process();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transferring email templates to new logic
|
||||||
|
*/
|
||||||
|
/*$templates_in_theme = 0;
|
||||||
$emails = UM()->config()->email_notifications;
|
$emails = UM()->config()->email_notifications;
|
||||||
foreach ( $emails as $email_key => $value ) {
|
foreach ( $emails as $email_key => $value ) {
|
||||||
|
|
||||||
$in_theme = UM()->mail()->template_in_theme( $email_key, true );
|
$in_theme = um_upgrade20beta1_template_in_theme( $email_key, true );
|
||||||
$theme_template_path = UM()->mail()->get_template_file( 'theme', $email_key );
|
$theme_template_path = um_upgrade20beta1_get_template_file( 'theme', $email_key );
|
||||||
|
|
||||||
if ( ! $in_theme ) {
|
if ( ! $in_theme ) {
|
||||||
|
//there isn't HTML email template's file in theme, get from option
|
||||||
|
//this value is correct for each multisite's subsites
|
||||||
|
$setting_value = UM()->options()->get( $email_key );
|
||||||
|
|
||||||
$html_email = UM()->options()->get( 'email_html' );
|
$html_email = UM()->options()->get( 'email_html' );
|
||||||
|
|
||||||
if ( $html_email ) {
|
if ( $html_email ) {
|
||||||
if ( ! UM()->mail()->copy_email_template( $email_key ) ) {
|
|
||||||
$setting_value = UM()->options()->get( $email_key );
|
|
||||||
|
|
||||||
$fp = fopen( $theme_template_path, "w" );
|
if ( ! um_upgrade20beta1_copy_email_template( $email_key ) ) {
|
||||||
$result = fputs( $fp, $setting_value );
|
|
||||||
fclose( $fp );
|
um_upgrade20beta1_insert_content( $theme_template_path, $setting_value );
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
$templates_in_theme++;
|
$templates_in_theme++;
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$setting_value = UM()->options()->get( $email_key );
|
|
||||||
|
|
||||||
$fp = @fopen( $theme_template_path, "w" );
|
um_upgrade20beta1_insert_content( $theme_template_path, $setting_value );
|
||||||
$result = @fputs( $fp, $setting_value );
|
|
||||||
fclose( $fp );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$theme_template_path_html = UM()->mail()->get_template_file( 'theme', $email_key, true );
|
//there is HTML email template in a theme's folder
|
||||||
|
$theme_template_path_html = um_upgrade20beta1_get_template_file( 'theme', $email_key, true );
|
||||||
|
|
||||||
$setting_value = preg_replace( '/<\/body>|<\/head>|<html>|<\/html>|<body.*?>|<head.*?>/' , '', file_get_contents( $theme_template_path_html ) );
|
$setting_value = preg_replace( '/<\/body>|<\/head>|<html>|<\/html>|<body.*?>|<head.*?>/' , '', file_get_contents( $theme_template_path_html ) );
|
||||||
|
|
||||||
if ( file_exists( $theme_template_path_html ) ) {
|
if ( file_exists( $theme_template_path_html ) ) {
|
||||||
|
|
||||||
if ( copy( $theme_template_path_html, $theme_template_path ) ) {
|
if ( copy( $theme_template_path_html, $theme_template_path ) ) {
|
||||||
$fp = fopen( $theme_template_path, "w" );
|
|
||||||
$result = fputs( $fp, $setting_value );
|
um_upgrade20beta1_insert_content( $theme_template_path, $setting_value );
|
||||||
fclose( $fp );
|
|
||||||
|
|
||||||
$templates_in_theme++;
|
$templates_in_theme++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $templates_in_theme > 0 ) {
|
$email_html = ( $templates_in_theme > 0 ) ? true : false;
|
||||||
UM()->options()->update( 'email_html', true );
|
UM()->options()->update( 'email_html', $email_html );*/
|
||||||
} else {
|
|
||||||
UM()->options()->update( 'email_html', false );
|
|
||||||
}
|
|
||||||
+97
-130
@@ -36,6 +36,23 @@ if ( ! class_exists( 'um\core\Mail' ) ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mandrill compatibility
|
||||||
|
*
|
||||||
|
* @param $nl2br
|
||||||
|
* @param string $message
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function mandrill_nl2br( $nl2br, $message = '' ) {
|
||||||
|
// text emails
|
||||||
|
if ( ! UM()->options()->get( 'email_html' ) ) {
|
||||||
|
$nl2br = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $nl2br;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init paths for email notifications
|
* Init paths for email notifications
|
||||||
*/
|
*/
|
||||||
@@ -66,72 +83,73 @@ if ( ! class_exists( 'um\core\Mail' ) ) {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mandrill compatibility
|
* Check blog ID on multisite, return '' if single site
|
||||||
*
|
*
|
||||||
* @param $nl2br
|
* @return string
|
||||||
* @param string $message
|
|
||||||
* @return bool
|
|
||||||
*/
|
*/
|
||||||
function mandrill_nl2br( $nl2br, $message = '' ) {
|
function get_blog_id() {
|
||||||
// text emails
|
$blog_id = '';
|
||||||
if ( ! UM()->options()->get( 'email_html' ) ) {
|
if ( is_multisite() ) {
|
||||||
$nl2br = true;
|
$blog_id = '/' . get_current_blog_id();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $nl2br;
|
return $blog_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send Email function
|
* Locate a template and return the path for inclusion.
|
||||||
*
|
*
|
||||||
* @param string $email
|
* @access public
|
||||||
* @param null $template
|
* @param string $template_name
|
||||||
* @param array $args
|
* @return string
|
||||||
*/
|
*/
|
||||||
function send( $email, $template, $args = array() ) {
|
function locate_template( $template_name ) {
|
||||||
|
// check if there is template at theme folder
|
||||||
|
$blog_id = $this->get_blog_id();
|
||||||
|
|
||||||
if ( ! is_email( $email ) ) return;
|
//get template file from current blog ID folder
|
||||||
if ( UM()->options()->get( $template . '_on' ) != 1 ) return;
|
$template = locate_template( array(
|
||||||
|
trailingslashit( 'ultimate-member/email' . $blog_id ) . $template_name . '.php'
|
||||||
|
) );
|
||||||
|
|
||||||
$this->attachments = null;
|
//if there isn't template at theme folder for current blog ID get template file from theme folder
|
||||||
$this->headers = 'From: '. UM()->options()->get('mail_from') .' <'. UM()->options()->get('mail_from_addr') .'>' . "\r\n";
|
if ( is_multisite() && ! $template ) {
|
||||||
|
$template = locate_template( array(
|
||||||
|
trailingslashit( 'ultimate-member/email' ) . $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 ) . $template_name . '.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return what we found.
|
||||||
/**
|
/**
|
||||||
* UM hook
|
* UM hook
|
||||||
*
|
*
|
||||||
* @type filter
|
* @type filter
|
||||||
* @title um_email_send_subject
|
* @title um_locate_email_template
|
||||||
* @description Change email notification subject
|
* @description Change email notification template path
|
||||||
* @input_vars
|
* @input_vars
|
||||||
* [{"var":"$subject","type":"string","desc":"Subject"},
|
* [{"var":"$template","type":"string","desc":"Template Path"},
|
||||||
* {"var":"$key","type":"string","desc":"Template Key"}]
|
* {"var":"$template_name","type":"string","desc":"Template Name"}]
|
||||||
* @change_log
|
* @change_log
|
||||||
* ["Since: 2.0"]
|
* ["Since: 2.0"]
|
||||||
* @usage
|
* @usage
|
||||||
* <?php add_filter( 'um_email_send_subject', 'function_name', 10, 2 ); ?>
|
* <?php add_filter( 'um_locate_email_template', 'function_name', 10, 2 ); ?>
|
||||||
* @example
|
* @example
|
||||||
* <?php
|
* <?php
|
||||||
* add_filter( 'um_email_send_subject', 'my_email_send_subject', 10, 2 );
|
* add_filter( 'um_locate_email_template', 'my_locate_email_template', 10, 2 );
|
||||||
* function my_email_send_subject( $subject, $key ) {
|
* function my_email_template_body_attrs( $template, $template_name ) {
|
||||||
* // your code here
|
* // your code here
|
||||||
* return $paths;
|
* return $template;
|
||||||
* }
|
* }
|
||||||
* ?>
|
* ?>
|
||||||
*/
|
*/
|
||||||
$subject = apply_filters( 'um_email_send_subject', UM()->options()->get( $template . '_sub' ), $template );
|
return apply_filters( 'um_locate_email_template', $template, $template_name );
|
||||||
$this->subject = um_convert_tags( $subject , $args );
|
|
||||||
|
|
||||||
$this->message = $this->prepare_template( $template, $args );
|
|
||||||
|
|
||||||
if ( UM()->options()->get( 'email_html' ) ) {
|
|
||||||
$this->headers .= "Content-Type: text/html\r\n";
|
|
||||||
} else {
|
|
||||||
$this->headers .= "Content-Type: text/plain\r\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send mail
|
|
||||||
wp_mail( $email, $this->subject, $this->message, $this->headers, $this->attachments );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -313,7 +331,7 @@ if ( ! class_exists( 'um\core\Mail' ) ) {
|
|||||||
|
|
||||||
<body <?php echo $body_attrs ?>>
|
<body <?php echo $body_attrs ?>>
|
||||||
|
|
||||||
<?php echo $this->get_email_template( $slug, $args ); ?>
|
<?php echo $this->get_email_template( $slug, $args ); ?>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -358,58 +376,55 @@ if ( ! class_exists( 'um\core\Mail' ) ) {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Locate a template and return the path for inclusion.
|
* Send Email function
|
||||||
*
|
*
|
||||||
* @access public
|
* @param string $email
|
||||||
* @param string $template_name
|
* @param null $template
|
||||||
* @return string
|
* @param array $args
|
||||||
*/
|
*/
|
||||||
function locate_template( $template_name ) {
|
function send( $email, $template, $args = array() ) {
|
||||||
// check if there is template at theme folder
|
|
||||||
$blog_id = $this->get_blog_id();
|
|
||||||
|
|
||||||
//get template file from current blog ID folder
|
if ( ! is_email( $email ) ) return;
|
||||||
$template = locate_template( array(
|
if ( UM()->options()->get( $template . '_on' ) != 1 ) return;
|
||||||
trailingslashit( 'ultimate-member/email' . $blog_id ) . $template_name . '.php'
|
|
||||||
) );
|
|
||||||
|
|
||||||
//if there isn't template at theme folder for current blog ID get template file from theme folder
|
$this->attachments = null;
|
||||||
if ( is_multisite() && ! $template ) {
|
$this->headers = 'From: '. UM()->options()->get('mail_from') .' <'. UM()->options()->get('mail_from_addr') .'>' . "\r\n";
|
||||||
$template = locate_template( array(
|
|
||||||
trailingslashit( 'ultimate-member/email' ) . $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 ) . $template_name . '.php';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return what we found.
|
|
||||||
/**
|
/**
|
||||||
* UM hook
|
* UM hook
|
||||||
*
|
*
|
||||||
* @type filter
|
* @type filter
|
||||||
* @title um_locate_email_template
|
* @title um_email_send_subject
|
||||||
* @description Change email notification template path
|
* @description Change email notification subject
|
||||||
* @input_vars
|
* @input_vars
|
||||||
* [{"var":"$template","type":"string","desc":"Template Path"},
|
* [{"var":"$subject","type":"string","desc":"Subject"},
|
||||||
* {"var":"$template_name","type":"string","desc":"Template Name"}]
|
* {"var":"$key","type":"string","desc":"Template Key"}]
|
||||||
* @change_log
|
* @change_log
|
||||||
* ["Since: 2.0"]
|
* ["Since: 2.0"]
|
||||||
* @usage
|
* @usage
|
||||||
* <?php add_filter( 'um_locate_email_template', 'function_name', 10, 2 ); ?>
|
* <?php add_filter( 'um_email_send_subject', 'function_name', 10, 2 ); ?>
|
||||||
* @example
|
* @example
|
||||||
* <?php
|
* <?php
|
||||||
* add_filter( 'um_locate_email_template', 'my_locate_email_template', 10, 2 );
|
* add_filter( 'um_email_send_subject', 'my_email_send_subject', 10, 2 );
|
||||||
* function my_email_template_body_attrs( $template, $template_name ) {
|
* function my_email_send_subject( $subject, $key ) {
|
||||||
* // your code here
|
* // your code here
|
||||||
* return $template;
|
* return $paths;
|
||||||
* }
|
* }
|
||||||
* ?>
|
* ?>
|
||||||
*/
|
*/
|
||||||
return apply_filters( 'um_locate_email_template', $template, $template_name );
|
$subject = apply_filters( 'um_email_send_subject', UM()->options()->get( $template . '_sub' ), $template );
|
||||||
|
$this->subject = um_convert_tags( $subject , $args );
|
||||||
|
|
||||||
|
$this->message = $this->prepare_template( $template, $args );
|
||||||
|
|
||||||
|
if ( UM()->options()->get( 'email_html' ) ) {
|
||||||
|
$this->headers .= "Content-Type: text/html\r\n";
|
||||||
|
} else {
|
||||||
|
$this->headers .= "Content-Type: text/plain\r\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send mail
|
||||||
|
wp_mail( $email, $this->subject, $this->message, $this->headers, $this->attachments );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -449,72 +464,47 @@ if ( ! class_exists( 'um\core\Mail' ) ) {
|
|||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $template_name
|
* @param string $template_name
|
||||||
* @param bool $html
|
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function template_in_theme( $template_name, $html = false ) {
|
function template_in_theme( $template_name ) {
|
||||||
$template_name_file = $this->get_template_filename( $template_name );
|
$template_name_file = $this->get_template_filename( $template_name );
|
||||||
$ext = ! $html ? '.php' : '.html';
|
|
||||||
|
|
||||||
$blog_id = $this->get_blog_id();
|
$blog_id = $this->get_blog_id();
|
||||||
|
|
||||||
// check if there is template at theme blog ID folder
|
// check if there is template at theme blog ID folder
|
||||||
$template = locate_template( array(
|
$template = locate_template( array(
|
||||||
trailingslashit( 'ultimate-member/email' . $blog_id ) . $template_name_file . $ext
|
trailingslashit( 'ultimate-member/email' . $blog_id ) . $template_name_file . '.php'
|
||||||
) );
|
) );
|
||||||
|
|
||||||
//if there isn't template at theme folder for current blog ID get template file from theme folder
|
|
||||||
if ( is_multisite() && ! $template ) {
|
|
||||||
$template = locate_template( array(
|
|
||||||
trailingslashit( 'ultimate-member/email' ) . $template_name_file . $ext
|
|
||||||
) );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return what we found.
|
// Return what we found.
|
||||||
return ! $template ? false : true;
|
return ! $template ? false : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check blog ID on multisite, return '' if single site
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
function get_blog_id() {
|
|
||||||
$blog_id = '';
|
|
||||||
if ( is_multisite() ) {
|
|
||||||
$blog_id = '/' . get_current_blog_id();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $blog_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method returns expected path for template
|
* Method returns expected path for template
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
|
*
|
||||||
* @param string $location
|
* @param string $location
|
||||||
* @param string $template_name
|
* @param string $template_name
|
||||||
* @param bool $html
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function get_template_file( $location, $template_name, $html = false ) {
|
function get_template_file( $location, $template_name ) {
|
||||||
$template_path = '';
|
$template_path = '';
|
||||||
$template_name_file = $this->get_template_filename( $template_name );
|
$template_name_file = $this->get_template_filename( $template_name );
|
||||||
|
|
||||||
$ext = ! $html ? '.php' : '.html';
|
|
||||||
|
|
||||||
switch( $location ) {
|
switch( $location ) {
|
||||||
case 'theme':
|
case 'theme':
|
||||||
//save email template in blog ID folder if we use multisite
|
//save email template in blog ID folder if we use multisite
|
||||||
$blog_id = $this->get_blog_id();
|
$blog_id = $this->get_blog_id();
|
||||||
|
|
||||||
$template_path = trailingslashit( get_stylesheet_directory() . '/ultimate-member/email' . $blog_id ). $template_name_file . $ext;
|
$template_path = trailingslashit( get_stylesheet_directory() . '/ultimate-member/email' . $blog_id ). $template_name_file . '.php';
|
||||||
break;
|
break;
|
||||||
case 'plugin':
|
case 'plugin':
|
||||||
$path = ! empty( $this->path_by_slug[ $template_name ] ) ? $this->path_by_slug[ $template_name ] : um_path . 'templates/email';
|
$path = ! empty( $this->path_by_slug[ $template_name ] ) ? $this->path_by_slug[ $template_name ] : um_path . 'templates/email';
|
||||||
$template_path = trailingslashit( $path ) . $template_name . $ext;
|
$template_path = trailingslashit( $path ) . $template_name . '.php';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -525,10 +515,10 @@ if ( ! class_exists( 'um\core\Mail' ) ) {
|
|||||||
/**
|
/**
|
||||||
* Ajax copy template to the theme
|
* Ajax copy template to the theme
|
||||||
*
|
*
|
||||||
* @param bool $template
|
* @param string $template
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
function copy_email_template( $template = false ) {
|
function copy_email_template( $template ) {
|
||||||
|
|
||||||
$in_theme = $this->template_in_theme( $template );
|
$in_theme = $this->template_in_theme( $template );
|
||||||
if ( $in_theme ) {
|
if ( $in_theme ) {
|
||||||
@@ -559,28 +549,5 @@ if ( ! class_exists( 'um\core\Mail' ) ) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete Email Notification Template
|
|
||||||
*
|
|
||||||
* @deprecated since 2.0.17
|
|
||||||
*/
|
|
||||||
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' ) ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user