Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC: Use Block bindings API with existing post_meta #332

Open
4 tasks done
carstingaxion opened this issue Feb 21, 2024 · 0 comments
Open
4 tasks done

POC: Use Block bindings API with existing post_meta #332

carstingaxion opened this issue Feb 21, 2024 · 0 comments

Comments

@carstingaxion
Copy link

carstingaxion commented Feb 21, 2024

Similar to #330 I wanted to validate my ideas on data-migration.

Today: The new Block bindings API connected to existing post_meta.

This should help migrating the existing shortcodes, which use some special template tags like {{duration}} to display post_meta. I did bind the post_meta field of remark to a new core block variation, and it worked really well.

Ressources

Steps I took

  • Update to WP 6.5 beta 1
  • Change register_post_type arguments of wp_theatre_prod to support `'custom-fields'
  • Change register_post_meta to include 'show_in_rest' following the Testing Instructions
  • Just add the markup into the editor
<!-- wp:paragraph {"metadata":{"bindings":{"content":{"source":"core/post-meta","args":{"key":"remark"}}}}} -->
<p>Paragraph</p>
<!-- /wp:paragraph -->

This worked really well.

Image

To make this a little easier to recognize for the editor I created a simple block-variation of the paragraph block to hold the markup I added by hand in the step before. This block variation even allowed me to define a custom name and icon, which was nice.

Image

Block variations could be one way to go to properly migrate into the new era. You can give it a try and have a look through the code at https://github.com/figuren-theater/theater-production-blocks/tree/feature/wpt-shortcode-to-query-block

some findings to feed back to the gutenberg contributors

  • Transforming a paragraph into a headline erases all relevant block attributes, which is a known issue
  • adding the attributes to registerBlockVariation() fails, because 'metadata' is undefined; 🐛 maybe this is no properly registered attribute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant