Filter
uncanny-automator
automator_wpai_common_possible_tokens_for_posttype
Filters possible tokens for post types during WP All Import processing.
add_filter( 'automator_wpai_common_possible_tokens_for_posttype', $callback, 10, 1 );
Description
This filter allows developers to modify the list of available tokens for post types when using WP All Import. By filtering `automator_wpai_common_possible_tokens_for_posttype`, you can add custom tokens or remove default ones, giving fine-grained control over data available for automations triggered by imported posts.
Usage
add_filter( 'automator_wpai_common_possible_tokens_for_posttype', 'your_function_name', 10, 1 );
Parameters
-
$args(mixed) - This parameter contains an array of token types, initialized with `'WPAI_POSTTYPE_IMPORTED'`.
Return Value
The filtered value.
Examples
/**
* Example function to hook into 'automator_wpai_common_possible_tokens_for_posttype'.
*
* This function adds a custom post type token to the list of available tokens
* when a post is imported via WP All Import, if that post type is 'book'.
*
* @param array $trigger_meta_validations The current array of validation codes.
* @param array $args The arguments passed to the filter.
* @return array The modified array of validation codes.
*/
function my_automator_wpai_custom_post_tokens( $trigger_meta_validations, $args ) {
// Check if the current trigger meta code is for a post import.
if ( isset( $args['triggers_meta']['code'] ) && 'WPAI_POSTTYPE_IMPORTED' === $args['triggers_meta']['code'] ) {
// Assuming the post type is stored in $args['post_type'] (this might vary based on the actual plugin structure).
// You would need to inspect the $args array to confirm the exact key for the post type.
if ( isset( $args['post_type'] ) && 'book' === $args['post_type'] ) {
// Add a custom token for 'book' post type imports.
$trigger_meta_validations[] = 'WPAI_BOOK_IMPORTED';
}
}
return $trigger_meta_validations;
}
add_filter( 'automator_wpai_common_possible_tokens_for_posttype', 'my_automator_wpai_custom_post_tokens', 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/wp-all-import/tokens/wpai-tokens.php:73
* @param array $args
*
* @return array|array[]|mixed
*/
public function wpai_possible_post_tokens( $tokens = array(), $args = array() ) {
$trigger_code = $args['triggers_meta']['code'];
$trigger_meta_validations = apply_filters(
'automator_wpai_common_possible_tokens_for_posttype',
array( 'WPAI_POSTTYPE_IMPORTED' ),
$args
);
if ( in_array( $trigger_code, $trigger_meta_validations, true ) ) {