Filter uncanny-automator

automator_thrive_ovation_validate_common_triggers_tokens_save

Filters data to validate common triggers and tokens when saving Thrive Ovation settings.

add_filter( 'automator_thrive_ovation_validate_common_triggers_tokens_save', $callback, 10, 1 );

Description

This filter allows developers to modify the list of Thrive Ovation trigger types that require additional validation before saving token data. Developers can add or remove trigger codes from the default array to customize which triggers undergo further checks.


Usage

add_filter( 'automator_thrive_ovation_validate_common_triggers_tokens_save', 'your_function_name', 10, 1 );

Parameters

$args (mixed)
This parameter contains an array of common Thrive Ovation trigger codes that are validated when saving token data.

Return Value

The filtered value.


Examples

/**
 * Example callback function for the 'automator_thrive_ovation_validate_common_triggers_tokens_save' filter.
 *
 * This example adds another trigger code to the validation list for Thrive Ovation tokens.
 *
 * @param array $trigger_codes An array of trigger codes to validate.
 * @param array $args          The arguments passed to the save_token_data function.
 *
 * @return array The modified array of trigger codes.
 */
function my_custom_thrive_ovation_token_validation( $trigger_codes, $args ) {
    // Add a custom trigger code to the list if it's not already present.
    // For demonstration purposes, let's assume 'MY_CUSTOM_TRIGGER' is a valid trigger.
    if ( ! in_array( 'MY_CUSTOM_TRIGGER', $trigger_codes, true ) ) {
        $trigger_codes[] = 'MY_CUSTOM_TRIGGER';
    }

    // You can also conditionally remove trigger codes or perform other logic based on $args
    // For instance, if you wanted to remove 'TVO_TESTIMONIAL_SUBMITTED' for a specific scenario:
    /*
    if ( isset( $args['some_other_condition'] ) && $args['some_other_condition'] === true ) {
        $trigger_codes = array_diff( $trigger_codes, array( 'TVO_TESTIMONIAL_SUBMITTED' ) );
    }
    */

    return $trigger_codes;
}

// Add the filter to WordPress.
// The third parameter '3' indicates that the callback function accepts 3 arguments:
// 1. The filtered value (in this case, $trigger_codes)
// 2. The original arguments ($args)
// 3. The trigger object (though not explicitly used in this example, it's available)
add_filter( 'automator_thrive_ovation_validate_common_triggers_tokens_save', 'my_custom_thrive_ovation_token_validation', 10, 2 );

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/thrive-ovation/tokens/thrive-ovation-tokens.php:44

public function save_token_data( $args, $trigger ) {
		if ( ! isset( $args['trigger_args'], $args['entry_args']['code'] ) ) {
			return;
		}

		$trigger_meta_validations = apply_filters(
			'automator_thrive_ovation_validate_common_triggers_tokens_save',
			array( 'TVO_TESTIMONIAL_SUBMITTED' ),
			$args
		);

		if ( in_array( $args['entry_args']['code'], $trigger_meta_validations, true ) ) {
			$testimonial_data  = $args['trigger_args'][0];
			$trigger_log_entry = $args['trigger_entry'];
			if ( ! empty( $testimonial_data ) ) {
				Automator()->db->token->save( 'testimonial_data', maybe_serialize( $testimonial_data ), $trigger_log_entry );
			}
		}
	}


Scroll to Top