Merge pull request 'fix(forum): relax cap_cache meta hook arg types' (#205) from fix/forum-cap-meta-hook-types into main
Reviewed-on: CYL/wordpress-theme-aksrt#205
This commit is contained in:
commit
1bfa92ac33
2 files changed
+13
-6
No files matched your search
@@ -887,15 +887,15 @@ class Forum {
|
|||||||
$this->permission_service()->cap_cache_on_login($user_login, $user);
|
$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);
|
$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);
|
$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);
|
$this->permission_service()->cap_cache_on_plate_save($post_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -386,7 +386,12 @@ class PermissionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Flush cache when plate moderator meta changes. */
|
/** 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)) {
|
if (in_array($meta_key, ['_aksrt_moderators', '_aksrt_moderator_roles'], true)) {
|
||||||
self::$cap_cache = [];
|
self::$cap_cache = [];
|
||||||
self::$tier_cache = [];
|
self::$tier_cache = [];
|
||||||
@@ -394,7 +399,8 @@ class PermissionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Flush cache when plate_cat moderator term meta changes. */
|
/** 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') {
|
if ($meta_key === 'moderator') {
|
||||||
self::$cap_cache = [];
|
self::$cap_cache = [];
|
||||||
self::$tier_cache = [];
|
self::$tier_cache = [];
|
||||||
@@ -402,7 +408,8 @@ class PermissionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Flush cache when a plate CPT post is saved (plate_author may change). */
|
/** 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) {
|
foreach (array_keys(self::$tier_cache) as $k) {
|
||||||
if (substr($k, -strlen(":$post_id")) === ":$post_id") {
|
if (substr($k, -strlen(":$post_id")) === ":$post_id") {
|
||||||
unset(self::$tier_cache[$k]);
|
unset(self::$tier_cache[$k]);
|
||||||
|
|||||||
Reference in new issue
Block a user