From 8b5bb5d7840cdc4edf7307fddbba3965a1222023 Mon Sep 17 00:00:00 2001 From: Nikita Sinelnikov Date: Tue, 13 Dec 2022 15:52:57 +0200 Subject: [PATCH] - fixed #1082; - used wp_mkdir to avoid the filesystem conflict; --- includes/admin/core/class-admin-settings.php | 12 +++++----- includes/core/class-mail.php | 25 +++++++------------- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/includes/admin/core/class-admin-settings.php b/includes/admin/core/class-admin-settings.php index 50f8c98a..aaa0b977 100644 --- a/includes/admin/core/class-admin-settings.php +++ b/includes/admin/core/class-admin-settings.php @@ -3457,7 +3457,6 @@ Use Only Cookies: mail()->get_template_file( 'theme', $template ); - if ( ! file_exists( $theme_template_path ) ) { UM()->mail()->copy_email_template( $template ); } - $fp = fopen( $theme_template_path, "w" ); - $result = fputs( $fp, $content ); - fclose( $fp ); + if ( file_exists( $theme_template_path ) ) { + $fp = fopen( $theme_template_path, "w" ); + $result = fputs( $fp, $content ); + fclose( $fp ); + } - if ( $result !== false ) { + if ( isset( $result ) && $result !== false ) { unset( $settings['um_email_template'] ); unset( $settings[ $template ] ); } diff --git a/includes/core/class-mail.php b/includes/core/class-mail.php index bef34181..e7c7b288 100644 --- a/includes/core/class-mail.php +++ b/includes/core/class-mail.php @@ -552,28 +552,19 @@ if ( ! class_exists( 'um\core\Mail' ) ) { * @return bool */ function copy_email_template( $template ) { - $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 ); + $plugin_template_path = wp_normalize_path( $this->get_template_file( 'plugin', $template ) ); + $theme_template_path = wp_normalize_path( $this->get_template_file( 'theme', $template ) ); + $template_filename = $this->get_template_filename( $template ) . '.php'; - $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 ); - } + $template_dir = wp_normalize_path( str_replace( $template_filename, '', $theme_template_path ) ); + $result = wp_mkdir_p( $template_dir ); + if ( ! $result ) { + return false; } if ( file_exists( $plugin_template_path ) && copy( $plugin_template_path, $theme_template_path ) ) { @@ -621,4 +612,4 @@ if ( ! class_exists( 'um\core\Mail' ) ) { return $replace_placeholders; } } -} \ No newline at end of file +}