wp-gutenberg-block-template/svg.php

47 lines
1.1 KiB
PHP
Raw Normal View History

2020-08-12 13:20:11 +00:00
<?php
2020-08-12 18:29:39 +00:00
$block_slug = basename( __FILE__, '.php' );
$theme_slug = get_option( 'stylesheet' );
add_action( 'init', function() {
global $block_slug, $theme_slug;
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:29:39 +00:00
register_block_type( "$theme_slug/$block_slug", array(
'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
} );