| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
class BBlocksStyleGenerator |
| 8 |
{ |
| 9 |
public static $styles = []; |
| 10 |
public static function addStyle($selector, $styles) |
| 11 |
{ |
| 12 |
if (array_key_exists($selector, self::$styles)) { |
| 13 |
self::$styles[$selector] = wp_parse_args(self::$styles[$selector], $styles); |
| 14 |
} else { |
| 15 |
self::$styles[$selector] = $styles; |
| 16 |
} |
| 17 |
} |
| 18 |
public static function renderStyle() |
| 19 |
{ |
| 20 |
$output = ''; |
| 21 |
foreach (self::$styles as $selector => $style) { |
| 22 |
$new = ''; |
| 23 |
foreach ($style as $property => $value) { |
| 24 |
if ( '' === $value ) { |
| 25 |
$new .= "$property ;"; |
| 26 |
} else { |
| 27 |
$new .= " $property: $value;"; |
| 28 |
} |
| 29 |
} |
| 30 |
$output .= "$selector { $new }"; |
| 31 |
} |
| 32 |
return $output; |
| 33 |
} |
| 34 |
} |
| 35 |
|