fix(theme): align reference layouts and restore passing contracts

Align homepage and category discovery, modern widgets, admin controls, quotes, and comments with the reference theme. Remove superseded paths and add rendering and behavior coverage. Update stale asset and finance contracts; all 760 Node tests and 139 widget assertions pass.
This commit is contained in:
kate522 committed 2026-10-29 19:16:03 +08:00
1 parent b520d29368
commit 8aa116ec43
63 files changed
+1985 -2304

No files matched your search

+26 -97
View File
@@ -20,21 +20,15 @@ if (!function_exists('aksrt_comments_template_query_args')) :
$order = isset($_GET['aksrt_comment_order'])
? sanitize_key((string) wp_unslash($_GET['aksrt_comment_order']))
: '';
if ($order === '') {
$settings = class_exists('\AKSRT\Settings\Settings')
? \AKSRT\Settings\Settings::get_comment_display_settings()
: [];
$order = (($settings['order'] ?? 'desc') === 'asc') ? 'oldest' : 'newest';
}
if (!in_array($order, ['newest', 'oldest', 'hottest'], true)) {
if (!in_array($order, ['newest', 'hottest'], true)) {
$order = 'newest';
}
if ($order === 'oldest') {
$args['order'] = 'ASC';
if ($order === 'hottest') {
$args['order'] = 'DESC';
$args['orderby'] = 'comment_date_gmt';
$args['aksrt_hottest_order'] = true;
} else {
// newest + hottest: base DESC; hottest reorders via comments_clauses.
$args['order'] = 'DESC';
$args['orderby'] = 'comment_date_gmt';
}
@@ -63,6 +57,17 @@ add_filter('comments_template_query_args', static function ($args) {
: $args;
});
add_filter('comments_clauses', static function (array $clauses, WP_Comment_Query $query): array {
if (empty($query->query_vars['aksrt_hottest_order'])) {
return $clauses;
}
global $wpdb;
$clauses['join'] .= " LEFT JOIN {$wpdb->commentmeta} AS aksrt_cm_hot ON ({$wpdb->comments}.comment_ID = aksrt_cm_hot.comment_id AND aksrt_cm_hot.meta_key = 'aksrt_comment_likes')";
$clauses['orderby'] = 'CAST(COALESCE(aksrt_cm_hot.meta_value, 0) AS UNSIGNED) DESC, ' . $wpdb->comments . '.comment_date_gmt DESC';
return $clauses;
}, 20, 2);
if (!function_exists('aksrt_comment_box_visible')) :
/**
* Whether the comment module may render for the current visitor.
@@ -103,14 +108,12 @@ if (!function_exists('aksrt_comments_build_context')) :
'nested_depth' => 3,
'require_login' => false,
'avatar_size' => 48,
'empty_text' => __('暂无评论,来做第一个评论的人吧~', 'aksrt'),
];
$default_order = (($settings['order'] ?? 'desc') === 'asc') ? 'oldest' : 'newest';
$order = isset($_GET['aksrt_comment_order'])
? sanitize_key((string) wp_unslash($_GET['aksrt_comment_order']))
: $default_order;
if (!in_array($order, ['newest', 'oldest', 'hottest'], true)) {
: 'newest';
if (!in_array($order, ['newest', 'hottest'], true)) {
$order = 'newest';
}
@@ -126,13 +129,10 @@ if (!function_exists('aksrt_comments_build_context')) :
'current_user' => wp_get_current_user(),
'require_login' => !empty($settings['require_login']),
'order' => $order,
'reverse_comments' => $order === 'newest',
'is_hottest' => $order === 'hottest',
'author_only' => isset($_GET['aksrt_author_only']) && (int) $_GET['aksrt_author_only'] === 1,
'post_author_id' => (int) get_the_author_meta('ID'),
'avatar_size' => $avatar_size,
'max_depth' => max(1, (int) ($settings['nested_depth'] ?? 3)),
'empty_text' => (string) ($settings['empty_text'] ?? __('暂无评论,来做第一个评论的人吧~', 'aksrt')),
'toolbar' => $toolbar,
'upload_enabled' => !empty($toolbar['upload_img']),
'link_enabled' => !empty($toolbar['link']),
@@ -140,7 +140,7 @@ if (!function_exists('aksrt_comments_build_context')) :
'box_placeholder' => (string) ($settings['box_placeholder'] ?? __('说点什么吧...', 'aksrt')),
'submit_text' => (string) ($settings['submit_text'] ?? __('提交评论', 'aksrt')),
'title_text' => (string) ($settings['title'] ?? __('评论', 'aksrt')),
'corderby_enabled' => !empty($settings['corderby']),
'corderby_enabled' => !empty($settings['corderby']) && !empty($settings['like_enabled']),
'close_comments' => !empty($settings['close_comments']),
'box_hidden' => !aksrt_comment_box_visible(),
'oauth_providers' => class_exists('\AKSRT\Auth\OAuth')
@@ -150,26 +150,6 @@ if (!function_exists('aksrt_comments_build_context')) :
}
endif;
if (!function_exists('aksrt_comments_apply_hottest_order')) :
/**
* Apply hottest-order SQL once for the current comments query.
*/
function aksrt_comments_apply_hottest_order(): void {
static $applied = false;
if ($applied) {
return;
}
$applied = true;
add_filter('comments_clauses', static function ($clauses) {
global $wpdb;
$clauses['join'] .= " LEFT JOIN {$wpdb->commentmeta} AS aksrt_cm ON ({$wpdb->comments}.comment_ID = aksrt_cm.comment_id AND aksrt_cm.meta_key = 'aksrt_comment_likes')";
$clauses['orderby'] = 'CAST(aksrt_cm.meta_value AS UNSIGNED) DESC, ' . $clauses['orderby'];
return $clauses;
});
}
endif;
if (!function_exists('aksrt_comments_normalize_order')) :
/**
@@ -177,13 +157,7 @@ if (!function_exists('aksrt_comments_normalize_order')) :
*/
function aksrt_comments_normalize_order(string $order = ''): string {
$order = sanitize_key($order);
if (!in_array($order, ['newest', 'oldest', 'hottest'], true)) {
$settings = class_exists('\AKSRT\Settings\Settings')
? \AKSRT\Settings\Settings::get_comment_display_settings()
: [];
$order = (($settings['order'] ?? 'desc') === 'asc') ? 'oldest' : 'newest';
}
if (!in_array($order, ['newest', 'oldest', 'hottest'], true)) {
if (!in_array($order, ['newest', 'hottest'], true)) {
$order = 'newest';
}
return $order;
@@ -212,7 +186,7 @@ if (!function_exists('aksrt_comments_query_for_post')) :
'number' => $per_page,
'offset' => ($page - 1) * $per_page,
'orderby' => 'comment_date_gmt',
'order' => $order === 'oldest' ? 'ASC' : 'DESC',
'order' => 'DESC',
'hierarchical' => 'threaded',
];
@@ -228,46 +202,13 @@ if (!function_exists('aksrt_comments_query_for_post')) :
// WP_Comment_Query does not support mixed status easily; keep approve only for list fragment.
}
// Hottest uses meta_value_num when meta exists; fall back to date.
$hottest_filter = null;
if ($order === 'hottest') {
$query_args['orderby'] = 'meta_value_num';
$query_args['meta_key'] = 'aksrt_comment_likes';
$query_args['order'] = 'DESC';
// Ensure comments without like meta still appear.
$query_args['meta_query'] = [
'relation' => 'OR',
[
'key' => 'aksrt_comment_likes',
'compare' => 'EXISTS',
],
[
'key' => 'aksrt_comment_likes',
'compare' => 'NOT EXISTS',
],
];
// Prefer clauses filter for stable hottest ordering.
$hottest_filter = static function ($clauses) {
global $wpdb;
if (strpos($clauses['join'], 'aksrt_cm_hot') === false) {
$clauses['join'] .= " LEFT JOIN {$wpdb->commentmeta} AS aksrt_cm_hot ON ({$wpdb->comments}.comment_ID = aksrt_cm_hot.comment_id AND aksrt_cm_hot.meta_key = 'aksrt_comment_likes')";
}
$clauses['orderby'] = 'CAST(COALESCE(aksrt_cm_hot.meta_value, 0) AS UNSIGNED) DESC, ' . $wpdb->comments . '.comment_date_gmt DESC';
return $clauses;
};
add_filter('comments_clauses', $hottest_filter, 20);
// Prefer date orderby with clauses override.
$query_args['orderby'] = 'comment_date_gmt';
unset($query_args['meta_key'], $query_args['meta_query']);
$query_args['aksrt_hottest_order'] = true;
}
$comment_query = new WP_Comment_Query($query_args);
$comments = is_array($comment_query->comments) ? $comment_query->comments : [];
if ($hottest_filter) {
remove_filter('comments_clauses', $hottest_filter, 20);
}
// Pin reorder for page 1 when not author-only.
if ($page === 1 && !$author_only && function_exists('aksrt_reorder_pinned_comments')) {
$comments = aksrt_reorder_pinned_comments($comments, $post_id);
@@ -325,8 +266,6 @@ if (!function_exists('aksrt_comments_render_items_html')) :
'style' => 'ol',
'avatar_size' => $avatar,
'max_depth' => $depth,
'reverse_top_level' => $reverse,
'reverse_children' => $reverse,
], $comments);
return (string) ob_get_clean();
}
@@ -370,9 +309,8 @@ if (!function_exists('aksrt_comments_render_list_fragment')) :
'order' => $order,
'author_only' => $author_only,
'post_author_id' => (int) get_post_field('post_author', $post_id),
'corderby_enabled' => !empty($settings['corderby']),
'corderby_enabled' => !empty($settings['corderby']) && !empty($settings['like_enabled']),
'comment_count' => $total,
'empty_text' => (string) ($settings['empty_text'] ?? __('暂无评论,来做第一个评论的人吧~', 'aksrt')),
];
ob_start();
@@ -623,7 +561,7 @@ if (!function_exists('aksrt_comments_render_filter')) :
</li>
</ul>
<?php if ($post_author_id > 0) : ?>
<a href="javascript:;" class="but comment-orderby btn-only-author p2-10<?php echo $author_only ? ' active' : ''; ?>" data-author-only="<?php echo $author_only ? '0' : '1'; ?>" rel="nofollow">
<a href="javascript:;" class="but comment-orderby btn-only-author p2-10" data-author-only="<?php echo $author_only ? '0' : '1'; ?>" rel="nofollow">
<?php echo $author_only ? esc_html__('查看全部', 'aksrt') : esc_html__('只看作者', 'aksrt'); ?>
</a>
<?php endif; ?>
@@ -652,12 +590,9 @@ if (!function_exists('aksrt_comments_render_empty')) :
* @param array<string,mixed> $ctx Comments context.
*/
function aksrt_comments_render_empty(array $ctx): void {
$text = (string) ($ctx['empty_text'] ?? __('暂无评论内容', 'aksrt'));
if (!empty($ctx['author_only'])) {
$text = __('暂无作者评论', 'aksrt');
}
$text = __('暂无评论内容', 'aksrt');
if (function_exists('aksrt_get_null')) {
echo aksrt_get_null($text, 40, 'null.svg', 'comment comment-null', 280); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo aksrt_get_null($text, 40, 'comment-null.svg', 'comment comment-null', 280); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
return;
}
echo '<div class="text-center comment comment-null" style="padding:40px 0;"><p class="em09 muted-3-color separator">' . esc_html($text) . '</p></div>';
@@ -678,10 +613,6 @@ if (!function_exists('aksrt_comments_render')) :
return;
}
if (!empty($ctx['is_hottest'])) {
aksrt_comments_apply_hottest_order();
}
set_query_var('aksrt_comment_order', (string) $ctx['order']);
set_query_var('aksrt_comment_settings', $ctx['settings']);
@@ -707,7 +638,7 @@ if (!function_exists('aksrt_comments_render')) :
<div id="postcomments">
<ol class="commentlist list-unstyled">
<?php
$show_filter = !empty($ctx['corderby_enabled']) && ($count > 0 || !empty($ctx['author_only']) || have_comments());
$show_filter = !empty($ctx['corderby_enabled']) && have_comments();
if ($show_filter) {
aksrt_comments_render_filter($ctx);
}
@@ -740,8 +671,6 @@ if (!function_exists('aksrt_comments_render_list_items')) :
'avatar_size' => (int) $ctx['avatar_size'],
'max_depth' => (int) $ctx['max_depth'],
'callback' => 'aksrt_comment_callback',
'reverse_top_level' => !empty($ctx['reverse_comments']),
'reverse_children' => !empty($ctx['reverse_comments']),
]);
echo aksrt_get_comment_ajax_loader(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
if (function_exists('aksrt_render_comment_pagination')) {