用户中心 posts/sidebar/form 渲染器整包拆分并清理标记

This commit is contained in:
2026-07-10 22:44:15 +08:00
parent 81d5647205
commit 57ccdb60c4
13 changed files with 450 additions and 380 deletions
@@ -0,0 +1,34 @@
<?php
/**
* User center profile form: contact rows block.
*
* Expects extracted $context vars.
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
if (empty($user_center_settings['social_links'])) {
return;
}
?>
<div class="widget-card">
<h3 class="widget-title"><?php esc_html_e('联系方式', 'aksrt'); ?></h3>
<p class="profile-hint profile-hint--top"><?php esc_html_e('添加你的社交链接,显示在公开用户主页', 'aksrt'); ?></p>
<div id="contacts-list">
<?php foreach ((array) $user_contacts as $i => $contact) : ?>
<div class="contact-row" data-index="<?php echo (int) $i; ?>">
<select name="contacts[<?php echo (int) $i; ?>][icon]" class="profile-input contact-icon">
<?php echo aksrt_contact_icon_options($contact['icon'] ?? ''); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</select>
<input type="hidden" name="contacts[<?php echo (int) $i; ?>][name]" value="">
<input type="url" name="contacts[<?php echo (int) $i; ?>][url]"
value="<?php echo esc_url($contact['url'] ?? ''); ?>"
class="profile-input contact-url" placeholder="<?php esc_attr_e('链接 URL', 'aksrt'); ?>">
<button type="button" class="contact-remove" onclick="this.parentElement.remove()" title="<?php esc_attr_e('删除', 'aksrt'); ?>">&times;</button>
</div>
<?php endforeach; ?>
</div>
<button type="button" class="btn-ghost btn-sm profile-add-contact" id="add-contact-btn">+ <?php esc_html_e('添加联系方式', 'aksrt'); ?></button>
</div>
@@ -0,0 +1,60 @@
<?php
/**
* User center posts: list + pagination.
*
* Expects extracted $context vars.
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
$ps_args = [
'author' => $user_id,
'post_status' => ('all' === $post_status_filter)
? ['publish', 'draft', 'pending', 'private']
: $post_status_filter,
'posts_per_page' => $per_page,
'paged' => $posts_page,
'no_found_rows' => false,
'update_post_meta_cache' => false,
'update_post_term_cache' => true,
];
$q = new WP_Query($ps_args);
if ($q->have_posts()) :
?>
<div class="profile-list">
<?php
while ($q->have_posts()) :
$q->the_post();
$st = get_post_status();
$status_label = '';
if ('publish' !== $st) {
$st_map = [
'draft' => __('草稿', 'aksrt'),
'pending' => __('待审', 'aksrt'),
'private' => __('私密', 'aksrt'),
'future' => __('定时', 'aksrt'),
];
$status_label = $st_map[$st] ?? $st;
}
$edit_link = get_edit_post_link();
get_template_part('templates/parts/content', 'profile-list-item', [
'action' => $edit_link ? ['type' => 'edit', 'url' => $edit_link, 'label' => __('编辑', 'aksrt')] : [],
'status' => $status_label,
]);
endwhile;
?>
</div>
<?php
aksrt_render_profile_pagination((int) $q->max_num_pages, $posts_page, 'posts_page');
wp_reset_postdata();
else :
aksrt_render_profile_empty(
$svg_empty_post,
__('还没有文章', 'aksrt'),
__('试试发布你的第一篇文章吧。', 'aksrt'),
admin_url('post-new.php'),
__('写文章', 'aksrt')
);
endif;
@@ -0,0 +1,40 @@
<?php
/**
* User center posts: status filter chips.
*
* Expects extracted $context vars.
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
$status_chip_defs = [
'publish' => __('已发布', 'aksrt'),
'draft' => __('草稿', 'aksrt'),
'pending' => __('待审', 'aksrt'),
'private' => __('私密', 'aksrt'),
'all' => __('全部', 'aksrt'),
];
?>
<div class="profile-status-filter" role="tablist" aria-label="<?php esc_attr_e('文章状态筛选', 'aksrt'); ?>">
<?php foreach ($status_chip_defs as $status_key => $status_text) :
$count_for_chip = ('all' === $status_key)
? $post_count
: ($user_status_counts[$status_key] ?? 0);
if ('publish' !== $status_key && 'all' !== $status_key && $count_for_chip < 1) {
continue;
}
$chip_url = add_query_arg([
'tab' => 'posts',
'post_status' => $status_key,
'posts_page' => 1,
], remove_query_arg(['posts_page']));
$chip_active = ($post_status_filter === $status_key);
?>
<a href="<?php echo esc_url($chip_url); ?>" class="profile-status-chip<?php echo $chip_active ? ' is-active' : ''; ?>" role="tab" aria-selected="<?php echo $chip_active ? 'true' : 'false'; ?>">
<?php echo esc_html($status_text); ?>
<span class="profile-status-chip__count"><?php echo esc_html((string) $count_for_chip); ?></span>
</a>
<?php endforeach; ?>
</div>
@@ -10,37 +10,38 @@ defined('ABSPATH') || exit;
$context = is_array($args['context'] ?? null) ? $args['context'] : [];
extract($context, EXTR_SKIP); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
?>
<!-- ==================== 我的评论 ==================== -->
<div class="widget-card">
<div class="profile-list-header">
<h3 class="widget-title widget-title--inline">
<?php printf( esc_html__( '我的评论(%d 条)', 'aksrt' ), $comment_count ); ?>
</h3>
</div>
<?php
$comments_total = $comment_count;
$cs = get_comments( [
'user_id' => $user_id,
'number' => $per_page,
'offset' => ( $comments_page - 1 ) * $per_page,
'status' => 'approve',
'update_comment_meta_cache' => false,
] );
if ( $cs ) : ?>
<div class="profile-comment-list">
<?php foreach ( $cs as $c ) :
get_template_part('templates/parts/content', 'profile-comment-item', ['comment' => $c]);
endforeach; ?>
</div>
<?php
$comments_total_pages = (int) ceil( $comments_total / $per_page );
aksrt_render_profile_pagination( $comments_total_pages, $comments_page, 'comments_page' );
?>
<?php else :
aksrt_render_profile_empty(
$svg_empty_comment,
__( '暂无评论', 'aksrt' ),
__( '在你感兴趣的文章下留下你的看法吧。', 'aksrt' )
);
endif; ?>
<div class="widget-card">
<div class="profile-list-header">
<h3 class="widget-title widget-title--inline">
<?php printf(esc_html__('我的评论(%d 条)', 'aksrt'), $comment_count); ?>
</h3>
</div>
<?php
$cs = get_comments([
'user_id' => $user_id,
'number' => $per_page,
'offset' => ($comments_page - 1) * $per_page,
'status' => 'approve',
'update_comment_meta_cache' => false,
]);
if ($cs) :
?>
<div class="profile-comment-list">
<?php
foreach ($cs as $c) {
get_template_part('templates/parts/content', 'profile-comment-item', ['comment' => $c]);
}
?>
</div>
<?php
$comments_total_pages = (int) ceil($comment_count / $per_page);
aksrt_render_profile_pagination($comments_total_pages, $comments_page, 'comments_page');
else :
aksrt_render_profile_empty(
$svg_empty_comment,
__('暂无评论', 'aksrt'),
__('在你感兴趣的文章下留下你的看法吧。', 'aksrt')
);
endif;
?>
</div>
@@ -10,56 +10,60 @@ defined('ABSPATH') || exit;
$context = is_array($args['context'] ?? null) ? $args['context'] : [];
extract($context, EXTR_SKIP); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
?>
<!-- ==================== 我的收藏 ==================== -->
<div class="widget-card">
<div class="profile-list-header">
<h3 class="widget-title widget-title--inline">
<?php printf( esc_html__( '我的收藏(%d 篇)', 'aksrt' ), $favorite_count ); ?>
</h3>
</div>
<?php if ( ! empty( $favorite_post_ids ) ) :
$favorites_query = new WP_Query( [
'post_type' => 'post',
'post_status' => 'publish',
'post__in' => $favorite_post_ids,
'orderby' => 'post__in',
'posts_per_page' => $per_page,
'paged' => $favorites_page,
'ignore_sticky_posts' => true,
'no_found_rows' => false,
'update_post_meta_cache' => false,
] );
if ( $favorites_query->have_posts() ) : ?>
<div class="profile-list" data-list="favorites">
<?php while ( $favorites_query->have_posts() ) : $favorites_query->the_post();
get_template_part('templates/parts/content', 'profile-list-item', [
'action' => [
'type' => 'unfavorite',
'url' => '#',
'label' => __('取消收藏', 'aksrt'),
],
]);
endwhile; ?>
</div>
<?php aksrt_render_profile_pagination( (int) $favorites_query->max_num_pages, $favorites_page, 'favorites_page' ); ?>
<?php
wp_reset_postdata();
else :
aksrt_render_profile_empty(
$svg_empty_favorite,
__( '收藏列表为空', 'aksrt' ),
__( '点击文章页面的星标收藏喜欢的内容。', 'aksrt' ),
home_url( '/' ),
__( '去发现好文', 'aksrt' )
);
endif;
else :
aksrt_render_profile_empty(
$svg_empty_favorite,
__( '收藏列表为空', 'aksrt' ),
__( '点击文章页面的星标收藏喜欢的内容。', 'aksrt' ),
home_url( '/' ),
__( '去发现好文', 'aksrt' )
);
endif; ?>
</div>
<div class="widget-card">
<div class="profile-list-header">
<h3 class="widget-title widget-title--inline">
<?php printf(esc_html__('我的收藏(%d 篇)', 'aksrt'), $favorite_count); ?>
</h3>
</div>
<?php if (!empty($favorite_post_ids)) :
$favorites_query = new WP_Query([
'post_type' => 'post',
'post_status' => 'publish',
'post__in' => $favorite_post_ids,
'orderby' => 'post__in',
'posts_per_page' => $per_page,
'paged' => $favorites_page,
'ignore_sticky_posts' => true,
'no_found_rows' => false,
'update_post_meta_cache' => false,
]);
if ($favorites_query->have_posts()) :
?>
<div class="profile-list" data-list="favorites">
<?php
while ($favorites_query->have_posts()) :
$favorites_query->the_post();
get_template_part('templates/parts/content', 'profile-list-item', [
'action' => [
'type' => 'unfavorite',
'url' => '#',
'label' => __('取消收藏', 'aksrt'),
],
]);
endwhile;
?>
</div>
<?php
aksrt_render_profile_pagination((int) $favorites_query->max_num_pages, $favorites_page, 'favorites_page');
wp_reset_postdata();
else :
aksrt_render_profile_empty(
$svg_empty_favorite,
__('收藏列表为空', 'aksrt'),
__('点击文章页面的星标收藏喜欢的内容。', 'aksrt'),
home_url('/'),
__('去发现好文', 'aksrt')
);
endif;
else :
aksrt_render_profile_empty(
$svg_empty_favorite,
__('收藏列表为空', 'aksrt'),
__('点击文章页面的星标收藏喜欢的内容。', 'aksrt'),
home_url('/'),
__('去发现好文', 'aksrt')
);
endif;
?>
</div>
@@ -1,6 +1,6 @@
<?php
/**
* User center profile form part.
* User center profile form part (orchestrator).
*
* @package AKSRT
*/
@@ -10,57 +10,32 @@ defined('ABSPATH') || exit;
$context = is_array($args['context'] ?? null) ? $args['context'] : [];
extract($context, EXTR_SKIP); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
?>
<!-- ==================== 个人信息(可编辑) ==================== -->
<form class="profile-form" id="profile-form" method="post">
<?php wp_nonce_field( 'aksrt_profile_save', '_profile_nonce' ); ?>
<input type="hidden" name="action" value="aksrt_save_profile">
<input type="hidden" name="user_id" value="<?php echo (int) $user_id; ?>">
<form class="profile-form" id="profile-form" method="post">
<?php wp_nonce_field('aksrt_profile_save', '_profile_nonce'); ?>
<input type="hidden" name="action" value="aksrt_save_profile">
<input type="hidden" name="user_id" value="<?php echo (int) $user_id; ?>">
<!-- 昵称 -->
<div class="widget-card">
<h3 class="widget-title"><?php esc_html_e( '昵称', 'aksrt' ); ?></h3>
<input type="text" name="nickname" id="profile-nickname"
value="<?php echo esc_attr( $target_user->display_name ); ?>"
class="profile-input" maxlength="50" required>
<p class="profile-hint"><?php esc_html_e( '修改后会同步更新个人主页地址', 'aksrt' ); ?></p>
</div>
<div class="widget-card">
<h3 class="widget-title"><?php esc_html_e('昵称', 'aksrt'); ?></h3>
<input type="text" name="nickname" id="profile-nickname"
value="<?php echo esc_attr($target_user->display_name); ?>"
class="profile-input" maxlength="50" required>
<p class="profile-hint"><?php esc_html_e('修改后会同步更新个人主页地址', 'aksrt'); ?></p>
</div>
<!-- 个人简介 -->
<div class="widget-card">
<h3 class="widget-title"><?php esc_html_e( '个人简介', 'aksrt' ); ?></h3>
<textarea name="description" id="profile-bio" class="profile-input profile-textarea"
rows="4" maxlength="500" placeholder="<?php esc_attr_e( '介绍一下自己…', 'aksrt' ); ?>"><?php echo esc_textarea( $target_user->description ); ?></textarea>
<p class="profile-hint"><?php esc_html_e( '显示在你的公开用户主页上,最多 500 字', 'aksrt' ); ?></p>
</div>
<div class="widget-card">
<h3 class="widget-title"><?php esc_html_e('个人简介', 'aksrt'); ?></h3>
<textarea name="description" id="profile-bio" class="profile-input profile-textarea"
rows="4" maxlength="500" placeholder="<?php esc_attr_e('介绍一下自己…', 'aksrt'); ?>"><?php echo esc_textarea($target_user->description); ?></textarea>
<p class="profile-hint"><?php esc_html_e('显示在你的公开用户主页上,最多 500 字', 'aksrt'); ?></p>
</div>
<?php if ( ! empty( $user_center_settings['social_links'] ) ) : ?>
<!-- 联系方式 -->
<div class="widget-card">
<h3 class="widget-title"><?php esc_html_e( '联系方式', 'aksrt' ); ?></h3>
<p class="profile-hint profile-hint--top"><?php esc_html_e( '添加你的社交链接,显示在公开用户主页', 'aksrt' ); ?></p>
<div id="contacts-list">
<?php foreach ( $user_contacts as $i => $contact ) : ?>
<div class="contact-row" data-index="<?php echo (int) $i; ?>">
<select name="contacts[<?php echo (int) $i; ?>][icon]" class="profile-input contact-icon">
<?php echo aksrt_contact_icon_options( $contact['icon'] ?? '' ); ?>
</select>
<input type="hidden" name="contacts[<?php echo (int) $i; ?>][name]" value="">
<input type="url" name="contacts[<?php echo (int) $i; ?>][url]"
value="<?php echo esc_url( $contact['url'] ?? '' ); ?>"
class="profile-input contact-url" placeholder="<?php esc_attr_e( '链接 URL', 'aksrt' ); ?>">
<button type="button" class="contact-remove" onclick="this.parentElement.remove()" title="<?php esc_attr_e( '删除', 'aksrt' ); ?>">&times;</button>
</div>
<?php endforeach; ?>
</div>
<button type="button" class="btn-ghost btn-sm profile-add-contact" id="add-contact-btn">+ <?php esc_html_e( '添加联系方式', 'aksrt' ); ?></button>
</div>
<?php endif; ?>
<?php require __DIR__ . '/form-contacts.php'; ?>
<!-- 保存按钮 -->
<div class="profile-form__submit">
<button type="submit" class="btn-primary btn-lg" id="profile-save-btn">
<?php esc_html_e( '保存修改', 'aksrt' ); ?>
</button>
<span id="profile-save-msg" class="profile-form__submit-msg"></span>
</div>
</form>
<div class="profile-form__submit">
<button type="submit" class="btn-primary btn-lg" id="profile-save-btn">
<?php esc_html_e('保存修改', 'aksrt'); ?>
</button>
<span id="profile-save-msg" class="profile-form__submit-msg"></span>
</div>
</form>
@@ -10,70 +10,71 @@ defined('ABSPATH') || exit;
$context = is_array($args['context'] ?? null) ? $args['context'] : [];
extract($context, EXTR_SKIP); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
?>
<!-- 头图 + 用户卡 -->
<div class="uc-header">
<div class="uc-header__cover">
<img id="aksrt-cover-img" class="uc-header__cover-img" src="<?php echo esc_url( $user_background_url ? $user_background_url : get_theme_file_uri( 'assets/img/person_background.png' ) ); ?>" alt="">
<div class="uc-header__cover-mask"></div>
<?php if ( $allow_bg_upload ) : ?>
<button type="button" class="uc-header__cover-upload" id="aksrt-upload-bg-btn" title="<?php esc_attr_e( '编辑背景图', 'aksrt' ); ?>">
<i class="fas fa-pen" aria-hidden="true"></i>
<span><?php esc_html_e( '编辑', 'aksrt' ); ?></span>
</button>
<input type="file" id="aksrt-bg-file-input" accept="image/jpeg,image/png,image/webp,image/gif" style="display:none">
<div class="uc-header">
<div class="uc-header__cover">
<img id="aksrt-cover-img" class="uc-header__cover-img" src="<?php echo esc_url($user_background_url ? $user_background_url : get_theme_file_uri('assets/img/person_background.png')); ?>" alt="">
<div class="uc-header__cover-mask"></div>
<?php if ($allow_bg_upload) : ?>
<button type="button" class="uc-header__cover-upload" id="aksrt-upload-bg-btn" title="<?php esc_attr_e('编辑背景图', 'aksrt'); ?>">
<i class="fas fa-pen" aria-hidden="true"></i>
<span><?php esc_html_e('编辑', 'aksrt'); ?></span>
</button>
<input type="file" id="aksrt-bg-file-input" accept="image/jpeg,image/png,image/webp,image/gif" style="display:none">
<?php endif; ?>
</div>
<div class="uc-header__content">
<div class="uc-header__avatar">
<?php echo get_avatar($user_id, 120, '', $target_user->display_name); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</div>
<div class="uc-header__info">
<h1 class="uc-header__name">
<?php echo esc_html($target_user->display_name); ?>
<?php
$vip_badge = function_exists('aksrt_render_vip_badge') ? aksrt_render_vip_badge($user_id) : '';
if ($vip_badge) {
echo $vip_badge; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
?>
</h1>
<?php if ($target_user->description) : ?>
<p class="uc-header__desc"><?php echo esc_html($target_user->description); ?></p>
<?php endif; ?>
<?php if (!empty($profile_signals)) : ?>
<div class="aksrt-identity-chips">
<?php foreach ($profile_signals as $signal) : ?>
<span class="aksrt-identity-chip aksrt-identity-chip--<?php echo esc_attr($signal['tone']); ?>">
<i class="fas fa-<?php echo esc_attr($signal['icon']); ?>" aria-hidden="true"></i>
<span><?php echo esc_html($signal['label']); ?></span>
</span>
<?php endforeach; ?>
</div>
<?php endif; ?>
<div class="uc-header__meta">
<span class="uc-header__meta-item" title="<?php esc_attr_e('用户名', 'aksrt'); ?>">
<i class="fas fa-user" aria-hidden="true"></i> <?php echo esc_html($target_user->user_login); ?>
</span>
<?php if ($target_user->user_email) : ?>
<span class="uc-header__meta-item" title="<?php esc_attr_e('邮箱', 'aksrt'); ?>">
<i class="fas fa-envelope" aria-hidden="true"></i> <?php echo esc_html($target_user->user_email); ?>
</span>
<?php endif; ?>
</div>
<div class="uc-header__content">
<div class="uc-header__avatar">
<?php echo get_avatar( $user_id, 120, '', $target_user->display_name ); ?>
</div>
<div class="uc-header__info">
<h1 class="uc-header__name">
<?php echo esc_html( $target_user->display_name ); ?>
<?php
$vip_badge = function_exists('aksrt_render_vip_badge') ? aksrt_render_vip_badge($user_id) : '';
if ($vip_badge) echo $vip_badge; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
?>
</h1>
<?php if ( $target_user->description ) : ?>
<p class="uc-header__desc"><?php echo esc_html( $target_user->description ); ?></p>
<?php endif; ?>
<?php if ( ! empty( $profile_signals ) ) : ?>
<div class="aksrt-identity-chips">
<?php foreach ( $profile_signals as $signal ) : ?>
<span class="aksrt-identity-chip aksrt-identity-chip--<?php echo esc_attr( $signal['tone'] ); ?>">
<i class="fas fa-<?php echo esc_attr( $signal['icon'] ); ?>" aria-hidden="true"></i>
<span><?php echo esc_html( $signal['label'] ); ?></span>
</span>
<?php endforeach; ?>
</div>
<?php endif; ?>
<div class="uc-header__meta">
<span class="uc-header__meta-item" title="<?php esc_attr_e( '用户名', 'aksrt' ); ?>">
<i class="fas fa-user" aria-hidden="true"></i> <?php echo esc_html( $target_user->user_login ); ?>
</span>
<?php if ( $target_user->user_email ) : ?>
<span class="uc-header__meta-item" title="<?php esc_attr_e( '邮箱', 'aksrt' ); ?>">
<i class="fas fa-envelope" aria-hidden="true"></i> <?php echo esc_html( $target_user->user_email ); ?>
</span>
<?php endif; ?>
</div>
</div>
<div class="uc-header__actions">
<a href="<?php echo esc_url( $messages_url ); ?>" class="btn-ghost btn-sm">
<i class="fas fa-bell" aria-hidden="true"></i> <?php esc_html_e( '消息通知', 'aksrt' ); ?>
<?php if ( $notification_unread_count > 0 ) : ?>
<span class="uc-header__action-badge"><?php echo esc_html( (string) $notification_unread_count ); ?></span>
<?php endif; ?>
</a>
<?php if ( $show_avatar_edit ) : ?>
<a href="<?php echo esc_url( $avatar_settings_url ); ?>" class="btn-ghost btn-sm">
<i class="fas fa-camera" aria-hidden="true"></i> <?php esc_html_e( '更换头像', 'aksrt' ); ?>
</a>
<?php endif; ?>
<a href="<?php echo esc_url( aksrt_get_user_home_url() ); ?>" class="btn-ghost btn-sm">
<i class="fas fa-map-marker-alt" aria-hidden="true"></i> <?php esc_html_e( '我的主页', 'aksrt' ); ?>
</a>
</div>
</div>
</div>
<div class="uc-header__actions">
<a href="<?php echo esc_url($messages_url); ?>" class="btn-ghost btn-sm">
<i class="fas fa-bell" aria-hidden="true"></i> <?php esc_html_e('消息通知', 'aksrt'); ?>
<?php if ($notification_unread_count > 0) : ?>
<span class="uc-header__action-badge"><?php echo esc_html((string) $notification_unread_count); ?></span>
<?php endif; ?>
</a>
<?php if ($show_avatar_edit) : ?>
<a href="<?php echo esc_url($avatar_settings_url); ?>" class="btn-ghost btn-sm">
<i class="fas fa-camera" aria-hidden="true"></i> <?php esc_html_e('更换头像', 'aksrt'); ?>
</a>
<?php endif; ?>
<a href="<?php echo esc_url(aksrt_get_user_home_url()); ?>" class="btn-ghost btn-sm">
<i class="fas fa-map-marker-alt" aria-hidden="true"></i> <?php esc_html_e('我的主页', 'aksrt'); ?>
</a>
</div>
</div>
</div>
@@ -1,6 +1,6 @@
<?php
/**
* User center profile posts part.
* User center profile posts part (orchestrator).
*
* @package AKSRT
*/
@@ -10,92 +10,15 @@ defined('ABSPATH') || exit;
$context = is_array($args['context'] ?? null) ? $args['context'] : [];
extract($context, EXTR_SKIP); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
?>
<!-- ==================== 我的文章 ==================== -->
<div class="widget-card">
<div class="profile-list-header">
<h3 class="widget-title widget-title--inline">
<?php
/* translators: %d: post count */
printf( esc_html__( '我的文章(%d 篇)', 'aksrt' ), $post_count );
?>
</h3>
<?php
$status_chip_defs = [
'publish' => __( '已发布', 'aksrt' ),
'draft' => __( '草稿', 'aksrt' ),
'pending' => __( '待审', 'aksrt' ),
'private' => __( '私密', 'aksrt' ),
'all' => __( '全部', 'aksrt' ),
];
?>
<div class="profile-status-filter" role="tablist" aria-label="<?php esc_attr_e( '文章状态筛选', 'aksrt' ); ?>">
<?php foreach ( $status_chip_defs as $status_key => $status_text ) :
$count_for_chip = ( 'all' === $status_key )
? $post_count
: ( $user_status_counts[ $status_key ] ?? 0 );
if ( 'publish' !== $status_key && 'all' !== $status_key && $count_for_chip < 1 ) {
continue;
}
$chip_url = add_query_arg( [
'tab' => 'posts',
'post_status' => $status_key,
'posts_page' => 1,
], remove_query_arg( [ 'posts_page' ] ) );
$chip_active = ( $post_status_filter === $status_key );
?>
<a href="<?php echo esc_url( $chip_url ); ?>" class="profile-status-chip<?php echo $chip_active ? ' is-active' : ''; ?>" role="tab" aria-selected="<?php echo $chip_active ? 'true' : 'false'; ?>">
<?php echo esc_html( $status_text ); ?>
<span class="profile-status-chip__count"><?php echo esc_html( (string) $count_for_chip ); ?></span>
</a>
<?php endforeach; ?>
</div>
</div>
<?php
$ps_args = [
'author' => $user_id,
'post_status' => ( 'all' === $post_status_filter )
? [ 'publish', 'draft', 'pending', 'private' ]
: $post_status_filter,
'posts_per_page' => $per_page,
'paged' => $posts_page,
'no_found_rows' => false,
'update_post_meta_cache' => false,
'update_post_term_cache' => true,
];
$q = new WP_Query( $ps_args );
if ( $q->have_posts() ) : ?>
<div class="profile-list">
<?php while ( $q->have_posts() ) : $q->the_post();
$st = get_post_status();
$status_label = '';
if ( 'publish' !== $st ) {
$st_map = [
'draft' => __( '草稿', 'aksrt' ),
'pending' => __( '待审', 'aksrt' ),
'private' => __( '私密', 'aksrt' ),
'future' => __( '定时', 'aksrt' ),
];
$status_label = $st_map[ $st ] ?? $st;
}
$edit_link = get_edit_post_link();
get_template_part('templates/parts/content', 'profile-list-item', [
'action' => $edit_link ? ['type' => 'edit', 'url' => $edit_link, 'label' => __('编辑', 'aksrt')] : [],
'status' => $status_label,
]);
endwhile; ?>
</div>
<?php aksrt_render_profile_pagination( (int) $q->max_num_pages, $posts_page, 'posts_page' ); ?>
<?php
wp_reset_postdata();
else :
aksrt_render_profile_empty(
$svg_empty_post,
__( '还没有文章', 'aksrt' ),
__( '试试发布你的第一篇文章吧。', 'aksrt' ),
admin_url( 'post-new.php' ),
__( '写文章', 'aksrt' )
);
endif; ?>
</div>
<div class="widget-card">
<div class="profile-list-header">
<h3 class="widget-title widget-title--inline">
<?php
/* translators: %d: post count */
printf(esc_html__('我的文章(%d 篇)', 'aksrt'), $post_count);
?>
</h3>
<?php require __DIR__ . '/posts-status-filter.php'; ?>
</div>
<?php require __DIR__ . '/posts-list.php'; ?>
</div>
@@ -1,6 +1,6 @@
<?php
/**
* User center profile sidebar part.
* User center profile sidebar part (orchestrator).
*
* @package AKSRT
*/
@@ -9,86 +9,11 @@ defined('ABSPATH') || exit;
$context = is_array($args['context'] ?? null) ? $args['context'] : [];
extract($context, EXTR_SKIP); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
require __DIR__ . '/sidebar-stats.php';
require __DIR__ . '/sidebar-nav.php';
require __DIR__ . '/sidebar-commerce.php';
?>
<!-- 数据统计 -->
<div class="uc-sidebar__section">
<div class="uc-sidebar__title"><?php esc_html_e( '数据统计', 'aksrt' ); ?></div>
<div class="uc-stats">
<?php foreach ( [ 'posts', 'comments', 'favorites' ] as $stat_tab ) : ?>
<?php if ( ! isset( $dashboard_tabs[ $stat_tab ] ) ) { continue; } ?>
<?php
$stat_count = 'posts' === $stat_tab
? $post_count
: ( 'comments' === $stat_tab ? $comment_count : $favorite_count );
?>
<a class="uc-stats__item" href="<?php echo esc_url( add_query_arg( 'tab', $stat_tab, remove_query_arg( 'tab' ) ) ); ?>">
<span class="uc-stats__value"><?php echo esc_html( (string) $stat_count ); ?></span>
<span class="uc-stats__label"><?php echo esc_html( $dashboard_tabs[ $stat_tab ]['label'] ); ?></span>
</a>
<?php endforeach; ?>
<a class="uc-stats__item" href="<?php echo esc_url( $messages_url ); ?>">
<span class="uc-stats__value"><?php echo esc_html( (string) $notification_unread_count ); ?></span>
<span class="uc-stats__label"><?php esc_html_e( '通知', 'aksrt' ); ?></span>
</a>
</div>
</div>
<!-- 我的服务 -->
<div class="uc-sidebar__section">
<div class="uc-sidebar__title"><?php esc_html_e( '我的服务', 'aksrt' ); ?></div>
<div class="uc-sidebar__buttons">
<?php foreach ( $dashboard_tabs as $tab_key => $tab ) : ?>
<a class="uc-sidebar__btn<?php echo $active_tab === $tab_key ? ' is-active' : ''; ?>" href="<?php echo esc_url(aksrt_get_user_center_tab_url($tab_key)); ?>" data-tab="<?php echo esc_attr($tab_key); ?>">
<i class="fas fa-<?php echo esc_attr( $tab['icon'] ); ?>" aria-hidden="true"></i>
<span><?php echo esc_html( $tab['label'] ); ?></span>
</a>
<?php endforeach; ?>
<a href="<?php echo esc_url( $messages_url ); ?>" class="uc-sidebar__btn">
<i class="fas fa-bell" aria-hidden="true"></i>
<span><?php esc_html_e( '消息通知', 'aksrt' ); ?></span>
<?php if ( $notification_unread_count > 0 ) : ?>
<span class="uc-sidebar__badge"><?php echo esc_html( (string) $notification_unread_count ); ?></span>
<?php endif; ?>
</a>
</div>
</div>
<!-- 交易服务 -->
<?php if ($orders_url || $show_vip || $show_credit_tabs) : ?>
<div class="uc-sidebar__section">
<div class="uc-sidebar__title"><?php esc_html_e('权益与消费', 'aksrt'); ?></div>
<div class="uc-sidebar__buttons">
<?php if ($orders_url) : ?>
<a href="<?php echo esc_url($orders_url); ?>" class="uc-sidebar__btn">
<i class="fas fa-receipt" aria-hidden="true"></i>
<span><?php esc_html_e('我的订单', 'aksrt'); ?></span>
</a>
<?php endif; ?>
<?php if ($show_vip) : ?>
<a class="uc-sidebar__btn<?php echo $active_tab === 'credits' ? ' is-active' : ''; ?>" href="<?php echo esc_url(aksrt_get_user_center_tab_url('credits')); ?>" data-tab="credits">
<i class="fas fa-crown" aria-hidden="true"></i>
<span><?php esc_html_e('VIP 会员', 'aksrt'); ?></span>
</a>
<?php endif; ?>
<?php if ($show_credit_tabs) : ?>
<a class="uc-sidebar__btn<?php echo $active_tab === 'credits' ? ' is-active' : ''; ?>" href="<?php echo esc_url(aksrt_get_user_center_tab_url('credits')); ?>" data-tab="credits">
<i class="fas fa-coins" aria-hidden="true"></i>
<span><?php echo esc_html($currency_name); ?></span>
</a>
<?php endif; ?>
<?php if ($affiliate_enabled) : ?>
<a class="uc-sidebar__btn<?php echo $active_tab === 'credits' ? ' is-active' : ''; ?>" href="<?php echo esc_url(aksrt_get_user_center_tab_url('credits')); ?>" data-tab="credits">
<i class="fas fa-share-alt" aria-hidden="true"></i>
<span><?php esc_html_e('推广返佣', 'aksrt'); ?></span>
</a>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
<!-- 功能设置 -->
<!-- 移动端抽屉触发器 -->
<button type="button" class="uc-sidebar__drawer-trigger" id="uc-drawer-trigger" aria-label="<?php esc_attr_e( '打开导航', 'aksrt' ); ?>">
<i class="fas fa-bars" aria-hidden="true"></i>
</button>
<button type="button" class="uc-sidebar__drawer-trigger" id="uc-drawer-trigger" aria-label="<?php esc_attr_e('打开导航', 'aksrt'); ?>">
<i class="fas fa-bars" aria-hidden="true"></i>
</button>
@@ -0,0 +1,44 @@
<?php
/**
* User center sidebar: rights / commerce shortcuts.
*
* Expects extracted $context vars.
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
if (empty($orders_url) && empty($show_vip) && empty($show_credit_tabs)) {
return;
}
?>
<div class="uc-sidebar__section">
<div class="uc-sidebar__title"><?php esc_html_e('权益与消费', 'aksrt'); ?></div>
<div class="uc-sidebar__buttons">
<?php if ($orders_url) : ?>
<a href="<?php echo esc_url($orders_url); ?>" class="uc-sidebar__btn">
<i class="fas fa-receipt" aria-hidden="true"></i>
<span><?php esc_html_e('我的订单', 'aksrt'); ?></span>
</a>
<?php endif; ?>
<?php if ($show_vip) : ?>
<a class="uc-sidebar__btn<?php echo $active_tab === 'credits' ? ' is-active' : ''; ?>" href="<?php echo esc_url(aksrt_get_user_center_tab_url('credits')); ?>" data-tab="credits">
<i class="fas fa-crown" aria-hidden="true"></i>
<span><?php esc_html_e('VIP 会员', 'aksrt'); ?></span>
</a>
<?php endif; ?>
<?php if ($show_credit_tabs) : ?>
<a class="uc-sidebar__btn<?php echo $active_tab === 'credits' ? ' is-active' : ''; ?>" href="<?php echo esc_url(aksrt_get_user_center_tab_url('credits')); ?>" data-tab="credits">
<i class="fas fa-coins" aria-hidden="true"></i>
<span><?php echo esc_html($currency_name); ?></span>
</a>
<?php endif; ?>
<?php if (!empty($affiliate_enabled)) : ?>
<a class="uc-sidebar__btn<?php echo $active_tab === 'credits' ? ' is-active' : ''; ?>" href="<?php echo esc_url(aksrt_get_user_center_tab_url('credits')); ?>" data-tab="credits">
<i class="fas fa-share-alt" aria-hidden="true"></i>
<span><?php esc_html_e('推广返佣', 'aksrt'); ?></span>
</a>
<?php endif; ?>
</div>
</div>
@@ -0,0 +1,29 @@
<?php
/**
* User center sidebar: main service navigation.
*
* Expects extracted $context vars.
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
?>
<div class="uc-sidebar__section">
<div class="uc-sidebar__title"><?php esc_html_e('我的服务', 'aksrt'); ?></div>
<div class="uc-sidebar__buttons">
<?php foreach ($dashboard_tabs as $tab_key => $tab) : ?>
<a class="uc-sidebar__btn<?php echo $active_tab === $tab_key ? ' is-active' : ''; ?>" href="<?php echo esc_url(aksrt_get_user_center_tab_url($tab_key)); ?>" data-tab="<?php echo esc_attr($tab_key); ?>">
<i class="fas fa-<?php echo esc_attr($tab['icon']); ?>" aria-hidden="true"></i>
<span><?php echo esc_html($tab['label']); ?></span>
</a>
<?php endforeach; ?>
<a href="<?php echo esc_url($messages_url); ?>" class="uc-sidebar__btn">
<i class="fas fa-bell" aria-hidden="true"></i>
<span><?php esc_html_e('消息通知', 'aksrt'); ?></span>
<?php if ($notification_unread_count > 0) : ?>
<span class="uc-sidebar__badge"><?php echo esc_html((string) $notification_unread_count); ?></span>
<?php endif; ?>
</a>
</div>
</div>
@@ -0,0 +1,32 @@
<?php
/**
* User center sidebar: stats section.
*
* Expects extracted $context vars.
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
?>
<div class="uc-sidebar__section">
<div class="uc-sidebar__title"><?php esc_html_e('数据统计', 'aksrt'); ?></div>
<div class="uc-stats">
<?php foreach (['posts', 'comments', 'favorites'] as $stat_tab) : ?>
<?php if (!isset($dashboard_tabs[$stat_tab])) { continue; } ?>
<?php
$stat_count = 'posts' === $stat_tab
? $post_count
: ('comments' === $stat_tab ? $comment_count : $favorite_count);
?>
<a class="uc-stats__item" href="<?php echo esc_url(add_query_arg('tab', $stat_tab, remove_query_arg('tab'))); ?>">
<span class="uc-stats__value"><?php echo esc_html((string) $stat_count); ?></span>
<span class="uc-stats__label"><?php echo esc_html($dashboard_tabs[$stat_tab]['label']); ?></span>
</a>
<?php endforeach; ?>
<a class="uc-stats__item" href="<?php echo esc_url($messages_url); ?>">
<span class="uc-stats__value"><?php echo esc_html((string) $notification_unread_count); ?></span>
<span class="uc-stats__label"><?php esc_html_e('通知', 'aksrt'); ?></span>
</a>
</div>
</div>
+8 -6
View File
@@ -7,12 +7,14 @@
- aksrt_user_center_resolve_tabs()
- aksrt_capture_user_center_view() (profile → form 映射)
- 挂载点:header / sidebar / mobile-tabs / panel / account-modals / runtime-config
- 渲染器:inc/helpers/user-center-renderers/
- profile-form / posts / comments / favorites / header / sidebar / account-modals
- profile-credits.php 编排:
credits-balance / credits-vip / credits-signin / credits-transactions
- profile-settings.php 编排:
settings-bindings / settings-security / settings-invite / settings-runtime-fields
渲染器(inc/helpers/user-center-renderers/):
- profile-form.php → form-contacts.php
- profile-posts.php → posts-status-filter.php + posts-list.php
- profile-sidebar.php → sidebar-stats/nav/commerce.php
- profile-credits.php → credits-balance/vip/signin/transactions.php
- profile-settings.php → settings-bindings/security/invite/runtime-fields.php
- profile-header / comments / favorites / account-modals
样式归属:
- assets/css/routes/user-center.css