Skip to content

Commit df87cc2

Browse files
committed
respect DISALLOW_FILE_MODS
1 parent d3dcfdb commit df87cc2

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Load text-domain on-demand
77
- Call `redis_object_cache_error` action before `wp_die()`
88
- Don't try to define `WP_REDIS_PLUGIN_PATH` twice
9+
- Respect `file_mod_allowed` filter and `DISALLOW_FILE_MODS` constant
910
- Renamed `.redis-write-test.tmp` test file to `object-cache.tmp`
1011

1112
## 2.4.4

includes/class-plugin.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,6 +1361,19 @@ public function initialize_filesystem( $url, $silent = false ) {
13611361
return true;
13621362
}
13631363

1364+
/**
1365+
* Determines whether object cache file modifications are allowed.
1366+
*
1367+
* @return bool
1368+
*/
1369+
function is_file_mod_allowed() {
1370+
return apply_filters(
1371+
'file_mod_allowed',
1372+
! defined( 'DISALLOW_FILE_MODS' ) || ! DISALLOW_FILE_MODS,
1373+
'object_cache_dropin'
1374+
);
1375+
}
1376+
13641377
/**
13651378
* Test if we can write in the WP_CONTENT_DIR and modify the `object-cache.php` drop-in
13661379
*
@@ -1370,6 +1383,10 @@ public function test_filesystem_writing() {
13701383
/** @var \WP_Filesystem_Base $wp_filesystem */
13711384
global $wp_filesystem;
13721385

1386+
if ( ! $this->is_file_mod_allowed() ) {
1387+
return new WP_Error( 'disallowed', __( 'File modifications are not allowed.', 'redis-cache' ) );
1388+
}
1389+
13731390
if ( ! $this->initialize_filesystem( '', true ) ) {
13741391
return new WP_Error( 'fs', __( 'Could not initialize filesystem.', 'redis-cache' ) );
13751392
}

0 commit comments

Comments
 (0)