Problem: I would like to automatically register functions for use inside conditionals, by adding those functions with code.
Solution: It turns out there is an undocumented filter wpv_filter_wpv_custom_conditional_functions that you can use to add your own custom functions to the allowed function name array. That part works pretty well right now, you can register your own functions and use them as needed in conditionals. There are a couple of minor issues:
- The functions you add with this hook will not appear in the list of function names in Toolset > Settings > Frontend Content > Functions inside conditional evaluations
- The functions you add here will not appear in the list of available custom functions in the conditional builder popup (see the screenshot here)
Those minor issues aside, it works!
Example
1. Register function
function custom_function($type, $object) { $return = 0; return $return; }
2. Add Conditional Support for function:
add_filter( 'wpv_filter_wpv_custom_conditional_functions', 'ts_custom_stuff', 10, 1 ); function ts_custom_stuff( $allowed_functions ) { if ( ! in_array( 'custom_function', $allowed_functions ) ) { $allowed_functions[] = 'custom_function'; } return $allowed_functions; }
3. Insert function in HTML condition. The syntax is tricky, so pay close attention to the quotes and parentheses as shown in the documentation link below.
[wpv-conditional if="( 'custom_function()' eq 0 )"] Custom function equals zero! [/wpv-conditional]
Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-custom-functions-in-conditions/
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 3 replies, has 2 voices.
Last updated by 5 years, 2 months ago.
Assisted by: Christian Cox.