* @param string $id Option ID.
protected function _conf_pswd( $id ) {
$check_ids = [ self::O_CDN_CLOUDFLARE_KEY, self::O_OBJECT_PSWD ];
return in_array( $id, $check_ids, true );
* If the setting is cron related or not.
* @param string $id Option ID.
protected function _conf_cron( $id ) {
$check_ids = [ self::O_OPTM_CSS_ASYNC, self::O_MEDIA_PLACEHOLDER_RESP_ASYNC, self::O_DISCUSS_AVATAR_CRON, self::O_IMG_OPTM_AUTO, self::O_CRAWLER ];
return in_array( $id, $check_ids, true );
* If the setting changes worth a purge, return the tag.
* @param string $id Option ID.
protected function _conf_purge_tag( $id ) {
self::O_CACHE_PAGE_LOGIN => Tag::TYPE_LOGIN,
if ( ! empty( $check_ids[ $id ] ) ) {
return $check_ids[ $id ];
* @return array<string,mixed> Map of constant name => value|null.
public function server_vars() {
foreach ( $consts as $v ) {
$server_vars[ $v ] = defined( $v ) ? constant( $v ) : null;
* Save CSS content (UCSS/CCSS) to file and register in DB.
* Shared by UCSS, CSS, and Optimax classes.
* @param string $type CSS type ('ucss' or 'ccss').
* @param string $css CSS content.
* @param string $url_tag URL tag for DB mapping.
* @param string $vary Vary string.
* @param string $queue_k Queue key (for filter and purge tag).
* @param bool $is_mobile Whether is mobile.
* @param bool $is_webp Whether supports webp.
protected function _save_css_con( $type, $css, $url_tag, $vary, $queue_k, $is_mobile, $is_webp ) {
$css = apply_filters( 'litespeed_' . $type, $css, $queue_k );
$css = $this->cls('Optimizer')->optm_font_face( $css );
// Sanitize: CSS must not contain HTML tags
$css = wp_strip_all_tags( $css );
self::debug2( 'con: ', $css );
if ( '/*' === substr( $css, 0, 2 ) && '*/' === substr( $css, -2 ) ) {
self::debug( '❌ empty ' . $type . ' [content] ' . $css );
$filecon_md5 = md5( $css );
$filepath_prefix = $this->_build_filepath_prefix( $type );
$static_file = LITESPEED_STATIC_DIR . $filepath_prefix . $filecon_md5 . '.css';
File::save( $static_file, $css, true );
self::debug2( "Save URL to file [file] $static_file [vary] $vary" );
$this->cls( 'Data' )->save_url( $url_tag, $vary, $type, $filecon_md5, dirname( $static_file ), $is_mobile, $is_webp );
Purge::add( strtoupper( $type ) . '.' . md5( $queue_k ) );