BP_REST_Media_Endpoint::bp_media_ids_get_rest_field_callback_messages( array $data, string $attribute )
The function to use to get medias of the messages REST Field.
Description
Parameters
- $data
-
(Required) The message value for the REST response.
- $attribute
-
(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-media/classes/class-bp-rest-media-endpoint.php
protected function bp_media_ids_get_rest_field_callback_messages( $data, $attribute ) { $message_id = $data['id']; if ( empty( $message_id ) ) { return; } $media_ids = bp_messages_get_meta( $message_id, 'bp_media_ids', true ); $media_ids = trim( $media_ids ); $media_ids = explode( ',', $media_ids ); if ( empty( $media_ids ) ) { return; } $medias = $this->assemble_response_data( array( 'media_ids' => $media_ids ) ); if ( empty( $medias['medias'] ) ) { return; } $retval = array(); foreach ( $medias['medias'] as $media ) { $retval[] = array( 'id' => $media->id, 'full' => wp_get_attachment_image_url( $media->attachment_id, 'full' ), 'thumb' => wp_get_attachment_image_url( $media->attachment_id, 'bp-media-thumbnail' ), ); } 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.