$style ){ $new = ''; foreach( $style as $property => $value ){ if( $value == '' ){ $new .= $property; }else { $new .= " $property: $value;"; } } $output .= "$selector { $new }"; } return $output; } } // Alert Box Block class ABBAlertBoxBlock{ function __construct(){ add_action( 'enqueue_block_assets', [$this, 'enqueueBlockAssets'] ); add_action( 'init', [$this, 'onInit'] ); } function enqueueBlockAssets(){ wp_enqueue_style( 'fontAwesome', ABB_ASSETS_DIR . 'css/fontAwesome.min.css', [], '5.15.4' ); } function onInit() { wp_register_style( 'abb-alert-box-editor-style', plugins_url( 'dist/editor.css', __FILE__ ), [ 'wp-edit-blocks' ], ABB_PLUGIN_VERSION ); // Backend Style wp_register_style( 'abb-alert-box-style', plugins_url( 'dist/style.css', __FILE__ ), [ 'wp-editor' ], ABB_PLUGIN_VERSION ); // Frontend Style register_block_type( __DIR__, [ 'editor_style' => 'abb-alert-box-editor-style', 'style' => 'abb-alert-box-style', 'render_callback' => [$this, 'render'] ] ); // Register Block wp_set_script_translations( 'abb-alert-box-editor-script', 'alert-box-block', plugin_dir_path( __FILE__ ) . 'languages' ); // Translate } function render( $attributes ){ extract( $attributes ); $alertBoxStyle = new ABBStyleGenerator(); // Generate Styles $alertBoxStyle::addStyle( "#abbAlertBox-$cId .abbAlertBox", [ 'text-align' => $alignment ] ); $alertBoxStyle::addStyle( "#abbAlertBox-$cId .abbAlertBox .alert", [ 'text-align' => $textAlign, 'width' => '0px' === $width || '0%' === $width || '0em' === $width ? 'auto' : $width, $typography['styles'] ?? 'font-size: 25px;' => '', $colors['styles'] ?? 'color: #333; background: #fff;' => '', 'padding' => $padding['styles'] ?? '15px 30px', $border['styles'] ?? 'border: 2px solid #333; border-radius: 8px;' => '', 'box-shadow' => $shadow['styles'] ?? 'none' ] ); $alertBoxStyle::addStyle( "#abbAlertBox-$cId .abbAlertBox .alert .alertIcon", [ 'font-size' => $typography['fontSize'] ?? '25px', 'color' => $colors['color'] ?? '#333' ] ); $alertBoxStyle::addStyle( "#abbAlertBox-$cId .abbAlertBox .alert .alertClose", [ 'color' => $colors['color'] ?? '#333' ] ); ob_start(); ?>