Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcavins/399cf7e0c7affcd475ac8bd5f46cada9 to your computer and use it in GitHub Desktop.
Save dcavins/399cf7e0c7affcd475ac8bd5f46cada9 to your computer and use it in GitHub Desktop.
Allow group administrators and moderators to manage group-associated BuddyPress Docs.
<?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