fix(badges): hide "我的徽章" button until user has visible badges

profile-header.php was rendering two badge buttons ("我的徽章"
opening the local modal and "徽章弹层" opening a remote modal).
Drop the remote one and gate the local one behind the new
aksrt_user_has_visible_badges() helper, which only returns true
when the user actually has at least one badge entry that exists
in the active catalog dictionary — preventing a useless empty
modal when nothing can be shown.
This commit is contained in:
kate522 committed 2026-08-04 10:51:20 +08:00
1 parent e991f1a0c6
commit 3a33f7cd7f
2 files changed
+37 -11

No files matched your search

+32
View File
@@ -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).