61 lines
2.0 KiB
PHP
61 lines
2.0 KiB
PHP
<?php
|
|
/**
|
|
* Public user home — comments tab panel body.
|
|
*
|
|
* Rendered inside the #panel-comments wrapper on the public user home and via
|
|
* the aksrt/v1 user-home panel REST fragment. Later pages append through the
|
|
* existing REST route and never touch the URL.
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
$args = is_array($args ?? null) ? $args : [];
|
|
extract($args, EXTR_SKIP); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
|
|
|
|
$is_own_profile = !empty($is_own_profile);
|
|
$comments_page = max(1, (int) $comments_page);
|
|
$per_page = max(1, (int) $per_page);
|
|
$comment_offset = ($comments_page - 1) * $per_page;
|
|
$comment_status = $is_own_profile ? 'all' : 'approve';
|
|
$comment_args = [
|
|
'user_id' => (int) $user_id,
|
|
'status' => $comment_status,
|
|
'type' => 'comment',
|
|
'post_type' => ['post'],
|
|
'orderby' => 'comment_date_gmt',
|
|
'order' => 'DESC',
|
|
'update_comment_meta_cache' => false,
|
|
];
|
|
$user_comments = get_comments(array_merge($comment_args, [
|
|
'number' => $per_page,
|
|
'offset' => $comment_offset,
|
|
]));
|
|
$comments_total = (int) get_comments(array_merge($comment_args, ['count' => true]));
|
|
$has_more = $comments_total > ($comment_offset + count($user_comments));
|
|
|
|
if ($user_comments) :
|
|
?>
|
|
<div class="profile-comment-list">
|
|
<?php foreach ($user_comments as $c) : ?>
|
|
<?php
|
|
get_template_part('templates/parts/content', 'profile-comment-item', [
|
|
'comment' => $c,
|
|
]);
|
|
?>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php if ($has_more) : ?>
|
|
<div class="profile-comment-more text-center theme-pagination ajax-pag">
|
|
<div class="next-page ajax-next">
|
|
<button type="button" data-uh-comments-next="<?php echo esc_attr((string) ($comments_page + 1)); ?>">
|
|
<?php esc_html_e('加载更多', 'aksrt'); ?>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php else : ?>
|
|
<?php aksrt_render_profile_empty($svg_empty_comment, __('TA 还没有发表评论', 'aksrt')); ?>
|
|
<?php endif; ?>
|