The $bp Global
The $bp global is deprecated. Instead, you should use the following, inside a function:
Now the $bp, 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:
Here’s an description of each setting:
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/groupsbut also in the root:
http://example.org/groups/my-group/. Settings can be added using the function
bp_core_add_root_component( $component_slug )
The domain of the root blog on your WPMU installation.
Contains the ID, URL and name of the currently logged in user.
$bp->loggedin_user->idThe user ID of the user.
$bp->loggedin_user->domainThe profile page URL of the user
$bp->loggedin_user->fullnameThe display name of the user
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
$bp->displayed_user->idThe user ID of the user.
$bp->displayed_user->domainThe profile page URL of the user
$bp->displayed_user->fullnameThe display name of the user
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
http://example.org/groups/my-groupcurrent_component would be
groups. If no component is being viewed (for example on the root) then current_component will equal
The action being carried out within a component. Current action usually always is the next parameter in the URL after
$bp->current_component. For example the URL
http://example.org/members/andy/messages/view/345current_action would be
$bp->current_componentis in the list in
$bp->root_components, and we are in the root (not /members/):
http://example.org/groups/my-group/joincurrent_action would be
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
15would each be items in the action_variables array.
Only used when
$bp->current_componentis 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_actionby one, to make way for a content item. For example:
http://example.org/groups/my-group/jointhe current_item would be
my-groupas it is the current content item that we are viewing.
$bp->current_actionwould then become join. Again, this is only when working in the root, and not under the
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_itemto true when viewing /chocolate/, so that the BuddyPress member theme can be used to display templates.
When the user visits
http://example.org/members/[username]/which component should be shown? This is the slug value of that component.
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->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.
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.
This is the array used to render all of the sub navigation items for the
$bp->bp_navarray. 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.
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.
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.
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”.
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.
Exactly the same as
$bp->is_item_adminbut for moderation privileges (basically a step down from admin privileges). This is used in the groups component for group moderators.
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_baseThe image directory for component specific images
table_nameThe name of the primary table used by the component
slugThe URL slug for the component.
format_activity_functionThe function name that will format activity items into something readable by the end user.
format_notification_functionThe function name that will format notifications into something readable by the end user.