Created
September 22, 2017 10:53
-
-
Save gabrielmerovingi/e51ce0da212d814130e4ebd463caef2c to your computer and use it in GitHub Desktop.
Daily cron script that will delete log entries that are "older" than a given timestamp.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Delete Old Entries | |
* Uses the daily myCRED cron job "mycred_cron_reset_key" to | |
* delete entries that are older than a given time each day | |
* @version 1.0 | |
*/ | |
function mycred_pro_delete_old_entries() { | |
// The maximum age a log entry can have in seconds | |
// Example 3 months | |
$max_age = ( 3 * MONTH_IN_SECONDS ); | |
$now = current_time( 'timestamp' ); | |
// Times are stored as unix timestamps so we just deduct the seconds from now | |
$timestamp = $now - $max_age; | |
global $wpdb, $mycred; | |
// Delete entries that are older than our $timestamp | |
$wpdb->query( $wpdb->prepare( "DELETE FROM {$mycred->log_table} WHERE time < %d;", $timestamp ) ); | |
} | |
add_action( 'mycred_cron_reset_key', 'mycred_pro_delete_old_entries' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment