BP_Forums_Component

Sets up the forums component.

Defined (1)

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

/bp-forums/bp-forums-loader.php  
  1. class BP_Forums_Component extends BP_Component { 
  2.  
  3. /** 
  4. * Start the forums component creation process. 
  5. * @since 1.5.0 
  6. */ 
  7. public function __construct() { 
  8. parent::start( 
  9. 'forums',  
  10. __( 'Discussion Forums', 'buddypress' ),  
  11. buddypress()->plugin_dir,  
  12. array( 
  13. 'adminbar_myaccount_order' => 80 
  14. ); 
  15.  
  16. /** 
  17. * Set up bp-forums global settings. 
  18. * The BP_FORUMS_SLUG constant is deprecated, and only used here for 
  19. * backwards compatibility. 
  20. * @since 1.5.0 
  21. * @see BP_Component::setup_globals() for description of parameters. 
  22. * @param array $args See {@link BP_Component::setup_globals()}. 
  23. */ 
  24. public function setup_globals( $args = array() ) { 
  25. $bp = buddypress(); 
  26.  
  27. // Define the parent forum ID. 
  28. if ( ! defined( 'BP_FORUMS_PARENT_FORUM_ID' ) ) { 
  29. define( 'BP_FORUMS_PARENT_FORUM_ID', 1 ); 
  30.  
  31. // Define a slug, if necessary. 
  32. if ( ! defined( 'BP_FORUMS_SLUG' ) ) { 
  33. define( 'BP_FORUMS_SLUG', $this->id ); 
  34.  
  35. // The location of the bbPress stand-alone config file. 
  36. $bbconfig = bp_core_get_root_option( 'bb-config-location' ); 
  37. if ( '' !== $bbconfig ) { 
  38. $this->bbconfig = $bbconfig; 
  39.  
  40. // All globals for messaging component. 
  41. // Note that global_tables is included in this array. 
  42. $globals = array( 
  43. 'slug' => BP_FORUMS_SLUG,  
  44. 'root_slug' => isset( $bp->pages->forums->slug ) ? $bp->pages->forums->slug : BP_FORUMS_SLUG,  
  45. 'has_directory' => true,  
  46. 'notification_callback' => 'messages_format_notifications',  
  47. 'search_string' => __( 'Search Forums...', 'buddypress' ),  
  48. ); 
  49.  
  50. parent::setup_globals( $globals ); 
  51.  
  52. /** 
  53. * Include bp-forums files. 
  54. * @since 1.5.0 
  55. * @see BP_Component::includes() for description of parameters. 
  56. * @param array $includes See {@link BP_Component::includes()}. 
  57. */ 
  58. public function includes( $includes = array() ) { 
  59.  
  60. // Files to include. 
  61. $includes = array( 
  62. 'actions',  
  63. 'screens',  
  64. 'classes',  
  65. 'filters',  
  66. 'template',  
  67. 'functions',  
  68. ); 
  69.  
  70. // bbPress stand-alone. 
  71. if ( ! defined( 'BB_PATH' ) ) { 
  72. $includes[] = 'bbpress-sa'; 
  73.  
  74. // Admin-specific code. 
  75. if ( is_admin() ) { 
  76. $includes[] = 'deprecated/1.6'; 
  77. $includes[] = 'deprecated/1.7'; 
  78.  
  79. parent::includes( $includes ); 
  80.  
  81. /** 
  82. * Set up component navigation. 
  83. * @since 1.5.0 
  84. * @see BP_Component::setup_nav() for a description of arguments. 
  85. * @param array $main_nav Optional. See BP_Component::setup_nav() for 
  86. * description. 
  87. * @param array $sub_nav Optional. See BP_Component::setup_nav() for 
  88. * description. 
  89. */ 
  90. public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 
  91.  
  92. // Stop if forums haven't been set up yet. 
  93. if ( ! bp_forums_is_installed_correctly() ) { 
  94. return; 
  95.  
  96. // Stop if there is no user displayed or logged in. 
  97. if ( ! is_user_logged_in() && ! bp_displayed_user_id() ) { 
  98. return; 
  99.  
  100. // Determine user to use. 
  101. if ( bp_displayed_user_domain() ) { 
  102. $user_domain = bp_displayed_user_domain(); 
  103. } elseif ( bp_loggedin_user_domain() ) { 
  104. $user_domain = bp_loggedin_user_domain(); 
  105. } else { 
  106. return; 
  107.  
  108. // User link. 
  109. $slug = bp_get_forums_slug(); 
  110. $forums_link = trailingslashit( $user_domain . $slug ); 
  111.  
  112. // Add 'Forums' to the main navigation. 
  113. $main_nav = array( 
  114. 'name' => __( 'Forums', 'buddypress' ),  
  115. 'slug' => $slug,  
  116. 'position' => 80,  
  117. 'screen_function' => 'bp_member_forums_screen_topics',  
  118. 'default_subnav_slug' => 'topics',  
  119. 'item_css_id' => $this->id 
  120. ); 
  121.  
  122. // Topics started. 
  123. $sub_nav[] = array( 
  124. 'name' => __( 'Topics Started', 'buddypress' ),  
  125. 'slug' => 'topics',  
  126. 'parent_url' => $forums_link,  
  127. 'parent_slug' => $slug,  
  128. 'screen_function' => 'bp_member_forums_screen_topics',  
  129. 'position' => 20,  
  130. 'item_css_id' => 'topics' 
  131. ); 
  132.  
  133. // Topics replied to. 
  134. $sub_nav[] = array( 
  135. 'name' => __( 'Replied To', 'buddypress' ),  
  136. 'slug' => 'replies',  
  137. 'parent_url' => $forums_link,  
  138. 'parent_slug' => $slug,  
  139. 'screen_function' => 'bp_member_forums_screen_replies',  
  140. 'position' => 40,  
  141. 'item_css_id' => 'replies' 
  142. ); 
  143.  
  144. parent::setup_nav( $main_nav, $sub_nav ); 
  145.  
  146. /** 
  147. * Set up bp-forums integration with the WordPress admin bar. 
  148. * @since 1.5.0 
  149. * @see BP_Component::setup_admin_bar() for a description of arguments. 
  150. * @param array $wp_admin_nav See BP_Component::setup_admin_bar() 
  151. * for description. 
  152. */ 
  153. public function setup_admin_bar( $wp_admin_nav = array() ) { 
  154.  
  155. // Menus for logged in user. 
  156. if ( is_user_logged_in() ) { 
  157.  
  158. // Setup the logged in user variables. 
  159. $forums_link = trailingslashit( bp_loggedin_user_domain() . bp_get_forums_slug() ); 
  160.  
  161. // Add the "My Account" sub menus. 
  162. $wp_admin_nav[] = array( 
  163. 'parent' => buddypress()->my_account_menu_id,  
  164. 'id' => 'my-account-' . $this->id,  
  165. 'title' => __( 'Forums', 'buddypress' ),  
  166. 'href' => $forums_link 
  167. ); 
  168.  
  169. // Topics. 
  170. $wp_admin_nav[] = array( 
  171. 'parent' => 'my-account-' . $this->id,  
  172. 'id' => 'my-account-' . $this->id . '-topics-started',  
  173. 'title' => __( 'Topics Started', 'buddypress' ),  
  174. 'href' => $forums_link 
  175. ); 
  176.  
  177. // Replies. 
  178. $wp_admin_nav[] = array( 
  179. 'parent' => 'my-account-' . $this->id,  
  180. 'id' => 'my-account-' . $this->id . '-replies',  
  181. 'title' => __( 'Replies', 'buddypress' ),  
  182. 'href' => trailingslashit( $forums_link . 'replies' ) 
  183. ); 
  184.  
  185. // Favorites. 
  186. $wp_admin_nav[] = array( 
  187. 'parent' => 'my-account-' . $this->id,  
  188. 'id' => 'my-account-' . $this->id . '-favorite-topics',  
  189. 'title' => __( 'Favorite Topics', 'buddypress' ),  
  190. 'href' => trailingslashit( $forums_link . 'favorites' ) 
  191. ); 
  192.  
  193. parent::setup_admin_bar( $wp_admin_nav ); 
  194.  
  195. /** 
  196. * Set up the title for pages and the <title> element. 
  197. * @since 1.5.0 
  198. */ 
  199. public function setup_title() { 
  200.  
  201. // Adjust title based on view. 
  202. if ( bp_is_forums_component() ) { 
  203. $bp = buddypress(); 
  204.  
  205. if ( bp_is_my_profile() ) { 
  206. $bp->bp_options_title = __( 'Forums', 'buddypress' ); 
  207. } else { 
  208. $bp->bp_options_avatar = bp_core_fetch_avatar( array( 
  209. 'item_id' => bp_displayed_user_id(),  
  210. 'type' => 'thumb',  
  211. 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_get_displayed_user_fullname() ) 
  212. ) ); 
  213. $bp->bp_options_title = bp_get_displayed_user_fullname(); 
  214.  
  215. parent::setup_title(); 
  216.  
  217. /** 
  218. * Disable cache groups due to a caching discrepancy in BackPress. 
  219. * @since 2.7.0 
  220. * @see https://buddypress.trac.wordpress.org/ticket/4759 
  221. */ 
  222. public function setup_cache_groups() { 
  223. wp_cache_add_non_persistent_groups( array( 
  224. // Posts. 
  225. 'bb_forums',  
  226. 'bb_query',  
  227. 'bb_cache_posts_post_ids',  
  228.  
  229. // Topics 
  230. 'bb_post' 
  231. ) );