Hi,
Sure, that is a good idea, I have added it to our ToDo and we will add it in an update soon.
Thread Starter
NF
(@nanasflowers)
We were unable to wait any longer for this to be implemented due to insane database bloat, so created this snippet (goes in functions.php).
It runs daily on action scheduler (could be changed to a WordPress cron for wider compatibility, however action scheduler is better due to logging and retries).
The deletion period is configurable (last number at the bottom, currently set to 30).
Feel free to incorporate this into your code and/or tweak as you see fit.
// Schedule the cleanup on activation
function schedule_login_fails_cleanup_as() {
if ( ! as_next_scheduled_action( 'cleanup_login_fails_action' ) ) {
// Schedule daily
as_schedule_recurring_action( time(), DAY_IN_SECONDS, 'cleanup_login_fails_action' );
}
}
add_action( 'init', 'schedule_login_fails_cleanup_as' );
// The function that actually runs the cleanup
add_action( 'cleanup_login_fails_action', 'cleanup_login_fails_function_as' );
function cleanup_login_fails_function_as() {
global $wpdb;
$table = $wpdb->prefix . 'wpc_login_fails';
$wpdb->query(
$wpdb->prepare(
"DELETE FROM $table WHERE login_attempt_date < NOW() - INTERVAL %d DAY",
30
)
);
}
-
This reply was modified 9 months, 2 weeks ago by
NF.
Thread Starter
NF
(@nanasflowers)
More efficient version with tweaks and cleaned up:
// Schedule the cleanup on activation
function schedule_login_fails_cleanup_as() {
if ( ! as_next_scheduled_action( 'cleanup_login_fails_action' ) ) {
as_schedule_recurring_action( time(), DAY_IN_SECONDS, 'cleanup_login_fails_action' );
}
}
add_action( 'wp_loaded', 'schedule_login_fails_cleanup_as' );
// Cleanup function
add_action( 'cleanup_login_fails_action', 'cleanup_login_fails_function_as' );
function cleanup_login_fails_function_as() {
global $wpdb;
$table = $wpdb->esc_sql( $wpdb->prefix . 'wpc_login_fails' );
// Delete entries older than 30 days
$wpdb->query( "DELETE FROM {$table} WHERE login_attempt_date < NOW() - INTERVAL 30 DAY" );
}