删除评论模块

This commit is contained in:
2026-03-04 01:19:38 +08:00
parent 7723b1c0ba
commit 7217c0f0c2
4 changed files with 41 additions and 394 deletions
-240
View File
@@ -412,12 +412,6 @@
.single-related-empty { .single-related-empty {
color: var(--text-secondary); color: var(--text-secondary);
} }
.single-article-comments {
max-width: 900px;
margin: 64px auto 0;
}
@media (max-width: 980px) { @media (max-width: 980px) {
.single-article-page { .single-article-page {
padding: 34px 0 56px; padding: 34px 0 56px;
@@ -468,10 +462,6 @@
grid-template-columns: 1fr; grid-template-columns: 1fr;
gap: 20px; gap: 20px;
} }
.single-article-comments {
margin-top: 48px;
}
} }
/* ========================================= /* =========================================
@@ -606,236 +596,6 @@
border-top: 1px solid var(--border-muted); border-top: 1px solid var(--border-muted);
} }
/* --- Comments Section (Pro Timeline) --- */
.gh-pro-comments {
max-width: 900px;
margin: 0 auto;
}
.timeline-header h3 {
font-size: 1.25rem;
margin-bottom: 24px;
border-bottom: 1px solid var(--border-default);
padding-bottom: 8px;
}
/* Reuse existing gh-timeline styles from previous step but center align */
.gh-timeline {
margin-top: 0;
margin-left: 0; /* Clear previous offset */
}
/* Vertical Timeline Line - NEW FIX */
.gh-timeline::before {
content: "";
position: absolute;
top: 0;
bottom: 0;
left: 20px; /* Center of 40px avatar */
width: 2px;
background-color: var(--border-muted);
z-index: 0;
display: block; /* Ensure it is displayed */
}
/* Fix z-index for items so line is behind */
.gh-timeline-item {
position: relative;
z-index: 1;
}
ol.comment-list {
list-style: none; /* 去掉列表默认样式 */
padding: 0;
margin: 0;
}
/* Timeline Item (Main Post & Comments) */
.gh-timeline-item,
.gh-comment-item {
display: flex;
gap: 16px;
margin-bottom: 24px;
position: relative;
z-index: 1;
}
/* Avatar Column */
.gh-avatar,
.gh-comment-avatar {
flex-shrink: 0;
width: 40px;
}
.gh-avatar img,
.gh-comment-avatar img {
width: 40px;
height: 40px;
border-radius: 50%;
border: 1px solid var(--border-muted);
}
/* Content Box (Speech Bubble) */
.gh-item-box,
.gh-comment-box {
flex-grow: 1;
min-width: 0;
border: 1px solid var(--border-default);
border-radius: 6px;
background-color: var(--bg-card);
position: relative;
}
/* Speech Bubble Beak (Arrow) - Desktop Only */
@media (min-width: 768px) {
.gh-item-box::before, .gh-item-box::after,
.gh-comment-box::before, .gh-comment-box::after {
content: " ";
position: absolute;
top: 11px;
right: 100%;
height: 0;
width: 0;
border: solid transparent;
pointer-events: none;
}
.gh-item-box::after,
.gh-comment-box::after {
border-right-color: var(--bg-surface); /* Header BG color */
border-width: 7px;
margin-top: -7px;
}
.gh-item-box::before,
.gh-comment-box::before {
border-right-color: var(--border-default);
border-width: 8px;
margin-top: -8px;
}
}
/* Box Header */
.gh-box-header,
.gh-comment-header {
padding: 8px 16px;
background-color: var(--bg-surface);
border-bottom: 1px solid var(--border-default);
border-top-left-radius: 6px;
border-top-right-radius: 6px;
display: flex;
justify-content: space-between;
align-items: center;
font-size: 14px;
color: var(--text-secondary);
}
.gh-header-meta {
display: flex;
align-items: center;
gap: 4px;
flex-wrap: wrap;
}
.gh-comment-meta,
.gh-header-meta {
display: flex;
align-items: center;
gap: 4px;
flex-wrap: wrap;
}
.gh-header-meta strong,
.gh-author-name a {
color: var(--text-primary);
font-weight: 600;
text-decoration: none;
}
.gh-header-meta a,
.gh-comment-meta time,
.gh-comment-meta a {
color: var(--text-secondary);
text-decoration: none;
font-size: 0.85rem;
}
.gh-header-meta a:hover,
.gh-comment-meta time:hover,
.gh-comment-meta a:hover {
color: var(--color-primary);
text-decoration: underline;
}
/* Badge (Author/Member) */
.gh-badge {
display: inline-block;
padding: 2px 7px;
font-size: 12px;
font-weight: 500;
line-height: 18px;
border-radius: 2em;
border: 1px solid var(--border-default);
color: var(--text-secondary);
margin-left: 8px;
}
/* Box Body */
.gh-box-body,
.gh-comment-body {
padding: 16px;
background-color: var(--bg-card);
border-bottom-left-radius: 6px;
border-bottom-right-radius: 6px;
overflow-wrap: break-word;
}
.gh-box-body .entry-content,
.gh-comment-body {
font-size: 15px;
line-height: 1.6;
}
/* Comment Form Styles */
.gh-comment-form textarea {
display: block;
width: 100%;
padding: 8px 12px;
border: 1px solid var(--border-default);
border-radius: 6px;
background-color: var(--bg-surface);
color: var(--text-primary);
font-family: inherit;
resize: vertical;
min-height: 100px;
}
.gh-comment-form textarea:focus {
border-color: var(--color-primary);
outline: none;
box-shadow: 0 0 0 3px rgba(9, 105, 218, 0.3);
}
.form-submit {
text-align: right;
margin-top: 10px;
}
.gh-comment-form input[type="submit"] {
background-color: var(--color-success);
color: #fff;
border: 1px solid rgba(27, 31, 36, 0.15);
border-radius: 6px;
padding: 5px 16px;
font-size: 14px;
font-weight: 600;
cursor: pointer;
}
.gh-comment-form input[type="submit"]:hover {
background-color: #2c974b;
}
/* Buttons */ /* Buttons */
.btn-sm { .btn-sm {
font-size: 12px; font-size: 12px;
-66
View File
@@ -1,66 +0,0 @@
<?php
if (post_password_required()) {
return;
}
?>
<div id="comments" class="comments-area">
<?php if (have_comments()) : ?>
<div class="comments-header">
<h3 class="comments-title">
<?php
$comment_count = get_comments_number();
if ($comment_count === 1) {
printf(esc_html__('1个回复', 'itstudio'));
} else {
printf(
/* translators: 1: comment count number */
esc_html(_n('%1$s个回复', '%1$s个回复', $comment_count, 'itstudio')),
number_format_i18n($comment_count)
);
}
?>
</h3>
</div>
<ol class="comment-list">
<?php
wp_list_comments(array(
'style' => 'ol',
'short_ping' => true,
'avatar_size' => 48,
'callback' => 'itstudio_comment_callback' // We will need to define this in functions.php or handle logic here if simple
));
?>
</ol>
<?php
the_comments_navigation();
// If comments are closed and there are comments, let's leave a little note, shall we?
if (!comments_open()) :
?>
<p class="no-comments"><?php esc_html_e('评论已关闭。', 'itstudio'); ?></p>
<?php
endif;
endif; // Check for have_comments().
?>
<div class="comment-form-wrapper">
<?php
comment_form(array(
'class_form' => 'gh-comment-form',
'title_reply_before' => '<h3 id="reply-title" class="comment-reply-title" data-cn="发表回复" data-en="Leave a comment">',
'title_reply_after' => '</h3>',
'title_reply' => '', // Handled by data-cn/en in before tag
'label_submit' => __('发表评论', 'itstudio'), // This submits button text, harder to change via attr, usually needs JS or just leave as is if acceptable
'submit_button' => '<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="" data-cn="发表评论" data-en="Comment" />',
'comment_notes_before' => '',
'comment_field' => '<div class="comment-form-comment"><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></div>',
));
?>
</div>
</div><!-- #comments -->
+41 -77
View File
@@ -6,8 +6,6 @@ function itstudio_theme_setup() {
add_theme_support('automatic-feed-links'); add_theme_support('automatic-feed-links');
add_theme_support('html5', array( add_theme_support('html5', array(
'search-form', 'search-form',
'comment-form',
'comment-list',
'gallery', 'gallery',
'caption', 'caption',
)); ));
@@ -20,6 +18,47 @@ function itstudio_theme_setup() {
} }
add_action('after_setup_theme', 'itstudio_theme_setup'); add_action('after_setup_theme', 'itstudio_theme_setup');
add_filter('comments_open', '__return_false', 20, 2);
add_filter('pings_open', '__return_false', 20, 2);
add_filter('comments_array', '__return_empty_array', 10, 2);
function itstudio_disable_comments_post_types() {
$post_types = array('post', 'page', 'announcement', 'news');
foreach ($post_types as $post_type) {
if (post_type_supports($post_type, 'comments')) {
remove_post_type_support($post_type, 'comments');
}
if (post_type_supports($post_type, 'trackbacks')) {
remove_post_type_support($post_type, 'trackbacks');
}
}
}
add_action('init', 'itstudio_disable_comments_post_types', 100);
function itstudio_hide_comments_menu() {
remove_menu_page('edit-comments.php');
}
add_action('admin_menu', 'itstudio_hide_comments_menu', 999);
function itstudio_hide_admin_bar_comments() {
remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60);
}
add_action('init', 'itstudio_hide_admin_bar_comments');
function itstudio_redirect_comments_admin_pages() {
global $pagenow;
if ($pagenow === 'edit-comments.php' || $pagenow === 'comment.php') {
wp_safe_redirect(admin_url());
exit;
}
}
add_action('admin_init', 'itstudio_redirect_comments_admin_pages');
function itstudio_remove_comments_dashboard_widget() {
remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
}
add_action('wp_dashboard_setup', 'itstudio_remove_comments_dashboard_widget');
function itstudio_apply_site_identity() { function itstudio_apply_site_identity() {
$site_name = base64_decode('54ix54m55bel5L2c5a6k'); $site_name = base64_decode('54ix54m55bel5L2c5a6k');
$site_tagline = base64_decode('54ix54m55bel5L2c5a6k5a6Y5pa5572R56uZ'); $site_tagline = base64_decode('54ix54m55bel5L2c5a6k5a6Y5pa5572R56uZ');
@@ -330,81 +369,6 @@ function itstudio_news_fallback() {
} }
add_action('template_redirect', 'itstudio_news_fallback'); add_action('template_redirect', 'itstudio_news_fallback');
/**
* GitHub 风格评论
*/
function itstudio_comment_callback($comment, $args, $depth) {
?>
<li id="comment-<?php comment_ID(); ?>" <?php comment_class('gh-comment-item'); ?>>
<div class="gh-comment-avatar">
<?php if ($args['avatar_size'] != 0) echo get_avatar($comment, $args['avatar_size']); ?>
</div>
<div class="gh-comment-box">
<div class="gh-comment-header">
<div class="gh-comment-meta">
<span class="gh-author-name"><?php echo get_comment_author_link(); ?></span>
<!-- 双语支持: commented on / 评论于 -->
<span class="gh-action-text" data-cn="评论于" data-en="commented on"></span>
<a href="<?php echo htmlspecialchars(get_comment_link($comment->comment_ID)); ?>">
<time datetime="<?php comment_time('c'); ?>">
<?php
// 处理时间双语
$time_diff = human_time_diff(get_comment_time('U'), current_time('timestamp'));
// 简单的替换逻辑,或者直接输出两个 span
printf(
'<span data-cn="%s前" data-en="%s ago"></span>',
$time_diff, // 中文环境通常也是数字+单位(如 5 分钟),这里简化处理,假设 time_diff 本身已本地化或接受英文
$time_diff
);
// 注意:WP的 human_time_diff 返回的是翻译后的字符串(如果后台是中文),
// 要实现完美的前端双语切换,需要一种不依赖后台语言设置的方式,或者接受后台返回当前语言的时间。
// 鉴于切换是纯前端的,最佳方式是让 PHP 输出特定格式,前端解析,但这里为了简单,
// 我们假设 time_diff 主要是数字+单位。
// 更稳妥的方式是直接显示标准日期格式,或者接受当前状态。
// 这里先简单处理结构。
?>
</time>
</a>
<?php
// Author Badge
$post = get_post();
if ($comment->user_id === $post->post_author) {
// 双语支持: Author / 作者
echo '<span class="gh-badge author" data-cn="作者" data-en="Author"></span>';
}
?>
</div>
<div class="gh-header-actions">
<?php edit_comment_link('', '', '', null, 'gh-edit-link'); /* 获取链接URL逻辑较复杂,这里直接用 edit_comment_link 输出,但内容需要自定义 */ ?>
<span class="edit-link-wrapper">
<?php
// 为了支持双语,我们不仅需要 URL,还需要在这里手动构造 A 标签,或者利用 PHP 里的 filter
// 但 edit_comment_link 直接输出 HTML。
// 简单方案:输出时内容留空,用 CSS 伪元素填充。
// edit_comment_link( $text, $before, $after )
// 我们可以把 $text 设为空字符串,并给 wrapper 加 data 属性? 不行,A标签内部是空的。
// 我们可以让 A 标签带上 data 属性吗? edit_comment_link 没有直接参数加属性到 A 标签。
// 替代方案:手动构建
if (current_user_can('edit_comment', $comment->comment_ID)) {
$edit_url = get_edit_comment_link($comment->comment_ID);
echo '<a class="comment-edit-link" href="' . esc_url($edit_url) . '" data-cn="编辑" data-en="Edit"></a>';
}
?>
</span>
</div>
</div>
<div class="gh-comment-body">
<?php if ($comment->comment_approved == '0') : ?>
<em class="comment-awaiting-moderation" data-cn="您的评论正在等待审核。" data-en="Your comment is awaiting moderation."></em>
<br />
<?php endif; ?>
<?php comment_text(); ?>
</div>
</div>
</li>
<?php
}
function itstudio_get_post_views($post_id) { function itstudio_get_post_views($post_id) {
$post_id = (int) $post_id; $post_id = (int) $post_id;
if ($post_id <= 0) { if ($post_id <= 0) {
-11
View File
@@ -122,17 +122,6 @@
</div> </div>
</section> </section>
<?php if (comments_open() || get_comments_number()) : ?>
<section class="single-article-comments gh-pro-comments">
<div class="timeline-header">
<h3 data-cn="文章讨论" data-en="Discussion"></h3>
</div>
<div class="gh-timeline">
<?php comments_template(); ?>
</div>
</section>
<?php endif; ?>
<?php endwhile; ?> <?php endwhile; ?>
</div> </div>
</main> </main>