| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\AtomicWidgets\Styles; |
| 4 |
|
| 5 |
use Elementor\Core\Files\CSS\Post as Post_CSS; |
| 6 |
use Elementor\Element_Base; |
| 7 |
use Elementor\Modules\AtomicWidgets\Utils; |
| 8 |
use Elementor\Plugin; |
| 9 |
|
| 10 |
class Atomic_Widget_Styles { |
| 11 |
public function register_hooks() { |
| 12 |
add_action( 'elementor/element/parse_css', fn( Post_CSS $post, Element_Base $element ) => $this->parse_element_style( $post, $element ), 10, 2 ); |
| 13 |
} |
| 14 |
|
| 15 |
private function parse_element_style( Post_CSS $post, Element_Base $element ) { |
| 16 |
if ( ! Utils::is_atomic( $element ) ) { |
| 17 |
return; |
| 18 |
} |
| 19 |
|
| 20 |
$styles = $element->get_raw_data()['styles']; |
| 21 |
|
| 22 |
if ( empty( $styles ) ) { |
| 23 |
return; |
| 24 |
} |
| 25 |
|
| 26 |
$css = Styles_Renderer::make( |
| 27 |
Plugin::$instance->breakpoints->get_breakpoints_config() |
| 28 |
)->on_prop_transform( function( $key, $value ) use ( &$post ) { |
| 29 |
if ( 'font-family' !== $key ) { |
| 30 |
return; |
| 31 |
} |
| 32 |
|
| 33 |
$post->add_font( $value ); |
| 34 |
} )->render( $styles ); |
| 35 |
|
| 36 |
$post->get_stylesheet()->add_raw_css( $css ); |
| 37 |
} |
| 38 |
} |
| 39 |
|