comment_ID : (int) $comment; if ($comment_id <= 0) { return ''; } $like_count = function_exists('aksrt_get_comment_likes') ? (int) aksrt_get_comment_likes($comment_id) : 0; $is_liked = function_exists('aksrt_is_comment_liked') && aksrt_is_comment_liked($comment_id); $classes = 'action action-comment-like muted-2-color flex0 ml10' . ($is_liked ? ' actived' : ''); return sprintf( '%5$s', esc_attr($classes), $comment_id, $is_liked ? '1' : '0', $is_liked ? 'true' : 'false', esc_html((string) $like_count) ); } endif; if (!function_exists('aksrt_get_comment_avatar_box')) : /** * Comment avatar box (zibll: zib_get_comment_avatar_box). * * @param WP_Comment $comment Comment. * @param string $class Classes for the avatar wrapper. * @param bool $link Wrap in a link when a target URL exists. * @return string */ function aksrt_get_comment_avatar_box(WP_Comment $comment, string $class = 'avatar-img comt-avatar', bool $link = true): string { $user_id = (int) $comment->user_id; $size = 45; $avatar = $user_id > 0 ? get_avatar($user_id, $size, '', '', ['class' => 'avatar']) : get_avatar($comment->comment_author_email, $size, '', '', ['class' => 'avatar']); $html = '' . $avatar . ''; if (!$link) { return $html; } if ($user_id > 0) { $url = function_exists('aksrt_get_user_home_url') ? aksrt_get_user_home_url($user_id) : get_author_posts_url($user_id); return '' . $html . ''; } if (!empty($comment->comment_author_url)) { return '' . $html . ''; } return $html; } endif; if (!function_exists('aksrt_get_comments_user_name_html')) : /** * Name row (zibll: zib_get_comments_user_name) — topping + author + badges. * * @param WP_Comment $comment Comment. * @param array $settings Display settings. * @return string */ function aksrt_get_comments_user_name_html(WP_Comment $comment, array $settings = []): string { $user_id = (int) $comment->user_id; $show_author_tag = !isset($settings['author_tag']) || !empty($settings['author_tag']); $is_pinned = function_exists('aksrt_is_comment_pinned') && aksrt_is_comment_pinned($comment); $is_post_author = $user_id > 0 && $user_id === (int) get_post_field('post_author', $comment->comment_post_ID); $topping = ''; if ($is_pinned) { $topping = ''; } $user_name = ''; if ($user_id > 0) { $user = get_userdata($user_id); if ($user instanceof WP_User) { $url = function_exists('aksrt_get_user_home_url') ? aksrt_get_user_home_url($user_id) : get_author_posts_url($user_id); $user_name = '' . esc_html($user->display_name) . ''; if (function_exists('aksrt_render_user_identity_chips')) { $user_name .= aksrt_render_user_identity_chips($user_id, 'comment'); } } } elseif (!empty($comment->comment_author_url)) { $user_name = '' . esc_html($comment->comment_author) . ''; } $user_name = $user_name !== '' ? $user_name : '' . esc_html($comment->comment_author) . ''; $badge = ''; if ($show_author_tag && $is_post_author) { $badge .= '' . esc_html__('作者', 'aksrt') . ''; } return '' . $topping . $user_name . $badge . ''; } endif; if (!function_exists('aksrt_get_comment_header_html')) : /** * Comment header (zibll: zib_get_comment_header). * * @param WP_Comment $comment Comment. * @param array $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 '
' . $html . '
'; } 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 .= '
  • ' . esc_html($label) . '
  • '; } if (!empty($perms['can_edit'])) { $lists .= '
  • ' . esc_html__('编辑', 'aksrt') . '
  • '; } if (!empty($perms['can_moderate'])) { $text = $is_pending ? __('批准', 'aksrt') : __('驳回', 'aksrt'); $class = $is_pending ? 'approve' : 'unapprove'; $action = $is_pending ? 'approve' : 'hold'; $lists .= '
  • ' . esc_html($text) . '
  • '; } if (!empty($perms['can_delete'])) { $lists .= '
  • ' . esc_html__('删除', 'aksrt') . '
  • '; } 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 = '
  • '; $html .= '
      '; $html .= '
    • '; $html .= $header; $html .= ''; $html .= '
    • '; $html .= '
    '; return $html; } endif; if (!function_exists('aksrt_comment_callback')) : /** * Canonical wp_list_comments callback (zibll: zib_comments_list). * * The closing
  • 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;