Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. add_action( 'wp_scheduled_delete', 'delete_expired_db_transients' );
  2.  
  3. function delete_expired_db_transients() {
  4.  
  5.     global $wpdb, $_wp_using_ext_object_cache;
  6.  
  7.     if( $_wp_using_ext_object_cache )
  8.         return;
  9.  
  10.     $time = isset ( $_SERVER['REQUEST_TIME'] ) ? (int)$_SERVER['REQUEST_TIME'] : time() ;
  11.     $expired = $wpdb->get_col( "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '_transient_timeout%' AND option_value < {$time};" );
  12.  
  13.     foreach( $expired as $transient ) {
  14.  
  15.         $key = str_replace('_transient_timeout_', '', $transient);
  16.         delete_transient($key);
  17.     }
  18. }