用户中心 posts/sidebar/form 渲染器整包拆分并清理标记
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user