| @@ -2,11 +2,9 @@ | ||
| 2 | 2 | namespace Elementor; |
| 3 | 3 | |
| 4 | 4 | use Elementor\Core\Base\Base_Object; |
| 5 | 5 | use Elementor\Core\DynamicTags\Manager; |
| 6 | -use Elementor\Core\Breakpoints\Manager as Breakpoints_Manager; | |
| 7 | -use Elementor\Core\Frontend\Performance; | |
| 8 | -use Elementor\Utils; | |
| 6 | +use Elementor\Core\Schemes\Manager as Schemes_Manager; | |
| 9 | 7 | |
| 10 | 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 11 | 9 | exit; // Exit if accessed directly. |
| 12 | 10 | } |
| @@ -23,24 +21,18 @@ | ||
| 23 | 21 | abstract class Controls_Stack extends Base_Object { |
| 24 | 22 | |
| 25 | 23 | /** |
| 26 | 24 | * Responsive 'desktop' device name. |
| 27 | - * | |
| 28 | - * @deprecated 3.4.0 | |
| 29 | 25 | */ |
| 30 | 26 | const RESPONSIVE_DESKTOP = 'desktop'; |
| 31 | 27 | |
| 32 | 28 | /** |
| 33 | 29 | * Responsive 'tablet' device name. |
| 34 | - * | |
| 35 | - * @deprecated 3.4.0 | |
| 36 | 30 | */ |
| 37 | 31 | const RESPONSIVE_TABLET = 'tablet'; |
| 38 | 32 | |
| 39 | 33 | /** |
| 40 | 34 | * Responsive 'mobile' device name. |
| 41 | - * | |
| 42 | - * @deprecated 3.4.0 | |
| 43 | 35 | */ |
| 44 | 36 | const RESPONSIVE_MOBILE = 'mobile'; |
| 45 | 37 | |
| 46 | 38 | /** |
| @@ -91,22 +83,8 @@ | ||
| 91 | 83 | */ |
| 92 | 84 | private $config; |
| 93 | 85 | |
| 94 | 86 | /** |
| 95 | - * The additional configuration. | |
| 96 | - * | |
| 97 | - * Holds additional configuration that has been set using `set_config` method. | |
| 98 | - * The `config` property is not modified directly while using the method because | |
| 99 | - * it's used to check whether the initial config already loaded (in `get_config`). | |
| 100 | - * After the initial config loaded, the additional config is merged into it. | |
| 101 | - * | |
| 102 | - * @access private | |
| 103 | - * | |
| 104 | - * @var null|array | |
| 105 | - */ | |
| 106 | - private $additional_config = []; | |
| 107 | - | |
| 108 | - /** | |
| 109 | 87 | * Current section. |
| 110 | 88 | * |
| 111 | 89 | * Holds the current section while inserting a set of controls sections. |
| 112 | 90 | * |
| @@ -159,20 +137,8 @@ | ||
| 159 | 137 | */ |
| 160 | 138 | private $settings_sanitized = false; |
| 161 | 139 | |
| 162 | 140 | /** |
| 163 | - * Element render attributes. | |
| 164 | - * | |
| 165 | - * Holds all the render attributes of the element. Used to store data like | |
| 166 | - * the HTML class name and the class value, or HTML element ID name and value. | |
| 167 | - * | |
| 168 | - * @access private | |
| 169 | - * | |
| 170 | - * @var array | |
| 171 | - */ | |
| 172 | - private $render_attributes = []; | |
| 173 | - | |
| 174 | - /** | |
| 175 | 141 | * Get element name. |
| 176 | 142 | * |
| 177 | 143 | * Retrieve the element name. |
| 178 | 144 | * |
| @@ -226,26 +192,12 @@ | ||
| 226 | 192 | public function get_id_int() { |
| 227 | 193 | /** We ignore possible notices, in order to support elements created prior to v1.8.0 and might include |
| 228 | 194 | * non-base 16 characters as part of their ID. |
| 229 | 195 | */ |
| 230 | - return @hexdec( (string) $this->id ); | |
| 196 | + return @hexdec( $this->id ); | |
| 231 | 197 | } |
| 232 | 198 | |
| 233 | 199 | /** |
| 234 | - * Get widget number. | |
| 235 | - * | |
| 236 | - * Get the first three numbers of the element converted ID. | |
| 237 | - * | |
| 238 | - * @since 3.16 | |
| 239 | - * @access public | |
| 240 | - * | |
| 241 | - * @return string The widget number. | |
| 242 | - */ | |
| 243 | - public function get_widget_number(): string { | |
| 244 | - return substr( $this->get_id_int(), 0, 3 ); | |
| 245 | - } | |
| 246 | - | |
| 247 | - /** | |
| 248 | 200 | * Get the type. |
| 249 | 201 | * |
| 250 | 202 | * Retrieve the type, e.g. 'stack', 'section', 'widget' etc. |
| 251 | 203 | * |
| @@ -311,26 +263,9 @@ | ||
| 311 | 263 | * |
| 312 | 264 | * @return mixed Controls list. |
| 313 | 265 | */ |
| 314 | 266 | 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 ); | |
| 267 | + return self::get_items( $this->get_stack()['controls'], $control_id ); | |
| 333 | 268 | } |
| 334 | 269 | |
| 335 | 270 | /** |
| 336 | 271 | * Get active controls. |
| @@ -349,10 +284,10 @@ | ||
| 349 | 284 | * @param array $settings Optional. Controls settings. Default is null. |
| 350 | 285 | * |
| 351 | 286 | * @return array Active controls. |
| 352 | 287 | */ |
| 353 | - public function get_active_controls( ?array $controls = null, ?array $settings = null ) { | |
| 354 | - Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.0.0' ); | |
| 288 | + public function get_active_controls( array $controls = null, array $settings = null ) { | |
| 289 | + // _deprecated_function( __METHOD__, '3.0.0' ); | |
| 355 | 290 | |
| 356 | 291 | if ( ! $controls ) { |
| 357 | 292 | $controls = $this->get_controls(); |
| 358 | 293 | } |
| @@ -364,9 +299,9 @@ | ||
| 364 | 299 | $active_controls = array_reduce( |
| 365 | 300 | array_keys( $controls ), function( $active_controls, $control_key ) use ( $controls, $settings ) { |
| 366 | 301 | $control = $controls[ $control_key ]; |
| 367 | 302 | |
| 368 | - if ( $this->is_control_visible( $control, $settings, $controls ) ) { | |
| 303 | + if ( $this->is_control_visible( $control, $settings ) ) { | |
| 369 | 304 | $active_controls[ $control_key ] = $control; |
| 370 | 305 | } |
| 371 | 306 | |
| 372 | 307 | return $active_controls; |
| @@ -439,58 +374,14 @@ | ||
| 439 | 374 | } |
| 440 | 375 | |
| 441 | 376 | unset( $options['position'] ); |
| 442 | 377 | |
| 443 | - if ( $this->current_popover ) { | |
| 444 | - $args['popover'] = []; | |
| 445 | - | |
| 446 | - if ( ! $this->current_popover['initialized'] ) { | |
| 447 | - $args['popover']['start'] = true; | |
| 448 | - | |
| 449 | - $this->current_popover['initialized'] = true; | |
| 450 | - } | |
| 451 | - } | |
| 452 | - | |
| 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, | |
| 378 | + if ( $this->current_popover && ! $this->current_popover['initialized'] ) { | |
| 379 | + $args['popover'] = [ | |
| 380 | + 'start' => true, | |
| 462 | 381 | ]; |
| 463 | 382 | |
| 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 | - ); | |
| 383 | + $this->current_popover['initialized'] = true; | |
| 493 | 384 | } |
| 494 | 385 | |
| 495 | 386 | return Plugin::$instance->controls_manager->add_control_to_stack( $this, $id, $args, $options ); |
| 496 | 387 | } |
| @@ -612,12 +503,12 @@ | ||
| 612 | 503 | |
| 613 | 504 | $position = array_merge( $default_position, $position ); |
| 614 | 505 | |
| 615 | 506 | if ( |
| 616 | - ( 'control' === $position['type'] && in_array( $position['at'], [ 'start', 'end' ], true ) ) || | |
| 617 | - ( 'section' === $position['type'] && in_array( $position['at'], [ 'before', 'after' ], true ) ) | |
| 507 | + 'control' === $position['type'] && in_array( $position['at'], [ 'start', 'end' ], true ) || | |
| 508 | + 'section' === $position['type'] && in_array( $position['at'], [ 'before', 'after' ], true ) | |
| 618 | 509 | ) { |
| 619 | - _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 | |
| 510 | + _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' ); | |
| 620 | 511 | |
| 621 | 512 | return false; |
| 622 | 513 | } |
| 623 | 514 | |
| @@ -637,13 +528,13 @@ | ||
| 637 | 528 | |
| 638 | 529 | $controls_keys = array_keys( $registered_controls ); |
| 639 | 530 | |
| 640 | 531 | while ( Controls_Manager::SECTION !== $registered_controls[ $controls_keys[ $target_section_index ] ]['type'] ) { |
| 641 | - --$target_section_index; | |
| 532 | + $target_section_index--; | |
| 642 | 533 | } |
| 643 | 534 | |
| 644 | 535 | if ( 'section' === $position['type'] ) { |
| 645 | - ++$target_control_index; | |
| 536 | + $target_control_index++; | |
| 646 | 537 | |
| 647 | 538 | if ( 'end' === $position['at'] ) { |
| 648 | 539 | while ( Controls_Manager::SECTION !== $registered_controls[ $controls_keys[ $target_control_index ] ]['type'] ) { |
| 649 | 540 | if ( ++$target_control_index >= count( $registered_controls ) ) { |
| @@ -655,9 +546,9 @@ | ||
| 655 | 546 | |
| 656 | 547 | $target_control = $registered_controls[ $controls_keys[ $target_control_index ] ]; |
| 657 | 548 | |
| 658 | 549 | if ( 'after' === $position['at'] ) { |
| 659 | - ++$target_control_index; | |
| 550 | + $target_control_index++; | |
| 660 | 551 | } |
| 661 | 552 | |
| 662 | 553 | $section_id = $registered_controls[ $controls_keys[ $target_section_index ] ]['name']; |
| 663 | 554 | |
| @@ -737,9 +628,9 @@ | ||
| 737 | 628 | |
| 738 | 629 | $controls_keys = array_keys( $registered_controls ); |
| 739 | 630 | |
| 740 | 631 | while ( true ) { |
| 741 | - ++$section_index; | |
| 632 | + $section_index++; | |
| 742 | 633 | |
| 743 | 634 | if ( ! isset( $controls_keys[ $section_index ] ) ) { |
| 744 | 635 | break; |
| 745 | 636 | } |
| @@ -750,9 +641,9 @@ | ||
| 750 | 641 | break; |
| 751 | 642 | } |
| 752 | 643 | |
| 753 | 644 | $section_controls[ $control_key ] = $registered_controls[ $control_key ]; |
| 754 | - } | |
| 645 | + }; | |
| 755 | 646 | |
| 756 | 647 | return $section_controls; |
| 757 | 648 | } |
| 758 | 649 | |
| @@ -774,9 +665,9 @@ | ||
| 774 | 665 | final public function add_group_control( $group_name, array $args = [], array $options = [] ) { |
| 775 | 666 | $group = Plugin::$instance->controls_manager->get_control_groups( $group_name ); |
| 776 | 667 | |
| 777 | 668 | if ( ! $group ) { |
| 778 | - wp_die( sprintf( '%s::%s: Group "%s" not found.', get_called_class(), __FUNCTION__, $group_name ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 669 | + wp_die( sprintf( '%s::%s: Group "%s" not found.', get_called_class(), __FUNCTION__, $group_name ) ); | |
| 779 | 670 | } |
| 780 | 671 | |
| 781 | 672 | $group->add_controls( $this, $args, $options ); |
| 782 | 673 | } |
| @@ -781,8 +672,30 @@ | ||
| 781 | 672 | $group->add_controls( $this, $args, $options ); |
| 782 | 673 | } |
| 783 | 674 | |
| 784 | 675 | /** |
| 676 | + * Get scheme controls. | |
| 677 | + * | |
| 678 | + * Retrieve all the controls that use schemes. | |
| 679 | + * | |
| 680 | + * @since 1.4.0 | |
| 681 | + * @access public | |
| 682 | + * @deprecated 3.0.0 | |
| 683 | + * | |
| 684 | + * @return array Scheme controls. | |
| 685 | + */ | |
| 686 | + final public function get_scheme_controls() { | |
| 687 | + // _deprecated_function( __METHOD__, '3.0.0' ); | |
| 688 | + $enabled_schemes = Schemes_Manager::get_enabled_schemes(); | |
| 689 | + | |
| 690 | + return array_filter( | |
| 691 | + $this->get_controls(), function( $control ) use ( $enabled_schemes ) { | |
| 692 | + return ( ! empty( $control['scheme'] ) && in_array( $control['scheme']['type'], $enabled_schemes ) ); | |
| 693 | + } | |
| 694 | + ); | |
| 695 | + } | |
| 696 | + | |
| 697 | + /** | |
| 785 | 698 | * Get style controls. |
| 786 | 699 | * |
| 787 | 700 | * Retrieve style controls for all active controls or, when requested, from |
| 788 | 701 | * a specific set of controls. |
| @@ -796,10 +709,10 @@ | ||
| 796 | 709 | * @param array $settings Optional. Controls settings. Default is null. |
| 797 | 710 | * |
| 798 | 711 | * @return array Style controls. |
| 799 | 712 | */ |
| 800 | - final public function get_style_controls( ?array $controls = null, ?array $settings = null ) { | |
| 801 | - Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.0.0' ); | |
| 713 | + final public function get_style_controls( array $controls = null, array $settings = null ) { | |
| 714 | + // _deprecated_function( __METHOD__, '3.0.0' ); | |
| 802 | 715 | |
| 803 | 716 | $controls = $this->get_active_controls( $controls, $settings ); |
| 804 | 717 | |
| 805 | 718 | $style_controls = []; |
| @@ -848,15 +761,9 @@ | ||
| 848 | 761 | /** |
| 849 | 762 | * Add new responsive control to stack. |
| 850 | 763 | * |
| 851 | 764 | * Register a set of controls to allow editing based on user screen size. |
| 852 | - * This method registers one or more controls per screen size/device, depending on the current Responsive Control | |
| 853 | - * Duplication Mode. There are 3 control duplication modes: | |
| 854 | - * * 'off' - Only a single control is generated. In the Editor, this control is duplicated in JS. | |
| 855 | - * * 'on' - Multiple controls are generated, one control per enabled device/breakpoint + a default/desktop control. | |
| 856 | - * * 'dynamic' - If the control includes the `'dynamic' => 'active' => true` property - the control is duplicated, | |
| 857 | - * once for each device/breakpoint + default/desktop. | |
| 858 | - * If the control doesn't include the `'dynamic' => 'active' => true` property - the control is not duplicated. | |
| 765 | + * This method registers three screen sizes: Desktop, Tablet and Mobile. | |
| 859 | 766 | * |
| 860 | 767 | * @since 1.4.0 |
| 861 | 768 | * @access public |
| 862 | 769 | * |
| @@ -867,15 +774,14 @@ | ||
| 867 | 774 | */ |
| 868 | 775 | final public function add_responsive_control( $id, array $args, $options = [] ) { |
| 869 | 776 | $args['responsive'] = []; |
| 870 | 777 | |
| 871 | - $active_breakpoints = Plugin::$instance->breakpoints->get_active_breakpoints(); | |
| 778 | + $devices = [ | |
| 779 | + self::RESPONSIVE_DESKTOP, | |
| 780 | + self::RESPONSIVE_TABLET, | |
| 781 | + self::RESPONSIVE_MOBILE, | |
| 782 | + ]; | |
| 872 | 783 | |
| 873 | - $devices = Plugin::$instance->breakpoints->get_active_devices_list( [ | |
| 874 | - 'reverse' => true, | |
| 875 | - 'desktop_first' => true, | |
| 876 | - ] ); | |
| 877 | - | |
| 878 | 784 | if ( isset( $args['devices'] ) ) { |
| 879 | 785 | $devices = array_intersect( $devices, $args['devices'] ); |
| 880 | 786 | |
| 881 | 787 | $args['responsive']['devices'] = $devices; |
| @@ -882,46 +788,8 @@ | ||
| 882 | 788 | |
| 883 | 789 | unset( $args['devices'] ); |
| 884 | 790 | } |
| 885 | 791 | |
| 886 | - $control_to_check = $args; | |
| 887 | - | |
| 888 | - if ( ! empty( $options['overwrite'] ) ) { | |
| 889 | - $existing_control = Plugin::$instance->controls_manager->get_control_from_stack( $this->get_unique_name(), $id ); | |
| 890 | - | |
| 891 | - if ( ! is_wp_error( $existing_control ) ) { | |
| 892 | - $control_to_check = $existing_control; | |
| 893 | - } | |
| 894 | - } | |
| 895 | - | |
| 896 | - $responsive_duplication_mode = Plugin::$instance->breakpoints->get_responsive_control_duplication_mode(); | |
| 897 | - $additional_breakpoints_active = Plugin::$instance->experiments->is_feature_active( 'additional_custom_breakpoints' ); | |
| 898 | - $control_is_dynamic = ! empty( $control_to_check['dynamic']['active'] ); | |
| 899 | - $is_frontend_available = ! empty( $control_to_check['frontend_available'] ); | |
| 900 | - $has_prefix_class = ! empty( $control_to_check['prefix_class'] ); | |
| 901 | - | |
| 902 | - // If the new responsive controls experiment is active, create only one control - duplicates per device will | |
| 903 | - // be created in JS in the Editor. | |
| 904 | - if ( | |
| 905 | - $additional_breakpoints_active | |
| 906 | - && ( 'off' === $responsive_duplication_mode || ( 'dynamic' === $responsive_duplication_mode && ! $control_is_dynamic ) ) | |
| 907 | - // Some responsive controls need responsive settings to be available to the widget handler, even when empty. | |
| 908 | - && ! $is_frontend_available | |
| 909 | - && ! $has_prefix_class | |
| 910 | - ) { | |
| 911 | - $args['is_responsive'] = true; | |
| 912 | - | |
| 913 | - if ( ! empty( $options['overwrite'] ) ) { | |
| 914 | - $this->update_control( $id, $args, [ | |
| 915 | - 'recursive' => ! empty( $options['recursive'] ), | |
| 916 | - ] ); | |
| 917 | - } else { | |
| 918 | - $this->add_control( $id, $args, $options ); | |
| 919 | - } | |
| 920 | - | |
| 921 | - return; | |
| 922 | - } | |
| 923 | - | |
| 924 | 792 | if ( isset( $args['default'] ) ) { |
| 925 | 793 | $args['desktop_default'] = $args['default']; |
| 926 | 794 | |
| 927 | 795 | unset( $args['default'] ); |
| @@ -929,16 +797,8 @@ | ||
| 929 | 797 | |
| 930 | 798 | foreach ( $devices as $device_name ) { |
| 931 | 799 | $control_args = $args; |
| 932 | 800 | |
| 933 | - // Set parent using the name from previous iteration. | |
| 934 | - if ( isset( $control_name ) ) { | |
| 935 | - // If $control_name end with _widescreen use desktop name instead. | |
| 936 | - $control_args['parent'] = '_widescreen' === substr( $control_name, -strlen( '_widescreen' ) ) ? $id : $control_name; | |
| 937 | - } else { | |
| 938 | - $control_args['parent'] = null; | |
| 939 | - } | |
| 940 | - | |
| 941 | 801 | if ( isset( $control_args['device_args'] ) ) { |
| 942 | 802 | if ( ! empty( $control_args['device_args'][ $device_name ] ) ) { |
| 943 | 803 | $control_args = array_merge( $control_args, $control_args['device_args'][ $device_name ] ); |
| 944 | 804 | } |
| @@ -946,21 +806,15 @@ | ||
| 946 | 806 | unset( $control_args['device_args'] ); |
| 947 | 807 | } |
| 948 | 808 | |
| 949 | 809 | if ( ! empty( $args['prefix_class'] ) ) { |
| 950 | - $device_to_replace = Breakpoints_Manager::BREAKPOINT_KEY_DESKTOP === $device_name ? '' : '-' . $device_name; | |
| 810 | + $device_to_replace = self::RESPONSIVE_DESKTOP === $device_name ? '' : '-' . $device_name; | |
| 951 | 811 | |
| 952 | 812 | $control_args['prefix_class'] = sprintf( $args['prefix_class'], $device_to_replace ); |
| 953 | 813 | } |
| 954 | 814 | |
| 955 | - $direction = 'max'; | |
| 815 | + $control_args['responsive']['max'] = $device_name; | |
| 956 | 816 | |
| 957 | - if ( Breakpoints_Manager::BREAKPOINT_KEY_DESKTOP !== $device_name ) { | |
| 958 | - $direction = $active_breakpoints[ $device_name ]->get_direction(); | |
| 959 | - } | |
| 960 | - | |
| 961 | - $control_args['responsive'][ $direction ] = $device_name; | |
| 962 | - | |
| 963 | 817 | if ( isset( $control_args['min_affected_device'] ) ) { |
| 964 | 818 | if ( ! empty( $control_args['min_affected_device'][ $device_name ] ) ) { |
| 965 | 819 | $control_args['responsive']['min'] = $control_args['min_affected_device'][ $device_name ]; |
| 966 | 820 | } |
| @@ -971,26 +825,20 @@ | ||
| 971 | 825 | if ( isset( $control_args[ $device_name . '_default' ] ) ) { |
| 972 | 826 | $control_args['default'] = $control_args[ $device_name . '_default' ]; |
| 973 | 827 | } |
| 974 | 828 | |
| 975 | - foreach ( $devices as $device ) { | |
| 976 | - unset( $control_args[ $device . '_default' ] ); | |
| 977 | - } | |
| 829 | + unset( $control_args['desktop_default'] ); | |
| 830 | + unset( $control_args['tablet_default'] ); | |
| 831 | + unset( $control_args['mobile_default'] ); | |
| 978 | 832 | |
| 979 | - $id_suffix = Breakpoints_Manager::BREAKPOINT_KEY_DESKTOP === $device_name ? '' : '_' . $device_name; | |
| 980 | - $control_name = $id . $id_suffix; | |
| 833 | + $id_suffix = self::RESPONSIVE_DESKTOP === $device_name ? '' : '_' . $device_name; | |
| 981 | 834 | |
| 982 | - // Set this control as child of previous iteration control. | |
| 983 | - if ( ! empty( $control_args['parent'] ) ) { | |
| 984 | - $this->update_control( $control_args['parent'], [ 'inheritors' => [ $control_name ] ] ); | |
| 985 | - } | |
| 986 | - | |
| 987 | 835 | if ( ! empty( $options['overwrite'] ) ) { |
| 988 | - $this->update_control( $control_name, $control_args, [ | |
| 836 | + $this->update_control( $id . $id_suffix, $control_args, [ | |
| 989 | 837 | 'recursive' => ! empty( $options['recursive'] ), |
| 990 | 838 | ] ); |
| 991 | 839 | } else { |
| 992 | - $this->add_control( $control_name, $control_args, $options ); | |
| 840 | + $this->add_control( $id . $id_suffix, $control_args, $options ); | |
| 993 | 841 | } |
| 994 | 842 | } |
| 995 | 843 | } |
| 996 | 844 | |
| @@ -1025,12 +873,16 @@ | ||
| 1025 | 873 | * |
| 1026 | 874 | * @param string $id Responsive control ID. |
| 1027 | 875 | */ |
| 1028 | 876 | final public function remove_responsive_control( $id ) { |
| 1029 | - $devices = Plugin::$instance->breakpoints->get_active_devices_list( [ 'reverse' => true ] ); | |
| 877 | + $devices = [ | |
| 878 | + self::RESPONSIVE_DESKTOP, | |
| 879 | + self::RESPONSIVE_TABLET, | |
| 880 | + self::RESPONSIVE_MOBILE, | |
| 881 | + ]; | |
| 1030 | 882 | |
| 1031 | 883 | foreach ( $devices as $device_name ) { |
| 1032 | - $id_suffix = Breakpoints_Manager::BREAKPOINT_KEY_DESKTOP === $device_name ? '' : '_' . $device_name; | |
| 884 | + $id_suffix = self::RESPONSIVE_DESKTOP === $device_name ? '' : '_' . $device_name; | |
| 1033 | 885 | |
| 1034 | 886 | $this->remove_control( $id . $id_suffix ); |
| 1035 | 887 | } |
| 1036 | 888 | } |
| @@ -1060,10 +912,10 @@ | ||
| 1060 | 912 | * @return array|null The config. |
| 1061 | 913 | */ |
| 1062 | 914 | final public function get_config() { |
| 1063 | 915 | 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. | |
| 916 | + // TODO: This is for backwards compatibility starting from 2.9.0 | |
| 917 | + // This if statement should be removed when the method is hard-deprecated | |
| 1066 | 918 | if ( $this->has_own_method( '_get_initial_config', self::class ) ) { |
| 1067 | 919 | Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( '_get_initial_config', '2.9.0', __CLASS__ . '::get_initial_config()' ); |
| 1068 | 920 | |
| 1069 | 921 | $this->config = $this->_get_initial_config(); |
| @@ -1069,16 +921,8 @@ | ||
| 1069 | 921 | $this->config = $this->_get_initial_config(); |
| 1070 | 922 | } else { |
| 1071 | 923 | $this->config = $this->get_initial_config(); |
| 1072 | 924 | } |
| 1073 | - | |
| 1074 | - foreach ( $this->additional_config as $key => $value ) { | |
| 1075 | - if ( isset( $this->config[ $key ] ) ) { | |
| 1076 | - $this->config[ $key ] = wp_parse_args( $value, $this->config[ $key ] ); | |
| 1077 | - } else { | |
| 1078 | - $this->config[ $key ] = $value; | |
| 1079 | - } | |
| 1080 | - } | |
| 1081 | 925 | } |
| 1082 | 926 | |
| 1083 | 927 | return $this->config; |
| 1084 | 928 | } |
| @@ -1083,26 +927,8 @@ | ||
| 1083 | 927 | return $this->config; |
| 1084 | 928 | } |
| 1085 | 929 | |
| 1086 | 930 | /** |
| 1087 | - * Set a config property. | |
| 1088 | - * | |
| 1089 | - * Set a specific property of the config list for this controls-stack. | |
| 1090 | - * | |
| 1091 | - * @param string $key | |
| 1092 | - * @param string $value | |
| 1093 | - * @since 3.5.0 | |
| 1094 | - * @access public | |
| 1095 | - */ | |
| 1096 | - public function set_config( $key, $value ) { | |
| 1097 | - if ( isset( $this->additional_config[ $key ] ) ) { | |
| 1098 | - $this->additional_config[ $key ] = wp_parse_args( $value, $this->additional_config[ $key ] ); | |
| 1099 | - } else { | |
| 1100 | - $this->additional_config[ $key ] = $value; | |
| 1101 | - } | |
| 1102 | - } | |
| 1103 | - | |
| 1104 | - /** | |
| 1105 | 931 | * Get frontend settings keys. |
| 1106 | 932 | * |
| 1107 | 933 | * Retrieve settings keys for all frontend controls. |
| 1108 | 934 | * |
| @@ -1166,11 +992,8 @@ | ||
| 1166 | 992 | return self::get_items( $this->data, $item ); |
| 1167 | 993 | } |
| 1168 | 994 | |
| 1169 | 995 | /** |
| 1170 | - * @param null $setting | |
| 1171 | - * @param null $settings | |
| 1172 | - * @return array|mixed|null | |
| 1173 | 996 | * @since 2.0.14 |
| 1174 | 997 | * @access public |
| 1175 | 998 | */ |
| 1176 | 999 | public function get_parsed_dynamic_settings( $setting = null, $settings = null ) { |
| @@ -1189,16 +1012,16 @@ | ||
| 1189 | 1012 | * Get active settings. |
| 1190 | 1013 | * |
| 1191 | 1014 | * Retrieve the settings from all the active controls. |
| 1192 | 1015 | * |
| 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. | |
| 1016 | + * @since 1.4.0 | |
| 1197 | 1017 | * @since 2.1.0 Added the `controls` and the `settings` parameters. |
| 1198 | 1018 | * @access public |
| 1199 | 1019 | * |
| 1200 | - * @since 1.4.0 | |
| 1020 | + * @param array $controls Optional. An array of controls. Default is null. | |
| 1021 | + * @param array $settings Optional. Controls settings. Default is null. | |
| 1022 | + * | |
| 1023 | + * @return array Active settings. | |
| 1201 | 1024 | */ |
| 1202 | 1025 | public function get_active_settings( $settings = null, $controls = null ) { |
| 1203 | 1026 | $is_first_request = ! $settings && ! $this->active_settings; |
| 1204 | 1027 | |
| @@ -1213,10 +1036,8 @@ | ||
| 1213 | 1036 | } |
| 1214 | 1037 | |
| 1215 | 1038 | $active_settings = []; |
| 1216 | 1039 | |
| 1217 | - $controls_objs = Plugin::$instance->controls_manager->get_controls(); | |
| 1218 | - | |
| 1219 | 1040 | foreach ( $settings as $setting_key => $setting ) { |
| 1220 | 1041 | if ( ! isset( $controls[ $setting_key ] ) ) { |
| 1221 | 1042 | $active_settings[ $setting_key ] = $setting; |
| 1222 | 1043 | |
| @@ -1224,10 +1045,10 @@ | ||
| 1224 | 1045 | } |
| 1225 | 1046 | |
| 1226 | 1047 | $control = $controls[ $setting_key ]; |
| 1227 | 1048 | |
| 1228 | - if ( $this->is_control_visible( $control, $settings, $controls ) ) { | |
| 1229 | - $control_obj = $controls_objs[ $control['type'] ] ?? null; | |
| 1049 | + if ( $this->is_control_visible( $control, $settings ) ) { | |
| 1050 | + $control_obj = Plugin::$instance->controls_manager->get_control( $control['type'] ); | |
| 1230 | 1051 | |
| 1231 | 1052 | if ( $control_obj instanceof Control_Repeater ) { |
| 1232 | 1053 | foreach ( $setting as & $item ) { |
| 1233 | 1054 | $item = $this->get_active_settings( $item, $control['fields'] ); |
| @@ -1294,13 +1115,11 @@ | ||
| 1294 | 1115 | if ( null === $controls ) { |
| 1295 | 1116 | $controls = $this->get_controls(); |
| 1296 | 1117 | } |
| 1297 | 1118 | |
| 1298 | - $controls_objs = Plugin::$instance->controls_manager->get_controls(); | |
| 1299 | - | |
| 1300 | 1119 | foreach ( $controls as $control ) { |
| 1301 | 1120 | $control_name = $control['name']; |
| 1302 | - $control_obj = $controls_objs[ $control['type'] ] ?? null; | |
| 1121 | + $control_obj = Plugin::$instance->controls_manager->get_control( $control['type'] ); | |
| 1303 | 1122 | |
| 1304 | 1123 | if ( ! $control_obj instanceof Base_Data_Control ) { |
| 1305 | 1124 | continue; |
| 1306 | 1125 | } |
| @@ -1410,33 +1229,21 @@ | ||
| 1410 | 1229 | ); |
| 1411 | 1230 | } |
| 1412 | 1231 | |
| 1413 | 1232 | /** |
| 1414 | - * Get Responsive Control Device Suffix | |
| 1415 | - * | |
| 1416 | - * @deprecated 3.7.6 Use `Elementor\Controls_Manager::get_responsive_control_device_suffix()` instead. | |
| 1417 | - * @param array $control | |
| 1418 | - * @return string $device suffix | |
| 1419 | - */ | |
| 1420 | - protected function get_responsive_control_device_suffix( $control ) { | |
| 1421 | - Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.7.6', 'Elementor\Controls_Manager::get_responsive_control_device_suffix()' ); | |
| 1422 | - | |
| 1423 | - return Controls_Manager::get_responsive_control_device_suffix( $control ); | |
| 1424 | - } | |
| 1425 | - | |
| 1426 | - /** | |
| 1427 | 1233 | * Whether the control is visible or not. |
| 1428 | 1234 | * |
| 1429 | 1235 | * Used to determine whether the control is visible or not. |
| 1430 | 1236 | * |
| 1237 | + * @since 1.4.0 | |
| 1238 | + * @access public | |
| 1239 | + * | |
| 1431 | 1240 | * @param array $control The control. |
| 1432 | - * @param null $values Optional. Condition values. Default is null. | |
| 1433 | - * @param null $controls | |
| 1241 | + * @param array $values Optional. Condition values. Default is null. | |
| 1242 | + * | |
| 1434 | 1243 | * @return bool Whether the control is visible. |
| 1435 | - * @since 1.4.0 | |
| 1436 | - * @access public | |
| 1437 | 1244 | */ |
| 1438 | - public function is_control_visible( $control, $values = null, $controls = null ) { | |
| 1245 | + public function is_control_visible( $control, $values = null ) { | |
| 1439 | 1246 | if ( null === $values ) { |
| 1440 | 1247 | $values = $this->get_settings(); |
| 1441 | 1248 | } |
| 1442 | 1249 | |
| @@ -1447,37 +1254,21 @@ | ||
| 1447 | 1254 | if ( empty( $control['condition'] ) ) { |
| 1448 | 1255 | return true; |
| 1449 | 1256 | } |
| 1450 | 1257 | |
| 1451 | - if ( ! $controls ) { | |
| 1452 | - $controls = $this->get_controls(); | |
| 1453 | - } | |
| 1454 | - | |
| 1455 | 1258 | foreach ( $control['condition'] as $condition_key => $condition_value ) { |
| 1456 | 1259 | preg_match( '/([a-z_\-0-9]+)(?:\[([a-z_]+)])?(!?)$/i', $condition_key, $condition_key_parts ); |
| 1457 | 1260 | |
| 1458 | 1261 | $pure_condition_key = $condition_key_parts[1]; |
| 1459 | 1262 | $condition_sub_key = $condition_key_parts[2]; |
| 1460 | - $is_negative_condition = (bool) $condition_key_parts[3]; | |
| 1263 | + $is_negative_condition = ! ! $condition_key_parts[3]; | |
| 1461 | 1264 | |
| 1462 | 1265 | if ( ! isset( $values[ $pure_condition_key ] ) || null === $values[ $pure_condition_key ] ) { |
| 1463 | 1266 | return false; |
| 1464 | 1267 | } |
| 1465 | 1268 | |
| 1466 | - $are_control_and_condition_responsive = isset( $control['responsive'] ) && ! empty( $controls[ $pure_condition_key ]['responsive'] ); | |
| 1467 | - $condition_name_to_check = $pure_condition_key; | |
| 1269 | + $instance_value = $values[ $pure_condition_key ]; | |
| 1468 | 1270 | |
| 1469 | - if ( $are_control_and_condition_responsive ) { | |
| 1470 | - $device_suffix = Controls_Manager::get_responsive_control_device_suffix( $control ); | |
| 1471 | - | |
| 1472 | - $condition_name_to_check = $pure_condition_key . $device_suffix; | |
| 1473 | - | |
| 1474 | - // If the control is not desktop, and a conditioning control for the corresponding device exists, use it. | |
| 1475 | - $instance_value = $values[ $pure_condition_key . $device_suffix ] ?? $values[ $pure_condition_key ]; | |
| 1476 | - } else { | |
| 1477 | - $instance_value = $values[ $pure_condition_key ]; | |
| 1478 | - } | |
| 1479 | - | |
| 1480 | 1271 | if ( $condition_sub_key && is_array( $instance_value ) ) { |
| 1481 | 1272 | if ( ! isset( $instance_value[ $condition_sub_key ] ) ) { |
| 1482 | 1273 | return false; |
| 1483 | 1274 | } |
| @@ -1484,32 +1275,8 @@ | ||
| 1484 | 1275 | |
| 1485 | 1276 | $instance_value = $instance_value[ $condition_sub_key ]; |
| 1486 | 1277 | } |
| 1487 | 1278 | |
| 1488 | - if ( ! $instance_value ) { | |
| 1489 | - $parent = isset( $controls[ $condition_name_to_check ]['parent'] ) ? $controls[ $condition_name_to_check ]['parent'] : false; | |
| 1490 | - | |
| 1491 | - while ( $parent ) { | |
| 1492 | - $instance_value = $values[ $parent ]; | |
| 1493 | - | |
| 1494 | - if ( $instance_value ) { | |
| 1495 | - if ( ! is_array( $instance_value ) ) { | |
| 1496 | - break; | |
| 1497 | - } | |
| 1498 | - | |
| 1499 | - if ( $condition_sub_key && isset( $instance_value[ $condition_sub_key ] ) ) { | |
| 1500 | - $instance_value = $instance_value[ $condition_sub_key ]; | |
| 1501 | - | |
| 1502 | - if ( '' !== $instance_value ) { | |
| 1503 | - break; | |
| 1504 | - } | |
| 1505 | - } | |
| 1506 | - } | |
| 1507 | - | |
| 1508 | - $parent = isset( $controls[ $parent ]['parent'] ) ? $controls[ $parent ]['parent'] : false; | |
| 1509 | - } | |
| 1510 | - } | |
| 1511 | - | |
| 1512 | 1279 | /** |
| 1513 | 1280 | * If the $condition_value is a non empty array - check if the $condition_value contains the $instance_value, |
| 1514 | 1281 | * If the $instance_value is a non empty array - check if the $instance_value contains the $condition_value |
| 1515 | 1282 | * otherwise check if they are equal. ( and give the ability to check if the value is an empty array ) |
| @@ -1521,12 +1288,9 @@ | ||
| 1521 | 1288 | } else { |
| 1522 | 1289 | $is_contains = $instance_value === $condition_value; |
| 1523 | 1290 | } |
| 1524 | 1291 | |
| 1525 | - if ( | |
| 1526 | - ( $is_negative_condition && $is_contains ) || | |
| 1527 | - ( ! $is_negative_condition && ! $is_contains ) | |
| 1528 | - ) { | |
| 1292 | + if ( $is_negative_condition && $is_contains || ! $is_negative_condition && ! $is_contains ) { | |
| 1529 | 1293 | return false; |
| 1530 | 1294 | } |
| 1531 | 1295 | } |
| 1532 | 1296 | |
| @@ -1548,9 +1312,9 @@ | ||
| 1548 | 1312 | * @param string $section_id Section ID. |
| 1549 | 1313 | * @param array $args Section arguments Optional. |
| 1550 | 1314 | */ |
| 1551 | 1315 | public function start_controls_section( $section_id, array $args = [] ) { |
| 1552 | - $stack_name = $this->get_name(); | |
| 1316 | + $section_name = $this->get_name(); | |
| 1553 | 1317 | |
| 1554 | 1318 | /** |
| 1555 | 1319 | * Before section start. |
| 1556 | 1320 | * |
| @@ -1568,9 +1332,9 @@ | ||
| 1568 | 1332 | * Before section start. |
| 1569 | 1333 | * |
| 1570 | 1334 | * Fires before Elementor section starts in the editor panel. |
| 1571 | 1335 | * |
| 1572 | - * The dynamic portions of the hook name, `$stack_name` and `$section_id`, refers to the stack name and section ID, respectively. | |
| 1336 | + * The dynamic portions of the hook name, `$section_name` and `$section_id`, refers to the section name and section ID, respectively. | |
| 1573 | 1337 | * |
| 1574 | 1338 | * @since 1.4.0 |
| 1575 | 1339 | * |
| 1576 | 1340 | * @param Controls_Stack $this The control. |
| @@ -1575,20 +1339,16 @@ | ||
| 1575 | 1339 | * |
| 1576 | 1340 | * @param Controls_Stack $this The control. |
| 1577 | 1341 | * @param array $args Section arguments. |
| 1578 | 1342 | */ |
| 1579 | - do_action( "elementor/element/{$stack_name}/{$section_id}/before_section_start", $this, $args ); | |
| 1343 | + do_action( "elementor/element/{$section_name}/{$section_id}/before_section_start", $this, $args ); | |
| 1580 | 1344 | |
| 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 | 1345 | $args['type'] = Controls_Manager::SECTION; |
| 1586 | 1346 | |
| 1587 | 1347 | $this->add_control( $section_id, $args ); |
| 1588 | 1348 | |
| 1589 | 1349 | if ( null !== $this->current_section ) { |
| 1590 | - 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 | |
| 1350 | + wp_die( sprintf( 'Elementor: You can\'t start a section before the end of the previous section "%s".', $this->current_section['section'] ) ); // XSS ok. | |
| 1591 | 1351 | } |
| 1592 | 1352 | |
| 1593 | 1353 | $this->current_section = $this->get_section_args( $section_id ); |
| 1594 | 1354 | |
| @@ -1613,9 +1373,9 @@ | ||
| 1613 | 1373 | * After section start. |
| 1614 | 1374 | * |
| 1615 | 1375 | * Fires after Elementor section starts in the editor panel. |
| 1616 | 1376 | * |
| 1617 | - * The dynamic portions of the hook name, `$stack_name` and `$section_id`, refers to the stack name and section ID, respectively. | |
| 1377 | + * The dynamic portions of the hook name, `$section_name` and `$section_id`, refers to the section name and section ID, respectively. | |
| 1618 | 1378 | * |
| 1619 | 1379 | * @since 1.4.0 |
| 1620 | 1380 | * |
| 1621 | 1381 | * @param Controls_Stack $this The control. |
| @@ -1620,13 +1380,9 @@ | ||
| 1620 | 1380 | * |
| 1621 | 1381 | * @param Controls_Stack $this The control. |
| 1622 | 1382 | * @param array $args Section arguments. |
| 1623 | 1383 | */ |
| 1624 | - 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 | - } | |
| 1384 | + do_action( "elementor/element/{$section_name}/{$section_id}/after_section_start", $this, $args ); | |
| 1629 | 1385 | } |
| 1630 | 1386 | |
| 1631 | 1387 | /** |
| 1632 | 1388 | * End controls section. |
| @@ -1675,12 +1431,8 @@ | ||
| 1675 | 1431 | * @param array $args Section arguments. |
| 1676 | 1432 | */ |
| 1677 | 1433 | do_action( "elementor/element/{$stack_name}/{$section_id}/before_section_end", $this, $args ); |
| 1678 | 1434 | |
| 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 | 1435 | $this->current_section = null; |
| 1684 | 1436 | |
| 1685 | 1437 | /** |
| 1686 | 1438 | * After section end. |
| @@ -1699,9 +1451,9 @@ | ||
| 1699 | 1451 | * After section end. |
| 1700 | 1452 | * |
| 1701 | 1453 | * Fires after Elementor section ends in the editor panel. |
| 1702 | 1454 | * |
| 1703 | - * The dynamic portions of the hook name, `$stack_name` and `$section_id`, refers to the stack name and section ID, respectively. | |
| 1455 | + * The dynamic portions of the hook name, `$stack_name` and `$section_id`, refers to the section name and section ID, respectively. | |
| 1704 | 1456 | * |
| 1705 | 1457 | * @since 1.4.0 |
| 1706 | 1458 | * |
| 1707 | 1459 | * @param Controls_Stack $this The control. |
| @@ -1707,40 +1459,11 @@ | ||
| 1707 | 1459 | * @param Controls_Stack $this The control. |
| 1708 | 1460 | * @param array $args Section arguments. |
| 1709 | 1461 | */ |
| 1710 | 1462 | 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 | 1463 | } |
| 1716 | 1464 | |
| 1717 | 1465 | /** |
| 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 | 1466 | * Start controls tabs. |
| 1744 | 1467 | * |
| 1745 | 1468 | * Used to add a new set of tabs inside a section. You should use this |
| 1746 | 1469 | * method before adding new individual tabs using `start_controls_tab()`. |
| @@ -1756,9 +1479,9 @@ | ||
| 1756 | 1479 | * @param array $args Tabs arguments. |
| 1757 | 1480 | */ |
| 1758 | 1481 | public function start_controls_tabs( $tabs_id, array $args = [] ) { |
| 1759 | 1482 | if ( null !== $this->current_tab ) { |
| 1760 | - 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 | |
| 1483 | + wp_die( sprintf( 'Elementor: You can\'t start tabs before the end of the previous tabs "%s".', $this->current_tab['tabs_wrapper'] ) ); // XSS ok. | |
| 1761 | 1484 | } |
| 1762 | 1485 | |
| 1763 | 1486 | $args['type'] = Controls_Manager::TABS; |
| 1764 | 1487 | |
| @@ -1811,9 +1534,9 @@ | ||
| 1811 | 1534 | * @param array $args Tab arguments. |
| 1812 | 1535 | */ |
| 1813 | 1536 | public function start_controls_tab( $tab_id, $args ) { |
| 1814 | 1537 | if ( ! empty( $this->current_tab['inner_tab'] ) ) { |
| 1815 | - 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 | |
| 1538 | + wp_die( sprintf( 'Elementor: You can\'t start a tab before the end of the previous tab "%s".', $this->current_tab['inner_tab'] ) ); // XSS ok. | |
| 1816 | 1539 | } |
| 1817 | 1540 | |
| 1818 | 1541 | $args['type'] = Controls_Manager::TAB; |
| 1819 | 1542 | $args['tabs_wrapper'] = $this->current_tab['tabs_wrapper']; |
| @@ -1889,196 +1612,8 @@ | ||
| 1889 | 1612 | $this->update_control( $last_control_key, $args, $options ); |
| 1890 | 1613 | } |
| 1891 | 1614 | |
| 1892 | 1615 | /** |
| 1893 | - * Add render attribute. | |
| 1894 | - * | |
| 1895 | - * Used to add attributes to a specific HTML element. | |
| 1896 | - * | |
| 1897 | - * The HTML tag is represented by the element parameter, then you need to | |
| 1898 | - * define the attribute key and the attribute key. The final result will be: | |
| 1899 | - * `<element attribute_key="attribute_value">`. | |
| 1900 | - * | |
| 1901 | - * Example usage: | |
| 1902 | - * | |
| 1903 | - * `$this->add_render_attribute( 'wrapper', 'class', 'custom-widget-wrapper-class' );` | |
| 1904 | - * `$this->add_render_attribute( 'widget', 'id', 'custom-widget-id' );` | |
| 1905 | - * `$this->add_render_attribute( 'button', [ 'class' => 'custom-button-class', 'id' => 'custom-button-id' ] );` | |
| 1906 | - * | |
| 1907 | - * @since 1.0.0 | |
| 1908 | - * @access public | |
| 1909 | - * | |
| 1910 | - * @param array|string $element The HTML element. | |
| 1911 | - * @param array|string $key Optional. Attribute key. Default is null. | |
| 1912 | - * @param array|string $value Optional. Attribute value. Default is null. | |
| 1913 | - * @param bool $overwrite Optional. Whether to overwrite existing | |
| 1914 | - * attribute. Default is false, not to overwrite. | |
| 1915 | - * | |
| 1916 | - * @return self Current instance of the element. | |
| 1917 | - */ | |
| 1918 | - public function add_render_attribute( $element, $key = null, $value = null, $overwrite = false ) { | |
| 1919 | - if ( is_array( $element ) ) { | |
| 1920 | - foreach ( $element as $element_key => $attributes ) { | |
| 1921 | - $this->add_render_attribute( $element_key, $attributes, null, $overwrite ); | |
| 1922 | - } | |
| 1923 | - | |
| 1924 | - return $this; | |
| 1925 | - } | |
| 1926 | - | |
| 1927 | - if ( is_array( $key ) ) { | |
| 1928 | - foreach ( $key as $attribute_key => $attributes ) { | |
| 1929 | - $this->add_render_attribute( $element, $attribute_key, $attributes, $overwrite ); | |
| 1930 | - } | |
| 1931 | - | |
| 1932 | - return $this; | |
| 1933 | - } | |
| 1934 | - | |
| 1935 | - if ( empty( $this->render_attributes[ $element ][ $key ] ) ) { | |
| 1936 | - $this->render_attributes[ $element ][ $key ] = []; | |
| 1937 | - } | |
| 1938 | - | |
| 1939 | - settype( $value, 'array' ); | |
| 1940 | - | |
| 1941 | - if ( $overwrite ) { | |
| 1942 | - $this->render_attributes[ $element ][ $key ] = $value; | |
| 1943 | - } else { | |
| 1944 | - $this->render_attributes[ $element ][ $key ] = array_merge( $this->render_attributes[ $element ][ $key ], $value ); | |
| 1945 | - } | |
| 1946 | - | |
| 1947 | - return $this; | |
| 1948 | - } | |
| 1949 | - | |
| 1950 | - /** | |
| 1951 | - * Get Render Attributes | |
| 1952 | - * | |
| 1953 | - * Used to retrieve render attribute. | |
| 1954 | - * | |
| 1955 | - * The returned array is either all elements and their attributes if no `$element` is specified, an array of all | |
| 1956 | - * attributes of a specific element or a specific attribute properties if `$key` is specified. | |
| 1957 | - * | |
| 1958 | - * Returns null if one of the requested parameters isn't set. | |
| 1959 | - * | |
| 1960 | - * @since 2.2.6 | |
| 1961 | - * @access public | |
| 1962 | - * @param string $element | |
| 1963 | - * @param string $key | |
| 1964 | - * | |
| 1965 | - * @return array | |
| 1966 | - */ | |
| 1967 | - public function get_render_attributes( $element = '', $key = '' ) { | |
| 1968 | - $attributes = $this->render_attributes; | |
| 1969 | - | |
| 1970 | - if ( $element ) { | |
| 1971 | - if ( ! isset( $attributes[ $element ] ) ) { | |
| 1972 | - return null; | |
| 1973 | - } | |
| 1974 | - | |
| 1975 | - $attributes = $attributes[ $element ]; | |
| 1976 | - | |
| 1977 | - if ( $key ) { | |
| 1978 | - if ( ! isset( $attributes[ $key ] ) ) { | |
| 1979 | - return null; | |
| 1980 | - } | |
| 1981 | - | |
| 1982 | - $attributes = $attributes[ $key ]; | |
| 1983 | - } | |
| 1984 | - } | |
| 1985 | - | |
| 1986 | - return $attributes; | |
| 1987 | - } | |
| 1988 | - | |
| 1989 | - /** | |
| 1990 | - * Set render attribute. | |
| 1991 | - * | |
| 1992 | - * Used to set the value of the HTML element render attribute or to update | |
| 1993 | - * an existing render attribute. | |
| 1994 | - * | |
| 1995 | - * @since 1.0.0 | |
| 1996 | - * @access public | |
| 1997 | - * | |
| 1998 | - * @param array|string $element The HTML element. | |
| 1999 | - * @param array|string $key Optional. Attribute key. Default is null. | |
| 2000 | - * @param array|string $value Optional. Attribute value. Default is null. | |
| 2001 | - * | |
| 2002 | - * @return self Current instance of the element. | |
| 2003 | - */ | |
| 2004 | - public function set_render_attribute( $element, $key = null, $value = null ) { | |
| 2005 | - return $this->add_render_attribute( $element, $key, $value, true ); | |
| 2006 | - } | |
| 2007 | - | |
| 2008 | - /** | |
| 2009 | - * Remove render attribute. | |
| 2010 | - * | |
| 2011 | - * Used to remove an element (with its keys and their values), key (with its values), | |
| 2012 | - * or value/s from an HTML element's render attribute. | |
| 2013 | - * | |
| 2014 | - * @since 2.7.0 | |
| 2015 | - * @access public | |
| 2016 | - * | |
| 2017 | - * @param string $element The HTML element. | |
| 2018 | - * @param string $key Optional. Attribute key. Default is null. | |
| 2019 | - * @param array|string $values Optional. Attribute value/s. Default is null. | |
| 2020 | - */ | |
| 2021 | - public function remove_render_attribute( $element, $key = null, $values = null ) { | |
| 2022 | - if ( $key && ! isset( $this->render_attributes[ $element ][ $key ] ) ) { | |
| 2023 | - return; | |
| 2024 | - } | |
| 2025 | - | |
| 2026 | - if ( $values ) { | |
| 2027 | - $values = (array) $values; | |
| 2028 | - | |
| 2029 | - $this->render_attributes[ $element ][ $key ] = array_diff( $this->render_attributes[ $element ][ $key ], $values ); | |
| 2030 | - | |
| 2031 | - return; | |
| 2032 | - } | |
| 2033 | - | |
| 2034 | - if ( $key ) { | |
| 2035 | - unset( $this->render_attributes[ $element ][ $key ] ); | |
| 2036 | - | |
| 2037 | - return; | |
| 2038 | - } | |
| 2039 | - | |
| 2040 | - if ( isset( $this->render_attributes[ $element ] ) ) { | |
| 2041 | - unset( $this->render_attributes[ $element ] ); | |
| 2042 | - } | |
| 2043 | - } | |
| 2044 | - | |
| 2045 | - /** | |
| 2046 | - * Get render attribute string. | |
| 2047 | - * | |
| 2048 | - * Used to retrieve the value of the render attribute. | |
| 2049 | - * | |
| 2050 | - * @since 1.0.0 | |
| 2051 | - * @access public | |
| 2052 | - * | |
| 2053 | - * @param string $element The element. | |
| 2054 | - * | |
| 2055 | - * @return string Render attribute string, or an empty string if the attribute | |
| 2056 | - * is empty or not exist. | |
| 2057 | - */ | |
| 2058 | - public function get_render_attribute_string( $element ) { | |
| 2059 | - if ( empty( $this->render_attributes[ $element ] ) ) { | |
| 2060 | - return ''; | |
| 2061 | - } | |
| 2062 | - | |
| 2063 | - return Utils::render_html_attributes( $this->render_attributes[ $element ] ); | |
| 2064 | - } | |
| 2065 | - | |
| 2066 | - /** | |
| 2067 | - * Print render attribute string. | |
| 2068 | - * | |
| 2069 | - * Used to output the rendered attribute. | |
| 2070 | - * | |
| 2071 | - * @since 2.0.0 | |
| 2072 | - * @access public | |
| 2073 | - * | |
| 2074 | - * @param array|string $element The element. | |
| 2075 | - */ | |
| 2076 | - public function print_render_attribute_string( $element ) { | |
| 2077 | - Utils::print_unescaped_internal_string( $this->get_render_attribute_string( $element ) ); | |
| 2078 | - } | |
| 2079 | - | |
| 2080 | - /** | |
| 2081 | 1616 | * Print element template. |
| 2082 | 1617 | * |
| 2083 | 1618 | * Used to generate the element template on the editor. |
| 2084 | 1619 | * |
| @@ -2088,9 +1623,9 @@ | ||
| 2088 | 1623 | public function print_template() { |
| 2089 | 1624 | ob_start(); |
| 2090 | 1625 | |
| 2091 | 1626 | // TODO: This is for backwards compatibility starting from 2.9.0 |
| 2092 | - // This `if` statement should be removed when the method is removed. | |
| 1627 | + // This `if` statement should be removed when the method is removed | |
| 2093 | 1628 | if ( $this->has_own_method( '_content_template', self::class ) ) { |
| 2094 | 1629 | Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( '_content_template', '2.9.0', __CLASS__ . '::content_template()' ); |
| 2095 | 1630 | |
| 2096 | 1631 | $this->_content_template(); |
| @@ -2126,23 +1661,8 @@ | ||
| 2126 | 1661 | <?php |
| 2127 | 1662 | } |
| 2128 | 1663 | |
| 2129 | 1664 | /** |
| 2130 | - * On import update dynamic content (e.g. post and term IDs). | |
| 2131 | - * | |
| 2132 | - * @since 3.8.0 | |
| 2133 | - * | |
| 2134 | - * @param array $config The config of the passed element. | |
| 2135 | - * @param array $data The data that requires updating/replacement when imported. | |
| 2136 | - * @param array|null $controls The available controls. | |
| 2137 | - * | |
| 2138 | - * @return array Element data. | |
| 2139 | - */ | |
| 2140 | - public static function on_import_update_dynamic_content( array $config, array $data, $controls = null ): array { | |
| 2141 | - return $config; | |
| 2142 | - } | |
| 2143 | - | |
| 2144 | - /** | |
| 2145 | 1665 | * Start injection. |
| 2146 | 1666 | * |
| 2147 | 1667 | * Used to inject controls and sections to a specific position in the stack. |
| 2148 | 1668 | * |
| @@ -2217,12 +1737,12 @@ | ||
| 2217 | 1737 | * `start_controls_tab()`. |
| 2218 | 1738 | * |
| 2219 | 1739 | * @since 1.4.0 |
| 2220 | 1740 | * @access protected |
| 2221 | - * @deprecated 3.1.0 Use `register_controls()` method instead. | |
| 1741 | + * @deprecated 3.1.0 Use `Controls_Stack::register_controls()` instead | |
| 2222 | 1742 | */ |
| 2223 | 1743 | protected function _register_controls() { |
| 2224 | - Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.1.0', 'register_controls()' ); | |
| 1744 | + Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.1.0', __CLASS__ . '::register_controls()' ); | |
| 2225 | 1745 | |
| 2226 | 1746 | $this->register_controls(); |
| 2227 | 1747 | } |
| 2228 | 1748 | |
| @@ -2265,12 +1785,10 @@ | ||
| 2265 | 1785 | */ |
| 2266 | 1786 | protected function get_init_settings() { |
| 2267 | 1787 | $settings = $this->get_data( 'settings' ); |
| 2268 | 1788 | |
| 2269 | - $controls_objs = Plugin::$instance->controls_manager->get_controls(); | |
| 2270 | - | |
| 2271 | 1789 | foreach ( $this->get_controls() as $control ) { |
| 2272 | - $control_obj = $controls_objs[ $control['type'] ] ?? null; | |
| 1790 | + $control_obj = Plugin::$instance->controls_manager->get_control( $control['type'] ); | |
| 2273 | 1791 | |
| 2274 | 1792 | if ( ! $control_obj instanceof Base_Data_Control ) { |
| 2275 | 1793 | continue; |
| 2276 | 1794 | } |
| @@ -2306,15 +1824,15 @@ | ||
| 2306 | 1824 | * Retrieve the current element initial configuration - controls list and |
| 2307 | 1825 | * the tabs assigned to the control. |
| 2308 | 1826 | * |
| 2309 | 1827 | * @since 1.4.0 |
| 2310 | - * @deprecated 2.9.0 Use `get_initial_config()` method instead. | |
| 1828 | + * @deprecated 2.9.0 use `get_initial_config()` instead | |
| 2311 | 1829 | * @access protected |
| 2312 | 1830 | * |
| 2313 | 1831 | * @return array The initial config. |
| 2314 | 1832 | */ |
| 2315 | 1833 | protected function _get_initial_config() { |
| 2316 | - Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '2.9.0', 'get_initial_config()' ); | |
| 1834 | + Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '2.9.0', __CLASS__ . '::get_initial_config()' ); | |
| 2317 | 1835 | |
| 2318 | 1836 | return $this->get_initial_config(); |
| 2319 | 1837 | } |
| 2320 | 1838 | |
| @@ -2385,9 +1903,9 @@ | ||
| 2385 | 1903 | * |
| 2386 | 1904 | * @param string $template_content Template content. |
| 2387 | 1905 | */ |
| 2388 | 1906 | protected function print_template_content( $template_content ) { |
| 2389 | - Utils::print_unescaped_internal_string( $template_content ); | |
| 1907 | + echo $template_content; | |
| 2390 | 1908 | } |
| 2391 | 1909 | |
| 2392 | 1910 | /** |
| 2393 | 1911 | * Render element output in the editor. |
| @@ -2404,13 +1922,13 @@ | ||
| 2404 | 1922 | * |
| 2405 | 1923 | * Used to generate the live preview, using a Backbone JavaScript template. |
| 2406 | 1924 | * |
| 2407 | 1925 | * @since 2.0.0 |
| 2408 | - * @deprecated 2.9.0 Use `content_template()` method instead. | |
| 1926 | + * @deprecated 2.9.0 use `content_template()` instead | |
| 2409 | 1927 | * @access protected |
| 2410 | 1928 | */ |
| 2411 | 1929 | protected function _content_template() { |
| 2412 | - Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '2.9.0', 'content_template()' ); | |
| 1930 | + Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '2.9.0', __CLASS__ . '::content_template()' ); | |
| 2413 | 1931 | |
| 2414 | 1932 | $this->content_template(); |
| 2415 | 1933 | } |
| 2416 | 1934 | |
| @@ -2425,9 +1943,9 @@ | ||
| 2425 | 1943 | protected function init_controls() { |
| 2426 | 1944 | Plugin::$instance->controls_manager->open_stack( $this ); |
| 2427 | 1945 | |
| 2428 | 1946 | // TODO: This is for backwards compatibility starting from 2.9.0 |
| 2429 | - // This `if` statement should be removed when the method is removed. | |
| 1947 | + // This `if` statement should be removed when the method is removed | |
| 2430 | 1948 | if ( $this->has_own_method( '_register_controls', self::class ) ) { |
| 2431 | 1949 | Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( '_register_controls', '3.1.0', __CLASS__ . '::register_controls()' ); |
| 2432 | 1950 | |
| 2433 | 1951 | $this->_register_controls(); |
| @@ -2454,9 +1972,9 @@ | ||
| 2454 | 1972 | } |
| 2455 | 1973 | |
| 2456 | 1974 | if ( null !== $target_section_args ) { |
| 2457 | 1975 | if ( ! empty( $args['section'] ) || ! empty( $args['tab'] ) ) { |
| 2458 | - _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 | |
| 1976 | + _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' ); | |
| 2459 | 1977 | } |
| 2460 | 1978 | |
| 2461 | 1979 | $args = array_replace_recursive( $target_section_args, $args ); |
| 2462 | 1980 | |
| @@ -2463,11 +1981,9 @@ | ||
| 2463 | 1981 | if ( null !== $target_tab ) { |
| 2464 | 1982 | $args = array_replace_recursive( $target_tab, $args ); |
| 2465 | 1983 | } |
| 2466 | 1984 | } 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 | - } | |
| 1985 | + wp_die( sprintf( '%s::%s: Cannot add a control outside of a section (use `start_controls_section`).', get_called_class(), __FUNCTION__ ) ); | |
| 2470 | 1986 | } |
| 2471 | 1987 | |
| 2472 | 1988 | return $args; |
| 2473 | 1989 | } |
| @@ -2493,15 +2009,15 @@ | ||
| 2493 | 2009 | * |
| 2494 | 2010 | * Set the raw data, the ID and the parsed settings. |
| 2495 | 2011 | * |
| 2496 | 2012 | * @since 1.4.0 |
| 2497 | - * @deprecated 2.9.0 Use `init()` method instead. | |
| 2013 | + * @deprecated 2.9.0 use `init()` instead | |
| 2498 | 2014 | * @access protected |
| 2499 | 2015 | * |
| 2500 | 2016 | * @param array $data Initial data. |
| 2501 | 2017 | */ |
| 2502 | 2018 | protected function _init( $data ) { |
| 2503 | - Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '2.9.0', 'init()' ); | |
| 2019 | + Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '2.9.0', __CLASS__ . '::init()' ); | |
| 2504 | 2020 | |
| 2505 | 2021 | $this->init( $data ); |
| 2506 | 2022 | } |
| 2507 | 2023 | |
| @@ -2572,9 +2088,9 @@ | ||
| 2572 | 2088 | */ |
| 2573 | 2089 | public function __construct( array $data = [] ) { |
| 2574 | 2090 | if ( $data ) { |
| 2575 | 2091 | // TODO: This is for backwards compatibility starting from 2.9.0 |
| 2576 | - // This if statement should be removed when the method is hard-deprecated. | |
| 2092 | + // This if statement should be removed when the method is hard-deprecated | |
| 2577 | 2093 | if ( $this->has_own_method( '_init', self::class ) ) { |
| 2578 | 2094 | Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( '_init', '2.9.0', __CLASS__ . '::init()' ); |
| 2579 | 2095 | |
| 2580 | 2096 | $this->_init( $data ); |