|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Feed API: WP_Feed_Cache_Transient class |
|
4
|
|
|
* |
|
5
|
|
|
* @package WordPress |
|
6
|
|
|
* @subpackage Feed |
|
7
|
|
|
* @since 4.7.0 |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Core class used to implement feed cache transients. |
|
12
|
|
|
* |
|
13
|
|
|
* @since 2.8.0 |
|
14
|
|
|
*/ |
|
15
|
|
|
class WP_Feed_Cache_Transient { |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Holds the transient name. |
|
19
|
|
|
* |
|
20
|
|
|
* @since 2.8.0 |
|
21
|
|
|
* @access public |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
public $name; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Holds the transient mod name. |
|
28
|
|
|
* |
|
29
|
|
|
* @since 2.8.0 |
|
30
|
|
|
* @access public |
|
31
|
|
|
* @var string |
|
32
|
|
|
*/ |
|
33
|
|
|
public $mod_name; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Holds the cache duration in seconds. |
|
37
|
|
|
* |
|
38
|
|
|
* Defaults to 43200 seconds (12 hours). |
|
39
|
|
|
* |
|
40
|
|
|
* @since 2.8.0 |
|
41
|
|
|
* @access public |
|
42
|
|
|
* @var int |
|
43
|
|
|
*/ |
|
44
|
|
|
public $lifetime = 43200; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Constructor. |
|
48
|
|
|
* |
|
49
|
|
|
* @since 2.8.0 |
|
50
|
|
|
* @since 3.2.0 Updated to use a PHP5 constructor. |
|
51
|
|
|
* @access public |
|
52
|
|
|
* |
|
53
|
|
|
* @param string $location URL location (scheme is used to determine handler). |
|
54
|
|
|
* @param string $filename Unique identifier for cache object. |
|
55
|
|
|
* @param string $extension 'spi' or 'spc'. |
|
56
|
|
|
*/ |
|
57
|
|
|
public function __construct($location, $filename, $extension) { |
|
|
|
|
|
|
58
|
|
|
$this->name = 'feed_' . $filename; |
|
59
|
|
|
$this->mod_name = 'feed_mod_' . $filename; |
|
60
|
|
|
|
|
61
|
|
|
$lifetime = $this->lifetime; |
|
62
|
|
|
/** |
|
63
|
|
|
* Filters the transient lifetime of the feed cache. |
|
64
|
|
|
* |
|
65
|
|
|
* @since 2.8.0 |
|
66
|
|
|
* |
|
67
|
|
|
* @param int $lifetime Cache duration in seconds. Default is 43200 seconds (12 hours). |
|
68
|
|
|
* @param string $filename Unique identifier for the cache object. |
|
69
|
|
|
*/ |
|
70
|
|
|
$this->lifetime = apply_filters( 'wp_feed_cache_transient_lifetime', $lifetime, $filename); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Sets the transient. |
|
75
|
|
|
* |
|
76
|
|
|
* @since 2.8.0 |
|
77
|
|
|
* @access public |
|
78
|
|
|
* |
|
79
|
|
|
* @param SimplePie $data Data to save. |
|
80
|
|
|
* @return true Always true. |
|
|
|
|
|
|
81
|
|
|
*/ |
|
82
|
|
|
public function save($data) { |
|
83
|
|
|
if ( $data instanceof SimplePie ) { |
|
84
|
|
|
$data = $data->data; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
set_transient($this->name, $data, $this->lifetime); |
|
88
|
|
|
set_transient($this->mod_name, time(), $this->lifetime); |
|
89
|
|
|
return true; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Gets the transient. |
|
94
|
|
|
* |
|
95
|
|
|
* @since 2.8.0 |
|
96
|
|
|
* @access public |
|
97
|
|
|
* |
|
98
|
|
|
* @return mixed Transient value. |
|
99
|
|
|
*/ |
|
100
|
|
|
public function load() { |
|
101
|
|
|
return get_transient($this->name); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Gets mod transient. |
|
106
|
|
|
* |
|
107
|
|
|
* @since 2.8.0 |
|
108
|
|
|
* @access public |
|
109
|
|
|
* |
|
110
|
|
|
* @return mixed Transient value. |
|
111
|
|
|
*/ |
|
112
|
|
|
public function mtime() { |
|
113
|
|
|
return get_transient($this->mod_name); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Sets mod transient. |
|
118
|
|
|
* |
|
119
|
|
|
* @since 2.8.0 |
|
120
|
|
|
* @access public |
|
121
|
|
|
* |
|
122
|
|
|
* @return bool False if value was not set and true if value was set. |
|
123
|
|
|
*/ |
|
124
|
|
|
public function touch() { |
|
125
|
|
|
return set_transient($this->mod_name, time(), $this->lifetime); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* Deletes transients. |
|
130
|
|
|
* |
|
131
|
|
|
* @since 2.8.0 |
|
132
|
|
|
* @access public |
|
133
|
|
|
* |
|
134
|
|
|
* @return true Always true. |
|
|
|
|
|
|
135
|
|
|
*/ |
|
136
|
|
|
public function unlink() { |
|
137
|
|
|
delete_transient($this->name); |
|
138
|
|
|
delete_transient($this->mod_name); |
|
139
|
|
|
return true; |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.