PluginProbe
Elementor Website Builder – more than just a page builder / 3.0.4
Elementor Website Builder – more than just a page builder v3.0.4
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
← All changes | core/files/css/base.php +37 -162 4.2.0-dev23.0.4 View file →
@@ -4,15 +4,15 @@
4 4 use Elementor\Base_Data_Control;
5 5 use Elementor\Control_Repeater;
6 6 use Elementor\Controls_Manager;
7 7 use Elementor\Controls_Stack;
8 -use Elementor\Core\Breakpoints\Manager as Breakpoints_Manager;
9 8 use Elementor\Core\Files\Base as Base_File;
10 9 use Elementor\Core\DynamicTags\Manager;
11 10 use Elementor\Core\DynamicTags\Tag;
12 -use Elementor\Core\Frontend\Performance;
13 11 use Elementor\Core\Kits\Documents\Tabs\Global_Typography;
12 +use Elementor\Element_Base;
14 13 use Elementor\Plugin;
14 +use Elementor\Core\Responsive\Responsive;
15 15 use Elementor\Stylesheet;
16 16 use Elementor\Icons_Manager;
17 17
18 18 if ( ! defined( 'ABSPATH' ) ) {
@@ -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.
@@ -104,8 +102,22 @@
104 102 return false;
105 103 }
106 104
107 105 /**
106 + * CSS file constructor.
107 + *
108 + * Initializing Elementor CSS file.
109 + *
110 + * @since 1.2.0
111 + * @access public
112 + */
113 + public function __construct( $file_name ) {
114 + parent::__construct( $file_name );
115 +
116 + $this->init_stylesheet();
117 + }
118 +
119 + /**
108 120 * Use external file.
109 121 *
110 122 * Whether to use external CSS file of not. When there are new schemes or settings
111 123 * updates.
@@ -179,19 +191,8 @@
179 191 }
180 192 }
181 193
182 194 /**
183 - * Get Responsive Control Duplication Mode
184 - *
185 - * @since 3.4.0
186 - *
187 - * @return string
188 - */
189 - protected function get_responsive_control_duplication_mode() {
190 - return 'on';
191 - }
192 -
193 - /**
194 195 * Enqueue CSS.
195 196 *
196 197 * Either enqueue the CSS file in Elementor or add inline style.
197 198 *
@@ -214,17 +215,8 @@
214 215 if ( self::CSS_STATUS_EMPTY === $meta['status'] ) {
215 216 return;
216 217 }
217 218
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 219 // First time after clear cache and etc.
228 220 if ( '' === $meta['status'] || $this->is_update_required() ) {
229 221 $this->update();
230 222
@@ -234,14 +226,14 @@
234 226 if ( self::CSS_STATUS_INLINE === $meta['status'] ) {
235 227 $dep = $this->get_inline_dependency();
236 228 // If the dependency has already been printed ( like a template in footer )
237 229 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
230 + printf( '<style id="%1$s">%2$s</style>', $this->get_file_handle_id(), $meta['css'] ); // XSS ok.
239 231 } else {
240 232 wp_add_inline_style( $dep, $meta['css'] );
241 233 }
242 234 } 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 );
235 + wp_enqueue_style( $this->get_file_handle_id(), $this->get_url(), $this->get_enqueue_dependencies(), null ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
244 236 }
245 237
246 238 // Handle fonts.
247 239 if ( ! empty( $meta['fonts'] ) ) {
@@ -273,17 +265,8 @@
273 265 *
274 266 * @param Base $this The current CSS file.
275 267 */
276 268 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 269 }
287 270
288 271 /**
289 272 * Print CSS.
@@ -294,9 +277,9 @@
294 277 * @since 1.9.4
295 278 * @access public
296 279 */
297 280 public function print_css() {
298 - echo '<style>' . $this->get_content() . '</style>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
281 + echo '<style>' . $this->get_content() . '</style>'; // XSS ok.
299 282 Plugin::$instance->frontend->print_fonts_links();
300 283 }
301 284
302 285 /**
@@ -345,12 +328,8 @@
345 328 return;
346 329 }
347 330 }
348 331
349 - $stylesheet = $this->get_stylesheet();
350 -
351 - $control = apply_filters( 'elementor/files/css/selectors', $control, $value ?? [], $this );
352 -
353 332 foreach ( $control['selectors'] as $selector => $css_property ) {
354 333 $output_css_property = '';
355 334
356 335 if ( $global_key ) {
@@ -360,19 +339,13 @@
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 = '';
372 347
373 - $value = apply_filters( 'elementor/files/css/property', $value, $css_property, $matches, $control );
374 -
375 348 if ( ! $external_control_missing ) {
376 349 $parsed_value = $this->parse_property_placeholder( $control, $value, $controls_stack, $value_callback, $matches[2], $matches[1] );
377 350 }
378 351
@@ -401,12 +374,8 @@
401 374 throw new \Exception();
402 375 }
403 376 }
404 377
405 - if ( '__EMPTY__' === $parsed_value ) {
406 - $parsed_value = '';
407 - }
408 -
409 378 return $parsed_value;
410 379 }, $css_property );
411 380 } catch ( \Exception $e ) {
412 381 return;
@@ -430,9 +399,9 @@
430 399
431 400 $pure_device_rules = $pure_device_rules[1];
432 401
433 402 foreach ( $pure_device_rules as $device_rule ) {
434 - if ( Breakpoints_Manager::BREAKPOINT_KEY_DESKTOP === $device_rule ) {
403 + if ( Element_Base::RESPONSIVE_DESKTOP === $device_rule ) {
435 404 continue;
436 405 }
437 406
438 407 $device = preg_replace( '/\+$/', '', $device_rule );
@@ -447,21 +416,17 @@
447 416
448 417 if ( ! $query && ! empty( $control['responsive'] ) ) {
449 418 $query = array_intersect_key( $control['responsive'], array_flip( [ 'min', 'max' ] ) );
450 419
451 - if ( ! empty( $query['max'] ) && Breakpoints_Manager::BREAKPOINT_KEY_DESKTOP === $query['max'] ) {
420 + if ( ! empty( $query['max'] ) && Element_Base::RESPONSIVE_DESKTOP === $query['max'] ) {
452 421 unset( $query['max'] );
453 422 }
454 423 }
455 424
456 - $stylesheet->add_rules( $parsed_selector, $output_css_property, $query );
425 + $this->stylesheet_obj->add_rules( $parsed_selector, $output_css_property, $query );
457 426 }
458 427 }
459 428
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 429 /**
465 430 * @param array $control
466 431 * @param mixed $value
467 432 * @param array $controls_stack
@@ -472,27 +437,15 @@
472 437 * @return string
473 438 */
474 439 public function parse_property_placeholder( array $control, $value, array $controls_stack, $value_callback, $placeholder, $parser_control_name = null ) {
475 440 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 );
441 + $control = $controls_stack[ $parser_control_name ];
479 442
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 443 $value = call_user_func( $value_callback, $control );
486 444 }
487 445
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 446 if ( Controls_Manager::FONT === $control['type'] ) {
494 - $this->add_font( $value );
447 + $this->fonts[] = $value;
495 448 }
496 449
497 450 /** @var Base_Data_Control $control_obj */
498 451 $control_obj = Plugin::$instance->controls_manager->get_control( $control['type'] );
@@ -524,12 +477,8 @@
524 477 *
525 478 * @return Stylesheet The stylesheet object.
526 479 */
527 480 public function get_stylesheet() {
528 - if ( ! $this->stylesheet_obj ) {
529 - $this->init_stylesheet();
530 - }
531 -
532 481 return $this->stylesheet_obj;
533 482 }
534 483
535 484 /**
@@ -548,9 +497,9 @@
548 497 * @param array $placeholders Placeholders.
549 498 * @param array $replacements Replacements.
550 499 * @param array $all_controls All controls.
551 500 */
552 - public function add_controls_stack_style_rules( Controls_Stack $controls_stack, array $controls, array $values, array $placeholders, array $replacements, ?array $all_controls = null ) {
501 + public function add_controls_stack_style_rules( Controls_Stack $controls_stack, array $controls, array $values, array $placeholders, array $replacements, array $all_controls = null ) {
553 502 if ( ! $all_controls ) {
554 503 $all_controls = $controls_stack->get_controls();
555 504 }
556 505
@@ -572,13 +521,8 @@
572 521 if ( ! empty( $parsed_dynamic_settings[ Manager::DYNAMIC_SETTING_KEY ][ $control['name'] ] ) ) {
573 522 // Dynamic CSS should not be added to the CSS files.
574 523 // Instead it's handled by \Elementor\Core\DynamicTags\Dynamic_CSS
575 524 // 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 525 unset( $parsed_dynamic_settings[ $control['name'] ] );
582 526
583 527 $this->dynamic_elements_ids[] = $controls_stack->get_id();
584 528
@@ -677,14 +621,8 @@
677 621 * @since 1.2.0
678 622 * @access protected
679 623 */
680 624 protected function parse_content() {
681 - Performance::set_use_style_controls( true );
682 -
683 - $initial_responsive_controls_duplication_mode = Plugin::$instance->breakpoints->get_responsive_control_duplication_mode();
684 -
685 - Plugin::$instance->breakpoints->set_responsive_control_duplication_mode( $this->get_responsive_control_duplication_mode() );
686 -
687 625 $this->render_css();
688 626
689 627 $name = $this->get_name();
690 628
@@ -700,13 +638,9 @@
700 638 * @param Base $this The current CSS file.
701 639 */
702 640 do_action( "elementor/css-file/{$name}/parse", $this );
703 641
704 - Plugin::$instance->breakpoints->set_responsive_control_duplication_mode( $initial_responsive_controls_duplication_mode );
705 -
706 - Performance::set_use_style_controls( false );
707 -
708 - return $this->get_stylesheet()->__toString();
642 + return $this->stylesheet_obj->__toString();
709 643 }
710 644
711 645 /**
712 646 * Add control style rules.
@@ -730,44 +664,8 @@
730 664 );
731 665 }
732 666
733 667 /**
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 668 * Get style control value.
771 669 *
772 670 * Retrieve the value of the style control for any give control and values.
773 671 *
@@ -786,11 +684,9 @@
786 684 // When the control itself has no global value, but it refers to another control global value
787 685 return $this->get_selector_global_value( $control, $values['__globals__'][ $control['name'] ] );
788 686 }
789 687
790 - $value = isset( $values[ $control['name'] ] )
791 - ? $values[ $control['name'] ]
792 - : $this->preserved_dynamic_style_values[ $control['name'] ] ?? null;
688 + $value = $values[ $control['name'] ];
793 689
794 690 if ( isset( $control['selectors_dictionary'][ $value ] ) ) {
795 691 $value = $control['selectors_dictionary'][ $value ];
796 692 }
@@ -813,13 +709,14 @@
813 709 */
814 710 private function init_stylesheet() {
815 711 $this->stylesheet_obj = new Stylesheet();
816 712
817 - $active_breakpoints = Plugin::$instance->breakpoints->get_active_breakpoints();
713 + $breakpoints = Responsive::get_breakpoints();
818 714
819 - foreach ( $active_breakpoints as $breakpoint_name => $breakpoint ) {
820 - $this->stylesheet_obj->add_device( $breakpoint_name, $breakpoint->get_value() );
821 - }
715 + $this->stylesheet_obj
716 + ->add_device( 'mobile', 0 )
717 + ->add_device( 'tablet', $breakpoints['md'] )
718 + ->add_device( 'desktop', $breakpoints['lg'] );
822 719 }
823 720
824 721 /**
825 722 * Add repeater control style rules.
@@ -873,9 +770,9 @@
873 770 } );
874 771 }
875 772
876 773 private function get_selector_global_value( $control, $global_key ) {
877 - $data = Plugin::$instance->data_manager_v2->run( $global_key );
774 + $data = Plugin::$instance->data_manager->run( $global_key );
878 775
879 776 if ( empty( $data['value'] ) ) {
880 777 return null;
881 778 }
@@ -884,18 +781,10 @@
884 781
885 782 $id = $global_args[1];
886 783
887 784 if ( ! empty( $control['groupType'] ) ) {
888 - $strings_to_replace = [ $control['groupPrefix'] ];
785 + $property_name = str_replace( [ $control['groupPrefix'], '_tablet', '_mobile' ], '', $control['name'] );
889 786
890 - $active_breakpoint_keys = array_keys( Plugin::$instance->breakpoints->get_active_breakpoints() );
891 -
892 - foreach ( $active_breakpoint_keys as $breakpoint ) {
893 - $strings_to_replace[] = '_' . $breakpoint;
894 - }
895 -
896 - $property_name = str_replace( $strings_to_replace, '', $control['name'] );
897 -
898 787 // TODO: This check won't retrieve the proper answer for array values (multiple controls).
899 788 if ( empty( $data['value'][ Global_Typography::TYPOGRAPHY_GROUP_PREFIX . $property_name ] ) ) {
900 789 return null;
901 790 }
@@ -902,16 +791,8 @@
902 791
903 792 $property_name = str_replace( '_', '-', $property_name );
904 793
905 794 $value = "var( --e-global-$control[groupType]-$id-$property_name )";
906 -
907 - if ( $control['groupPrefix'] . 'font_family' === $control['name'] ) {
908 - $default_generic_fonts = Plugin::$instance->kits_manager->get_current_settings( 'default_generic_fonts' );
909 -
910 - if ( $default_generic_fonts ) {
911 - $value .= ", $default_generic_fonts";
912 - }
913 - }
914 795 } else {
915 796 $value = "var( --e-global-$control[type]-$id )";
916 797 }
917 798
@@ -917,9 +798,9 @@
917 798
918 799 return $value;
919 800 }
920 801
921 - final protected function get_active_controls( Controls_Stack $controls_stack, ?array $controls = null, ?array $settings = null ) {
802 + final protected function get_active_controls( Controls_Stack $controls_stack, array $controls = null, array $settings = null ) {
922 803 if ( ! $controls ) {
923 804 $controls = $controls_stack->get_controls();
924 805 }
925 806
@@ -934,9 +815,9 @@
934 815 $active_controls = array_reduce(
935 816 array_keys( $controls ), function( $active_controls, $control_key ) use ( $controls_stack, $controls, $settings ) {
936 817 $control = $controls[ $control_key ];
937 818
938 - if ( $controls_stack->is_control_visible( $control, $settings, $controls ) ) {
819 + if ( $controls_stack->is_control_visible( $control, $settings ) ) {
939 820 $active_controls[ $control_key ] = $control;
940 821 }
941 822
942 823 return $active_controls;
@@ -945,9 +826,9 @@
945 826
946 827 return $active_controls;
947 828 }
948 829
949 - final public function get_style_controls( Controls_Stack $controls_stack, ?array $controls = null, ?array $settings = null ) {
830 + final public function get_style_controls( Controls_Stack $controls_stack, array $controls = null, array $settings = null ) {
950 831 $controls = $this->get_active_controls( $controls_stack, $controls, $settings );
951 832
952 833 $style_controls = [];
953 834
@@ -1024,12 +905,6 @@
1024 905
1025 906 $globals = $controls_stack->get_settings( '__globals__' );
1026 907
1027 908 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 909 }
1035 910 }