+
+ // Deletes all expired transients.
+ // The multi-table delete syntax is used to delete the transient record from table a,
+ // and the corresponding transient_timeout record from table b.
+ $time = time();
+ $wpdb->query("DELETE a, b FROM $wpdb->options a, $wpdb->options b WHERE
+ a.option_name LIKE '\_transient\_%' AND
+ a.option_name NOT LIKE '\_transient\_timeout\_%' AND
+ b.option_name = CONCAT( '_transient_timeout_', SUBSTRING( a.option_name, 12 ) )
+ AND b.option_value < $time");
+
+ if ( is_main_site() && is_main_network() ) {
+ $wpdb->query("DELETE a, b FROM $wpdb->options a, $wpdb->options b WHERE
+ a.option_name LIKE '\_site\_transient\_%' AND
+ a.option_name NOT LIKE '\_site\_transient\_timeout\_%' AND
+ b.option_name = CONCAT( '_site_transient_timeout_', SUBSTRING( a.option_name, 17 ) )
+ AND b.option_value < $time");
+ }