| @@ -8,9 +8,8 @@ | ||
| 8 | 8 | use Elementor\Core\Breakpoints\Manager as Breakpoints_Manager; |
| 9 | 9 | use Elementor\Core\Files\Base as Base_File; |
| 10 | 10 | use Elementor\Core\DynamicTags\Manager; |
| 11 | 11 | use Elementor\Core\DynamicTags\Tag; |
| 12 | -use Elementor\Core\Frontend\Performance; | |
| 13 | 12 | use Elementor\Core\Kits\Documents\Tabs\Global_Typography; |
| 14 | 13 | use Elementor\Plugin; |
| 15 | 14 | use Elementor\Stylesheet; |
| 16 | 15 | use Elementor\Icons_Manager; |
| @@ -64,10 +63,8 @@ | ||
| 64 | 63 | private $icons_fonts = []; |
| 65 | 64 | |
| 66 | 65 | private $dynamic_elements_ids = []; |
| 67 | 66 | |
| 68 | - private $preserved_dynamic_style_values = []; | |
| 69 | - | |
| 70 | 67 | /** |
| 71 | 68 | * Stylesheet object. |
| 72 | 69 | * |
| 73 | 70 | * Holds the CSS file stylesheet instance. |
| @@ -214,17 +211,8 @@ | ||
| 214 | 211 | if ( self::CSS_STATUS_EMPTY === $meta['status'] ) { |
| 215 | 212 | return; |
| 216 | 213 | } |
| 217 | 214 | |
| 218 | - /** | |
| 219 | - * Enqueue CSS file. | |
| 220 | - * | |
| 221 | - * Fires before enqueuing a CSS file. | |
| 222 | - * | |
| 223 | - * @param Base $this The current CSS file. | |
| 224 | - */ | |
| 225 | - do_action( 'elementor/css-file/before_enqueue', $this ); | |
| 226 | - | |
| 227 | 215 | // First time after clear cache and etc. |
| 228 | 216 | if ( '' === $meta['status'] || $this->is_update_required() ) { |
| 229 | 217 | $this->update(); |
| 230 | 218 | |
| @@ -234,14 +222,14 @@ | ||
| 234 | 222 | if ( self::CSS_STATUS_INLINE === $meta['status'] ) { |
| 235 | 223 | $dep = $this->get_inline_dependency(); |
| 236 | 224 | // If the dependency has already been printed ( like a template in footer ) |
| 237 | 225 | if ( wp_styles()->query( $dep, 'done' ) ) { |
| 238 | - printf( '<style id="%1$s">%2$s</style>', $this->get_file_handle_id(), $meta['css'] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 226 | + printf( '<style id="%1$s">%2$s</style>', $this->get_file_handle_id(), $meta['css'] ); // XSS ok. | |
| 239 | 227 | } else { |
| 240 | 228 | wp_add_inline_style( $dep, $meta['css'] ); |
| 241 | 229 | } |
| 242 | 230 | } elseif ( self::CSS_STATUS_FILE === $meta['status'] ) { // Re-check if it's not empty after CSS update. |
| 243 | - wp_enqueue_style( $this->get_file_handle_id(), $this->get_url(), $this->get_enqueue_dependencies(), null ); | |
| 231 | + wp_enqueue_style( $this->get_file_handle_id(), $this->get_url(), $this->get_enqueue_dependencies(), null ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion | |
| 244 | 232 | } |
| 245 | 233 | |
| 246 | 234 | // Handle fonts. |
| 247 | 235 | if ( ! empty( $meta['fonts'] ) ) { |
| @@ -273,17 +261,8 @@ | ||
| 273 | 261 | * |
| 274 | 262 | * @param Base $this The current CSS file. |
| 275 | 263 | */ |
| 276 | 264 | do_action( "elementor/css-file/{$name}/enqueue", $this ); |
| 277 | - | |
| 278 | - /** | |
| 279 | - * Enqueue CSS file. | |
| 280 | - * | |
| 281 | - * Fires after enqueuing a CSS file. | |
| 282 | - * | |
| 283 | - * @param Base $this The current CSS file. | |
| 284 | - */ | |
| 285 | - do_action( 'elementor/css-file/after_enqueue', $this ); | |
| 286 | 265 | } |
| 287 | 266 | |
| 288 | 267 | /** |
| 289 | 268 | * Print CSS. |
| @@ -294,9 +273,9 @@ | ||
| 294 | 273 | * @since 1.9.4 |
| 295 | 274 | * @access public |
| 296 | 275 | */ |
| 297 | 276 | public function print_css() { |
| 298 | - echo '<style>' . $this->get_content() . '</style>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 277 | + echo '<style>' . $this->get_content() . '</style>'; // XSS ok. | |
| 299 | 278 | Plugin::$instance->frontend->print_fonts_links(); |
| 300 | 279 | } |
| 301 | 280 | |
| 302 | 281 | /** |
| @@ -360,12 +339,8 @@ | ||
| 360 | 339 | $output_css_property = preg_replace( '/(:)[^;]+(;?)/', '$1' . $selector_global_value . '$2', $css_property ); |
| 361 | 340 | } |
| 362 | 341 | } else { |
| 363 | 342 | try { |
| 364 | - if ( $this->unit_has_custom_selector( $control, $value ) ) { | |
| 365 | - $css_property = $control['unit_selectors_dictionary'][ $value['unit'] ]; | |
| 366 | - } | |
| 367 | - | |
| 368 | 343 | $output_css_property = preg_replace_callback( '/{{(?:([^.}]+)\.)?([^}| ]*)(?: *\|\| *(?:([^.}]+)\.)?([^}| ]*) *)*}}/', function( $matches ) use ( $control, $value_callback, $controls_stack, $value, $css_property ) { |
| 369 | 344 | $external_control_missing = $matches[1] && ! isset( $controls_stack[ $matches[1] ] ); |
| 370 | 345 | |
| 371 | 346 | $parsed_value = ''; |
| @@ -456,12 +431,8 @@ | ||
| 456 | 431 | $stylesheet->add_rules( $parsed_selector, $output_css_property, $query ); |
| 457 | 432 | } |
| 458 | 433 | } |
| 459 | 434 | |
| 460 | - protected function unit_has_custom_selector( $control, $value ) { | |
| 461 | - return isset( $control['unit_selectors_dictionary'] ) && isset( $control['unit_selectors_dictionary'][ $value['unit'] ] ); | |
| 462 | - } | |
| 463 | - | |
| 464 | 435 | /** |
| 465 | 436 | * @param array $control |
| 466 | 437 | * @param mixed $value |
| 467 | 438 | * @param array $controls_stack |
| @@ -490,9 +461,9 @@ | ||
| 490 | 461 | $value = $this->get_control_global_default_value( $control ); |
| 491 | 462 | } |
| 492 | 463 | |
| 493 | 464 | if ( Controls_Manager::FONT === $control['type'] ) { |
| 494 | - $this->add_font( $value ); | |
| 465 | + $this->fonts[] = $value; | |
| 495 | 466 | } |
| 496 | 467 | |
| 497 | 468 | /** @var Base_Data_Control $control_obj */ |
| 498 | 469 | $control_obj = Plugin::$instance->controls_manager->get_control( $control['type'] ); |
| @@ -548,9 +519,9 @@ | ||
| 548 | 519 | * @param array $placeholders Placeholders. |
| 549 | 520 | * @param array $replacements Replacements. |
| 550 | 521 | * @param array $all_controls All controls. |
| 551 | 522 | */ |
| 552 | - public function add_controls_stack_style_rules( Controls_Stack $controls_stack, array $controls, array $values, array $placeholders, array $replacements, ?array $all_controls = null ) { | |
| 523 | + public function add_controls_stack_style_rules( Controls_Stack $controls_stack, array $controls, array $values, array $placeholders, array $replacements, array $all_controls = null ) { | |
| 553 | 524 | if ( ! $all_controls ) { |
| 554 | 525 | $all_controls = $controls_stack->get_controls(); |
| 555 | 526 | } |
| 556 | 527 | |
| @@ -572,13 +543,8 @@ | ||
| 572 | 543 | if ( ! empty( $parsed_dynamic_settings[ Manager::DYNAMIC_SETTING_KEY ][ $control['name'] ] ) ) { |
| 573 | 544 | // Dynamic CSS should not be added to the CSS files. |
| 574 | 545 | // Instead it's handled by \Elementor\Core\DynamicTags\Dynamic_CSS |
| 575 | 546 | // and printed in a style tag. |
| 576 | - $should_preserve_value = isset( $control['control_type'] ) && 'content' === $control['control_type']; | |
| 577 | - if ( $should_preserve_value ) { | |
| 578 | - $this->preserved_dynamic_style_values[ $control['name'] ] = $parsed_dynamic_settings[ $control['name'] ]; | |
| 579 | - } | |
| 580 | - | |
| 581 | 547 | unset( $parsed_dynamic_settings[ $control['name'] ] ); |
| 582 | 548 | |
| 583 | 549 | $this->dynamic_elements_ids[] = $controls_stack->get_id(); |
| 584 | 550 | |
| @@ -677,10 +643,8 @@ | ||
| 677 | 643 | * @since 1.2.0 |
| 678 | 644 | * @access protected |
| 679 | 645 | */ |
| 680 | 646 | protected function parse_content() { |
| 681 | - Performance::set_use_style_controls( true ); | |
| 682 | - | |
| 683 | 647 | $initial_responsive_controls_duplication_mode = Plugin::$instance->breakpoints->get_responsive_control_duplication_mode(); |
| 684 | 648 | |
| 685 | 649 | Plugin::$instance->breakpoints->set_responsive_control_duplication_mode( $this->get_responsive_control_duplication_mode() ); |
| 686 | 650 | |
| @@ -702,10 +666,8 @@ | ||
| 702 | 666 | do_action( "elementor/css-file/{$name}/parse", $this ); |
| 703 | 667 | |
| 704 | 668 | Plugin::$instance->breakpoints->set_responsive_control_duplication_mode( $initial_responsive_controls_duplication_mode ); |
| 705 | 669 | |
| 706 | - Performance::set_use_style_controls( false ); | |
| 707 | - | |
| 708 | 670 | return $this->get_stylesheet()->__toString(); |
| 709 | 671 | } |
| 710 | 672 | |
| 711 | 673 | /** |
| @@ -786,11 +748,9 @@ | ||
| 786 | 748 | // When the control itself has no global value, but it refers to another control global value |
| 787 | 749 | return $this->get_selector_global_value( $control, $values['__globals__'][ $control['name'] ] ); |
| 788 | 750 | } |
| 789 | 751 | |
| 790 | - $value = isset( $values[ $control['name'] ] ) | |
| 791 | - ? $values[ $control['name'] ] | |
| 792 | - : $this->preserved_dynamic_style_values[ $control['name'] ] ?? null; | |
| 752 | + $value = $values[ $control['name'] ]; | |
| 793 | 753 | |
| 794 | 754 | if ( isset( $control['selectors_dictionary'][ $value ] ) ) { |
| 795 | 755 | $value = $control['selectors_dictionary'][ $value ]; |
| 796 | 756 | } |
| @@ -907,9 +867,9 @@ | ||
| 907 | 867 | if ( $control['groupPrefix'] . 'font_family' === $control['name'] ) { |
| 908 | 868 | $default_generic_fonts = Plugin::$instance->kits_manager->get_current_settings( 'default_generic_fonts' ); |
| 909 | 869 | |
| 910 | 870 | if ( $default_generic_fonts ) { |
| 911 | - $value .= ", $default_generic_fonts"; | |
| 871 | + $value .= ", $default_generic_fonts"; | |
| 912 | 872 | } |
| 913 | 873 | } |
| 914 | 874 | } else { |
| 915 | 875 | $value = "var( --e-global-$control[type]-$id )"; |
| @@ -917,9 +877,9 @@ | ||
| 917 | 877 | |
| 918 | 878 | return $value; |
| 919 | 879 | } |
| 920 | 880 | |
| 921 | - final protected function get_active_controls( Controls_Stack $controls_stack, ?array $controls = null, ?array $settings = null ) { | |
| 881 | + final protected function get_active_controls( Controls_Stack $controls_stack, array $controls = null, array $settings = null ) { | |
| 922 | 882 | if ( ! $controls ) { |
| 923 | 883 | $controls = $controls_stack->get_controls(); |
| 924 | 884 | } |
| 925 | 885 | |
| @@ -934,9 +894,9 @@ | ||
| 934 | 894 | $active_controls = array_reduce( |
| 935 | 895 | array_keys( $controls ), function( $active_controls, $control_key ) use ( $controls_stack, $controls, $settings ) { |
| 936 | 896 | $control = $controls[ $control_key ]; |
| 937 | 897 | |
| 938 | - if ( $controls_stack->is_control_visible( $control, $settings, $controls ) ) { | |
| 898 | + if ( $controls_stack->is_control_visible( $control, $settings ) ) { | |
| 939 | 899 | $active_controls[ $control_key ] = $control; |
| 940 | 900 | } |
| 941 | 901 | |
| 942 | 902 | return $active_controls; |
| @@ -945,9 +905,9 @@ | ||
| 945 | 905 | |
| 946 | 906 | return $active_controls; |
| 947 | 907 | } |
| 948 | 908 | |
| 949 | - final public function get_style_controls( Controls_Stack $controls_stack, ?array $controls = null, ?array $settings = null ) { | |
| 909 | + final public function get_style_controls( Controls_Stack $controls_stack, array $controls = null, array $settings = null ) { | |
| 950 | 910 | $controls = $this->get_active_controls( $controls_stack, $controls, $settings ); |
| 951 | 911 | |
| 952 | 912 | $style_controls = []; |
| 953 | 913 | |
| @@ -1024,12 +984,6 @@ | ||
| 1024 | 984 | |
| 1025 | 985 | $globals = $controls_stack->get_settings( '__globals__' ); |
| 1026 | 986 | |
| 1027 | 987 | return ! empty( $globals[ $control_global_key ] ); |
| 1028 | - } | |
| 1029 | - | |
| 1030 | - public function add_font( $font ) { | |
| 1031 | - if ( ! in_array( $font, $this->fonts, true ) ) { | |
| 1032 | - $this->fonts[] = $font; | |
| 1033 | - } | |
| 1034 | 988 | } |
| 1035 | 989 | } |