Custom code to display gallery of displayed user

Sidebar widget gallery displays media from all website users according to the criteria selected by admin. If you want to display media of displayed BuddyPress user and not from all users of the website then you need to use below code.

Using action rtmedia_before_gallery_widget_content, add this filter rtmedia-model-where-query to update the query for the currently displayed user.

Please try adding below code to your theme’s functions.php file:

add_action( 'rtmedia_before_gallery_widget_content','rtm_custom_widget_add_filter_update_where_query', 10 );
function rtm_custom_widget_add_filter_update_where_query(){
    if( function_exists( "bp_displayed_user_id" ) && bp_displayed_user_id () != 0 ){
        add_filter( "rtmedia-model-where-query", 'rtm_custom_widget_function_update_where_query', 20, 2 );
    }   
}

function rtm_custom_widget_function_update_where_query( $where, $table_name ){    
    $disp_user = bp_displayed_user_id();
    $where .= " AND ( {$table_name}.context = 'profile' and {$table_name}.context_id = '".$disp_user."' ) ";    
    add_action( 'rtmedia_after_gallery_widget_content', 'rtm_custom_widget_remove_filter_update_where_query', 10 );
    return $where; 
}

function rtm_custom_widget_remove_filter_update_where_query(){
    remove_filter( 'rtmedia-model-where-query', 'rtm_custom_widget_add_filter_update_where_query' );
}