BP_Blogs_Component

Creates our Blogs component.

Defined (1)

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

/bp-blogs/classes/class-bp-blogs-component.php  
  1. class BP_Blogs_Component extends BP_Component { 
  2.  
  3. /** 
  4. * Start the blogs component creation process. 
  5. * @since 1.5.0 
  6. */ 
  7. public function __construct() { 
  8. parent::start( 
  9. 'blogs',  
  10. __( 'Site Directory', 'buddypress' ),  
  11. buddypress()->plugin_dir,  
  12. array( 
  13. 'adminbar_myaccount_order' => 30,  
  14. 'search_query_arg' => 'sites_search',  
  15. 'features' => array( 'site-icon' ) 
  16. ); 
  17.  
  18. /** 
  19. * Set up global settings for the blogs component. 
  20. * The BP_BLOGS_SLUG constant is deprecated, and only used here for 
  21. * backwards compatibility. 
  22. * @since 1.5.0 
  23. * @see BP_Component::setup_globals() for description of parameters. 
  24. * @param array $args See {@link BP_Component::setup_globals()}. 
  25. */ 
  26. public function setup_globals( $args = array() ) { 
  27. $bp = buddypress(); 
  28.  
  29. if ( ! defined( 'BP_BLOGS_SLUG' ) ) { 
  30. define ( 'BP_BLOGS_SLUG', $this->id ); 
  31.  
  32. // Global tables for messaging component. 
  33. $global_tables = array( 
  34. 'table_name' => $bp->table_prefix . 'bp_user_blogs',  
  35. 'table_name_blogmeta' => $bp->table_prefix . 'bp_user_blogs_blogmeta',  
  36. ); 
  37.  
  38. $meta_tables = array( 
  39. 'blog' => $bp->table_prefix . 'bp_user_blogs_blogmeta',  
  40. ); 
  41.  
  42. // Fetch the default directory title. 
  43. $default_directory_titles = bp_core_get_directory_page_default_titles(); 
  44. $default_directory_title = $default_directory_titles[$this->id]; 
  45.  
  46. // All globals for blogs component. 
  47. $args = array( 
  48. 'slug' => BP_BLOGS_SLUG,  
  49. 'root_slug' => isset( $bp->pages->blogs->slug ) ? $bp->pages->blogs->slug : BP_BLOGS_SLUG,  
  50. 'has_directory' => is_multisite(), // Non-multisite installs don't need a top-level Sites directory, since there's only one site. 
  51. 'directory_title' => isset( $bp->pages->blogs->title ) ? $bp->pages->blogs->title : $default_directory_title,  
  52. 'notification_callback' => 'bp_blogs_format_notifications',  
  53. 'search_string' => __( 'Search sites...', 'buddypress' ),  
  54. 'autocomplete_all' => defined( 'BP_MESSAGES_AUTOCOMPLETE_ALL' ),  
  55. 'global_tables' => $global_tables,  
  56. 'meta_tables' => $meta_tables,  
  57. ); 
  58.  
  59. // Setup the globals. 
  60. parent::setup_globals( $args ); 
  61.  
  62. /** 
  63. * Filters if a blog is public. 
  64. * In case the config is not multisite, the blog_public option is ignored. 
  65. * @since 2.3.0 
  66. * @param int $value Whether or not the blog is public. 
  67. */ 
  68. if ( 0 !== apply_filters( 'bp_is_blog_public', (int) get_option( 'blog_public' ) ) || ! is_multisite() ) { 
  69.  
  70. /** 
  71. * Filters the post types to track for the Blogs component. 
  72. * @since 1.5.0 
  73. * @deprecated 2.3.0 
  74. * @param array $value Array of post types to track. 
  75. */ 
  76. $post_types = apply_filters( 'bp_blogs_record_post_post_types', array( 'post' ) ); 
  77.  
  78. foreach ( $post_types as $post_type ) { 
  79. add_post_type_support( $post_type, 'buddypress-activity' ); 
  80.  
  81. /** 
  82. * Include bp-blogs files. 
  83. * @see BP_Component::includes() for description of parameters. 
  84. * @param array $includes See {@link BP_Component::includes()}. 
  85. */ 
  86. public function includes( $includes = array() ) { 
  87.  
  88. // Files to include. 
  89. $includes = array( 
  90. 'cache',  
  91. 'actions',  
  92. 'screens',  
  93. 'template',  
  94. 'filters',  
  95. 'functions',  
  96. ); 
  97.  
  98. if ( bp_is_active( 'activity' ) ) { 
  99. $includes[] = 'activity'; 
  100.  
  101. if ( is_multisite() ) { 
  102. $includes[] = 'widgets'; 
  103.  
  104. // Include the files. 
  105. parent::includes( $includes ); 
  106.  
  107. /** 
  108. * Set up component navigation for bp-blogs. 
  109. * @see BP_Component::setup_nav() for a description of arguments. 
  110. * @param array $main_nav Optional. See BP_Component::setup_nav() for 
  111. * description. 
  112. * @param array $sub_nav Optional. See BP_Component::setup_nav() for 
  113. * description. 
  114. */ 
  115. public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 
  116.  
  117. /** 
  118. * Blog/post/comment menus should not appear on single WordPress setups. 
  119. * Although comments and posts made by users will still show on their 
  120. * activity stream. 
  121. */ 
  122. if ( ! is_multisite() ) { 
  123. return false; 
  124.  
  125. // Determine user to use. 
  126. if ( bp_displayed_user_domain() ) { 
  127. $user_domain = bp_displayed_user_domain(); 
  128. } elseif ( bp_loggedin_user_domain() ) { 
  129. $user_domain = bp_loggedin_user_domain(); 
  130. } else { 
  131. return; 
  132.  
  133. $slug = bp_get_blogs_slug(); 
  134. $parent_url = trailingslashit( $user_domain . $slug ); 
  135.  
  136. // Add 'Sites' to the main navigation. 
  137. $count = (int) bp_get_total_blog_count_for_user(); 
  138. $class = ( 0 === $count ) ? 'no-count' : 'count'; 
  139. $nav_text = sprintf( 
  140. /** translators: %s: Site count for the current user */ 
  141. __( 'Sites %s', 'buddypress' ),  
  142. sprintf( 
  143. '<span class="%s">%s</span>',  
  144. esc_attr( $class ),  
  145. bp_core_number_format( $count ) 
  146. ); 
  147. $main_nav = array( 
  148. 'name' => $nav_text,  
  149. 'slug' => $slug,  
  150. 'position' => 30,  
  151. 'screen_function' => 'bp_blogs_screen_my_blogs',  
  152. 'default_subnav_slug' => 'my-sites',  
  153. 'item_css_id' => $this->id 
  154. ); 
  155.  
  156. $sub_nav[] = array( 
  157. 'name' => __( 'My Sites', 'buddypress' ),  
  158. 'slug' => 'my-sites',  
  159. 'parent_url' => $parent_url,  
  160. 'parent_slug' => $slug,  
  161. 'screen_function' => 'bp_blogs_screen_my_blogs',  
  162. 'position' => 10 
  163. ); 
  164.  
  165. // Setup navigation. 
  166. parent::setup_nav( $main_nav, $sub_nav ); 
  167.  
  168. /** 
  169. * Set up bp-blogs integration with the WordPress admin bar. 
  170. * @since 1.5.0 
  171. * @see BP_Component::setup_admin_bar() for a description of arguments. 
  172. * @param array $wp_admin_nav See BP_Component::setup_admin_bar() 
  173. * for description. 
  174. * @return bool 
  175. */ 
  176. public function setup_admin_bar( $wp_admin_nav = array() ) { 
  177.  
  178. /** 
  179. * Site/post/comment menus should not appear on single WordPress setups. 
  180. * Comments and posts made by users will still show in their activity. 
  181. */ 
  182. if ( ! is_multisite() ) { 
  183. return false; 
  184.  
  185. // Menus for logged in user. 
  186. if ( is_user_logged_in() ) { 
  187.  
  188. // Setup the logged in user variables. 
  189. $blogs_link = trailingslashit( bp_loggedin_user_domain() . bp_get_blogs_slug() ); 
  190.  
  191. // Add the "Sites" sub menu. 
  192. $wp_admin_nav[] = array( 
  193. 'parent' => buddypress()->my_account_menu_id,  
  194. 'id' => 'my-account-' . $this->id,  
  195. 'title' => __( 'Sites', 'buddypress' ),  
  196. 'href' => $blogs_link 
  197. ); 
  198.  
  199. // My Sites. 
  200. $wp_admin_nav[] = array( 
  201. 'parent' => 'my-account-' . $this->id,  
  202. 'id' => 'my-account-' . $this->id . '-my-sites',  
  203. 'title' => __( 'My Sites', 'buddypress' ),  
  204. 'href' => $blogs_link,  
  205. 'position' => 10 
  206. ); 
  207.  
  208. // Create a Site. 
  209. if ( bp_blog_signup_enabled() ) { 
  210. $wp_admin_nav[] = array( 
  211. 'parent' => 'my-account-' . $this->id,  
  212. 'id' => 'my-account-' . $this->id . '-create',  
  213. 'title' => __( 'Create a Site', 'buddypress' ),  
  214. 'href' => trailingslashit( bp_get_blogs_directory_permalink() . 'create' ),  
  215. 'position' => 99 
  216. ); 
  217.  
  218. parent::setup_admin_bar( $wp_admin_nav ); 
  219.  
  220. /** 
  221. * Set up the title for pages and <title>. 
  222. */ 
  223. public function setup_title() { 
  224.  
  225. // Set up the component options navigation for Site. 
  226. if ( bp_is_blogs_component() ) { 
  227. $bp = buddypress(); 
  228.  
  229. if ( bp_is_my_profile() ) { 
  230. if ( bp_is_active( 'xprofile' ) ) { 
  231. $bp->bp_options_title = __( 'My Sites', 'buddypress' ); 
  232.  
  233. // If we are not viewing the logged in user, set up the current 
  234. // users avatar and name. 
  235. } else { 
  236. $bp->bp_options_avatar = bp_core_fetch_avatar( array( 
  237. 'item_id' => bp_displayed_user_id(),  
  238. 'type' => 'thumb',  
  239. 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_get_displayed_user_fullname() ) 
  240. ) ); 
  241. $bp->bp_options_title = bp_get_displayed_user_fullname(); 
  242.  
  243. parent::setup_title(); 
  244.  
  245. /** 
  246. * Setup cache groups 
  247. * @since 2.2.0 
  248. */ 
  249. public function setup_cache_groups() { 
  250.  
  251. // Global groups. 
  252. wp_cache_add_global_groups( array( 
  253. 'blog_meta' 
  254. ) ); 
  255.  
  256. parent::setup_cache_groups();