Bricks Echo Function Names
Overview
Allow specific PHP functions to be called from Bricks {echo:...} dynamic data.
Use the Static variant when you want to allowlist exact function names. Use the Regex variant when you want to allow a naming convention, such as every function that starts with mac_.
Bricks must still have code execution enabled for the relevant user role. Keep the allowlist narrow unless the site intentionally treats a function prefix as trusted.
Variants
- Static
- Regex
<?php
/**
* Bricks Echo Function Names
*
* https://academy.bricksbuilder.io/article/filter-bricks-code-echo_function_names/
*
* @return string[]
*/
add_filter( 'bricks/code/echo_function_names', function (): array {
return [
'mac_my_function_1',
'mac_my_function_2',
];
} );
<?php
/**
* Bricks Echo Function Names - Regex
*
* https://academy.bricksbuilder.io/article/filter-bricks-code-echo_function_names/
*
* @param string $function_name Function name passed by Bricks.
* @return string[]
*/
add_filter( 'bricks/code/echo_function_names', function ( string $function_name ): array {
return [
'@^mac_', // Allow all functions that start with "mac_"
];
} );