用户中心减层:收敛本人入口与 panel 契约
This commit is contained in:
@@ -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 = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/></svg>';
|
||||
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()
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -11,10 +11,9 @@ $context = is_array($args['context'] ?? null) ? $args['context'] : [];
|
||||
extract($context, EXTR_SKIP); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
|
||||
?>
|
||||
<?php
|
||||
$balance = function_exists( 'aksrt_user_credits' ) ? aksrt_user_credits( $user_id ) : 0;
|
||||
$currency_name = class_exists( 'AKSRT_Settings' ) ? AKSRT_Settings::get_currency_name() : __( '积分', 'aksrt' );
|
||||
$credits_enabled = class_exists( 'AKSRT_Settings' ) && AKSRT_Settings::credits_enabled();
|
||||
$vip_settings = class_exists( 'AKSRT_Settings' ) ? AKSRT_Settings::get_payment_vip_settings() : [];
|
||||
$balance = (float) ($credit_balance ?? 0.0);
|
||||
$credits_enabled = ! empty( $credits_enabled );
|
||||
$vip_settings = is_array( $vip_settings ?? null ) ? $vip_settings : [];
|
||||
$show_vip_card = ! empty( $vip_settings['enabled'] );
|
||||
$is_vip_user = function_exists( 'aksrt_is_vip' ) && aksrt_is_vip( $user_id );
|
||||
$vip_badge_text = function_exists( 'aksrt_get_vip_badge_text' ) ? aksrt_get_vip_badge_text() : 'VIP';
|
||||
@@ -175,4 +174,4 @@ extract($context, EXTR_SKIP); // phpcs:ignore WordPress.PHP.DontExtract.extract_
|
||||
<p><?php echo esc_html( sprintf( __( '还没有任何%s流水', 'aksrt' ), $currency_name ) ); ?></p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user