Created
June 16, 2021 14:24
-
-
Save dcavins/0d4750c54847afd1d92fa34e34539f45 to your computer and use it in GitHub Desktop.
BP Docs: Don't allow group docs to have "creator only" access
This file contains hidden or 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_get_access_options', 'remove_creator_option_for_group_docs', 10, 4 ); | |
function remove_creator_option_for_group_docs( $options, $settings_field, $doc_id = 0, $group_id = 0 ) { | |
if ( ! $group_id ) { | |
$group_id = bp_docs_get_associated_group_id( $doc_id ); | |
} | |
// If this is the Doc creation page, check to see whether a | |
// group id has been passed somewhere | |
if ( empty( $group_id ) ) { | |
if ( isset( $_POST['associated_group_id'] ) ) { | |
$group_id = intval( $_POST['associated_group_id'] ); | |
} else if ( isset( $_GET['associated_group_id'] ) ) { | |
$group_id = intval( $_GET['associated_group_id'] ); | |
} else if ( isset( $_GET['group'] ) ) { | |
$maybe_group = BP_Groups_Group::get_id_from_slug( $_GET['group'] ); | |
if ( $maybe_group ) { | |
$group_id = $maybe_group; | |
} | |
} | |
} | |
if ( $group_id && current_user_can( 'bp_docs_associate_with_group', $group_id ) ) { | |
foreach ( $options as $key => $opt ) { | |
if ( 'creator' === $opt['name'] ) { | |
unset( $options[ $key ] ); | |
} | |
} | |
} | |
return $options; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment