Filter
uncanny-automator
automator_action_log_date_time
Filters the date and time used for logging Automator actions.
add_filter( 'automator_action_log_date_time', $callback, 10, 1 );
Description
Filters the date and time used for logging completed actions. Developers can modify this date/time, for example, to delay logging or adjust it based on specific conditions. The default value is null, meaning the current time will be used if not filtered.
Usage
add_filter( 'automator_action_log_date_time', 'your_function_name', 10, 1 );
Parameters
-
$action_data(mixed) - This parameter is used to pass a placeholder value which can be filtered to determine the date and time of the action log entry.
Return Value
The filtered value.
Examples
<?php
/**
* Adjusts the action log date and time for specific automator actions.
*
* This function can be used to modify the logged date and time of an automator action.
* For example, you might want to set a specific future date for an action that
* is scheduled to run later.
*
* @param null $null The default null value passed from the filter.
* @param array $action_data An array containing data about the automator action.
* Expected keys include 'ID', 'completed', and potentially
* custom keys if the action data is extended.
*
* @return string|null The formatted date and time string, or null to use the default.
*/
function my_automator_custom_action_log_date_time( $null, $action_data ) {
// Check if the action is a specific type that needs custom date handling.
// Replace 'your_specific_action_id' with the actual ID of the action you want to target.
if ( isset( $action_data['ID'] ) && $action_data['ID'] === 'your_specific_action_id' ) {
// Example: Schedule the action to be logged 1 hour from now.
// This is a simplified example. In a real-world scenario, you might
// fetch a date from meta, user meta, or another source within $action_data.
$new_timestamp = time() + HOUR_IN_SECONDS;
return date( 'Y-m-d H:i:s', $new_timestamp );
}
// If it's not the specific action we're looking for, return the default value.
return $null;
}
add_filter( 'automator_action_log_date_time', 'my_automator_custom_action_log_date_time', 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/lib/process/class-automator-recipe-process-complete.php:806
public function create_action( $user_id = null, $action_data = null, $recipe_id = null, $error_message = '', $recipe_log_id = null, $args = array() ) {
$action_id = (int) $action_data['ID'];
$completed = (int) $action_data['completed'];
$date_time = apply_filters( 'automator_action_log_date_time', null, $action_data );
$values = array(
'user_id' => $user_id,
'action_id' => $action_id,
'recipe_id' => $recipe_id,
'recipe_log_id' => $recipe_log_id,
'completed' => $completed,
'error_message' => $error_message,
'date_time' => $date_time,
);
$action_log_id = Automator()->db->action->add( $values );
$sentences = Automator()->get->action_sentence( $action_id );
if ( ! empty( $sentences ) ) {
foreach ( $sentences as $meta_key => $meta_value ) {
if ( ! empty( $meta_value ) ) {
Automator()->db->action->add_meta( $user_id, $action_log_id, $action_id, $meta_key, maybe_serialize( $meta_value ) );
}
}
}
return $action_log_id;
}
Internal Usage
Found in uncanny-automator-pro/src/core/classes/async-actions.php:36:
add_filter( 'automator_action_log_date_time', array( $this, 'adjust_action_log_date_time' ), 10, 2 );