feat(widgets): paid posts AJAX + hot posts thumb persist

Wire /widgets/paid-posts load-more; fix hot posts show_thumb
not saved in update().
This commit is contained in:
kate522 committed 2026-07-20 20:55:02 +08:00
1 parent 425ca6cd2e
commit d508a9aef8
3 files changed
+120 -25

No files matched your search

+27
View File
@@ -34,6 +34,11 @@ class WidgetAjax {
'callback' => [$this, 'rest_tab_posts'],
'permission_callback' => '__return_true',
]);
register_rest_route('aksrt/v1', '/widgets/paid-posts', [
'methods' => 'GET',
'callback' => [$this, 'rest_paid_posts'],
'permission_callback' => '__return_true',
]);
}
public function rest_main_posts(\WP_REST_Request $request) {
@@ -89,4 +94,26 @@ class WidgetAjax {
'html' => $html,
], 200);
}
public function rest_paid_posts(\WP_REST_Request $request) {
if (!class_exists('\AKSRT\Widgets\WidgetPaidPosts')) {
return new \WP_REST_Response(['success' => false, 'message' => 'unavailable'], 500);
}
$instance = [
'count' => max(1, min(20, (int) ($request->get_param('count') ?? 6))),
'orderby' => sanitize_key((string) ($request->get_param('orderby') ?? 'date')),
'paginate' => sanitize_key((string) ($request->get_param('paginate') ?? 'ajax')),
];
$page = max(1, (int) ($request->get_param('page') ?? $request->get_param('paged') ?? 1));
$payload = \AKSRT\Widgets\WidgetPaidPosts::query_payload($instance, $page);
return new \WP_REST_Response([
'success' => true,
'html' => (string) ($payload['html'] ?? ''),
'paginate_html' => (string) ($payload['paginate_html'] ?? ''),
'has_more' => !empty($payload['has_more']),
'page' => (int) ($payload['page'] ?? $page),
'max_pages' => (int) ($payload['max_pages'] ?? 1),
'total' => (int) ($payload['total'] ?? 0),
], 200);
}
}