boonebgorges / buddypress-docs

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

Admin Setting - Default Doc Settings #664

Closed alieneila closed 4 years ago

alieneila commented 4 years ago

When someone created a new doc, I'd like to be able to set default settings in the admin that they can't change. For example..

I set it globally as : This Doc can be read by: Anyone This Doc can be edited by: Logged-in Users Comments are visible to: Anyone Comments can be posted by: Logged-in Users History can be viewed by: Anyone

And then when someone creates or edits a doc, they can't change it from that and it's set globally for all new docs created.

boonebgorges commented 4 years ago

It's unlikely that we'll introduce a new admin-level UI for this, but it can be done with a small plugin. First, to disable the "access" box when editing a Doc:

add_filter( 'bp_docs_allow_access_settings', '__return_false' ); // Or you can provide a custom callback with some more involved logic.

To force access settings:

add_filter(
  'bp_docs_get_doc_settings',
  function( $settings, $doc_id ) {
    // You can use $doc_id to do doc-specific things if you want. Otherwise:
    return array(
        'read' => 'anyone',
        'edit' => 'loggedin',
        'read_comments' => 'anyone',
        'post_comments' => 'loggedin',
        'view_history' => 'anyone',
    );
  },
  10,
  2
);
alieneila commented 4 years ago

Perfect, thank you =)