acf/blocks/top_toolbar_fields
Description
This filter allows you to add fields to the top toolbar of a specific ACF Block, enabling direct editing from the block’s header in the editor.
When a field is added to the toolbar, it appears as a button. Clicking this button opens a popover containing the field’s input, allowing for a more streamlined and integrated editing experience.
Changelog
- Added in version 6.7.
Parameters
apply_filters( 'acf/blocks/top_toolbar_fields', $fields, $block, $content, $is_preview, $post_id, $wp_block, $context );
$fields(array) An array of fields to be displayed in the toolbar. Defaults to an empty array.$block(array) An array of block properties.$content(string) The block’s inner content.$is_preview(bool) A boolean that is true when the block is being rendered for editing preview.$post_id(int) The ID of the post being edited.$wp_block(WP_Block|null) The WP_Block instance, or null.$context(array) The block context.
Return
(array) The modified array of fields.
Example
This example demonstrates how to add an image field to the toolbar of the ACF Block:
function my_block_top_toolbar_fields($block_top_toolbar_field_names, $block) {
// If the block in question is our block.
if ( 'acf/my-acf-block' === $block['name'] ) {
// Make some ACF fields show in the primary block toolbar.
return array( 'my_background_image_field', 'my_background_color_field');
}
// If the block in question is not our block, just pass the variable as is.
return $block_top_toolbar_field_names;
}
add_filter( 'acf/blocks/top_toolbar_fields', 'my_block_top_toolbar_fields', 10, 2 );
这篇文档对你有帮助吗?
谢谢你的反馈!