Filter uncanny-automator

automator_thrive_ovation_validate_common_triggers_tokens_parse

Filters testimonial submission triggers and tokens before they are parsed, allowing customization of available options.

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

Description

This filter allows developers to validate and modify the accepted trigger token types for Thrive Ovation integrations within the Automator plugin. It's applied before token parsing, enabling custom validation logic for specific trigger pieces and offering a way to dynamically adjust the available tokens.


Usage

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

Parameters

$pieces (mixed)
This parameter contains an array of the common Thrive Ovation trigger slugs that are expected to be validated.

Return Value

The filtered value.


Examples

// Example: Add custom validation for Thrive Ovation tokens.
// This function will check if a specific trigger is present and ensure its required pieces are valid.
add_filter(
	'automator_thrive_ovation_validate_common_triggers_tokens_parse',
	'my_custom_tvo_token_validation',
	10,
	2 // Expecting 2 arguments: the initial array and the pieces array.
);

function my_custom_tvo_token_validation( $default_validations, $passed_args ) {

	// Extract data passed to the filter.
	$pieces       = $passed_args['pieces'];
	$trigger_data = $passed_args['trigger_data'];

	// Check if the trigger is Thrive Ovation's 'TESTIMONIAL_SUBMITTED'.
	if ( isset( $trigger_data['type'] ) && $trigger_data['type'] === 'TVO_TESTIMONIAL_SUBMITTED' ) {

		// Ensure that the testimonial ID and user ID are present in the pieces.
		// These are crucial pieces of data for this specific trigger.
		if ( ! isset( $pieces[1] ) || empty( $pieces[1] ) || ! isset( $pieces[2] ) || empty( $pieces[2] ) ) {
			// If essential data is missing, we might want to return an empty array
			// or throw an error, depending on desired behavior.
			// For this example, let's indicate an invalid state by returning an empty array.
			return array();
		}

		// You could add more complex validation here, e.g., checking if the testimonial ID exists.

		// If validation passes, return the original (or modified) array of validations.
		// In this case, we're just ensuring the default validation (TESTIMONIAL_SUBMITTED) is allowed if conditions are met.
		return $default_validations;
	}

	// If it's not the trigger we're interested in, return the default validations as is.
	return $default_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/thrive-ovation/tokens/thrive-ovation-tokens.php:155

public function parse_thrive_ovation_tokens( $value, $pieces, $recipe_id, $trigger_data, $user_id, $replace_args ) {

		if ( ! is_array( $pieces ) || ! isset( $pieces[1], $pieces[2] ) ) {
			return $value;
		}

		$trigger_meta_validations = apply_filters(
			'automator_thrive_ovation_validate_common_triggers_tokens_parse',
			array( 'TVO_TESTIMONIAL_SUBMITTED' ),
			array(
				'pieces'       => $pieces,
				'recipe_id'    => $recipe_id,
				'trigger_data' => $trigger_data,
				'user_id'      => $user_id,
				'replace_args' => $replace_args,
			)
		);

		if ( ! array_intersect( $trigger_meta_validations, $pieces ) ) {
			return $value;
		}

		$testimonial_data = maybe_unserialize( Automator()->db->token->get( 'testimonial_data', $replace_args ) );

		switch ( $pieces[2] ) {
			case 'TESTIMONIAL_ID':
				$value = $testimonial_data['testimonial_id'];
				break;
			case 'TESTIMONIAL_TITLE':
				$value = $testimonial_data['testimonial_title'];
				break;
			case 'TESTIMONIAL_CONTENT':
				$value = $testimonial_data['testimonial_content'];
				break;
			case 'TESTIMONIAL_DATE':
				$value = get_the_date( '', $testimonial_data['testimonial_id'] );
				break;
			case 'TESTIMONIAL_AUTHOR':
				$value = $testimonial_data['testimonial_author'];
				break;
			case 'TESTIMONIAL_AUTHOR_EMAIL':
				$value = $testimonial_data['testimonial_author_email'];
				break;
			case 'TESTIMONIAL_AUTHOR_ROLE':
				$value = $testimonial_data['testimonial_author_role'];
				break;
			case 'TESTIMONIAL_AUTHOR_WEBSITE':
				$value = $testimonial_data['testimonial_author_website'];
				break;
			case 'TESTIMONIAL_STATUS':
				$value = tvo_get_testimonial_status_text( get_post_meta( $testimonial_data['testimonial_id'], TVO_STATUS_META_KEY, true ) );
				break;
		}

		return $value;
	}

Scroll to Top