Filter
uncanny-automator
automator_edd_validate_common_trigger_tokens
Filters the common trigger tokens available for EDD anonymous purchases and associated arguments.
add_filter( 'automator_edd_validate_common_trigger_tokens', $callback, 10, 1 );
Description
Allows developers to filter the list of common tokens validated for Easy Digital Downloads triggers. Modify this array to control which trigger codes require specific validation, ensuring correct data handling within the Automator. This hook fires after trigger meta is retrieved but before validation occurs.
Usage
add_filter( 'automator_edd_validate_common_trigger_tokens', 'your_function_name', 10, 1 );
Parameters
-
$args(mixed) - This parameter is an array that initially contains the constant `EDD_ANON_PURCHASE`, likely representing a token related to anonymous purchases in Easy Digital Downloads.
Return Value
The filtered value.
Examples
add_filter( 'automator_edd_validate_common_trigger_tokens', 'my_automator_edd_validate_common_trigger_tokens', 10, 2 );
/**
* Example function to validate EDD common trigger tokens for AutomatorWP.
*
* This function adds specific trigger codes to the list of validations for common EDD triggers.
* For instance, it ensures that 'EDD_ANON_PURCHASE' is considered a valid common trigger.
*
* @param array $trigger_meta_validations The array of trigger codes to validate.
* @param array $args The arguments passed to the filter, including trigger meta.
* @return array The modified array of trigger codes to validate.
*/
function my_automator_edd_validate_common_trigger_tokens( $trigger_meta_validations = array(), $args = array() ) {
// Ensure the 'EDD_ANON_PURCHASE' token is always included for anonymous purchases.
// This is an example of adding a specific, known trigger code that might be
// considered "common" in certain contexts.
if ( ! in_array( 'EDD_ANON_PURCHASE', $trigger_meta_validations, true ) ) {
$trigger_meta_validations[] = 'EDD_ANON_PURCHASE';
}
// You could add more complex logic here based on $args if needed.
// For example, if the trigger code in $args['triggers_meta']['code']
// matches a specific type, you might add other related tokens.
//
// if ( isset( $args['triggers_meta']['code'] ) && 'EDD_PURCHASE' === $args['triggers_meta']['code'] ) {
// if ( ! in_array( 'EDD_PURCHASE_BY_USER_ID', $trigger_meta_validations, true ) ) {
// $trigger_meta_validations[] = 'EDD_PURCHASE_BY_USER_ID';
// }
// }
return $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/edd/tokens/edd-tokens.php:354
public function edd_payment_possible_tokens( $tokens = array(), $args = array() ) {
if ( ! automator_do_identify_tokens() ) {
return $tokens;
}
$trigger_code = $args['triggers_meta']['code'];
$trigger_meta_validations = apply_filters(
'automator_edd_validate_common_trigger_tokens',
array( 'EDD_ANON_PURCHASE' ),
$args
);
if ( in_array( $trigger_code, $trigger_meta_validations, true ) ) {