Filter
uncanny-automator-pro
automator_pro_auto_purge_logs_days
Filters the number of days logs are kept before being automatically purged.
add_filter( 'automator_pro_auto_purge_logs_days', $callback, 10, 1 );
Description
Filters the number of days to retain activity logs before purging. Developers can modify this value to customize the automatic log cleanup period. Defaults to the value set in the plugin's settings or an empty string if not set.
Usage
add_filter( 'automator_pro_auto_purge_logs_days', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
/**
* Filter the number of days to keep logs.
*
* This example modifies the default log retention period to 60 days,
* ensuring older logs are purged.
*
* @param int|string $purge_days The current value for purging logs in days.
* @return int The modified number of days to keep logs.
*/
add_filter( 'automator_pro_auto_purge_logs_days', function( $purge_days ) {
// Default to 60 days if the option is not set or is empty.
if ( empty( $purge_days ) || ! is_numeric( $purge_days ) ) {
return 60;
}
// You could add more complex logic here, for example:
// if ( current_user_can( 'manage_options' ) && $purge_days > 90 ) {
// // For administrators, allow keeping logs for more than 90 days.
// return $purge_days;
// }
return intval( $purge_days ); // Ensure we always return an integer.
}, 10, 1 ); // Priority 10, accepts 1 argument.
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/core/extensions/activity-log-settings.php:135
public function delete_old_logs() {
$purge_value = apply_filters(
'automator_pro_auto_purge_logs_days',
automator_get_option( 'uap_automator_purge_days', '' )
);
$unit = automator_get_option( 'uap_automator_purge_unit', 'days' );
if ( false === apply_filters( 'automator_pro_auto_purge_logs_force_delete', false, $purge_value ) ) {
if ( empty( $purge_value ) || intval( $purge_value ) < 1 ) {
return;
}
}
$this->delete_records( $purge_value, $unit );
}