Skip to content

Commit c67f84d

Browse files
pmgarmantillkruss
andauthored
Add filter to allow customizing who can flush the cache (#535)
* Add filter and constant to allow customizing who can manage the plugin * Update CHANGELOG.md * Update README.md --------- Co-authored-by: Till Krüss <[email protected]>
1 parent 9dedfe3 commit c67f84d

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
- Fixed several issues with Predis and cluster/replicated connection
66
- Fixed rare fatal error in `show_error_and_die()` (one more time)
7+
- Add `redis_cache_manager_capability` filter
8+
- Add `WP_REDIS_MANAGER_CAPABILITY` constant
79

810
## 2.5.2
911

README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ The Redis Object Cache plugin comes with vast set of configuration options. If y
6464
| `WP_REDIS_DISABLE_BANNERS` | `false` | Disables promotional banners and notices |
6565
| `WP_REDIS_DISABLE_COMMENT` | `false` | Disables HTML source comment |
6666
| `WP_REDIS_SSL_CONTEXT` | `[]` | TLS connection options for `tls` or `rediss` scheme |
67+
| `WP_REDIS_MANAGER_CAPABILITY` | | The capability a user must have to manage the plugin |
6768

6869
</details>
6970

@@ -230,11 +231,12 @@ Redis Object Cache has various WP CLI commands, for more information run `wp hel
230231

231232
Redis Object Cache has various hooks and the commonly used ones are listed below.
232233

233-
| Filter / Action | Description |
234-
| --------------------------------------- | ------------------------------------------------- |
235-
| `redis_cache_expiration` | Filters the cache expiration for individual keys |
236-
| `redis_cache_validate_dropin` | Filters whether the drop-in is valid |
234+
| Filter / Action | Description |
235+
| --------------------------------------- | ----------- |
236+
| `redis_cache_expiration` | Filters the cache expiration for individual keys |
237+
| `redis_cache_validate_dropin` | Filters whether the drop-in is valid |
237238
| `redis_cache_add_non_persistent_groups` | Filters the groups to be marked as non persistent |
239+
| `redis_cache_manager_capability` | Filters the capability a user needs to manage the plugin |
238240

239241
## Footnotes
240242

includes/class-plugin.php

+13-1
Original file line numberDiff line numberDiff line change
@@ -1565,7 +1565,19 @@ public function obscure_url_secrets( $url ) {
15651565
* @return string
15661566
*/
15671567
public function manage_redis_capability() {
1568-
return is_multisite() ? 'manage_network_options' : 'manage_options';
1568+
if ( defined( 'WP_REDIS_MANAGER_CAPABILITY' ) && WP_REDIS_MANAGER_CAPABILITY ) {
1569+
return WP_REDIS_MANAGER_CAPABILITY;
1570+
}
1571+
1572+
$capability = is_multisite() ? 'manage_network_options' : 'manage_options';
1573+
1574+
/**
1575+
* Filters the capability used to determine if a user can manage Redis.
1576+
*
1577+
* @since 2.6.0
1578+
* @param string $capability The default capability to determine if the user can manage cache.
1579+
*/
1580+
return apply_filters( 'redis_cache_manager_capability', $capability );
15691581
}
15701582

15711583
/**

0 commit comments

Comments
 (0)