| @@ -8,10 +8,10 @@ | ||
| 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; |
| 13 | +use Elementor\Element_Base; | |
| 14 | 14 | use Elementor\Plugin; |
| 15 | 15 | use Elementor\Stylesheet; |
| 16 | 16 | use Elementor\Icons_Manager; |
| 17 | 17 | |
| @@ -64,10 +64,8 @@ | ||
| 64 | 64 | private $icons_fonts = []; |
| 65 | 65 | |
| 66 | 66 | private $dynamic_elements_ids = []; |
| 67 | 67 | |
| 68 | - private $preserved_dynamic_style_values = []; | |
| 69 | - | |
| 70 | 68 | /** |
| 71 | 69 | * Stylesheet object. |
| 72 | 70 | * |
| 73 | 71 | * Holds the CSS file stylesheet instance. |
| @@ -214,17 +212,8 @@ | ||
| 214 | 212 | if ( self::CSS_STATUS_EMPTY === $meta['status'] ) { |
| 215 | 213 | return; |
| 216 | 214 | } |
| 217 | 215 | |
| 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 | 216 | // First time after clear cache and etc. |
| 228 | 217 | if ( '' === $meta['status'] || $this->is_update_required() ) { |
| 229 | 218 | $this->update(); |
| 230 | 219 | |
| @@ -234,14 +223,14 @@ | ||
| 234 | 223 | if ( self::CSS_STATUS_INLINE === $meta['status'] ) { |
| 235 | 224 | $dep = $this->get_inline_dependency(); |
| 236 | 225 | // If the dependency has already been printed ( like a template in footer ) |
| 237 | 226 | 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 | |
| 227 | + printf( '<style id="%1$s">%2$s</style>', $this->get_file_handle_id(), $meta['css'] ); // XSS ok. | |
| 239 | 228 | } else { |
| 240 | 229 | wp_add_inline_style( $dep, $meta['css'] ); |
| 241 | 230 | } |
| 242 | 231 | } 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 ); | |
| 232 | + wp_enqueue_style( $this->get_file_handle_id(), $this->get_url(), $this->get_enqueue_dependencies(), null ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion | |
| 244 | 233 | } |
| 245 | 234 | |
| 246 | 235 | // Handle fonts. |
| 247 | 236 | if ( ! empty( $meta['fonts'] ) ) { |
| @@ -273,17 +262,8 @@ | ||
| 273 | 262 | * |
| 274 | 263 | * @param Base $this The current CSS file. |
| 275 | 264 | */ |
| 276 | 265 | 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 | 266 | } |
| 287 | 267 | |
| 288 | 268 | /** |
| 289 | 269 | * Print CSS. |
| @@ -294,9 +274,9 @@ | ||
| 294 | 274 | * @since 1.9.4 |
| 295 | 275 | * @access public |
| 296 | 276 | */ |
| 297 | 277 | public function print_css() { |
| 298 | - echo '<style>' . $this->get_content() . '</style>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 278 | + echo '<style>' . $this->get_content() . '</style>'; // XSS ok. | |
| 299 | 279 | Plugin::$instance->frontend->print_fonts_links(); |
| 300 | 280 | } |
| 301 | 281 | |
| 302 | 282 | /** |
| @@ -347,10 +327,8 @@ | ||
| 347 | 327 | } |
| 348 | 328 | |
| 349 | 329 | $stylesheet = $this->get_stylesheet(); |
| 350 | 330 | |
| 351 | - $control = apply_filters( 'elementor/files/css/selectors', $control, $value ?? [], $this ); | |
| 352 | - | |
| 353 | 331 | foreach ( $control['selectors'] as $selector => $css_property ) { |
| 354 | 332 | $output_css_property = ''; |
| 355 | 333 | |
| 356 | 334 | if ( $global_key ) { |
| @@ -360,19 +338,13 @@ | ||
| 360 | 338 | $output_css_property = preg_replace( '/(:)[^;]+(;?)/', '$1' . $selector_global_value . '$2', $css_property ); |
| 361 | 339 | } |
| 362 | 340 | } else { |
| 363 | 341 | try { |
| 364 | - if ( $this->unit_has_custom_selector( $control, $value ) ) { | |
| 365 | - $css_property = $control['unit_selectors_dictionary'][ $value['unit'] ]; | |
| 366 | - } | |
| 367 | - | |
| 368 | 342 | $output_css_property = preg_replace_callback( '/{{(?:([^.}]+)\.)?([^}| ]*)(?: *\|\| *(?:([^.}]+)\.)?([^}| ]*) *)*}}/', function( $matches ) use ( $control, $value_callback, $controls_stack, $value, $css_property ) { |
| 369 | 343 | $external_control_missing = $matches[1] && ! isset( $controls_stack[ $matches[1] ] ); |
| 370 | 344 | |
| 371 | 345 | $parsed_value = ''; |
| 372 | 346 | |
| 373 | - $value = apply_filters( 'elementor/files/css/property', $value, $css_property, $matches, $control ); | |
| 374 | - | |
| 375 | 347 | if ( ! $external_control_missing ) { |
| 376 | 348 | $parsed_value = $this->parse_property_placeholder( $control, $value, $controls_stack, $value_callback, $matches[2], $matches[1] ); |
| 377 | 349 | } |
| 378 | 350 | |
| @@ -401,12 +373,8 @@ | ||
| 401 | 373 | throw new \Exception(); |
| 402 | 374 | } |
| 403 | 375 | } |
| 404 | 376 | |
| 405 | - if ( '__EMPTY__' === $parsed_value ) { | |
| 406 | - $parsed_value = ''; | |
| 407 | - } | |
| 408 | - | |
| 409 | 377 | return $parsed_value; |
| 410 | 378 | }, $css_property ); |
| 411 | 379 | } catch ( \Exception $e ) { |
| 412 | 380 | return; |
| @@ -456,12 +424,8 @@ | ||
| 456 | 424 | $stylesheet->add_rules( $parsed_selector, $output_css_property, $query ); |
| 457 | 425 | } |
| 458 | 426 | } |
| 459 | 427 | |
| 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 | 428 | /** |
| 465 | 429 | * @param array $control |
| 466 | 430 | * @param mixed $value |
| 467 | 431 | * @param array $controls_stack |
| @@ -472,27 +436,15 @@ | ||
| 472 | 436 | * @return string |
| 473 | 437 | */ |
| 474 | 438 | public function parse_property_placeholder( array $control, $value, array $controls_stack, $value_callback, $placeholder, $parser_control_name = null ) { |
| 475 | 439 | if ( $parser_control_name ) { |
| 476 | - // If both the processed control and the control name found in the placeholder are responsive | |
| 477 | - if ( ! empty( $control['responsive'] ) && ! empty( $controls_stack[ $parser_control_name ]['responsive'] ) ) { | |
| 478 | - $device_suffix = Controls_Manager::get_responsive_control_device_suffix( $control ); | |
| 440 | + $control = $controls_stack[ $parser_control_name ]; | |
| 479 | 441 | |
| 480 | - $control = $controls_stack[ $parser_control_name . $device_suffix ] ?? $controls_stack[ $parser_control_name ]; | |
| 481 | - } else { | |
| 482 | - $control = $controls_stack[ $parser_control_name ]; | |
| 483 | - } | |
| 484 | - | |
| 485 | 442 | $value = call_user_func( $value_callback, $control ); |
| 486 | 443 | } |
| 487 | 444 | |
| 488 | - // If the control value is empty, check for global default. `0` (integer, string) are falsy but are valid values. | |
| 489 | - if ( empty( $value ) && '0' !== $value && 0 !== $value ) { | |
| 490 | - $value = $this->get_control_global_default_value( $control ); | |
| 491 | - } | |
| 492 | - | |
| 493 | 445 | if ( Controls_Manager::FONT === $control['type'] ) { |
| 494 | - $this->add_font( $value ); | |
| 446 | + $this->fonts[] = $value; | |
| 495 | 447 | } |
| 496 | 448 | |
| 497 | 449 | /** @var Base_Data_Control $control_obj */ |
| 498 | 450 | $control_obj = Plugin::$instance->controls_manager->get_control( $control['type'] ); |
| @@ -548,9 +500,9 @@ | ||
| 548 | 500 | * @param array $placeholders Placeholders. |
| 549 | 501 | * @param array $replacements Replacements. |
| 550 | 502 | * @param array $all_controls All controls. |
| 551 | 503 | */ |
| 552 | - public function add_controls_stack_style_rules( Controls_Stack $controls_stack, array $controls, array $values, array $placeholders, array $replacements, ?array $all_controls = null ) { | |
| 504 | + public function add_controls_stack_style_rules( Controls_Stack $controls_stack, array $controls, array $values, array $placeholders, array $replacements, array $all_controls = null ) { | |
| 553 | 505 | if ( ! $all_controls ) { |
| 554 | 506 | $all_controls = $controls_stack->get_controls(); |
| 555 | 507 | } |
| 556 | 508 | |
| @@ -572,13 +524,8 @@ | ||
| 572 | 524 | if ( ! empty( $parsed_dynamic_settings[ Manager::DYNAMIC_SETTING_KEY ][ $control['name'] ] ) ) { |
| 573 | 525 | // Dynamic CSS should not be added to the CSS files. |
| 574 | 526 | // Instead it's handled by \Elementor\Core\DynamicTags\Dynamic_CSS |
| 575 | 527 | // 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 | 528 | unset( $parsed_dynamic_settings[ $control['name'] ] ); |
| 582 | 529 | |
| 583 | 530 | $this->dynamic_elements_ids[] = $controls_stack->get_id(); |
| 584 | 531 | |
| @@ -677,10 +624,8 @@ | ||
| 677 | 624 | * @since 1.2.0 |
| 678 | 625 | * @access protected |
| 679 | 626 | */ |
| 680 | 627 | protected function parse_content() { |
| 681 | - Performance::set_use_style_controls( true ); | |
| 682 | - | |
| 683 | 628 | $initial_responsive_controls_duplication_mode = Plugin::$instance->breakpoints->get_responsive_control_duplication_mode(); |
| 684 | 629 | |
| 685 | 630 | Plugin::$instance->breakpoints->set_responsive_control_duplication_mode( $this->get_responsive_control_duplication_mode() ); |
| 686 | 631 | |
| @@ -702,10 +647,8 @@ | ||
| 702 | 647 | do_action( "elementor/css-file/{$name}/parse", $this ); |
| 703 | 648 | |
| 704 | 649 | Plugin::$instance->breakpoints->set_responsive_control_duplication_mode( $initial_responsive_controls_duplication_mode ); |
| 705 | 650 | |
| 706 | - Performance::set_use_style_controls( false ); | |
| 707 | - | |
| 708 | 651 | return $this->get_stylesheet()->__toString(); |
| 709 | 652 | } |
| 710 | 653 | |
| 711 | 654 | /** |
| @@ -730,44 +673,8 @@ | ||
| 730 | 673 | ); |
| 731 | 674 | } |
| 732 | 675 | |
| 733 | 676 | /** |
| 734 | - * Get Control Global Default Value | |
| 735 | - * | |
| 736 | - * If the control has a global default value, and the corresponding global default setting is enabled, this method | |
| 737 | - * fetches and returns the global default value. Otherwise, it returns null. | |
| 738 | - * | |
| 739 | - * @since 3.7.0 | |
| 740 | - * @access private | |
| 741 | - * | |
| 742 | - * @param $control | |
| 743 | - * @return string|null | |
| 744 | - */ | |
| 745 | - private function get_control_global_default_value( $control ) { | |
| 746 | - if ( empty( $control['global']['default'] ) ) { | |
| 747 | - return null; | |
| 748 | - } | |
| 749 | - | |
| 750 | - // If the control value is empty, and the control has a global default set, fetch the global value and use it. | |
| 751 | - $global_enabled = false; | |
| 752 | - | |
| 753 | - if ( 'color' === $control['type'] ) { | |
| 754 | - $global_enabled = Plugin::$instance->kits_manager->is_custom_colors_enabled(); | |
| 755 | - } elseif ( isset( $control['groupType'] ) && 'typography' === $control['groupType'] ) { | |
| 756 | - $global_enabled = Plugin::$instance->kits_manager->is_custom_typography_enabled(); | |
| 757 | - } | |
| 758 | - | |
| 759 | - $value = null; | |
| 760 | - | |
| 761 | - // Only apply the global default if Global Colors are enabled. | |
| 762 | - if ( $global_enabled ) { | |
| 763 | - $value = $this->get_selector_global_value( $control, $control['global']['default'] ); | |
| 764 | - } | |
| 765 | - | |
| 766 | - return $value; | |
| 767 | - } | |
| 768 | - | |
| 769 | - /** | |
| 770 | 677 | * Get style control value. |
| 771 | 678 | * |
| 772 | 679 | * Retrieve the value of the style control for any give control and values. |
| 773 | 680 | * |
| @@ -786,11 +693,9 @@ | ||
| 786 | 693 | // When the control itself has no global value, but it refers to another control global value |
| 787 | 694 | return $this->get_selector_global_value( $control, $values['__globals__'][ $control['name'] ] ); |
| 788 | 695 | } |
| 789 | 696 | |
| 790 | - $value = isset( $values[ $control['name'] ] ) | |
| 791 | - ? $values[ $control['name'] ] | |
| 792 | - : $this->preserved_dynamic_style_values[ $control['name'] ] ?? null; | |
| 697 | + $value = $values[ $control['name'] ]; | |
| 793 | 698 | |
| 794 | 699 | if ( isset( $control['selectors_dictionary'][ $value ] ) ) { |
| 795 | 700 | $value = $control['selectors_dictionary'][ $value ]; |
| 796 | 701 | } |
| @@ -907,9 +812,9 @@ | ||
| 907 | 812 | if ( $control['groupPrefix'] . 'font_family' === $control['name'] ) { |
| 908 | 813 | $default_generic_fonts = Plugin::$instance->kits_manager->get_current_settings( 'default_generic_fonts' ); |
| 909 | 814 | |
| 910 | 815 | if ( $default_generic_fonts ) { |
| 911 | - $value .= ", $default_generic_fonts"; | |
| 816 | + $value .= ", $default_generic_fonts"; | |
| 912 | 817 | } |
| 913 | 818 | } |
| 914 | 819 | } else { |
| 915 | 820 | $value = "var( --e-global-$control[type]-$id )"; |
| @@ -917,9 +822,9 @@ | ||
| 917 | 822 | |
| 918 | 823 | return $value; |
| 919 | 824 | } |
| 920 | 825 | |
| 921 | - final protected function get_active_controls( Controls_Stack $controls_stack, ?array $controls = null, ?array $settings = null ) { | |
| 826 | + final protected function get_active_controls( Controls_Stack $controls_stack, array $controls = null, array $settings = null ) { | |
| 922 | 827 | if ( ! $controls ) { |
| 923 | 828 | $controls = $controls_stack->get_controls(); |
| 924 | 829 | } |
| 925 | 830 | |
| @@ -934,9 +839,9 @@ | ||
| 934 | 839 | $active_controls = array_reduce( |
| 935 | 840 | array_keys( $controls ), function( $active_controls, $control_key ) use ( $controls_stack, $controls, $settings ) { |
| 936 | 841 | $control = $controls[ $control_key ]; |
| 937 | 842 | |
| 938 | - if ( $controls_stack->is_control_visible( $control, $settings, $controls ) ) { | |
| 843 | + if ( $controls_stack->is_control_visible( $control, $settings ) ) { | |
| 939 | 844 | $active_controls[ $control_key ] = $control; |
| 940 | 845 | } |
| 941 | 846 | |
| 942 | 847 | return $active_controls; |
| @@ -945,9 +850,9 @@ | ||
| 945 | 850 | |
| 946 | 851 | return $active_controls; |
| 947 | 852 | } |
| 948 | 853 | |
| 949 | - final public function get_style_controls( Controls_Stack $controls_stack, ?array $controls = null, ?array $settings = null ) { | |
| 854 | + final public function get_style_controls( Controls_Stack $controls_stack, array $controls = null, array $settings = null ) { | |
| 950 | 855 | $controls = $this->get_active_controls( $controls_stack, $controls, $settings ); |
| 951 | 856 | |
| 952 | 857 | $style_controls = []; |
| 953 | 858 | |
| @@ -1024,12 +929,6 @@ | ||
| 1024 | 929 | |
| 1025 | 930 | $globals = $controls_stack->get_settings( '__globals__' ); |
| 1026 | 931 | |
| 1027 | 932 | 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 | 933 | } |
| 1035 | 934 | } |