# xspeed/1.1.8/includes/wp-cache-constant.php

xSpeed Cache: AI-Powered Performance Hub with MCP, Caching &amp; CDN, version 1.1.8. 63 lines.

- Page: https://pluginprobe.com/plugins/xspeed/1.1.8/code/includes/wp-cache-constant.php
- Raw: https://pluginprobe.com/plugins/xspeed/1.1.8/raw/includes/wp-cache-constant.php
- Modified: 2026-08-13T15:55:04+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/xspeed/1.1.8/code/includes/wp-cache-constant.php#L10-L20`.

```php
<?php
/**
 * The WP_CACHE define, and how to strip it out of wp-config.php.
 *
 * Deliberately a plain function in its own file rather than a method on
 * Cache: `uninstall.php` runs standalone — WordPress loads it without
 * bootstrapping the plugin, so no class of ours exists there. Keeping the
 * pattern in one requirable file is what stops the two call sites drifting.
 * They already had, which is the bug this fixes: the removal regex was
 * copy-pasted, and hardening one copy would have left the other broken.
 *
 * @package XSpeed
 */

defined( 'ABSPATH' ) || exit;

if ( ! function_exists( 'xspeed_strip_wp_cache_define' ) ) {
	/**
	 * Remove every `define( 'WP_CACHE', … );` statement from wp-config source.
	 *
	 * The old pattern hardcoded a lowercase `true` with no `/i`, so
	 * `TRUE`, `True`, `1`, `'1'` and `"1"` never matched — disabling the
	 * cache (or uninstalling) silently left the constant behind. Those
	 * spellings are common: several hosts' one-click stacks and older
	 * tutorials write `TRUE` or `1`, and any plugin that previously owned
	 * the constant may have written it in its own style. The orphan then
	 * confuses the next caching plugin the site installs — W3 Total Cache
	 * and WP Rocket both branch on it — and makes a "clean uninstall" not
	 * clean. (#9)
	 *
	 * Matches the VALUE as `[^)]*`, the same shape the enable branch in
	 * Cache::set_wp_cache_constant() already uses, so any spelling goes:
	 * true / TRUE / 1 / '1' / false / 0, with or without inner spaces.
	 * `false` is removed too — leaving `define( 'WP_CACHE', false );`
	 * behind is the same orphan problem, just quieter.
	 *
	 * Only our own statement shape is targeted. A commented-out line keeps
	 * its `#`/`//` prefix and is left alone by the leading-boundary match;
	 * a define built dynamically (concatenation, a variable) is not a
	 * literal statement and is out of scope for a regex — those are
	 * vanishingly rare in wp-config.php and unsafe to rewrite blind.
	 *
	 * @param string $config Raw wp-config.php contents.
	 * @return string Contents with the define(s) removed.
	 */
	function xspeed_strip_wp_cache_define( $config ) {
		if ( ! is_string( $config ) || '' === $config ) {
			return $config;
		}

		$stripped = preg_replace(
			'/^[ \t]*define\(\s*[\'"]WP_CACHE[\'"]\s*,\s*[^)]*\)\s*;[ \t]*\r?\n?/mi',
			'',
			$config
		);

		// preg_replace() returns null on failure (catastrophic backtracking,
		// bad UTF-8). Returning that would blank wp-config.php — hand back
		// the untouched source instead and leave the constant in place.
		return is_string( $stripped ) ? $stripped : $config;
	}
}

```
