Filter
uncanny-automator
automator_edd_validate_trigger_code_pieces
Filters the EDD trigger code pieces array before validating them, allowing modification.
add_filter( 'automator_edd_validate_trigger_code_pieces', $callback, 10, 1 );
Description
This filter allows developers to modify the list of trigger codes that require specific validation for Easy Digital Downloads triggers. Developers can add or remove trigger codes from the default array to customize validation logic, particularly for anonymous purchase related triggers.
Usage
add_filter( 'automator_edd_validate_trigger_code_pieces', 'your_function_name', 10, 1 );
Parameters
-
$args(mixed) - This parameter is an array of trigger codes that are considered valid for processing by the `automator_edd_validate_trigger_code_pieces` filter.
Return Value
The filtered value.
Examples
/**
* Adds a custom trigger code to the automator_edd_validate_trigger_code_pieces filter.
* This allows a custom EDD trigger to be recognized and processed by the automation plugin.
*
* @param array $trigger_meta_validations The array of trigger codes that should be validated.
* @param array $args The arguments passed to the filter.
*
* @return array The modified array of trigger codes, including the custom one.
*/
function my_custom_edd_trigger_validation( $trigger_meta_validations, $args ) {
// Add a custom trigger code for a hypothetical "Gift Card Redeemed" event.
$trigger_meta_validations[] = 'EDD_GIFT_CARD_REDEEMED';
// You could also conditionally add triggers based on the $args if needed.
// For example, if a specific payment method is being used.
// if ( isset( $args['entry_args']['payment_method'] ) && 'stripe' === $args['entry_args']['payment_method'] ) {
// $trigger_meta_validations[] = 'EDD_STRIPE_PAYMENT_SUCCESS';
// }
return $trigger_meta_validations;
}
add_filter( 'automator_edd_validate_trigger_code_pieces', 'my_custom_edd_trigger_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/edd/tokens/edd-tokens.php:49
public function save_token_data( $args, $trigger ) {
if ( ! isset( $args['trigger_args'] ) || ! isset( $args['entry_args']['code'] ) ) {
return;
}
$trigger_meta_validations = apply_filters(
'automator_edd_validate_trigger_code_pieces',
array( 'EDD_ANON_PURCHASE' ),
$args
);
if ( in_array( $args['entry_args']['code'], $trigger_meta_validations, true ) ) {
$payment_id = $args['trigger_args'][0];
$trigger_log_entry = $args['trigger_entry'];
if ( ! empty( $payment_id ) ) {
Automator()->db->token->save( 'payment_id', $payment_id, $trigger_log_entry );
}
}
}