JavaScript for WordPress › Forums › Gutenberg Development › Fatal error due to the register_block_type
- This topic has 10 replies, 2 voices, and was last updated 6 years, 8 months ago by Zac Gordon.
-
AuthorPosts
-
January 28, 2018 at 7:00 pm #39941mikemcalisterParticipant
I’m also getting a fatal error due to the register_block_type. I’m not using the course files, I fired up my own plugin using CGB.
Fatal error: Uncaught Error: Call to undefined function register_block_type()
The error is referring to this snippet:
register_block_type( 'example/example-testimonial-list', [ 'render_callback' => 'atomic_testimonial_list_render', ] );
I’ve tried several different approaches but not sure why the function is returning as undefined. Anyone come up with a fix for this yet?
January 28, 2018 at 7:13 pm #39944Zac GordonKeymasterHey @mikemcalister
My guess is that this is because something like this is missing at the top of your code:
const { registerBlockType } = wp.blocks;
Is that it?
January 28, 2018 at 7:18 pm #39949mikemcalisterParticipant@zgordon Thanks for the quick reply, Zac! I do have that in my block.js, but not in the php file where the register_block_type function is. Similarly to your course files, I have the function that renders the posts and the register_block_type call in the main php file.
January 28, 2018 at 7:44 pm #39956Zac GordonKeymasterOoops! Sorry! I missed that you were talking on the PHP side for a dynamic block!
Okay, that is weird. Can’t remember if I have come across it before..
A couple shots in the dark here (some of them are real stretches, but hopefully something helps):
– When you install the course example plugin (or another plugin with a dynamic block) does it give you the same error?
– Does ‘example/example-testimonial-list’ exist as an actual block?
– Is there possibly an error before that line?
– The Gutenberg plugin is installed, right?
– This function actually exists, right? atomic_testimonial_list_renderJust some thoughts on starting points.. Please let me know what you find!
January 28, 2018 at 7:49 pm #39964Zac GordonKeymaster@mikemcalister Just pinging you here again since I moved this to it’s own thread 🙂
January 28, 2018 at 9:56 pm #39972mikemcalisterParticipantThanks for the checklist! I don’t get the error when working with the course plugin. I did get it when trying to rename the course plugin, similar to the other user. And now I’m having the error in my own plugin. Everything else looks good: block exists, Gutenberg installed, render function exists.
Here’s a zip of the plugin I’m working on for reference. It should throw the error on activation. To fix the error, you can comment out register_block_type in src/custom-post-types/cpt.php, where I have the render function as well. I don’t expect you to review this plugin or spend a bunch of time hunting down a bug, but might be helpful if it turns out to be a common issue.
January 28, 2018 at 10:24 pm #39980Zac GordonKeymasterHmmm this is weird. I am getting the same error as you. Played around a bit with it but not seeing a quick solution.
I would suggest try posting up here https://github.com/WordPress/gutenberg/issues and please let us know what you find!!!
January 28, 2018 at 10:25 pm #39982mikemcalisterParticipantThanks for the quick look! I will definitely report back anything I find.
January 28, 2018 at 10:29 pm #39984Zac GordonKeymasterAlso asked in #editor-js core channel for you 🙂
January 29, 2018 at 8:09 am #40008mikemcalisterParticipantThanks for pinging the #editor-js channel! Someone came through with a suggestion to hook your block loading to the init action, as seen below. This has removed the register_block_type error!
function load_your_blocks() { /** * Initialize the blocks */ require_once plugin_dir_path( __FILE__ ) . 'src/init.php'; } add_action( 'init', 'load_your_blocks' );
January 29, 2018 at 12:58 pm #40037Zac GordonKeymasterOhhhh that is interesting. Makes sense and sounds like they might change the priority so loads all the time or at least resolve the issue when it loads into Core.
Glad we got this sorted!!! Weird it only happens if your plugin name begins with something before G ;p
-
AuthorPosts
- You must be logged in to reply to this topic.