Forum Replies Created
-
AuthorPosts
-
mikemcalisterParticipant
Thanks for the reply! This looks super handy.
mikemcalisterParticipantI was actually able to solve this by using
withClientIdClassName
instead, which has props available to it. I’d still be curious to know if it’s possible to pass attributes as mentioned above!mikemcalisterParticipantHowdy folks,
I’m also working on something that uses filters to adjust classes, but I’m using
blocks.getBlockDefaultClassName
. Any clues on the cleanest way to get attributes (attributes.bgType
) from the block passed through to this function? I tried a few different ways but haven’t been able to tap into them yet since it runs outside of the block’s render where attributes are defined. Thanks in advance for any tips!wp.hooks.addFilter( "blocks.getBlockDefaultClassName", "atomicblocks/ab-column-block-class-name", abCustomClassName ); function abCustomClassName( className, name ) { if ( 'atomic-blocks/ab-columns' === name ) { return classnames( className, 'ab-has-bg-' + attributes.bgType ); } return className; }
mikemcalisterParticipantThat actually worked great! I extracted that out to its own file and everything is smooth sailing. Thanks, Zac!
mikemcalisterParticipantWhen I try to reference the SocialMediaIcons component in the save function, I get an undefined error. “ReferenceError: SocialMediaIcons is not defined.” That component is defined in the edit function and works as expected in that sense.
mikemcalisterParticipantHey there, there is a fix for this register_block_type error in another thread: https://javascriptforwp.com/forums/topic/moved-fatal-error-due-to-the-register_block_type/
mikemcalisterParticipantThanks 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' );
mikemcalisterParticipantThanks for the quick look! I will definitely report back anything I find.
mikemcalisterParticipantThanks 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.
mikemcalisterParticipant@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.
mikemcalisterParticipantI was able to solve this by installing babel-preset-stage-2 and adding it to the presets in webpack.config.js.
-
AuthorPosts