esc_html__('显示最新评论列表', 'aksrt'), ]); } public static function render_html(array $instance): string { $count = max(1, min(20, (int) ($instance['count'] ?? $instance['limit'] ?? 5))); $show_avatar = !isset($instance['show_avatar']) || !empty($instance['show_avatar']); $outpost = max(0, (int) ($instance['outpost'] ?? 0)); $outer = sanitize_text_field((string) ($instance['outer'] ?? '')); $query = [ 'number' => $count, 'status' => 'approve', 'post_status' => 'publish', ]; if ($outpost > 0) { $query['post__not_in'] = [$outpost]; } $comments = get_comments($query); if ($outer !== '' && $comments) { $keys = array_filter(array_map('trim', preg_split('/[,,]/', $outer) ?: [])); if ($keys) { $comments = array_values(array_filter($comments, static function ($c) use ($keys) { $body = (string) $c->comment_content; foreach ($keys as $k) { if ($k !== '' && str_contains($body, $k)) { return false; } } return true; })); } } if (!$comments) { return '
'; } ob_start(); echo '
sanitize_text_field((string) ($new_instance['title'] ?? '')), 'count' => max(1, min(20, (int) ($new_instance['count'] ?? 5))), 'show_avatar' => !empty($new_instance['show_avatar']) ? 1 : 0, 'outpost' => max(0, (int) ($new_instance['outpost'] ?? 0)), 'outer' => sanitize_text_field((string) ($new_instance['outer'] ?? '')), ]; } }
' . esc_html(wp_trim_words($comment->comment_content, 15, '...')) . '
'; echo '