Beginner’s Guide to BuddyPress: Tips And Resources
WordPress is quite possibly the most widely used open source CMS with thousands of free themes and plugins. Fans of the software have most likely heard of the infamous BuddyPress plugin for WordPress sites. You can extend the functionality to include user profile pages, private messaging, and even user discussion forums.
BuddyPress is almost a vast social networking library in itself, which just happens to run off the WordPress core. In this article we can take a peek at ten useful tricks for newly inducted BuddyPress users.
I will focus on some of the basic installation techniques while also including references to more detailed code snippets. This is an excellent guide for new users who are looking to play around in BuddyPress and see what it has to offer.
Before jumping right into the list, I’ll offer a brief overview explaining some of the features within BuddyPress. Many first time users get confused working with BuddyPress and bbPress forums. Allow me to clarify these ideas quickly.
60 Best Responsive WordPress Themes (Free and Paid)
The shift towards mobile browsing has made responsive website design more important than ever. As most people now... Read more
Differences between BuddyPress and bbPress
BuddyPress was the first of these two being released for WordPress back in 2008. The plugin has always been open source, and it thrives on user contribution. You can learn more about BuddyPress’s core features on their About page.
What most people don’t realize is that BuddyPress actually comes packaged with bbPress. That means if you install BuddyPress into your website this will include all the same functionality as the stand-alone bbPress plugin. The development team is comprised much of the same people, and both of these plugins have been in development for a few years.
In this guide I will be focusing mostly on BuddyPress functionality, but I also have some great tips for bbPress users. You can think of these features as one single package if that makes it easier.
BuddyPress doesn’t require the bbPress forums to run, as they are an optional setting. If you want to compare other differences check out this forum thread.
1. Install & Configure BuddyPress
For WordPress users who have never gone through the core process of using BuddyPress, then this article is for you. Adam Murray over at WPTuts+ has written an excellent series which focuses on installing and customizing BuddyPress for new users.
This walkthrough tutorial is the best way to learn the system without diving in alone by yourself. You can learn about the key features of BuddyPress and many of the various options inside the WordPress admin panel.
There are tons of resources and BP features to study, including private messaging, activity streams, user blogs, extended profiles, and a whole lot more.
Adam also discusses some deeper customizations like setting up groups and custom themes. BuddyPress has its own core files which can utilize alternate plugins and themes! Definitely some helpful knowledge for beginners.
2. Understanding bp-custom.php
WordPress developers are mostly familiar with the custom theme file functions.php. This allows you to copy and paste PHP code which changes settings in the WordPress core, without actually altering the core files. This system has been adopted in BuddyPress using a file named bp-custom.php.
The online documentation does an excellent job of explaining the file with some examples. Basically you create this file inside your plugins directory /wp-content/plugins/
and simply add all your codes. These will execute regardless of your current theme for WordPress and BuddyPress.
The function codes you write are tied into other functions placed in the core files. You can access these hooks by using filters and actions just like inside WordPress.
After enough time building inside BuddyPress you’ll begin to memorize the variable names and method calls. This is an excellent trick for customizing your forums without too much experience.
3. Developing BuddyPress Themes
This series of templating articles is split into three different sections, all written by Adam Murray who wrote our earlier introduction tutorial. Although there are probably other guides on theming BuddyPress I feel that Adam goes into a greater level of detail for beginners.
The tricks you can learn from this 3-part editorial are phenomenal, if you are just getting started. If you are already familiar developing WordPress themes then most of the code will look familiar.
There are similar functions you should call, such as the_content()
and the_category()
. But BuddyPress obviously has its own set of functions and methods for interacting with user profiles.
The content is broken down into loops which are usually PHP/SQL queries retrieving content from the database. You may think of these loops as some of the different pages inside BuddyPress.
These page loops could be referencing user profiles, group lists, member lists, forum topics, private messages, or anything similar. The concepts are all related to WordPress so if you already understand that domain of knowledge, theming for BuddyPress shouldn’t be too challenging.
A Guide To: WordPress Child Themes Development
There are a number of reasons that WordPress developers are starting to use child themes. They give you... Read more
4. Step-by-Step Guide to Custom bbPress Themes
Similar to BuddyPress theming you can also build your own custom bbPress themes. I found this online guide for bbPress theming in their documentation and it provides an excellent reference point.
The current guide is written for bbPress 2.0.2 themes and the most updated release as of this article is bbPress 2.2. However the topics are still applicable, and you can learn all of the basic ideas very quickly. Theming for bbPress is much simpler than BuddyPress since you are focusing solely on the forums areas (and possibly user profiles).
Another option which is mentioned in the documentation is to create a bbPress child theme. This will run off an already existing theme and only use your specific customizations in the template. Oftentimes this method is a lot easier so that you aren’t coding an entire theme layout from scratch.
Showcase of Beautiful WordPress-Powered Websites
WordPress has stepped into its 9th year of being the content management system that most website owners love,... Read more
5. Update BuddyPress User Profile Links
When first installing BuddyPress you will notice that the typical user profile link actually goes to the WordPress dashboard. You may customize this inside the plugin’s settings page where you see “Logged In Links”.
The second anchor tag needs to be edited to match your custom members URL. By default BuddyPress follows the schema http://yoursite.com/members/username/
which you could update. But to get this displaying properly as a link, you want to change the second anchor to look something like this:
<a href="http://yoursite.com/members/%USERNAME%/">Profile</a>
6. Excluding Users from Member Directory List
There may be times where you wish to hide certain members from your BuddyPress public listings. This could include friend pages or even searching for members. Just a few ideas could be hiding admin accounts, moderators, or fake accounts you have created for testing new features.
I’ve copied over a code snippet which you may place in your bp-custom.php file. All you need to edit is the list of $excluded_user
ID variables. This small hack comes courtesy of Brajesh Singh from his blog BuddyDev.
add_action('bp_ajax_querystring','bpdev_exclude_users',20,2); function bpdev_exclude_users($qs=false,$object=false){ //list of users to exclude $excluded_user='1,2,3';//comma separated ids of users whom you want to exclude if($object!='members')//hide for members only return $qs; $args=wp_parse_args($qs); //check if we are searching or we are listing friends?, do not exclude in this case if(!empty($args['user_id'])||!empty($args['search_terms'])) return $qs; if(!empty($args['exclude'])) $args['exclude']=$args['exclude'].','.$excluded_user; else $args['exclude']=$excluded_user; $qs=build_query($args); return $qs; }
7. Custom Member Redirect for Registration Page
When your users are logged in and trying to access the registration page, BuddyPress will send them over to the members listing instead. This effect is caused by a small bit of code in the core registration file. However instead of hacking the core we can use a filter to redirect users onto a custom page instead.
Copy the following codes into your own bp-custom.php or functions.php in WordPress. It is generally better to segregate bbPress/BuddyPress codes away from your WordPress codes. But all of the PHP here is fairly straightforward, and all you need to customize is the $redirect_to
variable.
function bbg_bp_loggedin_register_page_redirect_to( $redirect_to ) { if ( bp_is_component_front_page( 'register' ) ) $redirect_to = bp_get_root_domain() . '/home'; return $redirect_to; } add_filter( 'bp_loggedin_register_page_redirect_to', 'bbg_bp_loggedin_register_page_redirect_to' );
8. Reorder BuddyPress Default Profile Links
BuddyPress will set navigation menu positions for each link in your template. These links include ‘User Profile’, ‘Activity’, ‘Friends’, ‘Messages’, and other BuddyPress features. By creating your own custom action tied into bp_setup_nav
you may edit these position values to rearrange the navigation links.
I found an excellent solution in this StackExchange thread which outlines how you can setup the position array values. I have copied over the basic code below; feel free to customize and edit these values to suit your own needs. This will run perfectly from your BuddyPress bp-custom.php file and from your WordPress theme’s functions.php, as well.
function bbg_change_profile_tab_order() { global $bp; $bp->bp_nav['profile']['position'] = 10; $bp->bp_nav['activity']['position'] = 20; $bp->bp_nav['blogs']['position'] = 30; $bp->bp_nav['friends']['position'] = 40; $bp->bp_nav['messages']['position'] = 50; $bp->bp_nav['groups']['position'] = 60; $bp->bp_nav['settings']['position'] = 70; } add_action('bp_setup_nav', 'bbg_change_profile_tab_order', 999 );
9. Display User Total Posts & Topics Started
The bbPress forums are very generic from the beginning. This doesn’t mean you cannot customize your own styles, but it means you’ll be doing a lot of research and grunt coding work.
This code snippet will display each user’s total number of forum posts and forum threads started. This is a typical metric you find on forums all over the Web, so it is commonplace to expect these numbers on BuddyPress user profiles too.
I found this small bit of code in a blog post from 2009. The codes are very simple, pulling two unique SQL queries from the database depending on the current profile ID. Just locate bb_profile_data();
in your template and replace it with this:
<?php bb_profile_data(); ?> <div id="user-stats"> <?php global $bb_table_prefix; $query1 = "SELECT COUNT(*) FROM ".$bb_table_prefix."posts WHERE poster_id = $user_id AND post_status = 0"; $query2 = "SELECT COUNT(*) FROM ".$bb_table_prefix."posts WHERE poster_id = $user_id AND post_status = 0 AND post_position = 1"; echo "Forum Posts: <b>".$bbdb->get_var($query1)."</b> "; echo " Topics Started: <b>".$bbdb->get_var($query2)."</b>"; ?> </div>
10. Override Default BuddyPress Avatars
Custom user avatars is a regular feature most developers expect within any CMS. WordPress allows this feature for authors and users, but it doesn’t transfer well into BuddyPress. Also you may wish to setup two distinct avatars based on WordPress and BuddyPress.
With this bit of code you can overwrite the default avatar photo for your BuddyPress users and replace it with a new URL. Note that this will only display on members who have not customized their own avatar yet. Just add the following codes into your bp-custom.php file and make sure to update the my_default_avatar_url()
function so it returns the proper URL for your new default image.
add_filter( 'bp_core_fetch_avatar_no_grav', '__return_true' ); function my_default_avatar_url() { return 'http://mysite.com/images/static/avatar.jpg'; } add_filter( 'bp_core_default_avatar_user', 'my_default_avatar_url' );
Other Helpful Materials
Final Thoughts
I hope this guide can be informative to new BuddyPress and bbPress users. Managing your own blog can be a tough job, let alone a whole userbase and community. Getting comfortable with BuddyPress may require hours of practice and coding to get your install running just right. If you are ever lost, you can post questions in the BuddyPress support forums to chat with developers and other knowledgeable team members.