WordPress.org

Ready to get started?Download WordPress

Forums

BuddyPress Docs
[resolved] Filtering the show_cpt_ui() function (3 posts)

  1. daniel.vos
    Member
    Posted 1 year ago #

    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

    http://wordpress.org/extend/plugins/buddypress-docs/

  2. Boone Gorges
    Moderator
    Plugin Author

    Posted 1 year ago #

    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' );
  3. daniel.vos
    Member
    Posted 1 year ago #

    Thank you, Boone. That works very well!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.