register_default_panels(); } /** * 注册默认面板 */ private function register_default_panels(): void { $settings = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_user_center_settings() : [ 'tabs' => ['profile', 'posts', 'comments', 'favorites'], 'avatar_upload' => true, 'cover_upload' => true, 'social_links' => true, ]; $definitions = [ 'profile' => [ 'label' => __('个人信息', 'aksrt'), 'icon' => 'user', 'priority' => 10, 'type' => 'panel', ], 'posts' => [ 'label' => __('我的文章', 'aksrt'), 'icon' => 'file-alt', 'priority' => 20, 'type' => 'panel', ], 'comments' => [ 'label' => __('我的评论', 'aksrt'), 'icon' => 'comment', 'priority' => 30, 'type' => 'panel', ], 'favorites' => [ 'label' => __('我的收藏', 'aksrt'), 'icon' => 'star', 'priority' => 40, 'type' => 'panel', ], 'credits' => [ 'label' => class_exists('AKSRT_Settings') ? sprintf(__('我的%s', 'aksrt'), AKSRT_Settings::get_currency_name()) : __('我的积分', 'aksrt'), 'icon' => 'wallet', 'priority' => 50, 'type' => 'panel', ], 'notif' => [ 'label' => __('消息通知', 'aksrt'), 'icon' => 'bell', 'priority' => 60, 'type' => 'link', ], 'settings' => [ 'label' => __('账号设置', 'aksrt'), 'icon' => 'cog', 'priority' => 70, 'type' => 'panel', ], ]; $this->panels = []; foreach ((array) ($settings['tabs'] ?? []) as $key) { if ($key === 'credits') { $credits_on = class_exists('AKSRT_Settings') && AKSRT_Settings::credits_enabled(); $balance_on = class_exists('AKSRT_Balance') && AKSRT_Balance::enabled(); if (!$credits_on && !$balance_on) { continue; } if ($balance_on) { $definitions['credits']['label'] = __('我的资产', 'aksrt'); $definitions['credits']['icon'] = 'wallet'; } } if (isset($definitions[$key])) { $this->panels[$key] = $definitions[$key]; } } // Ensure assets panel when wallet and/or credits enabled (even if tabs list omitted credits). $credits_on = class_exists('AKSRT_Settings') && AKSRT_Settings::credits_enabled(); $balance_on = class_exists('AKSRT_Balance') && AKSRT_Balance::enabled(); if (!isset($this->panels['credits']) && ($credits_on || $balance_on)) { $panel = $definitions['credits']; if ($balance_on) { $panel['label'] = __('我的资产', 'aksrt'); $panel['icon'] = 'wallet'; } $this->panels['credits'] = $panel; } if (!isset($this->panels['settings'])) { $this->panels['settings'] = $definitions['settings']; } $this->panels['notif'] = $definitions['notif']; /** * 允许插件/子主题注册额外面板 * * @param array $panels 面板注册表 */ $this->panels = apply_filters('aksrt_user_center_panels', $this->panels); } /** * 获取面板注册表 */ public function get_panels(): array { return $this->panels; } /** * 获取可切换的本地面板(不含外链入口)。 */ public function get_dashboard_tabs(): array { return array_filter($this->panels, static function (array $panel): bool { return ($panel['type'] ?? 'panel') === 'panel'; }); } /** * 判断当前页面是否为本人中心 */ public static function is_page(): bool { return function_exists('aksrt_is_user_center_page') && aksrt_is_user_center_page(); } }