用户功能设置收口与废弃后台链路清理
This commit is contained in:
@@ -9,6 +9,31 @@ defined('ABSPATH') || exit;
|
||||
|
||||
class UserRuntime {
|
||||
|
||||
/**
|
||||
* Canonical avatar, cover, and signature settings.
|
||||
*
|
||||
* @return array{avatar_upload_s:bool,avatar_external:string,avatar_default_img:string,user_cover_upload_s:bool,user_cover_img:string,user_desc_std:string}
|
||||
*/
|
||||
public static function get_user_feature_settings(): array {
|
||||
$settings = Settings::read_domain('users', 'features');
|
||||
$source = sanitize_key((string) ($settings['avatar_external'] ?? ''));
|
||||
if (!in_array($source, ['', 'gravatar', 'weavatar', 'cravatar', 'geekzu', 'loli', 'sep', 'v2ex'], true)) {
|
||||
$source = '';
|
||||
}
|
||||
|
||||
$avatar = esc_url_raw((string) ($settings['avatar_default_img'] ?? ''));
|
||||
$cover = esc_url_raw((string) ($settings['user_cover_img'] ?? ''));
|
||||
|
||||
return [
|
||||
'avatar_upload_s' => !array_key_exists('avatar_upload_s', $settings) || !empty($settings['avatar_upload_s']),
|
||||
'avatar_external' => $source,
|
||||
'avatar_default_img' => $avatar !== '' ? $avatar : get_theme_file_uri('assets/img/avatar-default.png'),
|
||||
'user_cover_upload_s' => !array_key_exists('user_cover_upload_s', $settings) || !empty($settings['user_cover_upload_s']),
|
||||
'user_cover_img' => $cover !== '' ? $cover : get_theme_file_uri('assets/img/user_t.jpg'),
|
||||
'user_desc_std' => sanitize_text_field((string) ($settings['user_desc_std'] ?? '这家伙很懒,什么都没有写...')),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Public user-home display settings.
|
||||
*
|
||||
@@ -70,59 +95,11 @@ class UserRuntime {
|
||||
*
|
||||
* @return array{tabs:string[]}
|
||||
*/
|
||||
public static function get_user_center_settings(): array {
|
||||
$settings = Settings::get_all();
|
||||
$raw_tabs = $settings['user_center_tabs'] ?? 'profile,level,comments,credits,revenue,favorites,auth';
|
||||
$tabs = is_array($raw_tabs)
|
||||
? $raw_tabs
|
||||
: preg_split('/[\s,]+/', (string) $raw_tabs, -1, PREG_SPLIT_NO_EMPTY);
|
||||
|
||||
// Built-in switchable panels. VIP is always auto-injected when enabled
|
||||
// by AKSRT\User\Center — keep it allowed for explicit config too.
|
||||
$allowed_tabs = ['profile', 'level', 'comments', 'favorites', 'credits', 'revenue', 'vip', 'orders', 'auth', 'settings'];
|
||||
$normalized_tabs = ['profile'];
|
||||
|
||||
foreach ((array) $tabs as $tab) {
|
||||
$tab = sanitize_key((string) $tab);
|
||||
if ($tab === 'profile') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (in_array($tab, $allowed_tabs, true) && !in_array($tab, $normalized_tabs, true)) {
|
||||
$normalized_tabs[] = $tab;
|
||||
}
|
||||
}
|
||||
|
||||
if (!in_array('comments', $normalized_tabs, true)) {
|
||||
$normalized_tabs[] = 'comments';
|
||||
}
|
||||
|
||||
// Ensure VIP appears in configured tabs when membership is on, even if
|
||||
// the stored option string is older and omits it.
|
||||
$vip_on = !empty(Settings::get_payment_vip_settings()['enabled']);
|
||||
if ($vip_on && !in_array('vip', $normalized_tabs, true)) {
|
||||
// Prefer after credits, else after favorites, else append before settings.
|
||||
$insert_at = count($normalized_tabs);
|
||||
foreach (['credits', 'favorites', 'posts'] as $anchor) {
|
||||
$idx = array_search($anchor, $normalized_tabs, true);
|
||||
if ($idx !== false) {
|
||||
$insert_at = (int) $idx + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
array_splice($normalized_tabs, $insert_at, 0, ['vip']);
|
||||
}
|
||||
if (!$vip_on) {
|
||||
$normalized_tabs = array_values(array_filter(
|
||||
$normalized_tabs,
|
||||
static fn(string $t): bool => $t !== 'vip'
|
||||
));
|
||||
}
|
||||
|
||||
return [
|
||||
'tabs' => $normalized_tabs,
|
||||
];
|
||||
}
|
||||
public static function get_user_center_settings(): array {
|
||||
return [
|
||||
'tabs' => ['profile', 'level', 'comments', 'credits', 'revenue', 'favorites', 'auth'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* User identity, level, medal, and report governance settings.
|
||||
|
||||
Reference in New Issue
Block a user