BBP_Forums_Component

Loads Forums Component.

Defined (1)

The class is defined in the following location(s).

/includes/extend/buddypress/loader.php  
  1. class BBP_Forums_Component extends BP_Component { 
  2.  
  3. /** 
  4. * Start the forums component creation process 
  5. * @since bbPress (r3552) 
  6. */ 
  7. public function __construct() { 
  8. parent::start( 
  9. 'forums',  
  10. __( 'Forums', 'bbpress' ),  
  11. bbpress()->includes_dir . 'extend/buddypress/' 
  12. ); 
  13. $this->includes(); 
  14. $this->setup_globals(); 
  15. $this->setup_actions(); 
  16. $this->fully_loaded(); 
  17.  
  18. /** 
  19. * Include BuddyPress classes and functions 
  20. */ 
  21. public function includes( $includes = array() ) { 
  22.  
  23. // Helper BuddyPress functions 
  24. $includes[] = 'functions.php'; 
  25.  
  26. // Members modifications 
  27. $includes[] = 'members.php'; 
  28.  
  29. // BuddyPress Notfications Extension functions 
  30. if ( bp_is_active( 'notifications' ) ) { 
  31. $includes[] = 'notifications.php'; 
  32.  
  33. // BuddyPress Activity Extension class 
  34. if ( bp_is_active( 'activity' ) ) { 
  35. $includes[] = 'activity.php'; 
  36.  
  37. // BuddyPress Group Extension class 
  38. if ( bbp_is_group_forums_active() && bp_is_active( 'groups' ) ) { 
  39. $includes[] = 'groups.php'; 
  40.  
  41. parent::includes( $includes ); 
  42.  
  43. /** 
  44. * Setup globals 
  45. * The BP_FORUMS_SLUG constant is deprecated, and only used here for 
  46. * backwards compatibility. 
  47. * @since bbPress (r3552) 
  48. */ 
  49. public function setup_globals( $args = array() ) { 
  50. $bp = buddypress(); 
  51.  
  52. // Define the parent forum ID 
  53. if ( !defined( 'BP_FORUMS_PARENT_FORUM_ID' ) ) 
  54. define( 'BP_FORUMS_PARENT_FORUM_ID', 1 ); 
  55.  
  56. // Define a slug, if necessary 
  57. if ( !defined( 'BP_FORUMS_SLUG' ) ) 
  58. define( 'BP_FORUMS_SLUG', $this->id ); 
  59.  
  60. // All arguments for forums component 
  61. $args = array( 
  62. 'path' => BP_PLUGIN_DIR,  
  63. 'slug' => BP_FORUMS_SLUG,  
  64. 'root_slug' => isset( $bp->pages->forums->slug ) ? $bp->pages->forums->slug : BP_FORUMS_SLUG,  
  65. 'has_directory' => false,  
  66. 'search_string' => __( 'Search Forums...', 'bbpress' ),  
  67. ); 
  68.  
  69. parent::setup_globals( $args ); 
  70.  
  71. /** 
  72. * Setup the actions 
  73. * @since bbPress (r3395) 
  74. * @access private 
  75. * @uses add_filter() To add various filters 
  76. * @uses add_action() To add various actions 
  77. * @link http://bbpress.trac.wordpress.org/ticket/2176 
  78. */ 
  79. public function setup_actions() { 
  80.  
  81. // Setup the components 
  82. add_action( 'bp_init', array( $this, 'setup_components' ), 7 ); 
  83.  
  84. parent::setup_actions(); 
  85.  
  86. /** 
  87. * Instantiate classes for BuddyPress integration 
  88. * @since bbPress (r3395) 
  89. */ 
  90. public function setup_components() { 
  91.  
  92. // Always load the members component 
  93. bbpress()->extend->buddypress->members = new BBP_BuddyPress_Members; 
  94.  
  95. // Create new activity class 
  96. if ( bp_is_active( 'activity' ) ) { 
  97. bbpress()->extend->buddypress->activity = new BBP_BuddyPress_Activity; 
  98.  
  99. // Register the group extension only if groups are active 
  100. if ( bbp_is_group_forums_active() && bp_is_active( 'groups' ) ) { 
  101. bp_register_group_extension( 'BBP_Forums_Group_Extension' ); 
  102.  
  103. /** 
  104. * Allow the variables, actions, and filters to be modified by third party 
  105. * plugins and themes. 
  106. * @since bbPress (r3902) 
  107. */ 
  108. private function fully_loaded() { 
  109. do_action_ref_array( 'bbp_buddypress_loaded', array( $this ) ); 
  110.  
  111. /** 
  112. * Setup BuddyBar navigation 
  113. * @since bbPress (r3552) 
  114. */ 
  115. public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 
  116.  
  117. // Stop if there is no user displayed or logged in 
  118. if ( !is_user_logged_in() && !bp_displayed_user_id() ) 
  119. return; 
  120.  
  121. // Define local variable(s) 
  122. $user_domain = ''; 
  123.  
  124. // Add 'Forums' to the main navigation 
  125. $main_nav = array( 
  126. 'name' => __( 'Forums', 'bbpress' ),  
  127. 'slug' => $this->slug,  
  128. 'position' => 80,  
  129. 'screen_function' => 'bbp_member_forums_screen_topics',  
  130. 'default_subnav_slug' => bbp_get_topic_archive_slug(),  
  131. 'item_css_id' => $this->id 
  132. ); 
  133.  
  134. // Determine user to use 
  135. if ( bp_displayed_user_id() ) 
  136. $user_domain = bp_displayed_user_domain(); 
  137. elseif ( bp_loggedin_user_domain() ) 
  138. $user_domain = bp_loggedin_user_domain(); 
  139. else 
  140. return; 
  141.  
  142. // User link 
  143. $forums_link = trailingslashit( $user_domain . $this->slug ); 
  144.  
  145. // Topics started 
  146. $sub_nav[] = array( 
  147. 'name' => __( 'Topics Started', 'bbpress' ),  
  148. 'slug' => bbp_get_topic_archive_slug(),  
  149. 'parent_url' => $forums_link,  
  150. 'parent_slug' => $this->slug,  
  151. 'screen_function' => 'bbp_member_forums_screen_topics',  
  152. 'position' => 20,  
  153. 'item_css_id' => 'topics' 
  154. ); 
  155.  
  156. // Replies to topics 
  157. $sub_nav[] = array( 
  158. 'name' => __( 'Replies Created', 'bbpress' ),  
  159. 'slug' => bbp_get_reply_archive_slug(),  
  160. 'parent_url' => $forums_link,  
  161. 'parent_slug' => $this->slug,  
  162. 'screen_function' => 'bbp_member_forums_screen_replies',  
  163. 'position' => 40,  
  164. 'item_css_id' => 'replies' 
  165. ); 
  166.  
  167. // Favorite topics 
  168. $sub_nav[] = array( 
  169. 'name' => __( 'Favorites', 'bbpress' ),  
  170. 'slug' => bbp_get_user_favorites_slug(),  
  171. 'parent_url' => $forums_link,  
  172. 'parent_slug' => $this->slug,  
  173. 'screen_function' => 'bbp_member_forums_screen_favorites',  
  174. 'position' => 60,  
  175. 'item_css_id' => 'favorites' 
  176. ); 
  177.  
  178. // Subscribed topics (my profile only) 
  179. if ( bp_is_my_profile() ) { 
  180. $sub_nav[] = array( 
  181. 'name' => __( 'Subscriptions', 'bbpress' ),  
  182. 'slug' => bbp_get_user_subscriptions_slug(),  
  183. 'parent_url' => $forums_link,  
  184. 'parent_slug' => $this->slug,  
  185. 'screen_function' => 'bbp_member_forums_screen_subscriptions',  
  186. 'position' => 60,  
  187. 'item_css_id' => 'subscriptions' 
  188. ); 
  189.  
  190. parent::setup_nav( $main_nav, $sub_nav ); 
  191.  
  192. /** 
  193. * Set up the admin bar 
  194. * @since bbPress (r3552) 
  195. */ 
  196. public function setup_admin_bar( $wp_admin_nav = array() ) { 
  197.  
  198. // Menus for logged in user 
  199. if ( is_user_logged_in() ) { 
  200.  
  201. // Setup the logged in user variables 
  202. $user_domain = bp_loggedin_user_domain(); 
  203. $forums_link = trailingslashit( $user_domain . $this->slug ); 
  204.  
  205. // Add the "My Account" sub menus 
  206. $wp_admin_nav[] = array( 
  207. 'parent' => buddypress()->my_account_menu_id,  
  208. 'id' => 'my-account-' . $this->id,  
  209. 'title' => __( 'Forums', 'bbpress' ),  
  210. 'href' => trailingslashit( $forums_link ) 
  211. ); 
  212.  
  213. // Topics 
  214. $wp_admin_nav[] = array( 
  215. 'parent' => 'my-account-' . $this->id,  
  216. 'id' => 'my-account-' . $this->id . '-topics',  
  217. 'title' => __( 'Topics Started', 'bbpress' ),  
  218. 'href' => trailingslashit( $forums_link . bbp_get_topic_archive_slug() ) 
  219. ); 
  220.  
  221. // Replies 
  222. $wp_admin_nav[] = array( 
  223. 'parent' => 'my-account-' . $this->id,  
  224. 'id' => 'my-account-' . $this->id . '-replies',  
  225. 'title' => __( 'Replies Created', 'bbpress' ),  
  226. 'href' => trailingslashit( $forums_link . bbp_get_reply_archive_slug() ) 
  227. ); 
  228.  
  229. // Favorites 
  230. $wp_admin_nav[] = array( 
  231. 'parent' => 'my-account-' . $this->id,  
  232. 'id' => 'my-account-' . $this->id . '-favorites',  
  233. 'title' => __( 'Favorite Topics', 'bbpress' ),  
  234. 'href' => trailingslashit( $forums_link . bbp_get_user_favorites_slug() ) 
  235. ); 
  236.  
  237. // Subscriptions 
  238. $wp_admin_nav[] = array( 
  239. 'parent' => 'my-account-' . $this->id,  
  240. 'id' => 'my-account-' . $this->id . '-subscriptions',  
  241. 'title' => __( 'Subscribed Topics', 'bbpress' ),  
  242. 'href' => trailingslashit( $forums_link . bbp_get_user_subscriptions_slug() ) 
  243. ); 
  244.  
  245. parent::setup_admin_bar( $wp_admin_nav ); 
  246.  
  247. /** 
  248. * Sets up the title for pages and <title> 
  249. * @since bbPress (r3552) 
  250. */ 
  251. public function setup_title() { 
  252. $bp = buddypress(); 
  253.  
  254. // Adjust title based on view 
  255. if ( bp_is_forums_component() ) { 
  256. if ( bp_is_my_profile() ) { 
  257. $bp->bp_options_title = __( 'Forums', 'bbpress' ); 
  258. } elseif ( bp_is_user() ) { 
  259. $bp->bp_options_avatar = bp_core_fetch_avatar( array( 
  260. 'item_id' => bp_displayed_user_id(),  
  261. 'type' => 'thumb' 
  262. ) ); 
  263. $bp->bp_options_title = bp_get_displayed_user_fullname(); 
  264.  
  265. parent::setup_title();