wp-gutenberg-block-template/index.php

45 lines
1.1 KiB
PHP

<?php
add_action( 'init', function() {
$block_namespace = 'namespace'; // TODO
$block_slug = 'slug'; // TODO
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( "$block_namespace/$block_slug", array(
'editor_script' => "{$block_slug}-block-editor",
'editor_style' => "{$block_slug}-block-editor",
'style' => "{$block_slug}-block",
) );
} );