bp_document_user_can_edit( int|BP_Document $document = false )

Determine if the current user can edit an document item.

Description

Parameters

$document

(Optional) BP_Document object or ID of the document.

Default value: false

Return

(bool) True if can edit, false otherwise.

Source

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

782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
function bp_document_user_can_edit( $document = false ) {
 
    // Assume the user cannot edit the document item.
    $can_edit = false;
 
    if ( empty( $document ) ) {
        return $can_edit;
    }
 
    if ( ! is_object( $document ) ) {
        $document = new BP_Document( $document );
    }
 
    if ( empty( $document ) ) {
        return $can_edit;
    }
 
    // Only logged in users can edit document.
    if ( is_user_logged_in() ) {
 
        // Community moderators can always edit document (at least for now).
        if ( bp_current_user_can( 'bp_moderate' ) ) {
            $can_edit = true;
        }
 
        // Users are allowed to edit their own document.
        if ( isset( $document->user_id ) && ( $document->user_id === bp_loggedin_user_id() ) ) {
            $can_edit = true;
        }
 
        if ( bp_is_active( 'groups' ) && $document->group_id > 0 ) {
 
            $manage   = groups_can_user_manage_document( bp_loggedin_user_id(), $document->group_id );
            $status   = bp_group_get_media_status( $document->group_id );
            $is_admin = groups_is_user_admin( bp_loggedin_user_id(), $document->group_id );
            $is_mod   = groups_is_user_mod( bp_loggedin_user_id(), $document->group_id );
 
            if ( $manage ) {
                if ( $document->user_id === bp_loggedin_user_id() ) {
                    $can_edit = true;
                } elseif ( 'members' === $status && ( $is_mod || $is_admin ) ) {
                    $can_edit = true;
                } elseif ( 'mods' == $status && ( $is_mod || $is_admin ) ) {
                    $can_edit = true;
                } elseif ( 'admins' == $status && $is_admin ) {
                    $can_edit = true;
                }
            }
 
        }
 
    }
 
    /**
     * Filters whether the current user can edit an document item.
     *
     * @since BuddyBoss 1.4.2
     *
     * @param bool   $can_edit Whether the user can edit the item.
     * @param object $document   Current document item object.
     */
    return (bool) apply_filters( 'bp_document_user_can_edit', $can_edit, $document );
}

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.