Filter
uncanny-automator
automator_advanced_ads_validate_trigger_meta_pieces_common
Filters Advanced Ads trigger meta pieces for validation before saving.
add_filter( 'automator_advanced_ads_validate_trigger_meta_pieces_common', $callback, 10, 1 );
Description
This filter hook allows developers to modify the validation rules for Advanced Ads trigger meta pieces. It provides an array of default validation codes and the arguments passed to the function, enabling customization of how trigger meta data is processed and validated within the Advanced Ads integration.
Usage
add_filter( 'automator_advanced_ads_validate_trigger_meta_pieces_common', 'your_function_name', 10, 1 );
Parameters
-
$args(mixed) - This parameter contains an array of common validation codes for Advanced Ads trigger meta pieces.
Return Value
The filtered value.
Examples
// Example of how to use the 'automator_advanced_ads_validate_trigger_meta_pieces_common' filter.
// This example adds a new validation code to check if the trigger code is 'AD_VISIBILITY_CHANGED'.
// The filter allows developers to extend the list of trigger meta pieces that are considered common for validation.
add_filter(
'automator_advanced_ads_validate_trigger_meta_pieces_common',
function( $trigger_meta_validations, $args ) {
// You can conditionally add new validation codes based on the $args if needed.
// For this example, we're simply adding a new code.
$trigger_meta_validations[] = 'AD_VISIBILITY_CHANGED';
return $trigger_meta_validations;
},
10, // Priority
2 // Accepted arguments: $trigger_meta_validations, $args
);
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/advanced-ads/tokens/advanced-ads-tokens.php:59
src/integrations/advanced-ads/tokens/advanced-ads-tokens.php:142
public function advads_possible_tokens( $tokens = array(), $args = array() ) {
$trigger_code = $args['triggers_meta']['code'];
$trigger_meta_validations = apply_filters(
'automator_advanced_ads_validate_trigger_meta_pieces_common',
array( 'AD_STATUS_SET_CODE' ),
$args
);
if ( in_array( $trigger_code, $trigger_meta_validations, true ) ) {
$fields = array(
array(
'tokenId' => 'AD_ID',
'tokenName' => esc_html__( 'Ad ID', 'uncanny-automator' ),
'tokenType' => 'int',
'tokenIdentifier' => $trigger_code,
),
array(
'tokenId' => 'AD_TITLE',
'tokenName' => esc_html__( 'Ad title', 'uncanny-automator' ),
'tokenType' => 'text',
'tokenIdentifier' => $trigger_code,
),
array(
'tokenId' => 'AD_STATUS',
'tokenName' => esc_html__( 'Ad status', 'uncanny-automator' ),
'tokenType' => 'text',
'tokenIdentifier' => $trigger_code,
),
array(
'tokenId' => 'AD_GROUP',
'tokenName' => esc_html__( 'Ad group', 'uncanny-automator' ),
'tokenType' => 'text',
'tokenIdentifier' => $trigger_code,
),
array(
'tokenId' => 'AD_EXPIRY_DATE',
'tokenName' => esc_html__( 'Ad expiry date', 'uncanny-automator' ),
'tokenType' => 'text',
'tokenIdentifier' => $trigger_code,
),
array(
'tokenId' => 'AD_TYPE',
'tokenName' => esc_html__( 'Ad type', 'uncanny-automator' ),
'tokenType' => 'text',
'tokenIdentifier' => $trigger_code,
),
array(
'tokenId' => 'AD_DETAILS',
'tokenName' => esc_html__( 'Ad details', 'uncanny-automator' ),
'tokenType' => 'text',
'tokenIdentifier' => $trigger_code,
),
array(
'tokenId' => 'AD_AUTHOR',
'tokenName' => esc_html__( 'Ad author', 'uncanny-automator' ),
'tokenType' => 'text',
'tokenIdentifier' => $trigger_code,
),
);
$tokens = array_merge( $tokens, $fields );
}
return $tokens;
}