Hooks & Filters

All BF Blocks hooks are prefixed bf_blocks/. Use standard WordPress add_action() and add_filter() calls to hook in.

Actionbf_blocks/before_render

Fires before a block is rendered on the front end. Use to enqueue scripts/styles conditionally.

Parameters: string $block_slug, array $fields, array $block

Actionbf_blocks/after_render

Fires after a block renders. Output has already been sent — use for side effects like logging.

Parameters: string $block_slug, string $output

Filterbf_blocks/field_value

Modify a field's value before it is passed to the PHP template.

Parameters: mixed $value, string $field_key, string $block_slug

Filterbf_blocks/register_field_type

Add a custom field type class to the registry. Key = type slug, value = class name.

Parameters: array $types

Actionbf_blocks/block_saved

Fires when a block definition is created or updated.

Parameters: int $block_id, array $block_data

Actionbf_blocks/block_deleted

Fires after a block is deleted.

Parameters: int $block_id

Filterbf_blocks/template_path

Override the PHP template path for a specific block.

Parameters: string $path, string $block_slug

Filterbf_blocks/allowed_blocks

Filter the allowed block types for an Inner Blocks field.

Parameters: array $blocks, string $inner_blocks_field_key

Code Examples

Conditionally enqueue a stylesheet

add_action(
  'bf_blocks/before_render',
  function( string $slug, array $fields, array $block ): void {
    if ( $slug === 'bf-blocks/testimonial' ) {
      wp_enqueue_style(
        'testimonial-block',
        get_template_directory_uri() . '/css/testimonial.css'
      );
    }
  },
  10,
  3
);

Modify a field value before render

add_filter(
  'bf_blocks/field_value',
  function( mixed $value, string $key, string $slug ): mixed {
    if ( $slug === 'bf-blocks/testimonial' && $key === 'author_name' ) {
      return strtoupper( $value );
    }
    return $value;
  },
  10,
  3
);