$style ){ $new = ''; foreach( $style as $property => $value ){ if( $value == '' ){ $new .= $property; }else { $new .= " $property: $value;"; } } $output .= "$selector { $new }"; } return $output; } } // Countdown Time class CTBCountdownTimeBlock{ protected static $_instance = null; function __construct(){ add_action( 'init', [$this, 'register'] ); } public static function instance(){ if( self::$_instance === null ){ self::$_instance = new self(); } return self::$_instance; } function register() { wp_register_script( 'ctb_editor_script', plugins_url( 'dist/editor.js', __FILE__ ), [ 'wp-blob', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-html-entities', 'wp-i18n', 'wp-rich-text' ], CTB_PLUGIN_VERSION, false ); // Backend Script wp_register_style( 'ctb_editor_style', plugins_url( 'dist/editor.css', __FILE__ ), [ 'wp-edit-blocks' ], CTB_PLUGIN_VERSION ); // Backend Style wp_register_script( 'ctb_script', plugins_url( 'dist/script.js', __FILE__ ), [ 'jquery' ], CTB_PLUGIN_VERSION, true ); // Frontend Script wp_register_style( 'ctb_style', plugins_url( 'dist/style.css', __FILE__ ), [ 'wp-editor' ], CTB_PLUGIN_VERSION ); // Frontend Style register_block_type( 'ctb/countdown-time', [ 'editor_script' => 'ctb_editor_script', 'editor_style' => 'ctb_editor_style', 'script' => 'ctb_script', 'style' => 'ctb_style', 'render_callback' => [$this, 'render'] ] ); // Register Block wp_set_script_translations( 'ctb_editor_script', 'countdown-time', plugin_dir_path( __FILE__ ) . 'languages' ); // Translate } function render( $attributes ){ extract( $attributes ); $align = $align ?? ''; $cId = $cId ?? ''; $layout = $layout ?? 'default'; $boxIsInline = $boxIsInline ?? false; $boxPosition = $boxPosition ?? 'center'; $isLabels = $isLabels ?? true; $isDays = $isDays ?? true; $daysLabel = $daysLabel ?? 'Days'; $isHours = $isHours ?? true; $hoursLabel = $hoursLabel ?? 'Hours'; $isMinutes = $isMinutes ?? true; $minutesLabel = $minutesLabel ?? 'Minutes'; $isSeconds = $isSeconds ?? true; $secondsLabel = $secondsLabel ?? 'Seconds'; $width = $width ?? '0px'; $background = $background ?? [ 'color' => '#0000' ]; $padding = $padding ?? [ 'vertical' => '10px', 'horizontal' => '15px' ]; $shadow = $shadow ?? []; $alignment = $alignment ?? 'center'; $boxBG = $boxBG ?? [ 'type' => 'gradient', 'color' => '#4527a4', 'gradient' => 'linear-gradient(135deg, #4527a4, #8344c5)' ]; $boxWidth = $boxWidth ?? '170px'; $boxHeight = $boxHeight ?? '120px'; $boxSpace = $boxSpace ?? '30px'; $boxBorder = $boxBorder ?? [ 'radius' => '5%' ]; $boxShadow = $boxShadow ?? []; $digitTypo = $digitTypo ?? [ 'fontSize' => 48 ]; $digitColor = $digitColor ?? '#fff'; $labelTypo = $labelTypo ?? [ 'fontSize' => 18 ]; $labelColor = $labelColor ?? '#fff'; $isSep = $isSep ?? false; $sepType = $sepType ?? ':'; $sepSize = $sepSize ?? 52; $sepColor = $sepColor ?? '#4527a4'; $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(); ?>