Filter
uncanny-automator
automator_wsformlite_validate_common_trigger_tokens_save
Filters arguments for saving common trigger tokens in WS Form Lite submissions, allowing customization before data persistence.
add_filter( 'automator_wsformlite_validate_common_trigger_tokens_save', $callback, 10, 1 );
Description
Filters the list of valid WS Form Lite trigger token codes before saving token data. Developers can use this hook to add or remove custom WS Form Lite trigger codes, ensuring only intended tokens are processed for automations. This hook fires during the saving of trigger data.
Usage
add_filter( 'automator_wsformlite_validate_common_trigger_tokens_save', 'your_function_name', 10, 1 );
Parameters
-
$args(mixed) - This parameter contains an array of token identifiers that represent form submission data.
Return Value
The filtered value.
Examples
add_filter( 'automator_wsformlite_validate_common_trigger_tokens_save', 'my_custom_wsformlite_trigger_tokens', 10, 2 );
/**
* Custom logic to modify the validation of WS Form Lite trigger tokens.
*
* This example demonstrates how to add or remove specific WS Form Lite
* token codes from the validation list.
*
* @param array $trigger_meta_validations An array of WS Form Lite trigger token codes to validate.
* @param array $args The arguments passed to the filter, including trigger_args and entry_args.
* @return array The modified array of trigger token codes.
*/
function my_custom_wsformlite_trigger_tokens( $trigger_meta_validations, $args ) {
// Example: Remove 'WSFORM_ANON_FROM_SUBMITTED' if it's present.
if ( ( $key = array_search( 'WSFORM_ANON_FROM_SUBMITTED', $trigger_meta_validations ) ) !== false ) {
unset( $trigger_meta_validations[ $key ] );
}
// Example: Add a hypothetical new trigger token code for future use.
// Make sure this code actually exists or is defined elsewhere in your custom logic.
$trigger_meta_validations[] = 'MY_CUSTOM_WSFORM_TOKEN';
// Re-index the array to ensure sequential keys after unsetting.
return array_values( $trigger_meta_validations );
}
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/integrations/ws-form-lite/tokens/ws-form-lite-tokens.php:35
public function save_token_data( $args, $trigger ) {
if ( ! isset( $args['trigger_args'] ) || ! isset( $args['entry_args']['code'] ) ) {
return;
}
$trigger_meta_validations = apply_filters(
'automator_wsformlite_validate_common_trigger_tokens_save',
array( 'WSFORM_FROM_SUBMITTED', 'WSFORM_ANON_FROM_SUBMITTED' ),
$args
);
if ( in_array( $args['entry_args']['code'], $trigger_meta_validations ) ) {
$ws_form_submitted = $args['trigger_args'][0];
$trigger_log_entry = $args['trigger_entry'];
if ( ! empty( $ws_form_submitted ) ) {
Automator()->db->token->save( 'form_id', $ws_form_submitted->form_id, $trigger_log_entry );
Automator()->db->token->save( 'form_entry_id', $ws_form_submitted->id, $trigger_log_entry );
}
}
}