BP_REST_Messages_Endpoint::search_recipients_items( WP_REST_Request $request )
Search Recipients for the message.
Description
Parameters
- $request
-
(Required) Full details about the request.
Return
(WP_REST_Response) | WP_Error
Source
File: bp-messages/classes/class-bp-rest-messages-endpoint.php
public function search_recipients_items( $request ) { $term = $request->get_param( 'term' ); $group_id = $request->get_param( 'group_id' ); if ( empty( $term ) ) { return new WP_Error( 'bp_rest_term_required', __( 'Sorry, term is required parameter.', 'buddyboss' ), array( 'status' => rest_authorization_required_code(), ) ); } if ( empty( $group_id ) ) { add_filter( 'bp_members_suggestions_query_args', array( $this, 'bp_rest_nouveau_ajax_search_recipients_exclude_current', ) ); } $args = array( 'term' => sanitize_text_field( $term ), 'type' => 'members', ); if ( ! empty( $group_id ) ) { $args['group_id'] = $group_id; } $results = bp_core_get_suggestions( $args ); $results = apply_filters( 'bp_members_suggestions_results', $results ); $retval = array_map( function ( $result ) { return array( 'id' => $result->user_id, 'userhandle' => "@{$result->ID}", 'text' => $result->name, ); }, $results ); $response = rest_ensure_response( $retval ); /** * Fires after a member suggetion is fetched via the REST API. * * @param array $results member array. * @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_messages_search_recipients_items', $results, $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.