/** * Clean expired temporaries from database. * * Search database for all expired temporaries older * that one minute and use methods for retrieval to * delete them. * * Inspired by https://github.com/Seebz/Snippets/tree/master/Wordpress/plugins/purge-transients * * @since 1.0.0 * @access public */ public static function clean() { global $wpdb; /** * Allow short-circuit of cleaning of temporaries. * * Passing a truthy value to the filter * will short-circuit process of cleaning. * * @since 1.0.0 * * @param bool|mixed $pre_value Should cleaning be not done. * Default false to skip it. */ $pre = apply_filters('wp_temporary_clean_pre', false); if (false !== $pre) { return; } // Older than minute, just for case $older_than_time = time() - MINUTE_IN_SECONDS; // Clean single site temporaries $temporaries = $wpdb->get_col($wpdb->prepare("\n\t\t\t\tSELECT REPLACE(option_name, '_temporary_timeout_', '') AS transient_name\n\t\t\t\tFROM {$wpdb->options}\n\t\t\t\tWHERE option_name LIKE '\\_temporary\\_timeout\\__%%'\n\t\t\t\tAND option_value < %s\n\t\t\t\t", $older_than_time)); foreach ($temporaries as $temporary) { WP_Temporary::get($temporary); } // Clean network wide temporaries if (is_multisite()) { $temporaries = $wpdb->get_col($wpdb->prepare("\n\t\t\t\t\tSELECT REPLACE(meta_key, '_site_temporary_timeout_', '') AS temporary_name\n\t\t\t\t\tFROM {$wpdb->sitemeta}\n\t\t\t\t\tWHERE meta_key LIKE '\\_site\\_temporary\\_timeout\\__%%'\n\t\t\t\t\tAND meta_value < %s\n\t\t\t\t\t", $older_than_time)); } else { $temporaries = $wpdb->get_col($wpdb->prepare("\n\t\t\t\t\tSELECT REPLACE(option_name, '_site_temporary_timeout_', '') AS temporary_name\n\t\t\t\t\tFROM {$wpdb->options}\n\t\t\t\t\tWHERE option_name LIKE '\\_site\\_temporary\\_timeout\\__%%'\n\t\t\t\t\tAND option_value < %s\n\t\t\t\t\t", $older_than_time)); } foreach ($temporaries as $temporary) { WP_Temporary::get_site($temporary); } /** * Fires after the cleaning of temporaries has been done. * * @since 1.0.0 */ do_action('wp_temporary_clean_after'); }