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

Add filter to allow customizing who can flush the cache #535

Closed pmgarman closed 1 month ago

pmgarman commented 3 months ago

Couldn't find a CONTRIBUTING.md (i may be blind) so took a best guess. Also just assumed 2.6 but who knows?!

I think this could easily be a thing that gets enhanced deeper for multisite to allow individual site owners to flush their individual sites cache or something along those lines... but this probably serves my needs well enough :D

pmgarman commented 3 months ago

This was the code i used to test that this worked for the author role:

add_filter( 'roc_manage_redis_capability', function( $cap ) {
    return 'publish_posts';
});
pmgarman commented 3 months ago

Resolved conflict in changelog

tillkruss commented 2 months ago

Should we also make this a constant for easier access?

pmgarman commented 2 months ago

You would only be able to define your default as a constant though right? Since the constant can't change after being filtered?

tillkruss commented 2 months ago

You would only be able to define your default as a constant though right? Since the constant can't change after being filtered?

Yeah, it would be set once in the wp-config.php and should be opt-in, not used by default.

pmgarman commented 2 months ago

Oh I see what you mean, inverse of what I was thinking. It's monday...

I could see that being handy too yeah. I can update my PR and fix those codestyle complaints.

Any preference on your constant name?

pmgarman commented 2 months ago

Nevermind those errors are yours :P enjoy!

pmgarman commented 2 months ago

Opted for WP_REDIS_MANAGER_CAPABILITY until @tillkruss says otherwise :)

pmgarman commented 1 month ago

@tillkruss try this on for size