PluginProbe
Elementor Website Builder – more than just a page builder / 3.6.4
Elementor Website Builder – more than just a page builder v3.6.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 / controls-stack.php

controls-stack.php in Elementor Website Builder – more than just a page builder 3.6.4, at includes/base/controls-stack.php

2,432 lines 65.4 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\Base\Base_Object;
5 use Elementor\Core\DynamicTags\Manager;
6 use Elementor\Core\Schemes\Manager as Schemes_Manager;
7 use Elementor\Core\Breakpoints\Manager as Breakpoints_Manager;
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit; // Exit if accessed directly.
11 }
12
13 /**
14 * Elementor controls stack.
15 *
16 * An abstract class that provides the needed properties and methods to
17 * manage and handle controls in the editor panel to inheriting classes.
18 *
19 * @since 1.4.0
20 * @abstract
21 */
22 abstract class Controls_Stack extends Base_Object {
23
24 /**
25 * Responsive 'desktop' device name.
26 *
27 * @deprecated 3.4.0
28 */
29 const RESPONSIVE_DESKTOP = 'desktop';
30
31 /**
32 * Responsive 'tablet' device name.
33 *
34 * @deprecated 3.4.0
35 */
36 const RESPONSIVE_TABLET = 'tablet';
37
38 /**
39 * Responsive 'mobile' device name.
40 *
41 * @deprecated 3.4.0
42 */
43 const RESPONSIVE_MOBILE = 'mobile';
44
45 /**
46 * Generic ID.
47 *
48 * Holds the unique ID.
49 *
50 * @access private
51 *
52 * @var string
53 */
54 private $id;
55
56 private $active_settings;
57
58 private $parsed_active_settings;
59
60 /**
61 * Parsed Dynamic Settings.
62 *
63 * @access private
64 *
65 * @var null|array
66 */
67 private $parsed_dynamic_settings;
68
69 /**
70 * Raw Data.
71 *
72 * Holds all the raw data including the element type, the child elements,
73 * the user data.
74 *
75 * @access private
76 *
77 * @var null|array
78 */
79 private $data;
80
81 /**
82 * The configuration.
83 *
84 * Holds the configuration used to generate the Elementor editor. It includes
85 * the element name, icon, categories, etc.
86 *
87 * @access private
88 *
89 * @var null|array
90 */
91 private $config;
92
93 /**
94 * The additional configuration.
95 *
96 * Holds additional configuration that has been set using `set_config` method.
97 * The `config` property is not modified directly while using the method because
98 * it's used to check whether the initial config already loaded (in `get_config`).
99 * After the initial config loaded, the additional config is merged into it.
100 *
101 * @access private
102 *
103 * @var null|array
104 */
105 private $additional_config = [];
106
107 /**
108 * Current section.
109 *
110 * Holds the current section while inserting a set of controls sections.
111 *
112 * @access private
113 *
114 * @var null|array
115 */
116 private $current_section;
117
118 /**
119 * Current tab.
120 *
121 * Holds the current tab while inserting a set of controls tabs.
122 *
123 * @access private
124 *
125 * @var null|array
126 */
127 private $current_tab;
128
129 /**
130 * Current popover.
131 *
132 * Holds the current popover while inserting a set of controls.
133 *
134 * @access private
135 *
136 * @var null|array
137 */
138 private $current_popover;
139
140 /**
141 * Injection point.
142 *
143 * Holds the injection point in the stack where the control will be inserted.
144 *
145 * @access private
146 *
147 * @var null|array
148 */
149 private $injection_point;
150
151
152 /**
153 * Data sanitized.
154 *
155 * @access private
156 *
157 * @var bool
158 */
159 private $settings_sanitized = false;
160
161 /**
162 * Element render attributes.
163 *
164 * Holds all the render attributes of the element. Used to store data like
165 * the HTML class name and the class value, or HTML element ID name and value.
166 *
167 * @access private
168 *
169 * @var array
170 */
171 private $render_attributes = [];
172
173 /**
174 * Get element name.
175 *
176 * Retrieve the element name.
177 *
178 * @since 1.4.0
179 * @access public
180 * @abstract
181 *
182 * @return string The name.
183 */
184 abstract public function get_name();
185
186 /**
187 * Get unique name.
188 *
189 * Some classes need to use unique names, this method allows you to create
190 * them. By default it retrieves the regular name.
191 *
192 * @since 1.6.0
193 * @access public
194 *
195 * @return string Unique name.
196 */
197 public function get_unique_name() {
198 return $this->get_name();
199 }
200
201 /**
202 * Get element ID.
203 *
204 * Retrieve the element generic ID.
205 *
206 * @since 1.4.0
207 * @access public
208 *
209 * @return string The ID.
210 */
211 public function get_id() {
212 return $this->id;
213 }
214
215 /**
216 * Get element ID.
217 *
218 * Retrieve the element generic ID as integer.
219 *
220 * @since 1.8.0
221 * @access public
222 *
223 * @return string The converted ID.
224 */
225 public function get_id_int() {
226 /** We ignore possible notices, in order to support elements created prior to v1.8.0 and might include
227 * non-base 16 characters as part of their ID.
228 */
229 return @hexdec( $this->id );
230 }
231
232 /**
233 * Get the type.
234 *
235 * Retrieve the type, e.g. 'stack', 'section', 'widget' etc.
236 *
237 * @since 1.4.0
238 * @access public
239 * @static
240 *
241 * @return string The type.
242 */
243 public static function get_type() {
244 return 'stack';
245 }
246
247 /**
248 * @since 2.9.0
249 * @access public
250 *
251 * @return bool
252 */
253 public function is_editable() {
254 return true;
255 }
256
257 /**
258 * Get current section.
259 *
260 * When inserting new controls, this method will retrieve the current section.
261 *
262 * @since 1.7.1
263 * @access public
264 *
265 * @return null|array Current section.
266 */
267 public function get_current_section() {
268 return $this->current_section;
269 }
270
271 /**
272 * Get current tab.
273 *
274 * When inserting new controls, this method will retrieve the current tab.
275 *
276 * @since 1.7.1
277 * @access public
278 *
279 * @return null|array Current tab.
280 */
281 public function get_current_tab() {
282 return $this->current_tab;
283 }
284
285 /**
286 * Get controls.
287 *
288 * Retrieve all the controls or, when requested, a specific control.
289 *
290 * @since 1.4.0
291 * @access public
292 *
293 * @param string $control_id The ID of the requested control. Optional field,
294 * when set it will return a specific control.
295 * Default is null.
296 *
297 * @return mixed Controls list.
298 */
299 public function get_controls( $control_id = null ) {
300 return self::get_items( $this->get_stack()['controls'], $control_id );
301 }
302
303 /**
304 * Get active controls.
305 *
306 * Retrieve an array of active controls that meet the condition field.
307 *
308 * If specific controls was given as a parameter, retrieve active controls
309 * from that list, otherwise check for all the controls available.
310 *
311 * @since 1.4.0
312 * @since 2.0.9 Added the `controls` and the `settings` parameters.
313 * @access public
314 * @deprecated 3.0.0
315 *
316 * @param array $controls Optional. An array of controls. Default is null.
317 * @param array $settings Optional. Controls settings. Default is null.
318 *
319 * @return array Active controls.
320 */
321 public function get_active_controls( array $controls = null, array $settings = null ) {
322 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.0.0' );
323
324 if ( ! $controls ) {
325 $controls = $this->get_controls();
326 }
327
328 if ( ! $settings ) {
329 $settings = $this->get_controls_settings();
330 }
331
332 $active_controls = array_reduce(
333 array_keys( $controls ), function( $active_controls, $control_key ) use ( $controls, $settings ) {
334 $control = $controls[ $control_key ];
335
336 if ( $this->is_control_visible( $control, $settings ) ) {
337 $active_controls[ $control_key ] = $control;
338 }
339
340 return $active_controls;
341 }, []
342 );
343
344 return $active_controls;
345 }
346
347 /**
348 * Get controls settings.
349 *
350 * Retrieve the settings for all the controls that represent them.
351 *
352 * @since 1.5.0
353 * @access public
354 *
355 * @return array Controls settings.
356 */
357 public function get_controls_settings() {
358 return array_intersect_key( $this->get_settings(), $this->get_controls() );
359 }
360
361 /**
362 * Add new control to stack.
363 *
364 * Register a single control to allow the user to set/update data.
365 *
366 * This method should be used inside `register_controls()`.
367 *
368 * @since 1.4.0
369 * @access public
370 *
371 * @param string $id Control ID.
372 * @param array $args Control arguments.
373 * @param array $options Optional. Control options. Default is an empty array.
374 *
375 * @return bool True if control added, False otherwise.
376 */
377 public function add_control( $id, array $args, $options = [] ) {
378 $default_options = [
379 'overwrite' => false,
380 'position' => null,
381 ];
382
383 if ( isset( $args['scheme'] ) ) {
384 $args['global'] = [
385 'default' => Plugin::$instance->kits_manager->convert_scheme_to_global( $args['scheme'] ),
386 ];
387
388 unset( $args['scheme'] );
389 }
390
391 $options = array_merge( $default_options, $options );
392
393 if ( $options['position'] ) {
394 $this->start_injection( $options['position'] );
395 }
396
397 if ( $this->injection_point ) {
398 $options['index'] = $this->injection_point['index']++;
399 }
400
401 if ( empty( $args['type'] ) || ! in_array( $args['type'], [ Controls_Manager::SECTION, Controls_Manager::WP_WIDGET ], true ) ) {
402 $args = $this->handle_control_position( $args, $id, $options['overwrite'] );
403 }
404
405 if ( $options['position'] ) {
406 $this->end_injection();
407 }
408
409 unset( $options['position'] );
410
411 if ( $this->current_popover && ! $this->current_popover['initialized'] ) {
412 $args['popover'] = [
413 'start' => true,
414 ];
415
416 $this->current_popover['initialized'] = true;
417 }
418
419 return Plugin::$instance->controls_manager->add_control_to_stack( $this, $id, $args, $options );
420 }
421
422 /**
423 * Remove control from stack.
424 *
425 * Unregister an existing control and remove it from the stack.
426 *
427 * @since 1.4.0
428 * @access public
429 *
430 * @param string $control_id Control ID.
431 *
432 * @return bool|\WP_Error
433 */
434 public function remove_control( $control_id ) {
435 return Plugin::$instance->controls_manager->remove_control_from_stack( $this->get_unique_name(), $control_id );
436 }
437
438 /**
439 * Update control in stack.
440 *
441 * Change the value of an existing control in the stack. When you add new
442 * control you set the `$args` parameter, this method allows you to update
443 * the arguments by passing new data.
444 *
445 * @since 1.4.0
446 * @since 1.8.1 New `$options` parameter added.
447 *
448 * @access public
449 *
450 * @param string $control_id Control ID.
451 * @param array $args Control arguments. Only the new fields you want
452 * to update.
453 * @param array $options Optional. Some additional options. Default is
454 * an empty array.
455 *
456 * @return bool
457 */
458 public function update_control( $control_id, array $args, array $options = [] ) {
459 $is_updated = Plugin::$instance->controls_manager->update_control_in_stack( $this, $control_id, $args, $options );
460
461 if ( ! $is_updated ) {
462 return false;
463 }
464
465 $control = $this->get_controls( $control_id );
466
467 if ( Controls_Manager::SECTION === $control['type'] ) {
468 $section_args = $this->get_section_args( $control_id );
469
470 $section_controls = $this->get_section_controls( $control_id );
471
472 foreach ( $section_controls as $section_control_id => $section_control ) {
473 $this->update_control( $section_control_id, $section_args, $options );
474 }
475 }
476
477 return true;
478 }
479
480 /**
481 * Get stack.
482 *
483 * Retrieve the stack of controls.
484 *
485 * @since 1.9.2
486 * @access public
487 *
488 * @return array Stack of controls.
489 */
490 public function get_stack() {
491 $stack = Plugin::$instance->controls_manager->get_element_stack( $this );
492
493 if ( null === $stack ) {
494 $this->init_controls();
495
496 return Plugin::$instance->controls_manager->get_element_stack( $this );
497 }
498
499 return $stack;
500 }
501
502 /**
503 * Get position information.
504 *
505 * Retrieve the position while injecting data, based on the element type.
506 *
507 * @since 1.7.0
508 * @access public
509 *
510 * @param array $position {
511 * The injection position.
512 *
513 * @type string $type Injection type, either `control` or `section`.
514 * Default is `control`.
515 * @type string $at Where to inject. If `$type` is `control` accepts
516 * `before` and `after`. If `$type` is `section`
517 * accepts `start` and `end`. Default values based on
518 * the `type`.
519 * @type string $of Control/Section ID.
520 * @type array $fallback Fallback injection position. When the position is
521 * not found it will try to fetch the fallback
522 * position.
523 * }
524 *
525 * @return bool|array Position info.
526 */
527 final public function get_position_info( array $position ) {
528 $default_position = [
529 'type' => 'control',
530 'at' => 'after',
531 ];
532
533 if ( ! empty( $position['type'] ) && 'section' === $position['type'] ) {
534 $default_position['at'] = 'end';
535 }
536
537 $position = array_merge( $default_position, $position );
538
539 if (
540 'control' === $position['type'] && in_array( $position['at'], [ 'start', 'end' ], true ) ||
541 'section' === $position['type'] && in_array( $position['at'], [ 'before', 'after' ], true )
542 ) {
543 _doing_it_wrong( sprintf( '%s::%s', get_called_class(), __FUNCTION__ ), 'Invalid position arguments. Use `before` / `after` for control or `start` / `end` for section.', '1.7.0' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
544
545 return false;
546 }
547
548 $target_control_index = $this->get_control_index( $position['of'] );
549
550 if ( false === $target_control_index ) {
551 if ( ! empty( $position['fallback'] ) ) {
552 return $this->get_position_info( $position['fallback'] );
553 }
554
555 return false;
556 }
557
558 $target_section_index = $target_control_index;
559
560 $registered_controls = $this->get_controls();
561
562 $controls_keys = array_keys( $registered_controls );
563
564 while ( Controls_Manager::SECTION !== $registered_controls[ $controls_keys[ $target_section_index ] ]['type'] ) {
565 $target_section_index--;
566 }
567
568 if ( 'section' === $position['type'] ) {
569 $target_control_index++;
570
571 if ( 'end' === $position['at'] ) {
572 while ( Controls_Manager::SECTION !== $registered_controls[ $controls_keys[ $target_control_index ] ]['type'] ) {
573 if ( ++$target_control_index >= count( $registered_controls ) ) {
574 break;
575 }
576 }
577 }
578 }
579
580 $target_control = $registered_controls[ $controls_keys[ $target_control_index ] ];
581
582 if ( 'after' === $position['at'] ) {
583 $target_control_index++;
584 }
585
586 $section_id = $registered_controls[ $controls_keys[ $target_section_index ] ]['name'];
587
588 $position_info = [
589 'index' => $target_control_index,
590 'section' => $this->get_section_args( $section_id ),
591 ];
592
593 if ( ! empty( $target_control['tabs_wrapper'] ) ) {
594 $position_info['tab'] = [
595 'tabs_wrapper' => $target_control['tabs_wrapper'],
596 'inner_tab' => $target_control['inner_tab'],
597 ];
598 }
599
600 return $position_info;
601 }
602
603 /**
604 * Get control key.
605 *
606 * Retrieve the key of the control based on a given index of the control.
607 *
608 * @since 1.9.2
609 * @access public
610 *
611 * @param string $control_index Control index.
612 *
613 * @return int Control key.
614 */
615 final public function get_control_key( $control_index ) {
616 $registered_controls = $this->get_controls();
617
618 $controls_keys = array_keys( $registered_controls );
619
620 return $controls_keys[ $control_index ];
621 }
622
623 /**
624 * Get control index.
625 *
626 * Retrieve the index of the control based on a given key of the control.
627 *
628 * @since 1.7.6
629 * @access public
630 *
631 * @param string $control_key Control key.
632 *
633 * @return false|int Control index.
634 */
635 final public function get_control_index( $control_key ) {
636 $controls = $this->get_controls();
637
638 $controls_keys = array_keys( $controls );
639
640 return array_search( $control_key, $controls_keys );
641 }
642
643 /**
644 * Get section controls.
645 *
646 * Retrieve all controls under a specific section.
647 *
648 * @since 1.7.6
649 * @access public
650 *
651 * @param string $section_id Section ID.
652 *
653 * @return array Section controls
654 */
655 final public function get_section_controls( $section_id ) {
656 $section_index = $this->get_control_index( $section_id );
657
658 $section_controls = [];
659
660 $registered_controls = $this->get_controls();
661
662 $controls_keys = array_keys( $registered_controls );
663
664 while ( true ) {
665 $section_index++;
666
667 if ( ! isset( $controls_keys[ $section_index ] ) ) {
668 break;
669 }
670
671 $control_key = $controls_keys[ $section_index ];
672
673 if ( Controls_Manager::SECTION === $registered_controls[ $control_key ]['type'] ) {
674 break;
675 }
676
677 $section_controls[ $control_key ] = $registered_controls[ $control_key ];
678 };
679
680 return $section_controls;
681 }
682
683 /**
684 * Add new group control to stack.
685 *
686 * Register a set of related controls grouped together as a single unified
687 * control. For example grouping together like typography controls into a
688 * single, easy-to-use control.
689 *
690 * @since 1.4.0
691 * @access public
692 *
693 * @param string $group_name Group control name.
694 * @param array $args Group control arguments. Default is an empty array.
695 * @param array $options Optional. Group control options. Default is an
696 * empty array.
697 */
698 final public function add_group_control( $group_name, array $args = [], array $options = [] ) {
699 $group = Plugin::$instance->controls_manager->get_control_groups( $group_name );
700
701 if ( ! $group ) {
702 wp_die( sprintf( '%s::%s: Group "%s" not found.', get_called_class(), __FUNCTION__, $group_name ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
703 }
704
705 $group->add_controls( $this, $args, $options );
706 }
707
708 /**
709 * Get scheme controls.
710 *
711 * Retrieve all the controls that use schemes.
712 *
713 * @since 1.4.0
714 * @access public
715 * @deprecated 3.0.0
716 *
717 * @return array Scheme controls.
718 */
719 final public function get_scheme_controls() {
720
721 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.0.0' );
722
723 $enabled_schemes = Schemes_Manager::get_enabled_schemes();
724
725 return array_filter(
726 $this->get_controls(), function ( $control ) use ( $enabled_schemes ) {
727 return ( ! empty( $control['scheme'] ) && in_array( $control['scheme']['type'], $enabled_schemes ) );
728 }
729 );
730 }
731
732 /**
733 * Get style controls.
734 *
735 * Retrieve style controls for all active controls or, when requested, from
736 * a specific set of controls.
737 *
738 * @since 1.4.0
739 * @since 2.0.9 Added the `settings` parameter.
740 * @access public
741 * @deprecated 3.0.0
742 *
743 * @param array $controls Optional. Controls list. Default is null.
744 * @param array $settings Optional. Controls settings. Default is null.
745 *
746 * @return array Style controls.
747 */
748 final public function get_style_controls( array $controls = null, array $settings = null ) {
749 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.0.0' );
750
751 $controls = $this->get_active_controls( $controls, $settings );
752
753 $style_controls = [];
754
755 foreach ( $controls as $control_name => $control ) {
756 $control_obj = Plugin::$instance->controls_manager->get_control( $control['type'] );
757
758 if ( ! $control_obj instanceof Base_Data_Control ) {
759 continue;
760 }
761
762 $control = array_merge( $control_obj->get_settings(), $control );
763
764 if ( $control_obj instanceof Control_Repeater ) {
765 $style_fields = [];
766
767 foreach ( $this->get_settings( $control_name ) as $item ) {
768 $style_fields[] = $this->get_style_controls( $control['fields'], $item );
769 }
770
771 $control['style_fields'] = $style_fields;
772 }
773
774 if ( ! empty( $control['selectors'] ) || ! empty( $control['dynamic'] ) || ! empty( $control['style_fields'] ) ) {
775 $style_controls[ $control_name ] = $control;
776 }
777 }
778
779 return $style_controls;
780 }
781
782 /**
783 * Get tabs controls.
784 *
785 * Retrieve all the tabs assigned to the control.
786 *
787 * @since 1.4.0
788 * @access public
789 *
790 * @return array Tabs controls.
791 */
792 final public function get_tabs_controls() {
793 return $this->get_stack()['tabs'];
794 }
795
796 /**
797 * Add new responsive control to stack.
798 *
799 * Register a set of controls to allow editing based on user screen size.
800 * This method registers one or more controls per screen size/device, depending on the current Responsive Control
801 * Duplication Mode. There are 3 control duplication modes:
802 * * 'off' - Only a single control is generated. In the Editor, this control is duplicated in JS.
803 * * 'on' - Multiple controls are generated, one control per enabled device/breakpoint + a default/desktop control.
804 * * 'dynamic' - If the control includes the `'dynamic' => 'active' => true` property - the control is duplicated,
805 * once for each device/breakpoint + default/desktop.
806 * If the control doesn't include the `'dynamic' => 'active' => true` property - the control is not duplicated.
807 *
808 * @since 1.4.0
809 * @access public
810 *
811 * @param string $id Responsive control ID.
812 * @param array $args Responsive control arguments.
813 * @param array $options Optional. Responsive control options. Default is
814 * an empty array.
815 */
816 final public function add_responsive_control( $id, array $args, $options = [] ) {
817 $args['responsive'] = [];
818
819 $active_breakpoints = Plugin::$instance->breakpoints->get_active_breakpoints();
820
821 $devices = Plugin::$instance->breakpoints->get_active_devices_list( [
822 'reverse' => true,
823 'desktop_first' => true,
824 ] );
825
826 if ( isset( $args['devices'] ) ) {
827 $devices = array_intersect( $devices, $args['devices'] );
828
829 $args['responsive']['devices'] = $devices;
830
831 unset( $args['devices'] );
832 }
833
834 $control_to_check = $args;
835
836 if ( ! empty( $options['overwrite'] ) ) {
837 $existing_control = Plugin::$instance->controls_manager->get_control_from_stack( $this->get_unique_name(), $id );
838
839 if ( ! is_wp_error( $existing_control ) ) {
840 $control_to_check = $existing_control;
841 }
842 }
843
844 $responsive_duplication_mode = Plugin::$instance->breakpoints->get_responsive_control_duplication_mode();
845 $additional_breakpoints_active = Plugin::$instance->experiments->is_feature_active( 'additional_custom_breakpoints' );
846 $control_is_dynamic = ! empty( $control_to_check['dynamic']['active'] );
847 $is_frontend_available = ! empty( $control_to_check['frontend_available'] );
848 $has_prefix_class = ! empty( $control_to_check['prefix_class'] );
849
850 // If the new responsive controls experiment is active, create only one control - duplicates per device will
851 // be created in JS in the Editor.
852 if (
853 $additional_breakpoints_active
854 && ( 'off' === $responsive_duplication_mode || ( 'dynamic' === $responsive_duplication_mode && ! $control_is_dynamic ) )
855 // Some responsive controls need responsive settings to be available to the widget handler, even when empty.
856 && ! $is_frontend_available
857 && ! $has_prefix_class
858 ) {
859 $args['is_responsive'] = true;
860
861 if ( ! empty( $options['overwrite'] ) ) {
862 $this->update_control( $id, $args, [
863 'recursive' => ! empty( $options['recursive'] ),
864 ] );
865 } else {
866 $this->add_control( $id, $args, $options );
867 }
868
869 return;
870 }
871
872 if ( isset( $args['default'] ) ) {
873 $args['desktop_default'] = $args['default'];
874
875 unset( $args['default'] );
876 }
877
878 foreach ( $devices as $device_name ) {
879 $control_args = $args;
880
881 // Set parent using the name from previous iteration.
882 if ( isset( $control_name ) ) {
883 // If $control_name end with _widescreen use desktop name instead
884 $control_args['parent'] = '_widescreen' === substr( $control_name, -strlen( '_widescreen' ) ) ? $id : $control_name;
885 } else {
886 $control_args['parent'] = null;
887 }
888
889 if ( isset( $control_args['device_args'] ) ) {
890 if ( ! empty( $control_args['device_args'][ $device_name ] ) ) {
891 $control_args = array_merge( $control_args, $control_args['device_args'][ $device_name ] );
892 }
893
894 unset( $control_args['device_args'] );
895 }
896
897 if ( ! empty( $args['prefix_class'] ) ) {
898 $device_to_replace = Breakpoints_Manager::BREAKPOINT_KEY_DESKTOP === $device_name ? '' : '-' . $device_name;
899
900 $control_args['prefix_class'] = sprintf( $args['prefix_class'], $device_to_replace );
901 }
902
903 $direction = 'max';
904
905 if ( Breakpoints_Manager::BREAKPOINT_KEY_DESKTOP !== $device_name ) {
906 $direction = $active_breakpoints[ $device_name ]->get_direction();
907 }
908
909 $control_args['responsive'][ $direction ] = $device_name;
910
911 if ( isset( $control_args['min_affected_device'] ) ) {
912 if ( ! empty( $control_args['min_affected_device'][ $device_name ] ) ) {
913 $control_args['responsive']['min'] = $control_args['min_affected_device'][ $device_name ];
914 }
915
916 unset( $control_args['min_affected_device'] );
917 }
918
919 if ( isset( $control_args[ $device_name . '_default' ] ) ) {
920 $control_args['default'] = $control_args[ $device_name . '_default' ];
921 }
922
923 foreach ( $devices as $device ) {
924 unset( $control_args[ $device . '_default' ] );
925 }
926
927 $id_suffix = Breakpoints_Manager::BREAKPOINT_KEY_DESKTOP === $device_name ? '' : '_' . $device_name;
928 $control_name = $id . $id_suffix;
929
930 // Set this control as child of previous iteration control.
931 $this->update_control( $control_args['parent'], [ 'inheritors' => [ $control_name ] ] );
932
933 if ( ! empty( $options['overwrite'] ) ) {
934 $this->update_control( $control_name, $control_args, [
935 'recursive' => ! empty( $options['recursive'] ),
936 ] );
937 } else {
938 $this->add_control( $control_name, $control_args, $options );
939 }
940 }
941 }
942
943 /**
944 * Update responsive control in stack.
945 *
946 * Change the value of an existing responsive control in the stack. When you
947 * add new control you set the `$args` parameter, this method allows you to
948 * update the arguments by passing new data.
949 *
950 * @since 1.4.0
951 * @access public
952 *
953 * @param string $id Responsive control ID.
954 * @param array $args Responsive control arguments.
955 * @param array $options Optional. Additional options.
956 */
957 final public function update_responsive_control( $id, array $args, array $options = [] ) {
958 $this->add_responsive_control( $id, $args, [
959 'overwrite' => true,
960 'recursive' => ! empty( $options['recursive'] ),
961 ] );
962 }
963
964 /**
965 * Remove responsive control from stack.
966 *
967 * Unregister an existing responsive control and remove it from the stack.
968 *
969 * @since 1.4.0
970 * @access public
971 *
972 * @param string $id Responsive control ID.
973 */
974 final public function remove_responsive_control( $id ) {
975 $devices = Plugin::$instance->breakpoints->get_active_devices_list( [ 'reverse' => true ] );
976
977 foreach ( $devices as $device_name ) {
978 $id_suffix = Breakpoints_Manager::BREAKPOINT_KEY_DESKTOP === $device_name ? '' : '_' . $device_name;
979
980 $this->remove_control( $id . $id_suffix );
981 }
982 }
983
984 /**
985 * Get class name.
986 *
987 * Retrieve the name of the current class.
988 *
989 * @since 1.4.0
990 * @access public
991 *
992 * @return string Class name.
993 */
994 final public function get_class_name() {
995 return get_called_class();
996 }
997
998 /**
999 * Get the config.
1000 *
1001 * Retrieve the config or, if non set, use the initial config.
1002 *
1003 * @since 1.4.0
1004 * @access public
1005 *
1006 * @return array|null The config.
1007 */
1008 final public function get_config() {
1009 if ( null === $this->config ) {
1010 // TODO: This is for backwards compatibility starting from 2.9.0
1011 // This if statement should be removed when the method is hard-deprecated
1012 if ( $this->has_own_method( '_get_initial_config', self::class ) ) {
1013 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( '_get_initial_config', '2.9.0', __CLASS__ . '::get_initial_config()' );
1014
1015 $this->config = $this->_get_initial_config();
1016 } else {
1017 $this->config = $this->get_initial_config();
1018 }
1019
1020 foreach ( $this->additional_config as $key => $value ) {
1021 if ( isset( $this->config[ $key ] ) ) {
1022 $this->config[ $key ] = wp_parse_args( $value, $this->config[ $key ] );
1023 } else {
1024 $this->config[ $key ] = $value;
1025 }
1026 }
1027 }
1028
1029 return $this->config;
1030 }
1031
1032 /**
1033 * Set a config property.
1034 *
1035 * Set a specific property of the config list for this controls-stack.
1036 *
1037 * @since 3.5.0
1038 * @access public
1039 */
1040 public function set_config( $key, $value ) {
1041 if ( isset( $this->additional_config[ $key ] ) ) {
1042 $this->additional_config[ $key ] = wp_parse_args( $value, $this->additional_config[ $key ] );
1043 } else {
1044 $this->additional_config[ $key ] = $value;
1045 }
1046 }
1047
1048 /**
1049 * Get frontend settings keys.
1050 *
1051 * Retrieve settings keys for all frontend controls.
1052 *
1053 * @since 1.6.0
1054 * @access public
1055 *
1056 * @return array Settings keys for each control.
1057 */
1058 final public function get_frontend_settings_keys() {
1059 $controls = [];
1060
1061 foreach ( $this->get_controls() as $control ) {
1062 if ( ! empty( $control['frontend_available'] ) ) {
1063 $controls[] = $control['name'];
1064 }
1065 }
1066
1067 return $controls;
1068 }
1069
1070 /**
1071 * Get controls pointer index.
1072 *
1073 * Retrieve pointer index where the next control should be added.
1074 *
1075 * While using injection point, it will return the injection point index.
1076 * Otherwise index of the last control plus one.
1077 *
1078 * @since 1.9.2
1079 * @access public
1080 *
1081 * @return int Controls pointer index.
1082 */
1083 public function get_pointer_index() {
1084 if ( null !== $this->injection_point ) {
1085 return $this->injection_point['index'];
1086 }
1087
1088 return count( $this->get_controls() );
1089 }
1090
1091 /**
1092 * Get the raw data.
1093 *
1094 * Retrieve all the items or, when requested, a specific item.
1095 *
1096 * @since 1.4.0
1097 * @access public
1098 *
1099 * @param string $item Optional. The requested item. Default is null.
1100 *
1101 * @return mixed The raw data.
1102 */
1103 public function get_data( $item = null ) {
1104 if ( ! $this->settings_sanitized && ( ! $item || 'settings' === $item ) ) {
1105 $this->data['settings'] = $this->sanitize_settings( $this->data['settings'] );
1106
1107 $this->settings_sanitized = true;
1108 }
1109
1110 return self::get_items( $this->data, $item );
1111 }
1112
1113 /**
1114 * @since 2.0.14
1115 * @access public
1116 */
1117 public function get_parsed_dynamic_settings( $setting = null, $settings = null ) {
1118 if ( null === $settings ) {
1119 $settings = $this->get_settings();
1120 }
1121
1122 if ( null === $this->parsed_dynamic_settings ) {
1123 $this->parsed_dynamic_settings = $this->parse_dynamic_settings( $settings );
1124 }
1125
1126 return self::get_items( $this->parsed_dynamic_settings, $setting );
1127 }
1128
1129 /**
1130 * Get active settings.
1131 *
1132 * Retrieve the settings from all the active controls.
1133 *
1134 * @since 1.4.0
1135 * @since 2.1.0 Added the `controls` and the `settings` parameters.
1136 * @access public
1137 *
1138 * @param array $controls Optional. An array of controls. Default is null.
1139 * @param array $settings Optional. Controls settings. Default is null.
1140 *
1141 * @return array Active settings.
1142 */
1143 public function get_active_settings( $settings = null, $controls = null ) {
1144 $is_first_request = ! $settings && ! $this->active_settings;
1145
1146 if ( ! $settings ) {
1147 if ( $this->active_settings ) {
1148 return $this->active_settings;
1149 }
1150
1151 $settings = $this->get_controls_settings();
1152
1153 $controls = $this->get_controls();
1154 }
1155
1156 $active_settings = [];
1157
1158 foreach ( $settings as $setting_key => $setting ) {
1159 if ( ! isset( $controls[ $setting_key ] ) ) {
1160 $active_settings[ $setting_key ] = $setting;
1161
1162 continue;
1163 }
1164
1165 $control = $controls[ $setting_key ];
1166
1167 if ( $this->is_control_visible( $control, $settings ) ) {
1168 $control_obj = Plugin::$instance->controls_manager->get_control( $control['type'] );
1169
1170 if ( $control_obj instanceof Control_Repeater ) {
1171 foreach ( $setting as & $item ) {
1172 $item = $this->get_active_settings( $item, $control['fields'] );
1173 }
1174 }
1175
1176 $active_settings[ $setting_key ] = $setting;
1177 } else {
1178 $active_settings[ $setting_key ] = null;
1179 }
1180 }
1181
1182 if ( $is_first_request ) {
1183 $this->active_settings = $active_settings;
1184 }
1185
1186 return $active_settings;
1187 }
1188
1189 /**
1190 * Get settings for display.
1191 *
1192 * Retrieve all the settings or, when requested, a specific setting for display.
1193 *
1194 * Unlike `get_settings()` method, this method retrieves only active settings
1195 * that passed all the conditions, rendered all the shortcodes and all the dynamic
1196 * tags.
1197 *
1198 * @since 2.0.0
1199 * @access public
1200 *
1201 * @param string $setting_key Optional. The key of the requested setting.
1202 * Default is null.
1203 *
1204 * @return mixed The settings.
1205 */
1206 public function get_settings_for_display( $setting_key = null ) {
1207 if ( ! $this->parsed_active_settings ) {
1208 $this->parsed_active_settings = $this->get_active_settings( $this->get_parsed_dynamic_settings(), $this->get_controls() );
1209 }
1210
1211 return self::get_items( $this->parsed_active_settings, $setting_key );
1212 }
1213
1214 /**
1215 * Parse dynamic settings.
1216 *
1217 * Retrieve the settings with rendered dynamic tags.
1218 *
1219 * @since 2.0.0
1220 * @access public
1221 *
1222 * @param array $settings Optional. The requested setting. Default is null.
1223 * @param array $controls Optional. The controls array. Default is null.
1224 * @param array $all_settings Optional. All the settings. Default is null.
1225 *
1226 * @return array The settings with rendered dynamic tags.
1227 */
1228 public function parse_dynamic_settings( $settings, $controls = null, $all_settings = null ) {
1229 if ( null === $all_settings ) {
1230 $all_settings = $this->get_settings();
1231 }
1232
1233 if ( null === $controls ) {
1234 $controls = $this->get_controls();
1235 }
1236
1237 foreach ( $controls as $control ) {
1238 $control_name = $control['name'];
1239 $control_obj = Plugin::$instance->controls_manager->get_control( $control['type'] );
1240
1241 if ( ! $control_obj instanceof Base_Data_Control ) {
1242 continue;
1243 }
1244
1245 if ( $control_obj instanceof Control_Repeater ) {
1246 if ( ! isset( $settings[ $control_name ] ) ) {
1247 continue;
1248 }
1249
1250 foreach ( $settings[ $control_name ] as & $field ) {
1251 $field = $this->parse_dynamic_settings( $field, $control['fields'], $field );
1252 }
1253
1254 continue;
1255 }
1256
1257 $dynamic_settings = $control_obj->get_settings( 'dynamic' );
1258
1259 if ( ! $dynamic_settings ) {
1260 $dynamic_settings = [];
1261 }
1262
1263 if ( ! empty( $control['dynamic'] ) ) {
1264 $dynamic_settings = array_merge( $dynamic_settings, $control['dynamic'] );
1265 }
1266
1267 if ( empty( $dynamic_settings ) || ! isset( $all_settings[ Manager::DYNAMIC_SETTING_KEY ][ $control_name ] ) ) {
1268 continue;
1269 }
1270
1271 if ( ! empty( $dynamic_settings['active'] ) && ! empty( $all_settings[ Manager::DYNAMIC_SETTING_KEY ][ $control_name ] ) ) {
1272 $parsed_value = $control_obj->parse_tags( $all_settings[ Manager::DYNAMIC_SETTING_KEY ][ $control_name ], $dynamic_settings );
1273
1274 $dynamic_property = ! empty( $dynamic_settings['property'] ) ? $dynamic_settings['property'] : null;
1275
1276 if ( $dynamic_property ) {
1277 $settings[ $control_name ][ $dynamic_property ] = $parsed_value;
1278 } else {
1279 $settings[ $control_name ] = $parsed_value;
1280 }
1281 }
1282 }
1283
1284 return $settings;
1285 }
1286
1287 /**
1288 * Get frontend settings.
1289 *
1290 * Retrieve the settings for all frontend controls.
1291 *
1292 * @since 1.6.0
1293 * @access public
1294 *
1295 * @return array Frontend settings.
1296 */
1297 public function get_frontend_settings() {
1298 $frontend_settings = array_intersect_key( $this->get_settings_for_display(), array_flip( $this->get_frontend_settings_keys() ) );
1299
1300 foreach ( $frontend_settings as $key => $setting ) {
1301 if ( in_array( $setting, [ null, '' ], true ) ) {
1302 unset( $frontend_settings[ $key ] );
1303 }
1304 }
1305
1306 return $frontend_settings;
1307 }
1308
1309 /**
1310 * Filter controls settings.
1311 *
1312 * Receives controls, settings and a callback function to filter the settings by
1313 * and returns filtered settings.
1314 *
1315 * @since 1.5.0
1316 * @access public
1317 *
1318 * @param callable $callback The callback function.
1319 * @param array $settings Optional. Control settings. Default is an empty
1320 * array.
1321 * @param array $controls Optional. Controls list. Default is an empty
1322 * array.
1323 *
1324 * @return array Filtered settings.
1325 */
1326 public function filter_controls_settings( callable $callback, array $settings = [], array $controls = [] ) {
1327 if ( ! $settings ) {
1328 $settings = $this->get_settings();
1329 }
1330
1331 if ( ! $controls ) {
1332 $controls = $this->get_controls();
1333 }
1334
1335 return array_reduce(
1336 array_keys( $settings ), function( $filtered_settings, $setting_key ) use ( $controls, $settings, $callback ) {
1337 if ( isset( $controls[ $setting_key ] ) ) {
1338 $result = $callback( $settings[ $setting_key ], $controls[ $setting_key ] );
1339
1340 if ( null !== $result ) {
1341 $filtered_settings[ $setting_key ] = $result;
1342 }
1343 }
1344
1345 return $filtered_settings;
1346 }, []
1347 );
1348 }
1349
1350 /**
1351 * Whether the control is visible or not.
1352 *
1353 * Used to determine whether the control is visible or not.
1354 *
1355 * @since 1.4.0
1356 * @access public
1357 *
1358 * @param array $control The control.
1359 * @param array $values Optional. Condition values. Default is null.
1360 *
1361 * @return bool Whether the control is visible.
1362 */
1363 public function is_control_visible( $control, $values = null ) {
1364 if ( null === $values ) {
1365 $values = $this->get_settings();
1366 }
1367
1368 if ( ! empty( $control['conditions'] ) && ! Conditions::check( $control['conditions'], $values ) ) {
1369 return false;
1370 }
1371
1372 if ( empty( $control['condition'] ) ) {
1373 return true;
1374 }
1375
1376 foreach ( $control['condition'] as $condition_key => $condition_value ) {
1377 preg_match( '/([a-z_\-0-9]+)(?:\[([a-z_]+)])?(!?)$/i', $condition_key, $condition_key_parts );
1378
1379 $pure_condition_key = $condition_key_parts[1];
1380 $condition_sub_key = $condition_key_parts[2];
1381 $is_negative_condition = ! ! $condition_key_parts[3];
1382
1383 if ( ! isset( $values[ $pure_condition_key ] ) || null === $values[ $pure_condition_key ] ) {
1384 return false;
1385 }
1386
1387 $instance_value = $values[ $pure_condition_key ];
1388
1389 if ( ! $instance_value ) {
1390 $controls = $this->get_controls();
1391 $parent = isset( $controls[ $pure_condition_key ]['parent'] ) ? $controls[ $pure_condition_key ]['parent'] : false;
1392
1393 while ( $parent ) {
1394 $instance_value = $values[ $parent ];
1395
1396 if ( $instance_value ) {
1397 break;
1398 }
1399 $parent = isset( $controls[ $parent ]['parent'] ) ? $controls[ $parent ]['parent'] : false;
1400 }
1401 }
1402
1403 if ( $condition_sub_key && is_array( $instance_value ) ) {
1404 if ( ! isset( $instance_value[ $condition_sub_key ] ) ) {
1405 return false;
1406 }
1407
1408 $instance_value = $instance_value[ $condition_sub_key ];
1409 }
1410
1411 /**
1412 * If the $condition_value is a non empty array - check if the $condition_value contains the $instance_value,
1413 * If the $instance_value is a non empty array - check if the $instance_value contains the $condition_value
1414 * otherwise check if they are equal. ( and give the ability to check if the value is an empty array )
1415 */
1416 if ( is_array( $condition_value ) && ! empty( $condition_value ) ) {
1417 $is_contains = in_array( $instance_value, $condition_value, true );
1418 } elseif ( is_array( $instance_value ) && ! empty( $instance_value ) ) {
1419 $is_contains = in_array( $condition_value, $instance_value, true );
1420 } else {
1421 $is_contains = $instance_value === $condition_value;
1422 }
1423
1424 if ( $is_negative_condition && $is_contains || ! $is_negative_condition && ! $is_contains ) {
1425 return false;
1426 }
1427 }
1428
1429 return true;
1430 }
1431
1432 /**
1433 * Start controls section.
1434 *
1435 * Used to add a new section of controls. When you use this method, all the
1436 * registered controls from this point will be assigned to this section,
1437 * until you close the section using `end_controls_section()` method.
1438 *
1439 * This method should be used inside `register_controls()`.
1440 *
1441 * @since 1.4.0
1442 * @access public
1443 *
1444 * @param string $section_id Section ID.
1445 * @param array $args Section arguments Optional.
1446 */
1447 public function start_controls_section( $section_id, array $args = [] ) {
1448 $stack_name = $this->get_name();
1449
1450 /**
1451 * Before section start.
1452 *
1453 * Fires before Elementor section starts in the editor panel.
1454 *
1455 * @since 1.4.0
1456 *
1457 * @param Controls_Stack $this The control.
1458 * @param string $section_id Section ID.
1459 * @param array $args Section arguments.
1460 */
1461 do_action( 'elementor/element/before_section_start', $this, $section_id, $args );
1462
1463 /**
1464 * Before section start.
1465 *
1466 * Fires before Elementor section starts in the editor panel.
1467 *
1468 * The dynamic portions of the hook name, `$stack_name` and `$section_id`, refers to the stack name and section ID, respectively.
1469 *
1470 * @since 1.4.0
1471 *
1472 * @param Controls_Stack $this The control.
1473 * @param array $args Section arguments.
1474 */
1475 do_action( "elementor/element/{$stack_name}/{$section_id}/before_section_start", $this, $args );
1476
1477 $args['type'] = Controls_Manager::SECTION;
1478
1479 $this->add_control( $section_id, $args );
1480
1481 if ( null !== $this->current_section ) {
1482 wp_die( sprintf( 'Elementor: You can\'t start a section before the end of the previous section "%s".', $this->current_section['section'] ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1483 }
1484
1485 $this->current_section = $this->get_section_args( $section_id );
1486
1487 if ( $this->injection_point ) {
1488 $this->injection_point['section'] = $this->current_section;
1489 }
1490
1491 /**
1492 * After section start.
1493 *
1494 * Fires after Elementor section starts in the editor panel.
1495 *
1496 * @since 1.4.0
1497 *
1498 * @param Controls_Stack $this The control.
1499 * @param string $section_id Section ID.
1500 * @param array $args Section arguments.
1501 */
1502 do_action( 'elementor/element/after_section_start', $this, $section_id, $args );
1503
1504 /**
1505 * After section start.
1506 *
1507 * Fires after Elementor section starts in the editor panel.
1508 *
1509 * The dynamic portions of the hook name, `$stack_name` and `$section_id`, refers to the stack name and section ID, respectively.
1510 *
1511 * @since 1.4.0
1512 *
1513 * @param Controls_Stack $this The control.
1514 * @param array $args Section arguments.
1515 */
1516 do_action( "elementor/element/{$stack_name}/{$section_id}/after_section_start", $this, $args );
1517 }
1518
1519 /**
1520 * End controls section.
1521 *
1522 * Used to close an existing open controls section. When you use this method
1523 * it stops adding new controls to this section.
1524 *
1525 * This method should be used inside `register_controls()`.
1526 *
1527 * @since 1.4.0
1528 * @access public
1529 */
1530 public function end_controls_section() {
1531 $stack_name = $this->get_name();
1532
1533 // Save the current section for the action.
1534 $current_section = $this->current_section;
1535 $section_id = $current_section['section'];
1536 $args = [
1537 'tab' => $current_section['tab'],
1538 ];
1539
1540 /**
1541 * Before section end.
1542 *
1543 * Fires before Elementor section ends in the editor panel.
1544 *
1545 * @since 1.4.0
1546 *
1547 * @param Controls_Stack $this The control.
1548 * @param string $section_id Section ID.
1549 * @param array $args Section arguments.
1550 */
1551 do_action( 'elementor/element/before_section_end', $this, $section_id, $args );
1552
1553 /**
1554 * Before section end.
1555 *
1556 * Fires before Elementor section ends in the editor panel.
1557 *
1558 * The dynamic portions of the hook name, `$stack_name` and `$section_id`, refers to the stack name and section ID, respectively.
1559 *
1560 * @since 1.4.0
1561 *
1562 * @param Controls_Stack $this The control.
1563 * @param array $args Section arguments.
1564 */
1565 do_action( "elementor/element/{$stack_name}/{$section_id}/before_section_end", $this, $args );
1566
1567 $this->current_section = null;
1568
1569 /**
1570 * After section end.
1571 *
1572 * Fires after Elementor section ends in the editor panel.
1573 *
1574 * @since 1.4.0
1575 *
1576 * @param Controls_Stack $this The control.
1577 * @param string $section_id Section ID.
1578 * @param array $args Section arguments.
1579 */
1580 do_action( 'elementor/element/after_section_end', $this, $section_id, $args );
1581
1582 /**
1583 * After section end.
1584 *
1585 * Fires after Elementor section ends in the editor panel.
1586 *
1587 * The dynamic portions of the hook name, `$stack_name` and `$section_id`, refers to the stack name and section ID, respectively.
1588 *
1589 * @since 1.4.0
1590 *
1591 * @param Controls_Stack $this The control.
1592 * @param array $args Section arguments.
1593 */
1594 do_action( "elementor/element/{$stack_name}/{$section_id}/after_section_end", $this, $args );
1595 }
1596
1597 /**
1598 * Start controls tabs.
1599 *
1600 * Used to add a new set of tabs inside a section. You should use this
1601 * method before adding new individual tabs using `start_controls_tab()`.
1602 * Each tab added after this point will be assigned to this group of tabs,
1603 * until you close it using `end_controls_tabs()` method.
1604 *
1605 * This method should be used inside `register_controls()`.
1606 *
1607 * @since 1.4.0
1608 * @access public
1609 *
1610 * @param string $tabs_id Tabs ID.
1611 * @param array $args Tabs arguments.
1612 */
1613 public function start_controls_tabs( $tabs_id, array $args = [] ) {
1614 if ( null !== $this->current_tab ) {
1615 wp_die( sprintf( 'Elementor: You can\'t start tabs before the end of the previous tabs "%s".', $this->current_tab['tabs_wrapper'] ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1616 }
1617
1618 $args['type'] = Controls_Manager::TABS;
1619
1620 $this->add_control( $tabs_id, $args );
1621
1622 $this->current_tab = [
1623 'tabs_wrapper' => $tabs_id,
1624 ];
1625
1626 foreach ( [ 'condition', 'conditions' ] as $key ) {
1627 if ( ! empty( $args[ $key ] ) ) {
1628 $this->current_tab[ $key ] = $args[ $key ];
1629 }
1630 }
1631
1632 if ( $this->injection_point ) {
1633 $this->injection_point['tab'] = $this->current_tab;
1634 }
1635 }
1636
1637 /**
1638 * End controls tabs.
1639 *
1640 * Used to close an existing open controls tabs. When you use this method it
1641 * stops adding new controls to this tabs.
1642 *
1643 * This method should be used inside `register_controls()`.
1644 *
1645 * @since 1.4.0
1646 * @access public
1647 */
1648 public function end_controls_tabs() {
1649 $this->current_tab = null;
1650 }
1651
1652 /**
1653 * Start controls tab.
1654 *
1655 * Used to add a new tab inside a group of tabs. Use this method before
1656 * adding new individual tabs using `start_controls_tab()`.
1657 * Each tab added after this point will be assigned to this group of tabs,
1658 * until you close it using `end_controls_tab()` method.
1659 *
1660 * This method should be used inside `register_controls()`.
1661 *
1662 * @since 1.4.0
1663 * @access public
1664 *
1665 * @param string $tab_id Tab ID.
1666 * @param array $args Tab arguments.
1667 */
1668 public function start_controls_tab( $tab_id, $args ) {
1669 if ( ! empty( $this->current_tab['inner_tab'] ) ) {
1670 wp_die( sprintf( 'Elementor: You can\'t start a tab before the end of the previous tab "%s".', $this->current_tab['inner_tab'] ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1671 }
1672
1673 $args['type'] = Controls_Manager::TAB;
1674 $args['tabs_wrapper'] = $this->current_tab['tabs_wrapper'];
1675
1676 $this->add_control( $tab_id, $args );
1677
1678 $this->current_tab['inner_tab'] = $tab_id;
1679
1680 if ( $this->injection_point ) {
1681 $this->injection_point['tab']['inner_tab'] = $this->current_tab['inner_tab'];
1682 }
1683 }
1684
1685 /**
1686 * End controls tab.
1687 *
1688 * Used to close an existing open controls tab. When you use this method it
1689 * stops adding new controls to this tab.
1690 *
1691 * This method should be used inside `register_controls()`.
1692 *
1693 * @since 1.4.0
1694 * @access public
1695 */
1696 public function end_controls_tab() {
1697 unset( $this->current_tab['inner_tab'] );
1698 }
1699
1700 /**
1701 * Start popover.
1702 *
1703 * Used to add a new set of controls in a popover. When you use this method,
1704 * all the registered controls from this point will be assigned to this
1705 * popover, until you close the popover using `end_popover()` method.
1706 *
1707 * This method should be used inside `register_controls()`.
1708 *
1709 * @since 1.9.0
1710 * @access public
1711 */
1712 final public function start_popover() {
1713 $this->current_popover = [
1714 'initialized' => false,
1715 ];
1716 }
1717
1718 /**
1719 * End popover.
1720 *
1721 * Used to close an existing open popover. When you use this method it stops
1722 * adding new controls to this popover.
1723 *
1724 * This method should be used inside `register_controls()`.
1725 *
1726 * @since 1.9.0
1727 * @access public
1728 */
1729 final public function end_popover() {
1730 $this->current_popover = null;
1731
1732 $last_control_key = $this->get_control_key( $this->get_pointer_index() - 1 );
1733
1734 $args = [
1735 'popover' => [
1736 'end' => true,
1737 ],
1738 ];
1739
1740 $options = [
1741 'recursive' => true,
1742 ];
1743
1744 $this->update_control( $last_control_key, $args, $options );
1745 }
1746
1747 /**
1748 * Add render attribute.
1749 *
1750 * Used to add attributes to a specific HTML element.
1751 *
1752 * The HTML tag is represented by the element parameter, then you need to
1753 * define the attribute key and the attribute key. The final result will be:
1754 * `<element attribute_key="attribute_value">`.
1755 *
1756 * Example usage:
1757 *
1758 * `$this->add_render_attribute( 'wrapper', 'class', 'custom-widget-wrapper-class' );`
1759 * `$this->add_render_attribute( 'widget', 'id', 'custom-widget-id' );`
1760 * `$this->add_render_attribute( 'button', [ 'class' => 'custom-button-class', 'id' => 'custom-button-id' ] );`
1761 *
1762 * @since 1.0.0
1763 * @access public
1764 *
1765 * @param array|string $element The HTML element.
1766 * @param array|string $key Optional. Attribute key. Default is null.
1767 * @param array|string $value Optional. Attribute value. Default is null.
1768 * @param bool $overwrite Optional. Whether to overwrite existing
1769 * attribute. Default is false, not to overwrite.
1770 *
1771 * @return self Current instance of the element.
1772 */
1773 public function add_render_attribute( $element, $key = null, $value = null, $overwrite = false ) {
1774 if ( is_array( $element ) ) {
1775 foreach ( $element as $element_key => $attributes ) {
1776 $this->add_render_attribute( $element_key, $attributes, null, $overwrite );
1777 }
1778
1779 return $this;
1780 }
1781
1782 if ( is_array( $key ) ) {
1783 foreach ( $key as $attribute_key => $attributes ) {
1784 $this->add_render_attribute( $element, $attribute_key, $attributes, $overwrite );
1785 }
1786
1787 return $this;
1788 }
1789
1790 if ( empty( $this->render_attributes[ $element ][ $key ] ) ) {
1791 $this->render_attributes[ $element ][ $key ] = [];
1792 }
1793
1794 settype( $value, 'array' );
1795
1796 if ( $overwrite ) {
1797 $this->render_attributes[ $element ][ $key ] = $value;
1798 } else {
1799 $this->render_attributes[ $element ][ $key ] = array_merge( $this->render_attributes[ $element ][ $key ], $value );
1800 }
1801
1802 return $this;
1803 }
1804
1805 /**
1806 * Get Render Attributes
1807 *
1808 * Used to retrieve render attribute.
1809 *
1810 * The returned array is either all elements and their attributes if no `$element` is specified, an array of all
1811 * attributes of a specific element or a specific attribute properties if `$key` is specified.
1812 *
1813 * Returns null if one of the requested parameters isn't set.
1814 *
1815 * @since 2.2.6
1816 * @access public
1817 * @param string $element
1818 * @param string $key
1819 *
1820 * @return array
1821 */
1822 public function get_render_attributes( $element = '', $key = '' ) {
1823 $attributes = $this->render_attributes;
1824
1825 if ( $element ) {
1826 if ( ! isset( $attributes[ $element ] ) ) {
1827 return null;
1828 }
1829
1830 $attributes = $attributes[ $element ];
1831
1832 if ( $key ) {
1833 if ( ! isset( $attributes[ $key ] ) ) {
1834 return null;
1835 }
1836
1837 $attributes = $attributes[ $key ];
1838 }
1839 }
1840
1841 return $attributes;
1842 }
1843
1844 /**
1845 * Set render attribute.
1846 *
1847 * Used to set the value of the HTML element render attribute or to update
1848 * an existing render attribute.
1849 *
1850 * @since 1.0.0
1851 * @access public
1852 *
1853 * @param array|string $element The HTML element.
1854 * @param array|string $key Optional. Attribute key. Default is null.
1855 * @param array|string $value Optional. Attribute value. Default is null.
1856 *
1857 * @return self Current instance of the element.
1858 */
1859 public function set_render_attribute( $element, $key = null, $value = null ) {
1860 return $this->add_render_attribute( $element, $key, $value, true );
1861 }
1862
1863 /**
1864 * Remove render attribute.
1865 *
1866 * Used to remove an element (with its keys and their values), key (with its values),
1867 * or value/s from an HTML element's render attribute.
1868 *
1869 * @since 2.7.0
1870 * @access public
1871 *
1872 * @param string $element The HTML element.
1873 * @param string $key Optional. Attribute key. Default is null.
1874 * @param array|string $values Optional. Attribute value/s. Default is null.
1875 */
1876 public function remove_render_attribute( $element, $key = null, $values = null ) {
1877 if ( $key && ! isset( $this->render_attributes[ $element ][ $key ] ) ) {
1878 return;
1879 }
1880
1881 if ( $values ) {
1882 $values = (array) $values;
1883
1884 $this->render_attributes[ $element ][ $key ] = array_diff( $this->render_attributes[ $element ][ $key ], $values );
1885
1886 return;
1887 }
1888
1889 if ( $key ) {
1890 unset( $this->render_attributes[ $element ][ $key ] );
1891
1892 return;
1893 }
1894
1895 if ( isset( $this->render_attributes[ $element ] ) ) {
1896 unset( $this->render_attributes[ $element ] );
1897 }
1898 }
1899
1900 /**
1901 * Get render attribute string.
1902 *
1903 * Used to retrieve the value of the render attribute.
1904 *
1905 * @since 1.0.0
1906 * @access public
1907 *
1908 * @param string $element The element.
1909 *
1910 * @return string Render attribute string, or an empty string if the attribute
1911 * is empty or not exist.
1912 */
1913 public function get_render_attribute_string( $element ) {
1914 if ( empty( $this->render_attributes[ $element ] ) ) {
1915 return '';
1916 }
1917
1918 return Utils::render_html_attributes( $this->render_attributes[ $element ] );
1919 }
1920
1921 /**
1922 * Print render attribute string.
1923 *
1924 * Used to output the rendered attribute.
1925 *
1926 * @since 2.0.0
1927 * @access public
1928 *
1929 * @param array|string $element The element.
1930 */
1931 public function print_render_attribute_string( $element ) {
1932 echo $this->get_render_attribute_string( $element ); // XSS ok.
1933 }
1934
1935 /**
1936 * Print element template.
1937 *
1938 * Used to generate the element template on the editor.
1939 *
1940 * @since 2.0.0
1941 * @access public
1942 */
1943 public function print_template() {
1944 ob_start();
1945
1946 // TODO: This is for backwards compatibility starting from 2.9.0
1947 // This `if` statement should be removed when the method is removed
1948 if ( $this->has_own_method( '_content_template', self::class ) ) {
1949 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( '_content_template', '2.9.0', __CLASS__ . '::content_template()' );
1950
1951 $this->_content_template();
1952 } else {
1953 $this->content_template();
1954 }
1955
1956 $template_content = ob_get_clean();
1957
1958 $element_type = $this->get_type();
1959
1960 /**
1961 * Template content.
1962 *
1963 * Filters the controls stack template content before it's printed in the editor.
1964 *
1965 * The dynamic portion of the hook name, `$element_type`, refers to the element type.
1966 *
1967 * @since 1.0.0
1968 *
1969 * @param string $content_template The controls stack template in the editor.
1970 * @param Controls_Stack $this The controls stack.
1971 */
1972 $template_content = apply_filters( "elementor/{$element_type}/print_template", $template_content, $this );
1973
1974 if ( empty( $template_content ) ) {
1975 return;
1976 }
1977 ?>
1978 <script type="text/html" id="tmpl-elementor-<?php echo esc_attr( $this->get_name() ); ?>-content">
1979 <?php $this->print_template_content( $template_content ); ?>
1980 </script>
1981 <?php
1982 }
1983
1984 /**
1985 *
1986 * @since 3.6.0
1987 * @access public
1988 */
1989 public static function on_import_replace_dynamic_content( $config, $map_old_new_post_ids ) {
1990 return $config;
1991 }
1992
1993 /**
1994 * Start injection.
1995 *
1996 * Used to inject controls and sections to a specific position in the stack.
1997 *
1998 * When you use this method, all the registered controls and sections will
1999 * be injected to a specific position in the stack, until you stop the
2000 * injection using `end_injection()` method.
2001 *
2002 * @since 1.7.1
2003 * @access public
2004 *
2005 * @param array $position {
2006 * The position where to start the injection.
2007 *
2008 * @type string $type Injection type, either `control` or `section`.
2009 * Default is `control`.
2010 * @type string $at Where to inject. If `$type` is `control` accepts
2011 * `before` and `after`. If `$type` is `section`
2012 * accepts `start` and `end`. Default values based on
2013 * the `type`.
2014 * @type string $of Control/Section ID.
2015 * }
2016 */
2017 final public function start_injection( array $position ) {
2018 if ( $this->injection_point ) {
2019 wp_die( 'A controls injection is already opened. Please close current injection before starting a new one (use `end_injection`).' );
2020 }
2021
2022 $this->injection_point = $this->get_position_info( $position );
2023 }
2024
2025 /**
2026 * End injection.
2027 *
2028 * Used to close an existing opened injection point.
2029 *
2030 * When you use this method it stops adding new controls and sections to
2031 * this point and continue to add controls to the regular position in the
2032 * stack.
2033 *
2034 * @since 1.7.1
2035 * @access public
2036 */
2037 final public function end_injection() {
2038 $this->injection_point = null;
2039 }
2040
2041 /**
2042 * Get injection point.
2043 *
2044 * Retrieve the injection point in the stack where new controls and sections
2045 * will be inserted.
2046 *
2047 * @since 1.9.2
2048 * @access public
2049 *
2050 * @return array|null An array when an injection point is defined, null
2051 * otherwise.
2052 */
2053 final public function get_injection_point() {
2054 return $this->injection_point;
2055 }
2056
2057 /**
2058 * Register controls.
2059 *
2060 * Used to add new controls to any element type. For example, external
2061 * developers use this method to register controls in a widget.
2062 *
2063 * Should be inherited and register new controls using `add_control()`,
2064 * `add_responsive_control()` and `add_group_control()`, inside control
2065 * wrappers like `start_controls_section()`, `start_controls_tabs()` and
2066 * `start_controls_tab()`.
2067 *
2068 * @since 1.4.0
2069 * @access protected
2070 * @deprecated 3.1.0 Use `Controls_Stack::register_controls()` instead
2071 */
2072 protected function _register_controls() {
2073 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.1.0', __CLASS__ . '::register_controls()' );
2074
2075 $this->register_controls();
2076 }
2077
2078 /**
2079 * Register controls.
2080 *
2081 * Used to add new controls to any element type. For example, external
2082 * developers use this method to register controls in a widget.
2083 *
2084 * Should be inherited and register new controls using `add_control()`,
2085 * `add_responsive_control()` and `add_group_control()`, inside control
2086 * wrappers like `start_controls_section()`, `start_controls_tabs()` and
2087 * `start_controls_tab()`.
2088 *
2089 * @since 3.1.0
2090 * @access protected
2091 */
2092 protected function register_controls() {}
2093
2094 /**
2095 * Get default data.
2096 *
2097 * Retrieve the default data. Used to reset the data on initialization.
2098 *
2099 * @since 1.4.0
2100 * @access protected
2101 *
2102 * @return array Default data.
2103 */
2104 protected function get_default_data() {
2105 return [
2106 'id' => 0,
2107 'settings' => [],
2108 ];
2109 }
2110
2111 /**
2112 * @since 2.3.0
2113 * @access protected
2114 */
2115 protected function get_init_settings() {
2116 $settings = $this->get_data( 'settings' );
2117
2118 foreach ( $this->get_controls() as $control ) {
2119 $control_obj = Plugin::$instance->controls_manager->get_control( $control['type'] );
2120
2121 if ( ! $control_obj instanceof Base_Data_Control ) {
2122 continue;
2123 }
2124
2125 $control = array_merge_recursive( $control_obj->get_settings(), $control );
2126
2127 $settings[ $control['name'] ] = $control_obj->get_value( $control, $settings );
2128 }
2129
2130 return $settings;
2131 }
2132
2133 /**
2134 * Get initial config.
2135 *
2136 * Retrieve the current element initial configuration - controls list and
2137 * the tabs assigned to the control.
2138 *
2139 * @since 2.9.0
2140 * @access protected
2141 *
2142 * @return array The initial config.
2143 */
2144 protected function get_initial_config() {
2145 return [
2146 'controls' => $this->get_controls(),
2147 ];
2148 }
2149
2150 /**
2151 * Get initial config.
2152 *
2153 * Retrieve the current element initial configuration - controls list and
2154 * the tabs assigned to the control.
2155 *
2156 * @since 1.4.0
2157 * @deprecated 2.9.0 use `get_initial_config()` instead
2158 * @access protected
2159 *
2160 * @return array The initial config.
2161 */
2162 protected function _get_initial_config() {
2163 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '2.9.0', __CLASS__ . '::get_initial_config()' );
2164
2165 return $this->get_initial_config();
2166 }
2167
2168 /**
2169 * Get section arguments.
2170 *
2171 * Retrieve the section arguments based on section ID.
2172 *
2173 * @since 1.4.0
2174 * @access protected
2175 *
2176 * @param string $section_id Section ID.
2177 *
2178 * @return array Section arguments.
2179 */
2180 protected function get_section_args( $section_id ) {
2181 $section_control = $this->get_controls( $section_id );
2182
2183 $section_args_keys = [ 'tab', 'condition' ];
2184
2185 $args = array_intersect_key( $section_control, array_flip( $section_args_keys ) );
2186
2187 $args['section'] = $section_id;
2188
2189 return $args;
2190 }
2191
2192 /**
2193 * Render element.
2194 *
2195 * Generates the final HTML on the frontend.
2196 *
2197 * @since 2.0.0
2198 * @access protected
2199 */
2200 protected function render() {}
2201
2202 /**
2203 * Render element in static mode.
2204 *
2205 * If not inherent will call the base render.
2206 */
2207 protected function render_static() {
2208 $this->render();
2209 }
2210
2211 /**
2212 * Determine the render logic.
2213 */
2214 protected function render_by_mode() {
2215 if ( Plugin::$instance->frontend->is_static_render_mode() ) {
2216 $this->render_static();
2217
2218 return;
2219 }
2220
2221 $this->render();
2222 }
2223
2224 /**
2225 * Print content template.
2226 *
2227 * Used to generate the content template on the editor, using a
2228 * Backbone JavaScript template.
2229 *
2230 * @access protected
2231 * @since 2.0.0
2232 *
2233 * @param string $template_content Template content.
2234 */
2235 protected function print_template_content( $template_content ) {
2236 echo $template_content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2237 }
2238
2239 /**
2240 * Render element output in the editor.
2241 *
2242 * Used to generate the live preview, using a Backbone JavaScript template.
2243 *
2244 * @since 2.9.0
2245 * @access protected
2246 */
2247 protected function content_template() {}
2248
2249 /**
2250 * Render element output in the editor.
2251 *
2252 * Used to generate the live preview, using a Backbone JavaScript template.
2253 *
2254 * @since 2.0.0
2255 * @deprecated 2.9.0 use `content_template()` instead
2256 * @access protected
2257 */
2258 protected function _content_template() {
2259 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '2.9.0', __CLASS__ . '::content_template()' );
2260
2261 $this->content_template();
2262 }
2263
2264 /**
2265 * Initialize controls.
2266 *
2267 * Register the all controls added by `register_controls()`.
2268 *
2269 * @since 2.0.0
2270 * @access protected
2271 */
2272 protected function init_controls() {
2273 Plugin::$instance->controls_manager->open_stack( $this );
2274
2275 // TODO: This is for backwards compatibility starting from 2.9.0
2276 // This `if` statement should be removed when the method is removed
2277 if ( $this->has_own_method( '_register_controls', self::class ) ) {
2278 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( '_register_controls', '3.1.0', __CLASS__ . '::register_controls()' );
2279
2280 $this->_register_controls();
2281 } else {
2282 $this->register_controls();
2283 }
2284 }
2285
2286 protected function handle_control_position( array $args, $control_id, $overwrite ) {
2287 if ( isset( $args['type'] ) && in_array( $args['type'], [ Controls_Manager::SECTION, Controls_Manager::WP_WIDGET ], true ) ) {
2288 return $args;
2289 }
2290
2291 $target_section_args = $this->current_section;
2292
2293 $target_tab = $this->current_tab;
2294
2295 if ( $this->injection_point ) {
2296 $target_section_args = $this->injection_point['section'];
2297
2298 if ( ! empty( $this->injection_point['tab'] ) ) {
2299 $target_tab = $this->injection_point['tab'];
2300 }
2301 }
2302
2303 if ( null !== $target_section_args ) {
2304 if ( ! empty( $args['section'] ) || ! empty( $args['tab'] ) ) {
2305 _doing_it_wrong( sprintf( '%s::%s', get_called_class(), __FUNCTION__ ), sprintf( 'Cannot redeclare control with `tab` or `section` args inside section "%s".', $control_id ), '1.0.0' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2306 }
2307
2308 $args = array_replace_recursive( $target_section_args, $args );
2309
2310 if ( null !== $target_tab ) {
2311 $args = array_replace_recursive( $target_tab, $args );
2312 }
2313 } elseif ( empty( $args['section'] ) && ( ! $overwrite || is_wp_error( Plugin::$instance->controls_manager->get_control_from_stack( $this->get_unique_name(), $control_id ) ) ) ) {
2314 wp_die( sprintf( '%s::%s: Cannot add a control outside of a section (use `start_controls_section`).', get_called_class(), __FUNCTION__ ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2315 }
2316
2317 return $args;
2318 }
2319
2320 /**
2321 * Initialize the class.
2322 *
2323 * Set the raw data, the ID and the parsed settings.
2324 *
2325 * @since 2.9.0
2326 * @access protected
2327 *
2328 * @param array $data Initial data.
2329 */
2330 protected function init( $data ) {
2331 $this->data = array_merge( $this->get_default_data(), $data );
2332
2333 $this->id = $data['id'];
2334 }
2335
2336 /**
2337 * Initialize the class.
2338 *
2339 * Set the raw data, the ID and the parsed settings.
2340 *
2341 * @since 1.4.0
2342 * @deprecated 2.9.0 use `init()` instead
2343 * @access protected
2344 *
2345 * @param array $data Initial data.
2346 */
2347 protected function _init( $data ) {
2348 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '2.9.0', __CLASS__ . '::init()' );
2349
2350 $this->init( $data );
2351 }
2352
2353 /**
2354 * Sanitize initial data.
2355 *
2356 * Performs settings cleaning and sanitization.
2357 *
2358 * @since 2.1.5
2359 * @access private
2360 *
2361 * @param array $settings Settings to sanitize.
2362 * @param array $controls Optional. An array of controls. Default is an
2363 * empty array.
2364 *
2365 * @return array Sanitized settings.
2366 */
2367 private function sanitize_settings( array $settings, array $controls = [] ) {
2368 if ( ! $controls ) {
2369 $controls = $this->get_controls();
2370 }
2371
2372 foreach ( $controls as $control ) {
2373 $control_obj = Plugin::$instance->controls_manager->get_control( $control['type'] );
2374
2375 if ( $control_obj instanceof Control_Repeater ) {
2376 if ( empty( $settings[ $control['name'] ] ) ) {
2377 continue;
2378 }
2379
2380 foreach ( $settings[ $control['name'] ] as $index => $repeater_row_data ) {
2381 $sanitized_row_data = $this->sanitize_settings( $repeater_row_data, $control['fields'] );
2382
2383 $settings[ $control['name'] ][ $index ] = $sanitized_row_data;
2384 }
2385
2386 continue;
2387 }
2388
2389 $is_dynamic = isset( $settings[ Manager::DYNAMIC_SETTING_KEY ][ $control['name'] ] );
2390
2391 if ( ! $is_dynamic ) {
2392 continue;
2393 }
2394
2395 $value_to_check = $settings[ Manager::DYNAMIC_SETTING_KEY ][ $control['name'] ];
2396
2397 $tag_text_data = Plugin::$instance->dynamic_tags->tag_text_to_tag_data( $value_to_check );
2398
2399 if ( ! Plugin::$instance->dynamic_tags->get_tag_info( $tag_text_data['name'] ) ) {
2400 unset( $settings[ Manager::DYNAMIC_SETTING_KEY ][ $control['name'] ] );
2401 }
2402 }
2403
2404 return $settings;
2405 }
2406
2407 /**
2408 * Controls stack constructor.
2409 *
2410 * Initializing the control stack class using `$data`. The `$data` is required
2411 * for a normal instance. It is optional only for internal `type instance`.
2412 *
2413 * @since 1.4.0
2414 * @access public
2415 *
2416 * @param array $data Optional. Control stack data. Default is an empty array.
2417 */
2418 public function __construct( array $data = [] ) {
2419 if ( $data ) {
2420 // TODO: This is for backwards compatibility starting from 2.9.0
2421 // This if statement should be removed when the method is hard-deprecated
2422 if ( $this->has_own_method( '_init', self::class ) ) {
2423 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( '_init', '2.9.0', __CLASS__ . '::init()' );
2424
2425 $this->_init( $data );
2426 } else {
2427 $this->init( $data );
2428 }
2429 }
2430 }
2431 }
2432