options WHERE option_name LIKE '_transient_%'"; $clean = $wpdb -> query( $sql ); } else { $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 ); $sql = " 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, CHAR_LENGTH('_site_transient_') + 1 ) ) AND b.option_value < UNIX_TIMESTAMP() "; $clean = $wpdb -> query( $sql ); } // If a housekeep has been performed check the number of expired transients // remaining - if any exist, save as orphaned if ( !$clear_all ) { $results[ 'orphans' ] = $wpdb -> get_var( "SELECT COUNT(*) FROM $wpdb->options WHERE option_name LIKE '%_transient_timeout_%' AND option_value < UNIX_TIMESTAMP()" ); } // Save options field with number & timestamp $results[ 'timestamp' ] = time(); $results[ 'timestamp' ] = gmmktime() + ( get_option( 'gmt_offset' ) * 3600 ); $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" ); } } return $cleaned; } ?>