Filter uncanny-automator

automator_display_log_size_notification_threshold_days

Filters the number of days before a log size notification threshold is met.

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

Description

Filters the number of days used to determine when to display a log size notification. This allows developers to customize the threshold for when the system warns users about large log databases, potentially by increasing or decreasing the default 30-day period.


Usage

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

Return Value

The filtered value.


Examples

<?php
/**
 * Adjust the threshold for displaying log size notifications in days.
 *
 * This filter allows developers to customize how many days must pass
 * since the last dismissal of a log size notification before it reappears.
 * The default is 30 days.
 *
 * @param int $threshold_days The number of days to wait before showing the notification again. Default is 30.
 * @return int The adjusted number of days.
 */
add_filter( 'automator_display_log_size_notification_threshold_days', 'my_custom_log_notification_threshold', 10, 1 );

function my_custom_log_notification_threshold( $threshold_days ) {
	// Example: Increase the threshold to 60 days if the user has dismissed the notification less than 60 days ago.
	// In a real-world scenario, you might fetch this from user meta or a custom plugin setting.

	// For this example, let's say we want to display the notification every 45 days,
	// regardless of when it was last dismissed, if the database size is large.
	// This is a simplified example; a more robust solution would consider the `time()` calculation
	// shown in the source context.

	// Let's set a fixed custom threshold of 45 days for demonstration.
	$custom_threshold = 45;

	// If the default threshold is 30, and we want to always show it after 45 days, we return 45.
	// In a more complex scenario, you might check other conditions before returning a modified value.
	// For instance, if you only wanted to extend it for certain user roles:
	/*
	if ( current_user_can( 'administrator' ) ) {
		return 60; // Administrators see it after 60 days
	} else {
		return 30; // Other users see it after 30 days
	}
	*/

	// For this specific example, we are just setting a new default threshold.
	return $custom_threshold;
}

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/admin/class-prune-logs.php:153

public function display_log_size_notification() {

		// Only display on areas where credits are also displayed.
		if ( ! Automator_Review::can_display_credits_notif() ) {
			return;
		}

		$table_size = automator_get_option( 'automator_db_size', 0 );

		if ( 0 === (int) $table_size ) {
			$table_size = $this->calculate_and_save_table_size();
		}

		$threshold_size = apply_filters( 'automator_display_log_size_notification_threshold_size_in_mb', 1024 );
		$threshold_days = apply_filters( 'automator_display_log_size_notification_threshold_days', 30 );

		$min_db_size = $table_size >= $threshold_size;

		$days_last_dismissed = intval( automator_get_option( 'automator_dismiss_log_last_dismissed', 0 ) );

		// Calculate the difference in seconds
		$diff_in_seconds = time() - $days_last_dismissed;

		// Convert seconds to days
		$days_difference = ceil( $diff_in_seconds / ( 60 * 60 * 24 ) );

		if ( $min_db_size && $days_difference >= $threshold_days ) {
			// Load assets
			Automator_Review::load_banner_assets();

			include_once Utilities::automator_get_view( 'table-size-exceeds.php' );
		}
	}


Scroll to Top