Skip to content

Instantly share code, notes, and snippets.

@dcavins
Last active February 3, 2020 12:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dcavins/2f185a4023a67a9506a68fcd328de61c to your computer and use it in GitHub Desktop.
Save dcavins/2f185a4023a67a9506a68fcd328de61c to your computer and use it in GitHub Desktop.
Only allow certain users to create docs.
<?php
add_filter( 'bp_docs_map_meta_caps', function( $caps, $cap, $user_id, $args ) {
if ( 'bp_docs_create' === $cap ) {
// Site admins
if ( user_can( $user_id, 'bp_moderate' ) ) {
$caps = array( 'exist' );
// If this is a group and the user is a group mod or admin.
} else if ( bp_is_group() && ( bp_group_is_mod() || bp_group_is_admin() ) ) {
$caps = array( 'exist' );
} else {
$caps = array( 'do_not_allow' );
}
}
return $caps;
}, 20, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment