rhubarbgroup / redis-cache

A persistent object cache backend for WordPress powered by Redis. Supports Predis, PhpRedis, Relay, replication, sentinels, clustering and WP-CLI.
https://wordpress.org/plugins/redis-cache/
GNU General Public License v3.0
425 stars 148 forks source link

Bypass DISALLOW_FILE_MODS introduced in 2.5.0 #512

Closed Albvadi closed 5 months ago

Albvadi commented 5 months ago

Description

On my site I have the DISALLOW_FILE_MODS constant activated because I control file modifications through GIT. In this way, I am blocked from editing the theme files, installing / updating WordPress, plugins, themes, etc...

The problem is that with this constant configured, in the latest version of the plugin the error appears indicating that the file system is not writable as checked in https://github.com/rhubarbgroup/redis-cache/blob/b582fbad902fd11d4d035ed62b1cec144b52081c/includes/class-plugin.php#L1352-L1376

image

I don´t consider that writing the object-cache.php file to manage the cache should be prohibited even if the rest of the modifications to WordPress files are.

Expected Behavior

Can enable Redis cache with DISALLOW_FILE_MODS

Actual Behavior

Filesystem not writable error

Possible Fix

Not sure. Maybe create a new constant like WP_REDIS_SKIP_DISABLE_FILE_MODS or something like that. Or maybe use the actual WP_REDIS_DISABLE_DROPIN_CHECK to skip DISALLOW_FILE_MODS.

Steps to Reproduce

  1. Install new wordpress site and add the plugin
  2. Configure DISALLOW_FILE_MODS to true in wp-config.php
  3. Trye to enable plugin

Additional context

Environment

tillkruss commented 5 months ago

Right, when DISALLOW_FILE_MODS this doesn't need to be a red warning. We we just gray it out?

Because the "Enable Cache" button will be disabled regardless if DISALLOW_FILE_MODS is set.

Albvadi commented 5 months ago

Right, when DISALLOW_FILE_MODS this doesn't need to be a red warning. We we just gray it out?

Yes and no... You can have DISALLOW_FILE_MODS and at the same time (that was my case), have permissions problems in your server and the filesystem not be writeable too.

What I try to say it´s that are two totally different cases and should be treated that way.

For example, as I said, in my server I uploaded all files with my user and the server is running with apache user. I detected it becauses when I try to enable cache, It´s says the filesystem is not writable and I need a sysadmin to correcte the permissions.

And then, If I enable DISALLOW_FILE_MODS I can't enable cache it either becauses in the test writable filesystem is checking if the constant is defined, but it´s not a problem with the writability of the system.

I need any way to enable cache with DISALLOW_FILE_MODS, that's why I suggested adding a new constant that, when checking the system, can allow the cache to be activated even with DISALLOW_FILE_MODS defined, such as WP_REDIS_SKIP_DISABLE_FILE_MODS

And, sorry for my language, it's difficult to explain well when it's not your native language.

tillkruss commented 5 months ago

Thanks for the details!

If DISALLOW_FILE_MODS WordPress should not modify the filesystem and the only way to enable the object-cache.php drop-in is using the wp redis enable command. Or of course copying it by hand.

I think you're right. If DISALLOW_FILE_MODS the warning should not be so aggressive.

Albvadi commented 5 months ago

Thank you for your explanation. One last question.

If DISALLOW_FILE_MODS WordPress should not modify the filesystem and the only way to enable the object-cache.php drop-in is using the wp redis enable command. Or of course copying it by hand.

I believed that in order to activate the cache it was necessary to be able to write to the object-cache.php file and by not allowing writing with DISALLOW_FILE_MODS, it was not going to work.

So, can I activate the cache with the wp redis enable command and/or copying the file by hand and even if it is DISALLOW_FILE_MODS defined, will it still work? Because if that's the case and I can activate it from the console, for me it is the solution.

Thank you very much again.

tillkruss commented 5 months ago

Yep, that works!