• Resolved NF

    (@nanasflowers)


    Hi,

    Currently the only way to clear the failed login and access locks logs are to empty them entirely. Please could we have a setting to delete log records after x number of days, ideally 30 so that the graph still works. This will prevent database buildup (I sometimes record several thousand per day) and keep functionality.

    • This topic was modified 1 year, 2 months ago by NF.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Alexandru Tapuleasa

    (@talextech)

    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" );
    }
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Failed Login & Access Locks Logs’ is closed to new replies.