diff --git a/inc/helpers/aksrt-user-center.php b/inc/helpers/aksrt-user-center.php index ca6e1e86..c97505ab 100644 --- a/inc/helpers/aksrt-user-center.php +++ b/inc/helpers/aksrt-user-center.php @@ -109,7 +109,6 @@ if (!function_exists('aksrt_get_user_center_tab_url')) { } } - if (!function_exists('aksrt_normalize_user_center_tabs')) { /** * Normalize the dashboard tab contract. @@ -122,9 +121,9 @@ if (!function_exists('aksrt_normalize_user_center_tabs')) { continue; } $normalized[$key] = [ - 'label' => (string) ($tab['label'] ?? $key), - 'icon' => sanitize_html_class((string) ($tab['icon'] ?? 'circle')), - 'template' => isset($tab['template']) ? (string) $tab['template'] : '', + 'label' => (string) ($tab['label'] ?? $key), + 'icon' => sanitize_html_class((string) ($tab['icon'] ?? 'circle')), + 'template' => isset($tab['template']) ? (string) $tab['template'] : '', 'context_callback' => $tab['context_callback'] ?? null, ]; } @@ -132,26 +131,6 @@ if (!function_exists('aksrt_normalize_user_center_tabs')) { } } -if (!function_exists('aksrt_get_user_center_base_context')) { - /** - * Expose the normalized base context independently from panel assembly. - */ - function aksrt_get_user_center_base_context(WP_User $user): array { - $context = aksrt_get_user_center_render_context($user); - unset($context['panels'], $context['account_modals_html']); - return $context; - } -} - -if (!function_exists('aksrt_get_user_center_panel_context')) { - /** - * Return one assembled panel contract. - */ - function aksrt_get_user_center_panel_context(string $tab, array $context): array { - return is_array($context['panels'][$tab] ?? null) ? $context['panels'][$tab] : []; - } -} - if (!function_exists('aksrt_capture_user_center_view')) { /** * Render an internal user-center view into an inert HTML payload. @@ -241,7 +220,6 @@ if (!function_exists('aksrt_build_user_center_render_context')) { } } - if (!function_exists('aksrt_get_user_center_render_context')) { /** * Resolve the current user's complete render context outside template files. @@ -266,7 +244,7 @@ if (!function_exists('aksrt_get_user_center_render_context')) { 'settings' => ['label' => __('账号设置', 'aksrt'), 'icon' => 'cog'], ]; $dashboard_tabs = aksrt_normalize_user_center_tabs($dashboard_tabs); - $dashboard_tab_keys = array_keys($dashboard_tabs); + $dashboard_tab_keys = array_keys($dashboard_tabs); $default_dashboard_tab = in_array('profile', $dashboard_tab_keys, true) ? 'profile' : ($dashboard_tab_keys[0] ?? 'profile'); $active_tab = isset($_GET['tab']) ? sanitize_key(wp_unslash($_GET['tab'])) : $default_dashboard_tab; if ('signin' === $active_tab) { @@ -279,29 +257,33 @@ if (!function_exists('aksrt_get_user_center_render_context')) { } $dashboard = function_exists('aksrt_get_user_dashboard_view') - ? aksrt_get_user_dashboard_view($user_id, ['viewer_id' => $user_id]) + ? aksrt_get_user_dashboard_view($user_id, [ + 'viewer_id' => $user_id, + 'include_recent_posts' => false, + 'include_governance' => false, + ]) : []; - $target_user = $current_user; - $post_count = (int) ($dashboard['post_count'] ?? count_user_posts($user_id, 'post', true)); - $comment_count = (int) ($dashboard['comment_count'] ?? get_comments(['user_id' => $user_id, 'count' => true, 'status' => 'approve'])); - $favorite_post_ids = $dashboard['favorite_post_ids'] ?? []; - $favorite_count = (int) ($dashboard['favorite_count'] ?? count($favorite_post_ids)); - $user_contacts = $dashboard['user_contacts'] ?? get_user_meta($user_id, 'aksrt_user_contacts', true); - $user_contacts = is_array($user_contacts) ? $user_contacts : []; - $profile_signals = $dashboard['profile_signals'] ?? []; - $user_background_url = (string) get_user_meta($user_id, 'aksrt_background_image', true); - $allow_bg_upload = !empty($user_center_settings['cover_upload']) && class_exists('AKSRT_Settings') && aksrt_get_setting('allow_background_upload', false); - $show_avatar_edit = !empty($user_center_settings['avatar_upload']); - $avatar_settings_url = admin_url('profile.php'); + $target_user = $current_user; + $post_count = (int) ($dashboard['post_count'] ?? count_user_posts($user_id, 'post', true)); + $comment_count = (int) ($dashboard['comment_count'] ?? get_comments(['user_id' => $user_id, 'count' => true, 'status' => 'approve'])); + $favorite_post_ids = $dashboard['favorite_post_ids'] ?? []; + $favorite_count = (int) ($dashboard['favorite_count'] ?? count($favorite_post_ids)); + $user_contacts = $dashboard['user_contacts'] ?? get_user_meta($user_id, 'aksrt_user_contacts', true); + $user_contacts = is_array($user_contacts) ? $user_contacts : []; + $profile_signals = $dashboard['profile_signals'] ?? []; + $user_background_url = (string) ($dashboard['background_url'] ?? get_user_meta($user_id, 'aksrt_background_image', true)); + $allow_bg_upload = !empty($user_center_settings['cover_upload']) && class_exists('AKSRT_Settings') && aksrt_get_setting('allow_background_upload', false); + $show_avatar_edit = !empty($user_center_settings['avatar_upload']); + $avatar_settings_url = admin_url('profile.php'); $notification_unread_count = function_exists('aksrt_get_user_unread_notification_count') ? aksrt_get_user_unread_notification_count($user_id) : 0; - $messages_url = function_exists('aksrt_get_messages_url') + $messages_url = function_exists('aksrt_get_messages_url') ? aksrt_get_messages_url() : aksrt_get_user_center_url('notif'); - $per_page = 10; - $posts_page = max(1, isset($_GET['posts_page']) ? (int) $_GET['posts_page'] : 1); - $comments_page = max(1, isset($_GET['comments_page']) ? (int) $_GET['comments_page'] : 1); - $favorites_page = max(1, isset($_GET['favorites_page']) ? (int) $_GET['favorites_page'] : 1); - $post_status_filter = isset($_GET['post_status']) ? sanitize_key(wp_unslash($_GET['post_status'])) : 'publish'; + $per_page = 10; + $posts_page = max(1, isset($_GET['posts_page']) ? (int) $_GET['posts_page'] : 1); + $comments_page = max(1, isset($_GET['comments_page']) ? (int) $_GET['comments_page'] : 1); + $favorites_page = max(1, isset($_GET['favorites_page']) ? (int) $_GET['favorites_page'] : 1); + $post_status_filter = isset($_GET['post_status']) ? sanitize_key(wp_unslash($_GET['post_status'])) : 'publish'; if (!in_array($post_status_filter, ['all', 'publish', 'draft', 'pending', 'private'], true)) { $post_status_filter = 'publish'; } @@ -323,12 +305,13 @@ if (!function_exists('aksrt_get_user_center_render_context')) { $svg_empty_favorite = ''; require_once AKSRT_DIR . '/templates/parts/user-shared-helpers.php'; - $all_settings = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_all() : []; + $vip_settings = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_payment_vip_settings() : []; + $affiliate_settings = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_payment_affiliate_settings() : []; $orders_url = function_exists('aksrt_get_orders_page_url') ? aksrt_get_orders_page_url() : ''; - $show_vip = !empty($all_settings['payment_vip_enabled']); - $show_credit_tabs = class_exists('AKSRT_Settings') && AKSRT_Settings::credits_enabled(); - $affiliate_enabled = $show_credit_tabs && !empty($all_settings['payment_affiliate_enabled']); - $currency_name = $show_credit_tabs ? AKSRT_Settings::get_currency_name() : __('积分', 'aksrt'); + $show_vip = !empty($vip_settings['enabled']); + $show_credit_tabs = (bool) ($dashboard['credits_enabled'] ?? false); + $affiliate_enabled = $show_credit_tabs && !empty($affiliate_settings['enabled']); + $currency_name = (string) ($dashboard['currency_name'] ?? __('积分', 'aksrt')); $tab_urls = []; foreach ($dashboard_tab_keys as $tab_key) { $tab_urls[$tab_key] = aksrt_get_user_center_tab_url($tab_key); @@ -369,6 +352,9 @@ if (!function_exists('aksrt_get_user_center_render_context')) { 'show_credit_tabs' => $show_credit_tabs, 'affiliate_enabled' => $affiliate_enabled, 'currency_name' => $currency_name, + 'credit_balance' => (float) ($dashboard['credit_balance'] ?? 0.0), + 'credits_enabled' => $show_credit_tabs, + 'vip_settings' => $vip_settings, 'show_invite_section' => $show_credit_tabs && class_exists('AKSRT_Settings') && AKSRT_Settings::invite_enabled() diff --git a/inc/helpers/aksrt-user-dashboard.php b/inc/helpers/aksrt-user-dashboard.php index 23389c74..ef8ddee8 100644 --- a/inc/helpers/aksrt-user-dashboard.php +++ b/inc/helpers/aksrt-user-dashboard.php @@ -14,7 +14,10 @@ defined('ABSPATH') || exit; * Get aggregated dashboard view data for a user. * * @param int $user_id Target user ID. - * @param array $args Optional. 'viewer_id' => current viewer ID. + * @param array $args Optional. Supported keys: + * - viewer_id: Current viewer ID. + * - include_recent_posts: Whether to query recent posts. + * - include_governance: Whether to resolve notice/report data. * @return array { * @type int $post_count Published post count. * @type int $comment_count Approved comment count. @@ -31,8 +34,10 @@ defined('ABSPATH') || exit; * } */ function aksrt_get_user_dashboard_view(int $user_id, array $args = []): array { - $viewer_id = (int) ($args['viewer_id'] ?? get_current_user_id()); - $is_own_profile = is_user_logged_in() && $viewer_id === $user_id; + $viewer_id = (int) ($args['viewer_id'] ?? get_current_user_id()); + $include_recent_posts = !array_key_exists('include_recent_posts', $args) || (bool) $args['include_recent_posts']; + $include_governance = !array_key_exists('include_governance', $args) || (bool) $args['include_governance']; + $is_own_profile = is_user_logged_in() && $viewer_id === $user_id; $post_count = (int) count_user_posts($user_id, 'post', true); $comment_count = (int) get_comments([ @@ -45,15 +50,17 @@ function aksrt_get_user_dashboard_view(int $user_id, array $args = []): array { ? aksrt_get_user_interaction_posts('_aksrt_favorite_posts', $user_id) : []; $favorite_count = count($favorite_post_ids); - $recent_posts = get_posts([ - 'author' => $user_id, - 'post_type' => 'post', - 'post_status' => 'publish', - 'posts_per_page' => 5, - 'orderby' => 'date', - 'order' => 'DESC', - 'no_found_rows' => true, - ]); + $recent_posts = $include_recent_posts + ? get_posts([ + 'author' => $user_id, + 'post_type' => 'post', + 'post_status' => 'publish', + 'posts_per_page' => 5, + 'orderby' => 'date', + 'order' => 'DESC', + 'no_found_rows' => true, + ]) + : []; $user_contacts = get_user_meta($user_id, 'aksrt_user_contacts', true) ?: []; if (!is_array($user_contacts)) { @@ -74,7 +81,9 @@ function aksrt_get_user_dashboard_view(int $user_id, array $args = []): array { ? AKSRT_Settings::get_currency_name() : __('积分', 'aksrt'); - $user_home_manager = class_exists('AKSRT_User_Home') ? AKSRT_User_Home::get_instance() : null; + $user_home_manager = $include_governance && class_exists('AKSRT_User_Home') + ? AKSRT_User_Home::get_instance() + : null; $profile_signals = $user_home_manager ? $user_home_manager->get_profile_signals($user_id) : []; $profile_notice = $user_home_manager ? $user_home_manager->get_profile_notice($user_id) : []; $show_report = $user_home_manager ? $user_home_manager->show_report_entry() : false; diff --git a/inc/helpers/user-center-renderers/profile-credits.php b/inc/helpers/user-center-renderers/profile-credits.php index 7120cec2..048a14a7 100644 --- a/inc/helpers/user-center-renderers/profile-credits.php +++ b/inc/helpers/user-center-renderers/profile-credits.php @@ -11,10 +11,9 @@ $context = is_array($args['context'] ?? null) ? $args['context'] : []; extract($context, EXTR_SKIP); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract ?>

- +