BP_Media_Privacy::is_media_visible( bool $media_id = false )
Check if media is visible or not to the logged in user
Description
Parameters
- $media_id
-
(Optional)
Default value: false
Return
(bool|mixed|WP_Error)
Source
File: bp-media/classes/class-bp-media-privacy.php
public function is_media_visible( $media_id = false ) { $result = bp_media_get_specific( array( 'media_ids' => $media_id ) ); if ( empty( $result['medias'] ) || empty( $result['medias'][0] ) ) { return new WP_Error( 'no_media', __( 'There is no media.', 'buddyboss' ), array( 'status' => 500 ) ); } $media = $result['medias'][0]; $visibility = $media->privacy; $visible = true; if ( bp_loggedin_user_id() != $media->user_id ) { switch ( $visibility ) { //Logged in users case 'loggedin' : if ( ! bp_loggedin_user_id() ) { $visible = false; } break; //My friends case 'friends' : if ( bp_is_active( 'friends' ) ) { $is_friend = friends_check_friendship( bp_loggedin_user_id(), $media->user_id ); if ( ! $is_friend ) { $visible = false; } } break; //Only group members case 'grouponly' : $group_is_user_member = groups_is_user_member( bp_loggedin_user_id(), $media->activity_id ); if ( ! $group_is_user_member ) { $visible = false; } break; //Only Me case 'onlyme' : if ( bp_loggedin_user_id() != $media->user_id ) { $visible = false; } break; default: //public break; } } if ( is_super_admin() ) { $visible = true; } return apply_filters( 'bp_media_is_media_visible', $visible, $visibility, $media_id ); }
Changelog
Version | Description |
---|---|
BuddyBoss 1.0.0 | Introduced. |
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.