| @@ -8,10 +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 | -use Elementor\Core\Frontend\Widget_Content_Render_Mode; | |
| 14 | 12 | use Elementor\Core\Kits\Documents\Tabs\Global_Typography; |
| 15 | 13 | use Elementor\Plugin; |
| 16 | 14 | use Elementor\Stylesheet; |
| 17 | 15 | use Elementor\Icons_Manager; |
| @@ -65,10 +63,8 @@ | ||
| 65 | 63 | private $icons_fonts = []; |
| 66 | 64 | |
| 67 | 65 | private $dynamic_elements_ids = []; |
| 68 | 66 | |
| 69 | - private $preserved_dynamic_style_values = []; | |
| 70 | - | |
| 71 | 67 | /** |
| 72 | 68 | * Stylesheet object. |
| 73 | 69 | * |
| 74 | 70 | * Holds the CSS file stylesheet instance. |
| @@ -201,12 +197,8 @@ | ||
| 201 | 197 | * @since 1.2.0 |
| 202 | 198 | * @access public |
| 203 | 199 | */ |
| 204 | 200 | public function enqueue() { |
| 205 | - if ( $this->should_skip_enqueue() ) { | |
| 206 | - return; | |
| 207 | - } | |
| 208 | - | |
| 209 | 201 | $handle_id = $this->get_file_handle_id(); |
| 210 | 202 | |
| 211 | 203 | if ( isset( self::$printed[ $handle_id ] ) ) { |
| 212 | 204 | return; |
| @@ -219,17 +211,8 @@ | ||
| 219 | 211 | if ( self::CSS_STATUS_EMPTY === $meta['status'] ) { |
| 220 | 212 | return; |
| 221 | 213 | } |
| 222 | 214 | |
| 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 | 215 | // First time after clear cache and etc. |
| 233 | 216 | if ( '' === $meta['status'] || $this->is_update_required() ) { |
| 234 | 217 | $this->update(); |
| 235 | 218 | |
| @@ -237,17 +220,16 @@ | ||
| 237 | 220 | } |
| 238 | 221 | |
| 239 | 222 | if ( self::CSS_STATUS_INLINE === $meta['status'] ) { |
| 240 | 223 | $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 | |
| 224 | + // If the dependency has already been printed ( like a template in footer ) | |
| 225 | + if ( wp_styles()->query( $dep, 'done' ) ) { | |
| 226 | + printf( '<style id="%1$s">%2$s</style>', $this->get_file_handle_id(), $meta['css'] ); // XSS ok. | |
| 245 | 227 | } else { |
| 246 | 228 | wp_add_inline_style( $dep, $meta['css'] ); |
| 247 | 229 | } |
| 248 | 230 | } 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 ); | |
| 231 | + wp_enqueue_style( $this->get_file_handle_id(), $this->get_url(), $this->get_enqueue_dependencies(), null ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion | |
| 250 | 232 | } |
| 251 | 233 | |
| 252 | 234 | // Handle fonts. |
| 253 | 235 | if ( ! empty( $meta['fonts'] ) ) { |
| @@ -279,17 +261,8 @@ | ||
| 279 | 261 | * |
| 280 | 262 | * @param Base $this The current CSS file. |
| 281 | 263 | */ |
| 282 | 264 | 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 | 265 | } |
| 293 | 266 | |
| 294 | 267 | /** |
| 295 | 268 | * Print CSS. |
| @@ -300,9 +273,9 @@ | ||
| 300 | 273 | * @since 1.9.4 |
| 301 | 274 | * @access public |
| 302 | 275 | */ |
| 303 | 276 | public function print_css() { |
| 304 | - echo '<style>' . $this->get_content() . '</style>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 277 | + echo '<style>' . $this->get_content() . '</style>'; // XSS ok. | |
| 305 | 278 | Plugin::$instance->frontend->print_fonts_links(); |
| 306 | 279 | } |
| 307 | 280 | |
| 308 | 281 | /** |
| @@ -353,10 +326,8 @@ | ||
| 353 | 326 | } |
| 354 | 327 | |
| 355 | 328 | $stylesheet = $this->get_stylesheet(); |
| 356 | 329 | |
| 357 | - $control = apply_filters( 'elementor/files/css/selectors', $control, $value ?? [], $this ); | |
| 358 | - | |
| 359 | 330 | foreach ( $control['selectors'] as $selector => $css_property ) { |
| 360 | 331 | $output_css_property = ''; |
| 361 | 332 | |
| 362 | 333 | if ( $global_key ) { |
| @@ -366,19 +337,13 @@ | ||
| 366 | 337 | $output_css_property = preg_replace( '/(:)[^;]+(;?)/', '$1' . $selector_global_value . '$2', $css_property ); |
| 367 | 338 | } |
| 368 | 339 | } else { |
| 369 | 340 | try { |
| 370 | - if ( $this->unit_has_custom_selector( $control, $value ) ) { | |
| 371 | - $css_property = $control['unit_selectors_dictionary'][ $value['unit'] ]; | |
| 372 | - } | |
| 373 | - | |
| 374 | 341 | $output_css_property = preg_replace_callback( '/{{(?:([^.}]+)\.)?([^}| ]*)(?: *\|\| *(?:([^.}]+)\.)?([^}| ]*) *)*}}/', function( $matches ) use ( $control, $value_callback, $controls_stack, $value, $css_property ) { |
| 375 | 342 | $external_control_missing = $matches[1] && ! isset( $controls_stack[ $matches[1] ] ); |
| 376 | 343 | |
| 377 | 344 | $parsed_value = ''; |
| 378 | 345 | |
| 379 | - $value = apply_filters( 'elementor/files/css/property', $value, $css_property, $matches, $control ); | |
| 380 | - | |
| 381 | 346 | if ( ! $external_control_missing ) { |
| 382 | 347 | $parsed_value = $this->parse_property_placeholder( $control, $value, $controls_stack, $value_callback, $matches[2], $matches[1] ); |
| 383 | 348 | } |
| 384 | 349 | |
| @@ -407,12 +372,8 @@ | ||
| 407 | 372 | throw new \Exception(); |
| 408 | 373 | } |
| 409 | 374 | } |
| 410 | 375 | |
| 411 | - if ( '__EMPTY__' === $parsed_value ) { | |
| 412 | - $parsed_value = ''; | |
| 413 | - } | |
| 414 | - | |
| 415 | 376 | return $parsed_value; |
| 416 | 377 | }, $css_property ); |
| 417 | 378 | } catch ( \Exception $e ) { |
| 418 | 379 | return; |
| @@ -462,12 +423,8 @@ | ||
| 462 | 423 | $stylesheet->add_rules( $parsed_selector, $output_css_property, $query ); |
| 463 | 424 | } |
| 464 | 425 | } |
| 465 | 426 | |
| 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 | 427 | /** |
| 471 | 428 | * @param array $control |
| 472 | 429 | * @param mixed $value |
| 473 | 430 | * @param array $controls_stack |
| @@ -478,17 +435,10 @@ | ||
| 478 | 435 | * @return string |
| 479 | 436 | */ |
| 480 | 437 | public function parse_property_placeholder( array $control, $value, array $controls_stack, $value_callback, $placeholder, $parser_control_name = null ) { |
| 481 | 438 | 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 ); | |
| 439 | + $control = $controls_stack[ $parser_control_name ]; | |
| 485 | 440 | |
| 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 | 441 | $value = call_user_func( $value_callback, $control ); |
| 492 | 442 | } |
| 493 | 443 | |
| 494 | 444 | // If the control value is empty, check for global default. `0` (integer, string) are falsy but are valid values. |
| @@ -496,9 +446,9 @@ | ||
| 496 | 446 | $value = $this->get_control_global_default_value( $control ); |
| 497 | 447 | } |
| 498 | 448 | |
| 499 | 449 | if ( Controls_Manager::FONT === $control['type'] ) { |
| 500 | - $this->add_font( $value ); | |
| 450 | + $this->fonts[] = $value; | |
| 501 | 451 | } |
| 502 | 452 | |
| 503 | 453 | /** @var Base_Data_Control $control_obj */ |
| 504 | 454 | $control_obj = Plugin::$instance->controls_manager->get_control( $control['type'] ); |
| @@ -554,9 +504,9 @@ | ||
| 554 | 504 | * @param array $placeholders Placeholders. |
| 555 | 505 | * @param array $replacements Replacements. |
| 556 | 506 | * @param array $all_controls All controls. |
| 557 | 507 | */ |
| 558 | - public function add_controls_stack_style_rules( Controls_Stack $controls_stack, array $controls, array $values, array $placeholders, array $replacements, ?array $all_controls = null ) { | |
| 508 | + public function add_controls_stack_style_rules( Controls_Stack $controls_stack, array $controls, array $values, array $placeholders, array $replacements, array $all_controls = null ) { | |
| 559 | 509 | if ( ! $all_controls ) { |
| 560 | 510 | $all_controls = $controls_stack->get_controls(); |
| 561 | 511 | } |
| 562 | 512 | |
| @@ -578,13 +528,8 @@ | ||
| 578 | 528 | if ( ! empty( $parsed_dynamic_settings[ Manager::DYNAMIC_SETTING_KEY ][ $control['name'] ] ) ) { |
| 579 | 529 | // Dynamic CSS should not be added to the CSS files. |
| 580 | 530 | // Instead it's handled by \Elementor\Core\DynamicTags\Dynamic_CSS |
| 581 | 531 | // 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 | 532 | unset( $parsed_dynamic_settings[ $control['name'] ] ); |
| 588 | 533 | |
| 589 | 534 | $this->dynamic_elements_ids[] = $controls_stack->get_id(); |
| 590 | 535 | |
| @@ -611,31 +556,8 @@ | ||
| 611 | 556 | * @return string CSS file handle ID. |
| 612 | 557 | */ |
| 613 | 558 | abstract protected function get_file_handle_id(); |
| 614 | 559 | |
| 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 | 560 | /** |
| 639 | 561 | * Render CSS. |
| 640 | 562 | * |
| 641 | 563 | * Parse the CSS. |
| @@ -706,10 +628,8 @@ | ||
| 706 | 628 | * @since 1.2.0 |
| 707 | 629 | * @access protected |
| 708 | 630 | */ |
| 709 | 631 | protected function parse_content() { |
| 710 | - Performance::set_use_style_controls( true ); | |
| 711 | - | |
| 712 | 632 | $initial_responsive_controls_duplication_mode = Plugin::$instance->breakpoints->get_responsive_control_duplication_mode(); |
| 713 | 633 | |
| 714 | 634 | Plugin::$instance->breakpoints->set_responsive_control_duplication_mode( $this->get_responsive_control_duplication_mode() ); |
| 715 | 635 | |
| @@ -731,10 +651,8 @@ | ||
| 731 | 651 | do_action( "elementor/css-file/{$name}/parse", $this ); |
| 732 | 652 | |
| 733 | 653 | Plugin::$instance->breakpoints->set_responsive_control_duplication_mode( $initial_responsive_controls_duplication_mode ); |
| 734 | 654 | |
| 735 | - Performance::set_use_style_controls( false ); | |
| 736 | - | |
| 737 | 655 | return $this->get_stylesheet()->__toString(); |
| 738 | 656 | } |
| 739 | 657 | |
| 740 | 658 | /** |
| @@ -815,11 +733,9 @@ | ||
| 815 | 733 | // When the control itself has no global value, but it refers to another control global value |
| 816 | 734 | return $this->get_selector_global_value( $control, $values['__globals__'][ $control['name'] ] ); |
| 817 | 735 | } |
| 818 | 736 | |
| 819 | - $value = isset( $values[ $control['name'] ] ) | |
| 820 | - ? $values[ $control['name'] ] | |
| 821 | - : $this->preserved_dynamic_style_values[ $control['name'] ] ?? null; | |
| 737 | + $value = $values[ $control['name'] ]; | |
| 822 | 738 | |
| 823 | 739 | if ( isset( $control['selectors_dictionary'][ $value ] ) ) { |
| 824 | 740 | $value = $control['selectors_dictionary'][ $value ]; |
| 825 | 741 | } |
| @@ -936,9 +852,9 @@ | ||
| 936 | 852 | if ( $control['groupPrefix'] . 'font_family' === $control['name'] ) { |
| 937 | 853 | $default_generic_fonts = Plugin::$instance->kits_manager->get_current_settings( 'default_generic_fonts' ); |
| 938 | 854 | |
| 939 | 855 | if ( $default_generic_fonts ) { |
| 940 | - $value .= ", $default_generic_fonts"; | |
| 856 | + $value .= ", $default_generic_fonts"; | |
| 941 | 857 | } |
| 942 | 858 | } |
| 943 | 859 | } else { |
| 944 | 860 | $value = "var( --e-global-$control[type]-$id )"; |
| @@ -946,9 +862,9 @@ | ||
| 946 | 862 | |
| 947 | 863 | return $value; |
| 948 | 864 | } |
| 949 | 865 | |
| 950 | - final protected function get_active_controls( Controls_Stack $controls_stack, ?array $controls = null, ?array $settings = null ) { | |
| 866 | + final protected function get_active_controls( Controls_Stack $controls_stack, array $controls = null, array $settings = null ) { | |
| 951 | 867 | if ( ! $controls ) { |
| 952 | 868 | $controls = $controls_stack->get_controls(); |
| 953 | 869 | } |
| 954 | 870 | |
| @@ -963,9 +879,9 @@ | ||
| 963 | 879 | $active_controls = array_reduce( |
| 964 | 880 | array_keys( $controls ), function( $active_controls, $control_key ) use ( $controls_stack, $controls, $settings ) { |
| 965 | 881 | $control = $controls[ $control_key ]; |
| 966 | 882 | |
| 967 | - if ( $controls_stack->is_control_visible( $control, $settings, $controls ) ) { | |
| 883 | + if ( $controls_stack->is_control_visible( $control, $settings ) ) { | |
| 968 | 884 | $active_controls[ $control_key ] = $control; |
| 969 | 885 | } |
| 970 | 886 | |
| 971 | 887 | return $active_controls; |
| @@ -974,9 +890,9 @@ | ||
| 974 | 890 | |
| 975 | 891 | return $active_controls; |
| 976 | 892 | } |
| 977 | 893 | |
| 978 | - final public function get_style_controls( Controls_Stack $controls_stack, ?array $controls = null, ?array $settings = null ) { | |
| 894 | + final public function get_style_controls( Controls_Stack $controls_stack, array $controls = null, array $settings = null ) { | |
| 979 | 895 | $controls = $this->get_active_controls( $controls_stack, $controls, $settings ); |
| 980 | 896 | |
| 981 | 897 | $style_controls = []; |
| 982 | 898 | |
| @@ -1053,12 +969,6 @@ | ||
| 1053 | 969 | |
| 1054 | 970 | $globals = $controls_stack->get_settings( '__globals__' ); |
| 1055 | 971 | |
| 1056 | 972 | 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 | 973 | } |
| 1064 | 974 | } |