BP_REST_Reply_Endpoint::get_item( WP_REST_Request $request )
Retrieve a single reply.
Description
Parameters
- $request
-
(Required) Full details about the request.
Return
(WP_REST_Response) | WP_Error
Source
File: bp-forums/classes/class-bp-rest-reply-endpoint.php
public function get_item( $request ) { $reply = get_post( $request['id'] ); if ( bbp_thread_replies() ) { $reply_args = array( 'post_type' => bbp_get_reply_post_type(), 'post_parent' => $reply->post_parent, 'paged' => 1, 'posts_per_page' => - 1, ); // get all post status for moderator and admin. if ( bbp_get_view_all() ) { // Default view=all statuses. $post_statuses = array( bbp_get_public_status_id(), bbp_get_closed_status_id(), bbp_get_spam_status_id(), bbp_get_trash_status_id(), ); // Add support for private status. if ( current_user_can( 'read_private_replies' ) ) { $post_statuses[] = bbp_get_private_status_id(); } // Join post statuses together. $reply_args['post_status'] = implode( ',', $post_statuses ); } else { $reply_args['perm'] = 'readable'; } $reply_result = new WP_Query( $reply_args ); if ( ! empty( $reply_result->posts ) ) { foreach ( $reply_result->posts as $k => $v ) { $reply_result->posts[ $k ]->reply_to = (int) get_post_meta( $v->ID, '_bbp_reply_to', true ); } } // Parse arguments. $walk_arg = bbp_parse_args( array(), array( 'walker' => '', 'max_depth' => bbp_thread_replies_depth(), 'callback' => null, 'end_callback' => null, 'page' => 1, 'per_page' => -1, ), 'list_replies' ); global $buddyboss_thread_reply; $buddyboss_thread_reply = array(); $this->bbb_walker_reply->paged_walk( $reply_result->posts, $walk_arg['max_depth'], $walk_arg['page'], $walk_arg['per_page'], $walk_arg ); if ( isset( $buddyboss_thread_reply[ $reply->ID ] ) ) { $reply->depth = $buddyboss_thread_reply[ $reply->ID ]->depth; } } $retval = $this->prepare_response_for_collection( $this->prepare_item_for_response( $reply, $request ) ); $response = rest_ensure_response( $retval ); /** * Fires after a list of reply is fetched via the REST API. * * @param array $reply Fetched reply.. * @param WP_REST_Response $response The response data. * @param WP_REST_Request $request The request sent to the API. * * @since 0.1.0 */ do_action( 'bp_rest_reply_get_item', $reply, $response, $request ); return $response; }
Changelog
Version | Description |
---|---|
0.1.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.