PluginProbe ʕ •ᴥ•ʔ
LiteSpeed Cache / 7.6.1
LiteSpeed Cache v7.6.1
trunk 1.0.15 1.9.1.1 2.9.9.2 3.6.4 4.6 5.7.0.1 6.5.4 7.0.0.1 7.0.1 7.1 7.2 7.3 7.3.0.1 7.4 7.5 7.5.0.1 7.6 7.6.1 7.6.2 7.7 7.8 7.8.0.1 7.8.1
litespeed-cache / src / api.cls.php
litespeed-cache / src Last commit date
cdn 7 months ago data_structure 7 months ago activation.cls.php 7 months ago admin-display.cls.php 7 months ago admin-settings.cls.php 7 months ago admin.cls.php 7 months ago api.cls.php 7 months ago avatar.cls.php 7 months ago base.cls.php 7 months ago cdn.cls.php 7 months ago cloud.cls.php 7 months ago conf.cls.php 7 months ago control.cls.php 7 months ago core.cls.php 7 months ago crawler-map.cls.php 7 months ago crawler.cls.php 7 months ago css.cls.php 7 months ago data.cls.php 7 months ago data.upgrade.func.php 7 months ago db-optm.cls.php 7 months ago debug2.cls.php 7 months ago doc.cls.php 7 months ago error.cls.php 7 months ago esi.cls.php 7 months ago file.cls.php 7 months ago gui.cls.php 7 months ago health.cls.php 7 months ago htaccess.cls.php 7 months ago img-optm.cls.php 7 months ago import.cls.php 7 months ago import.preset.cls.php 7 months ago lang.cls.php 7 months ago localization.cls.php 7 months ago media.cls.php 7 months ago metabox.cls.php 7 months ago object-cache-wp.cls.php 7 months ago object-cache.cls.php 7 months ago object.lib.php 7 months ago optimize.cls.php 7 months ago optimizer.cls.php 7 months ago placeholder.cls.php 7 months ago purge.cls.php 7 months ago report.cls.php 7 months ago rest.cls.php 7 months ago root.cls.php 7 months ago router.cls.php 7 months ago str.cls.php 7 months ago tag.cls.php 7 months ago task.cls.php 7 months ago tool.cls.php 7 months ago ucss.cls.php 7 months ago utility.cls.php 7 months ago vary.cls.php 7 months ago vpi.cls.php 7 months ago
api.cls.php
339 lines
1 <?php
2 /**
3 * The plugin API class.
4 *
5 * @since 1.1.3
6 * @package LiteSpeed
7 */
8
9 namespace LiteSpeed;
10
11 defined( 'WPINC' ) || exit();
12
13 /**
14 * Class API
15 *
16 * Provides API hooks and methods for LiteSpeed Cache integration.
17 *
18 * @since 1.1.3
19 */
20 class API extends Base {
21
22 const VERSION = Core::VER;
23
24 const TYPE_FEED = Tag::TYPE_FEED;
25 const TYPE_FRONTPAGE = Tag::TYPE_FRONTPAGE;
26 const TYPE_HOME = Tag::TYPE_HOME;
27 const TYPE_PAGES = Tag::TYPE_PAGES;
28 const TYPE_PAGES_WITH_RECENT_POSTS = Tag::TYPE_PAGES_WITH_RECENT_POSTS;
29 const TYPE_HTTP = Tag::TYPE_HTTP;
30 const TYPE_ARCHIVE_POSTTYPE = Tag::TYPE_ARCHIVE_POSTTYPE;
31 const TYPE_ARCHIVE_TERM = Tag::TYPE_ARCHIVE_TERM;
32 const TYPE_AUTHOR = Tag::TYPE_AUTHOR;
33 const TYPE_ARCHIVE_DATE = Tag::TYPE_ARCHIVE_DATE;
34 const TYPE_BLOG = Tag::TYPE_BLOG;
35 const TYPE_LOGIN = Tag::TYPE_LOGIN;
36 const TYPE_URL = Tag::TYPE_URL;
37
38 const TYPE_ESI = Tag::TYPE_ESI;
39
40 const PARAM_NAME = ESI::PARAM_NAME;
41 const WIDGET_O_ESIENABLE = ESI::WIDGET_O_ESIENABLE;
42 const WIDGET_O_TTL = ESI::WIDGET_O_TTL;
43
44 /**
45 * Instance
46 *
47 * Initializes the API class.
48 *
49 * @since 3.0
50 */
51 public function __construct() {
52 }
53
54 /**
55 * Define hooks to be used in other plugins.
56 *
57 * The benefit to use hooks other than functions is no need to detach if LSCWP enabled and function existed or not anymore
58 *
59 * @since 3.0
60 */
61 public function init() {
62 /**
63 * Init
64 */
65 // Action `litespeed_init`
66
67 /**
68 * Conf
69 */
70 add_filter( 'litespeed_conf', array( $this, 'conf' ) );
71 // Action `litespeed_conf_append`
72 add_action( 'litespeed_conf_multi_switch', __NAMESPACE__ . '\Base::set_multi_switch', 10, 2 );
73 // Action `litespeed_conf_force`
74 add_action( 'litespeed_save_conf', array( $this, 'save_conf' ) );
75
76 /**
77 * Cache Control Hooks
78 */
79 // Action `litespeed_control_finalize`
80 add_action( 'litespeed_control_set_private', __NAMESPACE__ . '\Control::set_private' );
81 add_action( 'litespeed_control_set_nocache', __NAMESPACE__ . '\Control::set_nocache' );
82 add_action( 'litespeed_control_set_cacheable', array( $this, 'set_cacheable' ) );
83 add_action( 'litespeed_control_force_cacheable', __NAMESPACE__ . '\Control::force_cacheable' );
84 add_action( 'litespeed_control_force_public', __NAMESPACE__ . '\Control::set_public_forced' );
85 add_filter( 'litespeed_control_cacheable', __NAMESPACE__ . '\Control::is_cacheable', 3 );
86 add_action( 'litespeed_control_set_ttl', __NAMESPACE__ . '\Control::set_custom_ttl', 10, 2 );
87 add_filter( 'litespeed_control_ttl', array( $this, 'get_ttl' ), 3 );
88
89 /**
90 * Tag Hooks
91 */
92 // Action `litespeed_tag_finalize`
93 add_action( 'litespeed_tag', __NAMESPACE__ . '\Tag::add' );
94 add_action( 'litespeed_tag_post', __NAMESPACE__ . '\Tag::add_post' );
95 add_action( 'litespeed_tag_widget', __NAMESPACE__ . '\Tag::add_widget' );
96 add_action( 'litespeed_tag_private', __NAMESPACE__ . '\Tag::add_private' );
97 add_action( 'litespeed_tag_private_esi', __NAMESPACE__ . '\Tag::add_private_esi' );
98
99 add_action( 'litespeed_tag_add', __NAMESPACE__ . '\Tag::add' );
100 add_action( 'litespeed_tag_add_post', __NAMESPACE__ . '\Tag::add_post' );
101 add_action( 'litespeed_tag_add_widget', __NAMESPACE__ . '\Tag::add_widget' );
102 add_action( 'litespeed_tag_add_private', __NAMESPACE__ . '\Tag::add_private' );
103 add_action( 'litespeed_tag_add_private_esi', __NAMESPACE__ . '\Tag::add_private_esi' );
104
105 /**
106 * Purge Hooks
107 */
108 // Action `litespeed_purge_finalize`
109 add_action( 'litespeed_purge', __NAMESPACE__ . '\Purge::add' );
110 add_action( 'litespeed_purge_all', __NAMESPACE__ . '\Purge::purge_all' );
111 add_action( 'litespeed_purge_post', array( $this, 'purge_post' ) );
112 add_action( 'litespeed_purge_posttype', __NAMESPACE__ . '\Purge::purge_posttype' );
113 add_action( 'litespeed_purge_url', array( $this, 'purge_url' ) );
114 add_action( 'litespeed_purge_widget', __NAMESPACE__ . '\Purge::purge_widget' );
115 add_action( 'litespeed_purge_esi', __NAMESPACE__ . '\Purge::purge_esi' );
116 add_action( 'litespeed_purge_private', __NAMESPACE__ . '\Purge::add_private' );
117 add_action( 'litespeed_purge_private_esi', __NAMESPACE__ . '\Purge::add_private_esi' );
118 add_action( 'litespeed_purge_private_all', __NAMESPACE__ . '\Purge::add_private_all' );
119 // Action `litespeed_api_purge_post`
120 // Action `litespeed_purged_all`
121 add_action( 'litespeed_purge_all_object', __NAMESPACE__ . '\Purge::purge_all_object' );
122 add_action( 'litespeed_purge_ucss', __NAMESPACE__ . '\Purge::purge_ucss' );
123
124 /**
125 * ESI
126 */
127 // Action `litespeed_nonce`
128 add_filter( 'litespeed_esi_status', array( $this, 'esi_enabled' ) );
129 add_filter( 'litespeed_esi_url', array( $this, 'sub_esi_block' ), 10, 8 ); // Generate ESI block url
130 // Filter `litespeed_widget_default_options` // Hook widget default settings value. Currently used in Woo 3rd
131 // Filter `litespeed_esi_params`
132 // Action `litespeed_tpl_normal`
133 // Action `litespeed_esi_load-$block` // @usage add_action( 'litespeed_esi_load-' . $block, $hook )
134 add_action( 'litespeed_esi_combine', __NAMESPACE__ . '\ESI::combine' );
135
136 /**
137 * Vary
138 *
139 * To modify default vary, There are two ways: Action `litespeed_vary_append` or Filter `litespeed_vary`
140 */
141 add_action( 'litespeed_vary_ajax_force', __NAMESPACE__ . '\Vary::can_ajax_vary' ); // Force finalize vary even if its in an AJAX call
142 // Filter `litespeed_vary_curr_cookies` to generate current in use vary, which will be used for response vary header.
143 // Filter `litespeed_vary_cookies` to register the final vary cookies, which will be written to rewrite rule. (litespeed_vary_curr_cookies are always equal to or less than litespeed_vary_cookies)
144 // Filter `litespeed_vary`
145 add_action( 'litespeed_vary_no', __NAMESPACE__ . '\Control::set_no_vary' );
146
147 /**
148 * Cloud
149 */
150 add_filter( 'litespeed_is_from_cloud', array( $this, 'is_from_cloud' ) ); // Check if current request is from QC (usually its to check REST access) // @see https://wordpress.org/support/topic/image-optimization-not-working-3/
151
152 /**
153 * Media
154 */
155 add_action( 'litespeed_media_reset', __NAMESPACE__ . '\Media::delete_attachment' );
156
157 /**
158 * GUI
159 */
160 add_filter( 'litespeed_clean_wrapper_begin', __NAMESPACE__ . '\GUI::clean_wrapper_begin' );
161 add_filter( 'litespeed_clean_wrapper_end', __NAMESPACE__ . '\GUI::clean_wrapper_end' );
162
163 /**
164 * Misc
165 */
166 add_action( 'litespeed_debug', __NAMESPACE__ . '\Debug2::debug', 10, 2 );
167 add_action( 'litespeed_debug2', __NAMESPACE__ . '\Debug2::debug2', 10, 2 );
168 add_action( 'litespeed_disable_all', array( $this, 'disable_all' ) );
169
170 add_action( 'litespeed_after_admin_init', array( $this, 'after_admin_init' ) );
171 }
172
173 /**
174 * API for admin related
175 *
176 * Registers hooks for admin settings and UI elements.
177 *
178 * @since 3.0
179 * @access public
180 */
181 public function after_admin_init() {
182 /**
183 * GUI
184 */
185 add_action( 'litespeed_setting_enroll', array( $this->cls( 'Admin_Display' ), 'enroll' ), 10, 4 );
186 add_action( 'litespeed_build_switch', array( $this->cls( 'Admin_Display' ), 'build_switch' ) );
187 // Action `litespeed_settings_content`
188 // Action `litespeed_settings_tab`
189 }
190
191 /**
192 * Disable All
193 *
194 * Disables all LiteSpeed Cache features with a given reason.
195 *
196 * @since 2.9.7.2
197 * @access public
198 * @param string $reason The reason for disabling all features.
199 */
200 public function disable_all( $reason ) {
201 do_action( 'litespeed_debug', '[API] Disabled_all due to ' . $reason );
202
203 ! defined( 'LITESPEED_DISABLE_ALL' ) && define( 'LITESPEED_DISABLE_ALL', true );
204 }
205
206 /**
207 * Append commenter vary
208 *
209 * Adds commenter vary to the cache vary cookies.
210 *
211 * @since 3.0
212 * @access public
213 */
214 public static function vary_append_commenter() {
215 Vary::cls()->append_commenter();
216 }
217
218 /**
219 * Check if is from Cloud
220 *
221 * Checks if the current request originates from QUIC.cloud.
222 *
223 * @since 4.2
224 * @access public
225 * @return bool True if from QUIC.cloud, false otherwise.
226 */
227 public function is_from_cloud() {
228 return $this->cls( 'Cloud' )->is_from_cloud();
229 }
230
231 /**
232 * Purge post
233 *
234 * Purges the cache for a specific post.
235 *
236 * @since 3.0
237 * @access public
238 * @param int $pid Post ID to purge.
239 */
240 public function purge_post( $pid ) {
241 $this->cls( 'Purge' )->purge_post( $pid );
242 }
243
244 /**
245 * Purge URL
246 *
247 * Purges the cache for a specific URL.
248 *
249 * @since 3.0
250 * @access public
251 * @param string $url URL to purge.
252 */
253 public function purge_url( $url ) {
254 $this->cls( 'Purge' )->purge_url( $url );
255 }
256
257 /**
258 * Set cacheable
259 *
260 * Marks the current request as cacheable.
261 *
262 * @since 3.0
263 * @access public
264 * @param string|bool $reason Optional reason for setting cacheable.
265 */
266 public function set_cacheable( $reason = false ) {
267 $this->cls( 'Control' )->set_cacheable( $reason );
268 }
269
270 /**
271 * Check ESI enabled
272 *
273 * Returns whether ESI is enabled.
274 *
275 * @since 3.0
276 * @access public
277 * @return bool True if ESI is enabled, false otherwise.
278 */
279 public function esi_enabled() {
280 return $this->cls( 'Router' )->esi_enabled();
281 }
282
283 /**
284 * Get TTL
285 *
286 * Retrieves the cache TTL (time to live).
287 *
288 * @since 3.0
289 * @access public
290 * @return int Cache TTL value.
291 */
292 public function get_ttl() {
293 return $this->cls( 'Control' )->get_ttl();
294 }
295
296 /**
297 * Generate ESI block URL
298 *
299 * Generates a URL for an ESI block.
300 *
301 * @since 3.0
302 * @access public
303 * @param string $block_id ESI block ID.
304 * @param string $wrapper Wrapper identifier.
305 * @param array $params Parameters for the ESI block.
306 * @param string $control Cache control settings.
307 * @param bool $silence Silence output flag.
308 * @param bool $preserved Preserved flag.
309 * @param bool $svar Server variable flag.
310 * @param array $inline_param Inline parameters.
311 * @return string ESI block URL.
312 */
313 public function sub_esi_block(
314 $block_id,
315 $wrapper,
316 $params = array(),
317 $control = 'private,no-vary',
318 $silence = false,
319 $preserved = false,
320 $svar = false,
321 $inline_param = array()
322 ) {
323 return $this->cls( 'ESI' )->sub_esi_block( $block_id, $wrapper, $params, $control, $silence, $preserved, $svar, $inline_param );
324 }
325
326 /**
327 * Set and sync conf
328 *
329 * Updates and synchronizes configuration settings.
330 *
331 * @since 7.2
332 * @access public
333 * @param bool|array $the_matrix Configuration data to update.
334 */
335 public function save_conf( $the_matrix = false ) {
336 $this->cls( 'Conf' )->update_confs( $the_matrix );
337 }
338 }
339