PluginProbe
Elementor Website Builder – more than just a page builder / 4.1.4
Elementor Website Builder – more than just a page builder v4.1.4
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 4.1.4, at includes/base/element-base.php

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