PluginProbe
bbPress / 2.6.17
bbPress v2.6.17
2.6.17 trunk 2.0 2.0-beta-1 2.0-beta-2b 2.0-beta-3 2.0-beta-3b 2.0-rc-2 2.0-rc-3 2.0-rc-4 2.0-rc-5 2.0.1 2.0.2 2.0.3 2.1 2.1-beta-1 2.1-rc1 2.1-rc2 2.1-rc3 2.1-rc4 2.1.1 2.1.2 2.1.3 2.2 2.2.1 All 72 releases
bbpress / includes / extend / buddypress / loader.php

loader.php in bbPress 2.6.17, at includes/extend/buddypress/loader.php

410 lines 11.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * bbPress BuddyPress Component Class
5 *
6 * bbPress and BuddyPress are designed to connect together seamlessly and
7 * invisibly, and this is the hunk of code necessary to make that happen.
8 *
9 * The code in this BuddyPress Extension does some pretty complicated stuff,
10 * far outside the realm of the simplicity bbPress is traditionally known for.
11 *
12 * While the rest of bbPress serves as an example of how to write pretty, simple
13 * code, what's in these files is pure madness. It should not be used as an
14 * example of anything other than successfully juggling chainsaws and puppy-dogs.
15 *
16 * @package bbPress
17 * @subpackage BuddyPress
18 */
19
20 // Exit if accessed directly
21 defined( 'ABSPATH' ) || exit;
22
23 if ( ! class_exists( 'BBP_Forums_Component' ) ) :
24 /**
25 * Loads Forums Component
26 *
27 * @since 2.1.0 bbPress (r3552)
28 *
29 * @package bbPress
30 * @subpackage BuddyPress
31 */
32 class BBP_Forums_Component extends BP_Component {
33
34 /**
35 * BuddyPress Members component shim
36 *
37 * @since 2.0.0
38 *
39 * @var void|BBP_BuddyPress_Members
40 */
41 public $members;
42
43 /**
44 * BuddyPress Activity component shim
45 *
46 * @since 2.0.0
47 *
48 * @var void|BBP_BuddyPress_Members
49 */
50 public $activity;
51
52 /**
53 * Start the forums component creation process
54 *
55 * @since 2.1.0 bbPress (r3552)
56 */
57 public function __construct() {
58 parent::start(
59 'forums',
60 esc_html__( 'Forums', 'bbpress' ),
61 bbpress()->includes_dir . 'extend/buddypress/'
62 );
63 $this->includes();
64 $this->setup_globals();
65 $this->setup_actions();
66 $this->fully_loaded();
67 }
68
69 /**
70 * Include BuddyPress classes and functions
71 */
72 public function includes( $includes = array() ) {
73
74 // Helper BuddyPress functions
75 $includes[] = 'functions.php';
76
77 // Members modifications
78 $includes[] = 'members.php';
79
80 // BuddyPress Notfications Extension functions
81 if ( bp_is_active( 'notifications' ) ) {
82 $includes[] = 'notifications.php';
83 }
84
85 // BuddyPress Activity Extension class
86 if ( bp_is_active( 'activity' ) ) {
87 $includes[] = 'activity.php';
88 }
89
90 // BuddyPress Group Extension class
91 if ( bbp_is_group_forums_active() && bp_is_active( 'groups' ) ) {
92 $includes[] = 'groups.php';
93 }
94
95 // Require files if they exist
96 foreach ( $includes as $file ) {
97 if ( @is_file( $this->path . $file ) ) {
98 require $this->path . $file;
99 }
100 }
101
102 /**
103 * Hook for plugins to include files, if necessary.
104 *
105 * @since 2.6.0 bbPress (r3552)
106 */
107 do_action( "bp_{$this->id}_includes" );
108 }
109
110 /**
111 * Setup globals
112 *
113 * The BP_FORUMS_SLUG constant is deprecated, and only used here for
114 * backwards compatibility.
115 *
116 * @since 2.1.0 bbPress (r3552)
117 */
118 public function setup_globals( $args = array() ) {
119 $bp = buddypress();
120
121 // Define the parent forum ID
122 if ( ! defined( 'BP_FORUMS_PARENT_FORUM_ID' ) ) {
123 define( 'BP_FORUMS_PARENT_FORUM_ID', 1 );
124 }
125
126 // Define a slug, if necessary
127 if ( ! defined( 'BP_FORUMS_SLUG' ) ) {
128 define( 'BP_FORUMS_SLUG', $this->id );
129 }
130
131 // All arguments for forums component
132 $args = array(
133 'path' => BP_PLUGIN_DIR,
134 'slug' => BP_FORUMS_SLUG,
135 'root_slug' => isset( $bp->pages->forums->slug ) ? $bp->pages->forums->slug : BP_FORUMS_SLUG,
136 'has_directory' => false,
137 'search_string' => esc_html__( 'Search Forums...', 'bbpress' ),
138 );
139
140 parent::setup_globals( $args );
141 }
142
143 /**
144 * Setup the actions
145 *
146 * @since 2.0.0 bbPress (r3395)
147 *
148 * @access private
149 * @link https://bbpress.trac.wordpress.org/ticket/2176
150 */
151 public function setup_actions() {
152
153 // Setup the components
154 add_action( 'bp_init', array( $this, 'setup_components' ), 7 );
155
156 parent::setup_actions();
157 }
158
159 /**
160 * Instantiate classes for BuddyPress integration
161 *
162 * @since 2.0.0 bbPress (r3395)
163 */
164 public function setup_components() {
165
166 // Always load the members component
167 bbpress()->extend->buddypress->members = new BBP_BuddyPress_Members();
168
169 // Create new activity class
170 if ( bp_is_active( 'activity' ) ) {
171 bbpress()->extend->buddypress->activity = new BBP_BuddyPress_Activity();
172 }
173
174 // Register the group extension only if groups are active
175 if ( bbp_is_group_forums_active() && bp_is_active( 'groups' ) ) {
176 bp_register_group_extension( 'BBP_Forums_Group_Extension' );
177 }
178 }
179
180 /**
181 * Allow the variables, actions, and filters to be modified by third party
182 * plugins and themes.
183 *
184 * @since 2.1.0 bbPress (r3902)
185 */
186 private function fully_loaded() {
187 do_action_ref_array( 'bbp_buddypress_loaded', array( $this ) );
188 }
189
190 /**
191 * Setup BuddyBar navigation
192 *
193 * @since 2.1.0 bbPress (r3552)
194 */
195 public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
196
197 // Stop if there is no user displayed or logged in
198 if ( ! is_user_logged_in() && ! bp_displayed_user_id() ) {
199 return;
200 }
201
202 // Define local variable(s)
203 $user_domain = '';
204
205 // Add 'Forums' to the main navigation
206 $main_nav = array(
207 'name' => esc_html__( 'Forums', 'bbpress' ),
208 'slug' => $this->slug,
209 'position' => 80,
210 'screen_function' => 'bbp_member_forums_screen_topics',
211 'default_subnav_slug' => bbp_get_topic_archive_slug(),
212 'item_css_id' => $this->id
213 );
214
215 // Determine user to use
216 if ( bp_displayed_user_id() ) {
217 $user_domain = bp_displayed_user_domain();
218 } elseif ( bp_loggedin_user_domain() ) {
219 $user_domain = bp_loggedin_user_domain();
220 } else {
221 return;
222 }
223
224 // User link
225 $forums_link = trailingslashit( $user_domain . $this->slug );
226
227 // Topics started
228 $sub_nav[] = array(
229 'name' => esc_html__( 'Topics Started', 'bbpress' ),
230 'slug' => bbp_get_topic_archive_slug(),
231 'parent_url' => $forums_link,
232 'parent_slug' => $this->slug,
233 'screen_function' => 'bbp_member_forums_screen_topics',
234 'position' => 20,
235 'item_css_id' => 'topics'
236 );
237
238 // Replies to topics
239 $sub_nav[] = array(
240 'name' => esc_html__( 'Replies Created', 'bbpress' ),
241 'slug' => bbp_get_reply_archive_slug(),
242 'parent_url' => $forums_link,
243 'parent_slug' => $this->slug,
244 'screen_function' => 'bbp_member_forums_screen_replies',
245 'position' => 40,
246 'item_css_id' => 'replies'
247 );
248
249 // Engagements
250 if ( bbp_is_engagements_active() ) {
251 $sub_nav[] = array(
252 'name' => esc_html__( 'Engagements', 'bbpress' ),
253 'slug' => bbp_get_user_engagements_slug(),
254 'parent_url' => $forums_link,
255 'parent_slug' => $this->slug,
256 'screen_function' => 'bbp_member_forums_screen_engagements',
257 'position' => 60,
258 'item_css_id' => 'engagements'
259 );
260 }
261
262 // Favorite topics
263 if ( bbp_is_favorites_active() ) {
264 $sub_nav[] = array(
265 'name' => esc_html__( 'Favorites', 'bbpress' ),
266 'slug' => bbp_get_user_favorites_slug(),
267 'parent_url' => $forums_link,
268 'parent_slug' => $this->slug,
269 'screen_function' => 'bbp_member_forums_screen_favorites',
270 'position' => 80,
271 'item_css_id' => 'favorites'
272 );
273 }
274
275 // Subscribed topics (my profile only)
276 if ( bp_is_my_profile() && bbp_is_subscriptions_active() ) {
277 $sub_nav[] = array(
278 'name' => esc_html__( 'Subscriptions', 'bbpress' ),
279 'slug' => bbp_get_user_subscriptions_slug(),
280 'parent_url' => $forums_link,
281 'parent_slug' => $this->slug,
282 'screen_function' => 'bbp_member_forums_screen_subscriptions',
283 'position' => 100,
284 'item_css_id' => 'subscriptions'
285 );
286 }
287
288 parent::setup_nav( $main_nav, $sub_nav );
289 }
290
291 /**
292 * Set up the admin bar
293 *
294 * @since 2.1.0 bbPress (r3552)
295 */
296 public function setup_admin_bar( $wp_admin_nav = array() ) {
297
298 // Menus for logged in user
299 if ( is_user_logged_in() ) {
300
301 // If BuddyPress is network activated and bbPress is
302 // not activated on a the root blog but on any child one
303 if ( ! bp_is_root_blog() ) {
304 $user_id = bbp_get_current_user_id();
305 $my_account_link = bbp_get_user_profile_url( $user_id );
306 $my_topics_link = bbp_get_user_topics_created_url( $user_id );
307 $my_replies_link = bbp_get_user_replies_created_url( $user_id );
308 $my_engagements_link = bbp_get_user_engagements_url( $user_id );
309 $my_favorites_link = bbp_get_favorites_permalink( $user_id );
310 $my_subscriptions_link = bbp_get_subscriptions_permalink( $user_id );
311 } else {
312
313 // Setup the logged in user variables
314 $user_domain = bp_loggedin_user_domain();
315 $forums_link = trailingslashit( $user_domain . $this->slug );
316
317 $my_account_link = trailingslashit( $forums_link );
318 $my_topics_link = trailingslashit( $forums_link . bbp_get_topic_archive_slug() );
319 $my_replies_link = trailingslashit( $forums_link . bbp_get_reply_archive_slug() );
320 $my_engagements_link = trailingslashit( $forums_link . bbp_get_user_engagements_slug() );
321 $my_favorites_link = trailingslashit( $forums_link . bbp_get_user_favorites_slug() );
322 $my_subscriptions_link = trailingslashit( $forums_link . bbp_get_user_subscriptions_slug() );
323 }
324
325 // Add the "My Account" sub menus
326 $wp_admin_nav[] = array(
327 'parent' => buddypress()->my_account_menu_id,
328 'id' => 'my-account-' . $this->id,
329 'title' => esc_html__( 'Forums', 'bbpress' ),
330 'href' => $my_account_link
331 );
332
333 // Topics
334 $wp_admin_nav[] = array(
335 'parent' => 'my-account-' . $this->id,
336 'id' => 'my-account-' . $this->id . '-topics',
337 'title' => esc_html__( 'Topics Started', 'bbpress' ),
338 'href' => $my_topics_link
339 );
340
341 // Replies
342 $wp_admin_nav[] = array(
343 'parent' => 'my-account-' . $this->id,
344 'id' => 'my-account-' . $this->id . '-replies',
345 'title' => esc_html__( 'Replies Created', 'bbpress' ),
346 'href' => $my_replies_link
347 );
348
349 // Engagements
350 if ( bbp_is_engagements_active() ) {
351 $wp_admin_nav[] = array(
352 'parent' => 'my-account-' . $this->id,
353 'id' => 'my-account-' . $this->id . '-engagements',
354 'title' => esc_html__( 'Engagements', 'bbpress' ),
355 'href' => $my_engagements_link
356 );
357 }
358
359 // Favorites
360 if ( bbp_is_favorites_active() ) {
361 $wp_admin_nav[] = array(
362 'parent' => 'my-account-' . $this->id,
363 'id' => 'my-account-' . $this->id . '-favorites',
364 'title' => esc_html__( 'Favorite Topics', 'bbpress' ),
365 'href' => $my_favorites_link
366 );
367 }
368
369 // Subscriptions
370 if ( bbp_is_subscriptions_active() ) {
371 $wp_admin_nav[] = array(
372 'parent' => 'my-account-' . $this->id,
373 'id' => 'my-account-' . $this->id . '-subscriptions',
374 'title' => esc_html__( 'Subscribed Topics', 'bbpress' ),
375 'href' => $my_subscriptions_link
376 );
377 }
378 }
379
380 parent::setup_admin_bar( $wp_admin_nav );
381 }
382
383 /**
384 * Sets up the title for pages and <title>
385 *
386 * @since 2.1.0 bbPress (r3552)
387 */
388 public function setup_title() {
389 $bp = buddypress();
390
391 // Adjust title based on view
392 if ( bp_is_forums_component() ) {
393 if ( bp_is_my_profile() ) {
394 $bp->bp_options_title = esc_html__( 'Forums', 'bbpress' );
395 } elseif ( bp_is_user() ) {
396 $bp->bp_options_avatar = bp_core_fetch_avatar(
397 array(
398 'item_id' => bp_displayed_user_id(),
399 'type' => 'thumb'
400 )
401 );
402 $bp->bp_options_title = bp_get_displayed_user_fullname();
403 }
404 }
405
406 parent::setup_title();
407 }
408 }
409 endif;
410