Data Filters
This page documents filters for customizing data providers, meta values, and expression extensions.
| Filter | Description |
|---|---|
unblock/data/providers | Register custom data providers |
unblock/data/filters | Register custom expression filters |
unblock/data/functions | Register custom expression functions |
unblock/data/post_meta | Filter post meta values |
unblock/data/user_meta | Filter user meta values |
unblock/data/term_meta | Filter term meta values |
unblock/data/allowed_options | Whitelist accessible WordPress options |
unblock/data/allowed_meta_keys | Whitelist protected meta keys |
unblock/data/option_meta | Pre-filter for option retrieval from Site provider |
unblock/data/allowed_functions | Allowed PHP functions in expressions |
data/providers
Register custom data providers to expose new data sources in expressions.
| Parameter | Type | Description |
|---|---|---|
$providers | array | Registered providers configuration |
Each provider is an array of fields. Each field requires:
label— Display label for the fieldcallback— 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.
| Parameter | Type | Description |
|---|---|---|
$filters | array | Registered 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.
| Parameter | Type | Description |
|---|---|---|
$functions | array | Registered 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.
| Parameter | Type | Description |
|---|---|---|
$value | mixed | Meta value |
$meta_key | string | Meta key name |
$post_id | int | Post 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.
| Parameter | Type | Description |
|---|---|---|
$value | mixed | Meta value |
$meta_key | string | Meta key name |
$user_id | int | User 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.
| Parameter | Type | Description |
|---|---|---|
$value | mixed | Meta value |
$meta_key | string | Meta key name |
$term_id | int | Term 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().
| Parameter | Type | Description |
|---|---|---|
$allowed | array | Allowed 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.
| Parameter | Type | Description |
|---|---|---|
$allowed | array | Allowed meta keys |
$meta_type | string | Meta 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 );
| Parameter | Type | Description |
|---|---|---|
$value | mixed | Return non-null to override. Default: null |
$key | string | Option key being retrieved |
$options | array | Additional 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 );
| Parameter | Type | Description |
|---|---|---|
$functions | array | Array of allowed function names. Default: [] |
Example: Allow Date Functions
add_filter( 'unblock/data/allowed_functions', function ( $functions ) {
$functions[] = 'date';
$functions[] = 'strtotime';
return $functions;
} );
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
- Query filters — modify loop query arguments
- Security filters — customize HTML and SVG sanitization
- Actions — plugin lifecycle and form hooks