PluginProbe
Elementor Website Builder – more than just a page builder / 3.0.2
Elementor Website Builder – more than just a page builder v3.0.2
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / includes / base / element-base.php

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

991 lines 23.0 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 = wp_allowed_protocols();
454
455 $allowed_protocols += [ 'skype', 'viber' ];
456
457 $attributes['href'] = esc_url( $url_control['url'], $allowed_protocols );
458 }
459
460 if ( ! empty( $url_control['is_external'] ) ) {
461 $attributes['target'] = '_blank';
462 }
463
464 if ( ! empty( $url_control['nofollow'] ) ) {
465 $attributes['rel'] = 'nofollow';
466 }
467
468 if ( ! empty( $url_control['custom_attributes'] ) ) {
469 // Custom URL attributes should come as a string of comma-delimited key|value pairs
470 $attributes = array_merge( $attributes, Utils::parse_custom_attributes( $url_control['custom_attributes'] ) );
471 }
472
473 if ( $attributes ) {
474 $this->add_render_attribute( $element, $attributes, $overwrite );
475 }
476
477 return $this;
478 }
479
480 /**
481 * Get Render Attributes
482 *
483 * Used to retrieve render attribute.
484 *
485 * The returned array is either all elements and their attributes if no `$element` is specified, an array of all
486 * attributes of a specific element or a specific attribute properties if `$key` is specified.
487 *
488 * Returns null if one of the requested parameters isn't set.
489 *
490 * @since 2.2.6
491 * @access public
492 * @param string $element
493 * @param string $key
494 *
495 * @return array
496 */
497 public function get_render_attributes( $element = '', $key = '' ) {
498 $attributes = $this->render_attributes;
499
500 if ( $element ) {
501 if ( ! isset( $attributes[ $element ] ) ) {
502 return null;
503 }
504
505 $attributes = $attributes[ $element ];
506
507 if ( $key ) {
508 if ( ! isset( $attributes[ $key ] ) ) {
509 return null;
510 }
511
512 $attributes = $attributes[ $key ];
513 }
514 }
515
516 return $attributes;
517 }
518
519 /**
520 * Set render attribute.
521 *
522 * Used to set the value of the HTML element render attribute or to update
523 * an existing render attribute.
524 *
525 * @since 1.0.0
526 * @access public
527 *
528 * @param array|string $element The HTML element.
529 * @param array|string $key Optional. Attribute key. Default is null.
530 * @param array|string $value Optional. Attribute value. Default is null.
531 *
532 * @return Element_Base Current instance of the element.
533 */
534 public function set_render_attribute( $element, $key = null, $value = null ) {
535 return $this->add_render_attribute( $element, $key, $value, true );
536 }
537
538 /**
539 * Remove render attribute.
540 *
541 * Used to remove an element (with its keys and their values), key (with its values),
542 * or value/s from an HTML element's render attribute.
543 *
544 * @since 2.7.0
545 * @access public
546 *
547 * @param string $element The HTML element.
548 * @param string $key Optional. Attribute key. Default is null.
549 * @param array|string $values Optional. Attribute value/s. Default is null.
550 */
551 public function remove_render_attribute( $element, $key = null, $values = null ) {
552 if ( $key && ! isset( $this->render_attributes[ $element ][ $key ] ) ) {
553 return;
554 }
555
556 if ( $values ) {
557 $values = (array) $values;
558
559 $this->render_attributes[ $element ][ $key ] = array_diff( $this->render_attributes[ $element ][ $key ], $values );
560
561 return;
562 }
563
564 if ( $key ) {
565 unset( $this->render_attributes[ $element ][ $key ] );
566
567 return;
568 }
569
570 if ( isset( $this->render_attributes[ $element ] ) ) {
571 unset( $this->render_attributes[ $element ] );
572 }
573 }
574
575 /**
576 * Get render attribute string.
577 *
578 * Used to retrieve the value of the render attribute.
579 *
580 * @since 1.0.0
581 * @access public
582 *
583 * @param string $element The element.
584 *
585 * @return string Render attribute string, or an empty string if the attribute
586 * is empty or not exist.
587 */
588 public function get_render_attribute_string( $element ) {
589 if ( empty( $this->render_attributes[ $element ] ) ) {
590 return '';
591 }
592
593 return Utils::render_html_attributes( $this->render_attributes[ $element ] );
594 }
595
596 /**
597 * Print render attribute string.
598 *
599 * Used to output the rendered attribute.
600 *
601 * @since 2.0.0
602 * @access public
603 *
604 * @param array|string $element The element.
605 */
606 public function print_render_attribute_string( $element ) {
607 echo $this->get_render_attribute_string( $element ); // XSS ok.
608 }
609
610 /**
611 * Print element.
612 *
613 * Used to generate the element final HTML on the frontend and the editor.
614 *
615 * @since 1.0.0
616 * @access public
617 */
618 public function print_element() {
619 $element_type = $this->get_type();
620
621 /**
622 * Before frontend element render.
623 *
624 * Fires before Elementor element is rendered in the frontend.
625 *
626 * @since 2.2.0
627 *
628 * @param Element_Base $this The element.
629 */
630 do_action( 'elementor/frontend/before_render', $this );
631
632 /**
633 * Before frontend element render.
634 *
635 * Fires before Elementor element is rendered in the frontend.
636 *
637 * The dynamic portion of the hook name, `$element_type`, refers to the element type.
638 *
639 * @since 1.0.0
640 *
641 * @param Element_Base $this The element.
642 */
643 do_action( "elementor/frontend/{$element_type}/before_render", $this );
644
645 ob_start();
646 $this->_print_content();
647 $content = ob_get_clean();
648
649 $should_render = ( ! empty( $content ) || $this->should_print_empty() );
650
651 /**
652 * Should the element be rendered for frontend
653 *
654 * Filters if the element should be rendered on frontend.
655 *
656 * @since 2.3.3
657 *
658 * @param bool true The element.
659 * @param Element_Base $this The element.
660 */
661 $should_render = apply_filters( "elementor/frontend/{$element_type}/should_render", $should_render, $this );
662
663 if ( $should_render ) {
664 $this->_add_render_attributes();
665
666 $this->before_render();
667 echo $content;
668 $this->after_render();
669
670 $this->enqueue_scripts();
671 $this->enqueue_styles();
672 }
673
674 /**
675 * After frontend element render.
676 *
677 * Fires after Elementor element is rendered in the frontend.
678 *
679 * The dynamic portion of the hook name, `$element_type`, refers to the element type.
680 *
681 * @since 1.0.0
682 *
683 * @param Element_Base $this The element.
684 */
685 do_action( "elementor/frontend/{$element_type}/after_render", $this );
686
687 /**
688 * After frontend element render.
689 *
690 * Fires after Elementor element is rendered in the frontend.
691 *
692 * @since 2.3.0
693 *
694 * @param Element_Base $this The element.
695 */
696 do_action( 'elementor/frontend/after_render', $this );
697 }
698
699 /**
700 * Get the element raw data.
701 *
702 * Retrieve the raw element data, including the id, type, settings, child
703 * elements and whether it is an inner element.
704 *
705 * The data with the HTML used always to display the data, but the Elementor
706 * editor uses the raw data without the HTML in order not to render the data
707 * again.
708 *
709 * @since 1.0.0
710 * @access public
711 *
712 * @param bool $with_html_content Optional. Whether to return the data with
713 * HTML content or without. Used for caching.
714 * Default is false, without HTML.
715 *
716 * @return array Element raw data.
717 */
718 public function get_raw_data( $with_html_content = false ) {
719 $data = $this->get_data();
720
721 $elements = [];
722
723 foreach ( $this->get_children() as $child ) {
724 $elements[] = $child->get_raw_data( $with_html_content );
725 }
726
727 return [
728 'id' => $this->get_id(),
729 'elType' => $data['elType'],
730 'settings' => $data['settings'],
731 'elements' => $elements,
732 'isInner' => $data['isInner'],
733 ];
734 }
735
736 /**
737 * Get unique selector.
738 *
739 * Retrieve the unique selector of the element. Used to set a unique HTML
740 * class for each HTML element. This way Elementor can set custom styles for
741 * each element.
742 *
743 * @since 1.0.0
744 * @access public
745 *
746 * @return string Unique selector.
747 */
748 public function get_unique_selector() {
749 return '.elementor-element-' . $this->get_id();
750 }
751
752 /**
753 * Is type instance.
754 *
755 * Used to determine whether the element is an instance of that type or not.
756 *
757 * @since 1.0.0
758 * @access public
759 *
760 * @return bool Whether the element is an instance of that type.
761 */
762 public function is_type_instance() {
763 return $this->is_type_instance;
764 }
765
766 /**
767 * Add render attributes.
768 *
769 * Used to add attributes to the current element wrapper HTML tag.
770 *
771 * @since 1.3.0
772 * @access protected
773 */
774 protected function _add_render_attributes() {
775 $id = $this->get_id();
776
777 $settings = $this->get_settings_for_display();
778 $frontend_settings = $this->get_frontend_settings();
779 $controls = $this->get_controls();
780
781 $this->add_render_attribute( '_wrapper', [
782 'class' => [
783 'elementor-element',
784 'elementor-element-' . $id,
785 ],
786 'data-id' => $id,
787 'data-element_type' => $this->get_type(),
788 ] );
789
790 $class_settings = [];
791
792 foreach ( $settings as $setting_key => $setting ) {
793 if ( isset( $controls[ $setting_key ]['prefix_class'] ) ) {
794 $class_settings[ $setting_key ] = $setting;
795 }
796 }
797
798 foreach ( $class_settings as $setting_key => $setting ) {
799 if ( empty( $setting ) && '0' !== $setting ) {
800 continue;
801 }
802
803 $this->add_render_attribute( '_wrapper', 'class', $controls[ $setting_key ]['prefix_class'] . $setting );
804 }
805
806 if ( ! empty( $settings['animation'] ) || ! empty( $settings['_animation'] ) ) {
807 $is_static_render_mode = Plugin::$instance->frontend->is_static_render_mode();
808
809 if ( ! $is_static_render_mode ) {
810 // Hide the element until the animation begins
811 $this->add_render_attribute( '_wrapper', 'class', 'elementor-invisible' );
812 }
813 }
814
815 if ( ! empty( $settings['_element_id'] ) ) {
816 $this->add_render_attribute( '_wrapper', 'id', trim( $settings['_element_id'] ) );
817 }
818
819 if ( $frontend_settings ) {
820 $this->add_render_attribute( '_wrapper', 'data-settings', wp_json_encode( $frontend_settings ) );
821 }
822
823 /**
824 * After element attribute rendered.
825 *
826 * Fires after the attributes of the element HTML tag are rendered.
827 *
828 * @since 2.3.0
829 *
830 * @param Element_Base $this The element.
831 */
832 do_action( 'elementor/element/after_add_attributes', $this );
833 }
834
835 /**
836 * Get default data.
837 *
838 * Retrieve the default element data. Used to reset the data on initialization.
839 *
840 * @since 1.0.0
841 * @access protected
842 *
843 * @return array Default data.
844 */
845 protected function get_default_data() {
846 $data = parent::get_default_data();
847
848 return array_merge(
849 $data, [
850 'elements' => [],
851 'isInner' => false,
852 ]
853 );
854 }
855
856 /**
857 * Print element content.
858 *
859 * Output the element final HTML on the frontend.
860 *
861 * @since 1.0.0
862 * @access protected
863 */
864 protected function _print_content() {
865 foreach ( $this->get_children() as $child ) {
866 $child->print_element();
867 }
868 }
869
870 /**
871 * Get initial config.
872 *
873 * Retrieve the current element initial configuration.
874 *
875 * Adds more configuration on top of the controls list and the tabs assigned
876 * to the control. This method also adds element name, type, icon and more.
877 *
878 * @since 2.9.0
879 * @access protected
880 *
881 * @return array The initial config.
882 */
883 protected function get_initial_config() {
884 $config = [
885 'name' => $this->get_name(),
886 'elType' => $this->get_type(),
887 'title' => $this->get_title(),
888 'icon' => $this->get_icon(),
889 'reload_preview' => $this->is_reload_preview_required(),
890 ];
891
892 if ( preg_match( '/^' . __NAMESPACE__ . '(Pro)?\\\\/', get_called_class() ) ) {
893 $config['help_url'] = $this->get_help_url();
894 } else {
895 $config['help_url'] = $this->get_custom_help_url();
896 }
897
898 if ( ! $this->is_editable() ) {
899 $config['editable'] = false;
900 }
901
902 return $config;
903 }
904
905 /**
906 * Get child type.
907 *
908 * Retrieve the element child type based on element data.
909 *
910 * @since 2.0.0
911 * @access private
912 *
913 * @param array $element_data Element ID.
914 *
915 * @return Element_Base|false Child type or false if type not found.
916 */
917 private function get_child_type( $element_data ) {
918 $child_type = $this->_get_default_child_type( $element_data );
919
920 // If it's not a valid widget ( like a deactivated plugin )
921 if ( ! $child_type ) {
922 return false;
923 }
924
925 /**
926 * Element child type.
927 *
928 * Filters the child type of the element.
929 *
930 * @since 1.0.0
931 *
932 * @param Element_Base $child_type The child element.
933 * @param array $element_data The original element ID.
934 * @param Element_Base $this The original element.
935 */
936 $child_type = apply_filters( 'elementor/element/get_child_type', $child_type, $element_data, $this );
937
938 return $child_type;
939 }
940
941 /**
942 * Initialize children.
943 *
944 * Initializing the element child elements.
945 *
946 * @since 2.0.0
947 * @access private
948 */
949 private function init_children() {
950 $this->children = [];
951
952 $children_data = $this->get_data( 'elements' );
953
954 if ( ! $children_data ) {
955 return;
956 }
957
958 foreach ( $children_data as $child_data ) {
959 if ( ! $child_data ) {
960 continue;
961 }
962
963 $this->add_child( $child_data );
964 }
965 }
966
967 /**
968 * Element base constructor.
969 *
970 * Initializing the element base class using `$data` and `$args`.
971 *
972 * The `$data` parameter is required for a normal instance because of the
973 * way Elementor renders data when initializing elements.
974 *
975 * @since 1.0.0
976 * @access public
977 *
978 * @param array $data Optional. Element data. Default is an empty array.
979 * @param array|null $args Optional. Element default arguments. Default is null.
980 **/
981 public function __construct( array $data = [], array $args = null ) {
982 if ( $data ) {
983 $this->is_type_instance = false;
984 } elseif ( $args ) {
985 $this->default_args = $args;
986 }
987
988 parent::__construct( $data );
989 }
990 }
991