bp-custom.php

bp-custom.php

Codex Home → BuddyPress Theme Development → bp-custom.php
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.
bp-custom.php is often compared to your theme』s functions.php file.
However, there are two primary differences between bp-custom.php and your theme』s functions.php.

First, bp-custom.php runs from the /wp-content/plugins/ folder and is therefore independent from your theme. This is useful for adding code snippets that are BuddyPress-specific. Also, this code will always load regardless of what theme you are using.
Secondly, bp-custom.php runs early in the BuddyPress-loading process. This allows you to override various settings in BuddyPress.

Choosing which file to place your code snippet in is largely a matter of choice. If you are packaging a BuddyPress theme, then you might want to consider using your theme』s functions.php instead. However, for the most part, you should use bp-custom.php.
Creating your file
bp-custom.php does not exist by default. If you don』t have a file located at /wp-content/plugins/bp-custom.php, go ahead and create a blank file with the following:

Next, save the file as 「bp-custom.php」 and verify that this file is located at /wp-content/plugins/.
Now, when you encounter a forum thread telling you to put a code snippet in bp-custom.php, you』ll know what to do!
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' );
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.

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注