| 1 |
<?php |
| 2 |
|
| 3 |
namespace Sendy\WooCommerce\Utils; |
| 4 |
|
| 5 |
use Automattic\WooCommerce\Blocks\Integrations\IntegrationInterface; |
| 6 |
use Sendy\WooCommerce\Plugin; |
| 7 |
|
| 8 |
define('SENDY_BLOCK_VERSION', '1.0.0'); |
| 9 |
|
| 10 |
class BlocksIntegration implements IntegrationInterface |
| 11 |
{ |
| 12 |
public function get_name() |
| 13 |
{ |
| 14 |
return 'sendy-pickup-points'; |
| 15 |
} |
| 16 |
|
| 17 |
public function initialize() |
| 18 |
{ |
| 19 |
$this->register_block_frontend_scripts(); |
| 20 |
$this->register_block_editor_scripts(); |
| 21 |
} |
| 22 |
|
| 23 |
public function get_script_handles() |
| 24 |
{ |
| 25 |
return ['sendy-checkout-block-frontend']; |
| 26 |
} |
| 27 |
|
| 28 |
public function get_editor_script_handles() |
| 29 |
{ |
| 30 |
return ['sendy-block-editor']; |
| 31 |
} |
| 32 |
|
| 33 |
public function get_script_data() |
| 34 |
{ |
| 35 |
return []; |
| 36 |
} |
| 37 |
|
| 38 |
private function register_block_frontend_scripts() |
| 39 |
{ |
| 40 |
$script_url = SENDY_WC_PLUGIN_DIR_URL . '/build/sendy-checkout-block-frontend.js'; |
| 41 |
$script_asset_path = SENDY_WC_PLUGIN_DIR_URL . '/build/sendy-checkout-block-frontend.asset.php'; |
| 42 |
|
| 43 |
$script_asset = file_exists($script_asset_path) |
| 44 |
? require $script_asset_path |
| 45 |
: [ |
| 46 |
'dependencies' => [], |
| 47 |
'version' => $this->get_file_version($script_asset_path), |
| 48 |
]; |
| 49 |
|
| 50 |
wp_enqueue_style( |
| 51 |
'sendy-checkout-block-frontend-styling', |
| 52 |
SENDY_WC_PLUGIN_DIR_URL . '/resources/css/frontend.css', |
| 53 |
[], |
| 54 |
Plugin::VERSION, |
| 55 |
); |
| 56 |
|
| 57 |
wp_register_script( |
| 58 |
'sendy-checkout-block-frontend', |
| 59 |
$script_url, |
| 60 |
$script_asset['dependencies'], |
| 61 |
$script_asset['version'], |
| 62 |
true, |
| 63 |
); |
| 64 |
} |
| 65 |
|
| 66 |
private function register_block_editor_scripts() |
| 67 |
{ |
| 68 |
$script_path = '/build/index.js'; |
| 69 |
$script_url = plugins_url('sendy' . $script_path); |
| 70 |
$script_asset_path = plugins_url('sendy/build/index.asset.php'); |
| 71 |
$script_asset = file_exists($script_asset_path) |
| 72 |
? require $script_asset_path |
| 73 |
: [ |
| 74 |
'dependencies' => [], |
| 75 |
'version' => $this->get_file_version($script_asset_path), |
| 76 |
]; |
| 77 |
|
| 78 |
wp_register_script( |
| 79 |
'sendy-block-editor', |
| 80 |
$script_url, |
| 81 |
$script_asset['dependencies'], |
| 82 |
$script_asset['version'], |
| 83 |
true, |
| 84 |
); |
| 85 |
} |
| 86 |
|
| 87 |
protected function get_file_version($file) |
| 88 |
{ |
| 89 |
if (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG && file_exists($file)) { |
| 90 |
return filemtime($file); |
| 91 |
} |
| 92 |
|
| 93 |
return SENDY_BLOCK_VERSION; |
| 94 |
} |
| 95 |
} |
| 96 |
|