Code Snippets

Changing the default BuddyPress notifications settings

I think this is one of those small things that should be added to BuddyPress core, but the following snippet allows you to change the default Notification settings for new users. This snippet is taken directly from the BuddyDev blog. Buddydev is run by my friend Brajesh and his team who’ve been providing the community with free and premium plugins for years.

Add the code below to bp-custom.php

Note: This functionality is also available as a premium plugin on BuddyDev. Check it out!

Screenshot 2015-02-23 11.42.04
Code Snippets

High quality BuddyPress avatars with Jetpack Photon support

If you need high quality BuddyPress avatars that look amazing on retina devices and are also served through the blazing fast Jetpack Photon CDN, this is the trick for you.

Requirements:
– BuddyPress 1.5+
– Jetpack with Photon enabled

Step 1: Change the default BuddyPress Avatar values

Add the code below to bp-custom.php

Step 2: Change the default Photon image quality

Add the code below to bp-custom.php

Props to Devinsays

Screen Shot 2015-02-20 at 16.48.56
Code Snippets

Add a Easy Digital Downloads “My Purchases” page to a BuddyPress Member profile

The following snippet adds a “My Purchases” page to a member profile. In order for this to work you need the following

  • Easy Digital Downloads set up and configured
  • BuddyPress 2+
  • Both plugins needs to be active and running on the same site (in case of Multisite)

Add the following to bp-custom.php

Customize as needed!

Bonus Trick!

The snippet below also automatically redirects users that are logged in and browse to the “regular” EDD purchases page.

Screen Shot 2015-02-18 at 10.12.10
Code Snippets

Two BuddyPress login tricks you should be using for your community

It’s often in the small things, and this post will give you two small but valuable tricks that make the lives of your community members a lot easier.

Trick #1: Automatically check the “Remember me” box on your login form.

Add the following snippet to bp-custom.php

This quick snippet will automatically check the “remember me” checkbox on your front-end and wp-login.php login form. Sweet!

Trick #2: Extend the default login cookie expiration length

By default a user is logged out after 48 hours or when closing their browser completely. That is certainly less than ideal for a social network. The snippet below changes this only logout after a month of inactivity. Much better huh?

Thanks to: Sarah Gooding / WPMUDev & DZone

Any more tricks related to these? Feel feel to share them in the comments!

Code Snippets

Translate default BuddyPress widgets (or any other widget!)

This is one of those super specific things 99% of you guys probably won’t ever have to do. But it still might be useful for someone out there.

If you are running a multilingual BuddyPress community where users can switch languages, the following snippet allows you to make your BuddyPress widget translatable.

Further Instructions

Make sure to give your widget a title. In the above snippet that title is “Members”. But you can come up with whatever you like.

Mega props to David Cavins for this one.

Code Snippets

A Simple BuddyPress Shortcode: Display the username

I wanted to show the BuddyPress username of the currently logged in user in a regular WordPress page through a shortcode. Here is how you do it.

Add the following code to BP-Custom.php

Now you can use the shortcode in your post content like this:

Bonus tip: Want to display xprofile fields through shortcodes? Check out the following plugin

buddypress-global-search-plugin-new
Plugins

Search your entire BuddyPress community with the BuddyPress Global Search plugin

Every once in a while a new plugin comes along that I can recommend for every BuddyPress community and the new BuddyPress Global Search plugin from the team at BuddyBoss is one of those plugins.

The plugin allows your users to quickly search for:

  • Users
  • Groups
  • Activity Updates
  • Blog Posts
  • Forum Topics
  • Any custom post type you specify

Search results are shown instantly as you type using a fancy Ajax dropdown. It’s pretty darn awesome.

Where to download the plugin

You can grab the plugin from two places at the moment.

1: From the BuddyBoss Website
2: From the official WP.org repository

How to use the plugin

After you’ve downloaded and installed the plugin your default WordPress search form will be modified automatically to display your new BuddyPress Global Search results. So that means there’s nothing you have to behind the scenes. Install & Activate!

My Impressions

buddypress-global-search-plugin

After installing and activating the plugin everything worked exactly as advertised. Searching is fast, accurate and my custom post types (Videos) where shows in the search results as well. Superb!

Screenshot 2014-12-12 11.45.19
Design

Adding a CSS class to the body when the page is not a BuddyPress page

When I write my CSS/LESS I often use body classes to target elements on specific pages on my site. BuddyPress does a good job of adding it’s own custom body classes to the BuddyPress pages, but it also inherits some of the WordPress classes like .page. The snippet below adds a simple body class wordpress-page to all regular WordPress pages. This allows you to write custom CSS that is only applied to WordPress pages without affecting the styling of BuddyPress content.

Add the following to bp-custom.php

Here’s a quick example of how you could then use this.

.wordpress-page .content {
font-size: 110%;
}

Have fun theming!