bp_document_user_can_manage_folder( int $folder_id, int $user_id )

Check user have a permission to manage the folder.

Description

Parameters

$folder_id

(Required)

$user_id

(Required)

Return

(mixed|void)

Source

File: bp-document/bp-document-functions.php

function bp_document_user_can_manage_folder( $folder_id = 0, $user_id = 0 ) {

	$can_manage   = false;
	$can_view     = false;
	$can_download = false;
	$can_add      = false;
	$folder       = new BP_Document_Folder( $folder_id );
	$data         = array();

	switch ( $folder->privacy ) {

		case 'public':
			if ( $folder->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_document( $user_id, $folder->group_id );
				$status   = bp_group_get_media_status( $folder->group_id );
				$is_admin = groups_is_user_admin( $user_id, $folder->group_id );
				$is_mod   = groups_is_user_mod( $user_id, $folder->group_id );

				if ( $manage ) {
					if ( $folder->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( absint( $folder->group_id ) );
					if ( $the_group->id > 0 && $the_group->user_has_access ) {
						$can_view     = true;
						$can_download = true;
					}
				}
			}

			break;

		case 'loggedin':
			if ( $folder->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( $folder->user_id, $user_id ) : false;
			if ( $folder->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 'onlyme':
			if ( $folder->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_document_user_can_manage_folder', $data, $folder_id, $user_id );
}

Changelog

Changelog
Version Description
BuddyBoss 1.4.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.