bp_folder_user_can_edit( int|BP_Document_Folder $folder = false )

Determine if the current user can edit an folder item.

Description

Parameters

$folder

(int|BP_Document_Folder) (Optional) BP_Document_Folder object or ID of the folder.

Default value: false

Return

(bool) True if can edit, false otherwise.

Source

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

function bp_folder_user_can_edit( $folder = false ) {

	// Assume the user cannot edit the folder item.
	$can_edit = false;

	if ( empty( $folder ) ) {
		return $can_edit;
	}

	if ( ! is_object( $folder ) ) {
		$folder = new BP_Document_Folder( $folder );
	}

	if ( empty( $folder ) ) {
		return $can_edit;
	}

	// Only logged in users can edit folder.
	if ( is_user_logged_in() ) {

		// Users are allowed to edit their own folder.
		if ( isset( $folder->user_id ) && bp_loggedin_user_id() === $folder->user_id ) {
			$can_edit = true;
		// Community moderators can always edit folder (at least for now).
		} elseif ( bp_current_user_can( 'bp_moderate' ) ) {
			$can_edit = true;
		// Groups documents have their own access.
		} elseif ( ! empty( $folder->group_id ) && groups_can_user_manage_document( bp_loggedin_user_id(), $folder->group_id ) ) {
			$can_edit = true;
		}

	}

	/**
	 * Filters whether the current user can edit an folder item.
	 *
	 * @since BuddyBoss 1.4.2
	 *
	 * @param bool   $can_edit Whether the user can edit the item.
	 * @param object $folder   Current folder item object.
	 */
	return (bool) apply_filters( 'bp_folder_user_can_delete', $can_edit, $folder );
}

Changelog

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