Skip to content

Commit

Permalink
Add filter to allow customizing who can flush the cache (#535)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
pmgarman and tillkruss committed Oct 15, 2024
1 parent 1816d87 commit b6ef5a8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

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

## 2.5.2

Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ The Redis Object Cache plugin comes with vast set of configuration options. If y
| `WP_REDIS_DISABLE_BANNERS` | `false` | Disables promotional banners and notices |
| `WP_REDIS_DISABLE_COMMENT` | `false` | Disables HTML source comment |
| `WP_REDIS_SSL_CONTEXT` | `[]` | TLS connection options for `tls` or `rediss` scheme |
| `WP_REDIS_MANAGER_CAPABILITY` | | The capability a user must have to manage the plugin |

</details>

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

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

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

## Footnotes

Expand Down
14 changes: 13 additions & 1 deletion includes/class-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1565,7 +1565,19 @@ public function obscure_url_secrets( $url ) {
* @return string
*/
public function manage_redis_capability() {
return is_multisite() ? 'manage_network_options' : 'manage_options';
if ( defined( 'WP_REDIS_MANAGER_CAPABILITY' ) && WP_REDIS_MANAGER_CAPABILITY ) {
return WP_REDIS_MANAGER_CAPABILITY;
}

$capability = is_multisite() ? 'manage_network_options' : 'manage_options';

/**
* Filters the capability used to determine if a user can manage Redis.
*
* @since 2.6.0
* @param string $capability The default capability to determine if the user can manage cache.
*/
return apply_filters( 'redis_cache_manager_capability', $capability );
}

/**
Expand Down

0 comments on commit b6ef5a8

Please sign in to comment.