Skip to main content

Data Filters

This page documents filters for customizing data providers, meta values, and expression extensions.

FilterDescription
unblock/data/providersRegister custom data providers
unblock/data/filtersRegister custom expression filters
unblock/data/functionsRegister custom expression functions
unblock/data/post_metaFilter post meta values
unblock/data/user_metaFilter user meta values
unblock/data/term_metaFilter term meta values
unblock/data/allowed_optionsWhitelist accessible WordPress options
unblock/data/allowed_meta_keysWhitelist protected meta keys
unblock/data/option_metaPre-filter for option retrieval from Site provider
unblock/data/allowed_functionsAllowed PHP functions in expressions

data/providers

Register custom data providers to expose new data sources in expressions.

ParameterTypeDescription
$providersarrayRegistered providers configuration

Each provider is an array of fields. Each field requires:

  • label — Display label for the field
  • callback — Callable that returns the field value

Optional field properties:

  • escape — Escape function (false, 'esc_url', etc.)
  • returns — Return type hint ('WP_User', 'WP_Term', 'WP_Post', 'Reference')

Example: Register Custom Provider

add_filter( 'unblock/data/providers', function ( $providers ) {

$providers['shop'] = [
'name' => [
'label' => __( 'Shop Name', 'flavor' ),
'callback' => [ My_Shop_Provider::class, 'name' ],
],
'url' => [
'label' => __( 'Shop URL', 'flavor' ),
'escape' => 'esc_url',
'callback' => [ My_Shop_Provider::class, 'url' ],
],
];

return $providers;

} );

Use in expressions: {{ shop.name }}, {{ shop.url }}

Example: WooCommerce Product Provider

add_filter( 'unblock/data/providers', function ( $providers ) {

$providers['product'] = [
'price' => [
'label' => __( 'Price', 'flavor' ),
'callback' => function ( $context, $args ) {

$product = wc_get_product( $context->get_post_id() );

return $product ? $product->get_price() : null;

},
],
'sale_price' => [
'label' => __( 'Sale Price', 'flavor' ),
'callback' => function ( $context, $args ) {

$product = wc_get_product( $context->get_post_id() );

return $product ? $product->get_sale_price() : null;

},
],
'in_stock' => [
'label' => __( 'In Stock', 'flavor' ),
'callback' => function ( $context, $args ) {

$product = wc_get_product( $context->get_post_id() );

return $product ? $product->is_in_stock() : false;

},
],
];

return $providers;

} );

Use in expressions: {{ product.price }}, {{ product.in_stock }}

data/filters

Register custom expression filters for data transformation.

ParameterTypeDescription
$filtersarrayRegistered filters configuration

Example: Register Custom Filter

add_filter( 'unblock/data/filters', function ( $filters ) {

$filters['my_filter'] = [
'callback' => 'my_filter_function',
];

return $filters;

} );

Example: Currency Filter

add_filter( 'unblock/data/filters', function ( $filters ) {

$filters['price'] = [
'callback' => function ( $value, $currency = 'USD' ) {

return number_format( (float) $value, 2 ) . ' ' . $currency;

},
];

return $filters;

} );

Use in expressions: {{ product.price|price('EUR') }}

data/functions

Register custom functions callable directly in expressions.

ParameterTypeDescription
$functionsarrayRegistered functions configuration

Example: Simple Function

add_filter( 'unblock/data/functions', function ( $functions ) {

$functions['site_logo'] = [
'callback' => fn( $args ) => get_theme_mod( 'custom_logo' ),
];

return $functions;

} );

Use in expressions: {{ site_logo() }}

Example: Function with Provider Return

Functions that return provider objects can declare a returns key so users can chain property access:

add_filter( 'unblock/data/functions', function ( $functions ) {

$functions['get_product'] = [
'callback' => fn( $args ) => get_product_reference( $args[0] ?? 0 ),
'returns' => 'product',
];

return $functions;

} );

Use in expressions: {{ get_product(42).price }}

data/post_meta

Filter post meta values when retrieved.

ParameterTypeDescription
$valuemixedMeta value
$meta_keystringMeta key name
$post_idintPost ID

