| 1 |
<?php |
| 2 |
class CTBBlock{ |
| 3 |
function __construct(){ |
| 4 |
add_action( 'init', [$this, 'onInit'] ); |
| 5 |
} |
| 6 |
|
| 7 |
function onInit() { |
| 8 |
wp_register_style( 'ctb-countdown-time-style', CTB_DIR_URL . 'dist/style.css', [], CTB_VERSION ); |
| 9 |
wp_register_style( 'ctb-countdown-time-editor-style', CTB_DIR_URL . 'dist/editor.css', [ 'ctb-countdown-time-style' ], CTB_VERSION ); |
| 10 |
|
| 11 |
register_block_type( __DIR__, [ |
| 12 |
'editor_style' => 'ctb-countdown-time-editor-style', |
| 13 |
'render_callback' => [$this, 'render'] |
| 14 |
] ); |
| 15 |
|
| 16 |
wp_set_script_translations( 'ctb-countdown-time-editor-script', 'countdown-time', CTB_DIR_PATH . '/languages' ); |
| 17 |
} |
| 18 |
|
| 19 |
function render( $attributes, $content ){ |
| 20 |
extract( $attributes ); |
| 21 |
|
| 22 |
wp_enqueue_style( 'ctb-countdown-time-style' ); |
| 23 |
wp_enqueue_script( 'ctb-countdown-time-script', CTB_DIR_URL . 'dist/script.js', [ 'react', 'react-dom' ], CTB_VERSION, true ); |
| 24 |
wp_set_script_translations( 'ctb-countdown-time-script', 'countdown-time', CTB_DIR_PATH . '/languages' ); |
| 25 |
|
| 26 |
$className = $className ?? ''; |
| 27 |
$extraClass = ctbIsPremium() ? 'premium' : 'free'; |
| 28 |
$blockClassName = "wp-block-ctb-countdown-time $extraClass $className align$align"; |
| 29 |
|
| 30 |
ob_start(); ?> |
| 31 |
<div |
| 32 |
class='<?php echo esc_attr( $blockClassName ); ?>' |
| 33 |
id='ctbCountdownTime-<?php echo esc_attr( $cId ) ?>' |
| 34 |
data-nonce='<?php echo esc_attr( wp_json_encode( wp_create_nonce( 'wp_ajax' ) ) ); ?>' |
| 35 |
data-attributes='<?php echo esc_attr( wp_json_encode( $attributes ) ); ?>' |
| 36 |
data-content='<?php echo esc_attr( wp_json_encode( $content ) ); ?>' |
| 37 |
></div> |
| 38 |
|
| 39 |
<?php return ob_get_clean(); |
| 40 |
} // Render |
| 41 |
} |
| 42 |
new CTBBlock; |