options WHERE option_name LIKE '%_transient_%'"; $clean = $wpdb -> query( $sql ); $records .= $clean; // If multisite, and the main network, also clear the sitemeta table if ( is_multisite() && is_main_network() ) { $sql = "DELETE FROM $wpdb->sitemeta WHERE meta_key LIKE '_site_transient_%'"; $clean = $wpdb -> query( $sql ); $records .= $clean; } } else { // Delete transients from options table $sql = " 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, CHAR_LENGTH('_transient_') + 1 ) ) AND b.option_value < UNIX_TIMESTAMP() "; $clean = $wpdb -> query( $sql ); $records .= $clean; // Delete transients from multisite, if configured as such if ( is_multisite() && is_main_network() ) { $sql = " DELETE a, b FROM {$wpdb->sitemeta} a, {$wpdb->sitemeta} b WHERE a.meta_key LIKE '_site_transient_%' AND a.meta_key NOT LIKE '_site_transient_timeout_%' AND b.meta_key = CONCAT( '_site_transient_timeout_', SUBSTRING( a.meta_key, CHAR_LENGTH('_site_transient_') + 1 ) ) AND b.meta_value < UNIX_TIMESTAMP() "; $clean = $wpdb -> query( $sql ); $records .= $clean; } } // Save options field with number & timestamp $results = array(); $results[ 'timestamp' ] = time() + ( get_option( 'gmt_offset' ) * 3600 ); $results[ 'records' ] = $records; $option_name = 'transient_clean_'; if ( $clear_all ) { $option_name .= 'all'; } else { $option_name .= 'expired'; } update_option( $option_name, $results ); // Optimize the table after the deletions if ( ( ( $options[ 'upgrade_optimize' ] ) && ( $clear_all ) ) or ( ( $options[ 'clean_optimize' ] ) && ( !$clear_all ) ) ) { $wpdb -> query( "OPTIMIZE TABLE $wpdb->options" ); if ( is_multisite() && is_main_network() ) { $wpdb -> query( "OPTIMIZE TABLE $wpdb->sitemeta" ); } } } return $cleaned; }