WordPress.org

Ready to get started?Download WordPress

Forums

BuddyPress Follow
[resolved] How to remove Follow buttons based on user capabilities (6 posts)

  1. blurb
    Member
    Posted 1 year ago #

    Hello,

    I would like to limit the option of being 'followable' to authors (members of a certain group in Buddypress happen to be WP authors), so I am using the following snippet to remove follow buttons from other users (subscribers mostly):

    if ( ! user_can( bp_displayed_user_id(), 'delete_posts' )  )
    remove_action( 'bp_group_members_list_item_action', 'bp_follow_add_group_member_follow_button' );

    Is there a smarter way of doing this without messing with the plugin files?

    Thank you!

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

  2. r-a-y
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    You can try adding your snippet to your theme's functions.php or wp-content/plugins/bp-custom.php file.

    Let me know if that works for you.

  3. blurb
    Member
    Posted 1 year ago #

    Thanks for the quick response, and thank you for making your work and time available for the community.

    Unfortunately it didn't work from the functions.php or the bp-custom.php. It appears not to be reading the user capabilities and removes the buttons for everyone regardless of their caps.

    Only when I edit the bp-follow-hooks.php in the plugin folder I got it to work properly:

    function bp_follow_add_profile_follow_button() {
    
    	// customization to remove button from subscribers
    	if ( user_can( bp_displayed_user_id(), 'delete_posts' )  )
    
    		bp_follow_add_follow_button();
    }
    add_action( 'bp_member_header_actions', 'bp_follow_add_profile_follow_button' );

    Do you think this needs to be wrapped in a function to work from elsewhere?

    Your help is much appreciated.

  4. r-a-y
    Member
    Plugin Author

    Posted 1 year ago #

    Gotcha.

    Thanks for posting your example.

    What you need to do is remove the default button and run your function after BP Follow's.

    Try the following:

    // remove the default BP Follow button
    remove_action( 'bp_member_header_actions', 'bp_follow_add_profile_follow_button' );
    
    // add custom button
    function my_follow_add_profile_follow_button() {
    
    	// customization to remove button from subscribers
    	if ( user_can( bp_displayed_user_id(), 'delete_posts' )  )
    
    		bp_follow_add_follow_button();
    }
    add_action( 'bp_member_header_actions', 'my_follow_add_profile_follow_button' );
  5. blurb
    Member
    Posted 1 year ago #

    Worked like a charm! Thank you!

    But why couldn't I get this one (member listing buttons) to work in the same way? It removed the button from all users:

    // remove the default BP Follow button
    remove_action( 'bp_directory_members_actions', 'bp_follow_add_listing_follow_button' );
    
    // add custom button
    function my_follow_add_listing_follow_button() {
        global $members_template;
    
    	if ( $members_template->member->id == bp_loggedin_user_id() ||  ! user_can( bp_displayed_user_id(), 'delete_posts' )  )
    		return false;
    
    		bp_follow_add_follow_button( 'leader_id=' . $members_template->member->id );
    }
    add_action( 'bp_directory_members_actions', 'my_follow_add_listing_follow_button' );
  6. blurb
    Member
    Posted 1 year ago #

    Silly me, I got it. Changing the conditional from:

    ! user_can( bp_displayed_user_id(), 'delete_posts' )

    to

    ! user_can( $members_template->member->id, 'delete_posts' )

    fixed the problem. :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic