Skip to:
Content
Pages
Categories
Search
Top
Bottom
Codex HomeDeveloper Resources → BP_Component

BP_Component

We are currently working on a documentation reboot, here’s the new home of the best accurate docs (WIP). You’re very welcome to contribute to it.

The BP_Component class is the basis of getting your plugin initiated into BuddyPress. You extend this class to create custom components. In fact, the core components extend this class to create each core component (members, activity, groups etc.)

Updated documentation for following sections is available here.

This is the members component class which extends BP_Component:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
class BP_Members_Component extends BP_Component {
 
/**
 * Start the members component creation process
 *
 * <a class="bp-suggestions-mention" href="https://buddypress.org/members/since/" rel="nofollow">@since</a> BuddyPress (1.5)
 */
 function __construct() {
 parent::start(
 'members',
 __( 'Members', 'buddypress' ),
 BP_PLUGIN_DIR
 );
 }
 
/**
 * Include files
 *
 * <a class="bp-suggestions-mention" href="https://buddypress.org/members/global/" rel="nofollow">@global</a> BuddyPress $bp The one true BuddyPress instance
 */
 function includes() {
 $includes = array(
 'actions',
 'filters',
 'screens',
 'template',
 'buddybar',
 'adminbar',
 'functions',
 'notifications',
 );
 parent::includes( $includes );
 }
 
/**
 * Setup globals
 *
 * The BP_MEMBERS_SLUG constant is deprecated, and only used here for
 * backwards compatibility.
 *
 * <a class="bp-suggestions-mention" href="https://buddypress.org/members/since/" rel="nofollow">@since</a> BuddyPress (1.5)
 * <a class="bp-suggestions-mention" href="https://buddypress.org/members/global/" rel="nofollow">@global</a> BuddyPress $bp The one true BuddyPress instance
 */
 function setup_globals() {
 global $bp;
 
// Define a slug, if necessary
 if ( !defined( 'BP_MEMBERS_SLUG' ) )
 define( 'BP_MEMBERS_SLUG', $this-&gt;id );
 
$globals = array(
 'slug' =&gt; BP_MEMBERS_SLUG,
 'root_slug' =&gt; isset( $bp-&gt;pages-&gt;members-&gt;slug ) ? $bp-&gt;pages-&gt;members-&gt;slug : BP_MEMBERS_SLUG,
 'has_directory' =&gt; true,
 'search_string' =&gt; __( 'Search Members...', 'buddypress' ),
 );
 
parent::setup_globals( $globals );
 
/** Logged in user ****************************************************/
 
// Fetch the full name for the logged in user
 $bp-&gt;loggedin_user-&gt;fullname = bp_core_get_user_displayname( bp_loggedin_user_id() );
 
// Hits the DB on single WP installs so get this separately
 $bp-&gt;loggedin_user-&gt;is_super_admin = $bp-&gt;loggedin_user-&gt;is_site_admin = is_super_admin( bp_loggedin_user_id() );
 
// The domain for the user currently logged in. eg: http://domain.com/members/andy
 $bp-&gt;loggedin_user-&gt;domain = bp_core_get_user_domain( bp_loggedin_user_id() );
 
// The core userdata of the user who is currently logged in.
 $bp-&gt;loggedin_user-&gt;userdata = bp_core_get_core_userdata( bp_loggedin_user_id() );
 
/** Displayed user ****************************************************/
 
// The domain for the user currently being displayed
 $bp-&gt;displayed_user-&gt;domain = bp_core_get_user_domain( bp_displayed_user_id() );
 
// The core userdata of the user who is currently being displayed
 $bp-&gt;displayed_user-&gt;userdata = bp_core_get_core_userdata( bp_displayed_user_id() );
 
// Fetch the full name displayed user
 $bp-&gt;displayed_user-&gt;fullname = bp_core_get_user_displayname( bp_displayed_user_id() );
 
/** Profiles Fallback *************************************************/
 
if ( !bp_is_active( 'xprofile' ) ) {
 $bp-&gt;profile = new stdClass;
 $bp-&gt;profile-&gt;slug = 'profile';
 $bp-&gt;profile-&gt;id = 'profile';
 }
 
/** Default Profile Component *****************************************/
 if ( !defined( 'BP_DEFAULT_COMPONENT' ) ) {
 if ( bp_is_active( 'activity' ) &amp;&amp; isset( $bp-&gt;pages-&gt;activity ) )
 $bp-&gt;default_component = bp_get_activity_slug();
 else
 $bp-&gt;default_component = ( 'xprofile' == $bp-&gt;profile-&gt;id ) ? 'profile' : $bp-&gt;profile-&gt;id;
 
} else {
 $bp-&gt;default_component = BP_DEFAULT_COMPONENT;
 }
 
if ( bp_displayed_user_id() ) {
 $bp-&gt;canonical_stack['base_url'] = bp_displayed_user_domain();
 
if ( bp_current_component() ) {
 $bp-&gt;canonical_stack['component'] = bp_current_component();
 }
 
if ( bp_current_action() ) {
 $bp-&gt;canonical_stack['action'] = bp_current_action();
 }
 
if ( !empty( $bp-&gt;action_variables ) ) {
 $bp-&gt;canonical_stack['action_variables'] = bp_action_variables();
 }
 
if ( !bp_current_component() ) {
 $bp-&gt;current_component = $bp-&gt;default_component;
 } else if ( bp_is_current_component( $bp-&gt;default_component ) &amp;&amp; !bp_current_action() ) {
 // The canonical URL will not contain the default component
 unset( $bp-&gt;canonical_stack['component'] );
 }
 }
 }
 
/**
 * Setup BuddyBar navigation
 *
 * <a class="bp-suggestions-mention" href="https://buddypress.org/members/global/" rel="nofollow">@global</a> BuddyPress $bp The one true BuddyPress instance
 */
 function setup_nav() {
 global $bp;
 
// Add 'Profile' to the main navigation
 if ( !bp_is_active( 'xprofile' ) ) {
 
// Don't set up navigation if there's no user
 if ( !is_user_logged_in() &amp;&amp; !bp_is_user() )
 return;
 
$sub_nav = array();
 $main_nav = array(
 'name' =&gt; __( 'Profile', 'buddypress' ),
 'slug' =&gt; $bp-&gt;profile-&gt;slug,
 'position' =&gt; 20,
 'screen_function' =&gt; 'bp_members_screen_display_profile',
 'default_subnav_slug' =&gt; 'public', //bp 1.7 requires a default subnav. If no subnav use same slug as parent slug.
 'item_css_id' =&gt; $bp-&gt;profile-&gt;id
 );
 
// User links
 $user_domain = bp_displayed_user_domain() ? bp_displayed_user_domain() : bp_loggedin_user_domain();
 $profile_link = trailingslashit( $user_domain . $bp-&gt;profile-&gt;slug );
 
// Add the subnav items to the profile
 $sub_nav[] = array(
 'name' =&gt; __( 'Public', 'buddypress' ),
 'slug' =&gt; 'public',
 'parent_url' =&gt; $profile_link,
 'parent_slug' =&gt; $bp-&gt;profile-&gt;slug,
 'screen_function' =&gt; 'bp_members_screen_display_profile',
 'position' =&gt; 10
 );
 
parent::setup_nav( $main_nav, $sub_nav );
 }
 }
 
/**
 * Sets up the title for pages and &lt;title&gt;
 *
 * <a class="bp-suggestions-mention" href="https://buddypress.org/members/global/" rel="nofollow">@global</a> BuddyPress $bp The one true BuddyPress instance
 */
 function setup_title() {
 global $bp;
 
if ( bp_is_my_profile() ) {
 $bp-&gt;bp_options_title = __( 'You', 'buddypress' );
 } elseif( bp_is_user() ) {
 $bp-&gt;bp_options_avatar = bp_core_fetch_avatar( array(
 'item_id' =&gt; bp_displayed_user_id(),
 'type' =&gt; 'thumb',
 'alt' =&gt; sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_get_displayed_user_fullname() )
 ) );
 $bp-&gt;bp_options_title = bp_get_displayed_user_fullname();
 }
 
parent::setup_title();
 }
}
 
function bp_setup_members() {
 global $bp;
 $bp-&gt;members = new BP_Members_Component();
}
add_action( 'bp_setup_components', 'bp_setup_members', 1 );
Skip to toolbar