Filter uncanny-automator-pro

automator_hydrate_wordpress_post_token_{$token}

Filters the hydrated WordPress post token data before it's used in automations, allowing modification of the token's value.

add_filter( 'automator_hydrate_wordpress_post_token_{$token}', $callback, 10, 1 );

Description

Fires when hydrating a WordPress post token to allow modification of the token's value. Developers can filter the token value before it's added to the recipe. This hook is crucial for customizing how specific post-related tokens are represented within Uncanny Automator.


Usage

add_filter( 'automator_hydrate_wordpress_post_token_{$token}', 'your_function_name', 10, 1 );

Parameters

$post_id (mixed)
This parameter contains the option code for the post type being hydrated.

Return Value

The filtered value.


Examples

/**
 * Example filter for automator_hydrate_wordpress_post_token_{$token}
 *
 * This filter allows developers to modify the value of a specific WordPress post token
 * before it's used in an Uncanny Automator workflow. In this example, we'll
 * conditionally append a custom string to the post title if the post is published.
 *
 * @param mixed $value The current value of the token.
 * @param int   $post_id The ID of the WordPress post.
 * @return mixed The modified token value.
 */
add_filter( 'automator_hydrate_wordpress_post_token_post_title', function( $value, $post_id ) {
	// Check if the post exists and has a title
	if ( ! empty( $value ) && $post_id ) {
		$post_status = get_post_status( $post_id );

		// Only append if the post is published
		if ( 'publish' === $post_status ) {
			$value .= ' (Published Post)';
		}
	}
	return $value;
}, 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

uncanny-automator-pro/src/integrations/wp/helpers/wp-pro-helpers.php:232

public function hydrate_post_relevant_tokens( $option_code = 'WPPOSTTYPES', $post_id = 0 ) {
		$relevant_tokens = $this->get_post_relevant_tokens( 'action', $option_code );
		$tokens          = array();
		foreach ( $relevant_tokens as $token => $config ) {
			switch ( $token ) {
				case $option_code:
					$tokens[ $token ] = get_the_title( $post_id );
					break;
				case $option_code . '_ID':
					$tokens[ $token ] = $post_id;
					break;
				case $option_code . '_URL':
					$tokens[ $token ] = get_permalink( $post_id );
					break;
				case $option_code . '_POSTNAME':
					$tokens[ $token ] = get_post_field( 'post_name', $post_id );
					break;
				case $option_code . '_THUMB_ID':
					$tokens[ $token ] = get_post_thumbnail_id( $post_id );
					break;
				case $option_code . '_THUMB_URL':
					$tokens[ $token ] = get_the_post_thumbnail_url( $post_id );
					break;
				default:
					$tokens[ $token ] = apply_filters( "automator_hydrate_wordpress_post_token_{$token}", '', $post_id );
					break;
			}
		}

		return $tokens;
	}

Scroll to Top