thebbapp/rest-api-bbpress
Composer 安装命令:
composer require thebbapp/rest-api-bbpress
包简介
BBPress REST API implementation for BbApp.
README 文档
README
BBPress REST API implementation for BbApp. The library can be used independently of the full BbApp framework stack, making it reusable for any WordPress site that needs BBPress REST API functionality.
Simplified Dependency Tree
thebbapp/rest-api-bbpress
└── thebbapp/rest-api-wordpress-base
└── thebbapp/rest-api
Installation
Install via Composer:
composer require thebbapp/rest-api-bbpress
Requirements
- PHP >= 7.2.24
- WordPress with BBPress plugin installed and activated
thebbapp/rest-api-wordpress-base>= 0.1.0
Usage
This library extends the WordPress REST API to provide comprehensive BBPress forum, topic, and reply functionality. It adds REST endpoints, custom fields, meta queries, and anonymous posting support for BBPress.
Basic Setup
Initialize and register the BBPress REST API in your WordPress plugin or theme:
<?php use BbApp\RestAPI\BbPress\BbPressRESTAPI; // Create an instance $bbpress_rest_api = new BbPressRESTAPI(); // Register hooks and filters (call on 'rest_api_init' hook) add_action('rest_api_init', function() use ($bbpress_rest_api) { $bbpress_rest_api->register(); }); // Initialize post types and meta fields (call on 'init' hook or during plugin init) $bbpress_rest_api->init();
What This Library Provides
1. REST API Endpoints for BBPress
The library automatically enables REST API support for BBPress post types:
- Forums:
/wp/v2/forums - Topics:
/wp/v2/topics - Replies:
/wp/v2/replies
All endpoints support standard WordPress REST API operations (GET, POST, PUT, DELETE) with batch support.
2. Custom REST Fields
The library adds several computed and meta fields to BBPress resources:
For Forums:
menu_order- Menu order
For Forums, Topics:
_bbp_last_active_time- UNIX timestamp of last activityparent- Parent post ID
For Topics:
_bbp_reply_count- Number of replies in the topic_bbp_forum_id- The forum ID (in meta)
For Replies:
_bbp_reply_count- Number of replies to this reply (nested replies)_bbp_reply_to- Parent reply ID
For Anonymous Posts (when bbp_allow_anonymous() returns true):
_bbp_anonymous_name- Anonymous author name
3. Enhanced Query Parameters
The library extends collection endpoints with BBPress-specific query parameters:
Parent Filtering:
// Get topics in forum 123
GET /wp/v2/topics?parent=123
// Get topics in multiple forums
GET /wp/v2/topics?parent[]=123&parent[]=456
Meta Queries:
// Simple meta query
GET /wp/v2/topics?meta_key=_bbp_forum_id&meta_value=123&meta_compare==
// Advanced meta query (JSON)
GET /wp/v2/replies?meta_query[0][key]=_bbp_reply_to&meta_query[0][value]=456&meta_query[0][compare]==
Ordering by BBPress Fields:
// Order forums by menu order
GET /wp/v2/forums?orderby=menu_order
// Order topics by last active time
GET /wp/v2/topics?orderby=_bbp_last_active_time
4. Anonymous Posting Support
When BBPress anonymous posting is enabled (bbp_allow_anonymous() returns true), the library:
- Allows unauthenticated POST requests to
/wp/v2/topicsand/wp/v2/replies - Accepts anonymous author name and email via meta fields
- Allows anonymous comments on topics and replies
5. BBPress Handler Integration
The library uses BBPress's native handlers for creating and updating topics and replies, ensuring:
- Proper validation and sanitization
- BBPress hooks and filters are triggered
- Forum statistics are updated correctly
- Subscriptions and notifications work as expected
Advanced Usage
Extending the Library
You can extend BbPressRESTAPI to add additional functionality:
<?php use BbApp\RestAPI\BbPress\BbPressRESTAPI; class MyCustomBbPressRESTAPI extends BbPressRESTAPI { public function register(): void { parent::register(); // Add your custom REST fields, routes, or filters here register_rest_field('forum', 'my_custom_field', [ 'get_callback' => function($post) { return get_post_meta($post['id'], 'my_custom_meta', true); }, 'schema' => [ 'type' => 'string', 'context' => ['view', 'edit'] ] ]); } }
To keep BbApp development going, donate here
thebbapp/rest-api-bbpress 适用场景与选型建议
thebbapp/rest-api-bbpress 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 12 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 thebbapp/rest-api-bbpress 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 thebbapp/rest-api-bbpress 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 11
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: AGPL-3.0-or-later
- 更新时间: 2025-12-13