clear_cache_for_substring($template);
}
/**
* Clear the cache for keys which contain the given substring
*
* @since 1.0.0
* @param string $substring The subtring which is a part of the keys to be cleared
*/
public function clear_cache_for_substring($substring) {
global $wpdb;
$statement = 'DELETE from wp_options
WHERE option_name like %s or option_name like %s';
$transient_timeout_cache = '_transient_timeout_aalb%' . $substring . '%';
$transient_cache = '_transient_aalb%' . $substring . '%';
$prepared_statement = $wpdb->prepare($statement, $transient_timeout_cache, $transient_cache);
try {
$wpdb->query($prepared_statement);
} catch(Exception $e) {
error_log('Unable to clear cache. Query to clear cache for substring ' . $substring . ' failed with the Exception ' . $e->getMessage());
}
}
/**
* Clear the dead expired transients from cache at intervals
*
* @since 1.0.0
*/
public function clear_expired_transients_at_intervals() {
$randomNumber = rand(1,50);
// Clear the expired transients approximately once in 50 requests.
if($randomNumber == 25) {
$this->clear_expired_transients();
}
}
/**
* Clear the dead expired transients from cache
*
* @since 1.0.0
*/
public function clear_expired_transients() {
global $wpdb;
$transients_prefix = esc_sql( "_transient_timeout_aalb%" );
$sql = $wpdb -> prepare (
'
SELECT option_name
FROM wp_options
WHERE option_name LIKE %s
',
$transients_prefix
);
$transients = $wpdb -> get_col( $sql );
foreach( $transients as $transient ) {
// Strip away the WordPress prefix in order to arrive at the transient key.
$key = str_replace( '_transient_timeout_', '', $transient );
delete_transient($key);
}
wp_cache_flush();
}
/**
* Displays error messages in preview mode only
*
* @since 1.0.0
* @param string $error_message Error message to be displayed
*/
public function show_error_in_preview($error_message) {
if (is_preview()) {
//If it's preview mode
echo "
" . $error_message . "";
}
}
/**
* Returns the Store IDs Array.
* Returns AALB_DEFAULT_STORE_ID_NAME if the nothing is specified.
*
* @since 1.0.0
*/
public function get_store_ids_array(){
return explode("\r\n", strlen(get_option(AALB_STORE_ID_NAMES))?get_option(AALB_STORE_ID_NAMES):AALB_DEFAULT_STORE_ID_NAME);
}
/**
* Fetches the current plugins version number
*
* @since 1.0.0
* @return string Version number of the plugin
*/
function get_plugin_version() {
return AALB_PLUGIN_VERSION;
}
/**
* Fetches the Wordpress version number
*
* @since 1.0.0
* @return string Version number of Wordpress
*/
function get_wordpress_version() {
global $wp_version;
return $wp_version;
}
}
?>