Skip to content

W3TC should check if WP_CACHE is already defined before adding PHP code defining it. #1099

@ckeeney

Description

@ckeeney

I am using roots.io Bedrock, which refactors the WP config and folder structure quite a bit. W3TC adds code to the top of wp-config.php, and that is not where my configuration is stored:

<?php
/** Enable W3 Total Cache */
define('WP_CACHE', true); // Added by W3 Total Cache

/**
 * Do not edit this file. Edit the config files found in the config/ dir instead.
 * This file is required in the root directory so WordPress can find it.
 * WP is hardcoded to look in its own directory or one directory up for wp-config.php.
 */
require_once dirname(__DIR__) . '/vendor/autoload.php';
require_once dirname(__DIR__) . '/config/application.php';
require_once ABSPATH . 'wp-settings.php';

I moved the constant to application.php, but W3TC re-adds the code to wp-config.php without realizing the constant is already defined. This results in a PHP error for redefining a constant.

PHP Fatal error:  Uncaught Roots\\WPConfig\\Exceptions\\ConstantAlreadyDefinedException: Aborted trying to redefine constant 'WP_CACHE'. `define('WP_CACHE', ...)` has already been occurred elsewhere. 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions