/bp-groups/classes/class-bp-groups-component.php

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