Created
May 22, 2023 20:39
-
-
Save dcavins/399cf7e0c7affcd475ac8bd5f46cada9 to your computer and use it in GitHub Desktop.
Allow group administrators and moderators to manage group-associated BuddyPress Docs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'bp_docs_map_meta_caps', 'bp_docs_groups_allow_group_admins_to_manage_access', 20, 4 ); | |
function bp_docs_groups_allow_group_admins_to_manage_access( $caps, $cap, $user_id, $args ) { | |
// We only want to act on the "manage" capability, in group situations. | |
if ( 'bp_docs_manage' !== $cap ) { | |
return $caps; | |
} | |
$doc = bp_docs_get_doc_for_caps( $args ); | |
if ( empty( $doc ) ) { | |
return $caps; | |
} | |
$group_id = bp_docs_get_associated_group_id( $doc->ID, $doc ); | |
// If not associated with a group, nothing to do here | |
if ( ! $group_id ) { | |
return $caps; | |
} | |
if ( groups_is_user_admin( $user_id, $group_id ) || groups_is_user_mod( $user_id, $group_id ) ) { | |
$caps = array( 'exist' ); | |
} | |
return $caps; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment