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