$style ){ $new = ''; foreach( $style as $property => $value ){ if( $value == '' ){ $new .= $property; }else { $new .= " $property: $value;"; } } $output .= "$selector { $new }"; } return $output; } } // Countdown Time class CTBCountdownTimeBlock{ function __construct(){ add_action( 'init', [$this, 'onInit'] ); } function onInit() { wp_register_style( 'ctb-countdown-time-editor-style', plugins_url( 'dist/editor.css', __FILE__ ), [ 'wp-edit-blocks' ], CTB_PLUGIN_VERSION ); // Backend Style wp_register_style( 'ctb-countdown-time-style', plugins_url( 'dist/style.css', __FILE__ ), [ 'wp-editor' ], CTB_PLUGIN_VERSION ); // Frontend Style register_block_type( __DIR__, [ 'editor_style' => 'ctb-countdown-time-editor-style', 'style' => 'ctb-countdown-time-style', 'render_callback' => [$this, 'render'] ] ); // Register Block wp_set_script_translations( 'ctb-countdown-time-editor-script', 'countdown-time', plugin_dir_path( __FILE__ ) . 'languages' ); // Translate } function render( $attributes ){ extract( $attributes ); $countdownStyle = new CTBStyleGenerator(); // Generate Styles $countdownStyle::addStyle( "#ctbCountdownTime-$cId", [ 'align-items' => $alignment, 'justify-content' => $alignment ] ); $countdownStyle::addStyle( "#ctbCountdownTime-$cId .countdownItems", [ 'width' => '0px' === $width || '0%' === $width || '0em' === $width ? 'auto' : $width, $background['styles'] ?? 'background-color: #0000;' => '', 'padding' => $padding['styles'] ?? '10px 15px', 'box-shadow' => $shadow['styles'] ?? 'none', 'justify-content' => $boxPosition ] ); $countdownStyle::addStyle( "#ctbCountdownTime-$cId .countdownItems .countdownItem", [ $boxBG['styles'] ?? 'background-image: linear-gradient(135deg, #4527a4, #8344c5);' => '', 'width' => $boxWidth, 'height' => $boxHeight, 'margin-left' => "calc( $boxSpace / 2 )", 'margin-right' => "calc( $boxSpace / 2 )", $boxBorder['styles'] ?? 'border-radius: 5%;' => '', 'box-shadow' => $boxShadow['styles'] ?? '0 0 0 0 #0000' ] ); $countdownStyle::addStyle( "#ctbCountdownTime-$cId .countdownItems .separator::before", [ 'content' => "'$sepType'", 'font-size' => $sepSize . 'px', 'color' => $sepColor ] ); $countdownStyle::addStyle( "#ctbCountdownTime-$cId .countdownItems .countdownItem .digit", [ 'color' => $digitColor, $digitTypo['styles'] ?? 'font-size: 48px;' => '' ] ); $countdownStyle::addStyle( "#ctbCountdownTime-$cId .countdownItems .countdownItem .label", [ 'color' => $labelColor, $labelTypo['styles'] ?? 'font-size: 18px;' => '' ] ); $boxClass = $boxIsInline ? 'inline' : ''; ob_start(); ?>