Skip to:
Content
Pages
Categories
Search
Top
Bottom

Hide or Show content for specific BP Groups


  • Doremdou
    Participant

    @doremdou

    Hello,

    Is there a way I can hide or show a content to a specific BP Group?

    For example with user roles, I am using this in functions.php :

    add_shortcode( 'member', 'member_check_shortcode' );
    
    function member_check_shortcode( $atts, $content = null ) {
    	 if ( is_user_logged_in() && !is_null( $content ) && !is_feed() )
    		return do_shortcode($content);
    	return '';
    }

    this code is used to show content to only member user role with the shortcode [member]content[/member]

    Is there a way I can do the same to detect in which groups the user is in and then create a shortcode to hide/show specific content?

    Thank you a lot for your help,
    Dorem

Viewing 2 replies - 1 through 2 (of 2 total)

  • Doremdou
    Participant

    @doremdou

    I just found this on WPMU dev (quite old, 2012) http://premium.wpmudev.org/forums/topic/member-part-of-a-group-in-buddypress

    >>Aaron

    You can pass bp_group_is_member($group) a group object. I think you can do this:

    $group = new BP_Groups_Group( $group_id );
     if (bp_group_is_member($group)) {
       //do this stuff
    }

    >>CreativeSlice

    Thanks for your help Aaron. I’ve got it nearly working with your direction and am hoping you can help with the last few details.
    The

    if (bp_group_is_member($group))

    part doesn’t seem to be working so I did a

    print_r($groups);

    and found this:

    BP_Groups_Group Object ( [id] => group-three [creator_id] => [name] => [slug] => [description] => [status] => [enable_forum] => [date_created] => [admins] => [mods] => [total_member_count] => )

    Is there a way I can use this to see if the logged in user is a member of “group-three”?

    >>Aaron

    You need to get the ID number for your group. Maybe from the db.

    >>caevan_sachinwalla
    BP_Groups_Member::get_group_ids( $user_id );

    will give you the group_ids of the groups a user is a member of.

    Will this work with the new version of buddypress? how can I make a shortcode with this? thank you a lot 🙂

    I also found this on buddypress.org : https://buddypress.org/support/topic/check-if-an-user-is-or-not-a-group_member/

    functions.php:

    if(groups_is_user_member( bp_loggedin_user_id(), BP_Groups_Group::get_id_from_slug(‘VALUE’))){
    
    ...
    
    add_action( ‘bp_setup_nav’, ‘setup_nav’, 1000 );
    }

    Can I make a shortcode with this? I would like a shortcode like this:
    [group “Group1”] Content [/group]
    So how could I change the VALUE in the code with the group selected in the shortcode? (“group1”) so that I can use only one shortcode for all groups I have created.
    thanks 🙂


    Doremdou
    Participant

    @doremdou

    resolved, just used what I copied pasted earlier and created a shortcode with it…

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Hide or Show content for specific BP Groups’ is closed to new replies.
Skip to toolbar