| @@ -8,11 +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 | -use Elementor\Core\Frontend\Widget_Content_Render_Mode; | |
| 14 | 12 | use Elementor\Core\Kits\Documents\Tabs\Global_Typography; |
| 13 | +use Elementor\Element_Base; | |
| 15 | 14 | use Elementor\Plugin; |
| 16 | 15 | use Elementor\Stylesheet; |
| 17 | 16 | use Elementor\Icons_Manager; |
| 18 | 17 | |
| @@ -65,10 +64,8 @@ | ||
| 65 | 64 | private $icons_fonts = []; |
| 66 | 65 | |
| 67 | 66 | private $dynamic_elements_ids = []; |
| 68 | 67 | |
| 69 | - private $preserved_dynamic_style_values = []; | |
| 70 | - | |
| 71 | 68 | /** |
| 72 | 69 | * Stylesheet object. |
| 73 | 70 | * |
| 74 | 71 | * Holds the CSS file stylesheet instance. |
| @@ -201,12 +198,8 @@ | ||
| 201 | 198 | * @since 1.2.0 |
| 202 | 199 | * @access public |
| 203 | 200 | */ |
| 204 | 201 | public function enqueue() { |
| 205 | - if ( $this->should_skip_enqueue() ) { | |
| 206 | - return; | |
| 207 | - } | |
| 208 | - | |
| 209 | 202 | $handle_id = $this->get_file_handle_id(); |
| 210 | 203 | |
| 211 | 204 | if ( isset( self::$printed[ $handle_id ] ) ) { |
| 212 | 205 | return; |
| @@ -219,17 +212,8 @@ | ||
| 219 | 212 | if ( self::CSS_STATUS_EMPTY === $meta['status'] ) { |
| 220 | 213 | return; |
| 221 | 214 | } |
| 222 | 215 | |
| 223 | - /** | |
| 224 | - * Enqueue CSS file. | |
| 225 | - * | |
| 226 | - * Fires before enqueuing a CSS file. | |
| 227 | - * | |
| 228 | - * @param Base $this The current CSS file. | |
| 229 | - */ | |
| 230 | - do_action( 'elementor/css-file/before_enqueue', $this ); | |
| 231 | - | |
| 232 | 216 | // First time after clear cache and etc. |
| 233 | 217 | if ( '' === $meta['status'] || $this->is_update_required() ) { |
| 234 | 218 | $this->update(); |
| 235 | 219 | |
| @@ -237,17 +221,16 @@ | ||
| 237 | 221 | } |
| 238 | 222 | |
| 239 | 223 | if ( self::CSS_STATUS_INLINE === $meta['status'] ) { |
| 240 | 224 | $dep = $this->get_inline_dependency(); |
| 241 | - $is_dependency_registered = (bool) wp_styles()->query( $dep, 'registered' ); | |
| 242 | - | |
| 243 | - if ( ! $is_dependency_registered || wp_styles()->query( $dep, 'done' ) ) { | |
| 244 | - printf( '<style id="%1$s">%2$s</style>', $this->get_file_handle_id(), $meta['css'] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 225 | + // If the dependency has already been printed ( like a template in footer ) | |
| 226 | + if ( wp_styles()->query( $dep, 'done' ) ) { | |
| 227 | + printf( '<style id="%1$s">%2$s</style>', $this->get_file_handle_id(), $meta['css'] ); // XSS ok. | |
| 245 | 228 | } else { |
| 246 | 229 | wp_add_inline_style( $dep, $meta['css'] ); |
| 247 | 230 | } |
| 248 | 231 | } elseif ( self::CSS_STATUS_FILE === $meta['status'] ) { // Re-check if it's not empty after CSS update. |
| 249 | - wp_enqueue_style( $this->get_file_handle_id(), $this->get_url(), $this->get_registered_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 | |
| 250 | 233 | } |
| 251 | 234 | |
| 252 | 235 | // Handle fonts. |
| 253 | 236 | if ( ! empty( $meta['fonts'] ) ) { |
| @@ -279,17 +262,8 @@ | ||
| 279 | 262 | * |
| 280 | 263 | * @param Base $this The current CSS file. |
| 281 | 264 | */ |
| 282 | 265 | do_action( "elementor/css-file/{$name}/enqueue", $this ); |
| 283 | - | |
| 284 | - /** | |
| 285 | - * Enqueue CSS file. | |
| 286 | - * | |
| 287 | - * Fires after enqueuing a CSS file. | |
| 288 | - * | |
| 289 | - * @param Base $this The current CSS file. | |
| 290 | - */ | |
| 291 | - do_action( 'elementor/css-file/after_enqueue', $this ); | |
| 292 | 266 | } |
| 293 | 267 | |
| 294 | 268 | /** |
| 295 | 269 | * Print CSS. |
| @@ -300,9 +274,9 @@ | ||
| 300 | 274 | * @since 1.9.4 |
| 301 | 275 | * @access public |
| 302 | 276 | */ |
| 303 | 277 | public function print_css() { |
| 304 | - echo '<style>' . $this->get_content() . '</style>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 278 | + echo '<style>' . $this->get_content() . '</style>'; // XSS ok. | |
| 305 | 279 | Plugin::$instance->frontend->print_fonts_links(); |
| 306 | 280 | } |
| 307 | 281 | |
| 308 | 282 | /** |
| @@ -353,10 +327,8 @@ | ||
| 353 | 327 | } |
| 354 | 328 | |
| 355 | 329 | $stylesheet = $this->get_stylesheet(); |
| 356 | 330 | |
| 357 | - $control = apply_filters( 'elementor/files/css/selectors', $control, $value ?? [], $this ); | |
| 358 | - | |
| 359 | 331 | foreach ( $control['selectors'] as $selector => $css_property ) { |
| 360 | 332 | $output_css_property = ''; |
| 361 | 333 | |
| 362 | 334 | if ( $global_key ) { |
| @@ -366,19 +338,13 @@ | ||
| 366 | 338 | $output_css_property = preg_replace( '/(:)[^;]+(;?)/', '$1' . $selector_global_value . '$2', $css_property ); |
| 367 | 339 | } |
| 368 | 340 | } else { |
| 369 | 341 | try { |
| 370 | - if ( $this->unit_has_custom_selector( $control, $value ) ) { | |
| 371 | - $css_property = $control['unit_selectors_dictionary'][ $value['unit'] ]; | |
| 372 | - } | |
| 373 | - | |
| 374 | 342 | $output_css_property = preg_replace_callback( '/{{(?:([^.}]+)\.)?([^}| ]*)(?: *\|\| *(?:([^.}]+)\.)?([^}| ]*) *)*}}/', function( $matches ) use ( $control, $value_callback, $controls_stack, $value, $css_property ) { |
| 375 | 343 | $external_control_missing = $matches[1] && ! isset( $controls_stack[ $matches[1] ] ); |
| 376 | 344 | |
| 377 | 345 | $parsed_value = ''; |
| 378 | 346 | |
| 379 | - $value = apply_filters( 'elementor/files/css/property', $value, $css_property, $matches, $control ); | |
| 380 | - | |
| 381 | 347 | if ( ! $external_control_missing ) { |
| 382 | 348 | $parsed_value = $this->parse_property_placeholder( $control, $value, $controls_stack, $value_callback, $matches[2], $matches[1] ); |
| 383 | 349 | } |
| 384 | 350 | |
| @@ -407,12 +373,8 @@ | ||
| 407 | 373 | throw new \Exception(); |
| 408 | 374 | } |
| 409 | 375 | } |
| 410 | 376 | |
| 411 | - if ( '__EMPTY__' === $parsed_value ) { | |
| 412 | - $parsed_value = ''; | |
| 413 | - } | |
| 414 | - | |
| 415 | 377 | return $parsed_value; |
| 416 | 378 | }, $css_property ); |
| 417 | 379 | } catch ( \Exception $e ) { |
| 418 | 380 | return; |
| @@ -462,12 +424,8 @@ | ||
| 462 | 424 | $stylesheet->add_rules( $parsed_selector, $output_css_property, $query ); |
| 463 | 425 | } |
| 464 | 426 | } |
| 465 | 427 | |
| 466 | - protected function unit_has_custom_selector( $control, $value ) { | |
| 467 | - return isset( $control['unit_selectors_dictionary'] ) && isset( $control['unit_selectors_dictionary'][ $value['unit'] ] ); | |
| 468 | - } | |
| 469 | - | |
| 470 | 428 | /** |
| 471 | 429 | * @param array $control |
| 472 | 430 | * @param mixed $value |
| 473 | 431 | * @param array $controls_stack |
| @@ -478,27 +436,15 @@ | ||
| 478 | 436 | * @return string |
| 479 | 437 | */ |
| 480 | 438 | public function parse_property_placeholder( array $control, $value, array $controls_stack, $value_callback, $placeholder, $parser_control_name = null ) { |
| 481 | 439 | if ( $parser_control_name ) { |
| 482 | - // If both the processed control and the control name found in the placeholder are responsive | |
| 483 | - if ( ! empty( $control['responsive'] ) && ! empty( $controls_stack[ $parser_control_name ]['responsive'] ) ) { | |
| 484 | - $device_suffix = Controls_Manager::get_responsive_control_device_suffix( $control ); | |
| 440 | + $control = $controls_stack[ $parser_control_name ]; | |
| 485 | 441 | |
| 486 | - $control = $controls_stack[ $parser_control_name . $device_suffix ] ?? $controls_stack[ $parser_control_name ]; | |
| 487 | - } else { | |
| 488 | - $control = $controls_stack[ $parser_control_name ]; | |
| 489 | - } | |
| 490 | - | |
| 491 | 442 | $value = call_user_func( $value_callback, $control ); |
| 492 | 443 | } |
| 493 | 444 | |
| 494 | - // If the control value is empty, check for global default. `0` (integer, string) are falsy but are valid values. | |
| 495 | - if ( empty( $value ) && '0' !== $value && 0 !== $value ) { | |
| 496 | - $value = $this->get_control_global_default_value( $control ); | |
| 497 | - } | |
| 498 | - | |
| 499 | 445 | if ( Controls_Manager::FONT === $control['type'] ) { |
| 500 | - $this->add_font( $value ); | |
| 446 | + $this->fonts[] = $value; | |
| 501 | 447 | } |
| 502 | 448 | |
| 503 | 449 | /** @var Base_Data_Control $control_obj */ |
| 504 | 450 | $control_obj = Plugin::$instance->controls_manager->get_control( $control['type'] ); |
| @@ -554,9 +500,9 @@ | ||
| 554 | 500 | * @param array $placeholders Placeholders. |
| 555 | 501 | * @param array $replacements Replacements. |
| 556 | 502 | * @param array $all_controls All controls. |
| 557 | 503 | */ |
| 558 | - 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 ) { | |
| 559 | 505 | if ( ! $all_controls ) { |
| 560 | 506 | $all_controls = $controls_stack->get_controls(); |
| 561 | 507 | } |
| 562 | 508 | |
| @@ -578,13 +524,8 @@ | ||
| 578 | 524 | if ( ! empty( $parsed_dynamic_settings[ Manager::DYNAMIC_SETTING_KEY ][ $control['name'] ] ) ) { |
| 579 | 525 | // Dynamic CSS should not be added to the CSS files. |
| 580 | 526 | // Instead it's handled by \Elementor\Core\DynamicTags\Dynamic_CSS |
| 581 | 527 | // and printed in a style tag. |
| 582 | - $should_preserve_value = isset( $control['control_type'] ) && 'content' === $control['control_type']; | |
| 583 | - if ( $should_preserve_value ) { | |
| 584 | - $this->preserved_dynamic_style_values[ $control['name'] ] = $parsed_dynamic_settings[ $control['name'] ]; | |
| 585 | - } | |
| 586 | - | |
| 587 | 528 | unset( $parsed_dynamic_settings[ $control['name'] ] ); |
| 588 | 529 | |
| 589 | 530 | $this->dynamic_elements_ids[] = $controls_stack->get_id(); |
| 590 | 531 | |
| @@ -611,31 +552,8 @@ | ||
| 611 | 552 | * @return string CSS file handle ID. |
| 612 | 553 | */ |
| 613 | 554 | abstract protected function get_file_handle_id(); |
| 614 | 555 | |
| 615 | - protected function should_skip_enqueue(): bool { | |
| 616 | - if ( Widget_Content_Render_Mode::is( Widget_Content_Render_Mode::MARKDOWN ) ) { | |
| 617 | - return true; | |
| 618 | - } | |
| 619 | - | |
| 620 | - if ( ! is_admin() ) { | |
| 621 | - return false; | |
| 622 | - } | |
| 623 | - | |
| 624 | - $editor = Plugin::$instance->editor; | |
| 625 | - | |
| 626 | - return $editor && $editor->is_editor_request(); | |
| 627 | - } | |
| 628 | - | |
| 629 | - protected function get_registered_enqueue_dependencies(): array { | |
| 630 | - return array_values( array_filter( | |
| 631 | - $this->get_enqueue_dependencies(), | |
| 632 | - static function ( $handle ) { | |
| 633 | - return (bool) wp_styles()->query( $handle, 'registered' ); | |
| 634 | - } | |
| 635 | - ) ); | |
| 636 | - } | |
| 637 | - | |
| 638 | 556 | /** |
| 639 | 557 | * Render CSS. |
| 640 | 558 | * |
| 641 | 559 | * Parse the CSS. |
| @@ -706,10 +624,8 @@ | ||
| 706 | 624 | * @since 1.2.0 |
| 707 | 625 | * @access protected |
| 708 | 626 | */ |
| 709 | 627 | protected function parse_content() { |
| 710 | - Performance::set_use_style_controls( true ); | |
| 711 | - | |
| 712 | 628 | $initial_responsive_controls_duplication_mode = Plugin::$instance->breakpoints->get_responsive_control_duplication_mode(); |
| 713 | 629 | |
| 714 | 630 | Plugin::$instance->breakpoints->set_responsive_control_duplication_mode( $this->get_responsive_control_duplication_mode() ); |
| 715 | 631 | |
| @@ -731,10 +647,8 @@ | ||
| 731 | 647 | do_action( "elementor/css-file/{$name}/parse", $this ); |
| 732 | 648 | |
| 733 | 649 | Plugin::$instance->breakpoints->set_responsive_control_duplication_mode( $initial_responsive_controls_duplication_mode ); |
| 734 | 650 | |
| 735 | - Performance::set_use_style_controls( false ); | |
| 736 | - | |
| 737 | 651 | return $this->get_stylesheet()->__toString(); |
| 738 | 652 | } |
| 739 | 653 | |
| 740 | 654 | /** |
| @@ -759,44 +673,8 @@ | ||
| 759 | 673 | ); |
| 760 | 674 | } |
| 761 | 675 | |
| 762 | 676 | /** |
| 763 | - * Get Control Global Default Value | |
| 764 | - * | |
| 765 | - * If the control has a global default value, and the corresponding global default setting is enabled, this method | |
| 766 | - * fetches and returns the global default value. Otherwise, it returns null. | |
| 767 | - * | |
| 768 | - * @since 3.7.0 | |
| 769 | - * @access private | |
| 770 | - * | |
| 771 | - * @param $control | |
| 772 | - * @return string|null | |
| 773 | - */ | |
| 774 | - private function get_control_global_default_value( $control ) { | |
| 775 | - if ( empty( $control['global']['default'] ) ) { | |
| 776 | - return null; | |
| 777 | - } | |
| 778 | - | |
| 779 | - // If the control value is empty, and the control has a global default set, fetch the global value and use it. | |
| 780 | - $global_enabled = false; | |
| 781 | - | |
| 782 | - if ( 'color' === $control['type'] ) { | |
| 783 | - $global_enabled = Plugin::$instance->kits_manager->is_custom_colors_enabled(); | |
| 784 | - } elseif ( isset( $control['groupType'] ) && 'typography' === $control['groupType'] ) { | |
| 785 | - $global_enabled = Plugin::$instance->kits_manager->is_custom_typography_enabled(); | |
| 786 | - } | |
| 787 | - | |
| 788 | - $value = null; | |
| 789 | - | |
| 790 | - // Only apply the global default if Global Colors are enabled. | |
| 791 | - if ( $global_enabled ) { | |
| 792 | - $value = $this->get_selector_global_value( $control, $control['global']['default'] ); | |
| 793 | - } | |
| 794 | - | |
| 795 | - return $value; | |
| 796 | - } | |
| 797 | - | |
| 798 | - /** | |
| 799 | 677 | * Get style control value. |
| 800 | 678 | * |
| 801 | 679 | * Retrieve the value of the style control for any give control and values. |
| 802 | 680 | * |
| @@ -815,11 +693,9 @@ | ||
| 815 | 693 | // When the control itself has no global value, but it refers to another control global value |
| 816 | 694 | return $this->get_selector_global_value( $control, $values['__globals__'][ $control['name'] ] ); |
| 817 | 695 | } |
| 818 | 696 | |
| 819 | - $value = isset( $values[ $control['name'] ] ) | |
| 820 | - ? $values[ $control['name'] ] | |
| 821 | - : $this->preserved_dynamic_style_values[ $control['name'] ] ?? null; | |
| 697 | + $value = $values[ $control['name'] ]; | |
| 822 | 698 | |
| 823 | 699 | if ( isset( $control['selectors_dictionary'][ $value ] ) ) { |
| 824 | 700 | $value = $control['selectors_dictionary'][ $value ]; |
| 825 | 701 | } |
| @@ -936,9 +812,9 @@ | ||
| 936 | 812 | if ( $control['groupPrefix'] . 'font_family' === $control['name'] ) { |
| 937 | 813 | $default_generic_fonts = Plugin::$instance->kits_manager->get_current_settings( 'default_generic_fonts' ); |
| 938 | 814 | |
| 939 | 815 | if ( $default_generic_fonts ) { |
| 940 | - $value .= ", $default_generic_fonts"; | |
| 816 | + $value .= ", $default_generic_fonts"; | |
| 941 | 817 | } |
| 942 | 818 | } |
| 943 | 819 | } else { |
| 944 | 820 | $value = "var( --e-global-$control[type]-$id )"; |
| @@ -946,9 +822,9 @@ | ||
| 946 | 822 | |
| 947 | 823 | return $value; |
| 948 | 824 | } |
| 949 | 825 | |
| 950 | - 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 ) { | |
| 951 | 827 | if ( ! $controls ) { |
| 952 | 828 | $controls = $controls_stack->get_controls(); |
| 953 | 829 | } |
| 954 | 830 | |
| @@ -963,9 +839,9 @@ | ||
| 963 | 839 | $active_controls = array_reduce( |
| 964 | 840 | array_keys( $controls ), function( $active_controls, $control_key ) use ( $controls_stack, $controls, $settings ) { |
| 965 | 841 | $control = $controls[ $control_key ]; |
| 966 | 842 | |
| 967 | - if ( $controls_stack->is_control_visible( $control, $settings, $controls ) ) { | |
| 843 | + if ( $controls_stack->is_control_visible( $control, $settings ) ) { | |
| 968 | 844 | $active_controls[ $control_key ] = $control; |
| 969 | 845 | } |
| 970 | 846 | |
| 971 | 847 | return $active_controls; |
| @@ -974,9 +850,9 @@ | ||
| 974 | 850 | |
| 975 | 851 | return $active_controls; |
| 976 | 852 | } |
| 977 | 853 | |
| 978 | - 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 ) { | |
| 979 | 855 | $controls = $this->get_active_controls( $controls_stack, $controls, $settings ); |
| 980 | 856 | |
| 981 | 857 | $style_controls = []; |
| 982 | 858 | |
| @@ -1053,12 +929,6 @@ | ||
| 1053 | 929 | |
| 1054 | 930 | $globals = $controls_stack->get_settings( '__globals__' ); |
| 1055 | 931 | |
| 1056 | 932 | return ! empty( $globals[ $control_global_key ] ); |
| 1057 | - } | |
| 1058 | - | |
| 1059 | - public function add_font( $font ) { | |
| 1060 | - if ( ! in_array( $font, $this->fonts, true ) ) { | |
| 1061 | - $this->fonts[] = $font; | |
| 1062 | - } | |
| 1063 | 933 | } |
| 1064 | 934 | } |