2020-08-12 13:20:11 +00:00
|
|
|
<?php
|
2020-08-12 18:29:39 +00:00
|
|
|
add_action( 'init', function() {
|
2020-08-16 18:10:22 +00:00
|
|
|
$block_namespace = 'namespace'; // TODO
|
|
|
|
$block_slug = 'slug'; // TODO
|
2020-08-12 18:29:39 +00:00
|
|
|
|
2020-08-12 13:20:11 +00:00
|
|
|
if ( ! function_exists( 'register_block_type' ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-12 18:29:39 +00:00
|
|
|
$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");
|
2020-08-12 13:20:11 +00:00
|
|
|
|
|
|
|
$index_js = 'build/index.js';
|
|
|
|
wp_register_script(
|
2020-08-12 18:29:39 +00:00
|
|
|
"{$block_slug}-block-editor",
|
2020-08-12 13:20:11 +00:00
|
|
|
"$uri/$index_js",
|
|
|
|
$asset_file['dependencies'],
|
|
|
|
$asset_file['version']
|
|
|
|
);
|
|
|
|
|
2020-08-12 13:55:40 +00:00
|
|
|
$editor_css = 'build/index.css';
|
2020-08-12 13:20:11 +00:00
|
|
|
wp_register_style(
|
2020-08-12 18:29:39 +00:00
|
|
|
"{$block_slug}-block-editor",
|
2020-08-12 13:20:11 +00:00
|
|
|
"$uri/$editor_css",
|
|
|
|
array(),
|
|
|
|
filemtime( "$dir/$editor_css" )
|
|
|
|
);
|
|
|
|
|
2020-08-12 13:55:40 +00:00
|
|
|
$style_css = 'build/style-index.css';
|
2020-08-12 13:20:11 +00:00
|
|
|
wp_register_style(
|
2020-08-12 18:29:39 +00:00
|
|
|
"{$block_slug}-block",
|
2020-08-12 13:20:11 +00:00
|
|
|
"$uri/$style_css",
|
|
|
|
array(),
|
|
|
|
filemtime( "$dir/$style_css" )
|
|
|
|
);
|
|
|
|
|
2020-08-12 18:52:02 +00:00
|
|
|
register_block_type( "$block_namespace/$block_slug", array(
|
2020-08-12 18:29:39 +00:00
|
|
|
'editor_script' => "{$block_slug}-block-editor",
|
|
|
|
'editor_style' => "{$block_slug}-block-editor",
|
|
|
|
'style' => "{$block_slug}-block",
|
2020-08-12 13:20:11 +00:00
|
|
|
) );
|
2020-08-12 18:29:39 +00:00
|
|
|
} );
|