Tips – Tricks – Code Snippets

Codex HomeCustomizing → Tips – Tricks – Code Snippets

The following code snippets are to be used AT YOUR OWN RISK. Most are harmless but could cause potential conflict with other plugins or even the core code. Please test before using on a production site.

Snippets are from various places around the web and also posted in the BuddyPress support forums

This is a centralized location to find snippets of code to customize and enhance your BuddyPress site. Add the code snippets to a file bp-custom.php and place in wp-content/plugins/bp-custom.php

Skip the Gravatar check when using a default BP avatar.

When you choose the default avatar as the mystery man BuddyPress still sends a gravatar request. This turns off that extra request making page load times faster by lessening http requests.

add_filter( 'bp_core_fetch_avatar_no_grav', '__return_true' );
props r-a-y

↑ Table of Contents ↑

Show profile fields in member header.

If you want to add extra profile info in the members profile header this function will do that. Change field= to the field you want to display.

function extra_profile_fields_output(){
  global $bp;

  $field_text = bp_get_profile_field_data( 'field=Country' ) );
  echo '<span class="profile-fields">' .$field_text. '</span>';
}
add_action( 'bp_profile_header_meta', 'extra_profile_fields_output'  );
props modemlooper

↑ Table of Contents ↑

Convert birthdate and show user age in profile header.

If your user profile fields include a birth date field and you want to display age based on birthdate use this tip.

Get the tip here

props sbrajesh

↑ Table of Contents ↑

Restrict Group Creation.

2 easy ways to restrict group creation.

Get the tip here

props Polly