wp-gutenberg-block-template/svg.php

44 lines
1.1 KiB
PHP
Raw Normal View History

2020-08-12 13:20:11 +00:00
<?php
function svg_block_init() {
if ( ! function_exists( 'register_block_type' ) ) {
return;
}
2020-08-12 14:26:50 +00:00
// remember - for a block defined in a plugin, we will not be using
// get_template_directory(), etc, it will be the equivalent for plugins.
2020-08-12 13:20:11 +00:00
$dir = get_template_directory() . '/blocks/svg';
$uri = get_template_directory_uri() . "/blocks/svg";
$asset_file = include( get_template_directory() . '/blocks/svg/build/index.asset.php');
$index_js = 'build/index.js';
wp_register_script(
'svg-block-editor',
"$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(
'svg-block-editor',
"$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(
'svg-block',
"$uri/$style_css",
array(),
filemtime( "$dir/$style_css" )
);
register_block_type( 'room-vw/svg', array(
'editor_script' => 'svg-block-editor',
'editor_style' => 'svg-block-editor',
'style' => 'svg-block',
) );
}
add_action( 'init', 'svg_block_init' );