File: /var/www/html/wpprm/wp-content/themes/ronneby/inc/purge_transient.php
<?php
/*
Plugin Name: Purge Transients
Description: Purge old transients
Version: 0.2.1
Author: Seebz
*/
if ( ! defined( 'ABSPATH' ) ) { exit; }
if ( ! function_exists('purge_transients') ) {
function purge_transients($older_than = '1 hour', $safemode = false) {
global $wpdb;
$older_than_time = strtotime('-' . $older_than);
if ($older_than_time > time() || $older_than_time < 1) {
return false;
}
$transients = $wpdb->get_col(
$wpdb->prepare( "
SELECT REPLACE(option_name, '_transient_timeout_', '') AS transient_name
FROM {$wpdb->options}
WHERE option_name LIKE '%\_transient\_%'
AND option_value < %s
", $older_than_time)
);
if ($safemode) {
foreach($transients as $transient) {
get_transient($transient);
}
} else {
$options_names = array();
foreach($transients as $transient) {
$options_names[] = '_transient_' . $transient;
$options_names[] = '_transient_timeout_' . $transient;
}
if ($options_names) {
$options_names = array_map(array($wpdb, 'escape'), $options_names);
$options_names = "'". implode("','", $options_names) ."'";
$result = $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name IN ({$options_names})" );
if (!$result) {
return false;
}
}
}
return $transients;
}
}
add_action('admin_footer', 'purge_transients');
/**
add_action( 'wp_scheduled_delete', 'delete_expired_db_transients' );
function delete_expired_db_transients() {
global $wpdb, $_wp_using_ext_object_cache;
if( $_wp_using_ext_object_cache )
return;
$time = isset ( $_SERVER['REQUEST_TIME'] ) ? (int)$_SERVER['REQUEST_TIME'] : time() ;
$expired = $wpdb->get_col( "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '_transient_timeout%' AND option_value < {$time};" );
foreach( $expired as $transient ) {
$key = str_replace('_transient_timeout_', '', $transient);
delete_transient($key);
}
}
*/
?>