fix(identity): show certification in user admin
This commit is contained in:
@@ -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';
|
||||
|
||||
@@ -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 '<span style="color:#646970;">' . esc_html__('未认证', 'aksrt') . '</span>';
|
||||
}
|
||||
$colors = ['pending' => '#996800', 'verified' => '#008a20', 'rejected' => '#b32d2e', 'cancelled' => '#646970'];
|
||||
$html = '<span style="display:inline-block;padding:2px 8px;border:1px solid currentColor;border-radius:999px;color:'
|
||||
. esc_attr($colors[$status] ?? '#646970') . '">' . esc_html($labels[$status]) . '</span>';
|
||||
$info = self::get_auth_info($user_id);
|
||||
if ($status === 'verified' && !empty($info['name'])) {
|
||||
$html .= '<div class="description">' . esc_html((string) $info['name']) . '</div>';
|
||||
}
|
||||
if ($status === 'pending') {
|
||||
$html .= '<div><a href="' . esc_url(admin_url('users.php?page=aksrt_user_auth&status=pending&keyword=' . $user_id)) . '">' . esc_html__('查看申请', 'aksrt') . '</a></div>';
|
||||
}
|
||||
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'] ?? '');
|
||||
?>
|
||||
<h2><?php esc_html_e('身份认证(AKSRT)', 'aksrt'); ?></h2>
|
||||
<table class="form-table" role="presentation">
|
||||
<tr>
|
||||
<th><?php esc_html_e('认证状态', 'aksrt'); ?></th>
|
||||
<td>
|
||||
<strong><?php echo esc_html($display); ?></strong>
|
||||
<?php if ($status === 'pending') : ?>
|
||||
<a class="button button-small" href="<?php echo esc_url(admin_url('users.php?page=aksrt_user_auth&status=pending&keyword=' . (int) $user->ID)); ?>"><?php esc_html_e('前往审核', 'aksrt'); ?></a>
|
||||
<?php elseif ($status === 'verified') : ?>
|
||||
<a class="button button-small" href="<?php echo esc_url(admin_url('users.php?page=aksrt_user_auth&status=verified&keyword=' . (int) $user->ID)); ?>"><?php esc_html_e('查看并管理认证', 'aksrt'); ?></a>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php if ($identity_name !== '') : ?>
|
||||
<tr><th><?php esc_html_e('认证身份', 'aksrt'); ?></th><td><?php echo esc_html($identity_name); ?></td></tr>
|
||||
<?php endif; ?>
|
||||
<?php if ($reviewed_at !== '') : ?>
|
||||
<tr><th><?php esc_html_e('最近处理', 'aksrt'); ?></th><td><?php echo esc_html($reviewed_at); ?><?php if ($reviewer) : ?> · <?php echo esc_html($reviewer->display_name); ?><?php endif; ?></td></tr>
|
||||
<?php endif; ?>
|
||||
<?php if ($reason !== '') : ?>
|
||||
<tr><th><?php esc_html_e('审核说明', 'aksrt'); ?></th><td><?php echo nl2br(esc_html($reason)); ?></td></tr>
|
||||
<?php endif; ?>
|
||||
</table>
|
||||
<?php
|
||||
}
|
||||
|
||||
/** @return array<string,string> */
|
||||
private static function admin_status_labels(): array {
|
||||
return [
|
||||
'pending' => __('待审核', 'aksrt'),
|
||||
'verified' => __('已认证', 'aksrt'),
|
||||
'rejected' => __('已驳回', 'aksrt'),
|
||||
'cancelled' => __('已取消', 'aksrt'),
|
||||
];
|
||||
}
|
||||
|
||||
/** @return array<string,mixed> */
|
||||
public static function get_auth_info(int $user_id): array {
|
||||
$info = get_user_meta($user_id, self::INFO_META, true);
|
||||
|
||||
Reference in New Issue
Block a user