• Resolved daniel.vos

    (@danielvos)


    Good morning,

    In order to provide some of our users with the ability to add media attachments to their Docs, I would like to make the “Edit Doc” button available to a wider range of users. By default, the “Edit Doc” button is shown only to users with an Administrator role. However, I would like to make it visible to any user with the capability “edit_posts.”

    I noticed that the show_cpt_ui() function in bp-docs.php is filterable. Through my own testing, I have also found that I can get the results I’m looking for if I make the following change in bp-docs.php.

    BEFORE

    function show_cpt_ui() {
    	$show_ui = is_super_admin();
    	return apply_filters( 'bp_docs_show_cpt_ui', $show_ui );
    }

    AFTER

    function show_cpt_ui() {
    	$show_ui = current_user_can('edit_posts');
    	return apply_filters( 'bp_docs_show_cpt_ui', $show_ui );
    }

    However, this is not an effective method of achieving the result I am looking for, because I have to re-edit bp-docs.php every time a new version of the plugin is released.

    So I want to filter the show_cpt_ui() function as recommended by the function comments in bp-docs.php. But I am definitely a newbie when it comes to writing WordPress filters, so I’m not sure how to start.

    Here are my questions:

    1. Where do I put the filter? In the BuddyPress child theme we’ve created?
    2. How do I write the filter code?

    Thank you for any pointers anyone can provide.

    Sincerely,

    Daniel Vos

    https://www.ads-software.com/extend/plugins/buddypress-docs/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Boone Gorges

    (@boonebgorges)

    Daniel –

    I’d suggest putting it in your theme’s functions.php.

    The filter should look like this:

    function bbg_allow_editors_to_see_bp_docs_ui( $show_ui ) {
        return current_user_can( 'edit_posts' );
    }
    add_filter( 'bp_docs_show_cpt_ui', 'bbg_allow_editors_to_see_bp_docs_ui' );
    Thread Starter daniel.vos

    (@danielvos)

    Thank you, Boone. That works very well!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Filtering the show_cpt_ui() function’ is closed to new replies.