$settings Settings.
* @return string
*/
function aksrt_get_comment_header_html(WP_Comment $comment, array $settings = []): string {
$like_enabled = !isset($settings['like_enabled']) || !empty($settings['like_enabled']);
$avatar = aksrt_get_comment_avatar_box($comment, 'avatar-img comt-avatar');
$name = aksrt_get_comments_user_name_html($comment, $settings);
$like = aksrt_get_comment_like_html($comment, $like_enabled);
$html = '';
$html .= $avatar;
$html .= $name;
$html .= $like;
$html .= '
';
return '';
}
endif;
if (!function_exists('aksrt_get_comments_action_dropdown_html')) :
/**
* More-actions menu (zibll: zib_get_comments_action_list) — pin / edit / approve / delete.
*
* @param WP_Comment $comment Comment.
* @param int $depth Depth.
* @return string
*/
function aksrt_get_comments_action_dropdown_html(WP_Comment $comment, int $depth = 0): string {
$perms = function_exists('aksrt_comment_action_permissions')
? aksrt_comment_action_permissions($comment)
: ['can_edit' => false, 'can_delete' => false, 'can_moderate' => false, 'can_pin' => false];
$is_pinned = function_exists('aksrt_is_comment_pinned') && aksrt_is_comment_pinned($comment);
$is_pending = '0' === (string) $comment->comment_approved;
$lists = '';
if (!empty($perms['can_pin']) && (int) $comment->comment_parent === 0) {
$label = $is_pinned ? __('取消置顶', 'aksrt') : __('设置置顶', 'aksrt');
$lists .= '';
}
if (!empty($perms['can_edit'])) {
$lists .= '';
}
if (!empty($perms['can_moderate'])) {
$text = $is_pending ? __('批准', 'aksrt') : __('驳回', 'aksrt');
$class = $is_pending ? 'approve' : 'unapprove';
$action = $is_pending ? 'approve' : 'hold';
$lists .= '';
}
if (!empty($perms['can_delete'])) {
$lists .= '';
}
if ($lists === '') {
return '';
}
$icon_a = '';
return '' . $icon_a . '';
}
endif;
if (!function_exists('aksrt_get_comment_footer_html')) :
/**
* comt-meta row (zibll: zib_get_comment_footer).
*
* @param WP_Comment $comment Comment.
* @param array $args wp_list_comments args.
* @param int $depth Depth.
* @param array $settings Settings.
* @return string
*/
function aksrt_get_comment_footer_html(WP_Comment $comment, array $args, int $depth, array $settings = []): string {
$is_pending = '0' === (string) $comment->comment_approved;
$badg_approve = '';
if ($is_pending) {
$badg_approve = '' . esc_html__('待审核', 'aksrt') . '';
}
$badg_approve = '' . $badg_approve . '';
$absolute = date_i18n(__('Y年m月d日 H:i:s', 'aksrt'), strtotime((string) $comment->comment_date));
$ago = function_exists('aksrt_time_ago')
? aksrt_time_ago((string) $comment->comment_date)
: human_time_diff(strtotime((string) $comment->comment_date), current_time('timestamp')) . __('前', 'aksrt');
$time_html = '' . esc_html($ago) . '';
$city_html = function_exists('aksrt_get_comment_city_badge_html')
? aksrt_get_comment_city_badge_html($comment)
: '';
$parent_html = '';
if ((int) $comment->comment_parent > 0) {
$parent_author = get_comment_author((int) $comment->comment_parent);
$parent_html = '@' . esc_html($parent_author) . '';
}
$reply_html = '';
if (!$is_pending && $depth > 0) {
$max_depth = (int) ($args['max_depth'] ?? get_option('thread_comments_depth', 5));
$link = get_comment_reply_link(
[
'add_below' => 'div-comment',
'reply_text' => __('回复', 'aksrt'),
'login_text' => __('回复', 'aksrt'),
'depth' => $depth,
'max_depth' => $max_depth,
],
$comment
);
if ($link) {
// 去掉 WP 内联 onclick(addComment.moveForm),回复由 comment-move-form.js 事件委托处理。
$link = preg_replace('/ onclick="[^"]*"/i', '', $link);
if (strpos($link, 'data-commentid') === false) {
$link = str_replace(
'comment-reply-link',
'comment-reply-link" data-commentid="' . (int) $comment->comment_ID . '" data-postid="' . (int) $comment->comment_post_ID,
$link
);
}
$reply_html = '' . $link . '';
}
}
$actions = aksrt_get_comments_action_dropdown_html($comment, $depth);
$info = $time_html . $city_html . $parent_html . $badg_approve . $reply_html;
return '' . $info . $actions . '
';
}
endif;
if (!function_exists('aksrt_get_comments_list_html')) :
/**
* Single comment item HTML (zibll: zib_get_comments_list).
*
* @param WP_Comment $comment Comment.
* @param array $args Args.
* @param int $depth Depth.
* @param array $settings Settings.
* @return string
*/
function aksrt_get_comments_list_html(WP_Comment $comment, array $args = [], int $depth = 0, array $settings = []): string {
$comment_id = (int) $comment->comment_ID;
$con = function_exists('aksrt_render_comment_content')
? aksrt_render_comment_content((string) get_comment_text($comment))
: wp_kses_post((string) get_comment_text($comment));
$header = aksrt_get_comment_header_html($comment, $settings);
$footer = aksrt_get_comment_footer_html($comment, $args, $depth, $settings);
$html = ' is emitted by the walker after children.
*
* @param WP_Comment $comment Comment.
* @param array $args Args.
* @param int $depth Depth.
*/
function aksrt_comment_callback($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;
$settings = get_query_var('aksrt_comment_settings', []);
$settings = is_array($settings) ? $settings : [];
if (empty($settings) && class_exists('\AKSRT\Settings\Settings')) {
$settings = \AKSRT\Settings\Settings::get_comment_display_settings();
}
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- composed helpers escape.
echo aksrt_get_comments_list_html($comment, is_array($args) ? $args : [], (int) $depth, $settings);
}
endif;