Display Div for members in groups

Hello wpmudev team, I am currently working with buddypress groups. I want to give new users a tour of the website. I will know if a member is new if they are not joined in any buddypress group. How do I display Div #Tour if user is a member of 0 groups and Div #inbox if user is a member of 1 or more groups? :confused:

  • Predrag Dubajic

    Hi Schmirts,

    Sorry if I was unclear about how to use this code, adding it inside mu-plugin or theme functions.php is not a solution for this.

    This code needs to be added inside your theme templates for posts, pages, etc. depending on where you want to show your custom content.

    When you add this code you need to modify it to add your desired content that will show to group and non-group users, here's a bit more commented code that explains what's going on:

    <?php if( bp_group_is_member() ) { /* This checks if user is part of group, if it is do below code */?>
    	<!-- If user is part of a group content below this will show up -->
    	<div id="tour"></div>
    	<!-- End here content visible for user that's part of a group -->
    <?php } else { /* This checks if user is part of group, if it's not skip above code and do below one instead */ ?>
    	<!-- If user is NOT part of a group content below this will show up -->
    	<div id="inbox"></div>
    	<!-- End here content visible for user that's NOT part of a group -->
    <?php } ?>

    Best regards,

  • Predrag Dubajic

    Hi Schmirts,

    Your inbox page is using Default template so basically you will need to add the code inside your page.php however this would then show on all pages with default template.

    So what you would need to do is create new page template for your inbox page.

    I accessed your site and had a look at your theme files so I created this for you, can you please download the attached file, unzip it and place it inside your theme root folder, you may want to use a child theme for this so you're safe when theme update is released.

    Once the file is in place you can go to your Inbox page in backend of your site and there change the template of your page, you should see Inbox template there as available option that will add your code.

    Note that you should edit this file I attached and add the code you want to show for group and non-group users.

    If you're still having troubles with this let me know and perhaps we should be looking into alternative way of doing this :slight_smile:

    Best regards,

  • Schmirts

    Hello Predrag Dubajic , I think the method you used and the work you did is superb! It is working very well, but for one thing. I am using this shortcode: [bc_messages] in the inbox div, this is working because I am using this setup:
    <?php echo do_shortcode("[shortcode]"); ?>
    The problem however comes in when I try to size the buddypress avatar using this shortcode: [bc_messages size="40"] , this causes the site to crash and display the following error;

    Parse error: syntax error, unexpected '40' (T_LNUMBER) in /public_html/app.databoy.space/wp-content/themes/tesseract-for-the-space-1-0/template-inbox.php on line 21

    Is there any way I can work around this? to resize the avatar of the shortcode outside the template?