Skip to content

Commit

Permalink
respect DISALLOW_FILE_MODS
Browse files Browse the repository at this point in the history
  • Loading branch information
tillkruss committed Nov 5, 2023
1 parent d3dcfdb commit df87cc2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Load text-domain on-demand
- Call `redis_object_cache_error` action before `wp_die()`
- Don't try to define `WP_REDIS_PLUGIN_PATH` twice
- Respect `file_mod_allowed` filter and `DISALLOW_FILE_MODS` constant
- Renamed `.redis-write-test.tmp` test file to `object-cache.tmp`

## 2.4.4
Expand Down
17 changes: 17 additions & 0 deletions includes/class-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1361,6 +1361,19 @@ public function initialize_filesystem( $url, $silent = false ) {
return true;
}

/**
* Determines whether object cache file modifications are allowed.
*
* @return bool
*/
function is_file_mod_allowed() {
return apply_filters(
'file_mod_allowed',
! defined( 'DISALLOW_FILE_MODS' ) || ! DISALLOW_FILE_MODS,
'object_cache_dropin'
);
}

/**
* Test if we can write in the WP_CONTENT_DIR and modify the `object-cache.php` drop-in
*
Expand All @@ -1370,6 +1383,10 @@ public function test_filesystem_writing() {
/** @var \WP_Filesystem_Base $wp_filesystem */
global $wp_filesystem;

if ( ! $this->is_file_mod_allowed() ) {
return new WP_Error( 'disallowed', __( 'File modifications are not allowed.', 'redis-cache' ) );
}

if ( ! $this->initialize_filesystem( '', true ) ) {
return new WP_Error( 'fs', __( 'Could not initialize filesystem.', 'redis-cache' ) );
}
Expand Down

0 comments on commit df87cc2

Please sign in to comment.