| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package Flexible_Table_Block; |
| 4 |
* @author Aki Hamano |
| 5 |
* @license GPL-2.0+ |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Flexible_Table_Block; |
| 9 |
|
| 10 |
class Enqueue { |
| 11 |
|
| 12 |
/** |
| 13 |
* Constructor |
| 14 |
*/ |
| 15 |
public function __construct() { |
| 16 |
// Register block. |
| 17 |
add_action( 'init', array( $this, 'register_block' ) ); |
| 18 |
|
| 19 |
// Enqueue front-end scripts. |
| 20 |
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); |
| 21 |
|
| 22 |
// Enqueue block-editor assets. |
| 23 |
if ( is_admin() ) { |
| 24 |
add_action( 'enqueue_block_assets', array( $this, 'enqueue_block_editor_assets' ) ); |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Register block |
| 30 |
*/ |
| 31 |
public function register_block() { |
| 32 |
register_block_type( FTB_PATH . '/build' ); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Enqueue front-end scripts |
| 37 |
*/ |
| 38 |
public function enqueue_scripts() { |
| 39 |
wp_register_style( |
| 40 |
'flexible-table-block', |
| 41 |
FTB_URL . '/build/style-index.css', |
| 42 |
array(), |
| 43 |
filemtime( FTB_PATH . '/build/style-index.css' ), |
| 44 |
); |
| 45 |
|
| 46 |
$responsive_css = Helper::get_responsive_css(); |
| 47 |
$block_css = Helper::get_block_css( '.' . FTB_BLOCK_CLASS ); |
| 48 |
$css = Helper::minify_css( $block_css . $responsive_css ); |
| 49 |
|
| 50 |
wp_add_inline_style( 'flexible-table-block', $css ); |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Enqueue block-editor assets |
| 55 |
*/ |
| 56 |
public function enqueue_block_editor_assets() { |
| 57 |
$asset_file = include FTB_PATH . '/build/index.asset.php'; |
| 58 |
|
| 59 |
wp_register_script( |
| 60 |
'flexible-table-block-editor', |
| 61 |
FTB_URL . '/build/index.js', |
| 62 |
$asset_file['dependencies'], |
| 63 |
filemtime( FTB_PATH . '/build/index.js' ), |
| 64 |
); |
| 65 |
|
| 66 |
wp_set_script_translations( 'flexible-table-block-editor', FTB_NAMESPACE ); |
| 67 |
|
| 68 |
wp_register_style( |
| 69 |
'flexible-table-block-editor', |
| 70 |
FTB_URL . '/build/index.css', |
| 71 |
array(), |
| 72 |
filemtime( FTB_PATH . '/build/index.css' ), |
| 73 |
); |
| 74 |
|
| 75 |
$block_css = Helper::get_block_css( '.editor-styles-wrapper ' ); |
| 76 |
$css = Helper::minify_css( $block_css ); |
| 77 |
|
| 78 |
wp_add_inline_style( 'flexible-table-block-editor', $css ); |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
new Enqueue(); |
| 83 |
|