afb/should_render_block

Description

This filter hook allows developers to modify whether a block should be rendered based on ACF field visibility rules. This hook is triggered during the block rendering process when the block has ACF visibility settings enabled.

Parameters

apply_filters( 'afb/should_render_block', $should_render, $rules, $block );
$should_render

(bool)

Whether the block should be rendered based on evaluated visibility rules

$rules

(array)

Array of visibility rule groups and their evaluation results

$block

(array)

The complete block data including attributes and content

Example

/**
 * Always render blocks with visibility rules
 */
add_filter( 'afb/should_render_block', function( $should_render, $rules, $block ) {
    // Force render regardless of visibility rules
    return true;
}, 10, 3 );

/**
 * Add custom visibility logic based on user role
 */
add_filter( 'afb/should_render_block', function( $should_render, $rules, $block ) {
    // Hide blocks for non-admin users even if rules pass
    if ( ! current_user_can( 'manage_options' ) ) {
        return false;
    }
    return $should_render;
}, 10, 3 );Code language: PHP (php)