feat(forum): topic list widget AJAX load-more like zibll
Shared query_payload + REST /forum/frontend/widgets/topics wired to ajax-list for sidebar forum posts lists.
This commit is contained in:
1 parent
43fb65dcdd
commit
5cb6928b1e
2 files changed
+192
-53
No files matched your search
@@ -246,6 +246,40 @@ class Forum {
|
||||
$this->view_builder()->ajax_board_topics();
|
||||
}
|
||||
|
||||
public function register_widget_routes(): void {
|
||||
register_rest_route('aksrt/v1', '/forum/frontend/widgets/topics', [
|
||||
'methods' => 'GET',
|
||||
'callback' => [$this, 'rest_widget_topics'],
|
||||
'permission_callback' => '__return_true',
|
||||
]);
|
||||
}
|
||||
|
||||
public function rest_widget_topics(\WP_REST_Request $request) {
|
||||
if (!class_exists('\AKSRT\Widgets\WidgetForumTopicLists')) {
|
||||
return new \WP_REST_Response(['success' => false, 'message' => 'widget unavailable'], 500);
|
||||
}
|
||||
$instance = [
|
||||
'count' => max(1, min(30, (int) ($request->get_param('count') ?? 8))),
|
||||
'orderby' => sanitize_key((string) ($request->get_param('orderby') ?? 'date')),
|
||||
'style' => sanitize_key((string) ($request->get_param('style') ?? 'mini')),
|
||||
'plate_id' => max(0, (int) ($request->get_param('plate_id') ?? 0)),
|
||||
'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\WidgetForumTopicLists::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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function render_board_cards(array $boards): void {
|
||||
$this->view_builder()->render_board_cards($boards);
|
||||
}
|
||||
@@ -396,6 +430,7 @@ class Forum {
|
||||
// Public plate/board topic list (sort tabs)
|
||||
add_action('wp_ajax_aksrt_forum_board_topics', [$this, 'ajax_board_topics']);
|
||||
add_action('wp_ajax_nopriv_aksrt_forum_board_topics', [$this, 'ajax_board_topics']);
|
||||
add_action('rest_api_init', [$this, 'register_widget_routes']);
|
||||
|
||||
add_action('admin_init', [$this, 'maybe_migrate_boards'], 25);
|
||||
add_filter('template_include', [$this, 'template_routing']);
|
||||
|
||||
Reference in new issue
Block a user