boonebgorges / buddypress-docs

GNU General Public License v3.0
106 stars 44 forks source link

Set Access Defaults #684

Closed paulw32 closed 3 years ago

paulw32 commented 3 years ago

Is there a way to set the access defaults? Preferably so that they are uneditable by users.

I want the default to be so that only members of the group and view, only the author can edit and no docs have a parent. I want this to be the default so that the users cannot change this.

Cheers Paul

boonebgorges commented 3 years ago

You can disable the ability for users to edit Doc access settings like this:

add_filter( 'bp_docs_allow_access_settings', '__return_false' );

or provide a custom callback in place of __return_false if you want to block it on a per-document or per-user basis.

You can force specific access settings in a number of ways. The 'bp_docs_get_default_access_options' filter allows you to set the global defaults, but you would still be able to override them (assuming that your 'bp_docs_allow_access_settings' restriction allowed certain users to do so). If you want a more global override of settings, use the 'bp_docs_get_doc_settings' filter. Something like this:

add_filter(
  'bp_docs_get_doc_settings',
  function( $settings ) {
    $settings['read'] = 'group_members';
    $settings['edit'] = 'creator';
    return $settings;
  }
);