| 1 |
<?php |
| 2 |
class BBlocksAlert extends BBlocks{ |
| 3 |
public function __construct(){ |
| 4 |
add_action( 'init', [$this, 'register'] ); |
| 5 |
} |
| 6 |
|
| 7 |
function register(){ |
| 8 |
$this::registerScripts( 'alert', array( |
| 9 |
'render_callback' => [$this, 'render'] |
| 10 |
) ); |
| 11 |
} |
| 12 |
|
| 13 |
function render( $attributes ){ |
| 14 |
extract( $attributes ); |
| 15 |
$align = $align ?? ''; |
| 16 |
$cId = $cId ?? ''; |
| 17 |
$type = $type ?? 'general'; |
| 18 |
$width = $width ?? '100%'; |
| 19 |
$alignment = $alignment ?? 'center'; |
| 20 |
$textAlign = $textAlign ?? 'center'; |
| 21 |
$message = $message ?? 'You have an alert message!'; |
| 22 |
$icon = $icon ?? array( 'class' => 'fa fa-exclamation-circle' ); |
| 23 |
$isDismiss = $isDismiss ?? true; |
| 24 |
$typography = $typography ?? array( 'fontSize' => 25 ); |
| 25 |
$colors = $colors ?? array( 'color' => '#333', 'bg' => '#fff' ); |
| 26 |
$padding = $padding ?? array( 'vertical' => '15px', 'horizontal' => '30px' ); |
| 27 |
$border = $border ?? array( 'width' => '2px', 'color' => '#333', 'radius' => '8px' ); |
| 28 |
$shadow = $shadow ?? array(); |
| 29 |
|
| 30 |
// Generate Styles |
| 31 |
$alertStyle = new BBlocksStyleGenerator(); // Generate Styles |
| 32 |
$alertStyle::addStyle("#bBlocksAlert-$cId .bBlocksAlert", array( |
| 33 |
'text-align' => $alignment |
| 34 |
)); |
| 35 |
$alertStyle::addStyle("#bBlocksAlert-$cId .bBlocksAlert .alert", array( |
| 36 |
'text-align' => $textAlign, |
| 37 |
'width' => '0px' === $width || '0%' === $width || '0em' === $width ? 'auto' : $width, |
| 38 |
$typography['styles'] ?? 'font-size: 25px;' => '', |
| 39 |
$colors['styles'] ?? 'color: #333; background: #fff;' => '', |
| 40 |
'padding' => $padding['styles'] ?? '15px 30px', |
| 41 |
$border['styles'] ?? 'border: 2px solid #333; border-radius: 8px;' => '', |
| 42 |
'box-shadow' => $shadow['styles'] ?? 'none' |
| 43 |
)); |
| 44 |
$alertStyle::addStyle("#bBlocksAlert-$cId .bBlocksAlert .alert .alertIcon", array( |
| 45 |
'font-size' => $typography['fontSize'] ?? '25px', |
| 46 |
'color' => $colors['color'] ?? '#333' |
| 47 |
)); |
| 48 |
$alertStyle::addStyle("#bBlocksAlert-$cId .bBlocksAlert .alert .alertClose", array( |
| 49 |
'color' => $colors['color'] ?? '#333' |
| 50 |
)); |
| 51 |
|
| 52 |
ob_start(); ?> |
| 53 |
<div class='wp-block-b-blocks-alert <?php echo 'align' . esc_attr( $align ); ?>' id='bBlocksAlert-<?php echo esc_attr($cId) ?>'> |
| 54 |
<style>@import url(<?php echo esc_url($typography['googleFontLink'] ?? ''); ?>); <?php echo wp_kses($alertStyle::renderStyle(), []) ?></style> |
| 55 |
|
| 56 |
<div class='bBlocksAlert'> |
| 57 |
<div class='alert'> |
| 58 |
<?php echo $icon['class'] ? "<i class='". esc_attr( $icon['class'] ) ."'></i>" : ''; ?> |
| 59 |
|
| 60 |
<span class='alertMessage'><?php echo wp_kses_post( $message );?></span> |
| 61 |
|
| 62 |
<?php echo $isDismiss ? "<i class='alertClose fa fa-times-circle'></i>" : ''; ?> |
| 63 |
</div> |
| 64 |
</div> |
| 65 |
</div> |
| 66 |
|
| 67 |
<?php $alertStyle::$styles = array(); // Empty styles |
| 68 |
return ob_get_clean(); |
| 69 |
} |
| 70 |
} |
| 71 |
new BBlocksAlert(); |