PluginProbe
Elementor Website Builder – more than just a page builder / 3.2.0
Elementor Website Builder – more than just a page builder v3.2.0
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 +16 -143 4.2.13.2.0 View file →
@@ -4,14 +4,13 @@
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;
15 14 use Elementor\Stylesheet;
16 15 use Elementor\Icons_Manager;
17 16
@@ -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.
@@ -179,19 +176,8 @@
179 176 }
180 177 }
181 178
182 179 /**
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 180 * Enqueue CSS.
195 181 *
196 182 * Either enqueue the CSS file in Elementor or add inline style.
197 183 *
@@ -214,17 +200,8 @@
214 200 if ( self::CSS_STATUS_EMPTY === $meta['status'] ) {
215 201 return;
216 202 }
217 203
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 204 // First time after clear cache and etc.
228 205 if ( '' === $meta['status'] || $this->is_update_required() ) {
229 206 $this->update();
230 207
@@ -234,14 +211,14 @@
234 211 if ( self::CSS_STATUS_INLINE === $meta['status'] ) {
235 212 $dep = $this->get_inline_dependency();
236 213 // If the dependency has already been printed ( like a template in footer )
237 214 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
215 + printf( '<style id="%1$s">%2$s</style>', $this->get_file_handle_id(), $meta['css'] ); // XSS ok.
239 216 } else {
240 217 wp_add_inline_style( $dep, $meta['css'] );
241 218 }
242 219 } 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 );
220 + wp_enqueue_style( $this->get_file_handle_id(), $this->get_url(), $this->get_enqueue_dependencies(), null ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
244 221 }
245 222
246 223 // Handle fonts.
247 224 if ( ! empty( $meta['fonts'] ) ) {
@@ -273,17 +250,8 @@
273 250 *
274 251 * @param Base $this The current CSS file.
275 252 */
276 253 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 254 }
287 255
288 256 /**
289 257 * Print CSS.
@@ -294,9 +262,9 @@
294 262 * @since 1.9.4
295 263 * @access public
296 264 */
297 265 public function print_css() {
298 - echo '<style>' . $this->get_content() . '</style>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
266 + echo '<style>' . $this->get_content() . '</style>'; // XSS ok.
299 267 Plugin::$instance->frontend->print_fonts_links();
300 268 }
301 269
302 270 /**
@@ -347,10 +315,8 @@
347 315 }
348 316
349 317 $stylesheet = $this->get_stylesheet();
350 318
351 - $control = apply_filters( 'elementor/files/css/selectors', $control, $value ?? [], $this );
352 -
353 319 foreach ( $control['selectors'] as $selector => $css_property ) {
354 320 $output_css_property = '';
355 321
356 322 if ( $global_key ) {
@@ -360,19 +326,13 @@
360 326 $output_css_property = preg_replace( '/(:)[^;]+(;?)/', '$1' . $selector_global_value . '$2', $css_property );
361 327 }
362 328 } else {
363 329 try {
364 - if ( $this->unit_has_custom_selector( $control, $value ) ) {
365 - $css_property = $control['unit_selectors_dictionary'][ $value['unit'] ];
366 - }
367 -
368 330 $output_css_property = preg_replace_callback( '/{{(?:([^.}]+)\.)?([^}| ]*)(?: *\|\| *(?:([^.}]+)\.)?([^}| ]*) *)*}}/', function( $matches ) use ( $control, $value_callback, $controls_stack, $value, $css_property ) {
369 331 $external_control_missing = $matches[1] && ! isset( $controls_stack[ $matches[1] ] );
370 332
371 333 $parsed_value = '';
372 334
373 - $value = apply_filters( 'elementor/files/css/property', $value, $css_property, $matches, $control );
374 -
375 335 if ( ! $external_control_missing ) {
376 336 $parsed_value = $this->parse_property_placeholder( $control, $value, $controls_stack, $value_callback, $matches[2], $matches[1] );
377 337 }
378 338
@@ -401,12 +361,8 @@
401 361 throw new \Exception();
402 362 }
403 363 }
404 364
405 - if ( '__EMPTY__' === $parsed_value ) {
406 - $parsed_value = '';
407 - }
408 -
409 365 return $parsed_value;
410 366 }, $css_property );
411 367 } catch ( \Exception $e ) {
412 368 return;
@@ -430,9 +386,9 @@
430 386
431 387 $pure_device_rules = $pure_device_rules[1];
432 388
433 389 foreach ( $pure_device_rules as $device_rule ) {
434 - if ( Breakpoints_Manager::BREAKPOINT_KEY_DESKTOP === $device_rule ) {
390 + if ( Element_Base::RESPONSIVE_DESKTOP === $device_rule ) {
435 391 continue;
436 392 }
437 393
438 394 $device = preg_replace( '/\+$/', '', $device_rule );
@@ -447,9 +403,9 @@
447 403
448 404 if ( ! $query && ! empty( $control['responsive'] ) ) {
449 405 $query = array_intersect_key( $control['responsive'], array_flip( [ 'min', 'max' ] ) );
450 406
451 - if ( ! empty( $query['max'] ) && Breakpoints_Manager::BREAKPOINT_KEY_DESKTOP === $query['max'] ) {
407 + if ( ! empty( $query['max'] ) && Element_Base::RESPONSIVE_DESKTOP === $query['max'] ) {
452 408 unset( $query['max'] );
453 409 }
454 410 }
455 411
@@ -456,12 +412,8 @@
456 412 $stylesheet->add_rules( $parsed_selector, $output_css_property, $query );
457 413 }
458 414 }
459 415
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 416 /**
465 417 * @param array $control
466 418 * @param mixed $value
467 419 * @param array $controls_stack
@@ -472,27 +424,15 @@
472 424 * @return string
473 425 */
474 426 public function parse_property_placeholder( array $control, $value, array $controls_stack, $value_callback, $placeholder, $parser_control_name = null ) {
475 427 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 );
428 + $control = $controls_stack[ $parser_control_name ];
479 429
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 430 $value = call_user_func( $value_callback, $control );
486 431 }
487 432
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 433 if ( Controls_Manager::FONT === $control['type'] ) {
494 - $this->add_font( $value );
434 + $this->fonts[] = $value;
495 435 }
496 436
497 437 /** @var Base_Data_Control $control_obj */
498 438 $control_obj = Plugin::$instance->controls_manager->get_control( $control['type'] );
@@ -548,9 +488,9 @@
548 488 * @param array $placeholders Placeholders.
549 489 * @param array $replacements Replacements.
550 490 * @param array $all_controls All controls.
551 491 */
552 - public function add_controls_stack_style_rules( Controls_Stack $controls_stack, array $controls, array $values, array $placeholders, array $replacements, ?array $all_controls = null ) {
492 + public function add_controls_stack_style_rules( Controls_Stack $controls_stack, array $controls, array $values, array $placeholders, array $replacements, array $all_controls = null ) {
553 493 if ( ! $all_controls ) {
554 494 $all_controls = $controls_stack->get_controls();
555 495 }
556 496
@@ -572,13 +512,8 @@
572 512 if ( ! empty( $parsed_dynamic_settings[ Manager::DYNAMIC_SETTING_KEY ][ $control['name'] ] ) ) {
573 513 // Dynamic CSS should not be added to the CSS files.
574 514 // Instead it's handled by \Elementor\Core\DynamicTags\Dynamic_CSS
575 515 // 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 516 unset( $parsed_dynamic_settings[ $control['name'] ] );
582 517
583 518 $this->dynamic_elements_ids[] = $controls_stack->get_id();
584 519
@@ -677,14 +612,8 @@
677 612 * @since 1.2.0
678 613 * @access protected
679 614 */
680 615 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 616 $this->render_css();
688 617
689 618 $name = $this->get_name();
690 619
@@ -700,12 +629,8 @@
700 629 * @param Base $this The current CSS file.
701 630 */
702 631 do_action( "elementor/css-file/{$name}/parse", $this );
703 632
704 - Plugin::$instance->breakpoints->set_responsive_control_duplication_mode( $initial_responsive_controls_duplication_mode );
705 -
706 - Performance::set_use_style_controls( false );
707 -
708 633 return $this->get_stylesheet()->__toString();
709 634 }
710 635
711 636 /**
@@ -730,44 +655,8 @@
730 655 );
731 656 }
732 657
733 658 /**
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 659 * Get style control value.
771 660 *
772 661 * Retrieve the value of the style control for any give control and values.
773 662 *
@@ -786,11 +675,9 @@
786 675 // When the control itself has no global value, but it refers to another control global value
787 676 return $this->get_selector_global_value( $control, $values['__globals__'][ $control['name'] ] );
788 677 }
789 678
790 - $value = isset( $values[ $control['name'] ] )
791 - ? $values[ $control['name'] ]
792 - : $this->preserved_dynamic_style_values[ $control['name'] ] ?? null;
679 + $value = $values[ $control['name'] ];
793 680
794 681 if ( isset( $control['selectors_dictionary'][ $value ] ) ) {
795 682 $value = $control['selectors_dictionary'][ $value ];
796 683 }
@@ -873,9 +760,9 @@
873 760 } );
874 761 }
875 762
876 763 private function get_selector_global_value( $control, $global_key ) {
877 - $data = Plugin::$instance->data_manager_v2->run( $global_key );
764 + $data = Plugin::$instance->data_manager->run( $global_key );
878 765
879 766 if ( empty( $data['value'] ) ) {
880 767 return null;
881 768 }
@@ -884,18 +771,10 @@
884 771
885 772 $id = $global_args[1];
886 773
887 774 if ( ! empty( $control['groupType'] ) ) {
888 - $strings_to_replace = [ $control['groupPrefix'] ];
775 + $property_name = str_replace( [ $control['groupPrefix'], '_tablet', '_mobile' ], '', $control['name'] );
889 776
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 777 // TODO: This check won't retrieve the proper answer for array values (multiple controls).
899 778 if ( empty( $data['value'][ Global_Typography::TYPOGRAPHY_GROUP_PREFIX . $property_name ] ) ) {
900 779 return null;
901 780 }
@@ -907,9 +786,9 @@
907 786 if ( $control['groupPrefix'] . 'font_family' === $control['name'] ) {
908 787 $default_generic_fonts = Plugin::$instance->kits_manager->get_current_settings( 'default_generic_fonts' );
909 788
910 789 if ( $default_generic_fonts ) {
911 - $value .= ", $default_generic_fonts";
790 + $value .= ", $default_generic_fonts";
912 791 }
913 792 }
914 793 } else {
915 794 $value = "var( --e-global-$control[type]-$id )";
@@ -917,9 +796,9 @@
917 796
918 797 return $value;
919 798 }
920 799
921 - final protected function get_active_controls( Controls_Stack $controls_stack, ?array $controls = null, ?array $settings = null ) {
800 + final protected function get_active_controls( Controls_Stack $controls_stack, array $controls = null, array $settings = null ) {
922 801 if ( ! $controls ) {
923 802 $controls = $controls_stack->get_controls();
924 803 }
925 804
@@ -934,9 +813,9 @@
934 813 $active_controls = array_reduce(
935 814 array_keys( $controls ), function( $active_controls, $control_key ) use ( $controls_stack, $controls, $settings ) {
936 815 $control = $controls[ $control_key ];
937 816
938 - if ( $controls_stack->is_control_visible( $control, $settings, $controls ) ) {
817 + if ( $controls_stack->is_control_visible( $control, $settings ) ) {
939 818 $active_controls[ $control_key ] = $control;
940 819 }
941 820
942 821 return $active_controls;
@@ -945,9 +824,9 @@
945 824
946 825 return $active_controls;
947 826 }
948 827
949 - final public function get_style_controls( Controls_Stack $controls_stack, ?array $controls = null, ?array $settings = null ) {
828 + final public function get_style_controls( Controls_Stack $controls_stack, array $controls = null, array $settings = null ) {
950 829 $controls = $this->get_active_controls( $controls_stack, $controls, $settings );
951 830
952 831 $style_controls = [];
953 832
@@ -1024,12 +903,6 @@
1024 903
1025 904 $globals = $controls_stack->get_settings( '__globals__' );
1026 905
1027 906 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 907 }
1035 908 }