BP_REST_Group_Messages_Endpoint::bp_rest_groups_messages_validate_message( mixed $send, WP_REST_Request $request, string $type = 'all' )
Check group message has been successfully sent or not.
Description
Parameters
- $send
-
(Required) int|bool|WP_Error.
- $request
-
(Required) Rest request.
- $type
-
(Optional) Type of the message
all
orindividual
.Default value: 'all'
Return
(WP_Error)
Source
File: bp-messages/classes/class-bp-rest-group-messages-endpoint.php
public function bp_rest_groups_messages_validate_message( $send, $request, $type = 'all' ) { if ( is_wp_error( $send ) ) { return new WP_Error( 'bp_rest_unknown_error', $send->get_error_message(), array( 'status' => rest_authorization_required_code(), ) ); } elseif ( ! empty( $send ) ) { $thread = new BP_Messages_Thread( (int) $send ); $recipients_count = ( count( $thread->recipients ) > 1 ? count( $thread->recipients ) - ( isset( $request['user_id'] ) && ! empty( $request['user_id'] ) ? 1 : 0 ) : 0 ); if ( 'individual' === $type ) { $retval['message'] = sprintf( /* translators: Message member count. */ __( 'Your message was sent to %s members of this group.', 'buddyboss' ), $recipients_count ); } else { $retval['message'] = __( 'Your message was sent to all members of this group.', 'buddyboss' ); } $last_message = wp_list_filter( $thread->messages, array( 'id' => $thread->last_message_id ) ); $last_message = reset( $last_message ); $fields_update = $this->update_additional_fields_for_object( $last_message, $request ); if ( is_wp_error( $fields_update ) ) { return $fields_update; } $retval['data'] = $this->prepare_response_for_collection( $this->message_endppoint->prepare_item_for_response( $thread, $request ) ); $response = rest_ensure_response( $retval ); /** * Fires after a thread is fetched via the REST API. * * @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. * * @since 0.1.0 */ do_action( 'bp_rest_group_messages_create_items', $thread, $response, $request ); return $response; } }
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.