Filter
uncanny-automator
automator_action_tokens_meta_token_value
Filters the combined meta values for a token when an action token is being processed.
add_filter( 'automator_action_tokens_meta_token_value', $callback, 10, 3 );
Description
Fires after action meta values are combined and before they are used to generate tokens. Developers can filter the combined meta values to modify or add to them, influencing the available tokens for recipes. This filter is crucial for dynamically altering token data based on specific action contexts.
Usage
add_filter( 'automator_action_tokens_meta_token_value', 'your_function_name', 10, 3 );
Parameters
-
$combined_meta_valued(mixed) - This parameter contains the combined meta values retrieved from the action log, intended to be filtered and modified.
-
$action_id(mixed) - This parameter holds the combined values of the action's metadata, which are then processed to extract token data.
-
$process_args(mixed) - This parameter provides the ID of the specific action within the WordPress Automator plugin that is being processed.
Return Value
The filtered value.
Examples
/**
* Filters the meta token value to format a date before it's used as a token.
*
* This function takes the combined meta value, which might be a date string,
* and formats it into a more human-readable format if it's a valid date.
*
* @param mixed $combined_meta_valued The raw combined meta value.
* @param mixed $action_id The ID of the action.
* @param mixed $process_args Arguments related to the current process.
*
* @return mixed The potentially formatted meta value.
*/
add_filter( 'automator_action_tokens_meta_token_value', function( $combined_meta_valued, $action_id, $process_args ) {
// Check if the combined_meta_valued looks like a date string (e.g., Unix timestamp or YYYY-MM-DD format)
// and attempt to format it. This is a simplified check; a more robust solution might involve regex or date parsing libraries.
if ( is_numeric( $combined_meta_valued ) && (int)$combined_meta_valued > 0 ) {
// Assume it's a Unix timestamp
$formatted_date = date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $combined_meta_valued );
return $formatted_date;
} elseif ( is_string( $combined_meta_valued ) && strtotime( $combined_meta_valued ) !== false ) {
// Assume it's a string that can be parsed as a date
$timestamp = strtotime( $combined_meta_valued );
$formatted_date = date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $timestamp );
return $formatted_date;
}
// If it's not a date, return the original value.
return $combined_meta_valued;
}, 10, 3 );
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/core/services/recipe/action/token/parser.php:170
private function get_meta_value( $action_log_id = 0, $action_meta_key = '', $args = array(), $process_args = array(), $action_id = null ) {
$meta_values = Automator()->db->action->get_multiple_meta( $action_log_id, $this->meta_key );
// Combine the tokens.
$combined_meta_valued = self::merge_meta_values( $meta_values );
$action_meta_token = $this->stringify( apply_filters( 'automator_action_tokens_meta_token_value', $combined_meta_valued, $action_id, $process_args ) );
$tokens = (array) json_decode( $action_meta_token, true );
$token_value = isset( $tokens[ $action_meta_key ] ) ? $tokens[ $action_meta_key ] : '';
if ( ! empty( $args ) && isset( $args['action_data']['should_apply_extra_formatting'] ) ) {
if ( true === $args['action_data']['should_apply_extra_formatting'] ) {
// Standardize newline characters to "n".
$token_value = str_replace( array( "rn", "r" ), "n", $token_value );
// Remove more than two contiguous line breaks.
$token_value = preg_replace( "/nn+/", "nn", $token_value );
// Split up the contents into an array of strings, separated by double line breaks.
$paragraphs = preg_split( '/ns*n/', $token_value, - 1, PREG_SPLIT_NO_EMPTY );
// Only apply automatic formatting on the value if it's a paragraph.
if ( count( $paragraphs ) > 1 ) {
$token_value = apply_filters(
'automator_action_tokens_apply_auto_formatting',
wpautop( $token_value ),
$token_value,
$action_meta_key,
$action_log_id,
$args,
$this
);
}
}
}
return $token_value;
}
Internal Usage
Found in uncanny-automator-pro/src/core/loops/process-hooks-callbacks.php:59:
add_filter( 'automator_action_tokens_meta_token_value', array( $this, 'parse_action_tokens_meta' ), 10, 3 );