| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
if (!class_exists('CTRBPBlock')) { |
| 5 |
class CTRBPBlock |
| 6 |
{ |
| 7 |
function __construct() |
| 8 |
{ |
| 9 |
add_action('enqueue_block_assets', [$this, 'enqueueBlockAssets']); |
| 10 |
add_action('init', [$this, 'onInit']); |
| 11 |
} |
| 12 |
|
| 13 |
function enqueueBlockAssets() |
| 14 |
{ |
| 15 |
wp_register_style('font-awesome-7', CTRB_DIR_URL . 'public/css/font-awesome.min.css', [], '7.1.0'); |
| 16 |
wp_enqueue_style('font-awesome-7'); |
| 17 |
|
| 18 |
$handle = 'ctrb-inline-premium'; |
| 19 |
wp_register_script($handle, false, [], CTRB_VERSION, true); |
| 20 |
$data = [ |
| 21 |
'isPremium' => function_exists('ctrbIsPremium') ? ctrbIsPremium() : false, |
| 22 |
'hasPro' => defined('CTRB_HAS_PRO') ? CTRB_HAS_PRO : false, |
| 23 |
'version' => defined('CTRB_VERSION') ? CTRB_VERSION : '', |
| 24 |
'isWcActive' => class_exists('WooCommerce'), |
| 25 |
'isWcInstalled' => file_exists(WP_PLUGIN_DIR . '/woocommerce/woocommerce.php'), |
| 26 |
]; |
| 27 |
$inline = 'window.ctrbPremiumProps = Object.assign(window.ctrbPremiumProps || {}, ' . wp_json_encode($data) . ');'; |
| 28 |
wp_add_inline_script($handle, $inline, 'before'); |
| 29 |
wp_enqueue_script($handle); |
| 30 |
} |
| 31 |
|
| 32 |
function onInit() |
| 33 |
{ |
| 34 |
register_block_type(__DIR__ . '/build'); |
| 35 |
} |
| 36 |
} |
| 37 |
new CTRBPBlock(); |
| 38 |
} |
| 39 |
|