lesterchan / wp-sweep

WP-Sweep allows you to clean up unused, orphaned and duplicated data in your WordPress. It also optimizes your database tables.
https://wordpress.org/plugins/wp-sweep/
152 stars 23 forks source link

Delete expired transients only #48

Open dkrymov opened 7 years ago

dkrymov commented 7 years ago

Could you add expiry filter when delete transients? As option or as built-in behavior.

$time = isset ( $_SERVER['REQUEST_TIME'] ) ? (int)$_SERVER['REQUEST_TIME'] : time() ;
$expired = $wpdb->get_col( "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '_transient_timeout%' AND option_value < {$time};" );

foreach( $expired as $transient ) {
       $key = str_replace('_transient_timeout_', '', $transient);
       delete_transient($key);
}

https://wordpress.stackexchange.com/a/6652