Skip to content

Commit

Permalink
Update add_non_persistent_groups()
Browse files Browse the repository at this point in the history
Don't allow groups that were manually removed using `WP_REDIS_IGNORED_GROUPS` constant to be added to the ignored groups list.

* FIxes rhubarbgroup#114
* Fixes rhubarbgroup#74
* Ref: https://core.trac.wordpress.org/ticket/47884#ticket
  • Loading branch information
lots0logs authored Apr 4, 2022
1 parent 25669bd commit affbd77
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion includes/object-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -2417,7 +2417,21 @@ public function add_global_groups( $groups ) {
* @param array $groups List of groups that are to be ignored.
*/
public function add_non_persistent_groups( $groups ) {
$groups = (array) $groups;
$groups = (array) $groups;
$default_groups = [ 'counts', 'plugins', 'themes' ];

static $groups_override = null;
static $removed_default_groups = null;

if ( is_null( $groups_override ) && defined( 'WP_REDIS_IGNORED_GROUPS' ) && is_array( WP_REDIS_IGNORED_GROUPS ) ) {
$groups_override = array_map( [ $this, 'sanitize_key_part' ], WP_REDIS_IGNORED_GROUPS );
$removed_default_groups = array_diff( $default_groups, $groups_override );
}

if ( $removed_default_groups && array_intersect( $groups, $removed_default_groups ) ) {
// Don't allow default groups that were manually removed via WP_REDIS_IGNORED_GROUPS constant to be readded.
return;
}

$this->ignored_groups = array_unique( array_merge( $this->ignored_groups, $groups ) );
}
Expand Down

0 comments on commit affbd77

Please sign in to comment.