From 3a33f7cd7f80772a28dcfa7e1d81369ad028cc69 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 4 Aug 2026 10:51:20 +0800 Subject: [PATCH] =?UTF-8?q?fix(badges):=20hide=20"=E6=88=91=E7=9A=84?= =?UTF-8?q?=E5=BE=BD=E7=AB=A0"=20button=20until=20user=20has=20visible=20b?= =?UTF-8?q?adges?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- inc/helpers/aksrt-identity.php | 32 +++++++++++++++++++ .../user-center-renderers/profile-header.php | 16 +++------- 2 files changed, 37 insertions(+), 11 deletions(-) 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_
- - - - + + +