PluginProbe
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder / 51.1.86
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder v51.1.86
51.1.86 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 All 40 releases
← All changes | includes/widgets/Global_Section_Container/Global_Section_Container.php +163 -0 51.1.2 → 51.1.86 View file →
@@ -1,0 +1,163 @@
1 +<?php /** @noinspection PhpUnused, DuplicatedCode, SpellCheckingInspection */
2 +
3 +namespace King_Addons;
4 +
5 +use Elementor\Controls_Manager;
6 +use Elementor\Plugin;
7 +use Elementor\Widget_Base;
8 +
9 +if (!defined('ABSPATH')) {
10 + exit; // Exit if accessed directly.
11 +}
12 +
13 +
14 +
15 +class Global_Section_Container extends Widget_Base
16 +{
17 +
18 +
19 + public function get_name(): string
20 + {
21 + return 'king-addons-global-section-container';
22 + }
23 +
24 + public function get_title(): string
25 + {
26 + return esc_html__('Global Section & Container', 'king-addons');
27 + }
28 +
29 + public function get_icon(): string
30 + {
31 + return 'king-addons-icon king-addons-global-section-container';
32 + }
33 +
34 + public function get_categories(): array
35 + {
36 + return ['king-addons'];
37 + }
38 +
39 + public function get_keywords(): array
40 + {
41 + return ['content', 'template', 'templates', 'container', 'section', 'column', 'widget', 'module', 'connect',
42 + 'global widget', 'global', 'reusable', 'across', 'multiple', 'multi', 'page', 'pages',
43 + 'king', 'addons', 'kingaddons', 'king-addons', 'off canvas', 'embed'];
44 + }
45 +
46 + public function get_custom_help_url()
47 + {
48 + return 'mailto:[email protected]?subject=Bug Report - King Addons&body=Please describe the issue';
49 + }
50 +
51 + protected function register_controls(): void
52 + {
53 + $this->start_controls_section(
54 + 'kng_global_section_container_general',
55 + [
56 + 'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('General', 'king-addons'),
57 + ]
58 + );
59 +
60 + $this->add_control(
61 + 'kng_global_section_container_template',
62 + [
63 + 'label' => esc_html__('Select Template', 'king-addons'),
64 + 'type' => 'king-addons-ajax-select2',
65 + 'options' => 'ajaxselect2/getElementorTemplates',
66 + 'label_block' => true,
67 + ]
68 + );
69 +
70 + $this->add_control(
71 + 'kng_global_section_container_alert_info',
72 + [
73 + 'type' => Controls_Manager::ALERT,
74 + 'alert_type' => 'info',
75 + 'heading' => esc_html__('Note for Entrance Animations in Editor mode', 'king-addons'),
76 + 'content' => esc_html__('If any content within the global template has Entrance Animations configured in the Advanced -> Motion Effects tab, it may not be displayed after selecting the template in Editor mode (Elementor editor). This occurs because the Entrance Animations are triggered immediately after the page loads. To address this issue, try saving your changes and reloading this editor page; following this, the global template should fully appear in most cases. The problem does not affect the appearance of the live website and is only present in the editor.', 'king-addons'),
77 + ]
78 + );
79 +
80 +
81 +
82 +
83 +$this->end_controls_section();
84 +
85 +
86 + }
87 +
88 + public function getOffCanvasTemplate($template_id): ?string
89 + {
90 + if (empty($template_id)) {
91 + return null;
92 + }
93 +
94 + // Always include CSS for proper rendering in both editor and frontend
95 + $has_css = true;
96 +
97 + return Plugin::instance()->frontend->get_builder_content_for_display($template_id, $has_css);
98 + }
99 +
100 + protected function render(): void
101 + {
102 + $settings = $this->get_settings_for_display();
103 + if (!empty($settings['kng_global_section_container_template'])) {
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;
111 + }
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();
119 + }
120 + }
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>';
161 + }
162 + }
163 +}