PluginProbe
UiCore Elements – Free widgets and templates for Elementor / 1.3.17
UiCore Elements – Free widgets and templates for Elementor v1.3.17
1.3.17 1.3.16 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 All 41 releases
← All changes | includes/class-nested-widget-base.php +161 -139 1.0.61.3.17 View file →
@@ -1,174 +1,196 @@
1 1 <?php
2 +
2 3 namespace UiCoreElements;
3 4
4 5 use Elementor\Plugin;
6 +use Elementor\Settings;
5 7
6 8 /**
7 9 * Base for nested widgets.
8 10 * Based on Elementor Nested Widget Class. Keep it in sync with future updates on Elementor core.
9 11 *
10 - * @since [currentVersion]
12 + * @since 1.0.6
11 13 */
12 14
13 -abstract class UiCoreNestedWidget extends UiCoreWidget {
15 +abstract class UiCoreNestedWidget extends UiCoreWidget
16 +{
14 17
15 18 /**
16 - * Get default children elements structure.
17 - *
18 - * @return array
19 - */
20 - abstract protected function get_default_children_elements();
19 + * Get default children elements structure.
20 + *
21 + * @return array
22 + */
23 + abstract protected function get_default_children_elements();
21 24
22 - /**
23 - * Get repeater title setting key name.
24 - *
25 - * @return string
26 - */
27 - abstract protected function get_default_repeater_title_setting_key();
25 + /**
26 + * Get repeater title setting key name.
27 + *
28 + * @return string
29 + */
30 + abstract protected function get_default_repeater_title_setting_key();
28 31
29 - /**
30 - * Get default children title for the navigator, using `%d` as index in the format.
31 - *
32 - * @note The title in this method is used to set the default title for each created child in nested element.
33 - * for handling the children title for new created widget(s), use `get_default_children_elements()` method,
34 - * eg:
35 - * [
36 - * 'elType' => 'container',
37 - * 'settings' => [
38 - * '_title' => __( 'Tab #1', 'elementor' ),
39 - * ],
40 - * ],
41 - * @return string
42 - */
43 - protected function get_default_children_title() {
44 - return esc_html__( 'Item #%d', 'elementor' );
45 - }
32 + /**
33 + * Get default children title for the navigator, using `%d` as index in the format.
34 + *
35 + * @note The title in this method is used to set the default title for each created child in nested element.
36 + * for handling the children title for new created widget(s), use `get_default_children_elements()` method,
37 + * eg:
38 + * [
39 + * 'elType' => 'container',
40 + * 'settings' => [
41 + * '_title' => __( 'Tab #1', 'uicore-elements' ),
42 + * ],
43 + * ],
44 + * @return string
45 + */
46 + protected function get_default_children_title()
47 + {
48 + /* translators: item number */
49 + return esc_html__('Item #%d', 'uicore-elements');
50 + }
46 51
47 - /**
48 - * Get default children placeholder selector, Empty string, means will be added at the end view.
49 - *
50 - * @return string
51 - */
52 - protected function get_default_children_placeholder_selector() {
53 - return '';
54 - }
52 + /**
53 + * Get default children placeholder selector, Empty string, means will be added at the end view.
54 + *
55 + * @return string
56 + */
57 + protected function get_default_children_placeholder_selector()
58 + {
59 + return '';
60 + }
55 61
56 - protected function get_default_children_container_placeholder_selector() {
57 - return '';
58 - }
62 + protected function get_default_children_container_placeholder_selector()
63 + {
64 + return '';
65 + }
59 66
60 - /**
61 - * @inheritDoc
62 - *
63 - * To support nesting.
64 - */
65 - protected function _get_default_child_type( array $element_data ) {
66 - return Plugin::$instance->elements_manager->get_element_types( $element_data['elType'] );
67 - }
67 + /**
68 + * @inheritDoc
69 + *
70 + * To support nesting.
71 + */
72 + protected function _get_default_child_type(array $element_data)
73 + {
74 + return Plugin::$instance->elements_manager->get_element_types($element_data['elType']);
75 + }
68 76
69 - /**
70 - * @inheritDoc
71 - *
72 - * Adding new 'defaults' config for handling children elements.
73 - */
74 - protected function get_initial_config() {
75 - return array_merge( parent::get_initial_config(), [
76 - 'defaults' => [
77 - 'elements' => $this->get_default_children_elements(),
78 - 'elements_title' => $this->get_default_children_title(),
79 - 'elements_placeholder_selector' => $this->get_default_children_placeholder_selector(),
80 - 'child_container_placeholder_selector' => $this->get_default_children_container_placeholder_selector(),
81 - 'repeater_title_setting' => $this->get_default_repeater_title_setting_key(),
82 - ],
83 - 'support_nesting' => true,
84 - ] );
85 - }
77 + /**
78 + * @inheritDoc
79 + *
80 + * Adding new 'defaults' config for handling children elements.
81 + */
82 + protected function get_initial_config()
83 + {
84 + return array_merge(parent::get_initial_config(), [
85 + 'defaults' => [
86 + 'elements' => $this->get_default_children_elements(),
87 + 'elements_title' => $this->get_default_children_title(),
88 + 'elements_placeholder_selector' => $this->get_default_children_placeholder_selector(),
89 + 'child_container_placeholder_selector' => $this->get_default_children_container_placeholder_selector(),
90 + 'repeater_title_setting' => $this->get_default_repeater_title_setting_key(),
91 + ],
92 + 'support_nesting' => true,
93 + ]);
94 + }
86 95
87 - /**
88 - * @inheritDoc
89 - *
90 - * Each element including its children elements.
91 - */
92 - public function get_raw_data( $with_html_content = false ) {
93 - $elements = [];
94 - $data = $this->get_data();
96 + /**
97 + * @inheritDoc
98 + *
99 + * Each element including its children elements.
100 + */
101 + public function get_raw_data($with_html_content = false)
102 + {
103 + $elements = [];
104 + $data = $this->get_data();
95 105
96 - $children = $this->get_children();
106 + $children = $this->get_children();
97 107
98 - foreach ( $children as $child ) {
99 - $child_raw_data = $child->get_raw_data( $with_html_content );
108 + foreach ($children as $child) {
109 + $child_raw_data = $child->get_raw_data($with_html_content);
100 110
101 - $elements[] = $child_raw_data;
102 - }
111 + $elements[] = $child_raw_data;
112 + }
103 113
104 - return [
105 - 'id' => $this->get_id(),
106 - 'elType' => $data['elType'],
107 - 'widgetType' => $data['widgetType'],
108 - 'settings' => $data['settings'],
109 - 'elements' => $elements,
110 - ];
111 - }
114 + return [
115 + 'id' => $this->get_id(),
116 + 'elType' => $data['elType'],
117 + 'widgetType' => $data['widgetType'],
118 + 'settings' => $data['settings'],
119 + 'elements' => $elements,
120 + ];
121 + }
112 122
113 - /**
114 - * Print child, helper method to print the child element.
115 - *
116 - * @param int $index
117 - */
118 - public function print_child( $index ) {
119 - $children = $this->get_children();
123 + /**
124 + * Print child, helper method to print the child element.
125 + *
126 + * @param int $index
127 + */
128 + public function print_child($index)
129 + {
130 + $children = $this->get_children();
131 + // \error_log('print_child');
132 + // \error_log( print_r( $children, true ) );
133 + // \error_log( print_r( $index, true ) );
134 + if (! empty($children[$index])) {
135 + $children[$index]->print_element();
136 + }
137 + }
120 138
121 - if ( ! empty( $children[ $index ] ) ) {
122 - $children[ $index ]->print_element();
123 - }
124 - }
139 + protected function content_template_single_repeater_item() {}
125 140
126 - protected function content_template_single_repeater_item() {}
141 + public function print_template()
142 + {
143 + parent::print_template();
144 + if ($this->get_initial_config()['support_improved_repeaters'] ?? false) {
145 +?>
146 + <script type="text/html" id="tmpl-elementor-<?php echo esc_attr($this->get_name()); ?>-content-single">
147 + <?php $this->content_template_single_repeater_item(); ?>
148 + </script>
149 +<?php
150 + }
151 + }
127 152
128 - public function print_template() {
129 - parent::print_template();
130 - if ( $this->get_initial_config()['support_improved_repeaters'] ?? false ) {
131 - ?>
132 - <script type="text/html" id="tmpl-elementor-<?php echo esc_attr( $this->get_name() ); ?>-content-single">
133 - <?php $this->content_template_single_repeater_item(); ?>
134 - </script>
135 - <?php
136 - }
137 - }
153 + /**
154 + * Displays fallback content for the nesting feature.
155 + *
156 + * @param string $type The type of fallback content. Can be `controls` or `text`. Default is `text`.
157 + * @return void
158 + * @since 1.0.6
159 + */
160 + public function nesting_fallback(string $type = 'text')
161 + {
138 162
139 - /**
140 - * Displays fallback content for the nesting feature.
141 - *
142 - * @param string $type The type of fallback content. Can be `controls` or `text`. Default is `text`.
143 - * @return void
144 - * @since [currentVersion]
145 - */
146 - public function nesting_fallback(string $type = 'text') {
163 + /* translators: 1: Opening anchor tag, 2: Closing anchor tag for the link to the Elementor settings page. */
164 + $warning = sprintf(
165 + /* translators: 1: opening url tags 2: closing url tag */
166 + __('Please, %1$s click here %2$s and enable the Nested Elements experiment in Elementor settings', 'uicore-elements'),
167 + '<a href="' . esc_attr(Settings::get_settings_tab_url('experiments')) . '" target="_blank">',
168 + '</a>'
169 + );
147 170
148 - if ( 'text' === $type ) {
171 + if ('text' === $type) {
149 172
150 - echo esc_html__('Please, enable the Nested Elements experiment in Elementor settings to use this widget.', 'uicore-elements');
173 + echo wp_kses_post($warning);
174 + } else if ('controls' === $type) {
175 + $this->start_controls_section(
176 + 'section_tabs',
177 + [
178 + 'label' => esc_html__('Tabs', 'uicore-elements'),
179 + 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
180 + ]
181 + );
151 182
152 - } else if ('controls' === $type ){
153 - $this->start_controls_section(
154 - 'section_tabs',
155 - [
156 - 'label' => esc_html__( 'Tabs', 'uicore-elements' ),
157 - 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
158 - ]
159 - );
183 + $this->add_control(
184 + 'tabs_alert',
185 + [
186 + 'type' => \Elementor\Controls_Manager::ALERT,
187 + 'alert_type' => 'danger',
188 + 'heading' => esc_html__('Feature Disabled.', 'uicore-elements'),
189 + 'content' => wp_kses_post($warning)
190 + ]
191 + );
160 192
161 - $this->add_control(
162 - 'tabs_alert',
163 - [
164 - 'type' => \Elementor\Controls_Manager::ALERT,
165 - 'alert_type' => 'danger',
166 - 'heading' => esc_html__( 'Feature Disabled.', 'uicore-elements' ),
167 - 'content' => esc_html__( 'Please, enable the Nested Elements experiment in Elementor settings to use this widget.', 'uicore-elements' ),
168 - ]
169 - );
170 -
171 - $this->end_controls_section();
172 - }
193 + $this->end_controls_section();
194 + }
173 195 }
174 196 }