From 7dbbb2cddaa14729af4944061d66962e126a82b6 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 29 Jul 2026 12:46:44 +0800 Subject: [PATCH] fix(identity): show certification in user admin --- src/AKSRT/Admin/Native/UsersMenusVerify.php | 4 +- src/AKSRT/User/AuthApply.php | 81 +++++++++++++++++++++ 2 files changed, 83 insertions(+), 2 deletions(-) diff --git a/src/AKSRT/Admin/Native/UsersMenusVerify.php b/src/AKSRT/Admin/Native/UsersMenusVerify.php index 67cbd88f..4fad04e0 100644 --- a/src/AKSRT/Admin/Native/UsersMenusVerify.php +++ b/src/AKSRT/Admin/Native/UsersMenusVerify.php @@ -100,8 +100,8 @@ trait UsersMenusVerify { } if ($filters['keyword'] !== '') { $like = '%' . $wpdb->esc_like($filters['keyword']) . '%'; - $where[] = '(u.display_name LIKE %s OR u.user_login LIKE %s OR u.user_email LIKE %s OR apply.meta_value LIKE %s)'; - array_push($params, $like, $like, $like, $like); + $where[] = '(CAST(u.ID AS CHAR) LIKE %s OR u.display_name LIKE %s OR u.user_login LIKE %s OR u.user_email LIKE %s OR apply.meta_value LIKE %s)'; + array_push($params, $like, $like, $like, $like, $like); } if ($filters['date_from'] !== '') { $where[] = 'COALESCE(requested_at.meta_value, u.user_registered) >= %s'; diff --git a/src/AKSRT/User/AuthApply.php b/src/AKSRT/User/AuthApply.php index 40869395..ff8be3e1 100644 --- a/src/AKSRT/User/AuthApply.php +++ b/src/AKSRT/User/AuthApply.php @@ -32,6 +32,12 @@ class AuthApply { public function init(): void { add_action('wp_ajax_aksrt_user_auth_apply', [$this, 'ajax_apply']); add_action('admin_post_aksrt_verify_evidence', [$this, 'serve_evidence']); + if (is_admin()) { + add_filter('manage_users_columns', [$this, 'add_admin_user_column']); + add_filter('manage_users_custom_column', [$this, 'render_admin_user_column'], 10, 3); + add_action('show_user_profile', [$this, 'render_admin_profile_status']); + add_action('edit_user_profile', [$this, 'render_admin_profile_status']); + } } /** @@ -90,6 +96,81 @@ class AuthApply { return self::get_status($user_id) === 'verified'; } + public function add_admin_user_column(array $columns): array { + $columns['aksrt_identity_status'] = __('身份认证', 'aksrt'); + return $columns; + } + + public function render_admin_user_column(string $output, string $column_name, int $user_id): string { + if ($column_name !== 'aksrt_identity_status') { + return $output; + } + $status = self::get_status($user_id); + $labels = self::admin_status_labels(); + if ($status === '' || !isset($labels[$status])) { + return '' . esc_html__('未认证', 'aksrt') . ''; + } + $colors = ['pending' => '#996800', 'verified' => '#008a20', 'rejected' => '#b32d2e', 'cancelled' => '#646970']; + $html = '' . esc_html($labels[$status]) . ''; + $info = self::get_auth_info($user_id); + if ($status === 'verified' && !empty($info['name'])) { + $html .= '
' . esc_html((string) $info['name']) . '
'; + } + if ($status === 'pending') { + $html .= '
' . esc_html__('查看申请', 'aksrt') . '
'; + } + return $html; + } + + public function render_admin_profile_status(\WP_User $user): void { + $status = self::get_status((int) $user->ID); + $labels = self::admin_status_labels(); + $apply = self::get_apply_payload((int) $user->ID); + $info = self::get_auth_info((int) $user->ID); + $reason = (string) get_user_meta((int) $user->ID, self::REASON_META, true); + $reviewed_at = (string) get_user_meta((int) $user->ID, self::REVIEWED_AT_META, true); + $reviewer_id = (int) get_user_meta((int) $user->ID, self::REVIEWER_META, true); + $reviewer = $reviewer_id > 0 ? get_userdata($reviewer_id) : null; + $display = $status !== '' && isset($labels[$status]) ? $labels[$status] : __('未认证', 'aksrt'); + $identity_name = (string) ($info['name'] ?? $apply['name'] ?? ''); + ?> +

+ + + + + + + + + + + + + + + + */ + private static function admin_status_labels(): array { + return [ + 'pending' => __('待审核', 'aksrt'), + 'verified' => __('已认证', 'aksrt'), + 'rejected' => __('已驳回', 'aksrt'), + 'cancelled' => __('已取消', 'aksrt'), + ]; + } + /** @return array */ public static function get_auth_info(int $user_id): array { $info = get_user_meta($user_id, self::INFO_META, true);