WordPress.org

Ready to get started?Download WordPress

Forums

Bowe Codes
[resolved] Display group only if user is a member (4 posts)

  1. kraigg
    Member
    Posted 1 year ago #

    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?

    http://wordpress.org/extend/plugins/bowe-codes/

  2. kraigg
    Member
    Posted 1 year ago #

    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?

  3. imath
    Member
    Plugin Author

    Posted 1 year ago #

    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"]');?>

  4. kraigg
    Member
    Posted 1 year ago #

    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.

    <?php
    // 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; ?>

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.