BP_REST_Messages_Endpoint::get_items( WP_REST_Request $request )
Retrieve threads.
Description Description
Parameters Parameters
- $request
-
(Required) Full details about the request.
Return Return
(WP_REST_Response)
Source Source
File: bp-messages/classes/class-bp-rest-messages-endpoint.php
public function get_items( $request ) {
$args = array(
'user_id' => $request['user_id'],
'box' => $request['box'],
'type' => $request['type'],
'page' => $request['page'],
'per_page' => $request['per_page'],
'search_terms' => $request['search'],
);
// Include the meta_query for starred messages.
if ( 'starred' === $args['box'] ) {
$args['meta_query'] = array( // phpcs:ignore
array(
'key' => 'starred_by_user',
'value' => $args['user_id'],
),
);
}
/**
* Filter the query arguments for the request.
*
* @since 5.0.0
*
* @param array $args Key value array of query var to query value.
* @param WP_REST_Request $request The request sent to the API.
*/
$args = apply_filters( 'bp_rest_messages_get_items_query_args', $args, $request );
// Actually, query it.
$messages_box = new BP_Messages_Box_Template( $args );
$retval = array();
foreach ( (array) $messages_box->threads as $thread ) {
$retval[] = $this->prepare_response_for_collection(
$this->prepare_item_for_response( $thread, $request )
);
}
$response = rest_ensure_response( $retval );
$response = bp_rest_response_add_total_headers( $response, $messages_box->total_thread_count, $args['per_page'] );
/**
* Fires after a thread is fetched via the REST API.
*
* @since 5.0.0
*
* @param BP_Messages_Box_Template $messages_box Fetched thread.
* @param WP_REST_Response $response The response data.
* @param WP_REST_Request $request The request sent to the API.
*/
do_action( 'bp_rest_messages_get_items', $messages_box, $response, $request );
return $response;
}
Changelog Changelog
| Version | Description |
|---|---|
| 5.0.0 | Introduced. |