ClassicPress / ClassicPress-v1

A copy of ClassicPress v1.x.
1 stars 1 forks source link

WP_CACHE results in Warning #108

Closed bjornenio closed 4 years ago

bjornenio commented 4 years ago

Using the latest version with define( 'WP_CACHE', true ); in wp-config results in the following error: Warning: include(/wp-content/advanced-cache.php): failed to open stream: No such file or directory in /public_html/wp-settings.php on line 84

zulfgani commented 4 years ago

wp-settings.php is missing the && file_exists( WP_CONTENT_DIR . '/advanced-cache.php' ) check on line 82

ginsterbusch commented 4 years ago

@bjornenio To make this more understandable, start from original source, line 82 - the full snippet goes like this (1.1.2 is identicial to WP 4.9.13 in this case):

if ( WP_CACHE && apply_filters( 'enable_loading_advanced_cache_dropin', true ) ) {
    // For an advanced caching plugin to use. Uses a static drop-in because you would only want one.
    WP_DEBUG ? include( WP_CONTENT_DIR . '/advanced-cache.php' ) : @include( WP_CONTENT_DIR . '/advanced-cache.php' );

    // Re-initialize any hooks added manually by advanced-cache.php
    if ( $wp_filter ) {
        $wp_filter = WP_Hook::build_preinitialized_hooks( $wp_filter );
    }
}

So it states essentially if WP_CACHE (is true) AND the filter hook enable_loading_advanced_cache_dropin is true AS WELL, then it shoud look for the advanced-cache.php file in WP_CONTENT_DIR ..

So .. if this shows a warning, either WP_DEBUG is enabled, OR you're running PHP 8 (beta) already.

As advanced-cache.php is a drop-in replacement, the plugin (?) you're using failed to copy that into WP_CONTENT_DIR; one cause could be wrong file access permissions, including wrong OWNER (not just chmod 0755 or something similar).

cu, w0lf.

bjornenio commented 4 years ago

I understand that and I've changed the file now to include && file_exists( WP_CONTENT_DIR . '/advanced-cache.php' ) in the code. The warning goes away then.

Yes, I'm using wp_debug and wp_debug_display at all times to find errors. Using PHP 7.2 since later versions are not fully compatible with WP.

bjornenio commented 4 years ago

The reason for opening this "bug" was that I do not use a cache plugin, only define('WP_CACHE', true); in wp-config as I want the built in cache to work as intended.

I'm very new to Classic Press, so I don't know if there are things that do not work out of the box.

ginsterbusch commented 4 years ago

This is a bit off-topic, but: PHP 7.3 should be no issue at all. I'm currently in the finishing touches of a project with CP 1.1.2 as base, with quite a few common plugins (eg. ACF 5.8.8 Pro), with no issues whatsoever. If you need further help with that, just contact me directly my site ;)

bjornenio commented 4 years ago

I know, running 7.4.2 on my XAMPP local devs - but some things such as import of XML run into problems with later versions.

I was just surprised that WP_CACHE generated a problem.

zulfgani commented 4 years ago

Should define( 'WP_CACHE', true ); be generating the advanced-cache.php in the content folder? If not then how is the file generated if it's not present in the first place?

I've never used define( 'WP_CACHE', true ); so this is new to me. How was WP v4.9.x and by extension CP getting around it with out generating the error? Or was the error always there?

bjornenio commented 4 years ago

@zulfgani I do not know if adding it to wp-config should generate the file or not; meaning: I do not know what the intentions of CP are / were.

I use WP_CACHE when using WordPress without ever seeing an error or warning like this, which is what got me "confused".

I have not used any previous versions of CP and can therefore not say anything about if the error has always been there or not. I just discovered it and had to ask / raise a ticket.

zulfgani commented 4 years ago

I can confirm that the error is present in WP v4.9.x without the file_exists check in place so it's an inherited issue/bug.

nylen commented 4 years ago

define( 'WP_CACHE', true ); doesn't do anything by itself. You need an advanced caching drop-in in order to make this work: https://wordpress.org/support/article/editing-wp-config-php/#cache

This is a PHP file that you put in wp-content/advanced-cache.php. Usually it enables page caching or something related (not object caching like memcached, that is handled separately).

If you don't know what that is, then you should not set WP_CACHE. Many caching plugins will also manage both of these settings for you.

It seems like WP has included a change to avoid this warning in a 5.x release. In order to fix this we'd have to track down which changeset that was and then backport it.

I'm undecided on whether we should do this though. define( 'WP_CACHE', true ) without an advanced-cache.php file is actually an invalid configuration, and the current code looks like it will only provide this warning if WP_DEBUG is also enabled.

So this needs further investigation, and there is probably some relevant discussion on the WP ticket where this was changed (I haven't looked for it yet).

kktsvetkov commented 4 years ago

What about doing it in reverse ? E.g. set the value of WP_CACHE depending on whether advanced-cache.php exists, like this on line 82 in wp-settings.php

if (!defined('WP_CACHE'))
{
    define( 'WP_CACHE', file_exists( WP_CONTENT_DIR . '/advanced-cache.php' ) );
}
ginsterbusch commented 4 years ago

Because that line 82 in wp-settings.php reads quite differently, and that is not without reason:

if ( WP_CACHE && apply_filters( 'enable_loading_advanced_cache_dropin', true ) ) {
    // For an advanced caching plugin to use. Uses a static drop-in because you would only want one.
    WP_DEBUG ? include( WP_CONTENT_DIR . '/advanced-cache.php' ) : @include( WP_CONTENT_DIR . '/advanced-cache.php' );

    // Re-initialize any hooks added manually by advanced-cache.php
    if ( $wp_filter ) {
        $wp_filter = WP_Hook::build_preinitialized_hooks( $wp_filter );
    }
}

What it says here is: advanced-cache is ONLY enabled if BOTH WP_CACHE AND the filter enable_loading_advanced_cache_dropin return true. But out of some reason you DO NOT WANT THAT, eg. because you've already got a different caching solution running (ie. server-side), this leaves you still the option to auto-disable the drop-in replacement.

An auto-load like the one above WONT allow for this anymore. And as there are quite a big number of caching solutions, a few of them not just simple PHP scripts, I wouldn't dare breaking the current functionality. Yes, this would probably be a BREAKING change.

cu, w0lf.

nylen commented 4 years ago

And as there are quite a big number of caching solutions, a few of them not just simple PHP scripts, I wouldn't dare breaking the current functionality. Yes, this would probably be a BREAKING change.

This is correct.

ClassyBot commented 4 years ago

This issue has been mentioned on ClassicPress Forums. There might be relevant details there:

https://forums.classicpress.net/t/classicpress-1-2-0-rc1-release-notes/2479/23

nylen commented 4 years ago

define( 'WP_CACHE', true ); doesn't do anything by itself. You need an advanced caching drop-in in order to make this work: https://wordpress.org/support/article/editing-wp-config-php/#cache

define( 'WP_CACHE', true ) without an advanced-cache.php file is actually an invalid configuration

Closing because receiving a warning in this case is more correct behavior.