If you don’t see a Template Support Pack for your plugin on this page, you can adapt it yourself by following the steps below.
You may run across a cool plugin you want, but find that the pages it generates look kinda crappy in BuddyBuilder. (That’s probably because the plugin is using its own CSS to deliver its content to your site, but it doesn’t really fit. You’ll need to edit the plugin’s CSS file to fix that, but that’s not the subject of this tutorial… sorry).
Or, they might look absolutely perfect but you want to enable them with BuddyBuilder features. The following steps will show you how to do just that.
You’ll have to start by figuring out which plugin templates need editing. They’re likely called “index.php”, “home.php”, “directory.php”, etc. Depending on the complexity of the plugin, there may be a few that need attention. Be careful though; make sure you only edit plugin files that actually deliver content to the browser. If in doubt, contact the plugin author before proceeding with this tutorial.
The first thing you need to check for in any template file is that the content it generates fits in the standard Buddypress box. To do that, it needs to call the header, footer and sidebar files, as well as put everything else in a nice padded content area.
You should see this at the very top:
1 2 3 | <?php get_header() ?> <div id="content"> <div class="padder"> |
And this at the very bottom:
1 2 3 4 | </div><!-- .padder --> </div><!-- #content --> <?php locate_template( array( 'sidebar.php' ), true ) ?> <?php get_footer() ?> |
If you don’t see the above code in the appropriate files, add whatever is missing now.
Now let’s get stuff working with BuddyBuilder.
Start by adding the following global call immediately after the one to the header that tells the template there’s BuddyBuilder stuff going on here!
1 | <?php global $cap; ?> |
Next, you need to add a conditional statement to load the second sidebar if you select “Sidebars Left and Right” in your BuddyBuilder admin panel. Add the following code just before the call to the footer:
1 2 3 | <?php if($cap->sidebar_placement == "Sidebars Left and Right"){?> <?php locate_template( array( 'sidebar2.php' ), true ) ?> <?php };?> |
Add alternate headers for groups and member profiles.
If this plugin adds a subnav item in Groups or member Profiles, the plugin author has hopefully used the Buddypress plugin template for the appropriate component. This means that the alternate headers will show automatically if enabled in the “BP & WP” section of your admin panel (renamed to “BP Extras” in v1.1). If they don’t, you can edit the appropriate files to display the alternate BuddyBuilder headers. To do so, you’ll need to locate some code in your plugin’s template.
If the plugin adds content to Groups, find this snippet:
1 2 3 | <div id="item-header"> <?php locate_template( array( 'groups/single/group-header.php' ), true ) ?> </div> |
If the plugin adds content to Members, look for this one:
1 2 3 | <div id="item-header"> <?php locate_template( array( 'members/single/member-header.php' ), true ) ?> </div> |
First, let’s tell the template to load the default headers only if that is selected in BuddyBuilder. Add the following just before either of the above code snippets:
1 | <?php if($cap->alternate_headers == "Default Headers"){?> |
And this just after the snippet:
1 | <?php };?> |
Now let’s tell the templates how to load the alternate headers if that option is selected. If the plugin adds content to Groups, add the following code just after the above snippet:
1 2 3 4 5 6 7 8 9 10 11 | <?php if($cap->alternate_headers == "Alternate Headers"){?> <?php if ( bp_is_group_home() ) : ?> <div id="item-header" style="margin-bottom:20px;"> <?php locate_template( array( 'groups/single/group-header.php' ), true ) ?> </div><!-- #item-header --> <?php else : ?> <div id="alt-item-header"> <a href="<?php bp_group_permalink() ?>" title="<?php bp_group_name() ?>"><?php bp_group_avatar( 'type=thumb' ) ?></a><h2><br /> Group: <a style="text-decoration:none;" href="<?php bp_group_permalink() ?>home/" title="<?php bp_group_name() ?>"><?php bp_group_name() ?></a></h2> </div> <?php endif; ?> <?php };?> |
If the plugin adds content to Member Profiles, add the following:
1 2 3 4 5 6 7 8 9 10 11 | <?php if($cap->alternate_headers == "Alternate Headers"){?> <?php if ( bp_is_activity_component() ) : ?> <div id="item-header" style="margin-bottom:20px;"> <?php locate_template( array( 'members/single/member-header.php' ), true ) ?> </div><!-- #item-header --> <?php else : ?> <div id="alt-item-header"> <a href="<?php bp_user_link() ?>"><?php bp_displayed_user_avatar() ?></a><h2 class="fn"><a style="text-decoration:none;" href="<?php bp_displayed_user_link() ?>"><br /> <?php bp_displayed_user_fullname() ?></a></h2> </div> <?php endif; ?> <?php };?> |
Add the BuddyBuilder privacy feature.
If this is a plugin you want to control with the “Show BP⁄WP Plugin Directories to…” privacy feature in your BuddyBuilder admin panel, you’ll need to edit the directory template and the Groups & Profile templates (if applicable) differently.
For the directory template, simply add the following code near the top of the directory template file, just after the opening tag for the padder div:
1 2 3 4 5 6 7 8 9 | <?php if ($cap->hide_bp_plugins == 'Logged-in members only' && !is_user_logged_in() ) : ?> <div id="message" class="error"> <?php if(!$cap->not_loggedin_message == "") : ?> <p><?php echo($cap->not_loggedin_message)?></p> <?php else : ?> <p><?php echo 'You must be logged-in to view this page.' ?></p> <?php endif; ?> </div> <?php else : ?> |
Then add the following just before the closing tag for the padder div:
1 | <?php endif; ?><!--is_user_logged_in--> |
For templates delivering content to groups or member profiles, add the first part of the above code (the “php if” part) just before the opening item-body tag (between that tag and the code you added earlier for the alternate headers). Add the second part of the code (the “endif” part) just after the corresponding closing tag for the div container. Hopefully, the plugin author was thoughtful enough to identify the closing tags for you, otherwise you may have to hunt for it.