PluginProbe
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder / 51.1.83
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder v51.1.83
51.1.84 51.1.85 51.1.83 51.1.82 51.1.81 51.1.79 51.1.78 51.1.77 51.1.76 51.1.74 51.1.75 51.1.65 51.1.64 51.1.63 trunk 51.1.14 51.1.2 51.1.35 51.1.36 51.1.37 51.1.38 51.1.39 51.1.44 51.1.45 51.1.46 All 39 releases
← All changes | includes/widgets/Global_Section_Container/Global_Section_Container.php +56 -32 51.1.3551.1.83 View file →
@@ -1,9 +1,8 @@
1 1 <?php /** @noinspection PhpUnused, DuplicatedCode, SpellCheckingInspection */
2 2
3 3 namespace King_Addons;
4 4
5 -use DOMDocument;
6 5 use Elementor\Controls_Manager;
7 6 use Elementor\Plugin;
8 7 use Elementor\Widget_Base;
9 8
@@ -91,10 +90,10 @@
91 90 if (empty($template_id)) {
92 91 return null;
93 92 }
94 93
95 - $type = get_post_meta(get_the_ID(), '_king_addons_template_type', true);
96 - $has_css = 'internal' === get_option('elementor_css_print_method') || '' !== $type;
94 + // Always include CSS for proper rendering in both editor and frontend
95 + $has_css = true;
97 96
98 97 return Plugin::instance()->frontend->get_builder_content_for_display($template_id, $has_css);
99 98 }
100 99
@@ -101,39 +100,64 @@
101 100 protected function render(): void
102 101 {
103 102 $settings = $this->get_settings_for_display();
104 103 if (!empty($settings['kng_global_section_container_template'])) {
105 - $html = $this->getOffCanvasTemplate(esc_html($settings['kng_global_section_container_template']));
106 - $dom = new DOMDocument;
107 - libxml_use_internal_errors(true); // Disable libxml errors
108 - $dom->loadHTML($html);
109 - libxml_clear_errors();
110 -
111 - $tags = [];
112 - $this->getTagsAndAttributes($dom->documentElement, $tags);
113 -
114 - echo wp_kses($html, $tags);
115 - } else {
116 - echo '<p>' . esc_html__('Please select a template', 'king-addons') . '</p>';
117 - }
118 - }
119 -
120 - public function getTagsAndAttributes($node, &$tags): void
121 - {
122 - if ($node->nodeType == XML_ELEMENT_NODE) {
123 - $tagName = $node->nodeName;
124 - if (!isset($tags[$tagName])) {
125 - $tags[$tagName] = [];
104 + $template_id = intval($settings['kng_global_section_container_template']);
105 +
106 + // Verify template exists and is an Elementor template
107 + $template_post = get_post($template_id);
108 + if (!$template_post || 'elementor_library' !== $template_post->post_type) {
109 + echo '<p>' . esc_html__('Invalid template selected', 'king-addons') . '</p>';
110 + return;
126 111 }
127 -
128 - foreach ($node->attributes as $attr) {
129 - if (!isset($tags[$tagName][$attr->nodeName])) {
130 - $tags[$tagName][$attr->nodeName] = true;
112 +
113 + // Enqueue template styles in editor mode
114 + $is_editor = Plugin::$instance->editor->is_edit_mode() || Plugin::$instance->preview->is_preview_mode();
115 + if ($is_editor) {
116 + if (class_exists('\Elementor\Core\Files\CSS\Post')) {
117 + $css_file = new \Elementor\Core\Files\CSS\Post($template_id);
118 + $css_file->enqueue();
131 119 }
132 120 }
133 - }
134 -
135 - foreach ($node->childNodes as $child) {
136 - $this->getTagsAndAttributes($child, $tags);
121 +
122 + $html = $this->getOffCanvasTemplate($template_id);
123 +
124 + if (empty($html)) {
125 + echo '<p>' . esc_html__('Template is empty or not found', 'king-addons') . '</p>';
126 + return;
127 + }
128 +
129 + // Wrapper for editor animation reset
130 + $widget_id = $this->get_id();
131 + echo '<div class="king-addons-global-section-wrapper" data-widget-id="' . esc_attr($widget_id) . '">';
132 +
133 + // Elementor content is already sanitized by Elementor itself
134 + // Using wp_kses strips inline styles with background-image url() which breaks the layout
135 + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
136 + echo $html;
137 +
138 + echo '</div>';
139 +
140 + // In editor mode, reset entrance animations so content is visible immediately
141 + if ($is_editor) {
142 + ?>
143 + <script>
144 + (function() {
145 + var wrapper = document.querySelector('[data-widget-id="<?php echo esc_js($widget_id); ?>"]');
146 + if (wrapper) {
147 + // Remove animation classes and make elements visible
148 + var animatedElements = wrapper.querySelectorAll('.elementor-invisible, [class*="animated"]');
149 + animatedElements.forEach(function(el) {
150 + el.classList.remove('elementor-invisible');
151 + el.style.opacity = '1';
152 + el.style.visibility = 'visible';
153 + });
154 + }
155 + })();
156 + </script>
157 + <?php
158 + }
159 + } else {
160 + echo '<p>' . esc_html__('Please select a template', 'king-addons') . '</p>';
137 161 }
138 162 }
139 163 }