<?php
/**
* The tools
*
* @since 3.0
* @package LiteSpeed
*/
namespace LiteSpeed;
defined( 'WPINC' ) || exit();
/**
* Class Tool
*
* Provides utility functions for LiteSpeed Cache, including IP detection and heartbeat control.
*
* @since 3.0
*/
class Tool extends Root {
const LOG_TAG = '[Tool]';
/**
* Get public IP
*
* Retrieves the public IP address of the server.
*
* @since 3.0
* @access public
* @return string The public IP address or an error message.
*/
public function check_ip() {
self::debug( '✅ check_ip' );
$response = wp_safe_remote_get( 'https://cyberpanel.sh/?ip', [
'headers' => [
'User-Agent' => 'curl/8.7.1',
],
] );
if ( is_wp_error( $response ) ) {
return esc_html__( 'Failed to detect IP', 'litespeed-cache' );
}
$ip = trim( $response['body'] );
self::debug( 'result [ip] ' . $ip );
if ( Utility::valid_ipv4( $ip ) ) {
return $ip;
}
return esc_html__( 'Failed to detect IP', 'litespeed-cache' );
}
/**
* Heartbeat Control
*
* Configures WordPress heartbeat settings for frontend, backend, and editor.
*
* @since 3.0
* @access public
*/
public function heartbeat() {
add_action( 'wp_enqueue_scripts', [ $this, 'heartbeat_frontend' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'heartbeat_backend' ] );
add_filter( 'heartbeat_settings', [ $this, 'heartbeat_settings' ] );
}
/**
* Heartbeat Control frontend control
*
* Manages heartbeat settings for the frontend.
*
* @since 3.0
* @access public
*/
public function heartbeat_frontend() {
if ( ! $this->conf( Base::O_MISC_HEARTBEAT_FRONT ) ) {
return;
}
if ( ! $this->conf( Base::O_MISC_HEARTBEAT_FRONT_TTL ) ) {
wp_deregister_script( 'heartbeat' );
Debug2::debug( '[Tool] Deregistered frontend heartbeat' );
}
}
/**
* Heartbeat Control backend control
*
* Manages heartbeat settings for the backend and editor.
*
* @since 3.0
* @access public
*/
public function heartbeat_backend() {
if ( $this->is_editor() ) {
if ( ! $this->conf( Base::O_MISC_HEARTBEAT_EDITOR ) ) {
return;
}
if ( ! $this->conf( Base::O_MISC_HEARTBEAT_EDITOR_TTL ) ) {
wp_deregister_script( 'heartbeat' );
Debug2::debug( '[Tool] Deregistered editor heartbeat' );
}
} else {
if ( ! $this->conf( Base::O_MISC_HEARTBEAT_BACK ) ) {
return;
}
if ( ! $this->conf( Base::O_MISC_HEARTBEAT_BACK_TTL ) ) {
wp_deregister_script( 'heartbeat' );
Debug2::debug( '[Tool] Deregistered backend heartbeat' );
}
}
}
/**
* Heartbeat Control settings
*
* Adjusts heartbeat interval settings based on configuration.
*
* @since 3.0
* @access public
* @param array $settings Existing heartbeat settings.
* @return array Modified heartbeat settings.
*/
public function heartbeat_settings( $settings ) {
// Check editor first to make frontend editor valid too
if ( $this->is_editor() ) {
if ( $this->conf( Base::O_MISC_HEARTBEAT_EDITOR ) ) {
$settings['interval'] = $this->conf( Base::O_MISC_HEARTBEAT_EDITOR_TTL );
Debug2::debug( '[Tool] Heartbeat interval set to ' . $this->conf( Base::O_MISC_HEARTBEAT_EDITOR_TTL ) );
}
} elseif ( ! is_admin() ) {
if ( $this->conf( Base::O_MISC_HEARTBEAT_FRONT ) ) {
$settings['interval'] = $this->conf( Base::O_MISC_HEARTBEAT_FRONT_TTL );
Debug2::debug( '[Tool] Heartbeat interval set to ' . $this->conf( Base::O_MISC_HEARTBEAT_FRONT_TTL ) );
}
} elseif ( $this->conf( Base::O_MISC_HEARTBEAT_BACK ) ) {
$settings['interval'] = $this->conf( Base::O_MISC_HEARTBEAT_BACK_TTL );
Debug2::debug( '[Tool] Heartbeat interval set to ' . $this->conf( Base::O_MISC_HEARTBEAT_BACK_TTL ) );
}
return $settings;
}
/**
* Check if in editor
*
* Determines if the current request is within the WordPress editor.
*
* @since 3.0
* @access public
* @return bool True if in editor, false otherwise.
*/
public function is_editor() {
$request_uri = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
$res = is_admin() && Utility::str_hit_array( $request_uri, [ 'post.php', 'post-new.php' ] );
return apply_filters( 'litespeed_is_editor', $res );
}
}
| nama | waktu | ukuran | owner | perm | aksi |
|---|---|---|---|---|---|
| .. | |||||
| cdn/ | 2026-06-06 16:18 | 11.25 KB | 76129f60960:kunden | dxwrx-r--r | |
| data_structure/ | 2026-06-06 16:18 | 2.62 KB | 76129f60960:kunden | dxwrx-r--r | |
| activation.cls.php | 2026-06-06 16:18 | 17.31 KB | 76129f60960:kunden | -xw-x----- | |
| admin-display.cls.php | 2026-06-06 16:18 | 48.47 KB | 76129f60960:kunden | -xw-x----- | |
| admin-settings.cls.php | 2026-06-06 16:18 | 11.12 KB | 76129f60960:kunden | -xw-x----- | |
| admin.cls.php | 2026-06-06 16:18 | 6.13 KB | 76129f60960:kunden | -xw-x----- | |
| api.cls.php | 2026-06-06 16:18 | 10.36 KB | 76129f60960:kunden | -xw-x----- | |
| avatar.cls.php | 2026-06-06 16:18 | 8.65 KB | 76129f60960:kunden | -xw-x----- | |
| base.cls.php | 2026-06-06 16:18 | 37.66 KB | 76129f60960:kunden | -xw-x----- | |
| cdn.cls.php | 2026-06-06 16:18 | 15.92 KB | 76129f60960:kunden | -xw-x----- | |
| cloud-auth-callback.trait.php | 2026-06-06 16:18 | 10.43 KB | 76129f60960:kunden | -xw-x----- | |
| cloud-auth-ip.trait.php | 2026-06-06 16:18 | 4.33 KB | 76129f60960:kunden | -xw-x----- | |
| cloud-auth.trait.php | 2026-06-06 16:18 | 9.38 KB | 76129f60960:kunden | -xw-x----- | |
| cloud-misc.trait.php | 2026-06-06 16:18 | 10.32 KB | 76129f60960:kunden | -xw-x----- | |
| cloud-node.trait.php | 2026-06-06 16:18 | 5.95 KB | 76129f60960:kunden | -xw-x----- | |
| cloud-request.trait.php | 2026-06-06 16:18 | 19.68 KB | 76129f60960:kunden | -xw-x----- | |
| cloud.cls.php | 2026-06-06 16:18 | 7.32 KB | 76129f60960:kunden | -xw-x----- | |
| conf.cls.php | 2026-06-06 16:18 | 19.53 KB | 76129f60960:kunden | -xw-x----- | |
| control.cls.php | 2026-06-06 16:18 | 24.35 KB | 76129f60960:kunden | -xw-x----- | |
| core.cls.php | 2026-06-06 16:18 | 20.97 KB | 76129f60960:kunden | -xw-x----- | |
| crawler-map.cls.php | 2026-06-06 16:18 | 19.41 KB | 76129f60960:kunden | -xw-x----- | |
| crawler.cls.php | 2026-06-06 16:18 | 44.72 KB | 76129f60960:kunden | -xw-x----- | |
| css.cls.php | 2026-06-06 16:18 | 17.77 KB | 76129f60960:kunden | -xw-x----- | |
| data.cls.php | 2026-06-06 16:18 | 22.21 KB | 76129f60960:kunden | -xw-x----- | |
| data.upgrade.func.php | 2026-06-06 16:18 | 5.72 KB | 76129f60960:kunden | -xw-x----- | |
| db-optm.cls.php | 2026-06-06 16:18 | 15.35 KB | 76129f60960:kunden | -xw-x----- | |
| debug2.cls.php | 2026-06-06 16:18 | 18.4 KB | 76129f60960:kunden | -xw-x----- | |
| doc.cls.php | 2026-06-06 16:18 | 5.45 KB | 76129f60960:kunden | -xw-x----- | |
| error.cls.php | 2026-06-06 16:18 | 7.35 KB | 76129f60960:kunden | -xw-x----- | |
| esi.cls.php | 2026-06-06 16:18 | 27.18 KB | 76129f60960:kunden | -xw-x----- | |
| file.cls.php | 2026-06-06 16:18 | 10.57 KB | 76129f60960:kunden | -xw-x----- | |
| guest.cls.php | 2026-06-06 16:18 | 2.75 KB | 76129f60960:kunden | -xw-x----- | |
| gui.cls.php | 2026-06-06 16:18 | 36.57 KB | 76129f60960:kunden | -xw-x----- | |
| health.cls.php | 2026-06-06 16:18 | 2.83 KB | 76129f60960:kunden | -xw-x----- | |
| htaccess.cls.php | 2026-06-06 16:18 | 29.81 KB | 76129f60960:kunden | -xw-x----- | |
| img-optm-manage.trait.php | 2026-06-06 16:18 | 30.85 KB | 76129f60960:kunden | -xw-x----- | |
| img-optm-pull.trait.php | 2026-06-06 16:18 | 22.1 KB | 76129f60960:kunden | -xw-x----- | |
| img-optm-send.trait.php | 2026-06-06 16:18 | 21.9 KB | 76129f60960:kunden | -xw-x----- | |
| img-optm.cls.php | 2026-06-06 16:18 | 5.26 KB | 76129f60960:kunden | -xw-x----- | |
| import.cls.php | 2026-06-06 16:18 | 4.29 KB | 76129f60960:kunden | -xw-x----- | |
| import.preset.cls.php | 2026-06-06 16:18 | 5.5 KB | 76129f60960:kunden | -xw-x----- | |
| lang.cls.php | 2026-06-06 16:18 | 17.02 KB | 76129f60960:kunden | -xw-x----- | |
| localization.cls.php | 2026-06-06 16:18 | 4.03 KB | 76129f60960:kunden | -xw-x----- | |
| media.cls.php | 2026-06-06 16:18 | 44.08 KB | 76129f60960:kunden | -xw-x----- | |
| metabox.cls.php | 2026-06-06 16:18 | 5.29 KB | 76129f60960:kunden | -xw-x----- | |
| object-cache-wp.cls.php | 2026-06-06 16:18 | 18.82 KB | 76129f60960:kunden | -xw-x----- | |
| object-cache.cls.php | 2026-06-06 16:18 | 20.95 KB | 76129f60960:kunden | -xw-x----- | |
| object.lib.php | 2026-06-06 16:18 | 14.16 KB | 76129f60960:kunden | -xw-x----- | |
| optimize.cls.php | 2026-06-06 16:18 | 38.64 KB | 76129f60960:kunden | -xw-x----- | |
| optimizer.cls.php | 2026-06-06 16:18 | 10.5 KB | 76129f60960:kunden | -xw-x----- | |
| placeholder.cls.php | 2026-06-06 16:18 | 17.93 KB | 76129f60960:kunden | -xw-x----- | |
| purge.cls.php | 2026-06-06 16:18 | 34.41 KB | 76129f60960:kunden | -xw-x----- | |
| report.cls.php | 2026-06-06 16:18 | 6.12 KB | 76129f60960:kunden | -xw-x----- | |
| rest.cls.php | 2026-06-06 16:18 | 9.08 KB | 76129f60960:kunden | -xw-x----- | |
| root.cls.php | 2026-06-06 16:18 | 14.29 KB | 76129f60960:kunden | -xw-x----- | |
| router.cls.php | 2026-06-06 16:18 | 20.76 KB | 76129f60960:kunden | -xw-x----- | |
| str.cls.php | 2026-06-06 16:18 | 3.08 KB | 76129f60960:kunden | -xw-x----- | |
| tag.cls.php | 2026-06-06 16:18 | 9.26 KB | 76129f60960:kunden | -xw-x----- | |
| task.cls.php | 2026-06-06 16:18 | 7.05 KB | 76129f60960:kunden | -xw-x----- | |
| tool.cls.php | 2026-06-06 16:18 | 4.17 KB | 76129f60960:kunden | -xw-x----- | |
| ucss.cls.php | 2026-06-06 16:18 | 16.35 KB | 76129f60960:kunden | -xw-x----- | |
| utility.cls.php | 2026-06-06 16:18 | 26.01 KB | 76129f60960:kunden | -xw-x----- | |
| vary.cls.php | 2026-06-06 16:18 | 21.33 KB | 76129f60960:kunden | -xw-x----- | |
| vpi.cls.php | 2026-06-06 16:18 | 9.38 KB | 76129f60960:kunden | -xw-x----- | |