bp-custom.php

Codex HomeCustomizing → bp-custom.php

You’ve probably heard a lot of talk about a bp-custom.php file on the BuddyPress forums or WordPress forums.

So what is it?

bp-custom.php is a file that resides in your WordPress ‘plugins’ folder where you can add a bunch of custom code hacks and modifications to BuddyPress.

↑ Top ↑

When to use it

bp-custom.php is a sister file to functions.php which resides in your main theme folder. Both files perform a similar type of service, running snipets of code for a site. There are two primary differences in these files though, bp-custom.php runs from the plugins folder and is therefore independent of your theme so is useful for adding snippets that you require to interact with BP regardless of the theme in use also it runs at a specific point in the loading of BP that allows BP to acknowledge it’s instructions,functions.php on the other hand is tied to a specific theme so code in it is only run for that theme, changing themes means those snippets of code will no longer be run unless transfers to the other theme. Choosing which file you need to place your code in is largely a matter of choice, most bp code may be run from function.php using suitable hooks to ensure your code runs at specific points in the BP process but if those do not work or you want your code modifications to be available to any theme then run your code in bp-custom.php.

↑ Top ↑

Creating your file

bp-custom.php does not exist by default and is created by the user when they require it. If you don’t have a file called bp-custom.php located here ‘/wp-content/plugins/bp-custom.php‘, go ahead and add one by creating a blank file with the following:

<?php
// hacks and mods will go here

?>

When you encounter a forum thread telling you to put a code snippet in bp-custom.php, now you’ll know what to do!

↑ Top ↑

Examples

Removing the links automatically created in a member’s profile

This can be done by adding the following function to the bp-custom.php file.

BP 1.2.9

function remove_xprofile_links() {
	remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 50, 2 );
}
add_action( 'plugins_loaded', 'remove_xprofile_links' );

BP 1.5

function remove_xprofile_links() {
	remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 2 );
}
add_action( 'bp_init', 'remove_xprofile_links' );

↑ Table of Contents ↑

Defining custom slugs

Developers may modify the default URL slugs for activity, forums, etc by adding a statement in the bp-custom.php file.

// change 'discuss' to whatever you want
define( 'BP_FORUMS_SLUG', 'discuss' );

See the customizing labels messages and urls article for more information on modifying slugs.