Skip to content

Commit 862b5e2

Browse files
authored
Boost: Fix sometimes not correctly adding WP_CACHE to wp-config.php (#35632)
* Make adding WP_CACHE constant to wp-config.php more resilient * Add changelog
1 parent 7607faa commit 862b5e2

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

projects/plugins/boost/app/modules/cache/Page_Cache_Setup.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private static function create_advanced_cache() {
9191
*/
9292
private static function add_wp_cache_define() {
9393
$content = file_get_contents( ABSPATH . 'wp-config.php' );
94-
if ( preg_match( '#define\s*\(\s*[\'"]WP_CACHE[\'"]#', $content ) === 1 ) {
94+
if ( preg_match( '#^\s*define\s*\(\s*[\'"]WP_CACHE[\'"]#m', $content ) === 1 ) {
9595
/*
9696
* wp-settings.php checks "if ( WP_CACHE )" so it may be truthy and
9797
* not === true to pass that check.
@@ -105,8 +105,8 @@ private static function add_wp_cache_define() {
105105

106106
return true; // WP_CACHE already added.
107107
}
108-
$content = str_replace(
109-
'<?php',
108+
$content = preg_replace(
109+
'#^<\?php#',
110110
'<?php
111111
define( \'WP_CACHE\', true );',
112112
$content
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Significance: patch
2+
Type: fixed
3+
Comment: Fix not adding WP_CACHE to wp-config.php in some cases.
4+
5+

0 commit comments

Comments
 (0)