bp_document_user_can_delete( int|BP_Document $document = false )

Determine if the current user can delete an document item.

Description

Parameters

$document

(Optional) BP_Document object or ID of the document.

Default value: false

Return

(bool) True if can delete, false otherwise.

Source

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

function bp_document_user_can_delete( $document = false ) {

	// Assume the user cannot delete the document item.
	$can_delete = false;

	if ( empty( $document ) ) {
		return $can_delete;
	}

	if ( ! is_object( $document ) ) {
		$document = new BP_Document( $document );
	}

	if ( empty( $document ) ) {
		return $can_delete;
	}

	// Only logged in users can delete document.
	if ( is_user_logged_in() ) {

		// Community moderators can always delete document (at least for now).
		if ( bp_current_user_can( 'bp_moderate' ) ) {
			$can_delete = true;
		}

		// Users are allowed to delete their own document.
		if ( isset( $document->user_id ) && ( $document->user_id === bp_loggedin_user_id() ) ) {
			$can_delete = true;
		}
	}

	/**
	 * Filters whether the current user can delete an document item.
	 *
	 * @since BuddyBoss 1.4.0
	 *
	 * @param bool   $can_delete Whether the user can delete the item.
	 * @param object $document   Current document item object.
	 */
	return (bool) apply_filters( 'bp_document_user_can_delete', $can_delete, $document );
}

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.