PluginProbe
Elementor Website Builder – more than just a page builder / 3.32.2
Elementor Website Builder – more than just a page builder v3.32.2
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / core / base / traits / shared-widget-controls-trait.php

shared-widget-controls-trait.php in Elementor Website Builder – more than just a page builder 3.32.2, at core/base/traits/shared-widget-controls-trait.php

299 lines 7.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\Core\Base\Traits;
4
5 use Elementor\Controls_Manager;
6 use Elementor\Modules\FloatingButtons\Control\Hover_Animation_Floating_Buttons;
7 use Elementor\Plugin;
8 use Elementor\Shapes;
9 use Elementor\Utils;
10
11 trait Shared_Widget_Controls_Trait {
12
13 protected $border_width_range = [
14 'min' => 0,
15 'max' => 10,
16 'step' => 1,
17 ];
18
19 protected function add_html_tag_control( string $name, string $default = 'h2' ): void {
20 $this->add_control(
21 $name,
22 [
23 'label' => esc_html__( 'HTML Tag', 'elementor' ),
24 'type' => Controls_Manager::SELECT,
25 'options' => [
26 'h1' => 'H1',
27 'h2' => 'H2',
28 'h3' => 'H3',
29 'h4' => 'H4',
30 'h5' => 'H5',
31 'h6' => 'H6',
32 'div' => 'div',
33 'span' => 'span',
34 'p' => 'p',
35 ],
36 'default' => $default,
37 ]
38 );
39 }
40
41 /**
42 * Remove any child arrays where all properties are empty
43 */
44 protected function clean_array(
45 $input_array = []
46 ) {
47 $output_array = array_filter( $input_array, function( $sub_array ) {
48 // Use array_filter on the sub array
49 $filtered_sub_array = array_filter( $sub_array, function( $val ) {
50 // Filter out empty or null values
51 return ! is_null( $val ) && '' !== $val;
52 } );
53 // A non-empty result means the sub array contains some non-empty value(s)
54 return ! empty( $filtered_sub_array );
55 } );
56 return $output_array;
57 }
58
59 protected function get_link_attributes(
60 $link = [],
61 $other_attributes = []
62 ) {
63 $url_attrs = [];
64 $rel_string = '';
65
66 if ( ! empty( $link['url'] ) ) {
67 $url_attrs['href'] = esc_url( $link['url'] );
68 }
69
70 if ( ! empty( $link['is_external'] ) ) {
71 $url_attrs['target'] = '_blank';
72 $rel_string .= 'noopener ';
73 }
74
75 if ( ! empty( $link['nofollow'] ) ) {
76 $rel_string .= 'nofollow ';
77 }
78
79 if ( ! empty( $rel_string ) ) {
80 $url_attrs['rel'] = $rel_string;
81 }
82
83 /**
84 * Note - we deliberately merge $other_attributes second
85 * to allow overriding default attributes values such as a more formatted href
86 */
87 $url_combined_attrs = array_merge(
88 $url_attrs,
89 $other_attributes,
90 Utils::parse_custom_attributes( $link['custom_attributes'] ?? '' ),
91 );
92
93 return $url_combined_attrs;
94 }
95
96 protected function add_icons_per_row_control(
97 string $name = 'icons_per_row',
98 $options = [
99 '2' => '2',
100 '3' => '3',
101 ],
102 string $default = '3',
103 $label = '',
104 $selector_custom_property = '--e-link-in-bio-icon-columns'
105 ): void {
106 if ( ! $label ) {
107 $label = esc_html__( 'Icons Per Row', 'elementor' );
108 }
109 $this->add_control(
110 $name,
111 [
112 'label' => $label,
113 'type' => Controls_Manager::SELECT,
114 'options' => $options,
115 'default' => $default,
116 'render_type' => 'template',
117 'selectors' => [
118 '{{WRAPPER}} .e-link-in-bio' => $selector_custom_property . ': {{VALUE}};',
119 ],
120 ]
121 );
122 }
123
124 protected function add_slider_control(
125 string $name,
126 array $args = []
127 ): void {
128 $default_args = [
129 'type' => Controls_Manager::SLIDER,
130 'default' => [
131 'unit' => 'px',
132 ],
133 'size_units' => [ 'px', '%', 'em', 'rem', 'vw', 'custom' ],
134 'range' => [
135 'px' => [
136 'min' => 0,
137 'max' => 100,
138 'step' => 1,
139 ],
140 ],
141 ];
142
143 $this->add_control(
144 $name,
145 array_merge_recursive( $default_args, $args )
146 );
147 }
148
149 protected function add_borders_control(
150 string $prefix,
151 array $show_border_args = [],
152 array $border_width_args = [],
153 array $border_color_args = []
154 ): void {
155 $show_border = [
156 'label' => esc_html__( 'Border', 'elementor' ),
157 'type' => Controls_Manager::SWITCHER,
158 'label_on' => esc_html__( 'Yes', 'elementor' ),
159 'label_off' => esc_html__( 'No', 'elementor' ),
160 'return_value' => 'yes',
161 'default' => '',
162 ];
163
164 $this->add_control(
165 $prefix . '_show_border',
166 array_merge( $show_border, $show_border_args )
167 );
168
169 $condition = [
170 $prefix . '_show_border' => 'yes',
171 ];
172
173 if ( isset( $border_width_args['condition'] ) ) {
174 $condition = array_merge( $condition, $border_width_args['condition'] );
175 unset( $border_width_args['condition'] );
176 }
177
178 $border_width = [
179 'label' => esc_html__( 'Border Width', 'elementor' ) . ' (px)',
180 'type' => Controls_Manager::SLIDER,
181 'size_units' => [ 'px' ],
182 'range' => [
183 'px' => $this->border_width_range,
184 ],
185 'condition' => $condition,
186 'default' => [
187 'unit' => 'px',
188 'size' => 1,
189 ],
190 ];
191
192 $this->add_responsive_control(
193 $prefix . '_border_width',
194 array_merge( $border_width, $border_width_args ),
195 );
196
197 $condition = [
198 $prefix . '_show_border' => 'yes',
199 ];
200
201 if ( isset( $border_color_args['condition'] ) ) {
202 $condition = array_merge( $condition, $border_color_args['condition'] );
203 unset( $border_color_args['condition'] );
204 }
205
206 $border_color = [
207 'label' => esc_html__( 'Border Color', 'elementor' ),
208 'type' => Controls_Manager::COLOR,
209 'condition' => $condition,
210 'default' => '#000000',
211 ];
212
213 $this->add_control(
214 $prefix . '_border_color',
215 array_merge( $border_color, $border_color_args )
216 );
217 }
218
219 protected function get_shape_divider( $side = 'bottom' ) {
220 $settings = $this->settings;
221 $base_setting_key = "identity_section_style_cover_divider_$side";
222 $file_name = $settings[ $base_setting_key ];
223
224 if ( empty( $file_name ) ) {
225 return [];
226 }
227
228 $negative = ! empty( $settings[ $base_setting_key . '_negative' ] );
229 $shape_path = Shapes::get_shape_path( $file_name, $negative );
230
231 if ( ! is_file( $shape_path ) || ! is_readable( $shape_path ) ) {
232 return [];
233 }
234
235 return [
236 'negative' => $negative,
237 'svg' => Utils::file_get_contents( $shape_path ),
238 ];
239 }
240
241 protected function print_shape_divider( $side = 'bottom' ) {
242 $shape_divider = $this->get_shape_divider( $side );
243
244 if ( empty( $shape_divider ) ) {
245 return;
246 }
247 ?>
248 <div
249 class="elementor-shape elementor-shape-<?php echo esc_attr( $side ); ?>"
250 aria-hidden="true"
251 data-negative="<?php
252 echo esc_attr( $shape_divider['negative'] ? 'true' : 'false' );
253 ?>"
254 >
255 <?php
256 // PHPCS - The file content is being read from a strict file path structure.
257 echo $shape_divider['svg']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
258 ?>
259 </div>
260 <?php
261 }
262
263 protected function get_configured_breakpoints( $add_desktop = 'true' ) {
264 $active_devices = Plugin::$instance->breakpoints->get_active_devices_list( [ 'reverse' => true ] );
265 $active_breakpoint_instances = Plugin::$instance->breakpoints->get_active_breakpoints();
266
267 $devices_options = [];
268
269 foreach ( $active_devices as $device_key ) {
270 $device_label = 'desktop' === $device_key ? esc_html__( 'Desktop', 'elementor' ) : $active_breakpoint_instances[ $device_key ]->get_label();
271 $devices_options[ $device_key ] = $device_label;
272 }
273
274 return [
275 'active_devices' => $active_devices,
276 'devices_options' => $devices_options,
277 ];
278 }
279
280 protected function add_hover_animation_control(
281 string $name,
282 array $args = []
283 ): void {
284
285 $this->add_control(
286 $name,
287 array_merge(
288 [
289 'label' => esc_html__( 'Hover Animation', 'elementor' ),
290 'type' => Hover_Animation_Floating_Buttons::TYPE,
291 'frontend_available' => true,
292 'default' => 'grow',
293 ],
294 $args
295 )
296 );
297 }
298 }
299