feat(admin): rebuild page display settings
This commit is contained in:
@@ -15,65 +15,53 @@ class UserRuntime {
|
||||
* @return array
|
||||
*/
|
||||
public static function get_user_home_settings(): array {
|
||||
$settings = Settings::get_all();
|
||||
$allowed_tabs = ['posts', 'comments', 'favorites', 'credits', 'follow'];
|
||||
|
||||
$parse_csv = function (string $key, string $fallback) use ($settings, $allowed_tabs): array {
|
||||
$raw = $settings[$key] ?? $fallback;
|
||||
$items = is_array($raw) ? $raw : preg_split('/[\s,]+/', (string) $raw, -1, PREG_SPLIT_NO_EMPTY);
|
||||
$clean = [];
|
||||
foreach ((array) $items as $v) {
|
||||
$v = sanitize_key((string) $v);
|
||||
if (in_array($v, $allowed_tabs, true) && !in_array($v, $clean, true)) {
|
||||
$clean[] = $v;
|
||||
}
|
||||
}
|
||||
return $clean;
|
||||
};
|
||||
|
||||
// Public profile tabs supported by this theme.
|
||||
$normalized_tabs = $parse_csv('user_home_tabs', 'posts,favorites,comments,follow');
|
||||
if (empty($normalized_tabs)) {
|
||||
$normalized_tabs = ['posts', 'favorites', 'comments', 'follow'];
|
||||
}
|
||||
|
||||
$raw_order = $parse_csv('user_home_tabs_order', '');
|
||||
$ordered = [];
|
||||
foreach ($raw_order as $tab) {
|
||||
if (in_array($tab, $normalized_tabs, true)) {
|
||||
$ordered[] = $tab;
|
||||
}
|
||||
}
|
||||
foreach ($normalized_tabs as $tab) {
|
||||
if (!in_array($tab, $ordered, true)) {
|
||||
$ordered[] = $tab;
|
||||
}
|
||||
}
|
||||
|
||||
$pc_hide = $parse_csv('user_home_tabs_pc_hide', '');
|
||||
$mobile_hide = $parse_csv('user_home_tabs_mobile_hide', '');
|
||||
$settings = Settings::read_domain('page_display', 'user-home');
|
||||
$tab_options = is_array($settings['author_main_tab_opt'] ?? null)
|
||||
? $settings['author_main_tab_opt']
|
||||
: [
|
||||
'post' => ['pc_s' => true, 'm_s' => true],
|
||||
'favorite' => ['pc_s' => true, 'm_s' => true],
|
||||
'comment' => ['pc_s' => true, 'm_s' => true],
|
||||
'follow' => ['pc_s' => true, 'm_s' => true],
|
||||
];
|
||||
$map = ['post' => 'posts', 'favorite' => 'favorites', 'comment' => 'comments', 'follow' => 'follow'];
|
||||
$ordered = [];
|
||||
$pc_hide = [];
|
||||
$mobile_hide = [];
|
||||
foreach ($tab_options as $key => $option) {
|
||||
$key = sanitize_key((string) $key);
|
||||
if (!isset($map[$key]) || !is_array($option)) {
|
||||
continue;
|
||||
}
|
||||
$tab = $map[$key];
|
||||
$ordered[] = $tab;
|
||||
if (empty($option['pc_s'])) {
|
||||
$pc_hide[] = $tab;
|
||||
}
|
||||
if (empty($option['m_s'])) {
|
||||
$mobile_hide[] = $tab;
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'route_identifier' => (($settings['user_home_route_identifier'] ?? 'nicename') === 'uid') ? 'uid' : 'nicename',
|
||||
'tabs' => $normalized_tabs,
|
||||
'route_identifier' => 'nicename',
|
||||
'tabs' => $ordered,
|
||||
'tabs_order' => $ordered,
|
||||
'tabs_pc_hide' => $pc_hide,
|
||||
'tabs_mobile_hide' => $mobile_hide,
|
||||
// Public author page is full-width (Zibll author.php). Sidebar option kept as no-op reserved key.
|
||||
'sidebar' => false,
|
||||
'cover' => !isset($settings['user_home_cover']) || !empty($settings['user_home_cover']),
|
||||
'follow' => !isset($settings['user_home_follow']) || !empty($settings['user_home_follow']),
|
||||
'posts_per_page' => max(5, min(50, (int) ($settings['user_home_posts_per_page'] ?? 10))),
|
||||
'avatar' => !isset($settings['user_home_avatar']) || !empty($settings['user_home_avatar']),
|
||||
'name' => !isset($settings['user_home_name']) || !empty($settings['user_home_name']),
|
||||
'desc' => !isset($settings['user_home_desc']) || !empty($settings['user_home_desc']),
|
||||
// Body stats row removed; counts live in tabs like Zibll.
|
||||
'cover' => true,
|
||||
'follow' => true,
|
||||
'posts_per_page' => max(1, (int) get_option('posts_per_page', 10)),
|
||||
'avatar' => true,
|
||||
'name' => true,
|
||||
'desc' => true,
|
||||
'stats' => false,
|
||||
'social' => !isset($settings['user_home_social']) || !empty($settings['user_home_social']),
|
||||
'social' => true,
|
||||
'tab_swiper' => !empty($settings['author_main_tab_swiper']),
|
||||
'message' => !isset($settings['user_home_message']) || !empty($settings['user_home_message']),
|
||||
'private' => !isset($settings['user_home_private']) || !empty($settings['user_home_private']),
|
||||
'paging_ajax' => !isset($settings['user_home_paging_ajax']) || !empty($settings['user_home_paging_ajax']),
|
||||
'message' => true,
|
||||
'private' => true,
|
||||
'paging_ajax' => true,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user