Codex Home → Developer Resources → The $bp Global
The $bp Global
The $bp global contains all of the variables and configuration settings that BuddyPress needs to use throughout an installation. As a developer you may find a good first step is to use the function below to render out the contents. You』ll then be able to look over everything and get a glimpse into how things work behind the scenes.
Add this to the top of 『bp-core.php』 and you』ll be able to take a good look at it:
function bp_dump() {
global $bp;
foreach ( (array)$bp as $key => $value ) {
echo '<pre>';
echo '<strong>' . $key . ': </strong><br />';
print_r( $value );
echo '</pre>';
}
die;
}
add_action( 'wp', 'bp_dump' );
Here』s an description of each setting:
$bp->root_components array
The slug of each component that can run in the root of the site. For example, 『groups』 is a root component because it can run both on http://example.org/members/andy/groups but also in the root: http://example.org/groups/my-group/. Settings can be added using the function bp_core_add_root_component( $component_slug )
$bp->root_domain string
The domain of the root blog on your WPMU installation.
$bp->loggedin_user object
Contains the ID, URL and name of the currently logged in user.
$bp->loggedin_user->id The user ID of the user.
$bp->loggedin_user->domain The profile page URL of the user
$bp->loggedin_user->fullname The display name of the user
$bp->displayed_user object
If you』re looking at a user』s profile page, or any page under http://example.org/members/[username]/ then displayed_user will hold the ID, URL and name of that user. If you』re not currently looking at a user these values will return false.
$bp->displayed_user->id The user ID of the user.
$bp->displayed_user->domain The profile page URL of the user
$bp->displayed_user->fullname The display name of the user
$bp->current_component string
The slug of the component that is currently being viewed. For example on the URL http://example.org/members/andy/messages/ the current_component would be messages. On http://example.org/groups/my-group current_component would be groups. If no component is being viewed (for example on the root) then current_component will equal $bp->default_component.
$bp->current_action string
The action being carried out within a component. Current action is usually always the next parameter in the URL after $bp->current_component. For example the URL http://example.org/members/andy/messages/view/345 current_action would be view. If $bp->current_component is in the list in $bp->root_components, and we are in the root (not /members/): http://example.org/groups/my-group/join current_action would be join where as my-group would be $bp->current_item.
$bp->action_variables array
Action variables are all the remaining sections of the URL after $bp->current_action. Each section (chunks of the URL between forward slashes) become an item in the array. For example the URL http://example.org/members/andy/groups/my-groups/leave/15 the values leave and 15 would each be items in the action_variables array.
$bp->current_item string
Only used when $bp->current_component is in the list of components in $bp->root_components. If we are working in the root of the install, but within a BuddyPress component, we need to offset $bp->current_action by one, to make way for a content item. For example: http://example.org/groups/my-group/join the current_item would be my-group as it is the current content item that we are viewing. $bp->current_action would then become join. Again, this is only when working in the root, and not under the /members/ slug.
$bp->is_single_item bool
This parameter is set as true if we are viewing a single content item in the root of an installation. For example, if we are viewing a group under the URL: http://example.org/groups/my-group/ then is_single_item will be true. This forces WordPress to use the currently active BuddyPress member theme to display the content, where as it would normally have used the active WordPress theme. If you created a custom component with a URL such as: http://example.org/muffins/chocolate/ you』d want to set $bp->is_single_item to true when viewing /chocolate/, so that the BuddyPress member theme can be used to display templates.
$bp->default_component string
When the user visits http://example.org/members/[username]/ which component should be shown? This is the slug value of that component.
Default: profile
$bp->bp_nav array
This is the array used to render each component navigation menu item for the logged in user. Each component is an item of the array, which in itself is an array containing three items (listed below). You can add to this array by using the function bp_core_add_nav_item().
$bp->bp_nav[]['name'] The display name for the component.
$bp->bp_nav[]['link'] The URL to the main page of the component – using the currently logged in user』s profile link.
$bp->bp_nav[]['css_id'] The CSS ID to use for the navigation item when it is rendered to the page in HTML.
$bp->bp_users_nav array
This is the array used to render each component navigation menu item for the displayed user (when you view a user that is not you). It follows the same format as $bp->bp_nav. This navigation array is different though, as it will not contain links to components that are only viewable by a logged in user (for example, messaging).
$bp->bp_users_nav[]['name'] The display name for the component.
$bp->bp_users_nav[]['link'] The URL to the main page of the component – using the currently displayed user』s profile link.
$bp->bp_users_nav[]['css_id'] The CSS ID to use for the navigation item when it is rendered to the page in HTML.
$bp->bp_options_nav array
This is the array used to render all of the sub navigation items for the $bp->bp_nav array. Each item is mapped to a top level nav item via its array key. Each sub level nav item contains the same options as the top level nav items, shown below.
$bp->bp_options_nav[]['name'] The display name for the sub-nav item.
$bp->bp_options_nav[]['link'] The URL to the main page of the component – using the currently logged in user』s profile link.
$bp->bp_options_nav[]['css_id'] The CSS ID to use for the navigation item when it is rendered to the page in HTML.
$bp->bp_options_title string
This is the title for the currently displayed sub-navigation item list. For example, when viewing the 「Messages」 component, the title of the sub-navigation item list would be 「My Messages」. If we were viewing a user』s profile other than ours, the title for the sub-navigation item list would be the name of the user.
$bp->bp_options_avatar string
This is the avatar associated with the sub-navigation item list. For instance, if we are viewing a user other than the user logged in, the avatar would be that user』s avatar. If we were viewing a group, the avatar would be that group』s avatar.
$bp->grav_default string
The default setting for gravatar type, when the user has no avatar or gravatar set. This is changed in the wp-admin area under 「BuddyPress > General Settings」.
$bp->is_item_admin bool
This setting can be used to give a user admin privileges on a particular piece of content. For site admins, this is always set to true, giving them override privileges on any content. For example, on the groups component, this is set to true if the currently logged in user is the creator of a group and that group is currently being viewed.
$bp->is_item_mod bool
Exactly the same as $bp->is_item_admin but for moderation privileges (basically a step down from admin privileges). This is used in the groups component for group moderators.
$bp->[component_name] object
Replace [component_name] with the name of a component and you will be able to access all of the settings for that component. Common settings for all components are listed below:
image_base The image directory for component specific images
table_name The name of the primary table used by the component
slug The URL slug for the component.
format_activity_function The function name that will format activity items into something readable by the end user.
format_notification_function The function name that will format notifications into something readable by the end user.