From 13deeb975ef8564b682832bb0dbff5bee9de7a88 Mon Sep 17 00:00:00 2001 From: Kobi Zaltzberg Date: Wed, 8 Nov 2017 18:44:40 +0200 Subject: [PATCH] Fixed editor templates not loading in some server configurations. Fixes #2712 --- core/settings/base/manager.php | 2 +- includes/editor.php | 47 +++++++++++++++++++--------------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/core/settings/base/manager.php b/core/settings/base/manager.php index 63f7409212c..fb2d91b0fef 100644 --- a/core/settings/base/manager.php +++ b/core/settings/base/manager.php @@ -103,7 +103,7 @@ public function add_settings_css_rules( CSS_File $css_file ) { } public function on_elementor_init() { - Plugin::$instance->editor->add_editor_template( $this->get_editor_template() ); + Plugin::$instance->editor->add_editor_template( $this->get_editor_template(), 'text' ); } /** diff --git a/includes/editor.php b/includes/editor.php index 1cd868a7da8..6295d028ca0 100644 --- a/includes/editor.php +++ b/includes/editor.php @@ -30,8 +30,6 @@ public function init( $die = true ) { return; } - $this->init_editor_templates(); - // Send MIME Type header like WP admin-header. @header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) ); @@ -598,10 +596,20 @@ public function editor_head_trigger() { /** * @since 1.0.0 * @access public - * @param string $template_path - Can be either a link to template file or template HTML content + * + * @param string $template - Can be either a link to template file or template HTML content + * @param string $type Optional. Whether to handle the template as path or text */ - public function add_editor_template( $template_path ) { - $this->_editor_templates[] = $template_path; + public function add_editor_template( $template, $type = 'path' ) { + if ( 'path' === $type ) { + ob_start(); + + include $template; + + $template = ob_get_clean(); + } + + $this->_editor_templates[] = $template; } /** @@ -617,16 +625,10 @@ public function wp_footer() { $plugin->schemes_manager->print_schemes_templates(); - $abs_path = str_replace( '\\', '/', ABSPATH ); + $this->init_editor_templates(); foreach ( $this->_editor_templates as $editor_template ) { - $template_abs_path = str_replace( '\\', '/', substr( $editor_template, 0, strlen( ABSPATH ) ) ); - - if ( $template_abs_path === $abs_path ) { - include $editor_template; - } else { - echo $editor_template; - } + echo $editor_template; } do_action( 'elementor/editor/footer' ); @@ -655,13 +657,16 @@ public function __construct() { * @access private */ private function init_editor_templates() { - // It can be filled from plugins - $this->_editor_templates = array_merge( $this->_editor_templates, [ - __DIR__ . '/editor-templates/global.php', - __DIR__ . '/editor-templates/panel.php', - __DIR__ . '/editor-templates/panel-elements.php', - __DIR__ . '/editor-templates/repeater.php', - __DIR__ . '/editor-templates/templates.php', - ] ); + $template_names = [ + 'global', + 'panel', + 'panel-elements', + 'repeater', + 'templates', + ]; + + foreach ( $template_names as $template_name ) { + $this->add_editor_template( __DIR__ . "/editor-templates/$template_name.php" ); + } } }