HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/local/wp/vendor/wp-cli/scaffold-command/templates/block-php.mustache
<?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/designers-developers/developers/tutorials/block-tutorial/applying-styles-with-stylesheets/
 */
function {{machine_name}}_block_init() {
	// Skip block registration if Gutenberg is not enabled/merged.
	if ( ! function_exists( 'register_block_type' ) ) {
		return;
	}
	{{#plugin}}
	$dir = dirname( __FILE__ );
	{{/plugin}}
	{{#theme}}
	$dir = get_stylesheet_directory() . '/blocks';
	{{/theme}}

	$index_js = '{{slug}}/index.js';
	wp_register_script(
		'{{slug}}-block-editor',
		{{#plugin}}
		plugins_url( $index_js, __FILE__ ),
		{{/plugin}}
		{{#theme}}
		get_stylesheet_directory_uri() . "/blocks/{$index_js}",
		{{/theme}}
		[
			'wp-blocks',
			'wp-i18n',
			'wp-element',
		],
		filemtime( "{$dir}/{$index_js}" )
	);

	$editor_css = '{{slug}}/editor.css';
	wp_register_style(
		'{{slug}}-block-editor',
		{{#plugin}}
		plugins_url( $editor_css, __FILE__ ),
		{{/plugin}}
		{{#theme}}
		get_stylesheet_directory_uri() . "/blocks/{$editor_css}",
		{{/theme}}
		[],
		filemtime( "{$dir}/{$editor_css}" )
	);

	$style_css = '{{slug}}/style.css';
	wp_register_style(
		'{{slug}}-block',
		{{#plugin}}
		plugins_url( $style_css, __FILE__ ),
		{{/plugin}}
		{{#theme}}
		get_stylesheet_directory_uri() . "/blocks/{$style_css}",
		{{/theme}}
		[],
		filemtime( "{$dir}/{$style_css}" )
	);

	register_block_type( '{{namespace}}/{{slug}}', [
		'editor_script' => '{{slug}}-block-editor',
		'editor_style'  => '{{slug}}-block-editor',
		'style'         => '{{slug}}-block',
	] );
}

add_action( 'init', '{{machine_name}}_block_init' );