BP_REST_Media_Endpoint::bp_media_ids_get_rest_field_callback( BP_Activity_Activity $activity, string $attribute )
The function to use to get medias of the activity REST Field.
Description
Parameters
- $activity
-
(Required) Activity Array.
- $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( $activity, $attribute ) { $activity_id = $activity['id']; if ( empty( $activity_id ) ) { return; } $media_ids = bp_activity_get_meta( $activity_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.