Example: Type Conversion

add_filter( 'unblock/data/post_meta', function ( $value, $meta_key, $post_id ) {

if ( $meta_key === 'price' ) {
return floatval( $value );
}

return $value;

}, 10, 3 );

Example: Date Conversion

add_filter( 'unblock/data/post_meta', function ( $value, $meta_key, $post_id ) {

if ( $meta_key === 'event_date' && ! empty( $value ) ) {
return strtotime( $value );
}

return $value;

}, 10, 3 );

data/user_meta

Filter user meta values when retrieved.

ParameterTypeDescription
$valuemixedMeta value
$meta_keystringMeta key name
$user_idintUser ID

Example: Type Conversion

add_filter( 'unblock/data/user_meta', function ( $value, $meta_key, $user_id ) {

if ( $meta_key === 'points' ) {
return intval( $value );
}

return $value;

}, 10, 3 );

data/term_meta

Filter term meta values when retrieved.

ParameterTypeDescription
$valuemixedMeta value
$meta_keystringMeta key name
$term_idintTerm ID

Example: Fallback Value

add_filter( 'unblock/data/term_meta', function ( $value, $meta_key, $term_id ) {

if ( $meta_key === 'icon_url' && empty( $value ) ) {
return '/wp-content/themes/flavor/images/default-icon.svg';
}

return $value;

}, 10, 3 );

data/allowed_options

Whitelist WordPress options accessible via site.option().

ParameterTypeDescription
$allowedarrayAllowed option names

Default: ['date_format', 'time_format']

Example: Add Custom Option

add_filter( 'unblock/data/allowed_options', function ( $allowed ) {

$allowed[] = 'my_custom_option';

return $allowed;

} );

Example: Theme Settings

add_filter( 'unblock/data/allowed_options', function ( $allowed ) {

$allowed[] = 'theme_mods_flavor';
$allowed[] = 'flavor_settings';
$allowed[] = 'social_links';

return $allowed;

} );

Use in expressions: {{ site.option('social_links').twitter }}

data/allowed_meta_keys

Whitelist metadata keys that bypass protection checks. By default, private meta keys (starting with _) are blocked for security.

ParameterTypeDescription
$allowedarrayAllowed meta keys
$meta_typestringMeta type: 'post', 'user', or 'term'

Default: [] (empty — all private meta keys blocked)

Example: Allow Private Field

add_filter( 'unblock/data/allowed_meta_keys', function ( $allowed, $meta_type ) {

if ( $meta_type === 'post' ) {
$allowed[] = '_my_private_field';
}

return $allowed;

}, 10, 2 );

Example: Allow ACF Fields

add_filter( 'unblock/data/allowed_meta_keys', function ( $allowed, $meta_type ) {

if ( $meta_type === 'post' ) {

$allowed[] = '_edit_lock';
$allowed[] = '_edit_last';

}

return $allowed;

}, 10, 2 );

data/option_meta

Pre-filter for option retrieval from the Site provider. Return a non-null value to override get_option().

apply_filters( 'unblock/data/option_meta', null, string $key, array $options );
ParameterTypeDescription
$valuemixedReturn non-null to override. Default: null
$keystringOption key being retrieved
$optionsarrayAdditional options context

Example: ACF Options Page

add_filter( 'unblock/data/option_meta', function ( $value, $key, $options ) {

if ( function_exists( 'get_field' ) ) {
return get_field( $key, 'option' );
}

return null;

}, 10, 3 );

data/allowed_functions

Filter the list of allowed PHP functions in expressions.

apply_filters( 'unblock/data/allowed_functions', array $functions );
ParameterTypeDescription
$functionsarrayArray of allowed function names. Default: []

Example: Allow Date Functions

add_filter( 'unblock/data/allowed_functions', function ( $functions ) {

$functions[] = 'date';
$functions[] = 'strtotime';

return $functions;

} );
Common mistake

The unblock/data/post_meta filter receives null as the initial value — not the actual meta value. Return null to let WordPress handle the lookup. Returning any other value skips get_metadata() entirely.

Next steps