27 Jan

ACF Pro 5.12 Beta 1

By Liam Gladdy

To coincide with this week’s WordPress 5.9 release, ACF PRO v5.12-beta1 is now available with support for WordPress 5.9’s Full Site Editor and Block Themes. 🎉🥳

This is our first beta release since we took over stewardship of ACF. The release contains significant changes to ACF Blocks in order to support the structure of the new WordPress Full Site Editor. This new editor works differently to the rest of the block editor views by loading blocks inside of an iframe which is outside of the scope of the rest of the DOM. We’re keen to gather your feedback as you start to develop Block Themes using ACF.

The release features:

  • ACF Blocks now have preliminary support for the Full Site editor
  • ACF Blocks now work correctly in the Widget editor
  • ACF Blocks are now supported in the Query Loop block

To access this release, please login to your account, navigate to the “Licenses” page and select version “5.12-beta1” from the available downloads.

We’ve also introduced changes which let you use ACF Blocks inside Query Loop blocks, to display data for the currently displayed post in the loop. This means you can use ACF Blocks as a bridge between PHP templates for posts and the block editor without necessarily using any fields on the block itself.

Here’s the headline changes you need to know about:

Post ID changes inside a block

In releases prior to ACF 5.12, use of $post_id inside a block template would not be consistent. It would be null in the block editor, but return the $post_id of the container post when rendered on the frontend. In ACF 5.12, there is now a consistent use of $post_id across backend and frontend views of blocks, which is dependent on the context in which the block is used. A new $context variable is available inside the block template which provides more information about where the block is being displayed.

If used inside a Query Loop block, $post_id will be the post ID of the current post displayed inside the loop, and a new variable, $context['hostPostId'] will contain the post ID of the container post which contains the Query Loop block. This allows you to access any fields on that container post.

For all other uses of blocks, $post_id will be the post ID of the container post.

As before, by default get_field() and the_field() will return block field values. To access fields from the post, you need to use pass in the post ID, for example: get_field('field_name', get_the_ID())

Notes:

Editing a field assigned to a block used inside a Query Loop block will apply that change to every post inside the loop, as the block only exists once but is duplicated for each post in the loop.

Known Issues:

  • Blocks used inside the Query Loop block do not currently support in-block edit mode, and require the use of the sidebar editing tools to edit any fields specific for the block. Blocks used inside a Query Loop block will be forced into preview mode regardless of their defined setting.
  • Block preloading is disabled for blocks used inside a Query Loop block.
  • Some field types (including the datepicker, color picker, and WYSIWYG fields) may not yet work correctly in the site editor due to the site editor’s iframe changing the JavaScript scope.. We’ll be adding support for these fields in the near future.
  • The new $context variable may not be available in preloaded blocks.

Full Changelog (WIP)

  • New – ACF blocks now have preliminary support for the WordPress Query Loop block
  • New – ACF blocks now have preliminary support for the new Site Editor included in WordPress 5.9
  • Enhancement – Block preloading can now be disabled by using acf_update_setting( 'preload_blocks', false ); in the acf/init action hook
  • Enhancement – ACF and ACF PRO will now detect if each other are active and deactivate the other plugin on plugin activation. So activating ACF will deactivate ACF PRO and activating ACF PRO will deactivate ACF.
  • Fix – Fixed an issue where it was impossible to update an ACF block inside the widget block editor
  • Fix – Fixed an issue where ACF fields might not appear in REST API calls made via internal WordPress functions

Please download and test out the beta of ACF PRO 5.12. We’d really appreciate any feedback!

🙌 Thanks to everyone who helped make this release possible. Think you’ve found a bug? Please post in detail a new support ticket or over on our GitHub repo.

About the Author