diff --git a/inc/helpers/aksrt-identity.php b/inc/helpers/aksrt-identity.php index 782215f7..c017fde7 100644 --- a/inc/helpers/aksrt-identity.php +++ b/inc/helpers/aksrt-identity.php @@ -229,6 +229,38 @@ if (!function_exists('aksrt_get_user_name')) { } } +if (!function_exists('aksrt_user_has_visible_badges')) { + /** + * Whether a user owns at least one badge that exists in the current catalog. + * + * Used by user-center surfaces to decide whether to show the "我的徽章" + * button. Prevents rendering a button that opens an empty modal when the + * badge dictionary has no entries or none of the user's badges match it. + * + * @param int $user_id Target user (0 = current user). + * @return bool + */ + function aksrt_user_has_visible_badges(int $user_id = 0): bool { + if ($user_id <= 0) { + $user_id = get_current_user_id(); + } + if ($user_id <= 0 || !class_exists('AKSRT\\User\\Badges')) { + return false; + } + $map = \AKSRT\User\Badges::get_dictionary_map(); + if (empty($map)) { + return false; + } + $owned = \AKSRT\User\Badges::get_owned($user_id); + foreach ((array) $owned as $slug) { + if (is_string($slug) && $slug !== '' && isset($map[$slug])) { + return true; + } + } + return false; + } +} + if (!function_exists('aksrt_get_worn_medal_icon')) { /** * Render the worn medal icon HTML for a user (standalone, zibll parity). diff --git a/inc/helpers/user-center-renderers/profile-header.php b/inc/helpers/user-center-renderers/profile-header.php index 8d999988..4244b536 100644 --- a/inc/helpers/user-center-renderers/profile-header.php +++ b/inc/helpers/user-center-renderers/profile-header.php @@ -86,17 +86,11 @@ extract($context, EXTR_SKIP); // phpcs:ignore WordPress.PHP.DontExtract.extract_
- - - - + + +