PluginProbe
Elementor Website Builder – more than just a page builder / 3.34.3
Elementor Website Builder – more than just a page builder v3.34.3
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 / includes / base / element-base.php

element-base.php in Elementor Website Builder – more than just a page builder 3.34.3, at includes/base/element-base.php

1,595 lines 39.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor;
3
4 use Elementor\Core\Breakpoints\Manager as Breakpoints_Manager;
5
6 if ( ! defined( 'ABSPATH' ) ) {
7 exit; // Exit if accessed directly.
8 }
9
10 /**
11 * Elementor element base.
12 *
13 * An abstract class to register new Elementor elements. It extended the
14 * `Controls_Stack` class to inherit its properties.
15 *
16 * This abstract class must be extended in order to register new elements.
17 *
18 * @since 1.0.0
19 * @abstract
20 */
21 abstract class Element_Base extends Controls_Stack {
22
23 /**
24 * Child elements.
25 *
26 * Holds all the child elements of the element.
27 *
28 * @access private
29 *
30 * @var Element_Base[]
31 */
32 private $children;
33
34 /**
35 * Element default arguments.
36 *
37 * Holds all the default arguments of the element. Used to store additional
38 * data. For example WordPress widgets use this to store widget names.
39 *
40 * @access private
41 *
42 * @var array
43 */
44 private $default_args = [];
45
46 /**
47 * Is type instance.
48 *
49 * Whether the element is an instance of that type or not.
50 *
51 * @access private
52 *
53 * @var bool
54 */
55 private $is_type_instance = true;
56
57 /**
58 * Depended scripts.
59 *
60 * Holds all the element depended scripts to enqueue.
61 *
62 * @since 1.9.0
63 * @access private
64 *
65 * @var array
66 */
67 private $depended_scripts = [];
68
69 /**
70 * Depended styles.
71 *
72 * Holds all the element depended styles to enqueue.
73 *
74 * @since 1.9.0
75 * @access private
76 *
77 * @var array
78 */
79 private $depended_styles = [];
80
81 /**
82 * Add script depends.
83 *
84 * Register new script to enqueue by the handler.
85 *
86 * @since 1.9.0
87 * @access public
88 *
89 * @param string $handler Depend script handler.
90 */
91 public function add_script_depends( $handler ) {
92 $this->depended_scripts[] = $handler;
93 }
94
95 /**
96 * Add style depends.
97 *
98 * Register new style to enqueue by the handler.
99 *
100 * @since 1.9.0
101 * @access public
102 *
103 * @param string $handler Depend style handler.
104 */
105 public function add_style_depends( $handler ) {
106 $this->depended_styles[] = $handler;
107 }
108
109 /**
110 * Get script dependencies.
111 *
112 * Retrieve the list of script dependencies the element requires.
113 *
114 * @since 1.3.0
115 * @access public
116 *
117 * @return array Element scripts dependencies.
118 */
119 public function get_script_depends() {
120 return $this->depended_scripts;
121 }
122
123 public function get_global_scripts() {
124 return [ 'elementor-frontend' ];
125 }
126
127 /**
128 * Enqueue scripts.
129 *
130 * Registers all the scripts defined as element dependencies and enqueues
131 * them. Use `get_script_depends()` method to add custom script dependencies.
132 *
133 * @since 1.3.0
134 * @access public
135 */
136 final public function enqueue_scripts() {
137 $deprecated_scripts = [
138 // Insert here when you have a deprecated script.
139 ];
140
141 foreach ( $this->get_script_depends() as $script ) {
142 if ( isset( $deprecated_scripts[ $script ] ) ) {
143 Utils::handle_deprecation( $script, $deprecated_scripts[ $script ]['version'], $deprecated_scripts[ $script ]['replacement'] );
144 }
145
146 wp_enqueue_script( $script );
147 }
148
149 foreach ( $this->get_global_scripts() as $script ) {
150 wp_enqueue_script( $script );
151 }
152 }
153
154 public function register_frontend_handlers() {}
155
156 /**
157 * Get style dependencies.
158 *
159 * Retrieve the list of style dependencies the element requires.
160 *
161 * @since 1.9.0
162 * @access public
163 *
164 * @return array Element styles dependencies.
165 */
166 public function get_style_depends() {
167 return $this->depended_styles;
168 }
169
170 /**
171 * Enqueue styles.
172 *
173 * Registers all the styles defined as element dependencies and enqueues
174 * them. Use `get_style_depends()` method to add custom style dependencies.
175 *
176 * @since 1.9.0
177 * @access public
178 */
179 final public function enqueue_styles() {
180 foreach ( $this->get_style_depends() as $style ) {
181 wp_enqueue_style( $style );
182 }
183 }
184
185 /**
186 * @since 1.0.0
187 * @deprecated 2.6.0
188 * @access public
189 * @static
190 */
191 final public static function add_edit_tool() {}
192
193 /**
194 * @since 2.2.0
195 * @deprecated 2.6.0
196 * @access public
197 * @static
198 */
199 final public static function is_edit_buttons_enabled() {
200 return get_option( 'elementor_edit_buttons' );
201 }
202
203 /**
204 * Get default child type.
205 *
206 * Retrieve the default child type based on element data.
207 *
208 * Note that not all elements support children.
209 *
210 * @since 1.0.0
211 * @access protected
212 * @abstract
213 *
214 * @param array $element_data Element data.
215 *
216 * @return Element_Base
217 */
218 abstract protected function _get_default_child_type( array $element_data );
219
220 /**
221 * Before element rendering.
222 *
223 * Used to add stuff before the element.
224 *
225 * @since 1.0.0
226 * @access public
227 */
228 public function before_render() {}
229
230 /**
231 * After element rendering.
232 *
233 * Used to add stuff after the element.
234 *
235 * @since 1.0.0
236 * @access public
237 */
238 public function after_render() {}
239
240 /**
241 * Get element title.
242 *
243 * Retrieve the element title.
244 *
245 * @since 1.0.0
246 * @access public
247 *
248 * @return string Element title.
249 */
250 public function get_title() {
251 return '';
252 }
253
254 /**
255 * Get element icon.
256 *
257 * Retrieve the element icon.
258 *
259 * @since 1.0.0
260 * @access public
261 *
262 * @return string Element icon.
263 */
264 public function get_icon() {
265 return 'eicon-columns';
266 }
267
268 public function get_help_url() {
269 return 'https://go.elementor.com/widget-' . $this->get_name();
270 }
271
272 public function get_custom_help_url() {
273 return '';
274 }
275
276 /**
277 * Whether the reload preview is required.
278 *
279 * Used to determine whether the reload preview is required or not.
280 *
281 * @since 1.0.0
282 * @access public
283 *
284 * @return bool Whether the reload preview is required.
285 */
286 public function is_reload_preview_required() {
287 return false;
288 }
289
290 /**
291 * @since 2.3.1
292 * @access protected
293 */
294 protected function should_print_empty() {
295 return true;
296 }
297
298 /**
299 * Whether the element returns dynamic content.
300 *
301 * Set to determine whether to cache the element output or not.
302 *
303 * @since 3.22.0
304 * @access protected
305 *
306 * @return bool Whether to cache the element output.
307 */
308 protected function is_dynamic_content(): bool {
309 return true;
310 }
311
312 /**
313 * Get child elements.
314 *
315 * Retrieve all the child elements of this element.
316 *
317 * @since 1.0.0
318 * @access public
319 *
320 * @return Element_Base[] Child elements.
321 */
322 public function get_children() {
323 if ( null === $this->children ) {
324 $this->init_children();
325 }
326
327 return $this->children;
328 }
329
330 /**
331 * Get default arguments.
332 *
333 * Retrieve the element default arguments. Used to return all the default
334 * arguments or a specific default argument, if one is set.
335 *
336 * @since 1.0.0
337 * @access public
338 *
339 * @param array $item Optional. Default is null.
340 *
341 * @return array Default argument(s).
342 */
343 public function get_default_args( $item = null ) {
344 return self::get_items( $this->default_args, $item );
345 }
346
347 /**
348 * Get panel presets.
349 *
350 * Used for displaying the widget in the panel multiple times, but with different defaults values,
351 * icon, title etc.
352 *
353 * @since 3.16.0
354 * @access public
355 *
356 * @return array
357 */
358 public function get_panel_presets() {
359 return [];
360 }
361
362 /**
363 * Add new child element.
364 *
365 * Register new child element to allow hierarchy.
366 *
367 * @since 1.0.0
368 * @access public
369 * @param array $child_data Child element data.
370 * @param array $child_args Child element arguments.
371 *
372 * @return Element_Base|false Child element instance, or false if failed.
373 */
374 public function add_child( array $child_data, array $child_args = [] ) {
375 if ( null === $this->children ) {
376 $this->init_children();
377 }
378
379 $child_type = $this->get_child_type( $child_data );
380
381 if ( ! $child_type ) {
382 return false;
383 }
384
385 $child = Plugin::$instance->elements_manager->create_element_instance( $child_data, $child_args, $child_type );
386
387 if ( $child ) {
388 $this->children[] = $child;
389 }
390
391 return $child;
392 }
393
394 /**
395 * Add link render attributes.
396 *
397 * Used to add link tag attributes to a specific HTML element.
398 *
399 * The HTML link tag is represented by the element parameter. The `url_control` parameter
400 * needs to be an array of link settings in the same format they are set by Elementor's URL control.
401 *
402 * Example usage:
403 *
404 * `$this->add_link_attributes( 'button', $settings['link'] );`
405 *
406 * @since 2.8.0
407 * @access public
408 *
409 * @param array|string $element The HTML element.
410 * @param array $url_control Array of link settings.
411 * @param bool $overwrite Optional. Whether to overwrite existing
412 * attribute. Default is false, not to overwrite.
413 *
414 * @return Element_Base Current instance of the element.
415 */
416 public function add_link_attributes( $element, array $url_control, $overwrite = false ) {
417 $attributes = [];
418
419 if ( ! empty( $url_control['url'] ) ) {
420 $allowed_protocols = array_merge( wp_allowed_protocols(), [ 'skype', 'viber' ] );
421
422 $attributes['href'] = esc_url( $url_control['url'], $allowed_protocols );
423 }
424
425 if ( ! empty( $url_control['is_external'] ) ) {
426 $attributes['target'] = '_blank';
427 }
428
429 if ( ! empty( $url_control['nofollow'] ) ) {
430 $attributes['rel'] = 'nofollow';
431 }
432
433 if ( ! empty( $url_control['custom_attributes'] ) ) {
434 // Custom URL attributes should come as a string of comma-delimited key|value pairs.
435 $attributes = array_merge( $attributes, Utils::parse_custom_attributes( $url_control['custom_attributes'] ) );
436 }
437
438 if ( $attributes ) {
439 $this->add_render_attribute( $element, $attributes, null, $overwrite );
440 }
441
442 return $this;
443 }
444
445 /**
446 * Print element.
447 *
448 * Used to generate the element final HTML on the frontend and the editor.
449 *
450 * @since 1.0.0
451 * @access public
452 */
453 public function print_element() {
454 $element_type = $this->get_type();
455
456 if ( $this->should_render_shortcode() ) {
457 $unique_id = apply_filters( 'elementor/element_cache/unique_id', '' );
458
459 echo '[elementor-element k="' . esc_attr( $unique_id ) . '" data="' . esc_attr( base64_encode( wp_json_encode( $this->get_raw_data() ) ) ) . '"]';
460 return;
461 }
462
463 /**
464 * Before frontend element render.
465 *
466 * Fires before Elementor element is rendered in the frontend.
467 *
468 * @since 2.2.0
469 *
470 * @param Element_Base $this The element.
471 */
472 do_action( 'elementor/frontend/before_render', $this );
473
474 /**
475 * Before frontend element render.
476 *
477 * Fires before Elementor element is rendered in the frontend.
478 *
479 * The dynamic portion of the hook name, `$element_type`, refers to the element type.
480 *
481 * @since 1.0.0
482 *
483 * @param Element_Base $this The element.
484 */
485 do_action( "elementor/frontend/{$element_type}/before_render", $this );
486
487 ob_start();
488
489 if ( $this->has_own_method( '_print_content', self::class ) ) {
490 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( '_print_content', '3.1.0', __CLASS__ . '::print_content()' );
491
492 $this->_print_content();
493 } else {
494 $this->print_content();
495 }
496
497 $content = ob_get_clean();
498
499 $should_render = ( ! empty( $content ) || $this->should_print_empty() );
500
501 /**
502 * Should the element be rendered for frontend
503 *
504 * Filters if the element should be rendered on frontend.
505 *
506 * @since 2.3.3
507 *
508 * @param bool true The element.
509 * @param Element_Base $this The element.
510 */
511 $should_render = apply_filters( "elementor/frontend/{$element_type}/should_render", $should_render, $this );
512
513 if ( $should_render ) {
514 if ( $this->has_own_method( '_add_render_attributes', self::class ) ) {
515 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( '_add_render_attributes', '3.1.0', __CLASS__ . '::add_render_attributes()' );
516
517 $this->_add_render_attributes();
518 } else {
519 $this->add_render_attributes();
520 }
521
522 $this->before_render();
523 // PHPCS - The content has already been escaped by the `render` method.
524 echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
525 $this->after_render();
526
527 // TODO: Remove this in the future
528 // Since version 3.24.0 page scripts/styles are handled by `page_assets`.
529 $this->enqueue_scripts();
530 $this->enqueue_styles();
531 }
532
533 /**
534 * After frontend element render.
535 *
536 * Fires after Elementor element is rendered in the frontend.
537 *
538 * The dynamic portion of the hook name, `$element_type`, refers to the element type.
539 *
540 * @since 1.0.0
541 *
542 * @param Element_Base $this The element.
543 */
544 do_action( "elementor/frontend/{$element_type}/after_render", $this );
545
546 /**
547 * After frontend element render.
548 *
549 * Fires after Elementor element is rendered in the frontend.
550 *
551 * @since 2.3.0
552 *
553 * @param Element_Base $this The element.
554 */
555 do_action( 'elementor/frontend/after_render', $this );
556 }
557
558 protected function should_render_shortcode() {
559 $should_render_shortcode = apply_filters( 'elementor/element/should_render_shortcode', false );
560
561 if ( ! $should_render_shortcode ) {
562 return false;
563 }
564
565 $raw_data = $this->get_raw_data();
566
567 if ( ! empty( $raw_data['settings']['_element_cache'] ) ) {
568 return 'yes' === $raw_data['settings']['_element_cache'];
569 }
570
571 if ( $this->is_dynamic_content() ) {
572 return true;
573 }
574
575 $is_dynamic_content = apply_filters( 'elementor/element/is_dynamic_content', false, $raw_data, $this );
576
577 $has_dynamic_tag = $this->has_element_dynamic_tag( $raw_data['settings'] );
578
579 if ( $is_dynamic_content || $has_dynamic_tag ) {
580 return true;
581 }
582
583 return false;
584 }
585
586 private function has_element_dynamic_tag( $element_settings ): bool {
587 if ( is_array( $element_settings ) ) {
588 if ( ! empty( $element_settings['__dynamic__'] ) ) {
589 return true;
590 }
591
592 foreach ( $element_settings as $value ) {
593 $has_dynamic = $this->has_element_dynamic_tag( $value );
594
595 if ( $has_dynamic ) {
596 return true;
597 }
598 }
599 }
600
601 return false;
602 }
603
604 /**
605 * Get the element raw data.
606 *
607 * Retrieve the raw element data, including the id, type, settings, child
608 * elements and whether it is an inner element.
609 *
610 * The data with the HTML used always to display the data, but the Elementor
611 * editor uses the raw data without the HTML in order not to render the data
612 * again.
613 *
614 * @since 1.0.0
615 * @access public
616 *
617 * @param bool $with_html_content Optional. Whether to return the data with
618 * HTML content or without. Used for caching.
619 * Default is false, without HTML.
620 *
621 * @return array Element raw data.
622 */
623 public function get_raw_data( $with_html_content = false ) {
624 $data = $this->get_data();
625
626 $elements = [];
627
628 foreach ( $this->get_children() as $child ) {
629 $elements[] = $child->get_raw_data( $with_html_content );
630 }
631
632 $raw_data = [
633 'id' => $this->get_id(),
634 'elType' => $data['elType'],
635 'settings' => $data['settings'],
636 'elements' => $elements,
637 'isInner' => $data['isInner'],
638 ];
639
640 if ( ! empty( $data['isLocked'] ) ) {
641 $raw_data['isLocked'] = $data['isLocked'];
642 }
643
644 return $raw_data;
645 }
646
647 public function get_data_for_save() {
648 $data = $this->get_raw_data();
649
650 $elements = [];
651
652 foreach ( $this->get_children() as $child ) {
653 $elements[] = $child->get_data_for_save();
654 }
655
656 if ( ! empty( $elements ) ) {
657 $data['elements'] = $elements;
658 }
659
660 if ( ! empty( $data['settings'] ) ) {
661 $data['settings'] = $this->on_save( $data['settings'] );
662 }
663
664 return $data;
665 }
666
667 /**
668 * Get unique selector.
669 *
670 * Retrieve the unique selector of the element. Used to set a unique HTML
671 * class for each HTML element. This way Elementor can set custom styles for
672 * each element.
673 *
674 * @since 1.0.0
675 * @access public
676 *
677 * @return string Unique selector.
678 */
679 public function get_unique_selector() {
680 return '.elementor-element-' . $this->get_id();
681 }
682
683 /**
684 * Is type instance.
685 *
686 * Used to determine whether the element is an instance of that type or not.
687 *
688 * @since 1.0.0
689 * @access public
690 *
691 * @return bool Whether the element is an instance of that type.
692 */
693 public function is_type_instance() {
694 return $this->is_type_instance;
695 }
696
697 /**
698 * On import update dynamic content (e.g. post and term IDs).
699 *
700 * @since 3.8.0
701 *
702 * @param array $config The config of the passed element.
703 * @param array $data The data that requires updating/replacement when imported.
704 * @param array|null $controls The available controls.
705 *
706 * @return array Element data.
707 */
708 public static function on_import_update_dynamic_content( array $config, array $data, $controls = null ): array {
709 $tags_manager = Plugin::$instance->dynamic_tags;
710
711 if ( empty( $config['settings'][ $tags_manager::DYNAMIC_SETTING_KEY ] ) ) {
712 return $config;
713 }
714
715 foreach ( $config['settings'][ $tags_manager::DYNAMIC_SETTING_KEY ] as $dynamic_name => $dynamic_value ) {
716 $tag_config = $tags_manager->tag_text_to_tag_data( $dynamic_value );
717 $tag_instance = $tags_manager->create_tag( $tag_config['id'], $tag_config['name'], $tag_config['settings'] );
718
719 if ( is_null( $tag_instance ) ) {
720 continue;
721 }
722
723 if ( $tag_instance->has_own_method( 'on_import_replace_dynamic_content' ) ) {
724 // TODO: Remove this check in the future.
725 $tag_config = $tag_instance->on_import_replace_dynamic_content( $tag_config, $data['post_ids'] );
726 } else {
727 $tag_config = $tag_instance->on_import_update_dynamic_content( $tag_config, $data, $tag_instance->get_controls() );
728 }
729
730 $config['settings'][ $tags_manager::DYNAMIC_SETTING_KEY ][ $dynamic_name ] = $tags_manager->tag_data_to_tag_text( $tag_config['id'], $tag_config['name'], $tag_config['settings'] );
731 }
732
733 return $config;
734 }
735
736 /**
737 * Add render attributes.
738 *
739 * Used to add attributes to the current element wrapper HTML tag.
740 *
741 * @since 1.3.0
742 * @access protected
743 * @deprecated 3.1.0 Use `add_render_attribute()` method instead.
744 */
745 protected function _add_render_attributes() {
746 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.1.0', 'add_render_attributes()' );
747
748 return $this->add_render_attributes();
749 }
750
751 /**
752 * Add render attributes.
753 *
754 * Used to add attributes to the current element wrapper HTML tag.
755 *
756 * @since 3.1.0
757 * @access protected
758 */
759 protected function add_render_attributes() {
760 $id = $this->get_id();
761
762 $settings = $this->get_settings_for_display();
763 $frontend_settings = $this->get_frontend_settings();
764 $controls = $this->get_controls();
765
766 $this->add_render_attribute( '_wrapper', [
767 'class' => [
768 'elementor-element',
769 'elementor-element-' . $id,
770 ],
771 'data-id' => $id,
772 'data-element_type' => $this->get_type(),
773 ] );
774
775 $class_settings = [];
776
777 foreach ( $settings as $setting_key => $setting ) {
778 if ( isset( $controls[ $setting_key ]['prefix_class'] ) ) {
779 if ( isset( $controls[ $setting_key ]['classes_dictionary'][ $setting ] ) ) {
780 $value = $controls[ $setting_key ]['classes_dictionary'][ $setting ];
781 } else {
782 $value = $setting;
783 }
784
785 $class_settings[ $setting_key ] = $value;
786 }
787 }
788
789 foreach ( $class_settings as $setting_key => $setting ) {
790 if ( empty( $setting ) && '0' !== $setting ) {
791 continue;
792 }
793
794 $this->add_render_attribute( '_wrapper', 'class', $controls[ $setting_key ]['prefix_class'] . $setting );
795 }
796
797 $_animation = ! empty( $settings['_animation'] );
798 $animation = ! empty( $settings['animation'] );
799 $has_animation = ( $_animation && 'none' !== $settings['_animation'] ) || ( $animation && 'none' !== $settings['animation'] );
800
801 if ( $has_animation ) {
802 $is_static_render_mode = Plugin::$instance->frontend->is_static_render_mode();
803
804 if ( ! $is_static_render_mode ) {
805 // Hide the element until the animation begins.
806 $this->add_render_attribute( '_wrapper', 'class', 'elementor-invisible' );
807 }
808 }
809
810 if ( ! empty( $settings['_element_id'] ) ) {
811 $this->add_render_attribute( '_wrapper', 'id', trim( $settings['_element_id'] ) );
812 }
813
814 if ( $frontend_settings ) {
815 $this->add_render_attribute( '_wrapper', 'data-settings', wp_json_encode( $frontend_settings ) );
816 }
817
818 /**
819 * After element attribute rendered.
820 *
821 * Fires after the attributes of the element HTML tag are rendered.
822 *
823 * @since 2.3.0
824 *
825 * @param Element_Base $this The element.
826 */
827 do_action( 'elementor/element/after_add_attributes', $this );
828 }
829
830 /**
831 * Register the Transform controls in the advanced tab of the element.
832 *
833 * Previously registered under the Widget_Common class, but registered a more fundamental level now to enable access from other widgets.
834 *
835 * @param string $element_selector
836 * @param string $transform_selector_class
837 * @return void
838 * @since 3.9.0
839 * @access protected
840 */
841 protected function register_transform_section( $element_selector = '', $transform_selector_class = ' > .elementor-widget-container' ) {
842 $default_unit_values_deg = [];
843 $default_unit_values_ms = [];
844
845 // Set the default unit sizes for all active breakpoints.
846 foreach ( Breakpoints_Manager::get_default_config() as $breakpoint_name => $breakpoint_config ) {
847 $default_unit_values_deg[ $breakpoint_name ] = [
848 'default' => [
849 'unit' => 'deg',
850 ],
851 ];
852
853 $default_unit_values_ms[ $breakpoint_name ] = [
854 'default' => [
855 'unit' => 'ms',
856 ],
857 ];
858 }
859
860 $this->start_controls_section(
861 '_section_transform',
862 [
863 'label' => esc_html__( 'Transform', 'elementor' ),
864 'tab' => Controls_Manager::TAB_ADVANCED,
865 ]
866 );
867
868 $this->start_controls_tabs( '_tabs_positioning' );
869
870 $transform_prefix_class = 'e-';
871 $transform_return_value = 'transform';
872 $transform_css_modifier = '';
873
874 if ( 'con' === $element_selector ) {
875 $transform_selector_class = '.e-' . $element_selector;
876 $transform_css_modifier = $element_selector . '-';
877 }
878
879 foreach ( [ '', '_hover' ] as $tab ) {
880 $state = '_hover' === $tab ? ':hover' : '';
881
882 $this->start_controls_tab(
883 "_tab_positioning{$tab}",
884 [
885 'label' => '' === $tab ? esc_html__( 'Normal', 'elementor' ) : esc_html__( 'Hover', 'elementor' ),
886 ]
887 );
888
889 $this->add_control(
890 "_transform_rotate_popover{$tab}",
891 [
892 'label' => esc_html__( 'Rotate', 'elementor' ),
893 'type' => Controls_Manager::POPOVER_TOGGLE,
894 'prefix_class' => $transform_prefix_class,
895 'return_value' => $transform_return_value,
896 ]
897 );
898
899 $this->start_popover();
900
901 $this->add_responsive_control(
902 "_transform_rotateZ_effect{$tab}",
903 [
904 'label' => esc_html__( 'Rotate', 'elementor' ) . ' (deg)',
905 'type' => Controls_Manager::SLIDER,
906 'device_args' => $default_unit_values_deg,
907 'range' => [
908 'px' => [
909 'min' => -360,
910 'max' => 360,
911 ],
912 ],
913 'selectors' => [
914 "{{WRAPPER}}{$transform_selector_class}{$state}" => '--e-' . $transform_css_modifier . 'transform-rotateZ: {{SIZE}}deg',
915 ],
916 'condition' => [
917 "_transform_rotate_popover{$tab}!" => '',
918 ],
919 'frontend_available' => true,
920 ]
921 );
922
923 $this->add_control(
924 "_transform_rotate_3d{$tab}",
925 [
926 'label' => esc_html__( '3D Rotate', 'elementor' ),
927 'type' => Controls_Manager::SWITCHER,
928 'label_on' => esc_html__( 'On', 'elementor' ),
929 'label_off' => esc_html__( 'Off', 'elementor' ),
930 'selectors' => [
931 "{{WRAPPER}}{$transform_selector_class}{$state}" => '--e-' . $transform_css_modifier . 'transform-rotateX: 1{{UNIT}}; --e-' . $transform_css_modifier . 'transform-perspective: 20px;',
932 ],
933 'condition' => [
934 "_transform_rotate_popover{$tab}!" => '',
935 ],
936 'frontend_available' => true,
937 ]
938 );
939
940 $this->add_responsive_control(
941 "_transform_rotateX_effect{$tab}",
942 [
943 'label' => esc_html__( 'Rotate X', 'elementor' ) . ' (deg)',
944 'type' => Controls_Manager::SLIDER,
945 'device_args' => $default_unit_values_deg,
946 'range' => [
947 'px' => [
948 'min' => -360,
949 'max' => 360,
950 ],
951 ],
952 'condition' => [
953 "_transform_rotate_3d{$tab}!" => '',
954 "_transform_rotate_popover{$tab}!" => '',
955 ],
956 'selectors' => [
957 "{{WRAPPER}}{$transform_selector_class}{$state}" => '--e-' . $transform_css_modifier . 'transform-rotateX: {{SIZE}}deg;',
958 ],
959 'frontend_available' => true,
960 ]
961 );
962
963 $this->add_responsive_control(
964 "_transform_rotateY_effect{$tab}",
965 [
966 'label' => esc_html__( 'Rotate Y', 'elementor' ) . ' (deg)',
967 'type' => Controls_Manager::SLIDER,
968 'device_args' => $default_unit_values_deg,
969 'range' => [
970 'px' => [
971 'min' => -360,
972 'max' => 360,
973 ],
974 ],
975 'condition' => [
976 "_transform_rotate_3d{$tab}!" => '',
977 "_transform_rotate_popover{$tab}!" => '',
978 ],
979 'selectors' => [
980 "{{WRAPPER}}{$transform_selector_class}{$state}" => '--e-' . $transform_css_modifier . 'transform-rotateY: {{SIZE}}deg;',
981 ],
982 'frontend_available' => true,
983 ]
984 );
985
986 $this->add_responsive_control(
987 "_transform_perspective_effect{$tab}",
988 [
989 'label' => esc_html__( 'Perspective', 'elementor' ) . ' (px)',
990 'type' => Controls_Manager::SLIDER,
991 'range' => [
992 'px' => [
993 'max' => 1000,
994 ],
995 ],
996 'condition' => [
997 "_transform_rotate_popover{$tab}!" => '',
998 "_transform_rotate_3d{$tab}!" => '',
999 ],
1000 'selectors' => [
1001 "{{WRAPPER}}{$transform_selector_class}{$state}" => '--e-' . $transform_css_modifier . 'transform-perspective: {{SIZE}}px',
1002 ],
1003 'frontend_available' => true,
1004 ]
1005 );
1006
1007 $this->end_popover();
1008
1009 $this->add_control(
1010 "_transform_translate_popover{$tab}",
1011 [
1012 'label' => esc_html__( 'Offset', 'elementor' ),
1013 'type' => Controls_Manager::POPOVER_TOGGLE,
1014 'prefix_class' => $transform_prefix_class,
1015 'return_value' => $transform_return_value,
1016 ]
1017 );
1018
1019 $this->start_popover();
1020
1021 $this->add_responsive_control(
1022 "_transform_translateX_effect{$tab}",
1023 [
1024 'label' => esc_html__( 'Offset X', 'elementor' ),
1025 'type' => Controls_Manager::SLIDER,
1026 'size_units' => [ 'px', '%', 'em', 'rem', 'vw', 'custom' ],
1027 'range' => [
1028 '%' => [
1029 'min' => -100,
1030 'max' => 100,
1031 ],
1032 'px' => [
1033 'min' => -1000,
1034 'max' => 1000,
1035 ],
1036 ],
1037 'condition' => [
1038 "_transform_translate_popover{$tab}!" => '',
1039 ],
1040 'selectors' => [
1041 "{{WRAPPER}}{$transform_selector_class}{$state}" => '--e-' . $transform_css_modifier . 'transform-translateX: {{SIZE}}{{UNIT}};',
1042 ],
1043 'frontend_available' => true,
1044 ]
1045 );
1046
1047 $this->add_responsive_control(
1048 "_transform_translateY_effect{$tab}",
1049 [
1050 'label' => esc_html__( 'Offset Y', 'elementor' ),
1051 'type' => Controls_Manager::SLIDER,
1052 'size_units' => [ 'px', '%', 'em', 'rem', 'vh', 'custom' ],
1053 'range' => [
1054 '%' => [
1055 'min' => -100,
1056 'max' => 100,
1057 ],
1058 'px' => [
1059 'min' => -1000,
1060 'max' => 1000,
1061 ],
1062 ],
1063 'condition' => [
1064 "_transform_translate_popover{$tab}!" => '',
1065 ],
1066 'selectors' => [
1067 "{{WRAPPER}}{$transform_selector_class}{$state}" => '--e-' . $transform_css_modifier . 'transform-translateY: {{SIZE}}{{UNIT}};',
1068 ],
1069 'frontend_available' => true,
1070 ]
1071 );
1072
1073 $this->end_popover();
1074
1075 $this->add_control(
1076 "_transform_scale_popover{$tab}",
1077 [
1078 'label' => esc_html__( 'Scale', 'elementor' ),
1079 'type' => Controls_Manager::POPOVER_TOGGLE,
1080 'prefix_class' => $transform_prefix_class,
1081 'return_value' => $transform_return_value,
1082 ]
1083 );
1084
1085 $this->start_popover();
1086
1087 $this->add_control(
1088 "_transform_keep_proportions{$tab}",
1089 [
1090 'label' => esc_html__( 'Keep Proportions', 'elementor' ),
1091 'type' => Controls_Manager::SWITCHER,
1092 'label_on' => esc_html__( 'On', 'elementor' ),
1093 'label_off' => esc_html__( 'Off', 'elementor' ),
1094 'default' => 'yes',
1095 ]
1096 );
1097
1098 $this->add_responsive_control(
1099 "_transform_scale_effect{$tab}",
1100 [
1101 'label' => esc_html__( 'Scale', 'elementor' ),
1102 'type' => Controls_Manager::SLIDER,
1103 'range' => [
1104 'px' => [
1105 'max' => 2,
1106 'step' => 0.1,
1107 ],
1108 ],
1109 'condition' => [
1110 "_transform_scale_popover{$tab}!" => '',
1111 "_transform_keep_proportions{$tab}!" => '',
1112 ],
1113 'selectors' => [
1114 "{{WRAPPER}}{$transform_selector_class}{$state}" => '--e-' . $transform_css_modifier . 'transform-scale: {{SIZE}};',
1115 ],
1116 'frontend_available' => true,
1117 ]
1118 );
1119
1120 $this->add_responsive_control(
1121 "_transform_scaleX_effect{$tab}",
1122 [
1123 'label' => esc_html__( 'Scale X', 'elementor' ),
1124 'type' => Controls_Manager::SLIDER,
1125 'range' => [
1126 'px' => [
1127 'max' => 2,
1128 'step' => 0.1,
1129 ],
1130 ],
1131 'condition' => [
1132 "_transform_scale_popover{$tab}!" => '',
1133 "_transform_keep_proportions{$tab}" => '',
1134 ],
1135 'selectors' => [
1136 "{{WRAPPER}}{$transform_selector_class}{$state}" => '--e-' . $transform_css_modifier . 'transform-scaleX: {{SIZE}};',
1137 ],
1138 'frontend_available' => true,
1139 ]
1140 );
1141
1142 $this->add_responsive_control(
1143 "_transform_scaleY_effect{$tab}",
1144 [
1145 'label' => esc_html__( 'Scale Y', 'elementor' ),
1146 'type' => Controls_Manager::SLIDER,
1147 'range' => [
1148 'px' => [
1149 'max' => 2,
1150 'step' => 0.1,
1151 ],
1152 ],
1153 'condition' => [
1154 "_transform_scale_popover{$tab}!" => '',
1155 "_transform_keep_proportions{$tab}" => '',
1156 ],
1157 'selectors' => [
1158 "{{WRAPPER}}{$transform_selector_class}{$state}" => '--e-' . $transform_css_modifier . 'transform-scaleY: {{SIZE}};',
1159 ],
1160 'frontend_available' => true,
1161 ]
1162 );
1163
1164 $this->end_popover();
1165
1166 $this->add_control(
1167 "_transform_skew_popover{$tab}",
1168 [
1169 'label' => esc_html__( 'Skew', 'elementor' ),
1170 'type' => Controls_Manager::POPOVER_TOGGLE,
1171 'prefix_class' => $transform_prefix_class,
1172 'return_value' => $transform_return_value,
1173 ]
1174 );
1175
1176 $this->start_popover();
1177
1178 $this->add_responsive_control(
1179 "_transform_skewX_effect{$tab}",
1180 [
1181 'label' => esc_html__( 'Skew X', 'elementor' ) . ' (deg)',
1182 'type' => Controls_Manager::SLIDER,
1183 'device_args' => $default_unit_values_deg,
1184 'range' => [
1185 'px' => [
1186 'min' => -360,
1187 'max' => 360,
1188 ],
1189 ],
1190 'condition' => [
1191 "_transform_skew_popover{$tab}!" => '',
1192 ],
1193 'selectors' => [
1194 "{{WRAPPER}}{$transform_selector_class}{$state}" => '--e-' . $transform_css_modifier . 'transform-skewX: {{SIZE}}deg;',
1195 ],
1196 'frontend_available' => true,
1197 ]
1198 );
1199
1200 $this->add_responsive_control(
1201 "_transform_skewY_effect{$tab}",
1202 [
1203 'label' => esc_html__( 'Skew Y', 'elementor' ) . ' (deg)',
1204 'type' => Controls_Manager::SLIDER,
1205 'device_args' => $default_unit_values_deg,
1206 'range' => [
1207 'px' => [
1208 'min' => -360,
1209 'max' => 360,
1210 ],
1211 ],
1212 'condition' => [
1213 "_transform_skew_popover{$tab}!" => '',
1214 ],
1215 'selectors' => [
1216 "{{WRAPPER}}{$transform_selector_class}{$state}" => '--e-' . $transform_css_modifier . 'transform-skewY: {{SIZE}}deg;',
1217 ],
1218 'frontend_available' => true,
1219 ]
1220 );
1221
1222 $this->end_popover();
1223
1224 $this->add_control(
1225 "_transform_flipX_effect{$tab}",
1226 [
1227 'label' => esc_html__( 'Flip Horizontal', 'elementor' ),
1228 'type' => Controls_Manager::CHOOSE,
1229 'options' => [
1230 'transform' => [
1231 'title' => esc_html__( 'Flip Horizontal', 'elementor' ),
1232 'icon' => 'eicon-flip eicon-tilted',
1233 ],
1234 ],
1235 'prefix_class' => $transform_prefix_class,
1236 'selectors' => [
1237 "{{WRAPPER}}{$transform_selector_class}{$state}" => '--e-' . $transform_css_modifier . 'transform-flipX: -1',
1238 ],
1239 'frontend_available' => true,
1240 ]
1241 );
1242
1243 $this->add_control(
1244 "_transform_flipY_effect{$tab}",
1245 [
1246 'label' => esc_html__( 'Flip Vertical', 'elementor' ),
1247 'type' => Controls_Manager::CHOOSE,
1248 'options' => [
1249 'transform' => [
1250 'title' => esc_html__( 'Flip Vertical', 'elementor' ),
1251 'icon' => 'eicon-flip',
1252 ],
1253 ],
1254 'prefix_class' => $transform_prefix_class,
1255 'selectors' => [
1256 "{{WRAPPER}}{$transform_selector_class}{$state}" => '--e-' . $transform_css_modifier . 'transform-flipY: -1',
1257 ],
1258 'frontend_available' => true,
1259 ]
1260 );
1261
1262 if ( '_hover' === $tab ) {
1263 $this->add_control(
1264 '_transform_transition_hover',
1265 [
1266 'label' => esc_html__( 'Transition Duration', 'elementor' ) . ' (ms)',
1267 'type' => Controls_Manager::SLIDER,
1268 'device_args' => $default_unit_values_ms,
1269 'range' => [
1270 'px' => [
1271 'min' => 0,
1272 'max' => 10000,
1273 'step' => 100,
1274 ],
1275 ],
1276 'selectors' => [
1277 '{{WRAPPER}}' => '--e-' . $transform_css_modifier . 'transform-transition-duration: {{SIZE}}ms',
1278 ],
1279 ]
1280 );
1281 }
1282
1283 ${"transform_origin_conditions{$tab}"} = [
1284 [
1285 'name' => "_transform_scale_popover{$tab}",
1286 'operator' => '!=',
1287 'value' => '',
1288 ],
1289 [
1290 'name' => "_transform_rotate_popover{$tab}",
1291 'operator' => '!=',
1292 'value' => '',
1293 ],
1294 [
1295 'name' => "_transform_flipX_effect{$tab}",
1296 'operator' => '!=',
1297 'value' => '',
1298 ],
1299 [
1300 'name' => "_transform_flipY_effect{$tab}",
1301 'operator' => '!=',
1302 'value' => '',
1303 ],
1304 ];
1305
1306 $this->end_controls_tab();
1307 }
1308
1309 $this->end_controls_tabs();
1310
1311 $transform_origin_conditions = [
1312 'relation' => 'or',
1313 'terms' => array_merge( $transform_origin_conditions, $transform_origin_conditions_hover ),
1314 ];
1315
1316 // Will override motion effect transform-origin.
1317 $this->add_responsive_control(
1318 'motion_fx_transform_x_anchor_point',
1319 [
1320 'label' => esc_html__( 'X Anchor Point', 'elementor' ),
1321 'type' => Controls_Manager::CHOOSE,
1322 'options' => [
1323 'left' => [
1324 'title' => esc_html__( 'Left', 'elementor' ),
1325 'icon' => 'eicon-h-align-left',
1326 ],
1327 'center' => [
1328 'title' => esc_html__( 'Center', 'elementor' ),
1329 'icon' => 'eicon-h-align-center',
1330 ],
1331 'right' => [
1332 'title' => esc_html__( 'Right', 'elementor' ),
1333 'icon' => 'eicon-h-align-right',
1334 ],
1335 ],
1336 'conditions' => $transform_origin_conditions,
1337 'separator' => 'before',
1338 'selectors' => [
1339 '{{WRAPPER}}' => '--e-' . $transform_css_modifier . 'transform-origin-x: {{VALUE}}',
1340 ],
1341 ]
1342 );
1343
1344 // Will override motion effect transform-origin.
1345 $this->add_responsive_control(
1346 'motion_fx_transform_y_anchor_point',
1347 [
1348 'label' => esc_html__( 'Y Anchor Point', 'elementor' ),
1349 'type' => Controls_Manager::CHOOSE,
1350 'options' => [
1351 'top' => [
1352 'title' => esc_html__( 'Top', 'elementor' ),
1353 'icon' => 'eicon-v-align-top',
1354 ],
1355 'center' => [
1356 'title' => esc_html__( 'Center', 'elementor' ),
1357 'icon' => 'eicon-v-align-middle',
1358 ],
1359 'bottom' => [
1360 'title' => esc_html__( 'Bottom', 'elementor' ),
1361 'icon' => 'eicon-v-align-bottom',
1362 ],
1363 ],
1364 'conditions' => $transform_origin_conditions,
1365 'selectors' => [
1366 '{{WRAPPER}}' => '--e-' . $transform_css_modifier . 'transform-origin-y: {{VALUE}}',
1367 ],
1368 ]
1369 );
1370
1371 $this->end_controls_section();
1372 }
1373
1374 /**
1375 * Add Hidden Device Controls
1376 *
1377 * Adds controls for hiding elements within certain devices' viewport widths. Adds a control for each active device.
1378 *
1379 * @since 3.4.0
1380 * @access protected
1381 */
1382 protected function add_hidden_device_controls() {
1383 // The 'Hide On X' controls are displayed from largest to smallest, while the method returns smallest to largest.
1384 $active_devices = Plugin::$instance->breakpoints->get_active_devices_list( [ 'reverse' => true ] );
1385 $active_breakpoints = Plugin::$instance->breakpoints->get_active_breakpoints();
1386
1387 foreach ( $active_devices as $breakpoint_key ) {
1388 $label = 'desktop' === $breakpoint_key ? esc_html__( 'Desktop', 'elementor' ) : $active_breakpoints[ $breakpoint_key ]->get_label();
1389
1390 $this->add_control(
1391 'hide_' . $breakpoint_key,
1392 [
1393 'label' => sprintf(
1394 /* translators: %s: Device name. */
1395 esc_html__( 'Hide On %s', 'elementor' ),
1396 $label
1397 ),
1398 'type' => Controls_Manager::SWITCHER,
1399 'default' => '',
1400 'prefix_class' => 'elementor-',
1401 'label_on' => esc_html__( 'Hide', 'elementor' ),
1402 'label_off' => esc_html__( 'Show', 'elementor' ),
1403 'return_value' => 'hidden-' . $breakpoint_key,
1404 ]
1405 );
1406 }
1407 }
1408
1409 /**
1410 * Get default data.
1411 *
1412 * Retrieve the default element data. Used to reset the data on initialization.
1413 *
1414 * @since 1.0.0
1415 * @access protected
1416 *
1417 * @return array Default data.
1418 */
1419 protected function get_default_data() {
1420 $data = parent::get_default_data();
1421
1422 return array_merge(
1423 $data, [
1424 'elements' => [],
1425 'isInner' => false,
1426 ]
1427 );
1428 }
1429
1430 /**
1431 * Print element content.
1432 *
1433 * Output the element final HTML on the frontend.
1434 *
1435 * @since 1.0.0
1436 * @access protected
1437 * @deprecated 3.1.0 Use `print_content()` method instead.
1438 */
1439 protected function _print_content() {
1440 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.1.0', 'print_content()' );
1441
1442 $this->print_content();
1443 }
1444
1445 /**
1446 * Print element content.
1447 *
1448 * Output the element final HTML on the frontend.
1449 *
1450 * @since 3.1.0
1451 * @access protected
1452 */
1453 protected function print_content() {
1454 foreach ( $this->get_children() as $child ) {
1455 $child->print_element();
1456 }
1457 }
1458
1459 /**
1460 * Get initial config.
1461 *
1462 * Retrieve the current element initial configuration.
1463 *
1464 * Adds more configuration on top of the controls list and the tabs assigned
1465 * to the control. This method also adds element name, type, icon and more.
1466 *
1467 * @since 2.9.0
1468 * @access protected
1469 *
1470 * @return array The initial config.
1471 */
1472 protected function get_initial_config() {
1473 $config = [
1474 'name' => $this->get_name(),
1475 'elType' => $this->get_type(),
1476 'title' => $this->get_title(),
1477 'icon' => $this->get_icon(),
1478 'reload_preview' => $this->is_reload_preview_required(),
1479 ];
1480
1481 if ( preg_match( '/^' . __NAMESPACE__ . '(Pro)?\\\\/', get_called_class() ) ) {
1482 $config['help_url'] = $this->get_help_url();
1483 } else {
1484 $config['help_url'] = $this->get_custom_help_url();
1485 }
1486
1487 if ( ! $this->is_editable() ) {
1488 $config['editable'] = false;
1489 }
1490
1491 return $config;
1492 }
1493
1494 /**
1495 * A Base method for sanitizing the settings before save.
1496 * This method is meant to be overridden by the element.
1497 *
1498 * @param array $settings
1499 * @return array
1500 */
1501 protected function on_save( array $settings ) {
1502 return $settings;
1503 }
1504
1505 /**
1506 * Get child type.
1507 *
1508 * Retrieve the element child type based on element data.
1509 *
1510 * @since 2.0.0
1511 * @access private
1512 *
1513 * @param array $element_data Element ID.
1514 *
1515 * @return Element_Base|false Child type or false if type not found.
1516 */
1517 private function get_child_type( $element_data ) {
1518 $child_type = $this->_get_default_child_type( $element_data );
1519
1520 // If it's not a valid widget ( like a deactivated plugin ).
1521 if ( ! $child_type ) {
1522 return false;
1523 }
1524
1525 /**
1526 * Element child type.
1527 *
1528 * Filters the child type of the element.
1529 *
1530 * @since 1.0.0
1531 *
1532 * @param Element_Base $child_type The child element.
1533 * @param array $element_data The original element ID.
1534 * @param Element_Base $this The original element.
1535 */
1536 $child_type = apply_filters( 'elementor/element/get_child_type', $child_type, $element_data, $this );
1537
1538 return $child_type;
1539 }
1540
1541 /**
1542 * Initialize children.
1543 *
1544 * Initializing the element child elements.
1545 *
1546 * @since 2.0.0
1547 * @access private
1548 */
1549 private function init_children() {
1550 $this->children = [];
1551
1552 $children_data = $this->get_data( 'elements' );
1553
1554 if ( ! $children_data ) {
1555 return;
1556 }
1557
1558 foreach ( $children_data as $child_data ) {
1559 if ( ! $child_data ) {
1560 continue;
1561 }
1562
1563 $this->add_child( $child_data );
1564 }
1565 }
1566
1567 public function has_widget_inner_wrapper(): bool {
1568 return true;
1569 }
1570
1571 /**
1572 * Element base constructor.
1573 *
1574 * Initializing the element base class using `$data` and `$args`.
1575 *
1576 * The `$data` parameter is required for a normal instance because of the
1577 * way Elementor renders data when initializing elements.
1578 *
1579 * @since 1.0.0
1580 * @access public
1581 *
1582 * @param array $data Optional. Element data. Default is an empty array.
1583 * @param array|null $args Optional. Element default arguments. Default is null.
1584 **/
1585 public function __construct( array $data = [], ?array $args = null ) {
1586 if ( $data ) {
1587 $this->is_type_instance = false;
1588 } elseif ( $args ) {
1589 $this->default_args = $args;
1590 }
1591
1592 parent::__construct( $data );
1593 }
1594 }
1595