From a7441a6d155f5d7770cc70a1c34eeeb4b097dc21 Mon Sep 17 00:00:00 2001 From: Sal Ferrarello Date: Sat, 21 Apr 2018 23:53:37 -0400 Subject: [PATCH] Add function_exists() check to block PHP template Check for the existance of the function register_block_type() in the PHP code when creating a block. Since Gutenberg has not yet been merged into core, currently the function register_block_type() is only defined if the Gutenberg plugin is installed and activated. See #146 --- templates/block-php.mustache | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/templates/block-php.mustache b/templates/block-php.mustache index 43f6708e3..f925bcda3 100644 --- a/templates/block-php.mustache +++ b/templates/block-php.mustache @@ -13,6 +13,10 @@ * @see https://wordpress.org/gutenberg/handbook/blocks/writing-your-first-block-type/#enqueuing-block-scripts */ 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}}