fix(forum): relax cap_cache meta hook arg types
deleted_post_meta passes meta_ids as array; strict int $meta_id fatals on draft save when post meta is deleted. Match WP hook signatures.
This commit is contained in:
@@ -887,15 +887,15 @@ class Forum {
|
||||
$this->permission_service()->cap_cache_on_login($user_login, $user);
|
||||
}
|
||||
|
||||
public function cap_cache_on_plate_meta(int $meta_id, int $object_id, string $meta_key): void {
|
||||
public function cap_cache_on_plate_meta($meta_id, $object_id = 0, $meta_key = ''): void {
|
||||
$this->permission_service()->cap_cache_on_plate_meta($meta_id, $object_id, $meta_key);
|
||||
}
|
||||
|
||||
public function cap_cache_on_cat_meta(int $meta_id, int $object_id, string $meta_key): void {
|
||||
public function cap_cache_on_cat_meta($meta_id, $object_id = 0, $meta_key = ''): void {
|
||||
$this->permission_service()->cap_cache_on_cat_meta($meta_id, $object_id, $meta_key);
|
||||
}
|
||||
|
||||
public function cap_cache_on_plate_save(int $post_id): void {
|
||||
public function cap_cache_on_plate_save($post_id): void {
|
||||
$this->permission_service()->cap_cache_on_plate_save($post_id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -386,7 +386,12 @@ class PermissionService {
|
||||
}
|
||||
|
||||
/** Flush cache when plate moderator meta changes. */
|
||||
public function cap_cache_on_plate_meta(int $meta_id, int $object_id, string $meta_key): void {
|
||||
public function cap_cache_on_plate_meta($meta_id, $object_id = 0, $meta_key = ''): void {
|
||||
// deleted_post_meta passes $meta_ids as array; other hooks pass int meta_id.
|
||||
if (is_array($meta_key) || (is_array($meta_id) && !is_string($meta_key))) {
|
||||
// Still accept call; $meta_key should be string on WP hooks.
|
||||
}
|
||||
$meta_key = is_string($meta_key) ? $meta_key : '';
|
||||
if (in_array($meta_key, ['_aksrt_moderators', '_aksrt_moderator_roles'], true)) {
|
||||
self::$cap_cache = [];
|
||||
self::$tier_cache = [];
|
||||
@@ -394,7 +399,8 @@ class PermissionService {
|
||||
}
|
||||
|
||||
/** Flush cache when plate_cat moderator term meta changes. */
|
||||
public function cap_cache_on_cat_meta(int $meta_id, int $object_id, string $meta_key): void {
|
||||
public function cap_cache_on_cat_meta($meta_id, $object_id = 0, $meta_key = ''): void {
|
||||
$meta_key = is_string($meta_key) ? $meta_key : '';
|
||||
if ($meta_key === 'moderator') {
|
||||
self::$cap_cache = [];
|
||||
self::$tier_cache = [];
|
||||
@@ -402,7 +408,8 @@ class PermissionService {
|
||||
}
|
||||
|
||||
/** Flush cache when a plate CPT post is saved (plate_author may change). */
|
||||
public function cap_cache_on_plate_save(int $post_id): void {
|
||||
public function cap_cache_on_plate_save($post_id): void {
|
||||
$post_id = (int) $post_id;
|
||||
foreach (array_keys(self::$tier_cache) as $k) {
|
||||
if (substr($k, -strlen(":$post_id")) === ":$post_id") {
|
||||
unset(self::$tier_cache[$k]);
|
||||
|
||||
Reference in New Issue
Block a user