Detect when page has been edited by Bricks

I’m looking to integrate Bricks for a certain custom post types. What’s the recommended way to:

  1. Detect that a post has been edited by Bricks? This would be used to remove actions that add content to the bottom of the post, which can be added by my custom Bricks elements instead.

  2. Insert a template of elements when the Bricks editor loads? For example, I’d insert the “Course Information” and “Pricing Table” elements when a Course is first edited. If there’s a way to just mark gutenberg blocks to their Bricks element equivalent, that could work too.

There’s some other nice to haves to make it easy for users to edit content for a specific custom post type, but this would be a good start. Otherwise I’ll be trying to do this shortly and I’ll post any details I can find for others to see. Thanks!

1 Like

You can detect if a post has been edited by Bricks by checking the _bricks_data meta field in the post metadata. If it exists, the post has been modified using Bricks. To insert a template when the Bricks editor loads, you can use the bricks/editor/init hook to pre-populate elements. If you’re looking to map Gutenberg blocks to Bricks elements, you may need a custom script to translate block data. Let me know if you need specific code examples!

@adilhassan Thanks for the notes!

I ended up using the $block variable to specify the block that the Bricks element mapped to. For blocks that didn’t have any settings, I needed to return a non-empty array via convert_block_to_element_settings for the mapping to be detected. It does require that the Bricks setting to migrate blocks to elements is enabled, which I think makes sense.

Bricks seems to override and not use the hooks that were being used to output content at the bottom of the post, so I didn’t need to detect the _bricks_data meta field and remove actions if it existed.

In case you or others are interested I have the code we currently have ready for review here. Feedback welcome! Bricks support by brianhogg · Pull Request #2876 · gocodebox/lifterlms · GitHub