WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Bug: wp_cache_check_global_config() can execute even if WP_CACHE is true (3 posts)

  1. joelhardi
    Member
    Posted 5 years ago #

    The function wp_cache_check_global_config() executes every time you load the settings pane for WP Super Cache (version 0.8.3).

    It uses a (rather simplistic) regex to check whether WP_CACHE is defined to TRUE in wp-config.php. It then silently attempts to append "define('WP_CACHE', true);" to wp-config.php or prints an error message and blocks access to the settings pane if it is unable to do this.

    The problem is that it does not check whether WP_CACHE actually *is* TRUE before it does this. So, unnecessary processing and potentially destructive writes to wp-config.php result if WP_CACHE is defined somewhere else or syntax doesn't match the (far from perfect) regex.

    The following simple patch has it exit and return TRUE when WP_CACHE is already TRUE. It also slightly improves the regex to permit TRUE, 1 and not just the lowercase true (true is just an alias of 1) and allow indent characters other than space (like tab).

    --- wp-super-cache/wp-cache.php 2008-10-08 17:22:04.000000000 -0700
    +++ wp-super-cache-FIXED/wp-cache.php 2008-10-19 11:18:23.000000000 -0700
    @@ -938,6 +938,8 @@
    }

    function wp_cache_check_global_config() {
    + if (WP_CACHE)
    + return true;

    if ( file_exists( ABSPATH . 'wp-config.php') ) {
    $global = ABSPATH . 'wp-config.php';
    @@ -947,7 +949,7 @@

    $lines = file($global);
    foreach($lines as $line) {
    - if (preg_match('/^ *define *\( *\'WP_CACHE\' *, *true *\) *;/', $line)) {
    + if (preg_match('/^\s*define\s*\(\s*\'WP_CACHE\'\s*,\s*(?i:TRUE|1)\s*\)\s*;/', $line)) {
    return true;
    }
    }

  2. Donncha O Caoimh
    Member
    Posted 5 years ago #

    Thanks Joel, just checked this into trunk!

    Donncha

  3. joelhardi
    Member
    Posted 5 years ago #

    Awesome, thanks! I will mark resolved.

Topic Closed

This topic has been closed to new replies.

About this Topic