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:
1 parent
b520d29368
commit
8aa116ec43
63 files changed
+1985
-2304
No files matched your search
@@ -93,22 +93,6 @@ class GlobalController extends ControllerBase {
|
||||
'permission_callback' => [$this, 'check_permission'],
|
||||
]);
|
||||
|
||||
// Archive AJAX filter (public) — §2.5/§2.6/§2.7
|
||||
register_rest_route(self::API_NAMESPACE, '/archive/posts', [
|
||||
'methods' => 'GET',
|
||||
'callback' => [$this, 'rest_archive_posts'],
|
||||
'permission_callback' => '__return_true',
|
||||
'args' => [
|
||||
'archive_type' => ['type' => 'string', 'default' => 'category', 'sanitize_callback' => 'sanitize_key'],
|
||||
'term_id' => ['type' => 'integer', 'default' => 0, 'sanitize_callback' => 'absint'],
|
||||
'filter_cat' => ['type' => 'string', 'default' => '', 'sanitize_callback' => 'sanitize_text_field'],
|
||||
'filter_tag' => ['type' => 'string', 'default' => '', 'sanitize_callback' => 'sanitize_text_field'],
|
||||
'custom_filter' => ['type' => 'string', 'default' => '', 'sanitize_callback' => 'sanitize_text_field'],
|
||||
'sort' => ['type' => 'string', 'default' => 'date', 'sanitize_callback' => 'sanitize_key'],
|
||||
'page' => ['type' => 'integer', 'default' => 1, 'sanitize_callback' => 'absint'],
|
||||
],
|
||||
]);
|
||||
|
||||
// Homepage categories (for admin tab editor)
|
||||
register_rest_route(self::API_NAMESPACE, '/homepage/categories', [
|
||||
'methods' => 'GET',
|
||||
@@ -164,104 +148,6 @@ class GlobalController extends ControllerBase {
|
||||
return $this->success(['message' => '测试邮件已发送']);
|
||||
}
|
||||
|
||||
public function rest_archive_posts(\WP_REST_Request $request): \WP_REST_Response {
|
||||
$archive_type = sanitize_key((string) ($request->get_param('archive_type') ?: 'category'));
|
||||
$archive_type = in_array($archive_type, ['category', 'tag'], true) ? $archive_type : 'category';
|
||||
$term_id = absint($request->get_param('term_id'));
|
||||
$page = max(1, absint($request->get_param('page')));
|
||||
$page_settings = $archive_type === 'tag'
|
||||
? \AKSRT\Settings\Settings::get_tag_page_settings()
|
||||
: \AKSRT\Settings\Settings::get_category_page_settings();
|
||||
$per_page = min(50, max(1, (int) ($page_settings['per_page'] ?? get_option('posts_per_page', 10))));
|
||||
$sort = sanitize_key((string) ($request->get_param('sort') ?: 'date'));
|
||||
$allowed_sorts = \AKSRT\Settings\Settings::homepage_allowed_sorts();
|
||||
if (!in_array($sort, $allowed_sorts, true)) {
|
||||
$sort = 'date';
|
||||
}
|
||||
|
||||
$args = [
|
||||
'post_type' => 'post',
|
||||
'post_status' => 'publish',
|
||||
'posts_per_page' => $per_page,
|
||||
'paged' => $page,
|
||||
'ignore_sticky_posts' => true,
|
||||
];
|
||||
$tax_query = [];
|
||||
if ($term_id > 0) {
|
||||
$tax_query[] = [
|
||||
'taxonomy' => $archive_type === 'tag' ? 'post_tag' : 'category',
|
||||
'field' => 'term_id',
|
||||
'terms' => [$term_id],
|
||||
];
|
||||
}
|
||||
$filter_cat = absint($request->get_param('filter_cat'));
|
||||
$filter_tag = absint($request->get_param('filter_tag'));
|
||||
if ($filter_cat > 0) {
|
||||
$tax_query[] = ['taxonomy' => 'category', 'field' => 'term_id', 'terms' => [$filter_cat]];
|
||||
}
|
||||
if ($filter_tag > 0) {
|
||||
$tax_query[] = ['taxonomy' => 'post_tag', 'field' => 'term_id', 'terms' => [$filter_tag]];
|
||||
}
|
||||
if ($tax_query !== []) {
|
||||
$args['tax_query'] = $tax_query;
|
||||
}
|
||||
|
||||
// 自定义高级筛选维度(custom_filter=JSON {dim_key:value};参考主题 meta_query LIKE 语义)。
|
||||
$custom_raw = (string) $request->get_param('custom_filter');
|
||||
$custom = $custom_raw !== '' ? json_decode($custom_raw, true) : [];
|
||||
if (is_array($custom) && $custom !== []) {
|
||||
$filter_cfg = \AKSRT\Settings\Settings::get_post_filter_settings();
|
||||
$allowed = [];
|
||||
foreach ($filter_cfg['custom_filter'] as $dimension) {
|
||||
$dim_key = sanitize_key((string) ($dimension['key'] ?? ''));
|
||||
if ($dim_key === '') {
|
||||
continue;
|
||||
}
|
||||
$vals = [];
|
||||
foreach ((array) ($dimension['vals'] ?? []) as $val) {
|
||||
$vkey = sanitize_key((string) ($val['key'] ?? ''));
|
||||
if ($vkey !== '') {
|
||||
$vals[] = $vkey;
|
||||
}
|
||||
}
|
||||
$allowed[$dim_key] = $vals;
|
||||
}
|
||||
$meta_query = [];
|
||||
foreach ($custom as $dim_key => $dim_value) {
|
||||
$dim_key = sanitize_key((string) $dim_key);
|
||||
$dim_value = sanitize_key((string) $dim_value);
|
||||
if ($dim_key === '' || $dim_value === '' || !isset($allowed[$dim_key]) || !in_array($dim_value, $allowed[$dim_key], true)) {
|
||||
continue;
|
||||
}
|
||||
$meta_query[] = [
|
||||
'key' => '_aksrt_cf_' . $dim_key,
|
||||
'value' => '"' . $dim_value . '"',
|
||||
'compare' => 'LIKE',
|
||||
];
|
||||
}
|
||||
if ($meta_query !== []) {
|
||||
$args['meta_query'] = $meta_query;
|
||||
}
|
||||
}
|
||||
if (function_exists('aksrt_homepage_apply_named_sort_args')) {
|
||||
$args = aksrt_homepage_apply_named_sort_args($args, $sort);
|
||||
}
|
||||
|
||||
$query = new \WP_Query($args);
|
||||
$render_config = aksrt_resolve_post_list_render_config([
|
||||
'context' => $archive_type,
|
||||
'term_id' => $archive_type === 'category' ? $term_id : 0,
|
||||
]);
|
||||
$render_config['skip_wrapper'] = true;
|
||||
$html = aksrt_render_post_list($render_config, $query, false);
|
||||
|
||||
return $this->success([
|
||||
'html' => $html,
|
||||
'total' => (int) $query->found_posts,
|
||||
'has_more' => $page < (int) $query->max_num_pages,
|
||||
]);
|
||||
}
|
||||
|
||||
public function rest_homepage_categories(): \WP_REST_Response {
|
||||
$data = [];
|
||||
|
||||
|
||||
Reference in new issue
Block a user