Skip to content

Commit

Permalink
Respect site-wide anonymous comment setting.
Browse files Browse the repository at this point in the history
• Allow anonymous comments on Docs only if the site allows anonymous comments via the setting on the "Settings > Discussion" screen.
• Don't show the "Anyone" setting for the `post_comments` access setting if anonymous comments are not allowed on the site.
  • Loading branch information
dcavins committed Aug 6, 2018
1 parent 1aad178 commit 6906af1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions includes/caps.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ function bp_docs_map_meta_caps( $caps, $cap, $user_id, $args ) {
switch ( $doc_settings[ $cap_name ] ) {
case 'anyone' :
$caps[] = 'exist';

// Anonymous comment posting should respect site-wide setting.
if ( 'bp_docs_post_comments' == $cap_name && get_option( 'comment_registration' ) ) {
$caps = array();
}
break;

case 'loggedin' :
Expand Down
5 changes: 4 additions & 1 deletion includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,10 @@ function bp_docs_get_access_options( $settings_field, $doc_id = 0, $group_id = 0
}

// Allow anonymous reading
if ( in_array( $settings_field, array( 'read', 'read_comments', 'post_comments', 'view_history' ) ) ) {
if ( in_array( $settings_field, array( 'read', 'read_comments', 'view_history' ) )
// Allow anonymous comment posting setting if site option allows it.
|| ( 'post_comments' == $settings_field && ! get_option( 'comment_registration' ) )
) {
$options[10] = array(
'name' => 'anyone',
'label' => __( 'Anyone', 'buddypress-docs' ),
Expand Down

0 comments on commit 6906af1

Please sign in to comment.