Support » Plugin: Bowe Codes » [Plugin: Bowe Codes] Display group only if user is a member

  • Resolved kraigg


    Hi there,

    I am trying to find a way to use the shortcodes to show a list of private groups that a user is a member of. I thought I’d be able to do this by combining bc_restrict_gm and bc_group (such as below) but it’s not working.

    [bc_restrict_gm group_id="my-private-group"][bc_group slug="my-private-group"][/bc_restrict_gm]

    The ouput displays whatever is inside the bc_restrict_gm tags as text only (eg, [bc_group slug=”my-private-group”])

    Is it possible to do this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The other thing I tried to do was add the shortcode to my template file (eg homepage.php)

    <?php do_shortcode('[bc_group slug="my-private-group"]'); ?>

    But nothing appears, even when I log in as a member of this private group.

    I see that you have to add two lines of code to your functions.php file if using shortcodes in text widgets. Do you need to set anything up something similar before you can use shortcodes in template files?

    In reply to your first question : no.
    But you can try to use bc_user_groups shortcode by setting the dynamic attribute to 1 and build a widget out of it. The goal of this shortcode is to list the group of the loggedin user but if you are on a displayed user profile page, if dynamic is set to 1 then it will list the displayed user groups. (except the hidden ones).

    to allow rendering of shortcode in text widgets, in your functions.php :

    add_filter( 'widget_text', 'shortcode_unautop');
    add_filter( 'widget_text', 'do_shortcode');

    In reply to your 2nd one, you should try to echo your code as the shortcode is returning a string.

    <?php echo do_shortcode('[bc_group slug="buddypress"]');?>

    Thanks for the help imath,

    I tried the first option, but I wasn’t able to display just the private groups for the currently logged-in user. Using bc_user_groups worked much better than what I previously had, but I still need to try to find a way to filter out the public groups.

    So I ended up going with the second option for the time being, and hard-coding part of the template file. There won’t be very many private groups so this solution, although clunky and inelegant, works for me for the time being.

    // User is not a member of group
    if ( groups_is_user_member( bp_loggedin_user_id(), 15 ) ) :
    echo do_shortcode('[bc_group slug="my-private-group"]');
    endif; ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: Bowe Codes] Display group only if user is a member’ is closed to new replies.