scaffold-command/templates/block-php.mustache
2018-01-10 18:10:37 +01:00

56 lines
1.3 KiB
Text

<?php
/**
* Functions to register client-side assets (scripts and stylesheets) for the
* Gutenberg block.
*
* @package {{namespace}}
*/
/**
* Registers all block assets so that they can be enqueued through Gutenberg in
* the corresponding context.
*
* @see https://wordpress.org/gutenberg/handbook/blocks/writing-your-first-block-type/#enqueuing-block-scripts
*/
function {{machine_name}}_block_init() {
$dir = dirname( __FILE__ );
$block_js = '{{slug}}/block.js';
wp_register_script(
'{{slug}}-block-editor',
plugins_url( $block_js, __FILE__ ),
array(
'wp-blocks',
'wp-i18n',
'wp-element',
),
filemtime( "$dir/$block_js" )
);
$editor_css = '{{slug}}/editor.css';
wp_register_style(
'{{slug}}-block-editor',
plugins_url( $editor_css, __FILE__ ),
array(
'wp-blocks',
),
filemtime( "$dir/$editor_css" )
);
$style_css = '{{slug}}/style.css';
wp_register_style(
'{{slug}}-block',
plugins_url( $style_css, __FILE__ ),
array(
'wp-blocks',
),
filemtime( "$dir/$style_css" )
);
register_block_type( '{{namespace}}/{{slug}}', array(
'editor_script' => '{{slug}}-block-editor',
'editor_style' => '{{slug}}-block-editor',
'style' => '{{slug}}-block',
) );
}
add_action( 'init', '{{machine_name}}_block_init' );