MediaPress

MediaPress does not support the BuddyPress API at the time of this writing. To add MediaPress images and video to your AppCommunity app, you need to add them to the API response. You can do that using this code in a plugin (it may need to be edited for your use case):

<?php

add_filter( 'bp_rest_activity_prepare_value', 'app_add_mediapress', 10, 3 );


function app_add_mediapress( $response, $request, $activity ) {


    // Bail early.
    if ( empty( $response->data ) ) {
        return $response;
    }


    if( isset( $activity->id ) && $activity->type === 'mpp_media_upload' ) {
        if( $media_id = bp_activity_get_meta( $activity->id, '_mpp_attached_media_id', 1 ) ) {
            $url = wp_get_attachment_url( $media_id );


            if( !$url ) {
                return $response;
            }


            $n = strrpos($url,".");
            if( $n === FALSE ) {
                return $response;
            }


            $ext = substr($url,$n+1);
            $content;


            switch( $ext ) {
                case 'mov':
                case 'm4a':
                case 'mp4':
                case 'wmv':
                    $content = '<video width="320" height="240" controls><source src="' . $url . '" type="video/mp4">Your browser does not support the video tag.</video>';
                    break;
                case 'mp3':
                case 'wav':
                case 'aiff':
                case 'wma':
                case 'ogg':
                    $content = '<audio controls><source src="' . $url . '">Your browser does not support the audio tag.</audio>';
                    break;
                case 'jpg':
                case 'png':
                case 'gif':
                case 'pdf':
                    $content = '<img src="' . $url . '" class="app-bp-image" />';
                    break;
                default:
                    $content = '<a href="' . $url . '" target="_blank">' . $url . '</a>';
            }
            
            $response->data['content']['rendered'] .= $content;
        }
    }


    return $response;
}