PluginProbe ʕ •ᴥ•ʔ
LiteSpeed Cache / 6.5.4
LiteSpeed Cache v6.5.4
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 1 year ago data_structure 1 year ago activation.cls.php 1 year ago admin-display.cls.php 1 year ago admin-settings.cls.php 1 year ago admin.cls.php 1 year ago api.cls.php 1 year ago avatar.cls.php 1 year ago base.cls.php 1 year ago cdn-setup.cls.php 1 year ago cdn.cls.php 1 year ago cloud.cls.php 1 year ago conf.cls.php 1 year ago control.cls.php 1 year ago core.cls.php 1 year ago crawler-map.cls.php 1 year ago crawler.cls.php 1 year ago css.cls.php 1 year ago data.cls.php 1 year ago data.upgrade.func.php 1 year ago db-optm.cls.php 1 year ago debug2.cls.php 1 year ago doc.cls.php 1 year ago error.cls.php 1 year ago esi.cls.php 1 year ago file.cls.php 1 year ago gui.cls.php 1 year ago health.cls.php 1 year ago htaccess.cls.php 1 year ago img-optm.cls.php 1 year ago import.cls.php 1 year ago instance.cls.php 1 year ago lang.cls.php 1 year ago localization.cls.php 1 year ago media.cls.php 1 year ago metabox.cls.php 1 year ago object-cache.cls.php 1 year ago object.lib.php 1 year ago optimize.cls.php 1 year ago optimizer.cls.php 1 year ago placeholder.cls.php 1 year ago preset.cls.php 1 year ago purge.cls.php 1 year ago report.cls.php 1 year ago rest.cls.php 1 year ago root.cls.php 1 year ago router.cls.php 1 year ago str.cls.php 1 year ago tag.cls.php 1 year ago task.cls.php 1 year ago tool.cls.php 1 year ago ucss.cls.php 1 year ago utility.cls.php 1 year ago vary.cls.php 1 year ago vpi.cls.php 1 year ago
api.cls.php
257 lines
1 <?php
2 /**
3 * The plugin API class.
4 *
5 * @since 1.1.3
6 * @since 1.4 Moved into /inc
7 * @package LiteSpeed
8 * @subpackage LiteSpeed/inc
9 * @author LiteSpeed Technologies <info@litespeedtech.com>
10 */
11 namespace LiteSpeed;
12
13 defined('WPINC') || exit();
14
15 class API extends Base
16 {
17 const VERSION = Core::VER;
18
19 const TYPE_FEED = Tag::TYPE_FEED;
20 const TYPE_FRONTPAGE = Tag::TYPE_FRONTPAGE;
21 const TYPE_HOME = Tag::TYPE_HOME;
22 const TYPE_PAGES = Tag::TYPE_PAGES;
23 const TYPE_PAGES_WITH_RECENT_POSTS = Tag::TYPE_PAGES_WITH_RECENT_POSTS;
24 const TYPE_HTTP = Tag::TYPE_HTTP;
25 const TYPE_ARCHIVE_POSTTYPE = Tag::TYPE_ARCHIVE_POSTTYPE;
26 const TYPE_ARCHIVE_TERM = Tag::TYPE_ARCHIVE_TERM;
27 const TYPE_AUTHOR = Tag::TYPE_AUTHOR;
28 const TYPE_ARCHIVE_DATE = Tag::TYPE_ARCHIVE_DATE;
29 const TYPE_BLOG = Tag::TYPE_BLOG;
30 const TYPE_LOGIN = Tag::TYPE_LOGIN;
31 const TYPE_URL = Tag::TYPE_URL;
32
33 const TYPE_ESI = Tag::TYPE_ESI;
34
35 const PARAM_NAME = ESI::PARAM_NAME;
36 const WIDGET_O_ESIENABLE = ESI::WIDGET_O_ESIENABLE;
37 const WIDGET_O_TTL = ESI::WIDGET_O_TTL;
38
39 /**
40 * Instance
41 *
42 * @since 3.0
43 */
44 public function __construct()
45 {
46 }
47
48 /**
49 * Define hooks to be used in other plugins.
50 *
51 * The benefit to use hooks other than functions is no need to detach if LSCWP enabled and function existed or not anymore
52 *
53 * @since 3.0
54 */
55 public function init()
56 {
57 /**
58 * Init
59 */
60 // Action `litespeed_init` // @previous API::hook_init( $hook )
61
62 /**
63 * Conf
64 */
65 add_filter('litespeed_conf', array($this, 'conf')); // @previous API::config($id)
66 // Action `litespeed_conf_append` // @previous API::conf_append( $name, $default )
67 add_action('litespeed_conf_multi_switch', __NAMESPACE__ . '\Base::set_multi_switch', 10, 2);
68 // Action ``litespeed_conf_force` // @previous API::force_option( $k, $v )
69
70 /**
71 * Cache Control Hooks
72 */
73 // Action `litespeed_control_finalize` // @previous API::hook_control($tags) && action `litespeed_api_control`
74 add_action('litespeed_control_set_private', __NAMESPACE__ . '\Control::set_private'); // @previous API::set_cache_private()
75 add_action('litespeed_control_set_nocache', __NAMESPACE__ . '\Control::set_nocache'); // @previous API::set_nocache( $reason = false )
76 add_action('litespeed_control_set_cacheable', array($this, 'set_cacheable')); // Might needed if not call hook `wp` // @previous API::set_cacheable( $reason )
77 add_action('litespeed_control_force_cacheable', __NAMESPACE__ . '\Control::force_cacheable'); // Set cache status to force cacheable ( Will ignore most kinds of non-cacheable conditions ) // @previous API::set_force_cacheable( $reason )
78 add_action('litespeed_control_force_public', __NAMESPACE__ . '\Control::set_public_forced'); // Set cache to force public cache if cacheable ( Will ignore most kinds of non-cacheable conditions ) // @previous API::set_force_public( $reason )
79 add_filter('litespeed_control_cacheable', __NAMESPACE__ . '\Control::is_cacheable', 3); // Note: Read-Only. Directly append to this filter won't work. Call actions above to set cacheable or not // @previous API::not_cacheable()
80 add_action('litespeed_control_set_ttl', __NAMESPACE__ . '\Control::set_custom_ttl', 10, 2); // @previous API::set_ttl( $val )
81 add_filter('litespeed_control_ttl', array($this, 'get_ttl'), 3); // @previous API::get_ttl()
82
83 /**
84 * Tag Hooks
85 */
86 // Action `litespeed_tag_finalize` // @previous API::hook_tag( $hook )
87 add_action('litespeed_tag', __NAMESPACE__ . '\Tag::add'); // Shorter alias of `litespeed_tag_add`
88 add_action('litespeed_tag_post', __NAMESPACE__ . '\Tag::add_post'); // Shorter alias of `litespeed_tag_add_post`
89 add_action('litespeed_tag_widget', __NAMESPACE__ . '\Tag::add_widget'); // Shorter alias of `litespeed_tag_add_widget`
90 add_action('litespeed_tag_private', __NAMESPACE__ . '\Tag::add_private'); // Shorter alias of `litespeed_tag_add_private`
91 add_action('litespeed_tag_private_esi', __NAMESPACE__ . '\Tag::add_private_esi'); // Shorter alias of `litespeed_tag_add_private_esi`
92
93 add_action('litespeed_tag_add', __NAMESPACE__ . '\Tag::add'); // @previous API::tag_add( $tag )
94 add_action('litespeed_tag_add_post', __NAMESPACE__ . '\Tag::add_post');
95 add_action('litespeed_tag_add_widget', __NAMESPACE__ . '\Tag::add_widget');
96 add_action('litespeed_tag_add_private', __NAMESPACE__ . '\Tag::add_private'); // @previous API::tag_add_private( $tags )
97 add_action('litespeed_tag_add_private_esi', __NAMESPACE__ . '\Tag::add_private_esi');
98
99 /**
100 * Purge Hooks
101 */
102 // Action `litespeed_purge_finalize` // @previous API::hook_purge($tags)
103 add_action('litespeed_purge', __NAMESPACE__ . '\Purge::add'); // @previous API::purge($tags)
104 add_action('litespeed_purge_all', __NAMESPACE__ . '\Purge::purge_all');
105 add_action('litespeed_purge_post', array($this, 'purge_post')); // @previous API::purge_post( $pid )
106 add_action('litespeed_purge_posttype', __NAMESPACE__ . '\Purge::purge_posttype');
107 add_action('litespeed_purge_url', array($this, 'purge_url'));
108 add_action('litespeed_purge_widget', __NAMESPACE__ . '\Purge::purge_widget');
109 add_action('litespeed_purge_esi', __NAMESPACE__ . '\Purge::purge_esi');
110 add_action('litespeed_purge_private', __NAMESPACE__ . '\Purge::add_private'); // @previous API::purge_private( $tags )
111 add_action('litespeed_purge_private_esi', __NAMESPACE__ . '\Purge::add_private_esi');
112 add_action('litespeed_purge_private_all', __NAMESPACE__ . '\Purge::add_private_all'); // @previous API::purge_private_all()
113 // Action `litespeed_api_purge_post` // Triggered when purge a post // @previous API::hook_purge_post($hook)
114 // Action `litespeed_purged_all` // Triggered after purged all.
115 add_action('litespeed_purge_all_object', __NAMESPACE__ . '\Purge::purge_all_object');
116 add_action('litespeed_purge_ucss', __NAMESPACE__ . '\Purge::purge_ucss');
117
118 /**
119 * ESI
120 */
121 // Action `litespeed_nonce` // @previous API::nonce_action( $action ) & API::nonce( $action = -1, $defence_for_html_filter = true ) // NOTE: only available after `init` hook
122 add_filter('litespeed_esi_status', array($this, 'esi_enabled')); // Get ESI enable status // @previous API::esi_enabled()
123 add_filter('litespeed_esi_url', array($this, 'sub_esi_block'), 10, 8); // Generate ESI block url // @previous API::esi_url( $block_id, $wrapper, $params = array(), $control = 'private,no-vary', $silence = false, $preserved = false, $svar = false, $inline_val = false )
124 // Filter `litespeed_widget_default_options` // Hook widget default settings value. Currently used in Woo 3rd // @previous API::hook_widget_default_options( $hook )
125 // Filter `litespeed_esi_params` // @previous API::hook_esi_param( $hook )
126 // Action `litespeed_tpl_normal` // @previous API::hook_tpl_not_esi($hook) && Action `litespeed_is_not_esi_template`
127 // Action `litespeed_esi_load-$block` // @usage add_action( 'litespeed_esi_load-' . $block, $hook ) // @previous API::hook_tpl_esi($block, $hook)
128 add_action('litespeed_esi_combine', __NAMESPACE__ . '\ESI::combine');
129
130 /**
131 * Vary
132 *
133 * To modify default vary, There are two ways: Action `litespeed_vary_append` or Filter `litespeed_vary`
134 */
135 add_action('litespeed_vary_ajax_force', __NAMESPACE__ . '\Vary::can_ajax_vary'); // API::force_vary() -> Action `litespeed_vary_ajax_force` // Force finalize vary even if its in an AJAX call
136 // Filter `litespeed_vary_curr_cookies` to generate current in use vary, which will be used for response vary header.
137 // 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)
138 // Filter `litespeed_vary` // Previous API::hook_vary_finalize( $hook )
139 add_action('litespeed_vary_no', __NAMESPACE__ . '\Control::set_no_vary'); // API::set_cache_no_vary() -> Action `litespeed_vary_no` // Set cache status to no vary
140
141 // add_filter( 'litespeed_is_mobile', __NAMESPACE__ . '\Control::is_mobile' ); // API::set_mobile() -> Filter `litespeed_is_mobile`
142
143 /**
144 * Cloud
145 */
146 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/
147
148 /**
149 * Media
150 */
151 add_action('litespeed_media_reset', __NAMESPACE__ . '\Media::delete_attachment'); // Reset one media row
152
153 /**
154 * GUI
155 */
156 // API::clean_wrapper_begin( $counter = false ) -> Filter `litespeed_clean_wrapper_begin` // Start a to-be-removed html wrapper
157 add_filter('litespeed_clean_wrapper_begin', __NAMESPACE__ . '\GUI::clean_wrapper_begin');
158 // API::clean_wrapper_end( $counter = false ) -> Filter `litespeed_clean_wrapper_end` // End a to-be-removed html wrapper
159 add_filter('litespeed_clean_wrapper_end', __NAMESPACE__ . '\GUI::clean_wrapper_end');
160
161 /**
162 * Mist
163 */
164 add_action('litespeed_debug', __NAMESPACE__ . '\Debug2::debug', 10, 2); // API::debug()-> Action `litespeed_debug`
165 add_action('litespeed_debug2', __NAMESPACE__ . '\Debug2::debug2', 10, 2); // API::debug2()-> Action `litespeed_debug2`
166 add_action('litespeed_disable_all', array($this, '_disable_all')); // API::disable_all( $reason ) -> Action `litespeed_disable_all`
167
168 add_action('litspeed_after_admin_init', array($this, '_after_admin_init'));
169 }
170
171 /**
172 * API for admin related
173 *
174 * @since 3.0
175 * @access public
176 */
177 public function _after_admin_init()
178 {
179 /**
180 * GUI
181 */
182 add_action('litespeed_setting_enroll', array($this->cls('Admin_Display'), 'enroll'), 10, 4); // API::enroll( $id ) // Register a field in setting form to save
183 add_action('litespeed_build_switch', array($this->cls('Admin_Display'), 'build_switch')); // API::build_switch( $id ) // Build a switch div html snippet
184 // API::hook_setting_content( $hook, $priority = 10, $args = 1 ) -> Action `litespeed_settings_content`
185 // API::hook_setting_tab( $hook, $priority = 10, $args = 1 ) -> Action `litespeed_settings_tab`
186 }
187
188 /**
189 * Disable All (Note: Not for direct call, always use Hooks)
190 *
191 * @since 2.9.7.2
192 * @access public
193 */
194 public function _disable_all($reason)
195 {
196 do_action('litespeed_debug', '[API] Disabled_all due to ' . $reason);
197
198 !defined('LITESPEED_DISABLE_ALL') && define('LITESPEED_DISABLE_ALL', true);
199 }
200
201 /**
202 * @since 3.0
203 */
204 public static function vary_append_commenter()
205 {
206 Vary::cls()->append_commenter();
207 }
208
209 /**
210 * Check if is from Cloud
211 *
212 * @since 4.2
213 */
214 public function is_from_cloud()
215 {
216 return $this->cls('Cloud')->is_from_cloud();
217 }
218
219 public function purge_post($pid)
220 {
221 $this->cls('Purge')->purge_post($pid);
222 }
223
224 public function purge_url($url)
225 {
226 $this->cls('Purge')->purge_url($url);
227 }
228
229 public function set_cacheable($reason = false)
230 {
231 $this->cls('Control')->set_cacheable($reason);
232 }
233
234 public function esi_enabled()
235 {
236 return $this->cls('Router')->esi_enabled();
237 }
238
239 public function get_ttl()
240 {
241 return $this->cls('Control')->get_ttl();
242 }
243
244 public function sub_esi_block(
245 $block_id,
246 $wrapper,
247 $params = array(),
248 $control = 'private,no-vary',
249 $silence = false,
250 $preserved = false,
251 $svar = false,
252 $inline_param = array()
253 ) {
254 return $this->cls('ESI')->sub_esi_block($block_id, $wrapper, $params, $control, $silence, $preserved, $svar, $inline_param);
255 }
256 }
257