Latest TweetsPlugin update! Disable Gutenberg v1.5 adds whitelist options to always enable Block Editor on any post :) m0n.co/wpdg
Perishable Press

Fix Gutenberg Errors

I’ve been exploring WordPress new Gutenberg functionality, and unfortunately keep encountering various weird errors. So to keep things organized and hopefully help others on the same path, I’m going to update this post with any Gutenberg errors for which I am able to find a solution. This includes any PHP errors, warnings, notices, as well as any JavaScript and/or debug/console errors.

To save time, I sometimes abbreviate Gutenberg as a numeronym: G7G or g7g.

PHP Fatal error: Uncaught Error: Call to undefined function register_block_type()

First up, the following error:

[26-Mar-2018 22:34:31 UTC] PHP Fatal error:  Uncaught Error: Call to undefined function register_block_type() in /.../wp-content/plugins/whatever.php:111

From what I could find about this surprising error, it’s a known bug that will be fixed in a future update of Gutenberg. For those who want to resolve the issue now, here is a workaround..

The error above is related to calling the following tag directly:

register_block_type('g7g-blocks/block-06', array('render_callback' => 'g7g_render_block_latest_post'));

So look for any instances of code where register_block_type() is used, and replace with this:

function g7g_load_blocks() {
	
	register_block_type('g7g-blocks/block-06', array('render_callback' => 'g7g_render_block_latest_post'));
	
}
add_action('init', 'g7g_load_blocks');

Basically the idea here is to call register_block_type() only via the init hook, instead of just calling directly in the plugin source.

Surely, there are more errors (and solutions) to come! ;)

Jeff Starr
About the Author Jeff Starr = Web Developer. Book Author. Secretly Important.
Archives
[ Comments are closed for this post ]