Filter
uncanny-automator
automator_log_trigger_items_fields
Filters the fields displayed for trigger items in the Automator log, allowing customization before the log entry is generated.
add_filter( 'automator_log_trigger_items_fields', $callback, 10, 2 );
Description
Fires when processing trigger log items to modify the fields displayed. Developers can use this filter to add, remove, or alter the fields shown for trigger logs, providing custom data or refining existing information. The `$fields` parameter contains the log item's fields, and `$params` holds additional context.
Usage
add_filter( 'automator_log_trigger_items_fields', 'your_function_name', 10, 2 );
Parameters
-
$fields(mixed) - This parameter contains an array of fields that will be displayed for a specific trigger log item.
-
$params(mixed) - This parameter contains an array of fields to be displayed for trigger log items, which can be modified by the filter.
Return Value
The filtered value.
Examples
/**
* Filters the trigger items fields for log entries to add a custom field.
*
* This example demonstrates how to add a new key-value pair to the
* `$fields` array if a specific trigger ID is detected.
*
* @param array $fields The original fields array for the trigger log item.
* @param array $params An array containing additional parameters, such as trigger ID and trigger log ID.
*
* @return array The modified fields array.
*/
add_filter( 'automator_log_trigger_items_fields', function ( $fields, $params ) {
// Check if the current trigger ID matches a specific value.
if ( isset( $params['trigger_id'] ) && 'your_specific_trigger_id' === $params['trigger_id'] ) {
// Add a custom field to the fields array.
$fields['custom_added_field'] = 'This value was added by the filter.';
}
// Always return the (potentially modified) fields array.
return $fields;
}, 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/core/services/rest/endpoint/log-endpoint/resources/trigger-logs-resources.php:177
array(
'trigger_id' => $trigger_id,
'trigger_log_id' => $trigger_log_item['trigger_log_id'],
)
);
// The original $fields has its value separated by option type (e.g. option, options_group).
$fields = (array) apply_filters( 'automator_log_trigger_items_fields', json_decode( $fields, true ), $params );
if ( $utils::fields_has_combination_of_options_and_options_group( $fields ) ) {
$fields = array_unique( array_merge( ...$fields ), SORT_REGULAR );
}
$recorded_triggers = $this->trigger_logs_queries->recorded_triggers_query(
// @phpstan-ignore-next-line The following supplied parameter is ok.