48 lines
1.1 KiB
PHP
48 lines
1.1 KiB
PHP
<?php
|
|
$block_slug = basename( dirname( __FILE__ ) );
|
|
|
|
$theme_slug = get_option( 'stylesheet' );
|
|
|
|
add_action( 'init', function() {
|
|
global $block_slug, $theme_slug;
|
|
|
|
if ( ! function_exists( 'register_block_type' ) ) {
|
|
return;
|
|
}
|
|
|
|
$dir = get_template_directory() . "/blocks/$block_slug";
|
|
$uri = get_template_directory_uri() . "/blocks/$block_slug";
|
|
|
|
$asset_file = include( get_template_directory() . "/blocks/$block_slug/build/index.asset.php");
|
|
|
|
$index_js = 'build/index.js';
|
|
wp_register_script(
|
|
"{$block_slug}-block-editor",
|
|
"$uri/$index_js",
|
|
$asset_file['dependencies'],
|
|
$asset_file['version']
|
|
);
|
|
|
|
$editor_css = 'build/index.css';
|
|
wp_register_style(
|
|
"{$block_slug}-block-editor",
|
|
"$uri/$editor_css",
|
|
array(),
|
|
filemtime( "$dir/$editor_css" )
|
|
);
|
|
|
|
$style_css = 'build/style-index.css';
|
|
wp_register_style(
|
|
"{$block_slug}-block",
|
|
"$uri/$style_css",
|
|
array(),
|
|
filemtime( "$dir/$style_css" )
|
|
);
|
|
|
|
register_block_type( "$theme_slug/$block_slug", array(
|
|
'editor_script' => "{$block_slug}-block-editor",
|
|
'editor_style' => "{$block_slug}-block-editor",
|
|
'style' => "{$block_slug}-block",
|
|
) );
|
|
} );
|