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

989 lines 22.9 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 if ( ! defined( 'ABSPATH' ) ) {
5 exit; // Exit if accessed directly.
6 }
7
8 /**
9 * Elementor element base.
10 *
11 * An abstract class to register new Elementor elements. It extended the
12 * `Controls_Stack` class to inherit its properties.
13 *
14 * This abstract class must be extended in order to register new elements.
15 *
16 * @since 1.0.0
17 * @abstract
18 */
19 abstract class Element_Base extends Controls_Stack {
20
21 /**
22 * Child elements.
23 *
24 * Holds all the child elements of the element.
25 *
26 * @access private
27 *
28 * @var Element_Base[]
29 */
30 private $children;
31
32 /**
33 * Element render attributes.
34 *
35 * Holds all the render attributes of the element. Used to store data like
36 * the HTML class name and the class value, or HTML element ID name and value.
37 *
38 * @access private
39 *
40 * @var array
41 */
42 private $render_attributes = [];
43
44 /**
45 * Element default arguments.
46 *
47 * Holds all the default arguments of the element. Used to store additional
48 * data. For example WordPress widgets use this to store widget names.
49 *
50 * @access private
51 *
52 * @var array
53 */
54 private $default_args = [];
55
56 /**
57 * Is type instance.
58 *
59 * Whether the element is an instance of that type or not.
60 *
61 * @access private
62 *
63 * @var bool
64 */
65 private $is_type_instance = true;
66
67 /**
68 * Depended scripts.
69 *
70 * Holds all the element depended scripts to enqueue.
71 *
72 * @since 1.9.0
73 * @access private
74 *
75 * @var array
76 */
77 private $depended_scripts = [];
78
79 /**
80 * Depended styles.
81 *
82 * Holds all the element depended styles to enqueue.
83 *
84 * @since 1.9.0
85 * @access private
86 *
87 * @var array
88 */
89 private $depended_styles = [];
90
91 /**
92 * Add script depends.
93 *
94 * Register new script to enqueue by the handler.
95 *
96 * @since 1.9.0
97 * @access public
98 *
99 * @param string $handler Depend script handler.
100 */
101 public function add_script_depends( $handler ) {
102 $this->depended_scripts[] = $handler;
103 }
104
105 /**
106 * Add style depends.
107 *
108 * Register new style to enqueue by the handler.
109 *
110 * @since 1.9.0
111 * @access public
112 *
113 * @param string $handler Depend style handler.
114 */
115 public function add_style_depends( $handler ) {
116 $this->depended_styles[] = $handler;
117 }
118
119 /**
120 * Get script dependencies.
121 *
122 * Retrieve the list of script dependencies the element requires.
123 *
124 * @since 1.3.0
125 * @access public
126 *
127 * @return array Element scripts dependencies.
128 */
129 public function get_script_depends() {
130 return $this->depended_scripts;
131 }
132
133 /**
134 * Enqueue scripts.
135 *
136 * Registers all the scripts defined as element dependencies and enqueues
137 * them. Use `get_script_depends()` method to add custom script dependencies.
138 *
139 * @since 1.3.0
140 * @access public
141 */
142 final public function enqueue_scripts() {
143 $deprecated_scripts = [
144 'jquery-slick' => [
145 'version' => '2.7.0',
146 'replacement' => 'Swiper',
147 ],
148 ];
149
150 foreach ( $this->get_script_depends() as $script ) {
151 if ( isset( $deprecated_scripts[ $script ] ) ) {
152 Utils::handle_deprecation( $script, $deprecated_scripts[ $script ]['version'], $deprecated_scripts[ $script ]['replacement'] );
153 }
154
155 wp_enqueue_script( $script );
156 }
157 }
158
159 /**
160 * Get style dependencies.
161 *
162 * Retrieve the list of style dependencies the element requires.
163 *
164 * @since 1.9.0
165 * @access public
166 *
167 * @return array Element styles dependencies.
168 */
169 public function get_style_depends() {
170 return $this->depended_styles;
171 }
172
173 /**
174 * Enqueue styles.
175 *
176 * Registers all the styles defined as element dependencies and enqueues
177 * them. Use `get_style_depends()` method to add custom style dependencies.
178 *
179 * @since 1.9.0
180 * @access public
181 */
182 final public function enqueue_styles() {
183 foreach ( $this->get_style_depends() as $style ) {
184 wp_enqueue_style( $style );
185 }
186 }
187
188 /**
189 * @since 1.0.0
190 * @deprecated 2.6.0
191 * @access public
192 * @static
193 */
194 final public static function add_edit_tool() {}
195
196 /**
197 * @since 2.2.0
198 * @deprecated 2.6.0
199 * @access public
200 * @static
201 */
202 final public static function is_edit_buttons_enabled() {
203 return get_option( 'elementor_edit_buttons' );
204 }
205
206 /**
207 * Get default child type.
208 *
209 * Retrieve the default child type based on element data.
210 *
211 * Note that not all elements support children.
212 *
213 * @since 1.0.0
214 * @access protected
215 * @abstract
216 *
217 * @param array $element_data Element data.
218 *
219 * @return Element_Base
220 */
221 abstract protected function _get_default_child_type( array $element_data );
222
223 /**
224 * Before element rendering.
225 *
226 * Used to add stuff before the element.
227 *
228 * @since 1.0.0
229 * @access public
230 */
231 public function before_render() {}
232
233 /**
234 * After element rendering.
235 *
236 * Used to add stuff after the element.
237 *
238 * @since 1.0.0
239 * @access public
240 */
241 public function after_render() {}
242
243 /**
244 * Get element title.
245 *
246 * Retrieve the element title.
247 *
248 * @since 1.0.0
249 * @access public
250 *
251 * @return string Element title.
252 */
253 public function get_title() {
254 return '';
255 }
256
257 /**
258 * Get element icon.
259 *
260 * Retrieve the element icon.
261 *
262 * @since 1.0.0
263 * @access public
264 *
265 * @return string Element icon.
266 */
267 public function get_icon() {
268 return 'eicon-columns';
269 }
270
271 public function get_help_url() {
272 return 'https://go.elementor.com/widget-' . $this->get_name();
273 }
274
275 public function get_custom_help_url() {
276 return '';
277 }
278
279 /**
280 * Whether the reload preview is required.
281 *
282 * Used to determine whether the reload preview is required or not.
283 *
284 * @since 1.0.0
285 * @access public
286 *
287 * @return bool Whether the reload preview is required.
288 */
289 public function is_reload_preview_required() {
290 return false;
291 }
292
293 /**
294 * @since 2.3.1
295 * @access protected
296 */
297 protected function should_print_empty() {
298 return true;
299 }
300
301 /**
302 * Get child elements.
303 *
304 * Retrieve all the child elements of this element.
305 *
306 * @since 1.0.0
307 * @access public
308 *
309 * @return Element_Base[] Child elements.
310 */
311 public function get_children() {
312 if ( null === $this->children ) {
313 $this->init_children();
314 }
315
316 return $this->children;
317 }
318
319 /**
320 * Get default arguments.
321 *
322 * Retrieve the element default arguments. Used to return all the default
323 * arguments or a specific default argument, if one is set.
324 *
325 * @since 1.0.0
326 * @access public
327 *
328 * @param array $item Optional. Default is null.
329 *
330 * @return array Default argument(s).
331 */
332 public function get_default_args( $item = null ) {
333 return self::get_items( $this->default_args, $item );
334 }
335
336 /**
337 * Add new child element.
338 *
339 * Register new child element to allow hierarchy.
340 *
341 * @since 1.0.0
342 * @access public
343 * @param array $child_data Child element data.
344 * @param array $child_args Child element arguments.
345 *
346 * @return Element_Base|false Child element instance, or false if failed.
347 */
348 public function add_child( array $child_data, array $child_args = [] ) {
349 if ( null === $this->children ) {
350 $this->init_children();
351 }
352
353 $child_type = $this->get_child_type( $child_data );
354
355 if ( ! $child_type ) {
356 return false;
357 }
358
359 $child = Plugin::$instance->elements_manager->create_element_instance( $child_data, $child_args, $child_type );
360
361 if ( $child ) {
362 $this->children[] = $child;
363 }
364
365 return $child;
366 }
367
368 /**
369 * Add render attribute.
370 *
371 * Used to add attributes to a specific HTML element.
372 *
373 * The HTML tag is represented by the element parameter, then you need to
374 * define the attribute key and the attribute key. The final result will be:
375 * `<element attribute_key="attribute_value">`.
376 *
377 * Example usage:
378 *
379 * `$this->add_render_attribute( 'wrapper', 'class', 'custom-widget-wrapper-class' );`
380 * `$this->add_render_attribute( 'widget', 'id', 'custom-widget-id' );`
381 * `$this->add_render_attribute( 'button', [ 'class' => 'custom-button-class', 'id' => 'custom-button-id' ] );`
382 *
383 * @since 1.0.0
384 * @access public
385 *
386 * @param array|string $element The HTML element.
387 * @param array|string $key Optional. Attribute key. Default is null.
388 * @param array|string $value Optional. Attribute value. Default is null.
389 * @param bool $overwrite Optional. Whether to overwrite existing
390 * attribute. Default is false, not to overwrite.
391 *
392 * @return Element_Base Current instance of the element.
393 */
394 public function add_render_attribute( $element, $key = null, $value = null, $overwrite = false ) {
395 if ( is_array( $element ) ) {
396 foreach ( $element as $element_key => $attributes ) {
397 $this->add_render_attribute( $element_key, $attributes, null, $overwrite );
398 }
399
400 return $this;
401 }
402
403 if ( is_array( $key ) ) {
404 foreach ( $key as $attribute_key => $attributes ) {
405 $this->add_render_attribute( $element, $attribute_key, $attributes, $overwrite );
406 }
407
408 return $this;
409 }
410
411 if ( empty( $this->render_attributes[ $element ][ $key ] ) ) {
412 $this->render_attributes[ $element ][ $key ] = [];
413 }
414
415 settype( $value, 'array' );
416
417 if ( $overwrite ) {
418 $this->render_attributes[ $element ][ $key ] = $value;
419 } else {
420 $this->render_attributes[ $element ][ $key ] = array_merge( $this->render_attributes[ $element ][ $key ], $value );
421 }
422
423 return $this;
424 }
425
426 /**
427 * Add link render attributes.
428 *
429 * Used to add link tag attributes to a specific HTML element.
430 *
431 * The HTML link tag is represented by the element parameter. The `url_control` parameter
432 * needs to be an array of link settings in the same format they are set by Elementor's URL control.
433 *
434 * Example usage:
435 *
436 * `$this->add_link_attributes( 'button', $settings['link'] );`
437 *
438 * @since 2.8.0
439 * @access public
440 *
441 * @param array|string $element The HTML element.
442 * @param array $url_control Array of link settings.
443 * @param bool $overwrite Optional. Whether to overwrite existing
444 * attribute. Default is false, not to overwrite.
445 *
446 * @return Element_Base Current instance of the element.
447 */
448
449 public function add_link_attributes( $element, array $url_control, $overwrite = false ) {
450 $attributes = [];
451
452 if ( ! empty( $url_control['url'] ) ) {
453 $allowed_protocols = array_merge( wp_allowed_protocols(), [ 'skype', 'viber' ] );
454
455 $attributes['href'] = esc_url( $url_control['url'], $allowed_protocols );
456 }
457
458 if ( ! empty( $url_control['is_external'] ) ) {
459 $attributes['target'] = '_blank';
460 }
461
462 if ( ! empty( $url_control['nofollow'] ) ) {
463 $attributes['rel'] = 'nofollow';
464 }
465
466 if ( ! empty( $url_control['custom_attributes'] ) ) {
467 // Custom URL attributes should come as a string of comma-delimited key|value pairs
468 $attributes = array_merge( $attributes, Utils::parse_custom_attributes( $url_control['custom_attributes'] ) );
469 }
470
471 if ( $attributes ) {
472 $this->add_render_attribute( $element, $attributes, $overwrite );
473 }
474
475 return $this;
476 }
477
478 /**
479 * Get Render Attributes
480 *
481 * Used to retrieve render attribute.
482 *
483 * The returned array is either all elements and their attributes if no `$element` is specified, an array of all
484 * attributes of a specific element or a specific attribute properties if `$key` is specified.
485 *
486 * Returns null if one of the requested parameters isn't set.
487 *
488 * @since 2.2.6
489 * @access public
490 * @param string $element
491 * @param string $key
492 *
493 * @return array
494 */
495 public function get_render_attributes( $element = '', $key = '' ) {
496 $attributes = $this->render_attributes;
497
498 if ( $element ) {
499 if ( ! isset( $attributes[ $element ] ) ) {
500 return null;
501 }
502
503 $attributes = $attributes[ $element ];
504
505 if ( $key ) {
506 if ( ! isset( $attributes[ $key ] ) ) {
507 return null;
508 }
509
510 $attributes = $attributes[ $key ];
511 }
512 }
513
514 return $attributes;
515 }
516
517 /**
518 * Set render attribute.
519 *
520 * Used to set the value of the HTML element render attribute or to update
521 * an existing render attribute.
522 *
523 * @since 1.0.0
524 * @access public
525 *
526 * @param array|string $element The HTML element.
527 * @param array|string $key Optional. Attribute key. Default is null.
528 * @param array|string $value Optional. Attribute value. Default is null.
529 *
530 * @return Element_Base Current instance of the element.
531 */
532 public function set_render_attribute( $element, $key = null, $value = null ) {
533 return $this->add_render_attribute( $element, $key, $value, true );
534 }
535
536 /**
537 * Remove render attribute.
538 *
539 * Used to remove an element (with its keys and their values), key (with its values),
540 * or value/s from an HTML element's render attribute.
541 *
542 * @since 2.7.0
543 * @access public
544 *
545 * @param string $element The HTML element.
546 * @param string $key Optional. Attribute key. Default is null.
547 * @param array|string $values Optional. Attribute value/s. Default is null.
548 */
549 public function remove_render_attribute( $element, $key = null, $values = null ) {
550 if ( $key && ! isset( $this->render_attributes[ $element ][ $key ] ) ) {
551 return;
552 }
553
554 if ( $values ) {
555 $values = (array) $values;
556
557 $this->render_attributes[ $element ][ $key ] = array_diff( $this->render_attributes[ $element ][ $key ], $values );
558
559 return;
560 }
561
562 if ( $key ) {
563 unset( $this->render_attributes[ $element ][ $key ] );
564
565 return;
566 }
567
568 if ( isset( $this->render_attributes[ $element ] ) ) {
569 unset( $this->render_attributes[ $element ] );
570 }
571 }
572
573 /**
574 * Get render attribute string.
575 *
576 * Used to retrieve the value of the render attribute.
577 *
578 * @since 1.0.0
579 * @access public
580 *
581 * @param string $element The element.
582 *
583 * @return string Render attribute string, or an empty string if the attribute
584 * is empty or not exist.
585 */
586 public function get_render_attribute_string( $element ) {
587 if ( empty( $this->render_attributes[ $element ] ) ) {
588 return '';
589 }
590
591 return Utils::render_html_attributes( $this->render_attributes[ $element ] );
592 }
593
594 /**
595 * Print render attribute string.
596 *
597 * Used to output the rendered attribute.
598 *
599 * @since 2.0.0
600 * @access public
601 *
602 * @param array|string $element The element.
603 */
604 public function print_render_attribute_string( $element ) {
605 echo $this->get_render_attribute_string( $element ); // XSS ok.
606 }
607
608 /**
609 * Print element.
610 *
611 * Used to generate the element final HTML on the frontend and the editor.
612 *
613 * @since 1.0.0
614 * @access public
615 */
616 public function print_element() {
617 $element_type = $this->get_type();
618
619 /**
620 * Before frontend element render.
621 *
622 * Fires before Elementor element is rendered in the frontend.
623 *
624 * @since 2.2.0
625 *
626 * @param Element_Base $this The element.
627 */
628 do_action( 'elementor/frontend/before_render', $this );
629
630 /**
631 * Before frontend element render.
632 *
633 * Fires before Elementor element is rendered in the frontend.
634 *
635 * The dynamic portion of the hook name, `$element_type`, refers to the element type.
636 *
637 * @since 1.0.0
638 *
639 * @param Element_Base $this The element.
640 */
641 do_action( "elementor/frontend/{$element_type}/before_render", $this );
642
643 ob_start();
644 $this->_print_content();
645 $content = ob_get_clean();
646
647 $should_render = ( ! empty( $content ) || $this->should_print_empty() );
648
649 /**
650 * Should the element be rendered for frontend
651 *
652 * Filters if the element should be rendered on frontend.
653 *
654 * @since 2.3.3
655 *
656 * @param bool true The element.
657 * @param Element_Base $this The element.
658 */
659 $should_render = apply_filters( "elementor/frontend/{$element_type}/should_render", $should_render, $this );
660
661 if ( $should_render ) {
662 $this->_add_render_attributes();
663
664 $this->before_render();
665 echo $content;
666 $this->after_render();
667
668 $this->enqueue_scripts();
669 $this->enqueue_styles();
670 }
671
672 /**
673 * After frontend element render.
674 *
675 * Fires after Elementor element is rendered in the frontend.
676 *
677 * The dynamic portion of the hook name, `$element_type`, refers to the element type.
678 *
679 * @since 1.0.0
680 *
681 * @param Element_Base $this The element.
682 */
683 do_action( "elementor/frontend/{$element_type}/after_render", $this );
684
685 /**
686 * After frontend element render.
687 *
688 * Fires after Elementor element is rendered in the frontend.
689 *
690 * @since 2.3.0
691 *
692 * @param Element_Base $this The element.
693 */
694 do_action( 'elementor/frontend/after_render', $this );
695 }
696
697 /**
698 * Get the element raw data.
699 *
700 * Retrieve the raw element data, including the id, type, settings, child
701 * elements and whether it is an inner element.
702 *
703 * The data with the HTML used always to display the data, but the Elementor
704 * editor uses the raw data without the HTML in order not to render the data
705 * again.
706 *
707 * @since 1.0.0
708 * @access public
709 *
710 * @param bool $with_html_content Optional. Whether to return the data with
711 * HTML content or without. Used for caching.
712 * Default is false, without HTML.
713 *
714 * @return array Element raw data.
715 */
716 public function get_raw_data( $with_html_content = false ) {
717 $data = $this->get_data();
718
719 $elements = [];
720
721 foreach ( $this->get_children() as $child ) {
722 $elements[] = $child->get_raw_data( $with_html_content );
723 }
724
725 return [
726 'id' => $this->get_id(),
727 'elType' => $data['elType'],
728 'settings' => $data['settings'],
729 'elements' => $elements,
730 'isInner' => $data['isInner'],
731 ];
732 }
733
734 /**
735 * Get unique selector.
736 *
737 * Retrieve the unique selector of the element. Used to set a unique HTML
738 * class for each HTML element. This way Elementor can set custom styles for
739 * each element.
740 *
741 * @since 1.0.0
742 * @access public
743 *
744 * @return string Unique selector.
745 */
746 public function get_unique_selector() {
747 return '.elementor-element-' . $this->get_id();
748 }
749
750 /**
751 * Is type instance.
752 *
753 * Used to determine whether the element is an instance of that type or not.
754 *
755 * @since 1.0.0
756 * @access public
757 *
758 * @return bool Whether the element is an instance of that type.
759 */
760 public function is_type_instance() {
761 return $this->is_type_instance;
762 }
763
764 /**
765 * Add render attributes.
766 *
767 * Used to add attributes to the current element wrapper HTML tag.
768 *
769 * @since 1.3.0
770 * @access protected
771 */
772 protected function _add_render_attributes() {
773 $id = $this->get_id();
774
775 $settings = $this->get_settings_for_display();
776 $frontend_settings = $this->get_frontend_settings();
777 $controls = $this->get_controls();
778
779 $this->add_render_attribute( '_wrapper', [
780 'class' => [
781 'elementor-element',
782 'elementor-element-' . $id,
783 ],
784 'data-id' => $id,
785 'data-element_type' => $this->get_type(),
786 ] );
787
788 $class_settings = [];
789
790 foreach ( $settings as $setting_key => $setting ) {
791 if ( isset( $controls[ $setting_key ]['prefix_class'] ) ) {
792 $class_settings[ $setting_key ] = $setting;
793 }
794 }
795
796 foreach ( $class_settings as $setting_key => $setting ) {
797 if ( empty( $setting ) && '0' !== $setting ) {
798 continue;
799 }
800
801 $this->add_render_attribute( '_wrapper', 'class', $controls[ $setting_key ]['prefix_class'] . $setting );
802 }
803
804 if ( ! empty( $settings['animation'] ) || ! empty( $settings['_animation'] ) ) {
805 $is_static_render_mode = Plugin::$instance->frontend->is_static_render_mode();
806
807 if ( ! $is_static_render_mode ) {
808 // Hide the element until the animation begins
809 $this->add_render_attribute( '_wrapper', 'class', 'elementor-invisible' );
810 }
811 }
812
813 if ( ! empty( $settings['_element_id'] ) ) {
814 $this->add_render_attribute( '_wrapper', 'id', trim( $settings['_element_id'] ) );
815 }
816
817 if ( $frontend_settings ) {
818 $this->add_render_attribute( '_wrapper', 'data-settings', wp_json_encode( $frontend_settings ) );
819 }
820
821 /**
822 * After element attribute rendered.
823 *
824 * Fires after the attributes of the element HTML tag are rendered.
825 *
826 * @since 2.3.0
827 *
828 * @param Element_Base $this The element.
829 */
830 do_action( 'elementor/element/after_add_attributes', $this );
831 }
832
833 /**
834 * Get default data.
835 *
836 * Retrieve the default element data. Used to reset the data on initialization.
837 *
838 * @since 1.0.0
839 * @access protected
840 *
841 * @return array Default data.
842 */
843 protected function get_default_data() {
844 $data = parent::get_default_data();
845
846 return array_merge(
847 $data, [
848 'elements' => [],
849 'isInner' => false,
850 ]
851 );
852 }
853
854 /**
855 * Print element content.
856 *
857 * Output the element final HTML on the frontend.
858 *
859 * @since 1.0.0
860 * @access protected
861 */
862 protected function _print_content() {
863 foreach ( $this->get_children() as $child ) {
864 $child->print_element();
865 }
866 }
867
868 /**
869 * Get initial config.
870 *
871 * Retrieve the current element initial configuration.
872 *
873 * Adds more configuration on top of the controls list and the tabs assigned
874 * to the control. This method also adds element name, type, icon and more.
875 *
876 * @since 2.9.0
877 * @access protected
878 *
879 * @return array The initial config.
880 */
881 protected function get_initial_config() {
882 $config = [
883 'name' => $this->get_name(),
884 'elType' => $this->get_type(),
885 'title' => $this->get_title(),
886 'icon' => $this->get_icon(),
887 'reload_preview' => $this->is_reload_preview_required(),
888 ];
889
890 if ( preg_match( '/^' . __NAMESPACE__ . '(Pro)?\\\\/', get_called_class() ) ) {
891 $config['help_url'] = $this->get_help_url();
892 } else {
893 $config['help_url'] = $this->get_custom_help_url();
894 }
895
896 if ( ! $this->is_editable() ) {
897 $config['editable'] = false;
898 }
899
900 return $config;
901 }
902
903 /**
904 * Get child type.
905 *
906 * Retrieve the element child type based on element data.
907 *
908 * @since 2.0.0
909 * @access private
910 *
911 * @param array $element_data Element ID.
912 *
913 * @return Element_Base|false Child type or false if type not found.
914 */
915 private function get_child_type( $element_data ) {
916 $child_type = $this->_get_default_child_type( $element_data );
917
918 // If it's not a valid widget ( like a deactivated plugin )
919 if ( ! $child_type ) {
920 return false;
921 }
922
923 /**
924 * Element child type.
925 *
926 * Filters the child type of the element.
927 *
928 * @since 1.0.0
929 *
930 * @param Element_Base $child_type The child element.
931 * @param array $element_data The original element ID.
932 * @param Element_Base $this The original element.
933 */
934 $child_type = apply_filters( 'elementor/element/get_child_type', $child_type, $element_data, $this );
935
936 return $child_type;
937 }
938
939 /**
940 * Initialize children.
941 *
942 * Initializing the element child elements.
943 *
944 * @since 2.0.0
945 * @access private
946 */
947 private function init_children() {
948 $this->children = [];
949
950 $children_data = $this->get_data( 'elements' );
951
952 if ( ! $children_data ) {
953 return;
954 }
955
956 foreach ( $children_data as $child_data ) {
957 if ( ! $child_data ) {
958 continue;
959 }
960
961 $this->add_child( $child_data );
962 }
963 }
964
965 /**
966 * Element base constructor.
967 *
968 * Initializing the element base class using `$data` and `$args`.
969 *
970 * The `$data` parameter is required for a normal instance because of the
971 * way Elementor renders data when initializing elements.
972 *
973 * @since 1.0.0
974 * @access public
975 *
976 * @param array $data Optional. Element data. Default is an empty array.
977 * @param array|null $args Optional. Element default arguments. Default is null.
978 **/
979 public function __construct( array $data = [], array $args = null ) {
980 if ( $data ) {
981 $this->is_type_instance = false;
982 } elseif ( $args ) {
983 $this->default_args = $args;
984 }
985
986 parent::__construct( $data );
987 }
988 }
989