mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-07-13 19:56:27 +09:00
- fixed email templates for multisite;
- fixed upgrade script to 2.0.x version for multisites;
This commit is contained in:
@@ -156,7 +156,6 @@ if ( ! class_exists( 'um\admin\core\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' ),
|
||||
|
||||
@@ -1040,11 +1040,6 @@ if ( ! class_exists( 'um\admin\core\Admin_Forms' ) ) {
|
||||
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,
|
||||
|
||||
@@ -1692,8 +1692,9 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) {
|
||||
$email_key = empty( $_GET['email'] ) ? '' : urldecode( $_GET['email'] );
|
||||
$emails = UM()->config()->email_notifications;
|
||||
|
||||
if ( empty( $email_key ) || empty( $emails[$email_key] ) )
|
||||
if ( empty( $email_key ) || empty( $emails[ $email_key ] ) ) {
|
||||
return $section;
|
||||
}
|
||||
|
||||
$in_theme = UM()->mail()->template_in_theme( $email_key );
|
||||
|
||||
@@ -1722,7 +1723,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) {
|
||||
array(
|
||||
'id' => 'um_email_template',
|
||||
'type' => 'hidden',
|
||||
'value' => $email_key,
|
||||
'value' => $email_key,
|
||||
),
|
||||
array(
|
||||
'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 );
|
||||
|
||||
$in_theme = UM()->mail()->template_in_theme( $template );
|
||||
if ( ! $in_theme ) {
|
||||
UM()->mail()->copy_email_template( $template );
|
||||
}
|
||||
UM()->mail()->copy_email_template( $template );
|
||||
|
||||
$fp = fopen( $theme_template_path, "w" );
|
||||
$result = fputs( $fp, $content );
|
||||
|
||||
@@ -1,53 +1,241 @@
|
||||
<?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
|
||||
*/
|
||||
$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;
|
||||
foreach ( $emails as $email_key => $value ) {
|
||||
|
||||
$in_theme = UM()->mail()->template_in_theme( $email_key, true );
|
||||
$theme_template_path = UM()->mail()->get_template_file( 'theme', $email_key );
|
||||
$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()->mail()->copy_email_template( $email_key ) ) {
|
||||
$setting_value = UM()->options()->get( $email_key );
|
||||
|
||||
$fp = fopen( $theme_template_path, "w" );
|
||||
$result = fputs( $fp, $setting_value );
|
||||
fclose( $fp );
|
||||
if ( ! um_upgrade20beta1_copy_email_template( $email_key ) ) {
|
||||
|
||||
um_upgrade20beta1_insert_content( $theme_template_path, $setting_value );
|
||||
|
||||
} else {
|
||||
|
||||
$templates_in_theme++;
|
||||
|
||||
}
|
||||
} else {
|
||||
$setting_value = UM()->options()->get( $email_key );
|
||||
|
||||
$fp = @fopen( $theme_template_path, "w" );
|
||||
$result = @fputs( $fp, $setting_value );
|
||||
fclose( $fp );
|
||||
um_upgrade20beta1_insert_content( $theme_template_path, $setting_value );
|
||||
|
||||
}
|
||||
|
||||
} 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 ) );
|
||||
|
||||
if ( file_exists( $theme_template_path_html ) ) {
|
||||
|
||||
if ( copy( $theme_template_path_html, $theme_template_path ) ) {
|
||||
$fp = fopen( $theme_template_path, "w" );
|
||||
$result = fputs( $fp, $setting_value );
|
||||
fclose( $fp );
|
||||
|
||||
um_upgrade20beta1_insert_content( $theme_template_path, $setting_value );
|
||||
|
||||
$templates_in_theme++;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ( $templates_in_theme > 0 ) {
|
||||
UM()->options()->update( 'email_html', true );
|
||||
} else {
|
||||
UM()->options()->update( 'email_html', false );
|
||||
}
|
||||
$email_html = ( $templates_in_theme > 0 ) ? true : false;
|
||||
UM()->options()->update( 'email_html', $email_html );*/
|
||||
Reference in New Issue
Block a user