class-wpml-transient.php
1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
* Class WPML_Transient
*
* Due to some conflicts between cached environments (e.g. using W3TC) and the normal
* WP Transients API, we've added this class which should behaves almost like the normal
* transients API. Except for the fact that it is stored as normal options, so WP won't
* recognize/treat it as a transient.
*/
class WPML_Transient {
const WPML_TRANSIENT_PREFIX = '_wpml_transient_';
/**
* @param string $name
* @param string $value
* @param string $expiration
*/
public function set( $name, $value, $expiration = '' ) {
$data = array(
'value' => $value,
'expiration' => $expiration ? time() + (int) $expiration : '',
);
update_option( self::WPML_TRANSIENT_PREFIX . $name, $data );
}
/**
* @param string $name
*
* @return string
*/
public function get( $name ) {
$data = get_option( self::WPML_TRANSIENT_PREFIX . $name );
if ( $data ) {
if ( (int) $data['expiration'] < time() ) {
delete_option( self::WPML_TRANSIENT_PREFIX . $name );
return '';
}
return $data['value'];
}
return '';
}
/**
* @param string $name
*/
public function delete( $name ) {
delete_option( self::WPML_TRANSIENT_PREFIX . $name );
}
}