Get Bricks

Filter: bricks/code/echo_function_names

Starting at Bricks 1.9.7, you must explicitly allow any function names you want to call via Bricks’ dynamic data echo tag using the new bricks/code/echo_function_names filter. You can add this to your Bricks child theme or the code snippet plugin of your choice.

add_filter( 'bricks/code/echo_function_names', function() {
  return [
    'my_custom_function',
    'another_custom_function',
  ];
} );

You can get a list of all functions on your site called through the echo tag as part of the “Code review” results. Here’s how:

  1. Go to Bricks > Settings > Custom code
  2. Click the “Start: Code review” button
  3. Once finished, select “Echo tags” from the dropdown.
  4. Copy the code snippet under “Echo: Function names” and paste it into the functions.php file of your Bricks child name. Make sure to remove any unknown or unwanted function names from the array.

Using patterns (regex) to simplify echo function calls

Bricks 1.9.8 offers greater flexibility when it comes to echo function calls.

While you can still return an array with the exact function names, you can also return an array that contains specific regex checks. We identify those regex calls by the @ prefix.

If your function name matches any of those regex checks, it can be called through the echo tag.

Example: Allow calling any functions that start with brx_:

add_filter( 'bricks/code/echo_function_names', function() {
  return [
    '@^brx_', // Allow all functions that start with "brx_"
  ];
} );

Check function names against your own custom logic

Instead of returning an array, you can also perform any custom check against the function name itself or any other logic you want to run. Returning a boolean (true or false)

Example: Run any function when development mode is enabled

add_filter( 'bricks/code/echo_function_names', function() {
  return defined( 'WP_DEVELOPMENT_MODE' ) ? WP_DEVELOPMENT_MODE : false;
} );

The WP_DEVELOPMENT_MODE PHP constant has been available in WordPress core since version 6.3. We use it just as an example. You can use any custom PHP constant of your choice by defining it in your child theme’s functions.php file.

Example: Run function if the current user can edit posts

add_filter( 'bricks/code/echo_function_names', function() {
  return current_user_can( 'edit_posts' );
} );