PluginProbe
Elementor Website Builder – more than just a page builder / 3.17.2
Elementor Website Builder – more than just a page builder v3.17.2
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
← All changes | includes/base/controls-stack.php +35 -146 4.1.03.17.2 View file →
@@ -3,10 +3,8 @@
3 3
4 4 use Elementor\Core\Base\Base_Object;
5 5 use Elementor\Core\DynamicTags\Manager;
6 6 use Elementor\Core\Breakpoints\Manager as Breakpoints_Manager;
7 -use Elementor\Core\Frontend\Performance;
8 -use Elementor\Utils;
9 7
10 8 if ( ! defined( 'ABSPATH' ) ) {
11 9 exit; // Exit if accessed directly.
12 10 }
@@ -226,9 +224,9 @@
226 224 public function get_id_int() {
227 225 /** We ignore possible notices, in order to support elements created prior to v1.8.0 and might include
228 226 * non-base 16 characters as part of their ID.
229 227 */
230 - return @hexdec( (string) $this->id );
228 + return @hexdec( $this->id );
231 229 }
232 230
233 231 /**
234 232 * Get widget number.
@@ -311,26 +309,9 @@
311 309 *
312 310 * @return mixed Controls list.
313 311 */
314 312 public function get_controls( $control_id = null ) {
315 - $stack = $this->get_stack();
316 -
317 - if ( null !== $control_id ) {
318 - $control_data = self::get_items( $stack['controls'], $control_id );
319 - if ( null === $control_data && ! empty( $stack['style_controls'] ) ) {
320 - $control_data = self::get_items( $stack['style_controls'], $control_id );
321 - }
322 -
323 - return $control_data;
324 - }
325 -
326 - $controls = $stack['controls'];
327 -
328 - if ( Performance::is_use_style_controls() && ! empty( $stack['style_controls'] ) ) {
329 - $controls += $stack['style_controls'];
330 - }
331 -
332 - return self::get_items( $controls, $control_id );
313 + return self::get_items( $this->get_stack()['controls'], $control_id );
333 314 }
334 315
335 316 /**
336 317 * Get active controls.
@@ -349,9 +330,9 @@
349 330 * @param array $settings Optional. Controls settings. Default is null.
350 331 *
351 332 * @return array Active controls.
352 333 */
353 - public function get_active_controls( ?array $controls = null, ?array $settings = null ) {
334 + public function get_active_controls( array $controls = null, array $settings = null ) {
354 335 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.0.0' );
355 336
356 337 if ( ! $controls ) {
357 338 $controls = $this->get_controls();
@@ -449,50 +430,8 @@
449 430 $this->current_popover['initialized'] = true;
450 431 }
451 432 }
452 433
453 - if ( Performance::should_optimize_controls() ) {
454 - $ui_controls = [
455 - Controls_Manager::RAW_HTML,
456 - Controls_Manager::DIVIDER,
457 - Controls_Manager::HEADING,
458 - Controls_Manager::BUTTON,
459 - Controls_Manager::ALERT,
460 - Controls_Manager::NOTICE,
461 - Controls_Manager::DEPRECATED_NOTICE,
462 - ];
463 -
464 - if ( ! empty( $args['type'] ) && ! empty( $args['section'] ) && in_array( $args['type'], $ui_controls ) ) {
465 - $args = [
466 - 'type' => $args['type'],
467 - 'section' => $args['section'],
468 - ];
469 - }
470 -
471 - unset(
472 - $args['label_block'],
473 - $args['label'],
474 - $args['title'],
475 - $args['tab'],
476 - $args['options'],
477 - $args['placeholder'],
478 - $args['separator'],
479 - $args['size_units'],
480 - $args['range'],
481 - $args['toggle'],
482 - $args['ai'],
483 - $args['classes'],
484 - $args['style_transfer'],
485 - $args['show_label'],
486 - $args['description'],
487 - $args['label_on'],
488 - $args['label_off'],
489 - $args['labels'],
490 - $args['handles'],
491 - $args['editor_available'],
492 - );
493 - }
494 -
495 434 return Plugin::$instance->controls_manager->add_control_to_stack( $this, $id, $args, $options );
496 435 }
497 436
498 437 /**
@@ -612,10 +551,10 @@
612 551
613 552 $position = array_merge( $default_position, $position );
614 553
615 554 if (
616 - ( 'control' === $position['type'] && in_array( $position['at'], [ 'start', 'end' ], true ) ) ||
617 - ( 'section' === $position['type'] && in_array( $position['at'], [ 'before', 'after' ], true ) )
555 + 'control' === $position['type'] && in_array( $position['at'], [ 'start', 'end' ], true ) ||
556 + 'section' === $position['type'] && in_array( $position['at'], [ 'before', 'after' ], true )
618 557 ) {
619 558 _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
620 559
621 560 return false;
@@ -637,13 +576,13 @@
637 576
638 577 $controls_keys = array_keys( $registered_controls );
639 578
640 579 while ( Controls_Manager::SECTION !== $registered_controls[ $controls_keys[ $target_section_index ] ]['type'] ) {
641 - --$target_section_index;
580 + $target_section_index--;
642 581 }
643 582
644 583 if ( 'section' === $position['type'] ) {
645 - ++$target_control_index;
584 + $target_control_index++;
646 585
647 586 if ( 'end' === $position['at'] ) {
648 587 while ( Controls_Manager::SECTION !== $registered_controls[ $controls_keys[ $target_control_index ] ]['type'] ) {
649 588 if ( ++$target_control_index >= count( $registered_controls ) ) {
@@ -655,9 +594,9 @@
655 594
656 595 $target_control = $registered_controls[ $controls_keys[ $target_control_index ] ];
657 596
658 597 if ( 'after' === $position['at'] ) {
659 - ++$target_control_index;
598 + $target_control_index++;
660 599 }
661 600
662 601 $section_id = $registered_controls[ $controls_keys[ $target_section_index ] ]['name'];
663 602
@@ -737,9 +676,9 @@
737 676
738 677 $controls_keys = array_keys( $registered_controls );
739 678
740 679 while ( true ) {
741 - ++$section_index;
680 + $section_index++;
742 681
743 682 if ( ! isset( $controls_keys[ $section_index ] ) ) {
744 683 break;
745 684 }
@@ -750,9 +689,9 @@
750 689 break;
751 690 }
752 691
753 692 $section_controls[ $control_key ] = $registered_controls[ $control_key ];
754 - }
693 + };
755 694
756 695 return $section_controls;
757 696 }
758 697
@@ -796,9 +735,9 @@
796 735 * @param array $settings Optional. Controls settings. Default is null.
797 736 *
798 737 * @return array Style controls.
799 738 */
800 - final public function get_style_controls( ?array $controls = null, ?array $settings = null ) {
739 + final public function get_style_controls( array $controls = null, array $settings = null ) {
801 740 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.0.0' );
802 741
803 742 $controls = $this->get_active_controls( $controls, $settings );
804 743
@@ -931,9 +870,9 @@
931 870 $control_args = $args;
932 871
933 872 // Set parent using the name from previous iteration.
934 873 if ( isset( $control_name ) ) {
935 - // If $control_name end with _widescreen use desktop name instead.
874 + // If $control_name end with _widescreen use desktop name instead
936 875 $control_args['parent'] = '_widescreen' === substr( $control_name, -strlen( '_widescreen' ) ) ? $id : $control_name;
937 876 } else {
938 877 $control_args['parent'] = null;
939 878 }
@@ -1060,10 +999,10 @@
1060 999 * @return array|null The config.
1061 1000 */
1062 1001 final public function get_config() {
1063 1002 if ( null === $this->config ) {
1064 - // TODO: This is for backwards compatibility starting from 2.9.0.
1065 - // This if statement should be removed when the method is hard-deprecated.
1003 + // TODO: This is for backwards compatibility starting from 2.9.0
1004 + // This if statement should be removed when the method is hard-deprecated
1066 1005 if ( $this->has_own_method( '_get_initial_config', self::class ) ) {
1067 1006 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( '_get_initial_config', '2.9.0', __CLASS__ . '::get_initial_config()' );
1068 1007
1069 1008 $this->config = $this->_get_initial_config();
@@ -1087,10 +1026,8 @@
1087 1026 * Set a config property.
1088 1027 *
1089 1028 * Set a specific property of the config list for this controls-stack.
1090 1029 *
1091 - * @param string $key
1092 - * @param string $value
1093 1030 * @since 3.5.0
1094 1031 * @access public
1095 1032 */
1096 1033 public function set_config( $key, $value ) {
@@ -1166,11 +1103,8 @@
1166 1103 return self::get_items( $this->data, $item );
1167 1104 }
1168 1105
1169 1106 /**
1170 - * @param null $setting
1171 - * @param null $settings
1172 - * @return array|mixed|null
1173 1107 * @since 2.0.14
1174 1108 * @access public
1175 1109 */
1176 1110 public function get_parsed_dynamic_settings( $setting = null, $settings = null ) {
@@ -1189,16 +1123,16 @@
1189 1123 * Get active settings.
1190 1124 *
1191 1125 * Retrieve the settings from all the active controls.
1192 1126 *
1193 - * @param array|null $settings Optional. Controls settings. Default is null.
1194 - * @param array|null $controls Optional. An array of controls. Default is null.
1195 - *
1196 - * @return array Active settings.
1127 + * @since 1.4.0
1197 1128 * @since 2.1.0 Added the `controls` and the `settings` parameters.
1198 1129 * @access public
1199 1130 *
1200 - * @since 1.4.0
1131 + * @param array $controls Optional. An array of controls. Default is null.
1132 + * @param array $settings Optional. Controls settings. Default is null.
1133 + *
1134 + * @return array Active settings.
1201 1135 */
1202 1136 public function get_active_settings( $settings = null, $controls = null ) {
1203 1137 $is_first_request = ! $settings && ! $this->active_settings;
1204 1138
@@ -1427,14 +1361,15 @@
1427 1361 * Whether the control is visible or not.
1428 1362 *
1429 1363 * Used to determine whether the control is visible or not.
1430 1364 *
1365 + * @since 1.4.0
1366 + * @access public
1367 + *
1431 1368 * @param array $control The control.
1432 - * @param null $values Optional. Condition values. Default is null.
1433 - * @param null $controls
1369 + * @param array $values Optional. Condition values. Default is null.
1370 + *
1434 1371 * @return bool Whether the control is visible.
1435 - * @since 1.4.0
1436 - * @access public
1437 1372 */
1438 1373 public function is_control_visible( $control, $values = null, $controls = null ) {
1439 1374 if ( null === $values ) {
1440 1375 $values = $this->get_settings();
@@ -1456,9 +1391,9 @@
1456 1391 preg_match( '/([a-z_\-0-9]+)(?:\[([a-z_]+)])?(!?)$/i', $condition_key, $condition_key_parts );
1457 1392
1458 1393 $pure_condition_key = $condition_key_parts[1];
1459 1394 $condition_sub_key = $condition_key_parts[2];
1460 - $is_negative_condition = (bool) $condition_key_parts[3];
1395 + $is_negative_condition = ! ! $condition_key_parts[3];
1461 1396
1462 1397 if ( ! isset( $values[ $pure_condition_key ] ) || null === $values[ $pure_condition_key ] ) {
1463 1398 return false;
1464 1399 }
@@ -1521,12 +1456,9 @@
1521 1456 } else {
1522 1457 $is_contains = $instance_value === $condition_value;
1523 1458 }
1524 1459
1525 - if (
1526 - ( $is_negative_condition && $is_contains ) ||
1527 - ( ! $is_negative_condition && ! $is_contains )
1528 - ) {
1460 + if ( $is_negative_condition && $is_contains || ! $is_negative_condition && ! $is_contains ) {
1529 1461 return false;
1530 1462 }
1531 1463 }
1532 1464
@@ -1577,12 +1509,8 @@
1577 1509 * @param array $args Section arguments.
1578 1510 */
1579 1511 do_action( "elementor/element/{$stack_name}/{$section_id}/before_section_start", $this, $args );
1580 1512
1581 - if ( $this->should_manually_trigger_common_action( $stack_name ) ) {
1582 - do_action( "elementor/element/common/{$section_id}/before_section_start", $this, $args );
1583 - }
1584 -
1585 1513 $args['type'] = Controls_Manager::SECTION;
1586 1514
1587 1515 $this->add_control( $section_id, $args );
1588 1516
@@ -1621,12 +1549,8 @@
1621 1549 * @param Controls_Stack $this The control.
1622 1550 * @param array $args Section arguments.
1623 1551 */
1624 1552 do_action( "elementor/element/{$stack_name}/{$section_id}/after_section_start", $this, $args );
1625 -
1626 - if ( $this->should_manually_trigger_common_action( $stack_name ) ) {
1627 - do_action( "elementor/element/common/{$section_id}/after_section_start", $this, $args );
1628 - }
1629 1553 }
1630 1554
1631 1555 /**
1632 1556 * End controls section.
@@ -1675,12 +1599,8 @@
1675 1599 * @param array $args Section arguments.
1676 1600 */
1677 1601 do_action( "elementor/element/{$stack_name}/{$section_id}/before_section_end", $this, $args );
1678 1602
1679 - if ( $this->should_manually_trigger_common_action( $stack_name ) ) {
1680 - do_action( "elementor/element/common/{$section_id}/before_section_end", $this, $args );
1681 - }
1682 -
1683 1603 $this->current_section = null;
1684 1604
1685 1605 /**
1686 1606 * After section end.
@@ -1707,40 +1627,11 @@
1707 1627 * @param Controls_Stack $this The control.
1708 1628 * @param array $args Section arguments.
1709 1629 */
1710 1630 do_action( "elementor/element/{$stack_name}/{$section_id}/after_section_end", $this, $args );
1711 -
1712 - if ( $this->should_manually_trigger_common_action( $stack_name ) ) {
1713 - do_action( "elementor/element/common/{$section_id}/after_section_end", $this, $args );
1714 - }
1715 1631 }
1716 1632
1717 1633 /**
1718 - * Should manually trigger common action.
1719 - *
1720 - * With the Optimized Markup experiment, the Advanced Tab has been split to maintain backward compatibility:
1721 - * - 'common' refers to the existing Advanced Tab.
1722 - * - 'common-optimized' refers to the new Advanced Tab for optimized widgets.
1723 - *
1724 - * Third-party developers may have used hooks like 'elementor/element/common/_section_background/before_section_end'
1725 - * to add controls to the Advanced Tab. However, this hook will now only work on widgets that are not optimized.
1726 - *
1727 - * This method checks whether the 'elementor/element/common/...' hooks should be manually executed
1728 - * to prevent third parties from needing to add equivalent hooks for 'elementor/element/common-optimized/...'.
1729 - *
1730 - * @todo Remove this method and the manual execution of 'common' hooks when the feature is merged.
1731 - *
1732 - * @access private
1733 - *
1734 - * @param string $stack_name Stack name.
1735 - *
1736 - * @return bool
1737 - */
1738 - private function should_manually_trigger_common_action( $stack_name ): bool {
1739 - return 'common-optimized' === $stack_name && Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' );
1740 - }
1741 -
1742 - /**
1743 1634 * Start controls tabs.
1744 1635 *
1745 1636 * Used to add a new set of tabs inside a section. You should use this
1746 1637 * method before adding new individual tabs using `start_controls_tab()`.
@@ -2013,10 +1904,10 @@
2013 1904 *
2014 1905 * @since 2.7.0
2015 1906 * @access public
2016 1907 *
2017 - * @param string $element The HTML element.
2018 - * @param string $key Optional. Attribute key. Default is null.
1908 + * @param string $element The HTML element.
1909 + * @param string $key Optional. Attribute key. Default is null.
2019 1910 * @param array|string $values Optional. Attribute value/s. Default is null.
2020 1911 */
2021 1912 public function remove_render_attribute( $element, $key = null, $values = null ) {
2022 1913 if ( $key && ! isset( $this->render_attributes[ $element ][ $key ] ) ) {
@@ -2073,9 +1964,9 @@
2073 1964 *
2074 1965 * @param array|string $element The element.
2075 1966 */
2076 1967 public function print_render_attribute_string( $element ) {
2077 - Utils::print_unescaped_internal_string( $this->get_render_attribute_string( $element ) );
1968 + echo $this->get_render_attribute_string( $element ); // XSS ok.
2078 1969 }
2079 1970
2080 1971 /**
2081 1972 * Print element template.
@@ -2088,9 +1979,9 @@
2088 1979 public function print_template() {
2089 1980 ob_start();
2090 1981
2091 1982 // TODO: This is for backwards compatibility starting from 2.9.0
2092 - // This `if` statement should be removed when the method is removed.
1983 + // This `if` statement should be removed when the method is removed
2093 1984 if ( $this->has_own_method( '_content_template', self::class ) ) {
2094 1985 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( '_content_template', '2.9.0', __CLASS__ . '::content_template()' );
2095 1986
2096 1987 $this->_content_template();
@@ -2136,9 +2027,9 @@
2136 2027 * @param array|null $controls The available controls.
2137 2028 *
2138 2029 * @return array Element data.
2139 2030 */
2140 - public static function on_import_update_dynamic_content( array $config, array $data, $controls = null ): array {
2031 + public static function on_import_update_dynamic_content( array $config, array $data, $controls = null ) : array {
2141 2032 return $config;
2142 2033 }
2143 2034
2144 2035 /**
@@ -2385,9 +2276,9 @@
2385 2276 *
2386 2277 * @param string $template_content Template content.
2387 2278 */
2388 2279 protected function print_template_content( $template_content ) {
2389 - Utils::print_unescaped_internal_string( $template_content );
2280 + echo $template_content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2390 2281 }
2391 2282
2392 2283 /**
2393 2284 * Render element output in the editor.
@@ -2425,9 +2316,9 @@
2425 2316 protected function init_controls() {
2426 2317 Plugin::$instance->controls_manager->open_stack( $this );
2427 2318
2428 2319 // TODO: This is for backwards compatibility starting from 2.9.0
2429 - // This `if` statement should be removed when the method is removed.
2320 + // This `if` statement should be removed when the method is removed
2430 2321 if ( $this->has_own_method( '_register_controls', self::class ) ) {
2431 2322 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( '_register_controls', '3.1.0', __CLASS__ . '::register_controls()' );
2432 2323
2433 2324 $this->_register_controls();
@@ -2463,11 +2354,9 @@
2463 2354 if ( null !== $target_tab ) {
2464 2355 $args = array_replace_recursive( $target_tab, $args );
2465 2356 }
2466 2357 } elseif ( empty( $args['section'] ) && ( ! $overwrite || is_wp_error( Plugin::$instance->controls_manager->get_control_from_stack( $this->get_unique_name(), $control_id ) ) ) ) {
2467 - if ( ! Performance::should_optimize_controls() ) {
2468 - 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
2469 - }
2358 + 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
2470 2359 }
2471 2360
2472 2361 return $args;
2473 2362 }
@@ -2572,9 +2461,9 @@
2572 2461 */
2573 2462 public function __construct( array $data = [] ) {
2574 2463 if ( $data ) {
2575 2464 // TODO: This is for backwards compatibility starting from 2.9.0
2576 - // This if statement should be removed when the method is hard-deprecated.
2465 + // This if statement should be removed when the method is hard-deprecated
2577 2466 if ( $this->has_own_method( '_init', self::class ) ) {
2578 2467 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( '_init', '2.9.0', __CLASS__ . '::init()' );
2579 2468
2580 2469 $this->_init( $data );