PluginProbe ʕ •ᴥ•ʔ
LiteSpeed Cache / 7.8.1
LiteSpeed Cache v7.8.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 / tool.cls.php
litespeed-cache / src Last commit date
cdn 2 months ago data_structure 2 months ago activation.cls.php 2 months ago admin-display.cls.php 2 months ago admin-settings.cls.php 2 months ago admin.cls.php 2 months ago api.cls.php 2 months ago avatar.cls.php 2 months ago base.cls.php 2 months ago cdn.cls.php 2 months ago cloud-auth-callback.trait.php 2 months ago cloud-auth-ip.trait.php 2 months ago cloud-auth.trait.php 2 months ago cloud-misc.trait.php 2 months ago cloud-node.trait.php 2 months ago cloud-request.trait.php 2 months ago cloud.cls.php 2 months ago conf.cls.php 2 months ago control.cls.php 2 months ago core.cls.php 2 months ago crawler-map.cls.php 2 months ago crawler.cls.php 2 months ago css.cls.php 2 months ago data.cls.php 2 months ago data.upgrade.func.php 2 months ago db-optm.cls.php 2 months ago debug2.cls.php 2 months ago doc.cls.php 2 months ago error.cls.php 2 months ago esi.cls.php 2 months ago file.cls.php 2 months ago guest.cls.php 2 months ago gui.cls.php 2 months ago health.cls.php 2 months ago htaccess.cls.php 2 months ago img-optm-manage.trait.php 2 months ago img-optm-pull.trait.php 2 months ago img-optm-send.trait.php 2 months ago img-optm.cls.php 2 months ago import.cls.php 2 months ago import.preset.cls.php 2 months ago lang.cls.php 2 months ago localization.cls.php 2 months ago media.cls.php 2 months ago metabox.cls.php 2 months ago object-cache-wp.cls.php 2 months ago object-cache.cls.php 2 months ago object.lib.php 2 months ago optimize.cls.php 2 months ago optimizer.cls.php 2 months ago placeholder.cls.php 2 months ago purge.cls.php 2 months ago report.cls.php 2 months ago rest.cls.php 2 months ago root.cls.php 2 months ago router.cls.php 2 months ago str.cls.php 2 months ago tag.cls.php 2 months ago task.cls.php 2 months ago tool.cls.php 2 months ago ucss.cls.php 2 months ago utility.cls.php 2 months ago vary.cls.php 2 months ago vpi.cls.php 2 months ago
tool.cls.php
166 lines
1 <?php
2 /**
3 * The tools
4 *
5 * @since 3.0
6 * @package LiteSpeed
7 */
8
9 namespace LiteSpeed;
10
11 defined( 'WPINC' ) || exit();
12
13 /**
14 * Class Tool
15 *
16 * Provides utility functions for LiteSpeed Cache, including IP detection and heartbeat control.
17 *
18 * @since 3.0
19 */
20 class Tool extends Root {
21
22 const LOG_TAG = '[Tool]';
23
24 /**
25 * Get public IP
26 *
27 * Retrieves the public IP address of the server.
28 *
29 * @since 3.0
30 * @access public
31 * @return string The public IP address or an error message.
32 */
33 public function check_ip() {
34 self::debug( '�
35 check_ip' );
36
37 $response = wp_safe_remote_get( 'https://cyberpanel.sh/?ip', [
38 'headers' => [
39 'User-Agent' => 'curl/8.7.1',
40 ],
41 ] );
42
43 if ( is_wp_error( $response ) ) {
44 return esc_html__( 'Failed to detect IP', 'litespeed-cache' );
45 }
46
47 $ip = trim( $response['body'] );
48
49 self::debug( 'result [ip] ' . $ip );
50
51 if ( Utility::valid_ipv4( $ip ) ) {
52 return $ip;
53 }
54
55 return esc_html__( 'Failed to detect IP', 'litespeed-cache' );
56 }
57
58 /**
59 * Heartbeat Control
60 *
61 * Configures WordPress heartbeat settings for frontend, backend, and editor.
62 *
63 * @since 3.0
64 * @access public
65 */
66 public function heartbeat() {
67 add_action( 'wp_enqueue_scripts', [ $this, 'heartbeat_frontend' ] );
68 add_action( 'admin_enqueue_scripts', [ $this, 'heartbeat_backend' ] );
69 add_filter( 'heartbeat_settings', [ $this, 'heartbeat_settings' ] );
70 }
71
72 /**
73 * Heartbeat Control frontend control
74 *
75 * Manages heartbeat settings for the frontend.
76 *
77 * @since 3.0
78 * @access public
79 */
80 public function heartbeat_frontend() {
81 if ( ! $this->conf( Base::O_MISC_HEARTBEAT_FRONT ) ) {
82 return;
83 }
84
85 if ( ! $this->conf( Base::O_MISC_HEARTBEAT_FRONT_TTL ) ) {
86 wp_deregister_script( 'heartbeat' );
87 Debug2::debug( '[Tool] Deregistered frontend heartbeat' );
88 }
89 }
90
91 /**
92 * Heartbeat Control backend control
93 *
94 * Manages heartbeat settings for the backend and editor.
95 *
96 * @since 3.0
97 * @access public
98 */
99 public function heartbeat_backend() {
100 if ( $this->is_editor() ) {
101 if ( ! $this->conf( Base::O_MISC_HEARTBEAT_EDITOR ) ) {
102 return;
103 }
104
105 if ( ! $this->conf( Base::O_MISC_HEARTBEAT_EDITOR_TTL ) ) {
106 wp_deregister_script( 'heartbeat' );
107 Debug2::debug( '[Tool] Deregistered editor heartbeat' );
108 }
109 } else {
110 if ( ! $this->conf( Base::O_MISC_HEARTBEAT_BACK ) ) {
111 return;
112 }
113
114 if ( ! $this->conf( Base::O_MISC_HEARTBEAT_BACK_TTL ) ) {
115 wp_deregister_script( 'heartbeat' );
116 Debug2::debug( '[Tool] Deregistered backend heartbeat' );
117 }
118 }
119 }
120
121 /**
122 * Heartbeat Control settings
123 *
124 * Adjusts heartbeat interval settings based on configuration.
125 *
126 * @since 3.0
127 * @access public
128 * @param array $settings Existing heartbeat settings.
129 * @return array Modified heartbeat settings.
130 */
131 public function heartbeat_settings( $settings ) {
132 // Check editor first to make frontend editor valid too
133 if ( $this->is_editor() ) {
134 if ( $this->conf( Base::O_MISC_HEARTBEAT_EDITOR ) ) {
135 $settings['interval'] = $this->conf( Base::O_MISC_HEARTBEAT_EDITOR_TTL );
136 Debug2::debug( '[Tool] Heartbeat interval set to ' . $this->conf( Base::O_MISC_HEARTBEAT_EDITOR_TTL ) );
137 }
138 } elseif ( ! is_admin() ) {
139 if ( $this->conf( Base::O_MISC_HEARTBEAT_FRONT ) ) {
140 $settings['interval'] = $this->conf( Base::O_MISC_HEARTBEAT_FRONT_TTL );
141 Debug2::debug( '[Tool] Heartbeat interval set to ' . $this->conf( Base::O_MISC_HEARTBEAT_FRONT_TTL ) );
142 }
143 } elseif ( $this->conf( Base::O_MISC_HEARTBEAT_BACK ) ) {
144 $settings['interval'] = $this->conf( Base::O_MISC_HEARTBEAT_BACK_TTL );
145 Debug2::debug( '[Tool] Heartbeat interval set to ' . $this->conf( Base::O_MISC_HEARTBEAT_BACK_TTL ) );
146 }
147 return $settings;
148 }
149
150 /**
151 * Check if in editor
152 *
153 * Determines if the current request is within the WordPress editor.
154 *
155 * @since 3.0
156 * @access public
157 * @return bool True if in editor, false otherwise.
158 */
159 public function is_editor() {
160 $request_uri = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
161 $res = is_admin() && Utility::str_hit_array( $request_uri, [ 'post.php', 'post-new.php' ] );
162
163 return apply_filters( 'litespeed_is_editor', $res );
164 }
165 }
166