BP_Groups_Component

Creates our Groups component.

Defined (1)

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

/bp-groups/classes/class-bp-groups-component.php  
  1. class BP_Groups_Component extends BP_Component { 
  2.  
  3. /** 
  4. * Auto-join group when non group member performs group activity. 
  5. * @since 1.5.0 
  6. * @var bool 
  7. */ 
  8. public $auto_join; 
  9.  
  10. /** 
  11. * The group being currently accessed. 
  12. * @since 1.5.0 
  13. * @var BP_Groups_Group 
  14. */ 
  15. public $current_group; 
  16.  
  17. /** 
  18. * Default group extension. 
  19. * @since 1.6.0 
  20. * @todo Is this used anywhere? Is this a duplicate of $default_extension? 
  21. * @var string 
  22. */ 
  23. var $default_component; 
  24.  
  25. /** 
  26. * Default group extension. 
  27. * @since 1.6.0 
  28. * @var string 
  29. */ 
  30. public $default_extension; 
  31.  
  32. /** 
  33. * Illegal group names/slugs. 
  34. * @since 1.5.0 
  35. * @var array 
  36. */ 
  37. public $forbidden_names; 
  38.  
  39. /** 
  40. * Group creation/edit steps (e.g. Details, Settings, Avatar, Invites). 
  41. * @since 1.5.0 
  42. * @var array 
  43. */ 
  44. public $group_creation_steps; 
  45.  
  46. /** 
  47. * Types of group statuses (Public, Private, Hidden). 
  48. * @since 1.5.0 
  49. * @var array 
  50. */ 
  51. public $valid_status; 
  52.  
  53. /** 
  54. * Group types. 
  55. * @see bp_groups_register_group_type() 
  56. * @since 2.6.0 
  57. * @var array 
  58. */ 
  59. public $types = array(); 
  60.  
  61. /** 
  62. * Current directory group type. 
  63. * @see groups_directory_groups_setup() 
  64. * @since 2.7.0 
  65. * @var string 
  66. */ 
  67. public $current_directory_type = ''; 
  68.  
  69. /** 
  70. * Start the groups component creation process. 
  71. * @since 1.5.0 
  72. */ 
  73. public function __construct() { 
  74. parent::start( 
  75. 'groups',  
  76. _x( 'User Groups', 'Group screen page <title>', 'buddypress' ),  
  77. buddypress()->plugin_dir,  
  78. array( 
  79. 'adminbar_myaccount_order' => 70,  
  80. 'search_query_arg' => 'groups_search',  
  81. ); 
  82.  
  83. /** 
  84. * Include Groups component files. 
  85. * @since 1.5.0 
  86. * @see BP_Component::includes() for a description of arguments. 
  87. * @param array $includes See BP_Component::includes() for a description. 
  88. */ 
  89. public function includes( $includes = array() ) { 
  90. $includes = array( 
  91. 'cache',  
  92. 'forums',  
  93. 'actions',  
  94. 'filters',  
  95. 'screens',  
  96. 'widgets',  
  97. 'activity',  
  98. 'template',  
  99. 'adminbar',  
  100. 'functions',  
  101. 'notifications' 
  102. ); 
  103.  
  104. if ( is_admin() ) { 
  105. $includes[] = 'admin'; 
  106.  
  107. parent::includes( $includes ); 
  108.  
  109. /** 
  110. * Set up component global data. 
  111. * The BP_GROUPS_SLUG constant is deprecated, and only used here for 
  112. * backwards compatibility. 
  113. * @since 1.5.0 
  114. * @see BP_Component::setup_globals() for a description of arguments. 
  115. * @param array $args See BP_Component::setup_globals() for a description. 
  116. */ 
  117. public function setup_globals( $args = array() ) { 
  118. $bp = buddypress(); 
  119.  
  120. // Define a slug, if necessary. 
  121. if ( ! defined( 'BP_GROUPS_SLUG' ) ) { 
  122. define( 'BP_GROUPS_SLUG', $this->id ); 
  123.  
  124. // Global tables for groups component. 
  125. $global_tables = array( 
  126. 'table_name' => $bp->table_prefix . 'bp_groups',  
  127. 'table_name_members' => $bp->table_prefix . 'bp_groups_members',  
  128. 'table_name_groupmeta' => $bp->table_prefix . 'bp_groups_groupmeta' 
  129. ); 
  130.  
  131. // Metadata tables for groups component. 
  132. $meta_tables = array( 
  133. 'group' => $bp->table_prefix . 'bp_groups_groupmeta',  
  134. ); 
  135.  
  136. // Fetch the default directory title. 
  137. $default_directory_titles = bp_core_get_directory_page_default_titles(); 
  138. $default_directory_title = $default_directory_titles[$this->id]; 
  139.  
  140. // All globals for groups component. 
  141. // Note that global_tables is included in this array. 
  142. $args = array( 
  143. 'slug' => BP_GROUPS_SLUG,  
  144. 'root_slug' => isset( $bp->pages->groups->slug ) ? $bp->pages->groups->slug : BP_GROUPS_SLUG,  
  145. 'has_directory' => true,  
  146. 'directory_title' => isset( $bp->pages->groups->title ) ? $bp->pages->groups->title : $default_directory_title,  
  147. 'notification_callback' => 'groups_format_notifications',  
  148. 'search_string' => _x( 'Search Groups...', 'Component directory search', 'buddypress' ),  
  149. 'global_tables' => $global_tables,  
  150. 'meta_tables' => $meta_tables,  
  151. ); 
  152.  
  153. parent::setup_globals( $args ); 
  154.  
  155. /** Single Group Globals **********************************************/ 
  156.  
  157. // Are we viewing a single group? 
  158. if ( bp_is_groups_component() && $group_id = BP_Groups_Group::group_exists( bp_current_action() ) ) { 
  159.  
  160. $bp->is_single_item = true; 
  161.  
  162. /** 
  163. * Filters the current PHP Class being used. 
  164. * @since 1.5.0 
  165. * @param string $value Name of the class being used. 
  166. */ 
  167. $current_group_class = apply_filters( 'bp_groups_current_group_class', 'BP_Groups_Group' ); 
  168.  
  169. if ( $current_group_class == 'BP_Groups_Group' ) { 
  170. $this->current_group = groups_get_group( $group_id ); 
  171.  
  172. } else { 
  173.  
  174. /** 
  175. * Filters the current group object being instantiated from previous filter. 
  176. * @since 1.5.0 
  177. * @param object $value Newly instantiated object for the group. 
  178. */ 
  179. $this->current_group = apply_filters( 'bp_groups_current_group_object', new $current_group_class( $group_id ) ); 
  180.  
  181. // When in a single group, the first action is bumped down one because of the 
  182. // group name, so we need to adjust this and set the group name to current_item. 
  183. $bp->current_item = bp_current_action(); 
  184. $bp->current_action = bp_action_variable( 0 ); 
  185. array_shift( $bp->action_variables ); 
  186.  
  187. // Using "item" not "group" for generic support in other components. 
  188. if ( bp_current_user_can( 'bp_moderate' ) ) { 
  189. bp_update_is_item_admin( true, 'groups' ); 
  190. } else { 
  191. bp_update_is_item_admin( groups_is_user_admin( bp_loggedin_user_id(), $this->current_group->id ), 'groups' ); 
  192.  
  193. // If the user is not an admin, check if they are a moderator. 
  194. if ( ! bp_is_item_admin() ) { 
  195. bp_update_is_item_mod ( groups_is_user_mod ( bp_loggedin_user_id(), $this->current_group->id ), 'groups' ); 
  196.  
  197. // Is the logged in user a member of the group? 
  198. if ( ( is_user_logged_in() && groups_is_user_member( bp_loggedin_user_id(), $this->current_group->id ) ) ) { 
  199. $this->current_group->is_user_member = true; 
  200. } else { 
  201. $this->current_group->is_user_member = false; 
  202.  
  203. // Should this group be visible to the logged in user? 
  204. if ( 'public' == $this->current_group->status || $this->current_group->is_user_member ) { 
  205. $this->current_group->is_visible = true; 
  206. } else { 
  207. $this->current_group->is_visible = false; 
  208.  
  209. // Check once if the current group has a custom front template. 
  210. $this->current_group->front_template = bp_groups_get_front_template( $this->current_group ); 
  211.  
  212. // Initialize the nav for the groups component. 
  213. $this->nav = new BP_Core_Nav( $this->current_group->id ); 
  214.  
  215. // Set current_group to 0 to prevent debug errors. 
  216. } else { 
  217. $this->current_group = 0; 
  218.  
  219. // Set group type if available. 
  220. if ( bp_is_groups_directory() && bp_is_current_action( bp_get_groups_group_type_base() ) && bp_action_variable() ) { 
  221. $matched_types = bp_groups_get_group_types( array( 
  222. 'has_directory' => true,  
  223. 'directory_slug' => bp_action_variable(),  
  224. ) ); 
  225.  
  226. // Set 404 if we do not have a valid group type. 
  227. if ( empty( $matched_types ) ) { 
  228. bp_do_404(); 
  229. return; 
  230.  
  231. // Set our directory type marker. 
  232. $this->current_directory_type = reset( $matched_types ); 
  233.  
  234. // Set up variables specific to the group creation process. 
  235. if ( bp_is_groups_component() && bp_is_current_action( 'create' ) && bp_user_can_create_groups() && isset( $_COOKIE['bp_new_group_id'] ) ) { 
  236. $bp->groups->new_group_id = (int) $_COOKIE['bp_new_group_id']; 
  237.  
  238. /** 
  239. * Filters the list of illegal groups names/slugs. 
  240. * @since 1.0.0 
  241. * @param array $value Array of illegal group names/slugs. 
  242. */ 
  243. $this->forbidden_names = apply_filters( 'groups_forbidden_names', array( 
  244. 'my-groups',  
  245. 'create',  
  246. 'invites',  
  247. 'send-invites',  
  248. 'forum',  
  249. 'delete',  
  250. 'add',  
  251. 'admin',  
  252. 'request-membership',  
  253. 'members',  
  254. 'settings',  
  255. 'avatar',  
  256. $this->slug,  
  257. $this->root_slug,  
  258. ) ); 
  259.  
  260. // If the user was attempting to access a group, but no group by that name was found, 404. 
  261. if ( bp_is_groups_component() && empty( $this->current_group ) && empty( $this->current_directory_type ) && bp_current_action() && ! in_array( bp_current_action(), $this->forbidden_names ) ) { 
  262. bp_do_404(); 
  263. return; 
  264.  
  265. /** 
  266. * Filters the preconfigured groups creation steps. 
  267. * @since 1.1.0 
  268. * @param array $value Array of preconfigured group creation steps. 
  269. */ 
  270. $this->group_creation_steps = apply_filters( 'groups_create_group_steps', array( 
  271. 'group-details' => array( 
  272. 'name' => _x( 'Details', 'Group screen nav', 'buddypress' ),  
  273. 'position' => 0 
  274. ),  
  275. 'group-settings' => array( 
  276. 'name' => _x( 'Settings', 'Group screen nav', 'buddypress' ),  
  277. 'position' => 10 
  278. ) ); 
  279.  
  280. // If avatar uploads are not disabled, add avatar option. 
  281. $disabled_avatar_uploads = (int) bp_disable_group_avatar_uploads(); 
  282. if ( ! $disabled_avatar_uploads && $bp->avatar->show_avatars ) { 
  283. $this->group_creation_steps['group-avatar'] = array( 
  284. 'name' => _x( 'Photo', 'Group screen nav', 'buddypress' ),  
  285. 'position' => 20 
  286. ); 
  287.  
  288. if ( bp_group_use_cover_image_header() ) { 
  289. $this->group_creation_steps['group-cover-image'] = array( 
  290. 'name' => _x( 'Cover Image', 'Group screen nav', 'buddypress' ),  
  291. 'position' => 25 
  292. ); 
  293.  
  294. // If friends component is active, add invitations. 
  295. if ( bp_is_active( 'friends' ) ) { 
  296. $this->group_creation_steps['group-invites'] = array( 
  297. 'name' => _x( 'Invites', 'Group screen nav', 'buddypress' ),  
  298. 'position' => 30 
  299. ); 
  300.  
  301. /** 
  302. * Filters the list of valid groups statuses. 
  303. * @since 1.1.0 
  304. * @param array $value Array of valid group statuses. 
  305. */ 
  306. $this->valid_status = apply_filters( 'groups_valid_status', array( 
  307. 'public',  
  308. 'private',  
  309. 'hidden' 
  310. ) ); 
  311.  
  312. // Auto join group when non group member performs group activity. 
  313. $this->auto_join = defined( 'BP_DISABLE_AUTO_GROUP_JOIN' ) && BP_DISABLE_AUTO_GROUP_JOIN ? false : true; 
  314.  
  315. /** 
  316. * Set up canonical stack for this component. 
  317. * @since 2.1.0 
  318. */ 
  319. public function setup_canonical_stack() { 
  320. if ( ! bp_is_groups_component() ) { 
  321. return; 
  322.  
  323. if ( empty( $this->current_group ) ) { 
  324. return; 
  325.  
  326. /** 
  327. * Filters the default groups extension. 
  328. * @since 1.6.0 
  329. * @param string $value BP_GROUPS_DEFAULT_EXTENSION constant if defined,  
  330. * else 'home'. 
  331. */ 
  332. $this->default_extension = apply_filters( 'bp_groups_default_extension', defined( 'BP_GROUPS_DEFAULT_EXTENSION' ) ? BP_GROUPS_DEFAULT_EXTENSION : 'home' ); 
  333.  
  334. $bp = buddypress(); 
  335.  
  336. // If the activity component is not active and the current group has no custom front, members are displayed in the home nav. 
  337. if ( 'members' === $this->default_extension && ! bp_is_active( 'activity' ) && ! $this->current_group->front_template ) { 
  338. $this->default_extension = 'home'; 
  339.  
  340. if ( ! bp_current_action() ) { 
  341. $bp->current_action = $this->default_extension; 
  342.  
  343. // Prepare for a redirect to the canonical URL. 
  344. $bp->canonical_stack['base_url'] = bp_get_group_permalink( $this->current_group ); 
  345.  
  346. if ( bp_current_action() ) { 
  347. $bp->canonical_stack['action'] = bp_current_action(); 
  348.  
  349. /** 
  350. * If there's no custom front.php template for the group, we need to make sure the canonical stack action 
  351. * is set to 'home' in these 2 cases: 
  352. * - the current action is 'activity' (eg: site.url/groups/single/activity) and the Activity component is active 
  353. * - the current action is 'members' (eg: site.url/groups/single/members) and the Activity component is *not* active. 
  354. */ 
  355. if ( ! $this->current_group->front_template && ( bp_is_current_action( 'activity' ) || ( ! bp_is_active( 'activity' ) && bp_is_current_action( 'members' ) ) ) ) { 
  356. $bp->canonical_stack['action'] = 'home'; 
  357.  
  358. if ( ! empty( $bp->action_variables ) ) { 
  359. $bp->canonical_stack['action_variables'] = bp_action_variables(); 
  360.  
  361. // When viewing the default extension, the canonical URL should not have 
  362. // that extension's slug, unless more has been tacked onto the URL via 
  363. // action variables. 
  364. if ( bp_is_current_action( $this->default_extension ) && empty( $bp->action_variables ) ) { 
  365. unset( $bp->canonical_stack['action'] ); 
  366.  
  367. /** 
  368. * Set up component navigation. 
  369. * @since 1.5.0 
  370. * @see BP_Component::setup_nav() for a description of arguments. 
  371. * @param array $main_nav Optional. See BP_Component::setup_nav() for description. 
  372. * @param array $sub_nav Optional. See BP_Component::setup_nav() for description. 
  373. */ 
  374. public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 
  375.  
  376. // Determine user to use. 
  377. if ( bp_displayed_user_domain() ) { 
  378. $user_domain = bp_displayed_user_domain(); 
  379. } elseif ( bp_loggedin_user_domain() ) { 
  380. $user_domain = bp_loggedin_user_domain(); 
  381. } else { 
  382. $user_domain = false; 
  383.  
  384. // Only grab count if we're on a user page. 
  385. if ( bp_is_user() ) { 
  386. $class = ( 0 === groups_total_groups_for_user( bp_displayed_user_id() ) ) ? 'no-count' : 'count'; 
  387.  
  388. $nav_name = sprintf( 
  389. /** translators: %s: Group count for the current user */ 
  390. _x( 'Groups %s', 'Group screen nav with counter', 'buddypress' ),  
  391. sprintf( 
  392. '<span class="%s">%s</span>',  
  393. esc_attr( $class ),  
  394. bp_get_total_group_count_for_user() 
  395. ); 
  396. } else { 
  397. $nav_name = _x( 'Groups', 'Group screen nav without counter', 'buddypress' ); 
  398.  
  399. $slug = bp_get_groups_slug(); 
  400.  
  401. // Add 'Groups' to the main navigation. 
  402. $main_nav = array( 
  403. 'name' => $nav_name,  
  404. 'slug' => $slug,  
  405. 'position' => 70,  
  406. 'screen_function' => 'groups_screen_my_groups',  
  407. 'default_subnav_slug' => 'my-groups',  
  408. 'item_css_id' => $this->id 
  409. ); 
  410.  
  411. if ( ! empty( $user_domain ) ) { 
  412. $access = bp_core_can_edit_settings(); 
  413. $groups_link = trailingslashit( $user_domain . $slug ); 
  414.  
  415. // Add the My Groups nav item. 
  416. $sub_nav[] = array( 
  417. 'name' => __( 'Memberships', 'buddypress' ),  
  418. 'slug' => 'my-groups',  
  419. 'parent_url' => $groups_link,  
  420. 'parent_slug' => $slug,  
  421. 'screen_function' => 'groups_screen_my_groups',  
  422. 'position' => 10,  
  423. 'item_css_id' => 'groups-my-groups' 
  424. ); 
  425.  
  426. // Add the Group Invites nav item. 
  427. $sub_nav[] = array( 
  428. 'name' => __( 'Invitations', 'buddypress' ),  
  429. 'slug' => 'invites',  
  430. 'parent_url' => $groups_link,  
  431. 'parent_slug' => $slug,  
  432. 'screen_function' => 'groups_screen_group_invites',  
  433. 'user_has_access' => $access,  
  434. 'position' => 30 
  435. ); 
  436.  
  437. parent::setup_nav( $main_nav, $sub_nav ); 
  438.  
  439. if ( bp_is_groups_component() && bp_is_single_item() ) { 
  440.  
  441. // Reset sub nav. 
  442. $sub_nav = array(); 
  443.  
  444. /** 
  445. * The top-level Groups item is called 'Memberships' for legacy reasons. 
  446. * It does not appear in the interface. 
  447. */ 
  448. bp_core_new_nav_item( array( 
  449. 'name' => __( 'Memberships', 'buddypress' ),  
  450. 'slug' => $this->current_group->slug,  
  451. 'position' => -1, // Do not show in BuddyBar. 
  452. 'screen_function' => 'groups_screen_group_home',  
  453. 'default_subnav_slug' => $this->default_extension,  
  454. 'item_css_id' => $this->id 
  455. ), 'groups' ); 
  456.  
  457. $group_link = bp_get_group_permalink( $this->current_group ); 
  458.  
  459. // Add the "Home" subnav item, as this will always be present. 
  460. $sub_nav[] = array( 
  461. 'name' => _x( 'Home', 'Group screen navigation title', 'buddypress' ),  
  462. 'slug' => 'home',  
  463. 'parent_url' => $group_link,  
  464. 'parent_slug' => $this->current_group->slug,  
  465. 'screen_function' => 'groups_screen_group_home',  
  466. 'position' => 10,  
  467. 'item_css_id' => 'home' 
  468. ); 
  469.  
  470. // If this is a private group, and the user is not a 
  471. // member and does not have an outstanding invitation,  
  472. // show a "Request Membership" nav item. 
  473. if ( is_user_logged_in() && 
  474. ! $this->current_group->is_user_member && 
  475. ! groups_check_for_membership_request( bp_loggedin_user_id(), $this->current_group->id ) && 
  476. $this->current_group->status == 'private' && 
  477. ! groups_check_user_has_invite( bp_loggedin_user_id(), $this->current_group->id ) 
  478. ) { 
  479.  
  480. $sub_nav[] = array( 
  481. 'name' => _x( 'Request Membership', 'Group screen nav', 'buddypress' ),  
  482. 'slug' => 'request-membership',  
  483. 'parent_url' => $group_link,  
  484. 'parent_slug' => $this->current_group->slug,  
  485. 'screen_function' => 'groups_screen_group_request_membership',  
  486. 'position' => 30 
  487. ); 
  488.  
  489. // Forums are enabled and turned on. 
  490. if ( $this->current_group->enable_forum && bp_is_active( 'forums' ) ) { 
  491. $sub_nav[] = array( 
  492. 'name' => _x( 'Forum', 'My Group screen nav', 'buddypress' ),  
  493. 'slug' => 'forum',  
  494. 'parent_url' => $group_link,  
  495. 'parent_slug' => $this->current_group->slug,  
  496. 'screen_function' => 'groups_screen_group_forum',  
  497. 'position' => 40,  
  498. 'user_has_access' => $this->current_group->user_has_access,  
  499. 'item_css_id' => 'forums' 
  500. ); 
  501.  
  502. if ( $this->current_group->front_template || bp_is_active( 'activity' ) ) { 
  503. /** 
  504. * If the theme is using a custom front, create activity subnav. 
  505. */ 
  506. if ( $this->current_group->front_template && bp_is_active( 'activity' ) ) { 
  507. $sub_nav[] = array( 
  508. 'name' => _x( 'Activity', 'My Group screen nav', 'buddypress' ),  
  509. 'slug' => 'activity',  
  510. 'parent_url' => $group_link,  
  511. 'parent_slug' => $this->current_group->slug,  
  512. 'screen_function' => 'groups_screen_group_activity',  
  513. 'position' => 11,  
  514. 'user_has_access' => $this->current_group->user_has_access,  
  515. 'item_css_id' => 'activity',  
  516. 'no_access_url' => $group_link,  
  517. ); 
  518.  
  519. /** 
  520. * Only add the members subnav if it's not the home's nav. 
  521. */ 
  522. $sub_nav[] = array( 
  523. 'name' => sprintf( _x( 'Members %s', 'My Group screen nav', 'buddypress' ), '<span>' . number_format( $this->current_group->total_member_count ) . '</span>' ),  
  524. 'slug' => 'members',  
  525. 'parent_url' => $group_link,  
  526. 'parent_slug' => $this->current_group->slug,  
  527. 'screen_function' => 'groups_screen_group_members',  
  528. 'position' => 60,  
  529. 'user_has_access' => $this->current_group->user_has_access,  
  530. 'item_css_id' => 'members',  
  531. 'no_access_url' => $group_link,  
  532. ); 
  533.  
  534. if ( bp_is_active( 'friends' ) && bp_groups_user_can_send_invites() ) { 
  535. $sub_nav[] = array( 
  536. 'name' => _x( 'Send Invites', 'My Group screen nav', 'buddypress' ),  
  537. 'slug' => 'send-invites',  
  538. 'parent_url' => $group_link,  
  539. 'parent_slug' => $this->current_group->slug,  
  540. 'screen_function' => 'groups_screen_group_invite',  
  541. 'item_css_id' => 'invite',  
  542. 'position' => 70,  
  543. 'user_has_access' => $this->current_group->user_has_access,  
  544. 'no_access_url' => $group_link,  
  545. ); 
  546.  
  547. // If the user is a group admin, then show the group admin nav item. 
  548. if ( bp_is_item_admin() ) { 
  549. $sub_nav[] = array( 
  550. 'name' => _x( 'Manage', 'My Group screen nav', 'buddypress' ),  
  551. 'slug' => 'admin',  
  552. 'parent_url' => $group_link,  
  553. 'parent_slug' => $this->current_group->slug,  
  554. 'screen_function' => 'groups_screen_group_admin',  
  555. 'position' => 1000,  
  556. 'user_has_access' => true,  
  557. 'item_css_id' => 'admin',  
  558. 'no_access_url' => $group_link,  
  559. ); 
  560.  
  561. $admin_link = trailingslashit( $group_link . 'admin' ); 
  562.  
  563. // Common params to all nav items. 
  564. $default_params = array( 
  565. 'parent_url' => $admin_link,  
  566. 'parent_slug' => $this->current_group->slug . '_manage',  
  567. 'screen_function' => 'groups_screen_group_admin',  
  568. 'user_has_access' => bp_is_item_admin(),  
  569. 'show_in_admin_bar' => true,  
  570. ); 
  571.  
  572. $sub_nav[] = array_merge( array( 
  573. 'name' => __( 'Details', 'buddypress' ),  
  574. 'slug' => 'edit-details',  
  575. 'position' => 0,  
  576. ), $default_params ); 
  577.  
  578. $sub_nav[] = array_merge( array( 
  579. 'name' => __( 'Settings', 'buddypress' ),  
  580. 'slug' => 'group-settings',  
  581. 'position' => 10,  
  582. ), $default_params ); 
  583.  
  584. if ( ! bp_disable_group_avatar_uploads() && buddypress()->avatar->show_avatars ) { 
  585. $sub_nav[] = array_merge( array( 
  586. 'name' => __( 'Photo', 'buddypress' ),  
  587. 'slug' => 'group-avatar',  
  588. 'position' => 20,  
  589. ), $default_params ); 
  590.  
  591. if ( bp_group_use_cover_image_header() ) { 
  592. $sub_nav[] = array_merge( array( 
  593. 'name' => __( 'Cover Image', 'buddypress' ),  
  594. 'slug' => 'group-cover-image',  
  595. 'position' => 25,  
  596. ), $default_params ); 
  597.  
  598. $sub_nav[] = array_merge( array( 
  599. 'name' => __( 'Members', 'buddypress' ),  
  600. 'slug' => 'manage-members',  
  601. 'position' => 30,  
  602. ), $default_params ); 
  603.  
  604. if ( 'private' == $this->current_group->status ) { 
  605. $sub_nav[] = array_merge( array( 
  606. 'name' => __( 'Requests', 'buddypress' ),  
  607. 'slug' => 'membership-requests',  
  608. 'position' => 40,  
  609. ), $default_params ); 
  610.  
  611. $sub_nav[] = array_merge( array( 
  612. 'name' => __( 'Delete', 'buddypress' ),  
  613. 'slug' => 'delete-group',  
  614. 'position' => 1000,  
  615. ), $default_params ); 
  616.  
  617. foreach ( $sub_nav as $nav ) { 
  618. bp_core_new_subnav_item( $nav, 'groups' ); 
  619.  
  620. if ( isset( $this->current_group->user_has_access ) ) { 
  621.  
  622. /** 
  623. * Fires at the end of the groups navigation setup if user has access. 
  624. * @since 1.0.2 
  625. * @param bool $user_has_access Whether or not user has access. 
  626. */ 
  627. do_action( 'groups_setup_nav', $this->current_group->user_has_access ); 
  628. } else { 
  629.  
  630. /** This action is documented in bp-groups/bp-groups-loader.php */ 
  631. do_action( 'groups_setup_nav'); 
  632.  
  633. /** 
  634. * Set up the component entries in the WordPress Admin Bar. 
  635. * @since 1.5.0 
  636. * @see BP_Component::setup_nav() for a description of the $wp_admin_nav 
  637. * parameter array. 
  638. * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a description. 
  639. */ 
  640. public function setup_admin_bar( $wp_admin_nav = array() ) { 
  641.  
  642. // Menus for logged in user. 
  643. if ( is_user_logged_in() ) { 
  644.  
  645. // Setup the logged in user variables. 
  646. $groups_link = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() ); 
  647.  
  648. // Pending group invites. 
  649. $count = groups_get_invite_count_for_user(); 
  650. $title = _x( 'Groups', 'My Account Groups', 'buddypress' ); 
  651. $pending = _x( 'No Pending Invites', 'My Account Groups sub nav', 'buddypress' ); 
  652.  
  653. if ( ! empty( $count['total'] ) ) { 
  654. $title = sprintf( 
  655. /** translators: %s: Group invitation count for the current user */ 
  656. _x( 'Groups %s', 'My Account Groups nav', 'buddypress' ),  
  657. '<span class="count">' . bp_core_number_format( $count ) . '</span>' 
  658. ); 
  659.  
  660. $pending = sprintf( 
  661. /** translators: %s: Group invitation count for the current user */ 
  662. _x( 'Pending Invites %s', 'My Account Groups sub nav', 'buddypress' ),  
  663. '<span class="count">' . bp_core_number_format( $count ) . '</span>' 
  664. ); 
  665.  
  666. // Add the "My Account" sub menus. 
  667. $wp_admin_nav[] = array( 
  668. 'parent' => buddypress()->my_account_menu_id,  
  669. 'id' => 'my-account-' . $this->id,  
  670. 'title' => $title,  
  671. 'href' => $groups_link 
  672. ); 
  673.  
  674. // My Groups. 
  675. $wp_admin_nav[] = array( 
  676. 'parent' => 'my-account-' . $this->id,  
  677. 'id' => 'my-account-' . $this->id . '-memberships',  
  678. 'title' => _x( 'Memberships', 'My Account Groups sub nav', 'buddypress' ),  
  679. 'href' => $groups_link,  
  680. 'position' => 10 
  681. ); 
  682.  
  683. // Invitations. 
  684. $wp_admin_nav[] = array( 
  685. 'parent' => 'my-account-' . $this->id,  
  686. 'id' => 'my-account-' . $this->id . '-invites',  
  687. 'title' => $pending,  
  688. 'href' => trailingslashit( $groups_link . 'invites' ),  
  689. 'position' => 30 
  690. ); 
  691.  
  692. // Create a Group. 
  693. if ( bp_user_can_create_groups() ) { 
  694. $wp_admin_nav[] = array( 
  695. 'parent' => 'my-account-' . $this->id,  
  696. 'id' => 'my-account-' . $this->id . '-create',  
  697. 'title' => _x( 'Create a Group', 'My Account Groups sub nav', 'buddypress' ),  
  698. 'href' => trailingslashit( bp_get_groups_directory_permalink() . 'create' ),  
  699. 'position' => 90 
  700. ); 
  701.  
  702. parent::setup_admin_bar( $wp_admin_nav ); 
  703.  
  704. /** 
  705. * Set up the title for pages and <title>. 
  706. * @since 1.5.0 
  707. */ 
  708. public function setup_title() { 
  709.  
  710. if ( bp_is_groups_component() ) { 
  711. $bp = buddypress(); 
  712.  
  713. if ( bp_is_my_profile() && !bp_is_single_item() ) { 
  714. $bp->bp_options_title = _x( 'Memberships', 'My Groups page <title>', 'buddypress' ); 
  715.  
  716. } elseif ( !bp_is_my_profile() && !bp_is_single_item() ) { 
  717. $bp->bp_options_avatar = bp_core_fetch_avatar( array( 
  718. 'item_id' => bp_displayed_user_id(),  
  719. 'type' => 'thumb',  
  720. 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_get_displayed_user_fullname() ) 
  721. ) ); 
  722. $bp->bp_options_title = bp_get_displayed_user_fullname(); 
  723.  
  724. // We are viewing a single group, so set up the 
  725. // group navigation menu using the $this->current_group global. 
  726. } elseif ( bp_is_single_item() ) { 
  727. $bp->bp_options_title = $this->current_group->name; 
  728. $bp->bp_options_avatar = bp_core_fetch_avatar( array( 
  729. 'item_id' => $this->current_group->id,  
  730. 'object' => 'group',  
  731. 'type' => 'thumb',  
  732. 'avatar_dir' => 'group-avatars',  
  733. 'alt' => __( 'Group Profile Photo', 'buddypress' ) 
  734. ) ); 
  735.  
  736. if ( empty( $bp->bp_options_avatar ) ) { 
  737. $bp->bp_options_avatar = '<img src="' . esc_url( bp_core_avatar_default_thumb() ) . '" alt="' . esc_attr__( 'No Group Profile Photo', 'buddypress' ) . '" class="avatar" />'; 
  738.  
  739. parent::setup_title(); 
  740.  
  741. /** 
  742. * Setup cache groups 
  743. * @since 2.2.0 
  744. */ 
  745. public function setup_cache_groups() { 
  746.  
  747. // Global groups. 
  748. wp_cache_add_global_groups( array( 
  749. 'bp_groups',  
  750. 'bp_group_admins',  
  751. 'bp_group_invite_count',  
  752. 'group_meta',  
  753. 'bp_groups_memberships',  
  754. 'bp_groups_memberships_for_user',  
  755. ) ); 
  756.  
  757. parent::setup_cache_groups(); 
  758.  
  759. /** 
  760. * Set up taxonomies. 
  761. * @since 2.6.0 
  762. */ 
  763. public function register_taxonomies() { 
  764. // Group Type. 
  765. register_taxonomy( 'bp_group_type', 'bp_group', array( 
  766. 'public' => false,  
  767. ) );