Skip to content

Instantly share code, notes, and snippets.

@dcavins
Created November 9, 2017 18:38
Show Gist options
  • Select an option

  • Save dcavins/2884d5b10a365684a37bb50903c044b0 to your computer and use it in GitHub Desktop.

Select an option

Save dcavins/2884d5b10a365684a37bb50903c044b0 to your computer and use it in GitHub Desktop.
Set the "bp_docs_create" dynamically when in a group.
<?php
function my_docs_create_follow_group_associate_setting( $caps, $cap, $user_id, $args ) {
if ( 'bp_docs_create' == $cap && $group_id = bp_get_current_group_id() ) {
// In a group, only set this cap if the user can associate a doc with the group.
if ( current_user_can( 'bp_docs_associate_with_group', $group_id ) ) {
$caps[] = 'exist';
} else {
$caps[] = 'do_not_allow';
}
}
return $caps;
}
add_filter( 'bp_docs_map_meta_caps', 'my_docs_create_follow_group_associate_setting', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment