如何使用 bbPress API Server?

基础信息

  • API 命名空间:/bbpas/v1
  • 当前版本:1.0.0
  • 需要 bbPress 版本:2.6+

认证方式

所有 API 端点目前无需认证即可访问

端点列表

1. 测试连接

GET /bbpas/v1/test

响应示例

{
  "success": true,
  "message": "Connection successful",
  "version": "1.0.0",
  "bbpress_version": "2.6.4",
  "api_namespace": "bbpas/v1"
}

2. 论坛相关

获取论坛列表

GET /bbpas/v1/forums

参数:

  • parent (可选): 父论坛 ID,0 表示根论坛
  • per_page (默认-1): 每页数量 (1-100)
  • page (默认 1): 页码

获取单个论坛详情

GET /bbpas/v1/forum/{id}

3. 话题相关

获取话题列表

GET /bbpas/v1/topics

参数:

  • forum_id (可选): 按论坛 ID 过滤
  • per_page (默认 10): 每页数量 (1-100)
  • page (默认 1): 页码
  • orderby (默认 activity): 排序字段 (date/title/activity/popularity)
  • order (默认 DESC): 排序方向 (ASC/DESC)

获取话题详情

GET /bbpas/v1/topic/{id}

参数:

  • with_replies (默认 false): 是否包含回复

4. 回复相关

获取回复列表

GET /bbpas/v1/replies

参数:

  • topic_id (必填): 话题 ID
  • per_page (默认 20): 每页数量 (1-100)
  • page (默认 1): 页码
  • order (默认 ASC): 排序方向

获取单个回复

GET /bbpas/v1/reply/{id}

5. 用户相关

获取用户活动

GET /bbpas/v1/user/{id}/activity

参数:

  • type (默认 all): 活动类型 (topics/replies/all)
  • per_page (默认 10): 每页数量 (1-50)

6. 搜索

GET /bbpas/v1/search

参数:

  • query (必填): 搜索关键词
  • type (默认 all): 搜索类型 (forum/topic/reply/all)
  • per_page (默认 10): 每页数量 (1-50)
  • page (默认 1): 页码

7. 统计

GET /bbpas/v1/stats

响应示例:

{
"forums": {
"total": 15,
"active": 12
},
"topics": {
"total": 2450,
"open": 2300,
"closed": 150
},
"replies": {
"total": 15800
},
"users": {
"total": 850
}
}

Getting Started

  1. Install and activate bbPress on your WordPress site.
  2. Activate this plugin (bbPress API Server) from the Plugins page.
  3. Enable pretty permalinks in Settings > Permalinks (recommended: “Post name”).
  4. Test the API using the “Test API” tool above or an external tool like Postman.

Using the API

  • Access public data (e.g., forums, topics) with GET requests.
  • Create content (e.g., topics, replies) with POST requests, ensuring you are logged in with appropriate permissions.
  • Use the official SDK from our website for easier integration.
  • Integrate with third-party plugins:
    • WooCommerce Forum Integration Plugin
    • LearnDash Course Community Plugin
    • WeChat Mini Program Integration Solution

Permissions and Authentication

GET endpoints are publicly accessible. POST endpoints require a logged-in user with `publish_topics` or `publish_replies` capabilities. Use WordPress cookie-based authentication (e.g., via a logged-in browser session) or add JWT support with an extension plugin.

Advanced Tips

  • Enable object caching (e.g., Redis) for better performance in high-traffic sites.
  • Customize API responses using the `bbpas_response_data` filter in your theme』s functions.php.
  • Monitor API usage with logging extensions (coming soon).