PluginProbe
Elementor Website Builder – more than just a page builder / 3.7.8
Elementor Website Builder – more than just a page builder v3.7.8
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.7.8, at includes/base/controls-stack.php

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