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 ( ! buddypress()->do_autoload ) { 
  99. $includes[] = 'classes'; 
  100.  
  101. if ( bp_is_active( 'activity' ) ) { 
  102. $includes[] = 'activity'; 
  103.  
  104. if ( is_multisite() ) { 
  105. $includes[] = 'widgets'; 
  106.  
  107. // Include the files. 
  108. parent::includes( $includes ); 
  109.  
  110. /** 
  111. * Set up component navigation for bp-blogs. 
  112. * @see BP_Component::setup_nav() for a description of arguments. 
  113. * @param array $main_nav Optional. See BP_Component::setup_nav() for 
  114. * description. 
  115. * @param array $sub_nav Optional. See BP_Component::setup_nav() for 
  116. * description. 
  117. */ 
  118. public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 
  119.  
  120. /** 
  121. * Blog/post/comment menus should not appear on single WordPress setups. 
  122. * Although comments and posts made by users will still show on their 
  123. * activity stream. 
  124. */ 
  125. if ( ! is_multisite() ) { 
  126. return false; 
  127.  
  128. // Determine user to use. 
  129. if ( bp_displayed_user_domain() ) { 
  130. $user_domain = bp_displayed_user_domain(); 
  131. } elseif ( bp_loggedin_user_domain() ) { 
  132. $user_domain = bp_loggedin_user_domain(); 
  133. } else { 
  134. return; 
  135.  
  136. $slug = bp_get_blogs_slug(); 
  137. $parent_url = trailingslashit( $user_domain . $slug ); 
  138.  
  139. // Add 'Sites' to the main navigation. 
  140. $count = (int) bp_get_total_blog_count_for_user(); 
  141. $class = ( 0 === $count ) ? 'no-count' : 'count'; 
  142. $nav_text = sprintf( 
  143. /** translators: %s: Site count for the current user */ 
  144. __( 'Sites %s', 'buddypress' ),  
  145. sprintf( 
  146. '<span class="%s">%s</span>',  
  147. esc_attr( $class ),  
  148. bp_core_number_format( $count ) 
  149. ); 
  150. $main_nav = array( 
  151. 'name' => $nav_text,  
  152. 'slug' => $slug,  
  153. 'position' => 30,  
  154. 'screen_function' => 'bp_blogs_screen_my_blogs',  
  155. 'default_subnav_slug' => 'my-sites',  
  156. 'item_css_id' => $this->id 
  157. ); 
  158.  
  159. $sub_nav[] = array( 
  160. 'name' => __( 'My Sites', 'buddypress' ),  
  161. 'slug' => 'my-sites',  
  162. 'parent_url' => $parent_url,  
  163. 'parent_slug' => $slug,  
  164. 'screen_function' => 'bp_blogs_screen_my_blogs',  
  165. 'position' => 10 
  166. ); 
  167.  
  168. // Setup navigation. 
  169. parent::setup_nav( $main_nav, $sub_nav ); 
  170.  
  171. /** 
  172. * Set up bp-blogs integration with the WordPress admin bar. 
  173. * @since 1.5.0 
  174. * @see BP_Component::setup_admin_bar() for a description of arguments. 
  175. * @param array $wp_admin_nav See BP_Component::setup_admin_bar() 
  176. * for description. 
  177. * @return bool 
  178. */ 
  179. public function setup_admin_bar( $wp_admin_nav = array() ) { 
  180.  
  181. /** 
  182. * Site/post/comment menus should not appear on single WordPress setups. 
  183. * Comments and posts made by users will still show in their activity. 
  184. */ 
  185. if ( ! is_multisite() ) { 
  186. return false; 
  187.  
  188. // Menus for logged in user. 
  189. if ( is_user_logged_in() ) { 
  190.  
  191. // Setup the logged in user variables. 
  192. $blogs_link = trailingslashit( bp_loggedin_user_domain() . bp_get_blogs_slug() ); 
  193.  
  194. // Add the "Sites" sub menu. 
  195. $wp_admin_nav[] = array( 
  196. 'parent' => buddypress()->my_account_menu_id,  
  197. 'id' => 'my-account-' . $this->id,  
  198. 'title' => __( 'Sites', 'buddypress' ),  
  199. 'href' => $blogs_link 
  200. ); 
  201.  
  202. // My Sites. 
  203. $wp_admin_nav[] = array( 
  204. 'parent' => 'my-account-' . $this->id,  
  205. 'id' => 'my-account-' . $this->id . '-my-sites',  
  206. 'title' => __( 'My Sites', 'buddypress' ),  
  207. 'href' => $blogs_link,  
  208. 'position' => 10 
  209. ); 
  210.  
  211. // Create a Site. 
  212. if ( bp_blog_signup_enabled() ) { 
  213. $wp_admin_nav[] = array( 
  214. 'parent' => 'my-account-' . $this->id,  
  215. 'id' => 'my-account-' . $this->id . '-create',  
  216. 'title' => __( 'Create a Site', 'buddypress' ),  
  217. 'href' => trailingslashit( bp_get_blogs_directory_permalink() . 'create' ),  
  218. 'position' => 99 
  219. ); 
  220.  
  221. parent::setup_admin_bar( $wp_admin_nav ); 
  222.  
  223. /** 
  224. * Set up the title for pages and <title>. 
  225. */ 
  226. public function setup_title() { 
  227.  
  228. // Set up the component options navigation for Site. 
  229. if ( bp_is_blogs_component() ) { 
  230. $bp = buddypress(); 
  231.  
  232. if ( bp_is_my_profile() ) { 
  233. if ( bp_is_active( 'xprofile' ) ) { 
  234. $bp->bp_options_title = __( 'My Sites', 'buddypress' ); 
  235.  
  236. // If we are not viewing the logged in user, set up the current 
  237. // users avatar and name. 
  238. } else { 
  239. $bp->bp_options_avatar = bp_core_fetch_avatar( array( 
  240. 'item_id' => bp_displayed_user_id(),  
  241. 'type' => 'thumb',  
  242. 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_get_displayed_user_fullname() ) 
  243. ) ); 
  244. $bp->bp_options_title = bp_get_displayed_user_fullname(); 
  245.  
  246. parent::setup_title(); 
  247.  
  248. /** 
  249. * Setup cache groups 
  250. * @since 2.2.0 
  251. */ 
  252. public function setup_cache_groups() { 
  253.  
  254. // Global groups. 
  255. wp_cache_add_global_groups( array( 
  256. 'blog_meta' 
  257. ) ); 
  258.  
  259. parent::setup_cache_groups();