bp_media_user_can_manage_media( int $media_id, int $user_id )
Check user have a permission to manage the media.
Description
Parameters
- $media_id
-
(Required)
- $user_id
-
(Required)
- $thread_id
-
(Required)
- $message_id
-
(Required)
Return
(mixed|void)
Source
File: bp-media/bp-media-functions.php
function bp_media_user_can_manage_media( $media_id = 0, $user_id = 0 ) { $can_manage = false; $can_view = false; $can_download = false; $can_add = false; $media = new BP_Media( $media_id ); $data = array(); switch ( $media->privacy ) { case 'public': if ( $media->user_id === $user_id ) { $can_manage = true; $can_view = true; $can_download = true; $can_add = true; } elseif ( bp_current_user_can( 'bp_moderate' ) ) { $can_manage = true; $can_view = true; $can_download = true; $can_add = false; } else { $can_manage = false; $can_view = true; $can_download = true; } break; case 'grouponly': if ( bp_is_active( 'groups' ) ) { $manage = groups_can_user_manage_media( $user_id, $media->group_id ); $status = bp_group_get_media_status( $media->group_id ); $is_admin = groups_is_user_admin( $user_id, $media->group_id ); $is_mod = groups_is_user_mod( $user_id, $media->group_id ); if ( $manage ) { if ( $media->user_id === $user_id ) { $can_manage = true; $can_add = true; } elseif ( bp_current_user_can( 'bp_moderate' ) ) { $can_manage = true; $can_add = false; } elseif ( 'members' == $status && ( $is_mod || $is_admin ) ) { $can_manage = true; $can_add = false; } elseif ( 'mods' == $status && ( $is_mod || $is_admin ) ) { $can_manage = true; $can_add = false; } elseif ( 'admins' == $status && $is_admin ) { $can_manage = true; $can_add = false; } $can_view = true; $can_download = true; } else { $the_group = groups_get_group( (int) $media->group_id ); if ( $the_group->id > 0 && $the_group->user_has_access ) { $can_view = true; $can_download = true; } } } break; case 'loggedin': if ( $media->user_id === $user_id ) { $can_manage = true; $can_view = true; $can_download = true; $can_add = true; } elseif ( bp_current_user_can( 'bp_moderate' ) ) { $can_manage = true; $can_view = true; $can_download = true; $can_add = false; } elseif ( bp_loggedin_user_id() === $user_id ) { $can_manage = false; $can_view = true; $can_download = true; } break; case 'friends': $is_friend = ( bp_is_active( 'friends' ) ) ? friends_check_friendship( $media->user_id, $user_id ) : false; if ( $media->user_id === $user_id ) { $can_manage = true; $can_view = true; $can_download = true; $can_add = true; } elseif ( bp_current_user_can( 'bp_moderate' ) ) { $can_manage = true; $can_view = true; $can_download = true; $can_add = false; } elseif ( $is_friend ) { $can_manage = false; $can_view = true; $can_download = true; } break; case 'forums': $args = array( 'user_id' => $user_id, 'forum_id' => bp_media_get_forum_id( $media_id ), 'check_ancestors' => false, ); $has_access = bbp_user_can_view_forum( $args ); if ( $media->user_id === $user_id ) { $can_manage = true; $can_view = true; $can_download = true; $can_add = true; } elseif ( bp_current_user_can( 'bp_moderate' ) ) { $can_manage = true; $can_view = true; $can_download = true; $can_add = false; } elseif ( $has_access ) { if ( bp_current_user_can( 'bp_moderate' ) ) { $can_manage = true; } $can_view = true; $can_download = true; } break; case 'message': $thread_id = bp_media_get_thread_id( $media_id ); $has_access = messages_check_thread_access( $thread_id, $user_id ); if ( ! is_user_logged_in() ) { $can_manage = false; $can_view = false; $can_download = false; } elseif ( ! $thread_id ) { $can_manage = false; $can_view = false; $can_download = false; } elseif ( $media->user_id === $user_id ) { $can_manage = true; $can_view = true; $can_download = true; $can_add = true; } elseif ( bp_current_user_can( 'bp_moderate' ) ) { $can_manage = true; $can_view = true; $can_download = true; $can_add = false; } elseif ( $has_access > 0 ) { $can_manage = false; $can_view = true; $can_download = true; } break; case 'onlyme': if ( $media->user_id === $user_id ) { $can_manage = true; $can_view = true; $can_download = true; $can_add = true; } elseif ( bp_current_user_can( 'bp_moderate' ) ) { $can_manage = true; $can_view = true; $can_download = true; $can_add = false; } break; } $data['can_manage'] = $can_manage; $data['can_view'] = $can_view; $data['can_download'] = $can_download; $data['can_add'] = $can_add; return apply_filters( 'bp_media_user_can_manage_media', $data, $media_id, $user_id ); }
Changelog
Version | Description |
---|---|
BuddyBoss 1.4.4 | 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.