Filter uncanny-automator-pro

uap_purge_logs_minutes_interval

Filters the interval in minutes for purging user activity logs, allowing customization of log retention.

add_filter( 'uap_purge_logs_minutes_interval', $callback, 10, 1 );

Description

Filters the interval in minutes for purging Uncanny Automator Pro activity logs. Developers can use this to customize how frequently logs are cleared, overriding the default 10-minute interval. This filter fires when the plugin schedules recurring log purging actions.


Usage

add_filter( 'uap_purge_logs_minutes_interval', 'your_function_name', 10, 1 );

Return Value

The filtered value.


Examples

<?php
/**
 * Example filter to adjust the minutes interval for purging Uncanny Automator Pro logs.
 *
 * This filter allows you to change the default 10-minute interval for purging logs
 * to a custom value. For instance, you might want to purge logs more frequently
 * on a very busy site or less frequently on a less active one.
 *
 * @param int $minutes_interval The current interval in minutes. Defaults to 10.
 * @return int The new desired interval in minutes.
 */
function my_custom_automator_log_purge_interval( $minutes_interval ) {
    // Let's say we want to purge logs every 30 minutes instead of 10.
    // We'll add a check to ensure it's a positive integer to avoid issues.
    $new_interval = 30;

    if ( is_numeric( $new_interval ) && $new_interval > 0 ) {
        return absint( $new_interval );
    }

    // If the custom interval is invalid, return the original value.
    return $minutes_interval;
}
add_filter( 'uap_purge_logs_minutes_interval', 'my_custom_automator_log_purge_interval', 10, 1 );

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:345

public static function maybe_schedule_purge_logs() {

		if ( ! automator_filter_has_var( '_wpnonce', INPUT_POST ) || ! automator_filter_has_var( 'uap_automator_purge_days', INPUT_POST ) ) {
			return;
		}

		if ( ! wp_verify_nonce( automator_filter_input( '_wpnonce', INPUT_POST ), 'uncanny_automator' ) ) {
			return;
		}

		as_unschedule_all_actions( self::$cron_schedule );

		// Add Action Scheduler event.
		$interval_unit = automator_get_option( 'uap_automator_purge_unit', 'days' );

		// Hourly.
		if ( 'hours' === $interval_unit ) {
			as_schedule_recurring_action( strtotime( '+1 hour' ), 3600, self::$cron_schedule );
			return;
		}

		// Minutes.
		if ( 'minutes' === $interval_unit ) {
			$minutes_interval = apply_filters( 'uap_purge_logs_minutes_interval', 10 );
			as_schedule_recurring_action( strtotime( '+' . $minutes_interval . ' minutes' ), 60 * $minutes_interval, self::$cron_schedule );
			return;
		}

		// The default midnight daily.
		as_schedule_cron_action( strtotime( 'midnight tonight' ), '@daily', self::$cron_schedule );
	}

Scroll to Top