| 1 |
<?php |
| 2 |
|
| 3 |
class Gutenify_block_inline_styles { |
| 4 |
|
| 5 |
private static $all_styles; |
| 6 |
|
| 7 |
public static function init() { |
| 8 |
add_action( 'wp', 'Gutenify_block_inline_styles::add_styles' ); |
| 9 |
add_action( 'wp_enqueue_scripts', 'Gutenify_block_inline_styles::add_inline_styles', 201 ); |
| 10 |
} |
| 11 |
|
| 12 |
public static function add_styles() { |
| 13 |
add_filter( |
| 14 |
'render_block', |
| 15 |
function( $block_content, $block ) { |
| 16 |
if ( ! empty( $block['attrs']['gutenifyStyles'] ) ) { |
| 17 |
// var_dump( $block['attrs']['gutenifyStyles']); |
| 18 |
self::$all_styles .= $block['attrs']['gutenifyStyles']; |
| 19 |
|
| 20 |
} |
| 21 |
return $block_content; |
| 22 |
}, |
| 23 |
11, |
| 24 |
2 |
| 25 |
); |
| 26 |
} |
| 27 |
|
| 28 |
public static function add_inline_styles() { |
| 29 |
global $wp_styles; |
| 30 |
$handle = 'gutenify-block-inline-handle'; |
| 31 |
$deps = array( 'gutenify-frontend' ); |
| 32 |
wp_register_style( $handle, false, $deps ); |
| 33 |
wp_enqueue_style( $handle ); |
| 34 |
wp_add_inline_style( $handle, self::$all_styles ); |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
Gutenify_block_inline_styles::init(); |
| 39 |
|