Description
The wsf_config_parse_variables filter hook can be used to add custom variables to WS Form.
For example, you could create a variable called:
#custom_company_name
And it could output:
Acme Services, LLC
These variables can be used client-side (e.g in field settings) or in Actions (e.g. in the Send Email message setting).
Important
We recommend using the following formats in your filter hook function to avoid clashing with other existing WS Form variables:
- Group ID:
custom
- Group label:
Custom
- Variable name:
custom_<your variable name>
(i.e. prefix withcustom_
)
Usage
add_filter( 'wsf_config_parse_variables', 'my_hook_function', 10, 1 );
Parameters
$variables
ArrayAn array containing all of the registered variables in WS Form.
Example
add_filter('wsf_config_parse_variables', 'my_hook_function'); function my_hook_function($variables) { // Variable group ID $variables[ 'custom' ] = array( // Variable group label 'label' => __( 'Custom' ), // Array of variables in this custom group 'variables' => array( // Variable name (e.g. #custom_company_name) 'custom_company_name' => array( // Variable label 'label' => __( 'My Company Name' ), // Variable description 'description' => __( 'Returns my company name' ), // The output if the variable is used // Do not include private / sensitive data as this will be public 'value' => _( 'ACME Services, LLC' ), // Leave this as is 'usage' => array( 'client', 'action' ) ) ) ); return $variables; }
Source File
This hook can be found in:<plugin root>/includes/class-ws-form-config.php