Reply To: Is there an API for bbPress
Additionally, as an example of how you can add pretty much anything you want to the JSON responses returned by the REST API:
function bbpress_rest_api_replies_extra_data( WP_REST_Response $response ) {
if ( ! is_array( $response->data ) ) {
return $response;
}
foreach ( $response->data as $key => $single_item ) {
// Only modify replies
if ( bbp_get_reply_post_type() !== $single_item['type'] ) {
continue;
}
// Add the author's details using a custom format
$author_id = get_post( $single_item['id'] )->post_author;
$author = get_user_by( 'ID', $author_id );
$response->data[ $key ]['author'] = "{$author->display_name} <{$author->user_email}>";
}
return $response;
}
add_filter( 'rest_request_after_callbacks', 'bbpress_rest_api_replies_extra_data' );
You could say this is a bit of a brute force hack and although when combined with my last snippet it successfully adds the author’s display name and email address to replies (not topics), it shouldn’t really be used for that purpose “as is”: it doesn’t escape the author details, you probably don’t want to expose their email addresses, plus it’s out of alignment with how author meta is returned for other post types … However, I felt it was worth sharing an example of how you can quite quickly add arbitrary fields to REST API output.