bp_document_user_can_edit( int|BP_Document $document = false )
Determine if the current user can edit an document item.
Description
Parameters
- $document
-
(int|BP_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
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
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.