Filter uncanny-automator

automator_easy_affiliate_validate_trigger_meta_pieces

Filters meta pieces used to validate Easy Affiliate trigger conditions before execution.

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

Description

Filters the list of accepted trigger meta keys for Easy Affiliate integrations. Developers can use this hook to add or remove specific meta keys that the Easy Affiliate integration should validate for triggers, controlling which data points are considered valid.


Usage

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

Parameters

$args (mixed)
This parameter contains an array of codes representing possible Easy Affiliate trigger events.

Return Value

The filtered value.


Examples

<?php

/**
 * Example of using the 'automator_easy_affiliate_validate_trigger_meta_pieces' filter.
 *
 * This example demonstrates how to add a custom validation code to the list
 * of accepted meta pieces for Easy Affiliate triggers.
 *
 * @param array $meta_pieces An array of meta pieces to validate.
 * @param mixed $args        The arguments passed to the filter.
 *
 * @return array The modified array of meta pieces.
 */
function my_custom_easy_affiliate_meta_validation( $meta_pieces, $args ) {
    // Ensure we have the necessary arguments before proceeding.
    if ( ! is_array( $args ) || ! isset( $args['entry_args']['code'] ) ) {
        return $meta_pieces;
    }

    // Add a custom meta piece code to the list.
    // For example, if you have a custom trigger for 'NEW_REFERRAL_COMMISSION_PAID'.
    $custom_meta_piece = 'NEW_REFERRAL_COMMISSION_PAID';

    // Add the custom meta piece if it's not already present.
    if ( ! in_array( $custom_meta_piece, $meta_pieces ) ) {
        $meta_pieces[] = $custom_meta_piece;
    }

    // You could also potentially remove existing ones based on $args if needed.
    // For instance, if a certain type of sale shouldn't trigger a specific meta piece.
    // if ( $args['entry_args']['code'] === 'SALE_RECORDED_CODE' && /* some condition */ ) {
    //     $meta_pieces = array_diff( $meta_pieces, array( 'SALE_RECORDED_CODE' ) );
    // }

    return $meta_pieces;
}
add_filter( 'automator_easy_affiliate_validate_trigger_meta_pieces', 'my_custom_easy_affiliate_meta_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/easy-affiliate/tokens/esaf-tokens.php:58
src/integrations/easy-affiliate/tokens/esaf-tokens.php:85
src/integrations/easy-affiliate/tokens/esaf-tokens.php:197
src/integrations/easy-affiliate/tokens/esaf-tokens.php:286

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

		$trigger_meta_validations = apply_filters(
			'automator_easy_affiliate_validate_trigger_meta_pieces',
			array( 'AFFILIATE_ADDED_CODE', 'SALE_RECORDED_CODE' ),
			$args
		);

		if ( in_array( $args['entry_args']['code'], $trigger_meta_validations ) ) {
			$event             = array_shift( $args['trigger_args'] );
			$data              = ModelFactory::fetch( $event->evt_id_type, $event->evt_id );
			$trigger_log_entry = $args['trigger_entry'];
			if ( ! empty( $event ) ) {
				Automator()->db->token->save( 'event_data', maybe_serialize( $data ), $trigger_log_entry );
			}
		}
	}

Scroll to Top