$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{ protected static $_instance = null; function __construct(){ add_action( 'enqueue_block_assets', [$this, 'enqueue_block_assets'] ); add_action( 'init', [$this, 'register'] ); } public static function instance(){ if(self::$_instance === null){ self::$_instance = new self(); } return self::$_instance; } function enqueue_block_assets(){ wp_enqueue_script( 'fontAwesomeKit', ABB_ASSETS_DIR . 'js/font-awesome-kit.js', array(), ABB_PLUGIN_VERSION, true ); } function register() { wp_register_script( 'abb_editor_script', plugins_url( 'dist/editor.js', __FILE__ ), array( 'wp-blob', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-html-entities', 'wp-i18n', 'wp-rich-text', 'fontAwesomeKit' ), ABB_PLUGIN_VERSION, false ); // Backend Script wp_register_style( 'abb_editor_style', plugins_url( 'dist/editor.css', __FILE__ ), array( 'wp-edit-blocks' ), ABB_PLUGIN_VERSION ); // Backend Style wp_register_script( 'abb_script', plugins_url( 'dist/script.js', __FILE__ ), array( 'jquery', 'fontAwesomeKit' ), ABB_PLUGIN_VERSION, true ); // Frontend Script wp_register_style( 'abb_style', plugins_url( 'dist/style.css', __FILE__ ), array( 'wp-editor' ), ABB_PLUGIN_VERSION ); // Frontend Style register_block_type( 'abb/alert-box', array( 'editor_script' => 'abb_editor_script', 'editor_style' => 'abb_editor_style', 'script' => 'abb_script', 'style' => 'abb_style', 'render_callback' => [$this, 'render'] ) ); // Register Block wp_set_script_translations( 'abb_editor_script', 'alert-box-block', plugin_dir_path( __FILE__ ) . 'languages' ); // Translate } function render($attributes){ extract( $attributes ); $align = $align ?? ''; $cId = $cId ?? ''; $type = $type ?? 'general'; $width = $width ?? '100%'; $alignment = $alignment ?? 'center'; $textAlign = $textAlign ?? 'center'; $message = $message ?? 'You have an alert message!'; $icon = $icon ?? array( 'class' => 'fa fa-exclamation-circle' ); $isDismiss = $isDismiss ?? true; $typography = $typography ?? array( 'fontSize' => 25 ); $colors = $colors ?? array( 'color' => '#333', 'bg' => '#fff' ); $padding = $padding ?? array( 'vertical' => '15px', 'horizontal' => '30px' ); $border = $border ?? array( 'width' => '2px', 'color' => '#333', 'radius' => '8px' ); $shadow = $shadow ?? array(); $alertBoxStyle = new ABBStyleGenerator(); // Generate Styles $alertBoxStyle::addStyle("#abbAlertBox-$cId .abbAlertBox", array( 'text-align' => $alignment )); $alertBoxStyle::addStyle("#abbAlertBox-$cId .abbAlertBox .alert", array( '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", array( 'font-size' => $typography['fontSize'] ?? '25px', 'color' => $colors['color'] ?? '#333' )); $alertBoxStyle::addStyle("#abbAlertBox-$cId .abbAlertBox .alert .alertClose", array( 'color' => $colors['color'] ?? '#333' )); ob_start(); ?>
' id='abbAlertBox-'>
" : ''; ?> " : ''; ?>