Created
August 16, 2014 04:24
-
-
Save JulioPotier/1a6f91a4d243712facc8 to your computer and use it in GitHub Desktop.
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
add_action( 'wp_scheduled_delete', 'delete_expired_db_transients' ); | |
function delete_expired_db_transients() { | |
if ( wp_using_ext_object_cache() ) { // magic | |
return; | |
} | |
global $wpdb; | |
$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 ); | |
} | |
} | |
// by @rarst |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment