IMPLEMENTED: Better solution for echo function name filter

@MattHias Great suggestion :slight_smile:

We discussed the different approaches internally, and it seems that #1 is the most flexible.

We can pass the function name to the bricks/code/echo_function_names filter, and you can perform your logic in the filter and return true or false according to your custom checks, such as regex, etc.

Something like that:

add_filter('bricks/code/echo_function_names', function( $function_name ) {
    // True if the function name starts with "get_"
    return preg_match( '/^get_/', $function_name );
});

An alternative way would be to build the regex check into our code and you could simple pass it as part of the returned array like this.

add_filter('bricks/code/echo_function_names', function( $whitelisted_items ) {
    // True if the function name starts with "get_" (the "@" flags it in Bricks as a regex 
    $whitelisted_items[] = '@^get_';
    return $whitelisted_items;
});

Let us know what you think :pray:

6 Likes