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

732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
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.