BP_REST_Document_Endpoint::bp_documents_get_rest_field_callback_messages( array $data, string $attribute )

The function to use to get documents of the messages REST Field.

Description

Parameters

$data

(array) (Required) The message value for the REST response.

$attribute

(string) (Required) The REST Field key used into the REST response.

Return

(string) The value of the REST Field to include into the REST response.

Source

File: bp-document/classes/class-bp-rest-document-endpoint.php

	protected function bp_documents_get_rest_field_callback_messages( $data, $attribute ) {
		$message_id = $data['id'];

		if ( empty( $message_id ) ) {
			return;
		}

		$document_ids = bp_messages_get_meta( $message_id, 'bp_document_ids', true );
		$document_ids = trim( $document_ids );
		$document_ids = explode( ',', $document_ids );

		if ( empty( $document_ids ) ) {
			return;
		}

		$documents = $this->assemble_response_data( array( 'document_ids' => $document_ids ) );

		if ( empty( $documents['documents'] ) ) {
			return;
		}

		$retval = array();
		foreach ( $documents['documents'] as $document ) {
			$retval[] = $this->document_get_prepare_response( $document, array( 'support' => 'message' ) );
		}

		return $retval;
	}

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.