更多资料新增元信息
This commit is contained in:
+49
-15
@@ -124,23 +124,11 @@ class Home {
|
||||
$signals = [];
|
||||
|
||||
if (!empty($settings['verify']['enabled']) && !empty($settings['verify']['public_display']) && $this->is_user_verified($user_id, $settings['verify'])) {
|
||||
$info = class_exists('AKSRT\\User\\AuthApply') ? AuthApply::get_auth_info($user_id) : [];
|
||||
$application = class_exists('AKSRT\\User\\AuthApply') ? AuthApply::get_apply_payload($user_id) : [];
|
||||
$type = sanitize_key((string) ($info['type'] ?? $application['type'] ?? ''));
|
||||
$type_settings = is_array($settings['verify']['types'][$type] ?? null) ? $settings['verify']['types'][$type] : [];
|
||||
$label = trim((string) ($type_settings['badge_text'] ?? $type_settings['label'] ?? ''));
|
||||
if ($label === '') {
|
||||
foreach ((array) ($settings['verify']['types'] ?? []) as $configured_type) {
|
||||
if (is_array($configured_type) && !empty($configured_type['badge_text'])) {
|
||||
$label = trim((string) $configured_type['badge_text']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$resolved = $this->resolve_verified_type($user_id, $settings['verify']);
|
||||
$signals[] = [
|
||||
'type' => 'verify',
|
||||
'label' => $label,
|
||||
'title' => $label,
|
||||
'label' => $resolved['label'],
|
||||
'title' => $resolved['label'],
|
||||
'icon' => 'check-circle',
|
||||
'icon_url' => get_theme_file_uri('/assets/img/user/user-certification.svg'),
|
||||
'tone' => 'success',
|
||||
@@ -217,6 +205,52 @@ class Home {
|
||||
return $signals;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析"更多资料"弹窗用的认证三态标识。
|
||||
*
|
||||
* @return array{state:string,label:string} state 为空串表示认证公开展示已关闭;
|
||||
* 否则为 none|personal|enterprise,label 为对应展示文案(与名字旁认证 chip 同源)。
|
||||
*/
|
||||
public function get_verify_state(int $user_id): array {
|
||||
if ($user_id <= 0 || !class_exists('\AKSRT\Settings\Settings')) {
|
||||
return ['state' => '', 'label' => ''];
|
||||
}
|
||||
|
||||
$verify = \AKSRT\Settings\Settings::get_user_identity_settings()['verify'] ?? [];
|
||||
$verify = is_array($verify) ? $verify : [];
|
||||
if (empty($verify['enabled']) || empty($verify['public_display'])) {
|
||||
return ['state' => '', 'label' => ''];
|
||||
}
|
||||
if (!$this->is_user_verified($user_id, $verify)) {
|
||||
return ['state' => 'none', 'label' => __('未认证', 'aksrt')];
|
||||
}
|
||||
|
||||
$resolved = $this->resolve_verified_type($user_id, $verify);
|
||||
// 邮箱核验通过等无申请类型的场景与名字旁 chip 一致,回落到首个已配置类型。
|
||||
$state = in_array($resolved['state'], ['personal', 'enterprise'], true) ? $resolved['state'] : 'personal';
|
||||
return ['state' => $state, 'label' => $resolved['label']];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{state:string,label:string} state 为申请类型 personal|enterprise(可为空串),label 为展示文案。
|
||||
*/
|
||||
private function resolve_verified_type(int $user_id, array $verify): array {
|
||||
$info = class_exists('AKSRT\\User\\AuthApply') ? AuthApply::get_auth_info($user_id) : [];
|
||||
$application = class_exists('AKSRT\\User\\AuthApply') ? AuthApply::get_apply_payload($user_id) : [];
|
||||
$type = sanitize_key((string) ($info['type'] ?? $application['type'] ?? ''));
|
||||
$type_settings = is_array($verify['types'][$type] ?? null) ? $verify['types'][$type] : [];
|
||||
$label = trim((string) ($type_settings['badge_text'] ?? $type_settings['label'] ?? ''));
|
||||
if ($label === '') {
|
||||
foreach ((array) ($verify['types'] ?? []) as $configured_type) {
|
||||
if (is_array($configured_type) && !empty($configured_type['badge_text'])) {
|
||||
$label = trim((string) $configured_type['badge_text']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ['state' => $type, 'label' => $label];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取公开治理提示。
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user