Out of the box, BuddyPress allows for instant integration with bbPress. It automatically themes the forum to match the rest of the website, and even tracks a user’s forum activity throughout the site. These are compelling reasons to use bbPress over other alternatives such as Simple:Press on any BuddyPress site.
Unfortunately, BuddyPress forces bbPress forums to be tied to groups. You cannot participate in a forum unless you are a member of its associated group. Almost every client of ours has found this confusing and asked for a single central forum. We have a solution.
Credits: Credits for most of the code used here go to R-a-y.
The messy way to do it
You could install bbPress as a standalone installation, but you would then have to integrate it with BuddyPress and create a special bbPress theme that matches your BuddyPress theme. It’s a messy solution that will take hours, and it will make your head explode when it’s time to upgrade your site, especially considering the radical changes that bbPress is undergoing.
How we will be doing it
Our solution is reversible at any time and provides an elegant experience for your users. This tutorial is going to explain how to use a group forum as the site’s single forum. We will be hiding all references to the group so your users are unaware of the unconventional setup.
Warning: This will effectively remove the ability to have multiple groups on your site, and the one group you do have will be reduced to just a forum. Users won’t be able to manually join/leave it. They will automatically join it behind the scenes upon signup.
Step 1: Create a group and a forum
Log in to your Dashboard with your administrator account. Make sure you have enabled both the bbPress Forums and Groups components.
Go back to the front end of your site, and navigate to the Groups page. Click the “Create a Group” button.
Name the group carefully. You can change the name later, but changing the URL that is auto-generated will be difficult. I recommend using something simple like “support” so the URL says /support/ in it when users are accessing forum topics from this group.
On the Group’s Settings page, make the group public and select the checkbox to “Enable discussion forum.”
You should now have a group and a forum. Excellent start.
Step 2: Let users auto-join your group
A user can add a new forum topic to your site by going to the Forums tab. But when he clicks the “New Topic” button he will be presented with a pesky message that he first needs to join a group. Not what we want.
To fix this we will add a function to your functions.php file, auto-joining users to your group. Add this function, replacing <# group ID #> on line five with the numeric ID of your group.
//Automatically add new users to a group
function automatic_group_membership( $user_id ) {if( !$user_id ) return false;
groups_accept_invite( $user_id, <# group ID #> );
}
add_action( ‘bp_core_activated_user’, ‘automatic_group_membership’ );
Of course you will need to figure out the group’s number. Here’s a trick. If you have Firebug installed with Firefox, you can click on your group and then select the group’s avatar within Firebug. It will say the group’s number in the avatar’s image class. It will look something like: img class=”avatar group-2-avatar”.
This function will only work for new users. If you already have users on your site, they will not be added to the group. For this you may have to use the plugin BuddyPress Auto Group Join. Unfortunately it only works if you have multi-site enabled as it hasn’t been updated in a long time, so you will first have to enable multi-site in WordPress.
New users should now be automatically joined in your group.
Step 3: Have new topics automatically added to your group
Users should be able to add new topics now, but they will still get a pesky drop down forcing them to select which group they want to add the topic into, even though you only have the one group. To get rid of that you will need to replace some code in your theme. Via FTP, navigate to forums/index.php in your theme.
Find the lines that say:
<label><?php _e( ‘Post In Group Forum:’, ‘buddypress’ ) ?></label>
<select id=”topic_group_id” name=”topic_group_id”>
<option value=””>—-</option>
<?php while ( bp_groups() ) : bp_the_group(); ?>
<?php if ( bp_group_is_forum_enabled() && ‘public’ == bp_get_group_status() ) : ?>
<option value=”<?php bp_group_id() ?>”><?php bp_group_name() ?></option>
<?php endif; ?>
<?php endwhile; ?>
</select><!– #topic_group_id –>
Replace them with:
<input id=”topic_group_id” name=”topic_group_id” value=”5″ type=”hidden” />
Make sure to replace the value=”5” with your group’s number that we found earlier.
Step 4: Hide the group elements from your theme
Everything should be working flawlessly now. But, your forum will still look like a group, including options to add new groups, a group avatar, etc. No good. You will need to strip out some code from your group and forum template files until it is unnoticeable that there’s a group involved.
Edits to forums/index.php
The title of the forum will read as “Group Forums Directory”. This is misleading now. You will want to rename it as “Forum” or whatever you are titling your forum.
You can change this in your languages file, or you can change it right in the theme. To change it in the theme…
Find the lines:
<h3><?php _e( ‘Group Forums Directory’, ‘buddypress’ ) ?><?php if ( is_user_logged_in() ) : ?> <a class=”button” href=”#new-topic” id=”new-topic-button”><?php _e( ‘New Topic’, ‘buddypress’ ) ?></a><?php endif; ?></h3>
Replace them with:
<h3>Forum<?php if ( is_user_logged_in() ) : ?> <a class=”button” href=”#new-topic” id=”new-topic-button”><?php _e( ‘New Topic’, ‘buddypress’ ) ?></a><?php endif; ?></h3>
Edits to groups/index.php
Whenever you view a forum topic, you are actually viewing a group page. It will have a button to “Create a Group.” We will replace this with a button to “View all Forum Topics” returning users to the main forum.
Find the lines:
<h3><?php _e( ‘Groups Directory’, ‘buddypress’ ) ?><?php if ( is_user_logged_in() ) : ?> <a class=”button” href=”<?php echo bp_get_root_domain() . ‘/’ . BP_GROUPS_SLUG . ‘/create/’ ?>”><?php _e( ‘Create a Group’, ‘buddypress’ ) ?></a><?php endif; ?></h3>
Replace them with:
<h3><?php _e( ‘Groups Directory’, ‘buddypress’ ) ?> <a class=”button” href=”<?php echo bp_get_root_domain() . ‘/’ . BP_FORUMS_SLUG ?>”><?php _e( ‘View all Forum Topics’, ‘buddypress’ ) ?></a><?php if ( is_user_logged_in() && current_user_can(‘administrator’)) : ?> <a class=”button” href=”<?php echo bp_get_root_domain() . ‘/’ . BP_GROUPS_SLUG . ‘/create/’ ?>”><?php _e( ‘Create a Group’, ‘buddypress’ ) ?></a><?php endif; ?></h3>
Edits to groups/single/group-header.php
The group header is where most of the references to your forum being a group are. We will want to remove most of the code from this file.
Replace all code here with:
<?php do_action( ‘bp_before_group_header’ ) ?><?php do_action( ‘bp_after_group_header’ ) ?>
<?php do_action( ‘template_notices’ ) ?>
Edits to groups/single/forum/topic.php
Individual forum topics include a button for the “Group Forum Directory” which we will be replacing with a button to “View all Forum Topics.”
Find the lines:
<a class=”button” href=”<?php bp_forum_permalink() ?>/”>← <?php _e( ‘Group Forum’, ‘buddypress’ ) ?></a> <a class=”button” href=”<?php bp_forum_directory_permalink() ?>/”><?php _e( ‘Group Forum Directory’, ‘buddypress’) ?></a>
Replace them with:
<a class=”button” href=”<?php bp_forum_directory_permalink() ?>/”><?php _e( ‘View all Forum Topics’, ‘buddypress’) ?></a>
Edits to _inc/css/default.css
There are some elements that make sense to hide through CSS. It’s quick and reversible. Adding the following code to your stylesheet should do the trick:
/* > Single Forum Setup
————————————————————– */body.forum #item-header, body.forum #item-nav {
display: none;
}
table.forum th#th-group, table.forum td.td-group {
display: none;
}
body.my-groups #item-body #subnav.item-list-tabs, body.my-groups #item-body .groups {
display: none;
}
Step 5: Remove any ability to access groups
Remove Groups from navigation
In your header.php file, you will want to comment out the link to the Groups page so the Groups menu no longer shows up in your navigation.
<!–
<?php if ( bp_is_active( ‘groups’ ) ) : ?>
<li<?php if ( bp_is_page( BP_GROUPS_SLUG ) || bp_is_group() ) : ?> class=”selected”<?php endif; ?>>
<a href=”<?php echo site_url() ?>/<?php echo BP_GROUPS_SLUG ?>/” title=”<?php _e( ‘Groups’, ‘buddypress’ ) ?>”><?php _e( ‘Groups’, ‘buddypress’ ) ?></a>
</li>
–>
Remove Groups from URLs
If someone knows what they are doing, they could still potentially type /groups into your URL to get to the Groups page. They could also type /groups/create to create a new group on you site. You can install a redirect plugin such as Redirection and simply redirect these pages to /forums.
Remove Groups from Admin Bar
Your users can still navigate to the Groups menu in the Admin Bar, which is misleading and confusing. To remove this menu item completely, just add this function to functions.php:
// remove groups from adminbar
function bb_remove_groups_from_nav() {
global $bp;unset( $bp->bp_nav[groups] );
}
add_action( ‘init’, ‘bb_remove_groups_from_nav’ );
You should be all done now!
Reversing all of your changes
Down the road, bbPress will eventually be re-coded as a plugin and will potentially have the ability to integrate with BuddyPress as a standalone forum, without the need for hacking. Don’t worry, what we’ve done today is easily reversible for when that time finally comes.
Just comment back in the Groups menu in your header.php file, remove the extra functions from your functions.php file, and revert back to the default template files for groups and forums (included in bp-default). If you added some redirects, don’t forget to remove them. You should now be back to the default multi-groups and multi-forums setup, with one existing group and forum.
Want us to do it all for you?
We can set this up on your site in 2 hours at $100/hr. Click Add to Cart to get a single forum on your site.
[cart-button item=”112510001″ ]