PluginProbe
Elementor Website Builder – more than just a page builder / 3.27.3
Elementor Website Builder – more than just a page builder v3.27.3
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
elementor / modules / atomic-widgets / styles / atomic-widget-styles.php

atomic-widget-styles.php in Elementor Website Builder – more than just a page builder 3.27.3, at modules/atomic-widgets/styles/atomic-widget-styles.php

57 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\Modules\AtomicWidgets\Styles;
4
5 use Elementor\Core\Files\CSS\Post;
6 use Elementor\Element_Base;
7 use Elementor\Modules\AtomicWidgets\Base\Atomic_Element_Base;
8 use Elementor\Modules\AtomicWidgets\Base\Atomic_Widget_Base;
9 use Elementor\Plugin;
10
11 class Atomic_Widget_Styles {
12 public function register_hooks() {
13 add_action( 'elementor/element/parse_css', fn( Post $post, Element_Base $element ) => $this->parse_element_style( $post, $element ), 10, 2 );
14 }
15
16 private function parse_element_style( Post $post, Element_Base $element ) {
17 if ( ! ( $element instanceof Atomic_Widget_Base || $element instanceof Atomic_Element_Base )
18 || Post::class !== get_class( $post ) ) {
19 return;
20 }
21
22 $styles = $element->get_raw_data()['styles'];
23
24 if ( empty( $styles ) ) {
25 return;
26 }
27
28 $this->styles_enqueue_fonts( $styles );
29
30 $css = Styles_Renderer::make( [
31 'breakpoints' => Plugin::$instance->breakpoints->get_breakpoints_config(),
32 ] )->render( $styles );
33
34 $post->get_stylesheet()->add_raw_css( $css );
35 }
36
37 /**
38 * @param array<int, array{
39 * id: string,
40 * type: string,
41 * variants: array<int, array{
42 * props: array<string, mixed>,
43 * meta: array<string, mixed>
44 * }>
45 * }> $styles
46 */
47 private function styles_enqueue_fonts( array $styles ): void {
48 foreach ( $styles as $style ) {
49 foreach ( $style['variants'] as $variant ) {
50 if ( isset( $variant['props']['font-family'] ) ) {
51 Plugin::$instance->frontend->enqueue_font( $variant['props']['font-family'] );
52 }
53 }
54 }
55 }
56 }
57