/bp-groups/bp-groups-template.php

  1. <?php 
  2. /** 
  3. * BuddyPress Groups Template Functions. 
  4. * 
  5. * @package BuddyPress 
  6. * @subpackage GroupsTemplates 
  7. * @since 1.5.0 
  8. */ 
  9.  
  10. // Exit if accessed directly. 
  11. defined( 'ABSPATH' ) || exit; 
  12.  
  13. /** 
  14. * Output the groups component slug. 
  15. * 
  16. * @since 1.5.0 
  17. */ 
  18. function bp_groups_slug() { 
  19. echo bp_get_groups_slug(); 
  20. /** 
  21. * Return the groups component slug. 
  22. * 
  23. * @since 1.5.0 
  24. * 
  25. * @return string 
  26. */ 
  27. function bp_get_groups_slug() { 
  28.  
  29. /** 
  30. * Filters the groups component slug. 
  31. * 
  32. * @since 1.5.0 
  33. * 
  34. * @param string $slug Groups component slug. 
  35. */ 
  36. return apply_filters( 'bp_get_groups_slug', buddypress()->groups->slug ); 
  37.  
  38. /** 
  39. * Output the groups component root slug. 
  40. * 
  41. * @since 1.5.0 
  42. */ 
  43. function bp_groups_root_slug() { 
  44. echo bp_get_groups_root_slug(); 
  45. /** 
  46. * Return the groups component root slug. 
  47. * 
  48. * @since 1.5.0 
  49. * 
  50. * @return string 
  51. */ 
  52. function bp_get_groups_root_slug() { 
  53.  
  54. /** 
  55. * Filters the groups component root slug. 
  56. * 
  57. * @since 1.5.0 
  58. * 
  59. * @param string $root_slug Groups component root slug. 
  60. */ 
  61. return apply_filters( 'bp_get_groups_root_slug', buddypress()->groups->root_slug ); 
  62.  
  63. /** 
  64. * Output the group type base slug. 
  65. * 
  66. * @since 2.7.0 
  67. */ 
  68. function bp_groups_group_type_base() { 
  69. echo esc_url( bp_get_groups_group_type_base() ); 
  70. /** 
  71. * Get the group type base slug. 
  72. * 
  73. * The base slug is the string used as the base prefix when generating group 
  74. * type directory URLs. For example, in example.com/groups/type/foo/, 'foo' is 
  75. * the group type and 'type' is the base slug. 
  76. * 
  77. * @since 2.7.0 
  78. * 
  79. * @return string 
  80. */ 
  81. function bp_get_groups_group_type_base() { 
  82. /** 
  83. * Filters the group type URL base. 
  84. * 
  85. * @since 2.7.0 
  86. * 
  87. * @param string $base 
  88. */ 
  89. return apply_filters( 'bp_groups_group_type_base', _x( 'type', 'group type URL base', 'buddypress' ) ); 
  90.  
  91. /** 
  92. * Output group directory permalink. 
  93. * 
  94. * @since 1.5.0 
  95. */ 
  96. function bp_groups_directory_permalink() { 
  97. echo esc_url( bp_get_groups_directory_permalink() ); 
  98. /** 
  99. * Return group directory permalink. 
  100. * 
  101. * @since 1.5.0 
  102. * 
  103. * @return string 
  104. */ 
  105. function bp_get_groups_directory_permalink() { 
  106.  
  107. /** 
  108. * Filters the group directory permalink. 
  109. * 
  110. * @since 1.5.0 
  111. * 
  112. * @param string $value Permalink for the group directory. 
  113. */ 
  114. return apply_filters( 'bp_get_groups_directory_permalink', trailingslashit( bp_get_root_domain() . '/' . bp_get_groups_root_slug() ) ); 
  115.  
  116. /** 
  117. * Output group type directory permalink. 
  118. * 
  119. * @since 2.7.0 
  120. * 
  121. * @param string $group_type Optional. Group type. 
  122. */ 
  123. function bp_group_type_directory_permalink( $group_type = '' ) { 
  124. echo esc_url( bp_get_group_type_directory_permalink( $group_type ) ); 
  125. /** 
  126. * Return group type directory permalink. 
  127. * 
  128. * @since 2.7.0 
  129. * 
  130. * @param string $group_type Optional. Group type. Defaults to current group type. 
  131. * @return string Group type directory URL on success, an empty string on failure. 
  132. */ 
  133. function bp_get_group_type_directory_permalink( $group_type = '' ) { 
  134.  
  135. if ( $group_type ) { 
  136. $_group_type = $group_type; 
  137. } else { 
  138. // Fall back on the current group type. 
  139. $_group_type = bp_get_current_group_directory_type(); 
  140.  
  141. $type = bp_groups_get_group_type_object( $_group_type ); 
  142.  
  143. // Bail when member type is not found or has no directory. 
  144. if ( ! $type || ! $type->has_directory ) { 
  145. return ''; 
  146.  
  147. /** 
  148. * Filters the group type directory permalink. 
  149. * 
  150. * @since 2.7.0 
  151. * 
  152. * @param string $value Group type directory permalink. 
  153. * @param object $type Group type object. 
  154. * @param string $member_type Group type name, as passed to the function. 
  155. */ 
  156. return apply_filters( 'bp_get_group_type_directory_permalink', trailingslashit( bp_get_groups_directory_permalink() . bp_get_groups_group_type_base() . '/' . $type->directory_slug ), $type, $group_type ); 
  157.  
  158. /** 
  159. * Output group type directory link. 
  160. * 
  161. * @since 2.7.0 
  162. * 
  163. * @param string $group_type Unique group type identifier as used in bp_groups_register_group_type(). 
  164. */ 
  165. function bp_group_type_directory_link( $group_type = '' ) { 
  166. echo bp_get_group_type_directory_link( $group_type ); 
  167. /** 
  168. * Return group type directory link. 
  169. * 
  170. * @since 2.7.0 
  171. * 
  172. * @param string $group_type Unique group type identifier as used in bp_groups_register_group_type(). 
  173. * @return string 
  174. */ 
  175. function bp_get_group_type_directory_link( $group_type = '' ) { 
  176. if ( empty( $group_type ) ) { 
  177. return ''; 
  178.  
  179. return sprintf( '<a href="%s">%s</a>', esc_url( bp_get_group_type_directory_permalink( $group_type ) ), bp_groups_get_group_type_object( $group_type )->labels['name'] ); 
  180.  
  181. /** 
  182. * Output a comma-delimited list of group types. 
  183. * 
  184. * @since 2.7.0 
  185. * @see bp_get_group_type_list() for parameter documentation. 
  186. */ 
  187. function bp_group_type_list( $group_id = 0, $r = array() ) { 
  188. echo bp_get_group_type_list( $group_id, $r ); 
  189. /** 
  190. * Return a comma-delimited list of group types. 
  191. * 
  192. * @since 2.7.0 
  193. * 
  194. * @param int $group_id Group ID. Defaults to current group ID if on a group page. 
  195. * @param array|string $args { 
  196. * Array of parameters. All items are optional. 
  197. * @type string $parent_element Element to wrap around the list. Defaults to 'p'. 
  198. * @type array $parent_attr Element attributes for parent element. Defaults to 
  199. * array( 'class' => 'bp-group-type-list' ). 
  200. * @type string $label Label to add before the list. Defaults to 'Group Types:'. 
  201. * @type string $label_element Element to wrap around the label. Defaults to 'strong'. 
  202. * @type array $label_attr Element attributes for label element. Defaults to array(). 
  203. * @type bool $show_all Whether to show all registered group types. Defaults to 'false'. If 
  204. * 'false', only shows group types with the 'show_in_list' parameter set to 
  205. * true. See bp_groups_register_group_type() for more info. 
  206. * } 
  207. * @return string 
  208. */ 
  209. function bp_get_group_type_list( $group_id = 0, $r = array() ) { 
  210. if ( empty( $group_id ) ) { 
  211. $group_id = bp_get_current_group_id(); 
  212.  
  213. $r = bp_parse_args( $r, array( 
  214. 'parent_element' => 'p',  
  215. 'parent_attr' => array( 
  216. 'class' => 'bp-group-type-list',  
  217. ),  
  218. 'label' => __( 'Group Types:', 'buddypress' ),  
  219. 'label_element' => 'strong',  
  220. 'label_attr' => array(),  
  221. 'show_all' => false,  
  222. ), 'group_type_list' ); 
  223.  
  224. $retval = ''; 
  225.  
  226. if ( $types = bp_groups_get_group_type( $group_id, false ) ) { 
  227. // Make sure we can show the type in the list. 
  228. if ( false === $r['show_all'] ) { 
  229. $types = array_intersect( bp_groups_get_group_types( array( 'show_in_list' => true ) ), $types ); 
  230. if ( empty( $types ) ) { 
  231. return $retval; 
  232.  
  233. $before = $after = $label = ''; 
  234.  
  235. // Render parent element. 
  236. if ( ! empty( $r['parent_element'] ) ) { 
  237. $parent_elem = new BP_Core_HTML_Element( array( 
  238. 'element' => $r['parent_element'],  
  239. 'attr' => $r['parent_attr'] 
  240. ) ); 
  241.  
  242. // Set before and after. 
  243. $before = $parent_elem->get( 'open_tag' ); 
  244. $after = $parent_elem->get( 'close_tag' ); 
  245.  
  246. // Render label element. 
  247. if ( ! empty( $r['label_element'] ) ) { 
  248. $label = new BP_Core_HTML_Element( array( 
  249. 'element' => $r['label_element'],  
  250. 'attr' => $r['label_attr'],  
  251. 'inner_html' => esc_html( $r['label'] ) 
  252. ) ); 
  253. $label = $label->contents() . ' '; 
  254.  
  255. // No element, just the label. 
  256. } else { 
  257. $label = esc_html( $r['label'] ); 
  258.  
  259. // Comma-delimit each type into the group type directory link. 
  260. $label .= implode( ', ', array_map( 'bp_get_group_type_directory_link', $types ) ); 
  261.  
  262. // Retval time! 
  263. $retval = $before . $label . $after; 
  264.  
  265. return $retval; 
  266.  
  267. /** 
  268. * Start the Groups Template Loop. 
  269. * 
  270. * @since 1.0.0 
  271. * @since 2.6.0 Added `$group_type`, `$group_type__in`, and `$group_type__not_in` parameters. 
  272. * @since 2.7.0 Added `$update_admin_cache` parameter. 
  273. * 
  274. * @param array|string $args { 
  275. * Array of parameters. All items are optional. 
  276. * @type string $type Shorthand for certain orderby/order combinations. 'newest', 'active',  
  277. * 'popular', 'alphabetical', 'random'. When present, will override 
  278. * orderby and order params. Default: null. 
  279. * @type string $order Sort order. 'ASC' or 'DESC'. Default: 'DESC'. 
  280. * @type string $orderby Property to sort by. 'date_created', 'last_activity',  
  281. * 'total_member_count', 'name', 'random'. Default: 'last_activity'. 
  282. * @type int $page Page offset of results to return. Default: 1 (first page of results). 
  283. * @type int $per_page Number of items to return per page of results. Default: 20. 
  284. * @type int $max Does NOT affect query. May change the reported number of total groups 
  285. * found, but not the actual number of found groups. Default: false. 
  286. * @type bool $show_hidden Whether to include hidden groups in results. Default: false. 
  287. * @type string $page_arg Query argument used for pagination. Default: 'grpage'. 
  288. * @type int $user_id If provided, results will be limited to groups of which the specified 
  289. * user is a member. Default: value of bp_displayed_user_id(). 
  290. * @type string $slug If provided, only the group with the matching slug will be returned. 
  291. * Default: false. 
  292. * @type string $search_terms If provided, only groups whose names or descriptions match the search 
  293. * terms will be returned. Default: value of `$_REQUEST['groups_search']` or 
  294. * `$_REQUEST['s']`, if present. Otherwise false. 
  295. * @type array|string $group_type Array or comma-separated list of group types to limit results to. 
  296. * @type array|string $group_type__in Array or comma-separated list of group types to limit results to. 
  297. * @type array|string $group_type__not_in Array or comma-separated list of group types that will be 
  298. * excluded from results. 
  299. * @type array $meta_query An array of meta_query conditions. 
  300. * See {@link WP_Meta_Query::queries} for description. 
  301. * @type array|string $include Array or comma-separated list of group IDs. Results will be limited 
  302. * to groups within the list. Default: false. 
  303. * @type array|string $exclude Array or comma-separated list of group IDs. Results will exclude 
  304. * the listed groups. Default: false. 
  305. * @type array|string $parent_id Array or comma-separated list of group IDs. Results will include only 
  306. * child groups of the listed groups. Default: null. 
  307. * @type bool $update_meta_cache Whether to fetch groupmeta for queried groups. Default: true. 
  308. * @type bool $update_admin_cache Whether to pre-fetch group admins for queried groups. 
  309. * Defaults to true when on a group directory, where this 
  310. * information is needed in the loop. Otherwise false. 
  311. * } 
  312. * @return bool True if there are groups to display that match the params 
  313. */ 
  314. function bp_has_groups( $args = '' ) { 
  315. global $groups_template; 
  316.  
  317. /** 
  318. * Defaults based on the current page & overridden by parsed $args 
  319. */ 
  320. $slug = false; 
  321. $type = ''; 
  322. $search_terms = false; 
  323.  
  324. // When looking your own groups, check for two action variables. 
  325. if ( bp_is_current_action( 'my-groups' ) ) { 
  326. if ( bp_is_action_variable( 'most-popular', 0 ) ) { 
  327. $type = 'popular'; 
  328. } elseif ( bp_is_action_variable( 'alphabetically', 0 ) ) { 
  329. $type = 'alphabetical'; 
  330.  
  331. // When looking at invites, set type to invites. 
  332. } elseif ( bp_is_current_action( 'invites' ) ) { 
  333. $type = 'invites'; 
  334.  
  335. // When looking at a single group, set the type and slug. 
  336. } elseif ( bp_get_current_group_slug() ) { 
  337. $type = 'single-group'; 
  338. $slug = bp_get_current_group_slug(); 
  339.  
  340. $group_type = bp_get_current_group_directory_type(); 
  341. if ( ! $group_type && ! empty( $_GET['group_type'] ) ) { 
  342. if ( is_array( $_GET['group_type'] ) ) { 
  343. $group_type = $_GET['group_type']; 
  344. } else { 
  345. // Can be a comma-separated list. 
  346. $group_type = explode( ', ', $_GET['group_type'] ); 
  347.  
  348. // Default search string (too soon to escape here). 
  349. $search_query_arg = bp_core_get_component_search_query_arg( 'groups' ); 
  350. if ( ! empty( $_REQUEST[ $search_query_arg ] ) ) { 
  351. $search_terms = stripslashes( $_REQUEST[ $search_query_arg ] ); 
  352. } elseif ( ! empty( $_REQUEST['group-filter-box'] ) ) { 
  353. $search_terms = $_REQUEST['group-filter-box']; 
  354. } elseif ( !empty( $_REQUEST['s'] ) ) { 
  355. $search_terms = $_REQUEST['s']; 
  356.  
  357. // Parse defaults and requested arguments. 
  358. $r = bp_parse_args( $args, array( 
  359. 'type' => $type,  
  360. 'order' => 'DESC',  
  361. 'orderby' => 'last_activity',  
  362. 'page' => 1,  
  363. 'per_page' => 20,  
  364. 'max' => false,  
  365. 'show_hidden' => false,  
  366. 'page_arg' => 'grpage',  
  367. 'user_id' => bp_displayed_user_id(),  
  368. 'slug' => $slug,  
  369. 'search_terms' => $search_terms,  
  370. 'group_type' => $group_type,  
  371. 'group_type__in' => '',  
  372. 'group_type__not_in' => '',  
  373. 'meta_query' => false,  
  374. 'include' => false,  
  375. 'exclude' => false,  
  376. 'parent_id' => null,  
  377. 'update_meta_cache' => true,  
  378. 'update_admin_cache' => bp_is_groups_directory() || bp_is_user_groups(),  
  379. ), 'has_groups' ); 
  380.  
  381. // Setup the Groups template global. 
  382. $groups_template = new BP_Groups_Template( array( 
  383. 'type' => $r['type'],  
  384. 'order' => $r['order'],  
  385. 'orderby' => $r['orderby'],  
  386. 'page' => (int) $r['page'],  
  387. 'per_page' => (int) $r['per_page'],  
  388. 'max' => (int) $r['max'],  
  389. 'show_hidden' => $r['show_hidden'],  
  390. 'page_arg' => $r['page_arg'],  
  391. 'user_id' => (int) $r['user_id'],  
  392. 'slug' => $r['slug'],  
  393. 'search_terms' => $r['search_terms'],  
  394. 'group_type' => $r['group_type'],  
  395. 'group_type__in' => $r['group_type__in'],  
  396. 'group_type__not_in' => $r['group_type__not_in'],  
  397. 'meta_query' => $r['meta_query'],  
  398. 'include' => $r['include'],  
  399. 'exclude' => $r['exclude'],  
  400. 'parent_id' => $r['parent_id'],  
  401. 'update_meta_cache' => (bool) $r['update_meta_cache'],  
  402. 'update_admin_cache' => (bool) $r['update_admin_cache'],  
  403. ) ); 
  404.  
  405. /** 
  406. * Filters whether or not there are groups to iterate over for the groups loop. 
  407. * 
  408. * @since 1.1.0 
  409. * 
  410. * @param bool $value Whether or not there are groups to iterate over. 
  411. * @param BP_Groups_Template $groups_template BP_Groups_Template object based on parsed arguments. 
  412. * @param array $r Array of parsed arguments for the query. 
  413. */ 
  414. return apply_filters( 'bp_has_groups', $groups_template->has_groups(), $groups_template, $r ); 
  415.  
  416. /** 
  417. * Check whether there are more groups to iterate over. 
  418. * 
  419. * @since 1.0.0 
  420. * 
  421. * @return bool 
  422. */ 
  423. function bp_groups() { 
  424. global $groups_template; 
  425. return $groups_template->groups(); 
  426.  
  427. /** 
  428. * Set up the current group inside the loop. 
  429. * 
  430. * @since 1.0.0 
  431. * 
  432. * @return object 
  433. */ 
  434. function bp_the_group() { 
  435. global $groups_template; 
  436. return $groups_template->the_group(); 
  437.  
  438. /** 
  439. * Is the group visible to the currently logged-in user? 
  440. * 
  441. * @since 1.0.0 
  442. * 
  443. * @param BP_Groups_Group $group Optional. Group object. Default: current group in loop. 
  444. * @return bool 
  445. */ 
  446. function bp_group_is_visible( $group = null ) { 
  447. global $groups_template; 
  448.  
  449. if ( bp_current_user_can( 'bp_moderate' ) ) { 
  450. return true; 
  451.  
  452. if ( empty( $group ) ) { 
  453. $group =& $groups_template->group; 
  454.  
  455. if ( 'public' == $group->status ) { 
  456. return true; 
  457. } else { 
  458. if ( groups_is_user_member( bp_loggedin_user_id(), $group->id ) ) { 
  459. return true; 
  460.  
  461. return false; 
  462.  
  463. /** 
  464. * Output the ID of the current group in the loop. 
  465. * 
  466. * @since 1.0.0 
  467. * 
  468. * @param object|bool $group Optional. Group object. Default: current group in loop. 
  469. */ 
  470. function bp_group_id( $group = false ) { 
  471. echo bp_get_group_id( $group ); 
  472. /** 
  473. * Get the ID of the current group in the loop. 
  474. * 
  475. * @since 1.0.0 
  476. * 
  477. * @param object|bool $group Optional. Group object. 
  478. * Default: current group in loop. 
  479. * @return int 
  480. */ 
  481. function bp_get_group_id( $group = false ) { 
  482. global $groups_template; 
  483.  
  484. if ( empty( $group ) ) { 
  485. $group =& $groups_template->group; 
  486.  
  487. /** 
  488. * Filters the ID of the current group in the loop. 
  489. * 
  490. * @since 1.0.0 
  491. * @since 2.5.0 Added the `$group` parameter. 
  492. * 
  493. * @param int $id ID of the current group in the loop. 
  494. * @param object $group Group object. 
  495. */ 
  496. return apply_filters( 'bp_get_group_id', $group->id, $group ); 
  497.  
  498. /** 
  499. * Output the row class of the current group in the loop. 
  500. * 
  501. * @since 1.7.0 
  502. * 
  503. * @param array $classes Array of custom classes. 
  504. */ 
  505. function bp_group_class( $classes = array() ) { 
  506. echo bp_get_group_class( $classes ); 
  507. /** 
  508. * Get the row class of the current group in the loop. 
  509. * 
  510. * @since 1.7.0 
  511. * 
  512. * @param array $classes Array of custom classes. 
  513. * @return string Row class of the group. 
  514. */ 
  515. function bp_get_group_class( $classes = array() ) { 
  516. global $groups_template; 
  517.  
  518. // Add even/odd classes, but only if there's more than 1 group. 
  519. if ( $groups_template->group_count > 1 ) { 
  520. $pos_in_loop = (int) $groups_template->current_group; 
  521. $classes[] = ( $pos_in_loop % 2 ) ? 'even' : 'odd'; 
  522.  
  523. // If we've only one group in the loop, don't bother with odd and even. 
  524. } else { 
  525. $classes[] = 'bp-single-group'; 
  526.  
  527. // Group type - public, private, hidden. 
  528. $classes[] = sanitize_key( $groups_template->group->status ); 
  529.  
  530. // Add current group types. 
  531. if ( $group_types = bp_groups_get_group_type( bp_get_group_id(), false ) ) { 
  532. foreach ( $group_types as $group_type ) { 
  533. $classes[] = sprintf( 'group-type-%s', esc_attr( $group_type ) ); 
  534.  
  535. // User's group role. 
  536. if ( bp_is_user_active() ) { 
  537.  
  538. // Admin. 
  539. if ( bp_group_is_admin() ) { 
  540. $classes[] = 'is-admin'; 
  541.  
  542. // Moderator. 
  543. if ( bp_group_is_mod() ) { 
  544. $classes[] = 'is-mod'; 
  545.  
  546. // Member. 
  547. if ( bp_group_is_member() ) { 
  548. $classes[] = 'is-member'; 
  549.  
  550. // Whether a group avatar will appear. 
  551. if ( bp_disable_group_avatar_uploads() || ! buddypress()->avatar->show_avatars ) { 
  552. $classes[] = 'group-no-avatar'; 
  553. } else { 
  554. $classes[] = 'group-has-avatar'; 
  555.  
  556. /** 
  557. * Filters classes that will be applied to row class of the current group in the loop. 
  558. * 
  559. * @since 1.7.0 
  560. * 
  561. * @param array $classes Array of determined classes for the row. 
  562. */ 
  563. $classes = apply_filters( 'bp_get_group_class', $classes ); 
  564. $classes = array_merge( $classes, array() ); 
  565. $retval = 'class="' . join( ' ', $classes ) . '"'; 
  566.  
  567. return $retval; 
  568.  
  569. /** 
  570. * Output the name of the current group in the loop. 
  571. * 
  572. * @since 1.0.0 
  573. * 
  574. * @param object|bool $group Optional. Group object. 
  575. * Default: current group in loop. 
  576. */ 
  577. function bp_group_name( $group = false ) { 
  578. echo bp_get_group_name( $group ); 
  579. /** 
  580. * Get the name of the current group in the loop. 
  581. * 
  582. * @since 1.0.0 
  583. * 
  584. * @param object|bool $group Optional. Group object. 
  585. * Default: current group in loop. 
  586. * @return string 
  587. */ 
  588. function bp_get_group_name( $group = false ) { 
  589. global $groups_template; 
  590.  
  591. if ( empty( $group ) ) { 
  592. $group =& $groups_template->group; 
  593.  
  594. /** 
  595. * Filters the name of the current group in the loop. 
  596. * 
  597. * @since 1.0.0 
  598. * @since 2.5.0 Added the `$group` parameter. 
  599. * 
  600. * @param string $name Name of the current group in the loop. 
  601. * @param object $group Group object. 
  602. */ 
  603. return apply_filters( 'bp_get_group_name', $group->name, $group ); 
  604.  
  605. /** 
  606. * Output the type of the current group in the loop. 
  607. * 
  608. * @since 1.0.0 
  609. * 
  610. * @param object|bool $group Optional. Group object. 
  611. * Default: current group in loop. 
  612. */ 
  613. function bp_group_type( $group = false ) { 
  614. echo bp_get_group_type( $group ); 
  615.  
  616. /** 
  617. * Get the type of the current group in the loop. 
  618. * 
  619. * @since 1.0.0 
  620. * 
  621. * @param object|bool $group Optional. Group object. 
  622. * Default: current group in loop. 
  623. * @return string 
  624. */ 
  625. function bp_get_group_type( $group = false ) { 
  626. global $groups_template; 
  627.  
  628. if ( empty( $group ) ) { 
  629. $group =& $groups_template->group; 
  630.  
  631. if ( 'public' == $group->status ) { 
  632. $type = __( "Public Group", 'buddypress' ); 
  633. } elseif ( 'hidden' == $group->status ) { 
  634. $type = __( "Hidden Group", 'buddypress' ); 
  635. } elseif ( 'private' == $group->status ) { 
  636. $type = __( "Private Group", 'buddypress' ); 
  637. } else { 
  638. $type = ucwords( $group->status ) . ' ' . __( 'Group', 'buddypress' ); 
  639.  
  640. /** 
  641. * Filters the type for the current group in the loop. 
  642. * 
  643. * @since 1.0.0 
  644. * @since 2.5.0 Added the `$group` parameter. 
  645. * 
  646. * @param string $type Type for the current group in the loop. 
  647. * @param object $group Group object. 
  648. */ 
  649. return apply_filters( 'bp_get_group_type', $type, $group ); 
  650. /** 
  651. * Output the status of the current group in the loop. 
  652. * 
  653. * @since 1.1.0 
  654. * 
  655. * @param object|bool $group Optional. Group object. 
  656. * Default: current group in loop. 
  657. */ 
  658. function bp_group_status( $group = false ) { 
  659. echo bp_get_group_status( $group ); 
  660. /** 
  661. * Get the status of the current group in the loop. 
  662. * 
  663. * @since 1.1.0 
  664. * 
  665. * @param object|bool $group Optional. Group object. 
  666. * Default: current group in loop. 
  667. * @return string 
  668. */ 
  669. function bp_get_group_status( $group = false ) { 
  670. global $groups_template; 
  671.  
  672. if ( empty( $group ) ) { 
  673. $group =& $groups_template->group; 
  674.  
  675. /** 
  676. * Filters the status of the current group in the loop. 
  677. * 
  678. * @since 1.0.0 
  679. * @since 2.5.0 Added the `$group` parameter. 
  680. * 
  681. * @param string $status Status of the current group in the loop. 
  682. * @param object $group Group object. 
  683. */ 
  684. return apply_filters( 'bp_get_group_status', $group->status, $group ); 
  685.  
  686. /** 
  687. * Output the group avatar while in the groups loop. 
  688. * 
  689. * @since 1.0.0 
  690. * 
  691. * @param array|string $args { 
  692. * See {@link bp_get_group_avatar()} for description of arguments. 
  693. * } 
  694. */ 
  695. function bp_group_avatar( $args = '' ) { 
  696. echo bp_get_group_avatar( $args ); 
  697. /** 
  698. * Get a group's avatar. 
  699. * 
  700. * @since 1.0.0 
  701. * 
  702. * @see bp_core_fetch_avatar() For a description of arguments and return values. 
  703. * 
  704. * @param array|string $args { 
  705. * Arguments are listed here with an explanation of their defaults. 
  706. * For more information about the arguments, see {@link bp_core_fetch_avatar()}. 
  707. * 
  708. * @type string $alt Default: 'Group logo of [group name]'. 
  709. * @type string $class Default: 'avatar'. 
  710. * @type string $type Default: 'full'. 
  711. * @type int|bool $width Default: false. 
  712. * @type int|bool $height Default: false. 
  713. * @type bool $id Passed to `$css_id` parameter. 
  714. * } 
  715. * @return string Group avatar string. 
  716. */ 
  717. function bp_get_group_avatar( $args = '' ) { 
  718. global $groups_template; 
  719.  
  720. // Bail if avatars are turned off. 
  721. if ( bp_disable_group_avatar_uploads() || ! buddypress()->avatar->show_avatars ) { 
  722. return false; 
  723.  
  724. // Parse the arguments. 
  725. $r = bp_parse_args( $args, array( 
  726. 'type' => 'full',  
  727. 'width' => false,  
  728. 'height' => false,  
  729. 'class' => 'avatar',  
  730. 'id' => false,  
  731. 'alt' => sprintf( __( 'Group logo of %s', 'buddypress' ), $groups_template->group->name ) 
  732. ) ); 
  733.  
  734. // Fetch the avatar from the folder. 
  735. $avatar = bp_core_fetch_avatar( array( 
  736. 'item_id' => $groups_template->group->id,  
  737. 'avatar_dir' => 'group-avatars',  
  738. 'object' => 'group',  
  739. 'type' => $r['type'],  
  740. 'alt' => $r['alt'],  
  741. 'css_id' => $r['id'],  
  742. 'class' => $r['class'],  
  743. 'width' => $r['width'],  
  744. 'height' => $r['height'],  
  745. ) ); 
  746.  
  747. // If No avatar found, provide some backwards compatibility. 
  748. if ( empty( $avatar ) ) { 
  749. $avatar = '<img src="' . esc_url( $groups_template->group->avatar_thumb ) . '" class="avatar" alt="' . esc_attr( $groups_template->group->name ) . '" />'; 
  750.  
  751. /** 
  752. * Filters the group avatar while in the groups loop. 
  753. * 
  754. * @since 1.0.0 
  755. * 
  756. * @param string $avatar HTML image element holding the group avatar. 
  757. * @param array $r Array of parsed arguments for the group avatar. 
  758. */ 
  759. return apply_filters( 'bp_get_group_avatar', $avatar, $r ); 
  760.  
  761. /** 
  762. * Output the group avatar thumbnail while in the groups loop. 
  763. * 
  764. * @since 1.0.0 
  765. * 
  766. * @param object|bool $group Optional. Group object. 
  767. * Default: current group in loop. 
  768. */ 
  769. function bp_group_avatar_thumb( $group = false ) { 
  770. echo bp_get_group_avatar_thumb( $group ); 
  771. /** 
  772. * Return the group avatar thumbnail while in the groups loop. 
  773. * 
  774. * @since 1.0.0 
  775. * 
  776. * @param object|bool $group Optional. Group object. 
  777. * Default: current group in loop. 
  778. * @return string 
  779. */ 
  780. function bp_get_group_avatar_thumb( $group = false ) { 
  781. return bp_get_group_avatar( array( 
  782. 'type' => 'thumb',  
  783. 'id' => ! empty( $group->id ) ? $group->id : false 
  784. ) ); 
  785.  
  786. /** 
  787. * Output the miniature group avatar thumbnail while in the groups loop. 
  788. * 
  789. * @since 1.0.0 
  790. * 
  791. * @param object|bool $group Optional. Group object. 
  792. * Default: current group in loop. 
  793. */ 
  794. function bp_group_avatar_mini( $group = false ) { 
  795. echo bp_get_group_avatar_mini( $group ); 
  796. /** 
  797. * Return the miniature group avatar thumbnail while in the groups loop. 
  798. * 
  799. * @since 1.0.0 
  800. * 
  801. * @param object|bool $group Optional. Group object. 
  802. * Default: current group in loop. 
  803. * @return string 
  804. */ 
  805. function bp_get_group_avatar_mini( $group = false ) { 
  806. return bp_get_group_avatar( array( 
  807. 'type' => 'thumb',  
  808. 'width' => 30,  
  809. 'height' => 30,  
  810. 'id' => ! empty( $group->id ) ? $group->id : false 
  811. ) ); 
  812.  
  813. /** Group cover image *********************************************************/ 
  814.  
  815. /** 
  816. * Should we use the group's cover image header. 
  817. * 
  818. * @since 2.4.0 
  819. * 
  820. * @return bool True if the displayed user has a cover image,  
  821. * False otherwise 
  822. */ 
  823. function bp_group_use_cover_image_header() { 
  824. return (bool) bp_is_active( 'groups', 'cover_image' ) && ! bp_disable_group_cover_image_uploads() && bp_attachments_is_wp_version_supported(); 
  825.  
  826. /** 
  827. * Output the 'last active' string for the current group in the loop. 
  828. * 
  829. * @since 1.0.0 
  830. * @since 2.7.0 Added $args as a parameter. 
  831. * 
  832. * @param object|bool $group Optional. Group object. Default: current group in loop. 
  833. * @param array|string $args Optional. {@see bp_get_group_last_active()}. 
  834. */ 
  835. function bp_group_last_active( $group = false, $args = array() ) { 
  836. echo bp_get_group_last_active( $group, $args ); 
  837. /** 
  838. * Return the 'last active' string for the current group in the loop. 
  839. * 
  840. * @since 1.0.0 
  841. * @since 2.7.0 Added $args as a parameter. 
  842. * 
  843. * @param object|bool $group Optional. Group object. Default: current group in loop. 
  844. * @param array|string $args { 
  845. * Array of optional parameters. 
  846. * 
  847. * @type bool $relative Optional. If true, returns relative activity date. eg. active 5 months ago. 
  848. * If false, returns active date value from database. Default: true. 
  849. * } 
  850. * @return string 
  851. */ 
  852. function bp_get_group_last_active( $group = false, $args = array() ) { 
  853. global $groups_template; 
  854.  
  855. if ( empty( $group ) ) { 
  856. $group =& $groups_template->group; 
  857.  
  858. $r = wp_parse_args( $args, array( 
  859. 'relative' => true,  
  860. ) ); 
  861.  
  862. $last_active = $group->last_activity; 
  863. if ( ! $last_active ) { 
  864. $last_active = groups_get_groupmeta( $group->id, 'last_activity' ); 
  865.  
  866. // We do not want relative time, so return now. 
  867. // @todo Should the 'bp_get_group_last_active' filter be applied here? 
  868. if ( ! $r['relative'] ) { 
  869. return esc_attr( $last_active ); 
  870.  
  871. if ( empty( $last_active ) ) { 
  872. return __( 'not yet active', 'buddypress' ); 
  873. } else { 
  874.  
  875. /** 
  876. * Filters the 'last active' string for the current group in the loop. 
  877. * 
  878. * @since 1.0.0 
  879. * @since 2.5.0 Added the `$group` parameter. 
  880. * 
  881. * @param string $value Determined last active value for the current group. 
  882. * @param object $group Group object. 
  883. */ 
  884. return apply_filters( 'bp_get_group_last_active', bp_core_time_since( $last_active ), $group ); 
  885.  
  886. /** 
  887. * Output the permalink for the current group in the loop. 
  888. * 
  889. * @since 1.0.0 
  890. * 
  891. * @param BP_Groups_Group $group Optional. Group object. Default: current group in loop. 
  892. */ 
  893. function bp_group_permalink( $group = null ) { 
  894. echo bp_get_group_permalink( $group ); 
  895. /** 
  896. * Return the permalink for the current group in the loop. 
  897. * 
  898. * @since 1.0.0 
  899. * 
  900. * @param BP_Groups_Group $group Optional. Group object. Default: current group in loop. 
  901. * @return string 
  902. */ 
  903. function bp_get_group_permalink( $group = null ) { 
  904. global $groups_template; 
  905.  
  906. if ( empty( $group ) ) { 
  907. $group =& $groups_template->group; 
  908.  
  909. /** 
  910. * Filters the permalink for the current group in the loop. 
  911. * 
  912. * @since 1.0.0 
  913. * @since 2.5.0 Added the `$group` parameter. 
  914. * 
  915. * @param string $value Permalink for the current group in the loop. 
  916. * @param object $group Group object. 
  917. */ 
  918. return apply_filters( 'bp_get_group_permalink', trailingslashit( bp_get_groups_directory_permalink() . bp_get_group_slug( $group ) . '/' ), $group ); 
  919.  
  920. /** 
  921. * Output the permalink for the admin section of the current group in the loop. 
  922. * 
  923. * @since 1.0.0 
  924. * 
  925. * @param object|bool $group Optional. Group object. 
  926. * Default: current group in loop. 
  927. */ 
  928. function bp_group_admin_permalink( $group = false ) { 
  929. echo bp_get_group_admin_permalink( $group ); 
  930. /** 
  931. * Return the permalink for the admin section of the current group in the loop. 
  932. * 
  933. * @since 1.0.0 
  934. * 
  935. * @param object|bool $group Optional. Group object. 
  936. * Default: current group in loop. 
  937. * @return string 
  938. */ 
  939. function bp_get_group_admin_permalink( $group = false ) { 
  940. global $groups_template; 
  941.  
  942. if ( empty( $group ) ) { 
  943. $group =& $groups_template->group; 
  944.  
  945. /** 
  946. * Filters the permalink for the admin section of the current group in the loop. 
  947. * 
  948. * @since 1.0.0 
  949. * @since 2.5.0 Added the `$group` parameter. 
  950. * 
  951. * @param string $value Permalink for the admin section of the current group in the loop. 
  952. * @param object $group Group object. 
  953. */ 
  954. return apply_filters( 'bp_get_group_admin_permalink', trailingslashit( bp_get_group_permalink( $group ) . 'admin' ), $group ); 
  955.  
  956. /** 
  957. * Return the slug for the current group in the loop. 
  958. * 
  959. * @since 1.0.0 
  960. * 
  961. * @param object|bool $group Optional. Group object. 
  962. * Default: current group in loop. 
  963. */ 
  964. function bp_group_slug( $group = false ) { 
  965. echo bp_get_group_slug( $group ); 
  966. /** 
  967. * Return the slug for the current group in the loop. 
  968. * 
  969. * @since 1.0.0 
  970. * 
  971. * @param object|bool $group Optional. Group object. 
  972. * Default: current group in loop. 
  973. * @return string 
  974. */ 
  975. function bp_get_group_slug( $group = false ) { 
  976. global $groups_template; 
  977.  
  978. if ( empty( $group ) ) { 
  979. $group =& $groups_template->group; 
  980.  
  981. /** 
  982. * Filters the slug for the current group in the loop. 
  983. * 
  984. * @since 1.0.0 
  985. * @since 2.5.0 Added the `$group` parameter. 
  986. * 
  987. * @param string $slug Slug for the current group in the loop. 
  988. * @param object $group Group object. 
  989. */ 
  990. return apply_filters( 'bp_get_group_slug', $group->slug, $group ); 
  991.  
  992. /** 
  993. * Output the description for the current group in the loop. 
  994. * 
  995. * @since 1.0.0 
  996. * 
  997. * @param object|bool $group Optional. Group object. 
  998. * Default: current group in loop. 
  999. */ 
  1000. function bp_group_description( $group = false ) { 
  1001. echo bp_get_group_description( $group ); 
  1002. /** 
  1003. * Return the description for the current group in the loop. 
  1004. * 
  1005. * @since 1.0.0 
  1006. * 
  1007. * @param object|bool $group Optional. Group object. 
  1008. * Default: current group in loop. 
  1009. * @return string 
  1010. */ 
  1011. function bp_get_group_description( $group = false ) { 
  1012. global $groups_template; 
  1013.  
  1014. if ( empty( $group ) ) { 
  1015. $group =& $groups_template->group; 
  1016.  
  1017. /** 
  1018. * Filters the description for the current group in the loop. 
  1019. * 
  1020. * @since 1.0.0 
  1021. * @since 2.5.0 Added the `$group` parameter. 
  1022. * 
  1023. * @param string $value Description for the current group. 
  1024. * @param object $group Group object. 
  1025. */ 
  1026. return apply_filters( 'bp_get_group_description', stripslashes( $group->description ), $group ); 
  1027.  
  1028. /** 
  1029. * Output the description for the current group in the loop, for use in a textarea. 
  1030. * 
  1031. * @since 1.0.0 
  1032. * 
  1033. * @param object|bool $group Optional. Group object. 
  1034. * Default: current group in loop. 
  1035. */ 
  1036. function bp_group_description_editable( $group = false ) { 
  1037. echo bp_get_group_description_editable( $group ); 
  1038. /** 
  1039. * Return the permalink for the current group in the loop, for use in a textarea. 
  1040. * 
  1041. * 'bp_get_group_description_editable' does not have the formatting 
  1042. * filters that 'bp_get_group_description' has, which makes it 
  1043. * appropriate for "raw" editing. 
  1044. * 
  1045. * @since 1.0.0 
  1046. * 
  1047. * @param object|bool $group Optional. Group object. 
  1048. * Default: current group in loop. 
  1049. * @return string 
  1050. */ 
  1051. function bp_get_group_description_editable( $group = false ) { 
  1052. global $groups_template; 
  1053.  
  1054. if ( empty( $group ) ) { 
  1055. $group =& $groups_template->group; 
  1056.  
  1057. /** 
  1058. * Filters the permalink for the current group in the loop, for use in a textarea. 
  1059. * 
  1060. * 'bp_get_group_description_editable' does not have the formatting filters that 
  1061. * 'bp_get_group_description' has, which makes it appropriate for "raw" editing. 
  1062. * 
  1063. * @since 1.0.0 
  1064. * @since 2.5.0 Added the `$group` parameter. 
  1065. * 
  1066. * @param string $description Description for the current group in the loop. 
  1067. * @param object $group Group object. 
  1068. */ 
  1069. return apply_filters( 'bp_get_group_description_editable', $group->description, $group ); 
  1070.  
  1071. /** 
  1072. * Output an excerpt of the group description. 
  1073. * 
  1074. * @since 1.0.0 
  1075. * 
  1076. * @param object|bool $group Optional. The group being referenced. 
  1077. * Defaults to the group currently being 
  1078. * iterated on in the groups loop. 
  1079. */ 
  1080. function bp_group_description_excerpt( $group = false ) { 
  1081. echo bp_get_group_description_excerpt( $group ); 
  1082. /** 
  1083. * Get an excerpt of a group description. 
  1084. * 
  1085. * @since 1.0.0 
  1086. * 
  1087. * @param object|bool $group Optional. The group being referenced. 
  1088. * Defaults to the group currently being 
  1089. * iterated on in the groups loop. 
  1090. * @return string Excerpt. 
  1091. */ 
  1092. function bp_get_group_description_excerpt( $group = false ) { 
  1093. global $groups_template; 
  1094.  
  1095. if ( empty( $group ) ) { 
  1096. $group =& $groups_template->group; 
  1097.  
  1098. /** 
  1099. * Filters the excerpt of a group description. 
  1100. * 
  1101. * @since 1.0.0 
  1102. * 
  1103. * @param string $value Excerpt of a group description. 
  1104. * @param object $group Object for group whose description is made into an excerpt. 
  1105. */ 
  1106. return apply_filters( 'bp_get_group_description_excerpt', bp_create_excerpt( $group->description ), $group ); 
  1107.  
  1108. /** 
  1109. * Output the status of the current group in the loop. 
  1110. * 
  1111. * Either 'Public' or 'Private'. 
  1112. * 
  1113. * @since 1.0.0 
  1114. * 
  1115. * @param object|bool $group Optional. Group object. 
  1116. * Default: current group in loop. 
  1117. */ 
  1118. function bp_group_public_status( $group = false ) { 
  1119. echo bp_get_group_public_status( $group ); 
  1120. /** 
  1121. * Return the status of the current group in the loop. 
  1122. * 
  1123. * Either 'Public' or 'Private'. 
  1124. * 
  1125. * @since 1.0.0 
  1126. * 
  1127. * @param object|bool $group Optional. Group object. 
  1128. * Default: current group in loop. 
  1129. * @return string 
  1130. */ 
  1131. function bp_get_group_public_status( $group = false ) { 
  1132. global $groups_template; 
  1133.  
  1134. if ( empty( $group ) ) { 
  1135. $group =& $groups_template->group; 
  1136.  
  1137. if ( $group->is_public ) { 
  1138. return __( 'Public', 'buddypress' ); 
  1139. } else { 
  1140. return __( 'Private', 'buddypress' ); 
  1141.  
  1142. /** 
  1143. * Output whether the current group in the loop is public. 
  1144. * 
  1145. * No longer used in BuddyPress. 
  1146. * 
  1147. * @param object|bool $group Optional. Group object. 
  1148. * Default: current group in loop. 
  1149. */ 
  1150. function bp_group_is_public( $group = false ) { 
  1151. echo bp_get_group_is_public( $group ); 
  1152. /** 
  1153. * Return whether the current group in the loop is public. 
  1154. * 
  1155. * No longer used in BuddyPress. 
  1156. * 
  1157. * @param object|bool $group Optional. Group object. 
  1158. * Default: current group in loop. 
  1159. * @return mixed 
  1160. */ 
  1161. function bp_get_group_is_public( $group = false ) { 
  1162. global $groups_template; 
  1163.  
  1164. if ( empty( $group ) ) { 
  1165. $group =& $groups_template->group; 
  1166.  
  1167. /** 
  1168. * Filters whether the current group in the loop is public. 
  1169. * 
  1170. * @since 2.5.0 Added the `$group` parameter. 
  1171. * 
  1172. * @param bool $public True if the group is public. 
  1173. * @param object $group Group object. 
  1174. */ 
  1175. return apply_filters( 'bp_get_group_is_public', $group->is_public, $group ); 
  1176.  
  1177. /** 
  1178. * Output the created date of the current group in the loop. 
  1179. * 
  1180. * @since 1.0.0 
  1181. * @since 2.7.0 Added $args as a parameter. 
  1182. * 
  1183. * @param object|bool $group Optional. Group object. Default: current group in loop. 
  1184. * @param array|string $args {@see bp_get_group_date_created()}. 
  1185. */ 
  1186. function bp_group_date_created( $group = false, $args = array() ) { 
  1187. echo bp_get_group_date_created( $group, $args ); 
  1188. /** 
  1189. * Return the created date of the current group in the loop. 
  1190. * 
  1191. * @since 1.0.0 
  1192. * @since 2.7.0 Added $args as a parameter. 
  1193. * 
  1194. * @param object|bool $group Optional. Group object. Default: current group in loop. 
  1195. * @param array|string $args { 
  1196. * Array of optional parameters. 
  1197. * 
  1198. * @type bool $relative Optional. If true, returns relative created date. eg. active 5 months ago. 
  1199. * If false, returns created date value from database. Default: true. 
  1200. * } 
  1201. * @return string 
  1202. */ 
  1203. function bp_get_group_date_created( $group = false, $args = array() ) { 
  1204. global $groups_template; 
  1205.  
  1206. $r = wp_parse_args( $args, array( 
  1207. 'relative' => true,  
  1208. ) ); 
  1209.  
  1210. if ( empty( $group ) ) { 
  1211. $group =& $groups_template->group; 
  1212.  
  1213. // We do not want relative time, so return now. 
  1214. // @todo Should the 'bp_get_group_date_created' filter be applied here? 
  1215. if ( ! $r['relative'] ) { 
  1216. return esc_attr( $group->date_created ); 
  1217.  
  1218. /** 
  1219. * Filters the created date of the current group in the loop. 
  1220. * 
  1221. * @since 1.0.0 
  1222. * @since 2.5.0 Added the `$group` parameter. 
  1223. * 
  1224. * @param string $value Created date for the current group. 
  1225. * @param object $group Group object. 
  1226. */ 
  1227. return apply_filters( 'bp_get_group_date_created', bp_core_time_since( $group->date_created ), $group ); 
  1228.  
  1229. /** 
  1230. * Output the username of the creator of the current group in the loop. 
  1231. * 
  1232. * @since 1.7.0 
  1233. * 
  1234. * @param object|bool $group Optional. Group object. 
  1235. * Default: current group in loop. 
  1236. */ 
  1237. function bp_group_creator_username( $group = false ) { 
  1238. echo bp_get_group_creator_username( $group ); 
  1239. /** 
  1240. * Return the username of the creator of the current group in the loop. 
  1241. * 
  1242. * @since 1.7.0 
  1243. * 
  1244. * @param object|bool $group Optional. Group object. 
  1245. * Default: current group in loop. 
  1246. * @return string 
  1247. */ 
  1248. function bp_get_group_creator_username( $group = false ) { 
  1249. global $groups_template; 
  1250.  
  1251. if ( empty( $group ) ) { 
  1252. $group =& $groups_template->group; 
  1253.  
  1254. /** 
  1255. * Filters the username of the creator of the current group in the loop. 
  1256. * 
  1257. * @since 1.7.0 
  1258. * @since 2.5.0 Added the `$group` parameter. 
  1259. * 
  1260. * @param string $value Username of the group creator. 
  1261. * @param object $group Group object. 
  1262. */ 
  1263. return apply_filters( 'bp_get_group_creator_username', bp_core_get_user_displayname( $group->creator_id ), $group ); 
  1264.  
  1265. /** 
  1266. * Output the user ID of the creator of the current group in the loop. 
  1267. * 
  1268. * @since 1.7.0 
  1269. * 
  1270. * @param object|bool $group Optional. Group object. 
  1271. * Default: current group in loop. 
  1272. */ 
  1273. function bp_group_creator_id( $group = false ) { 
  1274. echo bp_get_group_creator_id( $group ); 
  1275. /** 
  1276. * Return the user ID of the creator of the current group in the loop. 
  1277. * 
  1278. * @since 1.7.0 
  1279. * 
  1280. * @param object|bool $group Optional. Group object. 
  1281. * Default: current group in loop. 
  1282. * @return int 
  1283. */ 
  1284. function bp_get_group_creator_id( $group = false ) { 
  1285. global $groups_template; 
  1286.  
  1287. if ( empty( $group ) ) { 
  1288. $group =& $groups_template->group; 
  1289.  
  1290. /** 
  1291. * Filters the user ID of the creator of the current group in the loop. 
  1292. * 
  1293. * @since 1.7.0 
  1294. * @since 2.5.0 Added the `$group` parameter. 
  1295. * 
  1296. * @param int $creator_id User ID of the group creator. 
  1297. * @param object $group Group object. 
  1298. */ 
  1299. return apply_filters( 'bp_get_group_creator_id', $group->creator_id, $group ); 
  1300.  
  1301. /** 
  1302. * Output the permalink of the creator of the current group in the loop. 
  1303. * 
  1304. * @since 1.7.0 
  1305. * 
  1306. * @param object|bool $group Optional. Group object. 
  1307. * Default: current group in loop. 
  1308. */ 
  1309. function bp_group_creator_permalink( $group = false ) { 
  1310. echo bp_get_group_creator_permalink( $group ); 
  1311. /** 
  1312. * Return the permalink of the creator of the current group in the loop. 
  1313. * 
  1314. * @since 1.7.0 
  1315. * 
  1316. * @param object|bool $group Optional. Group object. 
  1317. * Default: current group in loop. 
  1318. * @return string 
  1319. */ 
  1320. function bp_get_group_creator_permalink( $group = false ) { 
  1321. global $groups_template; 
  1322.  
  1323. if ( empty( $group ) ) { 
  1324. $group =& $groups_template->group; 
  1325.  
  1326. /** 
  1327. * Filters the permalink of the creator of the current group in the loop. 
  1328. * 
  1329. * @since 1.7.0 
  1330. * @since 2.5.0 Added the `$group` parameter. 
  1331. * 
  1332. * @param string $value Permalink of the group creator. 
  1333. * @param object $group Group object. 
  1334. */ 
  1335. return apply_filters( 'bp_get_group_creator_permalink', bp_core_get_user_domain( $group->creator_id ), $group ); 
  1336.  
  1337. /** 
  1338. * Determine whether a user is the creator of the current group in the loop. 
  1339. * 
  1340. * @since 1.7.0 
  1341. * 
  1342. * @param BP_Groups_Group $group Optional. Group object. Default: current group in loop. 
  1343. * @param int $user_id ID of the user. 
  1344. * @return bool 
  1345. */ 
  1346. function bp_is_group_creator( $group = null, $user_id = 0 ) { 
  1347. global $groups_template; 
  1348.  
  1349. if ( empty( $group ) ) { 
  1350. $group =& $groups_template->group; 
  1351.  
  1352. if ( empty( $user_id ) ) { 
  1353. $user_id = bp_loggedin_user_id(); 
  1354.  
  1355. return (bool) ( $group->creator_id == $user_id ); 
  1356.  
  1357. /** 
  1358. * Output the avatar of the creator of the current group in the loop. 
  1359. * 
  1360. * @since 1.7.0 
  1361. * 
  1362. * @param object|bool $group Optional. Group object. 
  1363. * Default: current group in loop. 
  1364. * @param array $args { 
  1365. * Array of optional arguments. See {@link bp_get_group_creator_avatar()} 
  1366. * for description. 
  1367. * } 
  1368. */ 
  1369. function bp_group_creator_avatar( $group = false, $args = array() ) { 
  1370. echo bp_get_group_creator_avatar( $group, $args ); 
  1371. /** 
  1372. * Return the avatar of the creator of the current group in the loop. 
  1373. * 
  1374. * @since 1.7.0 
  1375. * 
  1376. * @param object|bool $group Optional. Group object. 
  1377. * Default: current group in loop. 
  1378. * @param array $args { 
  1379. * Array of optional arguments. See {@link bp_core_fetch_avatar()} 
  1380. * for detailed description of arguments. 
  1381. * @type string $type Default: 'full'. 
  1382. * @type int $width Default: false. 
  1383. * @type int $height Default: false. 
  1384. * @type int $class Default: 'avatar'. 
  1385. * @type string $id Passed to 'css_id'. Default: false. 
  1386. * @type string $alt Alt text. Default: 'Group creator profile 
  1387. * photo of [user display name]'. 
  1388. * } 
  1389. * @return string 
  1390. */ 
  1391. function bp_get_group_creator_avatar( $group = false, $args = array() ) { 
  1392. global $groups_template; 
  1393.  
  1394. if ( empty( $group ) ) { 
  1395. $group =& $groups_template->group; 
  1396.  
  1397. $defaults = array( 
  1398. 'type' => 'full',  
  1399. 'width' => false,  
  1400. 'height' => false,  
  1401. 'class' => 'avatar',  
  1402. 'id' => false,  
  1403. 'alt' => sprintf( __( 'Group creator profile photo of %s', 'buddypress' ), bp_core_get_user_displayname( $group->creator_id ) ) 
  1404. ); 
  1405.  
  1406. $r = wp_parse_args( $args, $defaults ); 
  1407. extract( $r, EXTR_SKIP ); 
  1408.  
  1409. $avatar = bp_core_fetch_avatar( array( 'item_id' => $group->creator_id, 'type' => $type, 'css_id' => $id, 'class' => $class, 'width' => $width, 'height' => $height, 'alt' => $alt ) ); 
  1410.  
  1411. /** 
  1412. * Filters the avatar of the creator of the current group in the loop. 
  1413. * 
  1414. * @since 1.7.0 
  1415. * @since 2.5.0 Added the `$group` parameter. 
  1416. * 
  1417. * @param string $avatar Avatar of the group creator. 
  1418. * @param object $group Group object. 
  1419. */ 
  1420. return apply_filters( 'bp_get_group_creator_avatar', $avatar, $group ); 
  1421.  
  1422. /** 
  1423. * Determine whether the current user is the admin of the current group. 
  1424. * 
  1425. * Alias of {@link bp_is_item_admin()}. 
  1426. * 
  1427. * @since 1.1.0 
  1428. * 
  1429. * @return bool 
  1430. */ 
  1431. function bp_group_is_admin() { 
  1432. return bp_is_item_admin(); 
  1433.  
  1434. /** 
  1435. * Determine whether the current user is a mod of the current group. 
  1436. * 
  1437. * Alias of {@link bp_is_item_mod()}. 
  1438. * 
  1439. * @since 1.1.0 
  1440. * 
  1441. * @return bool 
  1442. */ 
  1443. function bp_group_is_mod() { 
  1444. return bp_is_item_mod(); 
  1445.  
  1446. /** 
  1447. * Output markup listing group admins. 
  1448. * 
  1449. * @since 1.0.0 
  1450. * 
  1451. * @param object|bool $group Optional. Group object. 
  1452. * Default: current group in loop. 
  1453. */ 
  1454. function bp_group_list_admins( $group = false ) { 
  1455. global $groups_template; 
  1456.  
  1457. if ( empty( $group ) ) { 
  1458. $group =& $groups_template->group; 
  1459.  
  1460. if ( ! empty( $group->admins ) ) { ?> 
  1461. <ul id="group-admins"> 
  1462. <?php foreach( (array) $group->admins as $admin ) { ?> 
  1463. <li> 
  1464. <a href="<?php echo bp_core_get_user_domain( $admin->user_id, $admin->user_nicename, $admin->user_login ) ?>"><?php echo bp_core_fetch_avatar( array( 'item_id' => $admin->user_id, 'email' => $admin->user_email, 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_core_get_user_displayname( $admin->user_id ) ) ) ) ?></a> 
  1465. </li> 
  1466. <?php } ?> 
  1467. </ul> 
  1468. <?php } else { ?> 
  1469. <span class="activity"><?php _e( 'No Admins', 'buddypress' ) ?></span> 
  1470. <?php } ?> 
  1471. <?php 
  1472.  
  1473. /** 
  1474. * Output markup listing group mod. 
  1475. * 
  1476. * @since 1.0.0 
  1477. * 
  1478. * @param object|bool $group Optional. Group object. 
  1479. * Default: current group in loop. 
  1480. */ 
  1481. function bp_group_list_mods( $group = false ) { 
  1482. global $groups_template; 
  1483.  
  1484. if ( empty( $group ) ) { 
  1485. $group =& $groups_template->group; 
  1486.  
  1487. if ( ! empty( $group->mods ) ) : ?> 
  1488.  
  1489. <ul id="group-mods"> 
  1490.  
  1491. <?php foreach( (array) $group->mods as $mod ) { ?> 
  1492.  
  1493. <li> 
  1494. <a href="<?php echo bp_core_get_user_domain( $mod->user_id, $mod->user_nicename, $mod->user_login ) ?>"><?php echo bp_core_fetch_avatar( array( 'item_id' => $mod->user_id, 'email' => $mod->user_email, 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_core_get_user_displayname( $mod->user_id ) ) ) ) ?></a> 
  1495. </li> 
  1496.  
  1497. <?php } ?> 
  1498.  
  1499. </ul> 
  1500.  
  1501. <?php else : ?> 
  1502.  
  1503. <span class="activity"><?php _e( 'No Mods', 'buddypress' ) ?></span> 
  1504.  
  1505. <?php endif; 
  1506.  
  1507.  
  1508. /** 
  1509. * Return a list of user IDs for a group's admins. 
  1510. * 
  1511. * @since 1.5.0 
  1512. * 
  1513. * @param BP_Groups_Group|bool $group Optional. The group being queried. Defaults 
  1514. * to the current group in the loop. 
  1515. * @param string $format Optional. 'string' to get a comma-separated string,  
  1516. * 'array' to get an array. 
  1517. * @return mixed $admin_ids A string or array of user IDs. 
  1518. */ 
  1519. function bp_group_admin_ids( $group = false, $format = 'string' ) { 
  1520. global $groups_template; 
  1521.  
  1522. if ( empty( $group ) ) { 
  1523. $group =& $groups_template->group; 
  1524.  
  1525. $admin_ids = array(); 
  1526.  
  1527. if ( $group->admins ) { 
  1528. foreach( $group->admins as $admin ) { 
  1529. $admin_ids[] = $admin->user_id; 
  1530.  
  1531. if ( 'string' == $format ) { 
  1532. $admin_ids = implode( ', ', $admin_ids ); 
  1533.  
  1534. /** 
  1535. * Filters a list of user IDs for a group's admins. 
  1536. * 
  1537. * This filter may return either an array or a comma separated string. 
  1538. * 
  1539. * @since 1.5.0 
  1540. * @since 2.5.0 Added the `$group` parameter. 
  1541. * 
  1542. * @param array|string $admin_ids List of user IDs for a group's admins. 
  1543. * @param object $group Group object. 
  1544. */ 
  1545. return apply_filters( 'bp_group_admin_ids', $admin_ids, $group ); 
  1546.  
  1547. /** 
  1548. * Return a list of user IDs for a group's moderators. 
  1549. * 
  1550. * @since 1.5.0 
  1551. * 
  1552. * @param BP_Groups_Group|bool $group Optional. The group being queried. 
  1553. * Defaults to the current group in the loop. 
  1554. * @param string $format Optional. 'string' to get a comma-separated string,  
  1555. * 'array' to get an array. 
  1556. * @return mixed $mod_ids A string or array of user IDs. 
  1557. */ 
  1558. function bp_group_mod_ids( $group = false, $format = 'string' ) { 
  1559. global $groups_template; 
  1560.  
  1561. if ( empty( $group ) ) { 
  1562. $group =& $groups_template->group; 
  1563.  
  1564. $mod_ids = array(); 
  1565.  
  1566. if ( $group->mods ) { 
  1567. foreach( $group->mods as $mod ) { 
  1568. $mod_ids[] = $mod->user_id; 
  1569.  
  1570. if ( 'string' == $format ) { 
  1571. $mod_ids = implode( ', ', $mod_ids ); 
  1572.  
  1573. /** 
  1574. * Filters a list of user IDs for a group's moderators. 
  1575. * 
  1576. * This filter may return either an array or a comma separated string. 
  1577. * 
  1578. * @since 1.5.0 
  1579. * @since 2.5.0 Added the `$group` parameter. 
  1580. * 
  1581. * @param array|string $admin_ids List of user IDs for a group's moderators. 
  1582. * @param object $group Group object. 
  1583. */ 
  1584. return apply_filters( 'bp_group_mod_ids', $mod_ids, $group ); 
  1585.  
  1586. /** 
  1587. * Output the permalink of the current group's Members page. 
  1588. * 
  1589. * @since 1.0.0 
  1590. */ 
  1591. function bp_group_all_members_permalink() { 
  1592. echo bp_get_group_all_members_permalink(); 
  1593. /** 
  1594. * Return the permalink of the Members page of the current group in the loop. 
  1595. * 
  1596. * @since 1.0.0 
  1597. * 
  1598. * @param object|bool $group Optional. Group object. 
  1599. * Default: current group in loop. 
  1600. * @return string 
  1601. */ 
  1602. function bp_get_group_all_members_permalink( $group = false ) { 
  1603. global $groups_template; 
  1604.  
  1605. if ( empty( $group ) ) { 
  1606. $group =& $groups_template->group; 
  1607.  
  1608. /** 
  1609. * Filters the permalink of the Members page for the current group in the loop. 
  1610. * 
  1611. * @since 1.0.0 
  1612. * @since 2.5.0 Added the `$group` parameter. 
  1613. * 
  1614. * @param string $value Permalink of the Members page for the current group. 
  1615. * @param object $group Group object. 
  1616. */ 
  1617. return apply_filters( 'bp_get_group_all_members_permalink', bp_get_group_permalink( $group ) . 'members', $group ); 
  1618.  
  1619. /** 
  1620. * Display a Groups search form. 
  1621. * 
  1622. * No longer used in BuddyPress. 
  1623. * 
  1624. * @todo Deprecate. 
  1625. */ 
  1626. function bp_group_search_form() { 
  1627.  
  1628. $action = bp_displayed_user_domain() . bp_get_groups_slug() . '/my-groups/search/'; 
  1629. $label = __('Filter Groups', 'buddypress'); 
  1630. $name = 'group-filter-box'; 
  1631.  
  1632. $search_form_html = '<form action="' . $action . '" id="group-search-form" method="post"> 
  1633. <label for="'. $name .'" id="'. $name .'-label">'. $label .'</label> 
  1634. <input type="search" name="'. $name . '" id="'. $name .'" value="'. $value .'"'. $disabled .' /> 
  1635.  
  1636. '. wp_nonce_field( 'group-filter-box', '_wpnonce_group_filter', true, false ) .' 
  1637. </form>'; 
  1638.  
  1639. echo apply_filters( 'bp_group_search_form', $search_form_html ); 
  1640.  
  1641. /** 
  1642. * Determine whether the displayed user has no groups. 
  1643. * 
  1644. * No longer used in BuddyPress. 
  1645. * 
  1646. * @todo Deprecate. 
  1647. * 
  1648. * @return bool True if the displayed user has no groups, otherwise false. 
  1649. */ 
  1650. function bp_group_show_no_groups_message() { 
  1651. if ( !groups_total_groups_for_user( bp_displayed_user_id() ) ) { 
  1652. return true; 
  1653.  
  1654. return false; 
  1655.  
  1656. /** 
  1657. * Determine whether the current page is a group activity permalink. 
  1658. * 
  1659. * No longer used in BuddyPress. 
  1660. * 
  1661. * @todo Deprecate. 
  1662. * 
  1663. * @return bool True if this is a group activity permalink, otherwise false. 
  1664. */ 
  1665. function bp_group_is_activity_permalink() { 
  1666.  
  1667. if ( !bp_is_single_item() || !bp_is_groups_component() || !bp_is_current_action( bp_get_activity_slug() ) ) { 
  1668. return false; 
  1669.  
  1670. return true; 
  1671.  
  1672. /** 
  1673. * Output the pagination HTML for a group loop. 
  1674. * 
  1675. * @since 1.2.0 
  1676. */ 
  1677. function bp_groups_pagination_links() { 
  1678. echo bp_get_groups_pagination_links(); 
  1679. /** 
  1680. * Get the pagination HTML for a group loop. 
  1681. * 
  1682. * @since 1.2.0 
  1683. * 
  1684. * @return string 
  1685. */ 
  1686. function bp_get_groups_pagination_links() { 
  1687. global $groups_template; 
  1688.  
  1689. /** 
  1690. * Filters the pagination HTML for a group loop. 
  1691. * 
  1692. * @since 1.2.0 
  1693. * 
  1694. * @param string $pag_links HTML markup for the pagination links. 
  1695. */ 
  1696. return apply_filters( 'bp_get_groups_pagination_links', $groups_template->pag_links ); 
  1697.  
  1698. /** 
  1699. * Output the "Viewing x-y of z groups" pagination message. 
  1700. * 
  1701. * @since 1.2.0 
  1702. */ 
  1703. function bp_groups_pagination_count() { 
  1704. echo bp_get_groups_pagination_count(); 
  1705. /** 
  1706. * Generate the "Viewing x-y of z groups" pagination message. 
  1707. * 
  1708. * @since 1.5.0 
  1709. * 
  1710. * @return string 
  1711. */ 
  1712. function bp_get_groups_pagination_count() { 
  1713. global $groups_template; 
  1714.  
  1715. $start_num = intval( ( $groups_template->pag_page - 1 ) * $groups_template->pag_num ) + 1; 
  1716. $from_num = bp_core_number_format( $start_num ); 
  1717. $to_num = bp_core_number_format( ( $start_num + ( $groups_template->pag_num - 1 ) > $groups_template->total_group_count ) ? $groups_template->total_group_count : $start_num + ( $groups_template->pag_num - 1 ) ); 
  1718. $total = bp_core_number_format( $groups_template->total_group_count ); 
  1719.  
  1720. if ( 1 == $groups_template->total_group_count ) { 
  1721. $message = __( 'Viewing 1 group', 'buddypress' ); 
  1722. } else { 
  1723. $message = sprintf( _n( 'Viewing %1$s - %2$s of %3$s group', 'Viewing %1$s - %2$s of %3$s groups', $groups_template->total_group_count, 'buddypress' ), $from_num, $to_num, $total ); 
  1724.  
  1725. /** 
  1726. * Filters the "Viewing x-y of z groups" pagination message. 
  1727. * 
  1728. * @since 1.5.0 
  1729. * 
  1730. * @param string $message "Viewing x-y of z groups" text. 
  1731. * @param string $from_num Total amount for the low value in the range. 
  1732. * @param string $to_num Total amount for the high value in the range. 
  1733. * @param string $total Total amount of groups found. 
  1734. */ 
  1735. return apply_filters( 'bp_get_groups_pagination_count', $message, $from_num, $to_num, $total ); 
  1736.  
  1737. /** 
  1738. * Determine whether groups auto-join is enabled. 
  1739. * 
  1740. * "Auto-join" is the toggle that determines whether users are joined to a 
  1741. * public group automatically when creating content in that group. 
  1742. * 
  1743. * @since 1.2.6 
  1744. * 
  1745. * @return bool 
  1746. */ 
  1747. function bp_groups_auto_join() { 
  1748.  
  1749. /** 
  1750. * Filters whether groups auto-join is enabled. 
  1751. * 
  1752. * @since 1.2.6 
  1753. * 
  1754. * @param bool $value Enabled status. 
  1755. */ 
  1756. return apply_filters( 'bp_groups_auto_join', (bool) buddypress()->groups->auto_join ); 
  1757.  
  1758. /** 
  1759. * Output the total member count for a group. 
  1760. * 
  1761. * @since 1.0.0 
  1762. * 
  1763. * @param object|bool $group Optional. Group object. Default: current group in loop. 
  1764. */ 
  1765. function bp_group_total_members( $group = false ) { 
  1766. echo bp_get_group_total_members( $group ); 
  1767. /** 
  1768. * Get the total member count for a group. 
  1769. * 
  1770. * @since 1.0.0 
  1771. * 
  1772. * @param object|bool $group Optional. Group object. 
  1773. * Default: current group in loop. 
  1774. * @return int 
  1775. */ 
  1776. function bp_get_group_total_members( $group = false ) { 
  1777. global $groups_template; 
  1778.  
  1779. if ( empty( $group ) ) { 
  1780. $group =& $groups_template->group; 
  1781.  
  1782. /** 
  1783. * Filters the total member count for a group. 
  1784. * 
  1785. * @since 1.0.0 
  1786. * @since 2.5.0 Added the `$group` parameter. 
  1787. * 
  1788. * @param int $total_member_count Total member count for a group. 
  1789. * @param object $group Group object. 
  1790. */ 
  1791. return apply_filters( 'bp_get_group_total_members', $group->total_member_count, $group ); 
  1792.  
  1793. /** 
  1794. * Output the "x members" count string for a group. 
  1795. * 
  1796. * @since 1.2.0 
  1797. */ 
  1798. function bp_group_member_count() { 
  1799. echo bp_get_group_member_count(); 
  1800. /** 
  1801. * Generate the "x members" count string for a group. 
  1802. * 
  1803. * @since 1.2.0 
  1804. * 
  1805. * @return string 
  1806. */ 
  1807. function bp_get_group_member_count() { 
  1808. global $groups_template; 
  1809.  
  1810. if ( isset( $groups_template->group->total_member_count ) ) { 
  1811. $count = (int) $groups_template->group->total_member_count; 
  1812. } else { 
  1813. $count = 0; 
  1814.  
  1815. $count_string = sprintf( _n( '%s member', '%s members', $count, 'buddypress' ), bp_core_number_format( $count ) ); 
  1816.  
  1817. /** 
  1818. * Filters the "x members" count string for a group. 
  1819. * 
  1820. * @since 1.2.0 
  1821. * 
  1822. * @param string $count_string The "x members" count string for a group. 
  1823. */ 
  1824. return apply_filters( 'bp_get_group_member_count', $count_string ); 
  1825.  
  1826. /** 
  1827. * Output the URL of the Forum page of the current group in the loop. 
  1828. * 
  1829. * @since 1.0.0 
  1830. */ 
  1831. function bp_group_forum_permalink() { 
  1832. echo bp_get_group_forum_permalink(); 
  1833. /** 
  1834. * Generate the URL of the Forum page of a group. 
  1835. * 
  1836. * @since 1.0.0 
  1837. * 
  1838. * @param object|bool $group Optional. Group object. 
  1839. * Default: current group in loop. 
  1840. * @return string 
  1841. */ 
  1842. function bp_get_group_forum_permalink( $group = false ) { 
  1843. global $groups_template; 
  1844.  
  1845. if ( empty( $group ) ) { 
  1846. $group =& $groups_template->group; 
  1847.  
  1848. /** 
  1849. * Filters the URL of the Forum page of a group. 
  1850. * 
  1851. * @since 1.0.0 
  1852. * @since 2.5.0 Added the `$group` parameter. 
  1853. * 
  1854. * @param string $value URL permalink for the Forum Page. 
  1855. * @param object $group Group object. 
  1856. */ 
  1857. return apply_filters( 'bp_get_group_forum_permalink', bp_get_group_permalink( $group ) . 'forum', $group ); 
  1858.  
  1859. /** 
  1860. * Output the topic count for a group forum. 
  1861. * 
  1862. * @since 1.2.0 
  1863. * 
  1864. * @param array|string $args See {@link bp_get_group_forum_topic_count()}. 
  1865. */ 
  1866. function bp_group_forum_topic_count( $args = '' ) { 
  1867. echo bp_get_group_forum_topic_count( $args ); 
  1868. /** 
  1869. * Generate the topic count string for a group forum. 
  1870. * 
  1871. * @since 1.2.0 
  1872. * 
  1873. * @param array|string $args { 
  1874. * Array of arguments. 
  1875. * @type bool $showtext Optional. If true, result will be formatted as "x topics". 
  1876. * If false, just a number will be returned. 
  1877. * Default: false. 
  1878. * } 
  1879. * @return string|int 
  1880. */ 
  1881. function bp_get_group_forum_topic_count( $args = '' ) { 
  1882. global $groups_template; 
  1883.  
  1884. $defaults = array( 
  1885. 'showtext' => false 
  1886. ); 
  1887.  
  1888. $r = wp_parse_args( $args, $defaults ); 
  1889. extract( $r, EXTR_SKIP ); 
  1890.  
  1891. if ( !$forum_id = groups_get_groupmeta( $groups_template->group->id, 'forum_id' ) ) { 
  1892. return false; 
  1893.  
  1894. if ( !bp_is_active( 'forums' ) ) { 
  1895. return false; 
  1896.  
  1897. if ( !$groups_template->group->forum_counts ) { 
  1898. $groups_template->group->forum_counts = bp_forums_get_forum_topicpost_count( (int) $forum_id ); 
  1899.  
  1900. if ( (bool) $showtext ) { 
  1901. if ( 1 == (int) $groups_template->group->forum_counts[0]->topics ) { 
  1902. $total_topics = sprintf( __( '%d topic', 'buddypress' ), (int) $groups_template->group->forum_counts[0]->topics ); 
  1903. } else { 
  1904. $total_topics = sprintf( __( '%d topics', 'buddypress' ), (int) $groups_template->group->forum_counts[0]->topics ); 
  1905. } else { 
  1906. $total_topics = (int) $groups_template->group->forum_counts[0]->topics; 
  1907.  
  1908. /** 
  1909. * Filters the topic count string for a group forum. 
  1910. * 
  1911. * @since 1.2.0 
  1912. * 
  1913. * @param string $total_topics Total topic count string. 
  1914. * @param bool $showtext Whether or not to return as formatted string. 
  1915. */ 
  1916. return apply_filters( 'bp_get_group_forum_topic_count', $total_topics, (bool)$showtext ); 
  1917.  
  1918. /** 
  1919. * Output the post count for a group forum. 
  1920. * 
  1921. * @since 1.2.0 
  1922. * 
  1923. * @param array|string $args See {@link bp_get_group_forum_post_count()}. 
  1924. */ 
  1925. function bp_group_forum_post_count( $args = '' ) { 
  1926. echo bp_get_group_forum_post_count( $args ); 
  1927. /** 
  1928. * Generate the post count string for a group forum. 
  1929. * 
  1930. * @since 1.2.0 
  1931. * 
  1932. * @param array|string $args { 
  1933. * Array of arguments. 
  1934. * @type bool $showtext Optional. If true, result will be formatted as "x posts". 
  1935. * If false, just a number will be returned. 
  1936. * Default: false. 
  1937. * } 
  1938. * @return string|int 
  1939. */ 
  1940. function bp_get_group_forum_post_count( $args = '' ) { 
  1941. global $groups_template; 
  1942.  
  1943. $defaults = array( 
  1944. 'showtext' => false 
  1945. ); 
  1946.  
  1947. $r = wp_parse_args( $args, $defaults ); 
  1948. extract( $r, EXTR_SKIP ); 
  1949.  
  1950. if ( !$forum_id = groups_get_groupmeta( $groups_template->group->id, 'forum_id' ) ) { 
  1951. return false; 
  1952.  
  1953. if ( !bp_is_active( 'forums' ) ) { 
  1954. return false; 
  1955.  
  1956. if ( !$groups_template->group->forum_counts ) { 
  1957. $groups_template->group->forum_counts = bp_forums_get_forum_topicpost_count( (int) $forum_id ); 
  1958.  
  1959. if ( (bool) $showtext ) { 
  1960. if ( 1 == (int) $groups_template->group->forum_counts[0]->posts ) { 
  1961. $total_posts = sprintf( __( '%d post', 'buddypress' ), (int) $groups_template->group->forum_counts[0]->posts ); 
  1962. } else { 
  1963. $total_posts = sprintf( __( '%d posts', 'buddypress' ), (int) $groups_template->group->forum_counts[0]->posts ); 
  1964. } else { 
  1965. $total_posts = (int) $groups_template->group->forum_counts[0]->posts; 
  1966.  
  1967. /** 
  1968. * Filters the post count string for a group forum. 
  1969. * 
  1970. * @since 1.2.0 
  1971. * 
  1972. * @param string $total_posts Total post count string. 
  1973. * @param bool $showtext Whether or not to return as formatted string. 
  1974. */ 
  1975. return apply_filters( 'bp_get_group_forum_post_count', $total_posts, (bool)$showtext ); 
  1976.  
  1977. /** 
  1978. * Determine whether forums are enabled for a group. 
  1979. * 
  1980. * @since 1.0.0 
  1981. * 
  1982. * @param object|bool $group Optional. Group object. Default: current group in loop. 
  1983. * @return bool 
  1984. */ 
  1985. function bp_group_is_forum_enabled( $group = false ) { 
  1986. global $groups_template; 
  1987.  
  1988. if ( empty( $group ) ) { 
  1989. $group =& $groups_template->group; 
  1990.  
  1991. if ( ! empty( $group->enable_forum ) ) { 
  1992. return true; 
  1993.  
  1994. return false; 
  1995.  
  1996. /** 
  1997. * Output the 'checked' attribute for the group forums settings UI. 
  1998. * 
  1999. * @since 1.0.0 
  2000. * 
  2001. * @param object|bool $group Optional. Group object. Default: current group in loop. 
  2002. */ 
  2003. function bp_group_show_forum_setting( $group = false ) { 
  2004. global $groups_template; 
  2005.  
  2006. if ( empty( $group ) ) { 
  2007. $group =& $groups_template->group; 
  2008.  
  2009. if ( $group->enable_forum ) { 
  2010. echo ' checked="checked"'; 
  2011.  
  2012. /** 
  2013. * Output the 'checked' attribute for a given status in the settings UI. 
  2014. * 
  2015. * @since 1.0.0 
  2016. * 
  2017. * @param string $setting Group status. 'public', 'private', 'hidden'. 
  2018. * @param object|bool $group Optional. Group object. Default: current group in loop. 
  2019. */ 
  2020. function bp_group_show_status_setting( $setting, $group = false ) { 
  2021. global $groups_template; 
  2022.  
  2023. if ( empty( $group ) ) { 
  2024. $group =& $groups_template->group; 
  2025.  
  2026. if ( $setting == $group->status ) { 
  2027. echo ' checked="checked"'; 
  2028.  
  2029. /** 
  2030. * Output the 'checked' value, if needed, for a given invite_status on the group create/admin screens 
  2031. * 
  2032. * @since 1.5.0 
  2033. * 
  2034. * @param string $setting The setting you want to check against ('members',  
  2035. * 'mods', or 'admins'). 
  2036. * @param object|bool $group Optional. Group object. Default: current group in loop. 
  2037. */ 
  2038. function bp_group_show_invite_status_setting( $setting, $group = false ) { 
  2039. $group_id = isset( $group->id ) ? $group->id : false; 
  2040.  
  2041. $invite_status = bp_group_get_invite_status( $group_id ); 
  2042.  
  2043. if ( $setting == $invite_status ) { 
  2044. echo ' checked="checked"'; 
  2045.  
  2046. /** 
  2047. * Get the invite status of a group. 
  2048. * 
  2049. * 'invite_status' became part of BuddyPress in BP 1.5. In order to provide 
  2050. * backward compatibility with earlier installations, groups without a status 
  2051. * set will default to 'members', ie all members in a group can send 
  2052. * invitations. Filter 'bp_group_invite_status_fallback' to change this 
  2053. * fallback behavior. 
  2054. * 
  2055. * This function can be used either in or out of the loop. 
  2056. * 
  2057. * @since 1.5.0 
  2058. * 
  2059. * @param int|bool $group_id Optional. The ID of the group whose status you want to 
  2060. * check. Default: the displayed group, or the current group 
  2061. * in the loop. 
  2062. * @return bool|string Returns false when no group can be found. Otherwise 
  2063. * returns the group invite status, from among 'members',  
  2064. * 'mods', and 'admins'. 
  2065. */ 
  2066. function bp_group_get_invite_status( $group_id = false ) { 
  2067. global $groups_template; 
  2068.  
  2069. if ( !$group_id ) { 
  2070. $bp = buddypress(); 
  2071.  
  2072. if ( isset( $bp->groups->current_group->id ) ) { 
  2073. // Default to the current group first. 
  2074. $group_id = $bp->groups->current_group->id; 
  2075. } elseif ( isset( $groups_template->group->id ) ) { 
  2076. // Then see if we're in the loop. 
  2077. $group_id = $groups_template->group->id; 
  2078. } else { 
  2079. return false; 
  2080.  
  2081. $invite_status = groups_get_groupmeta( $group_id, 'invite_status' ); 
  2082.  
  2083. // Backward compatibility. When 'invite_status' is not set, fall back to a default value. 
  2084. if ( !$invite_status ) { 
  2085. $invite_status = apply_filters( 'bp_group_invite_status_fallback', 'members' ); 
  2086.  
  2087. /** 
  2088. * Filters the invite status of a group. 
  2089. * 
  2090. * Invite status in this case means who from the group can send invites. 
  2091. * 
  2092. * @since 1.5.0 
  2093. * 
  2094. * @param string $invite_status Membership level needed to send an invite. 
  2095. * @param int $group_id ID of the group whose status is being checked. 
  2096. */ 
  2097. return apply_filters( 'bp_group_get_invite_status', $invite_status, $group_id ); 
  2098.  
  2099. /** 
  2100. * Can a user send invitations in the specified group? 
  2101. * 
  2102. * @since 1.5.0 
  2103. * @since 2.2.0 Added the $user_id parameter. 
  2104. * 
  2105. * @param int $group_id The group ID to check. 
  2106. * @param int $user_id The user ID to check. 
  2107. * @return bool 
  2108. */ 
  2109. function bp_groups_user_can_send_invites( $group_id = 0, $user_id = 0 ) { 
  2110. $can_send_invites = false; 
  2111. $invite_status = false; 
  2112.  
  2113. // If $user_id isn't specified, we check against the logged-in user. 
  2114. if ( ! $user_id ) { 
  2115. $user_id = bp_loggedin_user_id(); 
  2116.  
  2117. // If $group_id isn't specified, use existing one if available. 
  2118. if ( ! $group_id ) { 
  2119. $group_id = bp_get_current_group_id(); 
  2120.  
  2121. if ( $user_id ) { 
  2122. // Users with the 'bp_moderate' cap can always send invitations. 
  2123. if ( user_can( $user_id, 'bp_moderate' ) ) { 
  2124. $can_send_invites = true; 
  2125. } else { 
  2126. $invite_status = bp_group_get_invite_status( $group_id ); 
  2127.  
  2128. switch ( $invite_status ) { 
  2129. case 'admins' : 
  2130. if ( groups_is_user_admin( $user_id, $group_id ) ) { 
  2131. $can_send_invites = true; 
  2132. break; 
  2133.  
  2134. case 'mods' : 
  2135. if ( groups_is_user_mod( $user_id, $group_id ) || groups_is_user_admin( $user_id, $group_id ) ) { 
  2136. $can_send_invites = true; 
  2137. break; 
  2138.  
  2139. case 'members' : 
  2140. if ( groups_is_user_member( $user_id, $group_id ) ) { 
  2141. $can_send_invites = true; 
  2142. break; 
  2143.  
  2144. /** 
  2145. * Filters whether a user can send invites in a group. 
  2146. * 
  2147. * @since 1.5.0 
  2148. * @since 2.2.0 Added the $user_id parameter. 
  2149. * 
  2150. * @param bool $can_send_invites Whether the user can send invites 
  2151. * @param int $group_id The group ID being checked 
  2152. * @param bool $invite_status The group's current invite status 
  2153. * @param int $user_id The user ID being checked 
  2154. */ 
  2155. return apply_filters( 'bp_groups_user_can_send_invites', $can_send_invites, $group_id, $invite_status, $user_id ); 
  2156.  
  2157. /** 
  2158. * Since BuddyPress 1.0, this generated the group settings admin/member screen. 
  2159. * As of BuddyPress 1.5 (r4489), and because this function outputs HTML, it was moved into /bp-default/groups/single/admin.php. 
  2160. * 
  2161. * @deprecated 1.5 
  2162. * @deprecated No longer used. 
  2163. * @since 1.0.0 
  2164. * @todo Remove in 1.4 
  2165. * 
  2166. * @param bool $admin_list 
  2167. * @param bool $group 
  2168. */ 
  2169. function bp_group_admin_memberlist( $admin_list = false, $group = false ) { 
  2170. global $groups_template; 
  2171.  
  2172. _deprecated_function( __FUNCTION__, '1.5', 'No longer used. See /bp-default/groups/single/admin.php' ); 
  2173.  
  2174. if ( empty( $group ) ) { 
  2175. $group =& $groups_template->group; 
  2176.  
  2177.  
  2178. if ( $admins = groups_get_group_admins( $group->id ) ) : ?> 
  2179.  
  2180. <ul id="admins-list" class="item-list<?php if ( !empty( $admin_list ) ) : ?> single-line<?php endif; ?>"> 
  2181.  
  2182. <?php foreach ( (array) $admins as $admin ) { ?> 
  2183.  
  2184. <?php if ( !empty( $admin_list ) ) : ?> 
  2185.  
  2186. <li> 
  2187.  
  2188. <?php echo bp_core_fetch_avatar( array( 'item_id' => $admin->user_id, 'type' => 'thumb', 'width' => 30, 'height' => 30, 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_core_get_user_displayname( $admin->user_id ) ) ) ) ?> 
  2189.  
  2190. <h5> 
  2191.  
  2192. <?php echo bp_core_get_userlink( $admin->user_id ); ?> 
  2193.  
  2194. <span class="small"> 
  2195. <a class="button confirm admin-demote-to-member" href="<?php bp_group_member_demote_link($admin->user_id) ?>"><?php _e( 'Demote to Member', 'buddypress' ) ?></a> 
  2196. </span> 
  2197. </h5> 
  2198. </li> 
  2199.  
  2200. <?php else : ?> 
  2201.  
  2202. <li> 
  2203.  
  2204. <?php echo bp_core_fetch_avatar( array( 'item_id' => $admin->user_id, 'type' => 'thumb', 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_core_get_user_displayname( $admin->user_id ) ) ) ) ?> 
  2205.  
  2206. <h5><?php echo bp_core_get_userlink( $admin->user_id ) ?></h5> 
  2207. <span class="activity"> 
  2208. <?php echo bp_core_get_last_activity( strtotime( $admin->date_modified ), __( 'joined %s', 'buddypress') ); ?> 
  2209. </span> 
  2210.  
  2211. <?php if ( bp_is_active( 'friends' ) ) : ?> 
  2212.  
  2213. <div class="action"> 
  2214.  
  2215. <?php bp_add_friend_button( $admin->user_id ); ?> 
  2216.  
  2217. </div> 
  2218.  
  2219. <?php endif; ?> 
  2220.  
  2221. </li> 
  2222.  
  2223. <?php endif; 
  2224. } ?> 
  2225.  
  2226. </ul> 
  2227.  
  2228. <?php else : ?> 
  2229.  
  2230. <div id="message" class="info"> 
  2231. <p><?php _e( 'This group has no administrators', 'buddypress' ); ?></p> 
  2232. </div> 
  2233.  
  2234. <?php endif; 
  2235.  
  2236. /** 
  2237. * Generate the HTML for a list of group moderators. 
  2238. * 
  2239. * No longer used. 
  2240. * 
  2241. * @todo Deprecate. 
  2242. * 
  2243. * @param bool $admin_list 
  2244. * @param bool $group 
  2245. */ 
  2246. function bp_group_mod_memberlist( $admin_list = false, $group = false ) { 
  2247. global $groups_template; 
  2248.  
  2249. if ( empty( $group ) ) { 
  2250. $group =& $groups_template->group; 
  2251.  
  2252. if ( $group_mods = groups_get_group_mods( $group->id ) ) { ?> 
  2253.  
  2254. <ul id="mods-list" class="item-list<?php if ( $admin_list ) { ?> single-line<?php } ?>"> 
  2255.  
  2256. <?php foreach ( (array) $group_mods as $mod ) { ?> 
  2257.  
  2258. <?php if ( !empty( $admin_list ) ) { ?> 
  2259.  
  2260. <li> 
  2261.  
  2262. <?php echo bp_core_fetch_avatar( array( 'item_id' => $mod->user_id, 'type' => 'thumb', 'width' => 30, 'height' => 30, 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_core_get_user_displayname( $mod->user_id ) ) ) ) ?> 
  2263.  
  2264. <h5> 
  2265. <?php echo bp_core_get_userlink( $mod->user_id ); ?> 
  2266.  
  2267. <span class="small"> 
  2268. <a href="<?php bp_group_member_promote_admin_link( array( 'user_id' => $mod->user_id ) ) ?>" class="button confirm mod-promote-to-admin"><?php _e( 'Promote to Admin', 'buddypress' ); ?></a> 
  2269. <a class="button confirm mod-demote-to-member" href="<?php bp_group_member_demote_link($mod->user_id) ?>"><?php _e( 'Demote to Member', 'buddypress' ) ?></a> 
  2270. </span> 
  2271. </h5> 
  2272. </li> 
  2273.  
  2274. <?php } else { ?> 
  2275.  
  2276. <li> 
  2277.  
  2278. <?php echo bp_core_fetch_avatar( array( 'item_id' => $mod->user_id, 'type' => 'thumb', 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_core_get_user_displayname( $mod->user_id ) ) ) ) ?> 
  2279.  
  2280. <h5><?php echo bp_core_get_userlink( $mod->user_id ) ?></h5> 
  2281.  
  2282. <span class="activity"><?php echo bp_core_get_last_activity( strtotime( $mod->date_modified ), __( 'joined %s', 'buddypress') ); ?></span> 
  2283.  
  2284. <?php if ( bp_is_active( 'friends' ) ) : ?> 
  2285.  
  2286. <div class="action"> 
  2287. <?php bp_add_friend_button( $mod->user_id ) ?> 
  2288. </div> 
  2289.  
  2290. <?php endif; ?> 
  2291.  
  2292. </li> 
  2293.  
  2294. <?php } ?> 
  2295. <?php } ?> 
  2296.  
  2297. </ul> 
  2298.  
  2299. <?php } else { ?> 
  2300.  
  2301. <div id="message" class="info"> 
  2302. <p><?php _e( 'This group has no moderators', 'buddypress' ); ?></p> 
  2303. </div> 
  2304.  
  2305. <?php } 
  2306.  
  2307. /** 
  2308. * Determine whether a group has moderators. 
  2309. * 
  2310. * @since 1.0.0 
  2311. * 
  2312. * @param object|bool $group Optional. Group object. Default: current group in loop. 
  2313. * @return array Info about group admins (user_id + date_modified). 
  2314. */ 
  2315. function bp_group_has_moderators( $group = false ) { 
  2316. global $groups_template; 
  2317.  
  2318. if ( empty( $group ) ) { 
  2319. $group =& $groups_template->group; 
  2320.  
  2321. /** 
  2322. * Filters whether a group has moderators. 
  2323. * 
  2324. * @since 1.0.0 
  2325. * @since 2.5.0 Added the `$group` parameter. 
  2326. * 
  2327. * @param array $value Array of user IDs who are a moderator of the provided group. 
  2328. * @param object $group Group object. 
  2329. */ 
  2330. return apply_filters( 'bp_group_has_moderators', groups_get_group_mods( $group->id ), $group ); 
  2331.  
  2332. /** 
  2333. * Output a URL for promoting a user to moderator. 
  2334. * 
  2335. * @since 1.1.0 
  2336. * 
  2337. * @param array|string $args See {@link bp_get_group_member_promote_mod_link()}. 
  2338. */ 
  2339. function bp_group_member_promote_mod_link( $args = '' ) { 
  2340. echo bp_get_group_member_promote_mod_link( $args ); 
  2341. /** 
  2342. * Generate a URL for promoting a user to moderator. 
  2343. * 
  2344. * @since 1.1.0 
  2345. * 
  2346. * @param array|string $args { 
  2347. * @type int $user_id ID of the member to promote. Default: 
  2348. * current member in a group member loop. 
  2349. * @type object $group Group object. Default: current group. 
  2350. * } 
  2351. * @return string 
  2352. */ 
  2353. function bp_get_group_member_promote_mod_link( $args = '' ) { 
  2354. global $members_template, $groups_template; 
  2355.  
  2356. $defaults = array( 
  2357. 'user_id' => $members_template->member->user_id,  
  2358. 'group' => &$groups_template->group 
  2359. ); 
  2360.  
  2361. $r = wp_parse_args( $args, $defaults ); 
  2362. extract( $r, EXTR_SKIP ); 
  2363.  
  2364. /** 
  2365. * Filters a URL for promoting a user to moderator. 
  2366. * 
  2367. * @since 1.1.0 
  2368. * 
  2369. * @param string $value URL to use for promoting a user to moderator. 
  2370. */ 
  2371. return apply_filters( 'bp_get_group_member_promote_mod_link', wp_nonce_url( bp_get_group_permalink( $group ) . 'admin/manage-members/promote/mod/' . $user_id, 'groups_promote_member' ) ); 
  2372.  
  2373. /** 
  2374. * Output a URL for promoting a user to admin. 
  2375. * 
  2376. * @since 1.1.0 
  2377. * 
  2378. * @param array|string $args See {@link bp_get_group_member_promote_admin_link()}. 
  2379. */ 
  2380. function bp_group_member_promote_admin_link( $args = '' ) { 
  2381. echo bp_get_group_member_promote_admin_link( $args ); 
  2382. /** 
  2383. * Generate a URL for promoting a user to admin. 
  2384. * 
  2385. * @since 1.1.0 
  2386. * 
  2387. * @param array|string $args { 
  2388. * @type int $user_id ID of the member to promote. Default: 
  2389. * current member in a group member loop. 
  2390. * @type object $group Group object. Default: current group. 
  2391. * } 
  2392. * @return string 
  2393. */ 
  2394. function bp_get_group_member_promote_admin_link( $args = '' ) { 
  2395. global $members_template, $groups_template; 
  2396.  
  2397. $defaults = array( 
  2398. 'user_id' => !empty( $members_template->member->user_id ) ? $members_template->member->user_id : false,  
  2399. 'group' => &$groups_template->group 
  2400. ); 
  2401.  
  2402. $r = wp_parse_args( $args, $defaults ); 
  2403. extract( $r, EXTR_SKIP ); 
  2404.  
  2405. /** 
  2406. * Filters a URL for promoting a user to admin. 
  2407. * 
  2408. * @since 1.1.0 
  2409. * 
  2410. * @param string $value URL to use for promoting a user to admin. 
  2411. */ 
  2412. return apply_filters( 'bp_get_group_member_promote_admin_link', wp_nonce_url( bp_get_group_permalink( $group ) . 'admin/manage-members/promote/admin/' . $user_id, 'groups_promote_member' ) ); 
  2413.  
  2414. /** 
  2415. * Output a URL for demoting a user to member. 
  2416. * 
  2417. * @since 1.0.0 
  2418. * 
  2419. * @param int $user_id ID of the member to demote. Default: current member in 
  2420. * a member loop. 
  2421. */ 
  2422. function bp_group_member_demote_link( $user_id = 0 ) { 
  2423. global $members_template; 
  2424.  
  2425. if ( !$user_id ) { 
  2426. $user_id = $members_template->member->user_id; 
  2427.  
  2428. echo bp_get_group_member_demote_link( $user_id ); 
  2429. /** 
  2430. * Generate a URL for demoting a user to member. 
  2431. * 
  2432. * @since 1.0.0 
  2433. * 
  2434. * @param int $user_id ID of the member to demote. Default: current 
  2435. * member in a member loop. 
  2436. * @param object|bool $group Optional. Group object. Default: current group. 
  2437. * @return string 
  2438. */ 
  2439. function bp_get_group_member_demote_link( $user_id = 0, $group = false ) { 
  2440. global $members_template, $groups_template; 
  2441.  
  2442. if ( empty( $group ) ) { 
  2443. $group =& $groups_template->group; 
  2444.  
  2445. if ( !$user_id ) { 
  2446. $user_id = $members_template->member->user_id; 
  2447.  
  2448. /** 
  2449. * Filters a URL for demoting a user to member. 
  2450. * 
  2451. * @since 1.0.0 
  2452. * @since 2.5.0 Added the `$group` parameter. 
  2453. * 
  2454. * @param string $value URL to use for demoting a user to member. 
  2455. * @param object $group Group object. 
  2456. */ 
  2457. return apply_filters( 'bp_get_group_member_demote_link', wp_nonce_url( bp_get_group_permalink( $group ) . 'admin/manage-members/demote/' . $user_id, 'groups_demote_member' ), $group ); 
  2458.  
  2459. /** 
  2460. * Output a URL for banning a member from a group. 
  2461. * 
  2462. * @since 1.0.0 
  2463. * 
  2464. * @param int $user_id ID of the member to ban. 
  2465. * Default: current member in a member loop. 
  2466. */ 
  2467. function bp_group_member_ban_link( $user_id = 0 ) { 
  2468. global $members_template; 
  2469.  
  2470. if ( !$user_id ) { 
  2471. $user_id = $members_template->member->user_id; 
  2472.  
  2473. echo bp_get_group_member_ban_link( $user_id ); 
  2474. /** 
  2475. * Generate a URL for banning a member from a group. 
  2476. * 
  2477. * @since 1.0.0 
  2478. * 
  2479. * @param int $user_id ID of the member to ban. 
  2480. * Default: current member in a member loop. 
  2481. * @param object|bool $group Optional. Group object. Default: current group. 
  2482. * @return string 
  2483. */ 
  2484. function bp_get_group_member_ban_link( $user_id = 0, $group = false ) { 
  2485. global $groups_template; 
  2486.  
  2487. if ( empty( $group ) ) { 
  2488. $group =& $groups_template->group; 
  2489.  
  2490. /** 
  2491. * Filters a URL for banning a member from a group. 
  2492. * 
  2493. * @since 1.0.0 
  2494. * 
  2495. * @param string $value URL to use for banning a member. 
  2496. */ 
  2497. return apply_filters( 'bp_get_group_member_ban_link', wp_nonce_url( bp_get_group_permalink( $group ) . 'admin/manage-members/ban/' . $user_id, 'groups_ban_member' ) ); 
  2498.  
  2499. /** 
  2500. * Output a URL for unbanning a member from a group. 
  2501. * 
  2502. * @since 1.0.0 
  2503. * 
  2504. * @param int $user_id ID of the member to unban. 
  2505. * Default: current member in a member loop. 
  2506. */ 
  2507. function bp_group_member_unban_link( $user_id = 0 ) { 
  2508. global $members_template; 
  2509.  
  2510. if ( !$user_id ) { 
  2511. $user_id = $members_template->member->user_id; 
  2512.  
  2513. echo bp_get_group_member_unban_link( $user_id ); 
  2514. /** 
  2515. * Generate a URL for unbanning a member from a group. 
  2516. * 
  2517. * @since 1.0.0 
  2518. * 
  2519. * @param int $user_id ID of the member to unban. 
  2520. * Default: current member in a member loop. 
  2521. * @param object|bool $group Optional. Group object. Default: current group. 
  2522. * @return string 
  2523. */ 
  2524. function bp_get_group_member_unban_link( $user_id = 0, $group = false ) { 
  2525. global $members_template, $groups_template; 
  2526.  
  2527. if ( !$user_id ) { 
  2528. $user_id = $members_template->member->user_id; 
  2529.  
  2530. if ( empty( $group ) ) { 
  2531. $group =& $groups_template->group; 
  2532.  
  2533. /** 
  2534. * Filters a URL for unbanning a member from a group. 
  2535. * 
  2536. * @since 1.0.0 
  2537. * 
  2538. * @param string $value URL to use for unbanning a member. 
  2539. */ 
  2540. return apply_filters( 'bp_get_group_member_unban_link', wp_nonce_url( bp_get_group_permalink( $group ) . 'admin/manage-members/unban/' . $user_id, 'groups_unban_member' ) ); 
  2541.  
  2542. /** 
  2543. * Output a URL for removing a member from a group. 
  2544. * 
  2545. * @since 1.2.6 
  2546. * 
  2547. * @param int $user_id ID of the member to remove. 
  2548. * Default: current member in a member loop. 
  2549. */ 
  2550. function bp_group_member_remove_link( $user_id = 0 ) { 
  2551. global $members_template; 
  2552.  
  2553. if ( !$user_id ) { 
  2554. $user_id = $members_template->member->user_id; 
  2555.  
  2556. echo bp_get_group_member_remove_link( $user_id ); 
  2557. /** 
  2558. * Generate a URL for removing a member from a group. 
  2559. * 
  2560. * @since 1.2.6 
  2561. * 
  2562. * @param int $user_id ID of the member to remove. 
  2563. * Default: current member in a member loop. 
  2564. * @param object|bool $group Optional. Group object. Default: current group. 
  2565. * @return string 
  2566. */ 
  2567. function bp_get_group_member_remove_link( $user_id = 0, $group = false ) { 
  2568. global $groups_template; 
  2569.  
  2570. if ( empty( $group ) ) { 
  2571. $group =& $groups_template->group; 
  2572.  
  2573. /** 
  2574. * Filters a URL for removing a member from a group. 
  2575. * 
  2576. * @since 1.2.6 
  2577. * @since 2.5.0 Added the `$group` parameter. 
  2578. * 
  2579. * @param string $value URL to use for removing a member. 
  2580. * @param object $group Group object. 
  2581. */ 
  2582. return apply_filters( 'bp_get_group_member_remove_link', wp_nonce_url( bp_get_group_permalink( $group ) . 'admin/manage-members/remove/' . $user_id, 'groups_remove_member' ), $group ); 
  2583.  
  2584. /** 
  2585. * HTML admin subnav items for group pages. 
  2586. * 
  2587. * @since 1.0.0 
  2588. * 
  2589. * @param object|bool $group Optional. Group object. 
  2590. * Default: current group in the loop. 
  2591. */ 
  2592. function bp_group_admin_tabs( $group = false ) { 
  2593. global $groups_template; 
  2594.  
  2595. if ( empty( $group ) ) { 
  2596. $group = ( $groups_template->group ) ? $groups_template->group : groups_get_current_group(); 
  2597.  
  2598. $css_id = 'manage-members'; 
  2599.  
  2600. if ( 'private' == $group->status ) { 
  2601. $css_id = 'membership-requests'; 
  2602.  
  2603. add_filter( "bp_get_options_nav_{$css_id}", 'bp_group_admin_tabs_backcompat', 10, 3 ); 
  2604.  
  2605. bp_get_options_nav( $group->slug . '_manage' ); 
  2606.  
  2607. remove_filter( "bp_get_options_nav_{$css_id}", 'bp_group_admin_tabs_backcompat', 10 ); 
  2608.  
  2609. /** 
  2610. * BackCompat for plugins/themes directly hooking groups_admin_tabs 
  2611. * without using the Groups Extension API. 
  2612. * 
  2613. * @since 2.2.0 
  2614. * 
  2615. * @param string $subnav_output Subnav item output. 
  2616. * @param string $subnav_item subnav item params. 
  2617. * @param string $selected_item Surrent selected tab. 
  2618. * @return string HTML output 
  2619. */ 
  2620. function bp_group_admin_tabs_backcompat( $subnav_output = '', $subnav_item = '', $selected_item = '' ) { 
  2621. if ( ! has_action( 'groups_admin_tabs' ) ) { 
  2622. return $subnav_output; 
  2623.  
  2624. $group = groups_get_current_group(); 
  2625.  
  2626. ob_start(); 
  2627.  
  2628. do_action( 'groups_admin_tabs', $selected_item, $group->slug ); 
  2629.  
  2630. $admin_tabs_backcompat = trim( ob_get_contents() ); 
  2631. ob_end_clean(); 
  2632.  
  2633. if ( ! empty( $admin_tabs_backcompat ) ) { 
  2634. _doing_it_wrong( "do_action( 'groups_admin_tabs' )", __( 'This action should not be used directly. Please use the BuddyPress Group Extension API to generate Manage tabs.', 'buddypress' ), '2.2.0' ); 
  2635. $subnav_output .= $admin_tabs_backcompat; 
  2636.  
  2637. return $subnav_output; 
  2638.  
  2639. /** 
  2640. * Output the group count for the displayed user. 
  2641. * 
  2642. * @since 1.1.0 
  2643. */ 
  2644. function bp_group_total_for_member() { 
  2645. echo bp_get_group_total_for_member(); 
  2646. /** 
  2647. * Get the group count for the displayed user. 
  2648. * 
  2649. * @since 1.1.0 
  2650. * 
  2651. * @return string 
  2652. */ 
  2653. function bp_get_group_total_for_member() { 
  2654.  
  2655. /** 
  2656. * FIlters the group count for a displayed user. 
  2657. * 
  2658. * @since 1.1.0 
  2659. * 
  2660. * @param int $value Total group count for a displayed user. 
  2661. */ 
  2662. return apply_filters( 'bp_get_group_total_for_member', BP_Groups_Member::total_group_count() ); 
  2663.  
  2664. /** 
  2665. * Output the 'action' attribute for a group form. 
  2666. * 
  2667. * @since 1.0.0 
  2668. * 
  2669. * @param string $page Page slug. 
  2670. */ 
  2671. function bp_group_form_action( $page ) { 
  2672. echo bp_get_group_form_action( $page ); 
  2673. /** 
  2674. * Generate the 'action' attribute for a group form. 
  2675. * 
  2676. * @since 1.0.0 
  2677. * 
  2678. * @param string $page Page slug. 
  2679. * @param object|bool $group Optional. Group object. 
  2680. * Default: current group in the loop. 
  2681. * @return string 
  2682. */ 
  2683. function bp_get_group_form_action( $page, $group = false ) { 
  2684. global $groups_template; 
  2685.  
  2686. if ( empty( $group ) ) { 
  2687. $group =& $groups_template->group; 
  2688.  
  2689. /** 
  2690. * Filters the 'action' attribute for a group form. 
  2691. * 
  2692. * @since 1.0.0 
  2693. * @since 2.5.0 Added the `$group` parameter. 
  2694. * 
  2695. * @param string $value Action attribute for a group form. 
  2696. * @param object $group Group object. 
  2697. */ 
  2698. return apply_filters( 'bp_group_form_action', bp_get_group_permalink( $group ) . $page, $group ); 
  2699.  
  2700. /** 
  2701. * Output the 'action' attribute for a group admin form. 
  2702. * 
  2703. * @since 1.0.0 
  2704. * 
  2705. * @param string|bool $page Optional. Page slug. 
  2706. */ 
  2707. function bp_group_admin_form_action( $page = false ) { 
  2708. echo bp_get_group_admin_form_action( $page ); 
  2709. /** 
  2710. * Generate the 'action' attribute for a group admin form. 
  2711. * 
  2712. * @since 1.0.0 
  2713. * 
  2714. * @param string|bool $page Optional. Page slug. 
  2715. * @param object|bool $group Optional. Group object. 
  2716. * Default: current group in the loop. 
  2717. * @return string 
  2718. */ 
  2719. function bp_get_group_admin_form_action( $page = false, $group = false ) { 
  2720. global $groups_template; 
  2721.  
  2722. if ( empty( $group ) ) { 
  2723. $group =& $groups_template->group; 
  2724.  
  2725. if ( empty( $page ) ) { 
  2726. $page = bp_action_variable( 0 ); 
  2727.  
  2728. /** 
  2729. * Filters the 'action' attribute for a group admin form. 
  2730. * 
  2731. * @since 1.0.0 
  2732. * @since 2.5.0 Added the `$group` parameter. 
  2733. * 
  2734. * @param string $value Action attribute for a group admin form. 
  2735. * @param object $group Group object. 
  2736. */ 
  2737. return apply_filters( 'bp_group_admin_form_action', bp_get_group_permalink( $group ) . 'admin/' . $page, $group ); 
  2738.  
  2739. /** 
  2740. * Determine whether the logged-in user has requested membership to a group. 
  2741. * 
  2742. * @since 1.0.0 
  2743. * 
  2744. * @param object|bool $group Optional. Group object. 
  2745. * Default: current group in the loop. 
  2746. * @return bool 
  2747. */ 
  2748. function bp_group_has_requested_membership( $group = false ) { 
  2749. global $groups_template; 
  2750.  
  2751. if ( empty( $group ) ) { 
  2752. $group =& $groups_template->group; 
  2753.  
  2754. if ( groups_check_for_membership_request( bp_loggedin_user_id(), $group->id ) ) { 
  2755. return true; 
  2756.  
  2757. return false; 
  2758.  
  2759. /** 
  2760. * Check if current user is member of a group. 
  2761. * 
  2762. * @since 1.0.0 
  2763. * 
  2764. * @global object $groups_template 
  2765. * 
  2766. * @param object|bool $group Optional. Group to check is_member. 
  2767. * Default: current group in the loop. 
  2768. * @return bool If user is member of group or not. 
  2769. */ 
  2770. function bp_group_is_member( $group = false ) { 
  2771. global $groups_template; 
  2772.  
  2773. // Site admins always have access. 
  2774. if ( bp_current_user_can( 'bp_moderate' ) ) { 
  2775. return true; 
  2776.  
  2777. if ( empty( $group ) ) { 
  2778. $group =& $groups_template->group; 
  2779.  
  2780. /** 
  2781. * Filters whether current user is member of a group. 
  2782. * 
  2783. * @since 1.2.4 
  2784. * @since 2.5.0 Added the `$group` parameter. 
  2785. * 
  2786. * @param bool $is_member If user is a member of group or not. 
  2787. * @param object $group Group object. 
  2788. */ 
  2789. return apply_filters( 'bp_group_is_member', ! empty( $group->is_member ), $group ); 
  2790.  
  2791. /** 
  2792. * Check whether the current user has an outstanding invite to the current group in the loop. 
  2793. * 
  2794. * @since 2.1.0 
  2795. * 
  2796. * @param object|bool $group Optional. Group data object. 
  2797. * Default: the current group in the groups loop. 
  2798. * @return bool True if the user has an outstanding invite, otherwise false. 
  2799. */ 
  2800. function bp_group_is_invited( $group = false ) { 
  2801. global $groups_template; 
  2802.  
  2803. if ( empty( $group ) ) { 
  2804. $group =& $groups_template->group; 
  2805.  
  2806. /** 
  2807. * Filters whether current user has an outstanding invite to current group in loop. 
  2808. * 
  2809. * @since 2.1.0 
  2810. * @since 2.5.0 Added the `$group` parameter. 
  2811. * 
  2812. * @param bool $is_invited If user has an outstanding group invite. 
  2813. * @param object $group Group object. 
  2814. */ 
  2815. return apply_filters( 'bp_group_is_invited', ! empty( $group->is_invited ), $group ); 
  2816.  
  2817. /** 
  2818. * Check if a user is banned from a group. 
  2819. * 
  2820. * If this function is invoked inside the groups template loop, then we check 
  2821. * $groups_template->group->is_banned instead of using {@link groups_is_user_banned()} 
  2822. * and making another SQL query. 
  2823. * 
  2824. * In BuddyPress 2.1, to standardize this function, we are defaulting the 
  2825. * return value to a boolean. In previous versions, using this function would 
  2826. * return either a string of the integer (0 or 1) or null if a result couldn't 
  2827. * be found from the database. If the logged-in user had the 'bp_moderate' 
  2828. * capability, the return value would be boolean false. 
  2829. * 
  2830. * @since 1.5.0 
  2831. * 
  2832. * @global BP_Groups_Template $groups_template Group template loop object. 
  2833. * 
  2834. * @param BP_Groups_Group|bool $group Group to check if user is banned. 
  2835. * @param int $user_id The user ID to check. 
  2836. * @return bool True if user is banned. False if user isn't banned. 
  2837. */ 
  2838. function bp_group_is_user_banned( $group = false, $user_id = 0 ) { 
  2839. global $groups_template; 
  2840.  
  2841. // Site admins always have access. 
  2842. if ( bp_current_user_can( 'bp_moderate' ) ) { 
  2843. return false; 
  2844.  
  2845. // Check groups loop first 
  2846. // @see BP_Groups_Group::get_group_extras(). 
  2847. if ( ! empty( $groups_template->in_the_loop ) && isset( $groups_template->group->is_banned ) ) { 
  2848. $retval = $groups_template->group->is_banned; 
  2849.  
  2850. // Not in loop. 
  2851. } else { 
  2852. // Default to not banned. 
  2853. $retval = false; 
  2854.  
  2855. if ( empty( $group ) ) { 
  2856. $group = $groups_template->group; 
  2857.  
  2858. if ( empty( $user_id ) ) { 
  2859. $user_id = bp_loggedin_user_id(); 
  2860.  
  2861. if ( ! empty( $user_id ) && ! empty( $group->id ) ) { 
  2862. $retval = groups_is_user_banned( $user_id, $group->id ); 
  2863.  
  2864. /** 
  2865. * Filters whether current user has been banned from current group in loop. 
  2866. * 
  2867. * @since 1.5.0 
  2868. * @since 2.5.0 Added the `$group` parameter. 
  2869. * 
  2870. * @param bool $is_invited If user has been from current group. 
  2871. * @param object $group Group object. 
  2872. */ 
  2873. return (bool) apply_filters( 'bp_group_is_user_banned', $retval, $group ); 
  2874.  
  2875. /** 
  2876. * Output the URL for accepting an invitation to the current group in the loop. 
  2877. * 
  2878. * @since 1.0.0 
  2879. */ 
  2880. function bp_group_accept_invite_link() { 
  2881. echo bp_get_group_accept_invite_link(); 
  2882. /** 
  2883. * Generate the URL for accepting an invitation to a group. 
  2884. * 
  2885. * @since 1.0.0 
  2886. * 
  2887. * @param object|bool $group Optional. Group object. 
  2888. * Default: Current group in the loop. 
  2889. * @return string 
  2890. */ 
  2891. function bp_get_group_accept_invite_link( $group = false ) { 
  2892. global $groups_template; 
  2893.  
  2894. if ( empty( $group ) ) { 
  2895. $group =& $groups_template->group; 
  2896.  
  2897. $bp = buddypress(); 
  2898.  
  2899. /** 
  2900. * Filters the URL for accepting an invitation to a group. 
  2901. * 
  2902. * @since 1.0.0 
  2903. * @since 2.5.0 Added the `$group` parameter. 
  2904. * 
  2905. * @param string $value URL for accepting an invitation to a group. 
  2906. * @param object $group Group object. 
  2907. */ 
  2908. return apply_filters( 'bp_get_group_accept_invite_link', wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() . '/invites/accept/' . $group->id ), 'groups_accept_invite' ), $group ); 
  2909.  
  2910. /** 
  2911. * Output the URL for accepting an invitation to the current group in the loop. 
  2912. * 
  2913. * @since 1.0.0 
  2914. */ 
  2915. function bp_group_reject_invite_link() { 
  2916. echo bp_get_group_reject_invite_link(); 
  2917. /** 
  2918. * Generate the URL for rejecting an invitation to a group. 
  2919. * 
  2920. * @since 1.0.0 
  2921. * 
  2922. * @param object|bool $group Optional. Group object. 
  2923. * Default: Current group in the loop. 
  2924. * @return string 
  2925. */ 
  2926. function bp_get_group_reject_invite_link( $group = false ) { 
  2927. global $groups_template; 
  2928.  
  2929. if ( empty( $group ) ) { 
  2930. $group =& $groups_template->group; 
  2931.  
  2932. $bp = buddypress(); 
  2933.  
  2934. /** 
  2935. * Filters the URL for rejecting an invitation to a group. 
  2936. * 
  2937. * @since 1.0.0 
  2938. * @since 2.5.0 Added the `$group` parameter. 
  2939. * 
  2940. * @param string $value URL for rejecting an invitation to a group. 
  2941. * @param object $group Group object. 
  2942. */ 
  2943. return apply_filters( 'bp_get_group_reject_invite_link', wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() . '/invites/reject/' . $group->id ), 'groups_reject_invite' ), $group ); 
  2944.  
  2945. /** 
  2946. * Output the URL for confirming a request to leave a group. 
  2947. * 
  2948. * @since 1.0.0 
  2949. */ 
  2950. function bp_group_leave_confirm_link() { 
  2951. echo bp_get_group_leave_confirm_link(); 
  2952. /** 
  2953. * Generate the URL for confirming a request to leave a group. 
  2954. * 
  2955. * @since 1.0.0 
  2956. * 
  2957. * @param object|bool $group Optional. Group object. 
  2958. * Default: Current group in the loop. 
  2959. * @return string 
  2960. */ 
  2961. function bp_get_group_leave_confirm_link( $group = false ) { 
  2962. global $groups_template; 
  2963.  
  2964. if ( empty( $group ) ) { 
  2965. $group =& $groups_template->group; 
  2966.  
  2967. /** 
  2968. * Filters the URL for confirming a request to leave a group. 
  2969. * 
  2970. * @since 1.0.0 
  2971. * @since 2.5.0 Added the `$group` parameter. 
  2972. * 
  2973. * @param string $value URL for confirming a request to leave a group. 
  2974. * @param object $group Group object. 
  2975. */ 
  2976. return apply_filters( 'bp_group_leave_confirm_link', wp_nonce_url( bp_get_group_permalink( $group ) . 'leave-group/yes', 'groups_leave_group' ), $group ); 
  2977.  
  2978. /** 
  2979. * Output the URL for rejecting a request to leave a group. 
  2980. * 
  2981. * @since 1.0.0 
  2982. */ 
  2983. function bp_group_leave_reject_link() { 
  2984. echo bp_get_group_leave_reject_link(); 
  2985. /** 
  2986. * Generate the URL for rejecting a request to leave a group. 
  2987. * 
  2988. * @since 1.0.0 
  2989. * 
  2990. * @param object|bool $group Optional. Group object. 
  2991. * Default: Current group in the loop. 
  2992. * @return string 
  2993. */ 
  2994. function bp_get_group_leave_reject_link( $group = false ) { 
  2995. global $groups_template; 
  2996.  
  2997. if ( empty( $group ) ) { 
  2998. $group =& $groups_template->group; 
  2999.  
  3000. /** 
  3001. * Filters the URL for rejecting a request to leave a group. 
  3002. * 
  3003. * @since 1.0.0 
  3004. * @since 2.5.0 Added the `$group` parameter. 
  3005. * 
  3006. * @param string $value URL for rejecting a request to leave a group. 
  3007. * @param object $group Group object. 
  3008. */ 
  3009. return apply_filters( 'bp_get_group_leave_reject_link', bp_get_group_permalink( $group ), $group ); 
  3010.  
  3011. /** 
  3012. * Output the 'action' attribute for a group send invite form. 
  3013. * 
  3014. * @since 1.0.0 
  3015. */ 
  3016. function bp_group_send_invite_form_action() { 
  3017. echo bp_get_group_send_invite_form_action(); 
  3018. /** 
  3019. * Output the 'action' attribute for a group send invite form. 
  3020. * 
  3021. * @since 1.0.0 
  3022. * 
  3023. * @param object|bool $group Optional. Group object. 
  3024. * Default: current group in the loop. 
  3025. * @return string 
  3026. */ 
  3027. function bp_get_group_send_invite_form_action( $group = false ) { 
  3028. global $groups_template; 
  3029.  
  3030. if ( empty( $group ) ) { 
  3031. $group =& $groups_template->group; 
  3032.  
  3033. /** 
  3034. * Filters the 'action' attribute for a group send invite form. 
  3035. * 
  3036. * @since 1.0.0 
  3037. * @since 2.5.0 Added the `$group` parameter. 
  3038. * 
  3039. * @param string $value Action attribute for a group send invite form. 
  3040. * @param object $group Group object. 
  3041. */ 
  3042. return apply_filters( 'bp_group_send_invite_form_action', bp_get_group_permalink( $group ) . 'send-invites/send', $group ); 
  3043.  
  3044. /** 
  3045. * Determine whether the current user has friends to invite to a group. 
  3046. * 
  3047. * @since 1.0.0 
  3048. * 
  3049. * @param object|bool $group Optional. Group object. 
  3050. * Default: current group in the loop. 
  3051. * @return bool 
  3052. */ 
  3053. function bp_has_friends_to_invite( $group = false ) { 
  3054. global $groups_template; 
  3055.  
  3056. if ( !bp_is_active( 'friends' ) ) { 
  3057. return false; 
  3058.  
  3059. if ( empty( $group ) ) { 
  3060. $group =& $groups_template->group; 
  3061.  
  3062. if ( !friends_check_user_has_friends( bp_loggedin_user_id() ) || !friends_count_invitable_friends( bp_loggedin_user_id(), $group->id ) ) { 
  3063. return false; 
  3064.  
  3065. return true; 
  3066.  
  3067. /** 
  3068. * Output a 'New Topic' button for a group. 
  3069. * 
  3070. * @since 1.2.7 
  3071. * 
  3072. * @param BP_Groups_Group|bool $group The BP Groups_Group object if passed,  
  3073. * boolean false if not passed. 
  3074. */ 
  3075. function bp_group_new_topic_button( $group = false ) { 
  3076. echo bp_get_group_new_topic_button( $group ); 
  3077.  
  3078. /** 
  3079. * Returns a 'New Topic' button for a group. 
  3080. * 
  3081. * @since 1.2.7 
  3082. * 
  3083. * @param BP_Groups_Group|bool $group The BP Groups_Group object if 
  3084. * passed, boolean false if not passed. 
  3085. * @return string HTML code for the button. 
  3086. */ 
  3087. function bp_get_group_new_topic_button( $group = false ) { 
  3088. global $groups_template; 
  3089.  
  3090. if ( empty( $group ) ) { 
  3091. $group =& $groups_template->group; 
  3092.  
  3093. if ( !is_user_logged_in() || bp_group_is_user_banned() || !bp_is_group_forum() || bp_is_group_forum_topic() ) { 
  3094. return false; 
  3095.  
  3096. $button = array( 
  3097. 'id' => 'new_topic',  
  3098. 'component' => 'groups',  
  3099. 'must_be_logged_in' => true,  
  3100. 'block_self' => true,  
  3101. 'wrapper_class' => 'group-button',  
  3102. 'link_href' => '#post-new',  
  3103. 'link_class' => 'group-button show-hide-new',  
  3104. 'link_id' => 'new-topic-button',  
  3105. 'link_text' => __( 'New Topic', 'buddypress' ),  
  3106. ); 
  3107.  
  3108. /** 
  3109. * Filters the HTML button for creating a new topic in a group. 
  3110. * 
  3111. * @since 1.5.0 
  3112. * @since 2.5.0 Added the `$group` parameter. 
  3113. * 
  3114. * @param string $button HTML button for a new topic. 
  3115. * @param object $group Group object. 
  3116. */ 
  3117. return bp_get_button( apply_filters( 'bp_get_group_new_topic_button', $button, $group ) ); 
  3118.  
  3119. /** 
  3120. * Output button to join a group. 
  3121. * 
  3122. * @since 1.0.0 
  3123. * 
  3124. * @param object|bool $group Single group object. 
  3125. */ 
  3126. function bp_group_join_button( $group = false ) { 
  3127. echo bp_get_group_join_button( $group ); 
  3128. /** 
  3129. * Return button to join a group. 
  3130. * 
  3131. * @since 1.0.0 
  3132. * 
  3133. * @param object|bool $group Single group object. 
  3134. * @return false|string 
  3135. */ 
  3136. function bp_get_group_join_button( $group = false ) { 
  3137. global $groups_template; 
  3138.  
  3139. // Set group to current loop group if none passed. 
  3140. if ( empty( $group ) ) { 
  3141. $group =& $groups_template->group; 
  3142.  
  3143. // Don't show button if not logged in or previously banned. 
  3144. if ( ! is_user_logged_in() || bp_group_is_user_banned( $group ) ) { 
  3145. return false; 
  3146.  
  3147. // Group creation was not completed or status is unknown. 
  3148. if ( empty( $group->status ) ) { 
  3149. return false; 
  3150.  
  3151. // Already a member. 
  3152. if ( ! empty( $group->is_member ) ) { 
  3153.  
  3154. // Stop sole admins from abandoning their group. 
  3155. $group_admins = groups_get_group_admins( $group->id ); 
  3156. if ( ( 1 == count( $group_admins ) ) && ( bp_loggedin_user_id() === (int) $group_admins[0]->user_id ) ) { 
  3157. return false; 
  3158.  
  3159. // Setup button attributes. 
  3160. $button = array( 
  3161. 'id' => 'leave_group',  
  3162. 'component' => 'groups',  
  3163. 'must_be_logged_in' => true,  
  3164. 'block_self' => false,  
  3165. 'wrapper_class' => 'group-button ' . $group->status,  
  3166. 'wrapper_id' => 'groupbutton-' . $group->id,  
  3167. 'link_href' => wp_nonce_url( bp_get_group_permalink( $group ) . 'leave-group', 'groups_leave_group' ),  
  3168. 'link_text' => __( 'Leave Group', 'buddypress' ),  
  3169. 'link_class' => 'group-button leave-group',  
  3170. ); 
  3171.  
  3172. // Not a member. 
  3173. } else { 
  3174.  
  3175. // Show different buttons based on group status. 
  3176. switch ( $group->status ) { 
  3177. case 'hidden' : 
  3178. return false; 
  3179.  
  3180. case 'public': 
  3181. $button = array( 
  3182. 'id' => 'join_group',  
  3183. 'component' => 'groups',  
  3184. 'must_be_logged_in' => true,  
  3185. 'block_self' => false,  
  3186. 'wrapper_class' => 'group-button ' . $group->status,  
  3187. 'wrapper_id' => 'groupbutton-' . $group->id,  
  3188. 'link_href' => wp_nonce_url( bp_get_group_permalink( $group ) . 'join', 'groups_join_group' ),  
  3189. 'link_text' => __( 'Join Group', 'buddypress' ),  
  3190. 'link_class' => 'group-button join-group',  
  3191. ); 
  3192. break; 
  3193.  
  3194. case 'private' : 
  3195.  
  3196. // Member has outstanding invitation - 
  3197. // show an "Accept Invitation" button. 
  3198. if ( $group->is_invited ) { 
  3199. $button = array( 
  3200. 'id' => 'accept_invite',  
  3201. 'component' => 'groups',  
  3202. 'must_be_logged_in' => true,  
  3203. 'block_self' => false,  
  3204. 'wrapper_class' => 'group-button ' . $group->status,  
  3205. 'wrapper_id' => 'groupbutton-' . $group->id,  
  3206. 'link_href' => add_query_arg( 'redirect_to', bp_get_group_permalink( $group ), bp_get_group_accept_invite_link( $group ) ),  
  3207. 'link_text' => __( 'Accept Invitation', 'buddypress' ),  
  3208. 'link_class' => 'group-button accept-invite',  
  3209. ); 
  3210.  
  3211. // Member has requested membership but request is pending - 
  3212. // show a "Request Sent" button. 
  3213. } elseif ( $group->is_pending ) { 
  3214. $button = array( 
  3215. 'id' => 'membership_requested',  
  3216. 'component' => 'groups',  
  3217. 'must_be_logged_in' => true,  
  3218. 'block_self' => false,  
  3219. 'wrapper_class' => 'group-button pending ' . $group->status,  
  3220. 'wrapper_id' => 'groupbutton-' . $group->id,  
  3221. 'link_href' => bp_get_group_permalink( $group ),  
  3222. 'link_text' => __( 'Request Sent', 'buddypress' ),  
  3223. 'link_class' => 'group-button pending membership-requested',  
  3224. ); 
  3225.  
  3226. // Member has not requested membership yet - 
  3227. // show a "Request Membership" button. 
  3228. } else { 
  3229. $button = array( 
  3230. 'id' => 'request_membership',  
  3231. 'component' => 'groups',  
  3232. 'must_be_logged_in' => true,  
  3233. 'block_self' => false,  
  3234. 'wrapper_class' => 'group-button ' . $group->status,  
  3235. 'wrapper_id' => 'groupbutton-' . $group->id,  
  3236. 'link_href' => wp_nonce_url( bp_get_group_permalink( $group ) . 'request-membership', 'groups_request_membership' ),  
  3237. 'link_text' => __( 'Request Membership', 'buddypress' ),  
  3238. 'link_class' => 'group-button request-membership',  
  3239. ); 
  3240.  
  3241. break; 
  3242.  
  3243. /** 
  3244. * Filters the HTML button for joining a group. 
  3245. * 
  3246. * @since 1.2.6 
  3247. * @since 2.4.0 Added $group parameter to filter args. 
  3248. * 
  3249. * @param string $button HTML button for joining a group. 
  3250. * @param object $group BuddyPress group object 
  3251. */ 
  3252. return bp_get_button( apply_filters( 'bp_get_group_join_button', $button, $group ) ); 
  3253.  
  3254. /** 
  3255. * Output the Create a Group button. 
  3256. * 
  3257. * @since 2.0.0 
  3258. */ 
  3259. function bp_group_create_button() { 
  3260. echo bp_get_group_create_button(); 
  3261. /** 
  3262. * Get the Create a Group button. 
  3263. * 
  3264. * @since 2.0.0 
  3265. * 
  3266. * @return string 
  3267. */ 
  3268. function bp_get_group_create_button() { 
  3269. if ( ! is_user_logged_in() ) { 
  3270. return false; 
  3271.  
  3272. if ( ! bp_user_can_create_groups() ) { 
  3273. return false; 
  3274.  
  3275. $button_args = array( 
  3276. 'id' => 'create_group',  
  3277. 'component' => 'groups',  
  3278. 'link_text' => __( 'Create a Group', 'buddypress' ),  
  3279. 'link_class' => 'group-create no-ajax',  
  3280. 'link_href' => trailingslashit( bp_get_groups_directory_permalink() . 'create' ),  
  3281. 'wrapper' => false,  
  3282. 'block_self' => false,  
  3283. ); 
  3284.  
  3285. /** 
  3286. * Filters the HTML button for creating a group. 
  3287. * 
  3288. * @since 2.0.0 
  3289. * 
  3290. * @param string $button HTML button for creating a group. 
  3291. */ 
  3292. return bp_get_button( apply_filters( 'bp_get_group_create_button', $button_args ) ); 
  3293.  
  3294. /** 
  3295. * Output the Create a Group nav item. 
  3296. * 
  3297. * @since 2.2.0 
  3298. */ 
  3299. function bp_group_create_nav_item() { 
  3300. echo bp_get_group_create_nav_item(); 
  3301.  
  3302. /** 
  3303. * Get the Create a Group nav item. 
  3304. * 
  3305. * @since 2.2.0 
  3306. * 
  3307. * @return string 
  3308. */ 
  3309. function bp_get_group_create_nav_item() { 
  3310. // Get the create a group button. 
  3311. $create_group_button = bp_get_group_create_button(); 
  3312.  
  3313. // Make sure the button is available. 
  3314. if ( empty( $create_group_button ) ) { 
  3315. return; 
  3316.  
  3317. $output = '<li id="group-create-nav">' . $create_group_button . '</li>'; 
  3318.  
  3319. /** 
  3320. * Filters the Create a Group nav item. 
  3321. * 
  3322. * @since 2.2.0 
  3323. * 
  3324. * @param string $output HTML output for nav item. 
  3325. */ 
  3326. return apply_filters( 'bp_get_group_create_nav_item', $output ); 
  3327.  
  3328. /** 
  3329. * Checks if a specific theme is still filtering the Groups directory title 
  3330. * if so, transform the title button into a Groups directory nav item. 
  3331. * 
  3332. * @since 2.2.0 
  3333. * 
  3334. * @return string HTML Output 
  3335. */ 
  3336. function bp_group_backcompat_create_nav_item() { 
  3337. // Bail if the Groups nav item is already used by bp-legacy. 
  3338. if ( has_action( 'bp_groups_directory_group_filter', 'bp_legacy_theme_group_create_nav', 999 ) ) { 
  3339. return; 
  3340.  
  3341. // Bail if the theme is not filtering the Groups directory title. 
  3342. if ( ! has_filter( 'bp_groups_directory_header' ) ) { 
  3343. return; 
  3344.  
  3345. bp_group_create_nav_item(); 
  3346. add_action( 'bp_groups_directory_group_filter', 'bp_group_backcompat_create_nav_item', 1000 ); 
  3347.  
  3348. /** 
  3349. * Prints a message if the group is not visible to the current user (it is a 
  3350. * hidden or private group, and the user does not have access). 
  3351. * 
  3352. * @since 1.0.0 
  3353. * 
  3354. * @global BP_Groups_Template $groups_template Groups template object. 
  3355. * 
  3356. * @param object|null $group Group to get status message for. Optional; defaults to current group. 
  3357. */ 
  3358. function bp_group_status_message( $group = null ) { 
  3359. global $groups_template; 
  3360.  
  3361. // Group not passed so look for loop. 
  3362. if ( empty( $group ) ) { 
  3363. $group =& $groups_template->group; 
  3364.  
  3365. // Group status is not set (maybe outside of group loop?). 
  3366. if ( empty( $group->status ) ) { 
  3367. $message = __( 'This group is not currently accessible.', 'buddypress' ); 
  3368.  
  3369. // Group has a status. 
  3370. } else { 
  3371. switch( $group->status ) { 
  3372.  
  3373. // Private group. 
  3374. case 'private' : 
  3375. if ( ! bp_group_has_requested_membership( $group ) ) { 
  3376. if ( is_user_logged_in() ) { 
  3377. if ( bp_group_is_invited( $group ) ) { 
  3378. $message = __( 'You must accept your pending invitation before you can access this private group.', 'buddypress' ); 
  3379. } else { 
  3380. $message = __( 'This is a private group and you must request group membership in order to join.', 'buddypress' ); 
  3381. } else { 
  3382. $message = __( 'This is a private group. To join you must be a registered site member and request group membership.', 'buddypress' ); 
  3383. } else { 
  3384. $message = __( 'This is a private group. Your membership request is awaiting approval from the group administrator.', 'buddypress' ); 
  3385.  
  3386. break; 
  3387.  
  3388. // Hidden group. 
  3389. case 'hidden' : 
  3390. default : 
  3391. $message = __( 'This is a hidden group and only invited members can join.', 'buddypress' ); 
  3392. break; 
  3393.  
  3394. /** 
  3395. * Filters a message if the group is not visible to the current user. 
  3396. * 
  3397. * This will be true if it is a hidden or private group, and the user does not have access. 
  3398. * 
  3399. * @since 1.6.0 
  3400. * 
  3401. * @param string $message Message to display to the current user. 
  3402. * @param object $group Group to get status message for. 
  3403. */ 
  3404. echo apply_filters( 'bp_group_status_message', $message, $group ); 
  3405.  
  3406. /** 
  3407. * Output hidden form fields for group. 
  3408. * 
  3409. * This function is no longer used, but may still be used by older themes. 
  3410. * 
  3411. * @since 1.0.0 
  3412. */ 
  3413. function bp_group_hidden_fields() { 
  3414. $query_arg = bp_core_get_component_search_query_arg( 'groups' ); 
  3415.  
  3416. if ( isset( $_REQUEST[ $query_arg ] ) ) { 
  3417. echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST[ $query_arg ] ) . '" name="search_terms" />'; 
  3418.  
  3419. if ( isset( $_REQUEST['letter'] ) ) { 
  3420. echo '<input type="hidden" id="selected_letter" value="' . esc_attr( $_REQUEST['letter'] ) . '" name="selected_letter" />'; 
  3421.  
  3422. if ( isset( $_REQUEST['groups_search'] ) ) { 
  3423. echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['groups_search'] ) . '" name="search_terms" />'; 
  3424.  
  3425. /** 
  3426. * Output the total number of groups. 
  3427. * 
  3428. * @since 1.0.0 
  3429. */ 
  3430. function bp_total_group_count() { 
  3431. echo bp_get_total_group_count(); 
  3432. /** 
  3433. * Return the total number of groups. 
  3434. * 
  3435. * @since 1.0.0 
  3436. * 
  3437. * @return type 
  3438. */ 
  3439. function bp_get_total_group_count() { 
  3440.  
  3441. /** 
  3442. * Filters the total number of groups. 
  3443. * 
  3444. * @since 1.0.0 
  3445. * 
  3446. * @param int $value Total number of groups found. 
  3447. */ 
  3448. return apply_filters( 'bp_get_total_group_count', groups_get_total_group_count() ); 
  3449.  
  3450. /** 
  3451. * Output the total number of groups a user belongs to. 
  3452. * 
  3453. * @since 1.0.0 
  3454. * 
  3455. * @param int $user_id User ID to get group membership count. 
  3456. */ 
  3457. function bp_total_group_count_for_user( $user_id = 0 ) { 
  3458. echo bp_get_total_group_count_for_user( $user_id ); 
  3459. /** 
  3460. * Return the total number of groups a user belongs to. 
  3461. * 
  3462. * Filtered by `bp_core_number_format()` by default 
  3463. * 
  3464. * @since 1.0.0 
  3465. * 
  3466. * @param int $user_id User ID to get group membership count. 
  3467. * @return string 
  3468. */ 
  3469. function bp_get_total_group_count_for_user( $user_id = 0 ) { 
  3470. $count = groups_total_groups_for_user( $user_id ); 
  3471.  
  3472. /** 
  3473. * Filters the total number of groups a user belongs to. 
  3474. * 
  3475. * @since 1.2.0 
  3476. * 
  3477. * @param int $count Total number of groups for the user. 
  3478. * @param int $user_id ID of the user being checked. 
  3479. */ 
  3480. return apply_filters( 'bp_get_total_group_count_for_user', $count, $user_id ); 
  3481.  
  3482. /** Group Members *************************************************************/ 
  3483.  
  3484. /** 
  3485. * Initialize a group member query loop. 
  3486. * 
  3487. * @since 1.0.0 
  3488. * 
  3489. * @param array|string $args { 
  3490. * An array of optional arguments. 
  3491. * @type int $group_id ID of the group whose members are being queried. 
  3492. * Default: current group ID. 
  3493. * @type int $page Page of results to be queried. Default: 1. 
  3494. * @type int $per_page Number of items to return per page of results. 
  3495. * Default: 20. 
  3496. * @type int $max Optional. Max number of items to return. 
  3497. * @type array $exclude Optional. Array of user IDs to exclude. 
  3498. * @type bool|int $exclude_admin_mods True (or 1) to exclude admins and mods from results. 
  3499. * Default: 1. 
  3500. * @type bool|int $exclude_banned True (or 1) to exclude banned users from results. 
  3501. * Default: 1. 
  3502. * @type array $group_role Optional. Array of group roles to include. 
  3503. * @type string $type Optional. Sort order of results. 'last_joined',  
  3504. * 'first_joined', or any of the $type params available in 
  3505. * {@link BP_User_Query}. Default: 'last_joined'. 
  3506. * @type string $search_terms Optional. Search terms to match. Pass an 
  3507. * empty string to force-disable search, even in 
  3508. * the presence of $_REQUEST['s']. Default: null. 
  3509. * } 
  3510. * 
  3511. * @return bool 
  3512. */ 
  3513. function bp_group_has_members( $args = '' ) { 
  3514. global $members_template; 
  3515.  
  3516. $exclude_admins_mods = 1; 
  3517.  
  3518. if ( bp_is_group_members() ) { 
  3519. $exclude_admins_mods = 0; 
  3520.  
  3521. $search_terms_default = null; 
  3522. $search_query_arg = bp_core_get_component_search_query_arg( 'members' ); 
  3523. if ( ! empty( $_REQUEST[ $search_query_arg ] ) ) { 
  3524. $search_terms_default = stripslashes( $_REQUEST[ $search_query_arg ] ); 
  3525.  
  3526. $r = wp_parse_args( $args, array( 
  3527. 'group_id' => bp_get_current_group_id(),  
  3528. 'page' => 1,  
  3529. 'per_page' => 20,  
  3530. 'max' => false,  
  3531. 'exclude' => false,  
  3532. 'exclude_admins_mods' => $exclude_admins_mods,  
  3533. 'exclude_banned' => 1,  
  3534. 'group_role' => false,  
  3535. 'search_terms' => $search_terms_default,  
  3536. 'type' => 'last_joined',  
  3537. ) ); 
  3538.  
  3539. if ( is_null( $r['search_terms'] ) && ! empty( $_REQUEST['s'] ) ) { 
  3540. $r['search_terms'] = $_REQUEST['s']; 
  3541.  
  3542. $members_template = new BP_Groups_Group_Members_Template( $r ); 
  3543.  
  3544. /** 
  3545. * Filters whether or not a group member query has members to display. 
  3546. * 
  3547. * @since 1.1.0 
  3548. * 
  3549. * @param bool $value Whether there are members to display. 
  3550. * @param BP_Groups_Group_Members_Template $members_template Object holding the member query results. 
  3551. */ 
  3552. return apply_filters( 'bp_group_has_members', $members_template->has_members(), $members_template ); 
  3553.  
  3554. /** 
  3555. * @since 1.0.0 
  3556. * 
  3557. * @return mixed 
  3558. */ 
  3559. function bp_group_members() { 
  3560. global $members_template; 
  3561.  
  3562. return $members_template->members(); 
  3563.  
  3564. /** 
  3565. * @since 1.0.0 
  3566. * 
  3567. * @return mixed 
  3568. */ 
  3569. function bp_group_the_member() { 
  3570. global $members_template; 
  3571.  
  3572. return $members_template->the_member(); 
  3573.  
  3574. /** 
  3575. * Output the group member avatar while in the groups members loop. 
  3576. * 
  3577. * @since 1.0.0 
  3578. * 
  3579. * @param array|string $args {@see bp_core_fetch_avatar()}. 
  3580. */ 
  3581. function bp_group_member_avatar( $args = '' ) { 
  3582. echo bp_get_group_member_avatar( $args ); 
  3583. /** 
  3584. * Return the group member avatar while in the groups members loop. 
  3585. * 
  3586. * @since 1.0.0 
  3587. * 
  3588. * @param array|string $args {@see bp_core_fetch_avatar()}. 
  3589. * @return string 
  3590. */ 
  3591. function bp_get_group_member_avatar( $args = '' ) { 
  3592. global $members_template; 
  3593.  
  3594. $r = bp_parse_args( $args, array( 
  3595. 'item_id' => $members_template->member->user_id,  
  3596. 'type' => 'full',  
  3597. 'email' => $members_template->member->user_email,  
  3598. 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), $members_template->member->display_name ) 
  3599. ) ); 
  3600.  
  3601. /** 
  3602. * Filters the group member avatar while in the groups members loop. 
  3603. * 
  3604. * @since 1.0.0 
  3605. * 
  3606. * @param string $value HTML markup for group member avatar. 
  3607. * @param array $r Parsed args used for the avatar query. 
  3608. */ 
  3609. return apply_filters( 'bp_get_group_member_avatar', bp_core_fetch_avatar( $r ), $r ); 
  3610.  
  3611. /** 
  3612. * Output the group member avatar while in the groups members loop. 
  3613. * 
  3614. * @since 1.0.0 
  3615. * 
  3616. * @param array|string $args {@see bp_core_fetch_avatar()}. 
  3617. */ 
  3618. function bp_group_member_avatar_thumb( $args = '' ) { 
  3619. echo bp_get_group_member_avatar_thumb( $args ); 
  3620. /** 
  3621. * Return the group member avatar while in the groups members loop. 
  3622. * 
  3623. * @since 1.0.0 
  3624. * 
  3625. * @param array|string $args {@see bp_core_fetch_avatar()}. 
  3626. * @return string 
  3627. */ 
  3628. function bp_get_group_member_avatar_thumb( $args = '' ) { 
  3629. global $members_template; 
  3630.  
  3631. $r = bp_parse_args( $args, array( 
  3632. 'item_id' => $members_template->member->user_id,  
  3633. 'type' => 'thumb',  
  3634. 'email' => $members_template->member->user_email,  
  3635. 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), $members_template->member->display_name ) 
  3636. ) ); 
  3637.  
  3638. /** 
  3639. * Filters the group member avatar thumb while in the groups members loop. 
  3640. * 
  3641. * @since 1.1.0 
  3642. * 
  3643. * @param string $value HTML markup for group member avatar thumb. 
  3644. * @param array $r Parsed args used for the avatar query. 
  3645. */ 
  3646. return apply_filters( 'bp_get_group_member_avatar_thumb', bp_core_fetch_avatar( $r ), $r ); 
  3647.  
  3648. /** 
  3649. * Output the group member avatar while in the groups members loop. 
  3650. * 
  3651. * @since 1.0.0 
  3652. * 
  3653. * @param int $width Width of avatar to fetch. 
  3654. * @param int $height Height of avatar to fetch. 
  3655. */ 
  3656. function bp_group_member_avatar_mini( $width = 30, $height = 30 ) { 
  3657. echo bp_get_group_member_avatar_mini( $width, $height ); 
  3658. /** 
  3659. * Output the group member avatar while in the groups members loop. 
  3660. * 
  3661. * @since 1.0.0 
  3662. * 
  3663. * @param int $width Width of avatar to fetch. 
  3664. * @param int $height Height of avatar to fetch. 
  3665. * @return string 
  3666. */ 
  3667. function bp_get_group_member_avatar_mini( $width = 30, $height = 30 ) { 
  3668. global $members_template; 
  3669.  
  3670. $r = bp_parse_args( array(), array( 
  3671. 'item_id' => $members_template->member->user_id,  
  3672. 'type' => 'thumb',  
  3673. 'email' => $members_template->member->user_email,  
  3674. 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), $members_template->member->display_name ),  
  3675. 'width' => absint( $width ),  
  3676. 'height' => absint( $height ) 
  3677. ) ); 
  3678.  
  3679. /** 
  3680. * Filters the group member avatar mini while in the groups members loop. 
  3681. * 
  3682. * @since 1.0.0 
  3683. * 
  3684. * @param string $value HTML markup for group member avatar mini. 
  3685. * @param array $r Parsed args used for the avatar query. 
  3686. */ 
  3687. return apply_filters( 'bp_get_group_member_avatar_mini', bp_core_fetch_avatar( $r ), $r ); 
  3688.  
  3689. /** 
  3690. * @since 1.0.0 
  3691. */ 
  3692. function bp_group_member_name() { 
  3693. echo bp_get_group_member_name(); 
  3694.  
  3695. /** 
  3696. * @since 1.0.0 
  3697. * 
  3698. * @return mixed|void 
  3699. */ 
  3700. function bp_get_group_member_name() { 
  3701. global $members_template; 
  3702.  
  3703. /** 
  3704. * Filters the group member display name of the current user in the loop. 
  3705. * 
  3706. * @since 1.0.0 
  3707. * 
  3708. * @param string $display_name Display name of the current user. 
  3709. */ 
  3710. return apply_filters( 'bp_get_group_member_name', $members_template->member->display_name ); 
  3711.  
  3712. /** 
  3713. * @since 1.0.0 
  3714. */ 
  3715. function bp_group_member_url() { 
  3716. echo bp_get_group_member_url(); 
  3717.  
  3718. /** 
  3719. * @since 1.0.0 
  3720. * 
  3721. * @return mixed|void 
  3722. */ 
  3723. function bp_get_group_member_url() { 
  3724. global $members_template; 
  3725.  
  3726. /** 
  3727. * Filters the group member url for the current user in the loop. 
  3728. * 
  3729. * @since 1.0.0 
  3730. * 
  3731. * @param string $value URL for the current user. 
  3732. */ 
  3733. return apply_filters( 'bp_get_group_member_url', bp_core_get_user_domain( $members_template->member->user_id, $members_template->member->user_nicename, $members_template->member->user_login ) ); 
  3734.  
  3735. /** 
  3736. * @since 1.0.0 
  3737. */ 
  3738. function bp_group_member_link() { 
  3739. echo bp_get_group_member_link(); 
  3740.  
  3741. /** 
  3742. * @since 1.0.0 
  3743. * 
  3744. * @return mixed|void 
  3745. */ 
  3746. function bp_get_group_member_link() { 
  3747. global $members_template; 
  3748.  
  3749. /** 
  3750. * Filters the group member HTML link for the current user in the loop. 
  3751. * 
  3752. * @since 1.0.0 
  3753. * 
  3754. * @param string $value HTML link for the current user. 
  3755. */ 
  3756. return apply_filters( 'bp_get_group_member_link', '<a href="' . bp_core_get_user_domain( $members_template->member->user_id, $members_template->member->user_nicename, $members_template->member->user_login ) . '">' . $members_template->member->display_name . '</a>' ); 
  3757.  
  3758. /** 
  3759. * @since 1.2.0 
  3760. */ 
  3761. function bp_group_member_domain() { 
  3762. echo bp_get_group_member_domain(); 
  3763.  
  3764. /** 
  3765. * @since 1.2.0 
  3766. * 
  3767. * @return mixed|void 
  3768. */ 
  3769. function bp_get_group_member_domain() { 
  3770. global $members_template; 
  3771.  
  3772. /** 
  3773. * Filters the group member domain for the current user in the loop. 
  3774. * 
  3775. * @since 1.2.0 
  3776. * 
  3777. * @param string $value Domain for the current user. 
  3778. */ 
  3779. return apply_filters( 'bp_get_group_member_domain', bp_core_get_user_domain( $members_template->member->user_id, $members_template->member->user_nicename, $members_template->member->user_login ) ); 
  3780.  
  3781. /** 
  3782. * @since 1.2.0 
  3783. */ 
  3784. function bp_group_member_is_friend() { 
  3785. echo bp_get_group_member_is_friend(); 
  3786.  
  3787. /** 
  3788. * @since 1.2.0 
  3789. * 
  3790. * @return mixed|void 
  3791. */ 
  3792. function bp_get_group_member_is_friend() { 
  3793. global $members_template; 
  3794.  
  3795. if ( !isset( $members_template->member->is_friend ) ) { 
  3796. $friend_status = 'not_friends'; 
  3797. } else { 
  3798. $friend_status = ( 0 == $members_template->member->is_friend ) 
  3799. ? 'pending' 
  3800. : 'is_friend'; 
  3801.  
  3802. /** 
  3803. * Filters the friendship status between current user and displayed user in group member loop. 
  3804. * 
  3805. * @since 1.2.0 
  3806. * 
  3807. * @param string $friend_status Current status of the friendship. 
  3808. */ 
  3809. return apply_filters( 'bp_get_group_member_is_friend', $friend_status ); 
  3810.  
  3811. /** 
  3812. * @since 1.0.0 
  3813. */ 
  3814. function bp_group_member_is_banned() { 
  3815. echo bp_get_group_member_is_banned(); 
  3816.  
  3817. /** 
  3818. * @since 1.0.0 
  3819. * 
  3820. * @return mixed|void 
  3821. */ 
  3822. function bp_get_group_member_is_banned() { 
  3823. global $members_template; 
  3824.  
  3825. /** 
  3826. * Filters whether the member is banned from the current group. 
  3827. * 
  3828. * @since 1.0.0 
  3829. * 
  3830. * @param bool $is_banned Whether or not the member is banned. 
  3831. */ 
  3832. return apply_filters( 'bp_get_group_member_is_banned', $members_template->member->is_banned ); 
  3833.  
  3834. /** 
  3835. * @since 1.2.6 
  3836. */ 
  3837. function bp_group_member_css_class() { 
  3838. global $members_template; 
  3839.  
  3840. if ( $members_template->member->is_banned ) { 
  3841.  
  3842. /** 
  3843. * Filters the class to add to the HTML if member is banned. 
  3844. * 
  3845. * @since 1.2.6 
  3846. * 
  3847. * @param string $value HTML class to add. 
  3848. */ 
  3849. echo apply_filters( 'bp_group_member_css_class', 'banned-user' ); 
  3850.  
  3851. /** 
  3852. * Output the joined date for the current member in the group member loop. 
  3853. * 
  3854. * @since 1.0.0 
  3855. * @since 2.7.0 Added $args as a parameter. 
  3856. * 
  3857. * @param array|string $args {@see bp_get_group_member_joined_since()} 
  3858. * @return string 
  3859. */ 
  3860. function bp_group_member_joined_since( $args = array() ) { 
  3861. echo bp_get_group_member_joined_since( $args ); 
  3862. /** 
  3863. * Return the joined date for the current member in the group member loop. 
  3864. * 
  3865. * @since 1.0.0 
  3866. * @since 2.7.0 Added $args as a parameter. 
  3867. * 
  3868. * @param array|string $args { 
  3869. * Array of optional parameters. 
  3870. * 
  3871. * @type bool $relative Optional. If true, returns relative joined date. eg. joined 5 months ago. 
  3872. * If false, returns joined date value from database. Default: true. 
  3873. * } 
  3874. * @return string 
  3875. */ 
  3876. function bp_get_group_member_joined_since( $args = array() ) { 
  3877. global $members_template; 
  3878.  
  3879. $r = wp_parse_args( $args, array( 
  3880. 'relative' => true,  
  3881. ) ); 
  3882.  
  3883. // We do not want relative time, so return now. 
  3884. // @todo Should the 'bp_get_group_member_joined_since' filter be applied here? 
  3885. if ( ! $r['relative'] ) { 
  3886. return esc_attr( $members_template->member->date_modified ); 
  3887.  
  3888. /** 
  3889. * Filters the joined since time for the current member in the loop. 
  3890. * 
  3891. * @since 1.0.0 
  3892. * 
  3893. * @param string $value Joined since time. 
  3894. */ 
  3895. return apply_filters( 'bp_get_group_member_joined_since', bp_core_get_last_activity( $members_template->member->date_modified, __( 'joined %s', 'buddypress') ) ); 
  3896.  
  3897. /** 
  3898. * @since 1.0.0 
  3899. */ 
  3900. function bp_group_member_id() { 
  3901. echo bp_get_group_member_id(); 
  3902.  
  3903. /** 
  3904. * @since 1.0.0 
  3905. * 
  3906. * @return mixed|void 
  3907. */ 
  3908. function bp_get_group_member_id() { 
  3909. global $members_template; 
  3910.  
  3911. /** 
  3912. * Filters the member's user ID for group members loop. 
  3913. * 
  3914. * @since 1.0.0 
  3915. * 
  3916. * @param int $user_id User ID of the member. 
  3917. */ 
  3918. return apply_filters( 'bp_get_group_member_id', $members_template->member->user_id ); 
  3919.  
  3920. /** 
  3921. * @since 1.0.0 
  3922. * 
  3923. * @return bool 
  3924. */ 
  3925. function bp_group_member_needs_pagination() { 
  3926. global $members_template; 
  3927.  
  3928. if ( $members_template->total_member_count > $members_template->pag_num ) { 
  3929. return true; 
  3930.  
  3931. return false; 
  3932.  
  3933. /** 
  3934. * @since 1.0.0 
  3935. */ 
  3936. function bp_group_pag_id() { 
  3937. echo bp_get_group_pag_id(); 
  3938.  
  3939. /** 
  3940. * @since 1.0.0 
  3941. * 
  3942. * @return mixed|void 
  3943. */ 
  3944. function bp_get_group_pag_id() { 
  3945.  
  3946. /** 
  3947. * Filters the string to be used as the group pag id. 
  3948. * 
  3949. * @since 1.0.0 
  3950. * 
  3951. * @param string $value Value to use for the pag id. 
  3952. */ 
  3953. return apply_filters( 'bp_get_group_pag_id', 'pag' ); 
  3954.  
  3955. /** 
  3956. * @since 1.0.0 
  3957. */ 
  3958. function bp_group_member_pagination() { 
  3959. echo bp_get_group_member_pagination(); 
  3960. wp_nonce_field( 'bp_groups_member_list', '_member_pag_nonce' ); 
  3961.  
  3962. /** 
  3963. * @since 1.0.0 
  3964. * 
  3965. * @return mixed|void 
  3966. */ 
  3967. function bp_get_group_member_pagination() { 
  3968. global $members_template; 
  3969.  
  3970. /** 
  3971. * Filters the HTML markup to be used for group member listing pagination. 
  3972. * 
  3973. * @since 1.0.0 
  3974. * 
  3975. * @param string $pag_links HTML markup for the pagination. 
  3976. */ 
  3977. return apply_filters( 'bp_get_group_member_pagination', $members_template->pag_links ); 
  3978.  
  3979. /** 
  3980. * @since 1.0.0 
  3981. */ 
  3982. function bp_group_member_pagination_count() { 
  3983. echo bp_get_group_member_pagination_count(); 
  3984.  
  3985. /** 
  3986. * @since 1.0.0 
  3987. * 
  3988. * @return mixed|void 
  3989. */ 
  3990. function bp_get_group_member_pagination_count() { 
  3991. global $members_template; 
  3992.  
  3993. $start_num = intval( ( $members_template->pag_page - 1 ) * $members_template->pag_num ) + 1; 
  3994. $from_num = bp_core_number_format( $start_num ); 
  3995. $to_num = bp_core_number_format( ( $start_num + ( $members_template->pag_num - 1 ) > $members_template->total_member_count ) ? $members_template->total_member_count : $start_num + ( $members_template->pag_num - 1 ) ); 
  3996. $total = bp_core_number_format( $members_template->total_member_count ); 
  3997.  
  3998. if ( 1 == $members_template->total_member_count ) { 
  3999. $message = __( 'Viewing 1 member', 'buddypress' ); 
  4000. } else { 
  4001. $message = sprintf( _n( 'Viewing %1$s - %2$s of %3$s member', 'Viewing %1$s - %2$s of %3$s members', $members_template->total_member_count, 'buddypress' ), $from_num, $to_num, $total ); 
  4002.  
  4003. /** 
  4004. * Filters the "Viewing x-y of z members" pagination message. 
  4005. * 
  4006. * @since 1.0.0 
  4007. * 
  4008. * @param string $value "Viewing x-y of z members" text. 
  4009. * @param string $from_num Total amount for the low value in the range. 
  4010. * @param string $to_num Total amount for the high value in the range. 
  4011. * @param string $total Total amount of members found. 
  4012. */ 
  4013. return apply_filters( 'bp_get_group_member_pagination_count', $message, $from_num, $to_num, $total ); 
  4014.  
  4015. /** 
  4016. * @since 1.0.0 
  4017. */ 
  4018. function bp_group_member_admin_pagination() { 
  4019. echo bp_get_group_member_admin_pagination(); 
  4020. wp_nonce_field( 'bp_groups_member_admin_list', '_member_admin_pag_nonce' ); 
  4021.  
  4022. /** 
  4023. * @since 1.0.0 
  4024. * 
  4025. * @return mixed 
  4026. */ 
  4027. function bp_get_group_member_admin_pagination() { 
  4028. global $members_template; 
  4029.  
  4030. return $members_template->pag_links; 
  4031.  
  4032. /** 
  4033. * Output the contents of the current group's home page. 
  4034. * 
  4035. * You should only use this when on a single group page. 
  4036. * 
  4037. * @since 2.4.0 
  4038. */ 
  4039. function bp_groups_front_template_part() { 
  4040. $located = bp_groups_get_front_template(); 
  4041.  
  4042. if ( false !== $located ) { 
  4043. $slug = str_replace( '.php', '', $located ); 
  4044.  
  4045. /** 
  4046. * Let plugins adding an action to bp_get_template_part get it from here 
  4047. * 
  4048. * @param string $slug Template part slug requested. 
  4049. * @param string $name Template part name requested. 
  4050. */ 
  4051. do_action( 'get_template_part_' . $slug, $slug, false ); 
  4052.  
  4053. load_template( $located, true ); 
  4054.  
  4055. } else if ( bp_is_active( 'activity' ) ) { 
  4056. bp_get_template_part( 'groups/single/activity' ); 
  4057.  
  4058. } else if ( bp_is_active( 'members' ) ) { 
  4059. bp_groups_members_template_part(); 
  4060.  
  4061. return $located; 
  4062.  
  4063. /** 
  4064. * Locate a custom group front template if it exists. 
  4065. * 
  4066. * @since 2.4.0 
  4067. * @since 2.6.0 Adds the Group Type to the front template hierarchy. 
  4068. * 
  4069. * @param BP_Groups_Group|null $group Optional. Falls back to current group if not passed. 
  4070. * @return string|bool Path to front template on success; boolean false on failure. 
  4071. */ 
  4072. function bp_groups_get_front_template( $group = null ) { 
  4073. if ( ! is_a( $group, 'BP_Groups_Group' ) ) { 
  4074. $group = groups_get_current_group(); 
  4075.  
  4076. if ( ! isset( $group->id ) ) { 
  4077. return false; 
  4078.  
  4079. if ( isset( $group->front_template ) ) { 
  4080. return $group->front_template; 
  4081.  
  4082. $template_names = array( 
  4083. 'groups/single/front-id-' . sanitize_file_name( $group->id ) . '.php',  
  4084. 'groups/single/front-slug-' . sanitize_file_name( $group->slug ) . '.php',  
  4085. ); 
  4086.  
  4087. if ( bp_groups_get_group_types() ) { 
  4088. $group_type = bp_groups_get_group_type( $group->id ); 
  4089. if ( ! $group_type ) { 
  4090. $group_type = 'none'; 
  4091.  
  4092. $template_names[] = 'groups/single/front-group-type-' . sanitize_file_name( $group_type ) . '.php'; 
  4093.  
  4094. $template_names = array_merge( $template_names, array( 
  4095. 'groups/single/front-status-' . sanitize_file_name( $group->status ) . '.php',  
  4096. 'groups/single/front.php' 
  4097. ) ); 
  4098.  
  4099. /** 
  4100. * Filters the hierarchy of group front templates corresponding to a specific group. 
  4101. * 
  4102. * @since 2.4.0 
  4103. * @since 2.5.0 Added the `$group` parameter. 
  4104. * 
  4105. * @param array $template_names Array of template paths. 
  4106. * @param object $group Group object. 
  4107. */ 
  4108. return bp_locate_template( apply_filters( 'bp_groups_get_front_template', $template_names, $group ), false, true ); 
  4109.  
  4110. /** 
  4111. * Output the Group members template 
  4112. * 
  4113. * @since 2.0.0 
  4114. */ 
  4115. function bp_groups_members_template_part() { 
  4116. ?> 
  4117. <div class="item-list-tabs" id="subnav" aria-label="<?php esc_attr_e( 'Group secondary navigation', 'buddypress' ); ?>" role="navigation"> 
  4118. <ul> 
  4119. <li class="groups-members-search" role="search"> 
  4120. <?php bp_directory_members_search_form(); ?> 
  4121. </li> 
  4122.  
  4123. <?php bp_groups_members_filter(); ?> 
  4124. <?php 
  4125.  
  4126. /** 
  4127. * Fires at the end of the group members search unordered list. 
  4128. * 
  4129. * Part of bp_groups_members_template_part(). 
  4130. * 
  4131. * @since 1.5.0 
  4132. */ 
  4133. do_action( 'bp_members_directory_member_sub_types' ); ?> 
  4134.  
  4135. </ul> 
  4136. </div> 
  4137.  
  4138. <h2 class="bp-screen-reader-text"><?php 
  4139. /** translators: accessibility text */ 
  4140. _e( 'Members', 'buddypress' ); 
  4141. ?></h2> 
  4142.  
  4143. <div id="members-group-list" class="group_members dir-list"> 
  4144.  
  4145. <?php bp_get_template_part( 'groups/single/members' ); ?> 
  4146.  
  4147. </div> 
  4148. <?php 
  4149.  
  4150. /** 
  4151. * Output the Group members filters 
  4152. * 
  4153. * @since 2.0.0 
  4154. */ 
  4155. function bp_groups_members_filter() { 
  4156. ?> 
  4157. <li id="group_members-order-select" class="last filter"> 
  4158. <label for="group_members-order-by"><?php _e( 'Order By:', 'buddypress' ); ?></label> 
  4159. <select id="group_members-order-by"> 
  4160. <option value="last_joined"><?php _e( 'Newest', 'buddypress' ); ?></option> 
  4161. <option value="first_joined"><?php _e( 'Oldest', 'buddypress' ); ?></option> 
  4162.  
  4163. <?php if ( bp_is_active( 'activity' ) ) : ?> 
  4164. <option value="group_activity"><?php _e( 'Group Activity', 'buddypress' ); ?></option> 
  4165. <?php endif; ?> 
  4166.  
  4167. <option value="alphabetical"><?php _e( 'Alphabetical', 'buddypress' ); ?></option> 
  4168.  
  4169. <?php 
  4170.  
  4171. /** 
  4172. * Fires at the end of the Group members filters select input. 
  4173. * 
  4174. * Useful for plugins to add more filter options. 
  4175. * 
  4176. * @since 2.0.0 
  4177. */ 
  4178. do_action( 'bp_groups_members_order_options' ); ?> 
  4179.  
  4180. </select> 
  4181. </li> 
  4182. <?php 
  4183.  
  4184. /** 
  4185. * Group Creation Process Template Tags 
  4186. */ 
  4187.  
  4188. /** 
  4189. * Determine if the current logged in user can create groups. 
  4190. * 
  4191. * @since 1.5.0 
  4192. * 
  4193. * @return bool True if user can create groups. False otherwise. 
  4194. */ 
  4195. function bp_user_can_create_groups() { 
  4196.  
  4197. // Super admin can always create groups. 
  4198. if ( bp_current_user_can( 'bp_moderate' ) ) { 
  4199. return true; 
  4200.  
  4201. // Get group creation option, default to 0 (allowed). 
  4202. $restricted = (int) bp_get_option( 'bp_restrict_group_creation', 0 ); 
  4203.  
  4204. // Allow by default. 
  4205. $can_create = true; 
  4206.  
  4207. // Are regular users restricted? 
  4208. if ( $restricted ) { 
  4209. $can_create = false; 
  4210.  
  4211. /** 
  4212. * Filters if the current logged in user can create groups. 
  4213. * 
  4214. * @since 1.5.0 
  4215. * 
  4216. * @param bool $can_create Whether the person can create groups. 
  4217. * @param int $restricted Whether or not group creation is restricted. 
  4218. */ 
  4219. return apply_filters( 'bp_user_can_create_groups', $can_create, $restricted ); 
  4220.  
  4221. /** 
  4222. * @since 1.0.0 
  4223. * 
  4224. * @return bool 
  4225. */ 
  4226. function bp_group_creation_tabs() { 
  4227. $bp = buddypress(); 
  4228.  
  4229. if ( !is_array( $bp->groups->group_creation_steps ) ) { 
  4230. return false; 
  4231.  
  4232. if ( !bp_get_groups_current_create_step() ) { 
  4233. $keys = array_keys( $bp->groups->group_creation_steps ); 
  4234. $bp->groups->current_create_step = array_shift( $keys ); 
  4235.  
  4236. $counter = 1; 
  4237.  
  4238. foreach ( (array) $bp->groups->group_creation_steps as $slug => $step ) { 
  4239. $is_enabled = bp_are_previous_group_creation_steps_complete( $slug ); ?> 
  4240.  
  4241. <li<?php if ( bp_get_groups_current_create_step() == $slug ) : ?> class="current"<?php endif; ?>><?php if ( $is_enabled ) : ?><a href="<?php bp_groups_directory_permalink(); ?>create/step/<?php echo $slug ?>/"><?php else: ?><span><?php endif; ?><?php echo $counter ?>. <?php echo $step['name'] ?><?php if ( $is_enabled ) : ?></a><?php else: ?></span><?php endif ?></li><?php 
  4242. $counter++; 
  4243.  
  4244. unset( $is_enabled ); 
  4245.  
  4246. /** 
  4247. * Fires at the end of the creation of the group tabs. 
  4248. * 
  4249. * @since 1.0.0 
  4250. */ 
  4251. do_action( 'groups_creation_tabs' ); 
  4252.  
  4253. /** 
  4254. * @since 1.0.0 
  4255. */ 
  4256. function bp_group_creation_stage_title() { 
  4257. $bp = buddypress(); 
  4258.  
  4259. /** 
  4260. * Filters the group creation stage title. 
  4261. * 
  4262. * @since 1.1.0 
  4263. * 
  4264. * @param string $value HTML markup for the group creation stage title. 
  4265. */ 
  4266. echo apply_filters( 'bp_group_creation_stage_title', '<span>— ' . $bp->groups->group_creation_steps[bp_get_groups_current_create_step()]['name'] . '</span>' ); 
  4267.  
  4268. /** 
  4269. * @since 1.1.0 
  4270. */ 
  4271. function bp_group_creation_form_action() { 
  4272. echo bp_get_group_creation_form_action(); 
  4273.  
  4274. /** 
  4275. * @since 1.1.0 
  4276. * 
  4277. * @return mixed|void 
  4278. */ 
  4279. function bp_get_group_creation_form_action() { 
  4280. $bp = buddypress(); 
  4281.  
  4282. if ( !bp_action_variable( 1 ) ) { 
  4283. $keys = array_keys( $bp->groups->group_creation_steps ); 
  4284. $bp->action_variables[1] = array_shift( $keys ); 
  4285.  
  4286. /** 
  4287. * Filters the group creation form action. 
  4288. * 
  4289. * @since 1.1.0 
  4290. * 
  4291. * @param string $value Action to be used with group creation form. 
  4292. */ 
  4293. return apply_filters( 'bp_get_group_creation_form_action', trailingslashit( bp_get_groups_directory_permalink() . 'create/step/' . bp_action_variable( 1 ) ) ); 
  4294.  
  4295. /** 
  4296. * @since 1.1.0 
  4297. * 
  4298. * @param string $step_slug 
  4299. * 
  4300. * @return bool 
  4301. */ 
  4302. function bp_is_group_creation_step( $step_slug ) { 
  4303.  
  4304. // Make sure we are in the groups component. 
  4305. if ( ! bp_is_groups_component() || ! bp_is_current_action( 'create' ) ) { 
  4306. return false; 
  4307.  
  4308. $bp = buddypress(); 
  4309.  
  4310. // If this the first step, we can just accept and return true. 
  4311. $keys = array_keys( $bp->groups->group_creation_steps ); 
  4312. if ( !bp_action_variable( 1 ) && array_shift( $keys ) == $step_slug ) { 
  4313. return true; 
  4314.  
  4315. // Before allowing a user to see a group creation step we must make sure 
  4316. // previous steps are completed. 
  4317. if ( !bp_is_first_group_creation_step() ) { 
  4318. if ( !bp_are_previous_group_creation_steps_complete( $step_slug ) ) { 
  4319. return false; 
  4320.  
  4321. // Check the current step against the step parameter. 
  4322. if ( bp_is_action_variable( $step_slug ) ) { 
  4323. return true; 
  4324.  
  4325. return false; 
  4326.  
  4327. /** 
  4328. * @since 1.1.0 
  4329. * 
  4330. * @param array $step_slugs 
  4331. * 
  4332. * @return bool 
  4333. */ 
  4334. function bp_is_group_creation_step_complete( $step_slugs ) { 
  4335. $bp = buddypress(); 
  4336.  
  4337. if ( !isset( $bp->groups->completed_create_steps ) ) { 
  4338. return false; 
  4339.  
  4340. if ( is_array( $step_slugs ) ) { 
  4341. $found = true; 
  4342.  
  4343. foreach ( (array) $step_slugs as $step_slug ) { 
  4344. if ( !in_array( $step_slug, $bp->groups->completed_create_steps ) ) { 
  4345. $found = false; 
  4346.  
  4347. return $found; 
  4348. } else { 
  4349. return in_array( $step_slugs, $bp->groups->completed_create_steps ); 
  4350.  
  4351. return true; 
  4352.  
  4353. /** 
  4354. * @since 1.1.0 
  4355. * 
  4356. * @param string $step_slug 
  4357. * 
  4358. * @return bool 
  4359. */ 
  4360. function bp_are_previous_group_creation_steps_complete( $step_slug ) { 
  4361. $bp = buddypress(); 
  4362.  
  4363. // If this is the first group creation step, return true. 
  4364. $keys = array_keys( $bp->groups->group_creation_steps ); 
  4365. if ( array_shift( $keys ) == $step_slug ) { 
  4366. return true; 
  4367.  
  4368. reset( $bp->groups->group_creation_steps ); 
  4369.  
  4370. $previous_steps = array(); 
  4371.  
  4372. // Get previous steps. 
  4373. foreach ( (array) $bp->groups->group_creation_steps as $slug => $name ) { 
  4374. if ( $slug === $step_slug ) { 
  4375. break; 
  4376.  
  4377. $previous_steps[] = $slug; 
  4378.  
  4379. return bp_is_group_creation_step_complete( $previous_steps ); 
  4380.  
  4381. /** 
  4382. * @since 1.1.0 
  4383. */ 
  4384. function bp_new_group_id() { 
  4385. echo bp_get_new_group_id(); 
  4386.  
  4387. /** 
  4388. * @since 1.1.0 
  4389. * 
  4390. * @return mixed|void 
  4391. */ 
  4392. function bp_get_new_group_id() { 
  4393. $bp = buddypress(); 
  4394. $new_group_id = isset( $bp->groups->new_group_id ) 
  4395. ? $bp->groups->new_group_id 
  4396. : 0; 
  4397.  
  4398. /** 
  4399. * Filters the new group ID. 
  4400. * 
  4401. * @since 1.1.0 
  4402. * 
  4403. * @param int $new_group_id ID of the new group. 
  4404. */ 
  4405. return (int) apply_filters( 'bp_get_new_group_id', $new_group_id ); 
  4406.  
  4407. /** 
  4408. * @since 1.1.0 
  4409. */ 
  4410. function bp_new_group_name() { 
  4411. echo bp_get_new_group_name(); 
  4412.  
  4413. /** 
  4414. * @since 1.1.0 
  4415. * 
  4416. * @return mixed|void 
  4417. */ 
  4418. function bp_get_new_group_name() { 
  4419. $bp = buddypress(); 
  4420. $name = isset( $bp->groups->current_group->name ) 
  4421. ? $bp->groups->current_group->name 
  4422. : ''; 
  4423.  
  4424. /** 
  4425. * Filters the new group name. 
  4426. * 
  4427. * @since 1.1.0 
  4428. * 
  4429. * @param string $name Name of the new group. 
  4430. */ 
  4431. return apply_filters( 'bp_get_new_group_name', $name ); 
  4432.  
  4433. /** 
  4434. * @since 1.1.0 
  4435. */ 
  4436. function bp_new_group_description() { 
  4437. echo bp_get_new_group_description(); 
  4438.  
  4439. /** 
  4440. * @since 1.1.0 
  4441. * 
  4442. * @return mixed|void 
  4443. */ 
  4444. function bp_get_new_group_description() { 
  4445. $bp = buddypress(); 
  4446. $description = isset( $bp->groups->current_group->description ) 
  4447. ? $bp->groups->current_group->description 
  4448. : ''; 
  4449.  
  4450. /** 
  4451. * Filters the new group description. 
  4452. * 
  4453. * @since 1.1.0 
  4454. * 
  4455. * @param string $name Description of the new group. 
  4456. */ 
  4457. return apply_filters( 'bp_get_new_group_description', $description ); 
  4458.  
  4459. /** 
  4460. * @since 1.1.0 
  4461. */ 
  4462. function bp_new_group_enable_forum() { 
  4463. echo bp_get_new_group_enable_forum(); 
  4464.  
  4465. /** 
  4466. * @since 1.1.0 
  4467. * 
  4468. * @return int 
  4469. */ 
  4470. function bp_get_new_group_enable_forum() { 
  4471. $bp = buddypress(); 
  4472. $forum = isset( $bp->groups->current_group->enable_forum ) 
  4473. ? $bp->groups->current_group->enable_forum 
  4474. : false; 
  4475.  
  4476. /** 
  4477. * Filters whether or not to enable forums for the new group. 
  4478. * 
  4479. * @since 1.1.0 
  4480. * 
  4481. * @param int $forum Whether or not to enable forums. 
  4482. */ 
  4483. return (int) apply_filters( 'bp_get_new_group_enable_forum', $forum ); 
  4484.  
  4485. /** 
  4486. * @since 1.1.0 
  4487. */ 
  4488. function bp_new_group_status() { 
  4489. echo bp_get_new_group_status(); 
  4490.  
  4491. /** 
  4492. * @since 1.1.0 
  4493. * 
  4494. * @return mixed|void 
  4495. */ 
  4496. function bp_get_new_group_status() { 
  4497. $bp = buddypress(); 
  4498. $status = isset( $bp->groups->current_group->status ) 
  4499. ? $bp->groups->current_group->status 
  4500. : 'public'; 
  4501.  
  4502. /** 
  4503. * Filters the new group status. 
  4504. * 
  4505. * @since 1.1.0 
  4506. * 
  4507. * @param string $status Status for the new group. 
  4508. */ 
  4509. return apply_filters( 'bp_get_new_group_status', $status ); 
  4510.  
  4511. /** 
  4512. * Output the avatar for the group currently being created 
  4513. * 
  4514. * @since 1.1.0 
  4515. * 
  4516. * @see bp_core_fetch_avatar() For more information on accepted arguments 
  4517. * 
  4518. * @param array|string $args See bp_core_fetch_avatar(). 
  4519. */ 
  4520. function bp_new_group_avatar( $args = '' ) { 
  4521. echo bp_get_new_group_avatar( $args ); 
  4522. /** 
  4523. * Return the avatar for the group currently being created 
  4524. * 
  4525. * @since 1.1.0 
  4526. * 
  4527. * @see bp_core_fetch_avatar() For a description of arguments and return values. 
  4528. * 
  4529. * @param array|string $args { 
  4530. * Arguments are listed here with an explanation of their defaults. 
  4531. * For more information about the arguments, see {@link bp_core_fetch_avatar()}. 
  4532. * 
  4533. * @type string $alt Default: 'Group photo'. 
  4534. * @type string $class Default: 'avatar'. 
  4535. * @type string $type Default: 'full'. 
  4536. * @type int|bool $width Default: false. 
  4537. * @type int|bool $height Default: false. 
  4538. * @type string $id Passed to $css_id parameter. Default: 'avatar-crop-preview'. 
  4539. * } 
  4540. * @return string The avatar for the group being created 
  4541. */ 
  4542. function bp_get_new_group_avatar( $args = '' ) { 
  4543.  
  4544. // Parse arguments. 
  4545. $r = bp_parse_args( $args, array( 
  4546. 'type' => 'full',  
  4547. 'width' => false,  
  4548. 'height' => false,  
  4549. 'class' => 'avatar',  
  4550. 'id' => 'avatar-crop-preview',  
  4551. 'alt' => __( 'Group photo', 'buddypress' ),  
  4552. ), 'get_new_group_avatar' ); 
  4553.  
  4554. // Merge parsed arguments with object specific data. 
  4555. $r = array_merge( $r, array( 
  4556. 'item_id' => bp_get_current_group_id(),  
  4557. 'object' => 'group',  
  4558. 'avatar_dir' => 'group-avatars',  
  4559. ) ); 
  4560.  
  4561. // Get the avatar. 
  4562. $avatar = bp_core_fetch_avatar( $r ); 
  4563.  
  4564. /** 
  4565. * Filters the new group avatar. 
  4566. * 
  4567. * @since 1.1.0 
  4568. * 
  4569. * @param string $avatar HTML markup for the new group avatar. 
  4570. * @param array $r Array of parsed arguments for the group avatar. 
  4571. * @param array $args Array of original arguments passed to the function. 
  4572. */ 
  4573. return apply_filters( 'bp_get_new_group_avatar', $avatar, $r, $args ); 
  4574.  
  4575. /** 
  4576. * Escape & output the URL to the previous group creation step 
  4577. * 
  4578. * @since 1.1.0 
  4579. */ 
  4580. function bp_group_creation_previous_link() { 
  4581. echo esc_url( bp_get_group_creation_previous_link() ); 
  4582. /** 
  4583. * Return the URL to the previous group creation step 
  4584. * 
  4585. * @since 1.1.0 
  4586. * 
  4587. * @return string 
  4588. */ 
  4589. function bp_get_group_creation_previous_link() { 
  4590. $bp = buddypress(); 
  4591. $steps = array_keys( $bp->groups->group_creation_steps ); 
  4592.  
  4593. // Loop through steps. 
  4594. foreach ( $steps as $slug ) { 
  4595.  
  4596. // Break when the current step is found. 
  4597. if ( bp_is_action_variable( $slug ) ) { 
  4598. break; 
  4599.  
  4600. // Add slug to previous steps. 
  4601. $previous_steps[] = $slug; 
  4602.  
  4603. // Generate the URL for the previous step. 
  4604. $group_directory = bp_get_groups_directory_permalink(); 
  4605. $create_step = 'create/step/'; 
  4606. $previous_step = array_pop( $previous_steps ); 
  4607. $url = trailingslashit( $group_directory . $create_step . $previous_step ); 
  4608.  
  4609. /** 
  4610. * Filters the permalink for the previous step with the group creation process. 
  4611. * 
  4612. * @since 1.1.0 
  4613. * 
  4614. * @param string $url Permalink for the previous step. 
  4615. */ 
  4616. return apply_filters( 'bp_get_group_creation_previous_link', $url ); 
  4617.  
  4618. /** 
  4619. * Echoes the current group creation step. 
  4620. * 
  4621. * @since 1.6.0 
  4622. */ 
  4623. function bp_groups_current_create_step() { 
  4624. echo bp_get_groups_current_create_step(); 
  4625. /** 
  4626. * Returns the current group creation step. If none is found, returns an empty string. 
  4627. * 
  4628. * @since 1.6.0 
  4629. * 
  4630. * 
  4631. * @return string $current_create_step 
  4632. */ 
  4633. function bp_get_groups_current_create_step() { 
  4634. $bp = buddypress(); 
  4635.  
  4636. if ( !empty( $bp->groups->current_create_step ) ) { 
  4637. $current_create_step = $bp->groups->current_create_step; 
  4638. } else { 
  4639. $current_create_step = ''; 
  4640.  
  4641. /** 
  4642. * Filters the current group creation step. 
  4643. * 
  4644. * If none is found, returns an empty string. 
  4645. * 
  4646. * @since 1.6.0 
  4647. * 
  4648. * @param string $current_create_step Current step in the group creation process. 
  4649. */ 
  4650. return apply_filters( 'bp_get_groups_current_create_step', $current_create_step ); 
  4651.  
  4652. /** 
  4653. * Is the user looking at the last step in the group creation process. 
  4654. * 
  4655. * @since 1.1.0 
  4656. * 
  4657. * @param string $step Step to compare. 
  4658. * @return bool True if yes, False if no 
  4659. */ 
  4660. function bp_is_last_group_creation_step( $step = '' ) { 
  4661.  
  4662. // Use current step, if no step passed. 
  4663. if ( empty( $step ) ) { 
  4664. $step = bp_get_groups_current_create_step(); 
  4665.  
  4666. // Get the last step. 
  4667. $bp = buddypress(); 
  4668. $steps = array_keys( $bp->groups->group_creation_steps ); 
  4669. $l_step = array_pop( $steps ); 
  4670.  
  4671. // Compare last step to step. 
  4672. $retval = ( $l_step === $step ); 
  4673.  
  4674. /** 
  4675. * Filters whether or not user is looking at last step in group creation process. 
  4676. * 
  4677. * @since 2.4.0 
  4678. * 
  4679. * @param bool $retval Whether or not we are looking at last step. 
  4680. * @param array $steps Array of steps from the group creation process. 
  4681. * @param string $step Step to compare. 
  4682. */ 
  4683. return (bool) apply_filters( 'bp_is_last_group_creation_step', $retval, $steps, $step ); 
  4684.  
  4685. /** 
  4686. * Is the user looking at the first step in the group creation process 
  4687. * 
  4688. * @since 1.1.0 
  4689. * 
  4690. * @param string $step Step to compare. 
  4691. * @return bool True if yes, False if no 
  4692. */ 
  4693. function bp_is_first_group_creation_step( $step = '' ) { 
  4694.  
  4695. // Use current step, if no step passed. 
  4696. if ( empty( $step ) ) { 
  4697. $step = bp_get_groups_current_create_step(); 
  4698.  
  4699. // Get the first step. 
  4700. $bp = buddypress(); 
  4701. $steps = array_keys( $bp->groups->group_creation_steps ); 
  4702. $f_step = array_shift( $steps ); 
  4703.  
  4704. // Compare first step to step. 
  4705. $retval = ( $f_step === $step ); 
  4706.  
  4707. /** 
  4708. * Filters whether or not user is looking at first step in group creation process. 
  4709. * 
  4710. * @since 2.4.0 
  4711. * 
  4712. * @param bool $retval Whether or not we are looking at first step. 
  4713. * @param array $steps Array of steps from the group creation process. 
  4714. * @param string $step Step to compare. 
  4715. */ 
  4716. return (bool) apply_filters( 'bp_is_first_group_creation_step', $retval, $steps, $step ); 
  4717.  
  4718. /** 
  4719. * Output a list of friends who can be invited to a group 
  4720. * 
  4721. * @since 1.0.0 
  4722. * 
  4723. * @param array $args Array of arguments for friends list output. 
  4724. */ 
  4725. function bp_new_group_invite_friend_list( $args = array() ) { 
  4726. echo bp_get_new_group_invite_friend_list( $args ); 
  4727. /** 
  4728. * Return a list of friends who can be invited to a group 
  4729. * 
  4730. * @since 1.0.0 
  4731. * 
  4732. * @param array $args Array of arguments for friends list output. 
  4733. * @return false|string HTML list of checkboxes, or false 
  4734. */ 
  4735. function bp_get_new_group_invite_friend_list( $args = array() ) { 
  4736.  
  4737. // Bail if no friends component. 
  4738. if ( ! bp_is_active( 'friends' ) ) { 
  4739. return false; 
  4740.  
  4741. // Parse arguments. 
  4742. $r = wp_parse_args( $args, array( 
  4743. 'user_id' => bp_loggedin_user_id(),  
  4744. 'group_id' => false,  
  4745. 'separator' => 'li' 
  4746. ) ); 
  4747.  
  4748. // No group passed, so look for new or current group ID's. 
  4749. if ( empty( $r['group_id'] ) ) { 
  4750. $bp = buddypress(); 
  4751. $r['group_id'] = ! empty( $bp->groups->new_group_id ) 
  4752. ? $bp->groups->new_group_id 
  4753. : $bp->groups->current_group->id; 
  4754.  
  4755. // Setup empty items array. 
  4756. $items = array(); 
  4757.  
  4758. // Get user's friends who are not in this group already. 
  4759. $friends = friends_get_friends_invite_list( $r['user_id'], $r['group_id'] ); 
  4760.  
  4761. if ( ! empty( $friends ) ) { 
  4762.  
  4763. // Get already invited users. 
  4764. $invites = groups_get_invites_for_group( $r['user_id'], $r['group_id'] ); 
  4765.  
  4766. for ( $i = 0, $count = count( $friends ); $i < $count; ++$i ) { 
  4767. $checked = in_array( (int) $friends[ $i ]['id'], (array) $invites ); 
  4768. $items[] = '<' . $r['separator'] . '><label for="f-' . esc_attr( $friends[ $i ]['id'] ) . '"><input' . checked( $checked, true, false ) . ' type="checkbox" name="friends[]" id="f-' . esc_attr( $friends[ $i ]['id'] ) . '" value="' . esc_attr( $friends[ $i ]['id'] ) . '" /> ' . esc_html( $friends[ $i ]['full_name'] ) . '</label></' . $r['separator'] . '>'; 
  4769.  
  4770. /** 
  4771. * Filters the array of friends who can be invited to a group. 
  4772. * 
  4773. * @since 2.4.0 
  4774. * 
  4775. * @param array $items Array of friends. 
  4776. * @param array $r Parsed arguments from bp_get_new_group_invite_friend_list() 
  4777. * @param array $args Unparsed arguments from bp_get_new_group_invite_friend_list() 
  4778. */ 
  4779. $invitable_friends = apply_filters( 'bp_get_new_group_invite_friend_list', $items, $r, $args ); 
  4780.  
  4781. if ( ! empty( $invitable_friends ) && is_array( $invitable_friends ) ) { 
  4782. $retval = implode( "\n", $invitable_friends ); 
  4783. } else { 
  4784. $retval = false; 
  4785.  
  4786. return $retval; 
  4787.  
  4788. /** 
  4789. * @since 1.0.0 
  4790. */ 
  4791. function bp_directory_groups_search_form() { 
  4792.  
  4793. $query_arg = bp_core_get_component_search_query_arg( 'groups' ); 
  4794.  
  4795. if ( ! empty( $_REQUEST[ $query_arg ] ) ) { 
  4796. $search_value = stripslashes( $_REQUEST[ $query_arg ] ); 
  4797. } else { 
  4798. $search_value = bp_get_search_default_text( 'groups' ); 
  4799.  
  4800. $search_form_html = '<form action="" method="get" id="search-groups-form"> 
  4801. <label for="groups_search"><input type="text" name="' . esc_attr( $query_arg ) . '" id="groups_search" placeholder="'. esc_attr( $search_value ) .'" /></label> 
  4802. <input type="submit" id="groups_search_submit" name="groups_search_submit" value="'. __( 'Search', 'buddypress' ) .'" /> 
  4803. </form>'; 
  4804.  
  4805. /** 
  4806. * Filters the HTML markup for the groups search form. 
  4807. * 
  4808. * @since 1.9.0 
  4809. * 
  4810. * @param string $search_form_html HTML markup for the search form. 
  4811. */ 
  4812. echo apply_filters( 'bp_directory_groups_search_form', $search_form_html ); 
  4813.  
  4814.  
  4815. /** 
  4816. * Displays group header tabs. 
  4817. * 
  4818. * @since 1.0.0 
  4819. * 
  4820. * @todo Deprecate? 
  4821. */ 
  4822. function bp_groups_header_tabs() { 
  4823. $user_groups = bp_displayed_user_domain() . bp_get_groups_slug(); ?> 
  4824.  
  4825. <li<?php if ( !bp_action_variable( 0 ) || bp_is_action_variable( 'recently-active', 0 ) ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( $user_groups . '/my-groups/recently-active' ); ?>"><?php _e( 'Recently Active', 'buddypress' ); ?></a></li> 
  4826. <li<?php if ( bp_is_action_variable( 'recently-joined', 0 ) ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( $user_groups . '/my-groups/recently-joined' ); ?>"><?php _e( 'Recently Joined', 'buddypress' ); ?></a></li> 
  4827. <li<?php if ( bp_is_action_variable( 'most-popular', 0 ) ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( $user_groups . '/my-groups/most-popular' ); ?>"><?php _e( 'Most Popular', 'buddypress' ); ?></a></li> 
  4828. <li<?php if ( bp_is_action_variable( 'admin-of', 0 ) ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( $user_groups . '/my-groups/admin-of' ); ?>"><?php _e( 'Administrator Of', 'buddypress' ); ?></a></li> 
  4829. <li<?php if ( bp_is_action_variable( 'mod-of', 0 ) ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( $user_groups . '/my-groups/mod-of' ); ?>"><?php _e( 'Moderator Of', 'buddypress' ); ?></a></li> 
  4830. <li<?php if ( bp_is_action_variable( 'alphabetically' ) ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( $user_groups . '/my-groups/alphabetically' ); ?>"><?php _e( 'Alphabetically', 'buddypress' ); ?></a></li> 
  4831.  
  4832. <?php 
  4833. do_action( 'groups_header_tabs' ); 
  4834.  
  4835. /** 
  4836. * Displays group filter titles. 
  4837. * 
  4838. * @since 1.0.0 
  4839. * 
  4840. * @todo Deprecate? 
  4841. */ 
  4842. function bp_groups_filter_title() { 
  4843. $current_filter = bp_action_variable( 0 ); 
  4844.  
  4845. switch ( $current_filter ) { 
  4846. case 'recently-active': default: 
  4847. _e( 'Recently Active', 'buddypress' ); 
  4848. break; 
  4849. case 'recently-joined': 
  4850. _e( 'Recently Joined', 'buddypress' ); 
  4851. break; 
  4852. case 'most-popular': 
  4853. _e( 'Most Popular', 'buddypress' ); 
  4854. break; 
  4855. case 'admin-of': 
  4856. _e( 'Administrator Of', 'buddypress' ); 
  4857. break; 
  4858. case 'mod-of': 
  4859. _e( 'Moderator Of', 'buddypress' ); 
  4860. break; 
  4861. case 'alphabetically': 
  4862. _e( 'Alphabetically', 'buddypress' ); 
  4863. break; 
  4864. do_action( 'bp_groups_filter_title' ); 
  4865.  
  4866. /** 
  4867. * Echo the current group type message. 
  4868. * 
  4869. * @since 2.7.0 
  4870. */ 
  4871. function bp_current_group_directory_type_message() { 
  4872. echo bp_get_current_group_directory_type_message(); 
  4873. /** 
  4874. * Generate the current group type message. 
  4875. * 
  4876. * @since 2.7.0 
  4877. * 
  4878. * @return string 
  4879. */ 
  4880. function bp_get_current_group_directory_type_message() { 
  4881. $type_object = bp_groups_get_group_type_object( bp_get_current_group_directory_type() ); 
  4882.  
  4883. $message = sprintf( __( 'Viewing groups of the type: %s', 'buddypress' ), '<strong>' . $type_object->labels['singular_name'] . '</strong>' ); 
  4884.  
  4885. /** 
  4886. * Filters the current group type message. 
  4887. * 
  4888. * @since 2.7.0 
  4889. * 
  4890. * @param string $message Message to filter. 
  4891. */ 
  4892. return apply_filters( 'bp_get_current_group_type_message', $message ); 
  4893.  
  4894. /** 
  4895. * Is the current page a specific group admin screen? 
  4896. * 
  4897. * @since 1.1.0 
  4898. * 
  4899. * @param string $slug Admin screen slug. 
  4900. * @return bool 
  4901. */ 
  4902. function bp_is_group_admin_screen( $slug = '' ) { 
  4903. return (bool) ( bp_is_group_admin_page() && bp_is_action_variable( $slug ) ); 
  4904.  
  4905. /** 
  4906. * Echoes the current group admin tab slug. 
  4907. * 
  4908. * @since 1.6.0 
  4909. */ 
  4910. function bp_group_current_admin_tab() { 
  4911. echo bp_get_group_current_admin_tab(); 
  4912. /** 
  4913. * Returns the current group admin tab slug. 
  4914. * 
  4915. * @since 1.6.0 
  4916. * 
  4917. * 
  4918. * @return string $tab The current tab's slug. 
  4919. */ 
  4920. function bp_get_group_current_admin_tab() { 
  4921. if ( bp_is_groups_component() && bp_is_current_action( 'admin' ) ) { 
  4922. $tab = bp_action_variable( 0 ); 
  4923. } else { 
  4924. $tab = ''; 
  4925.  
  4926. /** 
  4927. * Filters the current group admin tab slug. 
  4928. * 
  4929. * @since 1.6.0 
  4930. * 
  4931. * @param string $tab Current group admin tab slug. 
  4932. */ 
  4933. return apply_filters( 'bp_get_current_group_admin_tab', $tab ); 
  4934.  
  4935. /** Group Avatar Template Tags ************************************************/ 
  4936.  
  4937. /** 
  4938. * Outputs the current group avatar. 
  4939. * 
  4940. * @since 1.0.0 
  4941. * 
  4942. * @param string $type Thumb or full. 
  4943. */ 
  4944. function bp_group_current_avatar( $type = 'thumb' ) { 
  4945. echo bp_get_group_current_avatar( $type ); 
  4946. /** 
  4947. * Returns the current group avatar. 
  4948. * 
  4949. * @since 2.0.0 
  4950. * 
  4951. * @param string $type Thumb or full. 
  4952. * @return string $tab The current tab's slug. 
  4953. */ 
  4954. function bp_get_group_current_avatar( $type = 'thumb' ) { 
  4955.  
  4956. $group_avatar = bp_core_fetch_avatar( array( 
  4957. 'item_id' => bp_get_current_group_id(),  
  4958. 'object' => 'group',  
  4959. 'type' => $type,  
  4960. 'avatar_dir' => 'group-avatars',  
  4961. 'alt' => __( 'Group avatar', 'buddypress' ),  
  4962. 'class' => 'avatar' 
  4963. ) ); 
  4964.  
  4965. /** 
  4966. * Filters the current group avatar. 
  4967. * 
  4968. * @since 2.0.0 
  4969. * 
  4970. * @param string $group_avatar HTML markup for current group avatar. 
  4971. */ 
  4972. return apply_filters( 'bp_get_group_current_avatar', $group_avatar ); 
  4973.  
  4974. /** 
  4975. * Return whether a group has an avatar. 
  4976. * 
  4977. * @since 1.1.0 
  4978. * 
  4979. * @param int|bool $group_id Group ID to check. 
  4980. * @return boolean 
  4981. */ 
  4982. function bp_get_group_has_avatar( $group_id = false ) { 
  4983.  
  4984. if ( false === $group_id ) { 
  4985. $group_id = bp_get_current_group_id(); 
  4986.  
  4987. $avatar_args = array( 
  4988. 'item_id' => $group_id,  
  4989. 'object' => 'group',  
  4990. 'no_grav' => true,  
  4991. 'html' => false,  
  4992. 'type' => 'thumb',  
  4993. ); 
  4994.  
  4995. $group_avatar = bp_core_fetch_avatar( $avatar_args ); 
  4996.  
  4997. if ( bp_core_avatar_default( 'local', $avatar_args ) === $group_avatar ) { 
  4998. return false; 
  4999.  
  5000. return true; 
  5001.  
  5002. /** 
  5003. * @since 1.1.0 
  5004. */ 
  5005. function bp_group_avatar_delete_link() { 
  5006. echo bp_get_group_avatar_delete_link(); 
  5007.  
  5008. /** 
  5009. * @since 1.1.0 
  5010. * 
  5011. * @return mixed|void 
  5012. */ 
  5013. function bp_get_group_avatar_delete_link() { 
  5014. $bp = buddypress(); 
  5015.  
  5016. /** 
  5017. * Filters the URL to delete the group avatar. 
  5018. * 
  5019. * @since 1.1.0 
  5020. * 
  5021. * @param string $value URL to delete the group avatar. 
  5022. */ 
  5023. return apply_filters( 'bp_get_group_avatar_delete_link', wp_nonce_url( bp_get_group_permalink( $bp->groups->current_group ) . 'admin/group-avatar/delete', 'bp_group_avatar_delete' ) ); 
  5024.  
  5025. /** 
  5026. * @since 1.0.0 
  5027. */ 
  5028. function bp_custom_group_boxes() { 
  5029. do_action( 'groups_custom_group_boxes' ); 
  5030.  
  5031. /** 
  5032. * @since 1.0.0 
  5033. */ 
  5034. function bp_custom_group_admin_tabs() { 
  5035. do_action( 'groups_custom_group_admin_tabs' ); 
  5036.  
  5037. /** 
  5038. * @since 1.0.0 
  5039. */ 
  5040. function bp_custom_group_fields_editable() { 
  5041. do_action( 'groups_custom_group_fields_editable' ); 
  5042.  
  5043. /** 
  5044. * @since 1.0.0 
  5045. */ 
  5046. function bp_custom_group_fields() { 
  5047. do_action( 'groups_custom_group_fields' ); 
  5048.  
  5049. /** Group Membership Requests *************************************************/ 
  5050.  
  5051. /** 
  5052. * Initialize a group membership request template loop. 
  5053. * 
  5054. * @since 1.0.0 
  5055. * 
  5056. * @param array|string $args { 
  5057. * @type int $group_id ID of the group. Defaults to current group. 
  5058. * @type int $per_page Number of records to return per page. Default: 10. 
  5059. * @type int $page Page of results to return. Default: 1. 
  5060. * @type int $max Max number of items to return. Default: false. 
  5061. * } 
  5062. * @return bool True if there are requests, otherwise false. 
  5063. */ 
  5064. function bp_group_has_membership_requests( $args = '' ) { 
  5065. global $requests_template; 
  5066.  
  5067. $defaults = array( 
  5068. 'group_id' => bp_get_current_group_id(),  
  5069. 'per_page' => 10,  
  5070. 'page' => 1,  
  5071. 'max' => false 
  5072. ); 
  5073.  
  5074. $r = wp_parse_args( $args, $defaults ); 
  5075.  
  5076. $requests_template = new BP_Groups_Membership_Requests_Template( $r ); 
  5077.  
  5078. /** 
  5079. * Filters whether or not a group membership query has requests to display. 
  5080. * 
  5081. * @since 1.1.0 
  5082. * 
  5083. * @param bool $value Whether there are requests to display. 
  5084. * @param BP_Groups_Membership_Requests_Template $requests_template Object holding the requests query results. 
  5085. */ 
  5086. return apply_filters( 'bp_group_has_membership_requests', $requests_template->has_requests(), $requests_template ); 
  5087.  
  5088. /** 
  5089. * @since 1.0.0 
  5090. * 
  5091. * @return mixed 
  5092. */ 
  5093. function bp_group_membership_requests() { 
  5094. global $requests_template; 
  5095.  
  5096. return $requests_template->requests(); 
  5097.  
  5098. /** 
  5099. * @since 1.0.0 
  5100. * 
  5101. * @return mixed 
  5102. */ 
  5103. function bp_group_the_membership_request() { 
  5104. global $requests_template; 
  5105.  
  5106. return $requests_template->the_request(); 
  5107.  
  5108. /** 
  5109. * @since 1.0.0 
  5110. */ 
  5111. function bp_group_request_user_avatar_thumb() { 
  5112. global $requests_template; 
  5113.  
  5114. /** 
  5115. * Filters the requesting user's avatar thumbnail. 
  5116. * 
  5117. * @since 1.0.0 
  5118. * 
  5119. * @param string $value HTML markup for the user's avatar thumbnail. 
  5120. */ 
  5121. echo apply_filters( 'bp_group_request_user_avatar_thumb', bp_core_fetch_avatar( array( 'item_id' => $requests_template->request->user_id, 'type' => 'thumb', 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_core_get_user_displayname( $requests_template->request->user_id ) ) ) ) ); 
  5122.  
  5123. /** 
  5124. * @since 1.0.0 
  5125. */ 
  5126. function bp_group_request_reject_link() { 
  5127. echo bp_get_group_request_reject_link(); 
  5128.  
  5129. /** 
  5130. * @since 1.2.6 
  5131. * 
  5132. * @return mixed|void 
  5133. */ 
  5134. function bp_get_group_request_reject_link() { 
  5135. global $requests_template; 
  5136.  
  5137. /** 
  5138. * Filters the URL to use to reject a membership request. 
  5139. * 
  5140. * @since 1.2.6 
  5141. * 
  5142. * @param string $value URL to use to reject a membership request. 
  5143. */ 
  5144. return apply_filters( 'bp_get_group_request_reject_link', wp_nonce_url( bp_get_group_permalink( groups_get_current_group() ) . 'admin/membership-requests/reject/' . $requests_template->request->membership_id, 'groups_reject_membership_request' ) ); 
  5145.  
  5146. /** 
  5147. * @since 1.0.0 
  5148. */ 
  5149. function bp_group_request_accept_link() { 
  5150. echo bp_get_group_request_accept_link(); 
  5151.  
  5152. /** 
  5153. * @since 1.2.6 
  5154. * @return mixed|void 
  5155. */ 
  5156. function bp_get_group_request_accept_link() { 
  5157. global $requests_template; 
  5158.  
  5159. /** 
  5160. * Filters the URL to use to accept a membership request. 
  5161. * 
  5162. * @since 1.2.6 
  5163. * 
  5164. * @param string $value URL to use to accept a membership request. 
  5165. */ 
  5166. return apply_filters( 'bp_get_group_request_accept_link', wp_nonce_url( bp_get_group_permalink( groups_get_current_group() ) . 'admin/membership-requests/accept/' . $requests_template->request->membership_id, 'groups_accept_membership_request' ) ); 
  5167.  
  5168. /** 
  5169. * @since 1.0.0 
  5170. */ 
  5171. function bp_group_request_user_link() { 
  5172. echo bp_get_group_request_user_link(); 
  5173.  
  5174. /** 
  5175. * @since 1.2.6 
  5176. * 
  5177. * @return mixed|void 
  5178. */ 
  5179. function bp_get_group_request_user_link() { 
  5180. global $requests_template; 
  5181.  
  5182. /** 
  5183. * Filters the URL for the user requesting membership. 
  5184. * 
  5185. * @since 1.2.6 
  5186. * 
  5187. * @param string $value URL for the user requestion membership. 
  5188. */ 
  5189. return apply_filters( 'bp_get_group_request_user_link', bp_core_get_userlink( $requests_template->request->user_id ) ); 
  5190.  
  5191. /** 
  5192. * @since 1.0.0 
  5193. */ 
  5194. function bp_group_request_time_since_requested() { 
  5195. global $requests_template; 
  5196.  
  5197. /** 
  5198. * Filters the formatted time since membership was requested. 
  5199. * 
  5200. * @since 1.0.0 
  5201. * 
  5202. * @param string $value Formatted time since membership was requested. 
  5203. */ 
  5204. echo apply_filters( 'bp_group_request_time_since_requested', sprintf( __( 'requested %s', 'buddypress' ), bp_core_time_since( $requests_template->request->date_modified ) ) ); 
  5205.  
  5206. /** 
  5207. * @since 1.0.0 
  5208. */ 
  5209. function bp_group_request_comment() { 
  5210. global $requests_template; 
  5211.  
  5212. /** 
  5213. * Filters the membership request comment left by user. 
  5214. * 
  5215. * @since 1.0.0 
  5216. * 
  5217. * @param string $value Membership request comment left by user. 
  5218. */ 
  5219. echo apply_filters( 'bp_group_request_comment', strip_tags( stripslashes( $requests_template->request->comments ) ) ); 
  5220.  
  5221. /** 
  5222. * Output pagination links for group membership requests. 
  5223. * 
  5224. * @since 2.0.0 
  5225. */ 
  5226. function bp_group_requests_pagination_links() { 
  5227. echo bp_get_group_requests_pagination_links(); 
  5228. /** 
  5229. * Get pagination links for group membership requests. 
  5230. * 
  5231. * @since 2.0.0 
  5232. * 
  5233. * @return string 
  5234. */ 
  5235. function bp_get_group_requests_pagination_links() { 
  5236. global $requests_template; 
  5237.  
  5238. /** 
  5239. * Filters pagination links for group membership requests. 
  5240. * 
  5241. * @since 2.0.0 
  5242. * 
  5243. * @param string $value Pagination links for group membership requests. 
  5244. */ 
  5245. return apply_filters( 'bp_get_group_requests_pagination_links', $requests_template->pag_links ); 
  5246.  
  5247. /** 
  5248. * Output pagination count text for group membership requests. 
  5249. * 
  5250. * @since 2.0.0 
  5251. */ 
  5252. function bp_group_requests_pagination_count() { 
  5253. echo bp_get_group_requests_pagination_count(); 
  5254. /** 
  5255. * Get pagination count text for group membership requests. 
  5256. * 
  5257. * @since 2.0.0 
  5258. * 
  5259. * @return string 
  5260. */ 
  5261. function bp_get_group_requests_pagination_count() { 
  5262. global $requests_template; 
  5263.  
  5264. $start_num = intval( ( $requests_template->pag_page - 1 ) * $requests_template->pag_num ) + 1; 
  5265. $from_num = bp_core_number_format( $start_num ); 
  5266. $to_num = bp_core_number_format( ( $start_num + ( $requests_template->pag_num - 1 ) > $requests_template->total_request_count ) ? $requests_template->total_request_count : $start_num + ( $requests_template->pag_num - 1 ) ); 
  5267. $total = bp_core_number_format( $requests_template->total_request_count ); 
  5268.  
  5269. if ( 1 == $requests_template->total_request_count ) { 
  5270. $message = __( 'Viewing 1 request', 'buddypress' ); 
  5271. } else { 
  5272. $message = sprintf( _n( 'Viewing %1$s - %2$s of %3$s request', 'Viewing %1$s - %2$s of %3$s requests', $requests_template->total_request_count, 'buddypress' ), $from_num, $to_num, $total ); 
  5273.  
  5274. /** 
  5275. * Filters pagination count text for group membership requests. 
  5276. * 
  5277. * @since 2.0.0 
  5278. * 
  5279. * @param string $message Pagination count text for group membership requests. 
  5280. * @param string $from_num Total amount for the low value in the range. 
  5281. * @param string $to_num Total amount for the high value in the range. 
  5282. * @param string $total Total amount of members found. 
  5283. */ 
  5284. return apply_filters( 'bp_get_group_requests_pagination_count', $message, $from_num, $to_num, $total ); 
  5285.  
  5286. /** Group Invitations *********************************************************/ 
  5287.  
  5288. /** 
  5289. * Whether or not there are invites. 
  5290. * 
  5291. * @since 1.1.0 
  5292. * 
  5293. * @param string $args 
  5294. * @return bool|mixed|void 
  5295. */ 
  5296. function bp_group_has_invites( $args = '' ) { 
  5297. global $invites_template, $group_id; 
  5298.  
  5299. $r = wp_parse_args( $args, array( 
  5300. 'group_id' => false,  
  5301. 'user_id' => bp_loggedin_user_id(),  
  5302. 'per_page' => false,  
  5303. 'page' => 1,  
  5304. ) ); 
  5305.  
  5306. if ( empty( $r['group_id'] ) ) { 
  5307. if ( groups_get_current_group() ) { 
  5308. $r['group_id'] = bp_get_current_group_id(); 
  5309. } elseif ( ! empty( buddypress()->groups->new_group_id ) ) { 
  5310. $r['group_id'] = buddypress()->groups->new_group_id; 
  5311.  
  5312. // Set the global (for use in BP_Groups_Invite_Template::the_invite()). 
  5313. if ( empty( $group_id ) ) { 
  5314. $group_id = $r['group_id']; 
  5315.  
  5316. if ( ! $group_id ) { 
  5317. return false; 
  5318.  
  5319. $invites_template = new BP_Groups_Invite_Template( $r ); 
  5320.  
  5321. /** 
  5322. * Filters whether or not a group invites query has invites to display. 
  5323. * 
  5324. * @since 1.1.0 
  5325. * 
  5326. * @param bool $value Whether there are requests to display. 
  5327. * @param BP_Groups_Invite_Template $invites_template Object holding the invites query results. 
  5328. */ 
  5329. return apply_filters( 'bp_group_has_invites', $invites_template->has_invites(), $invites_template ); 
  5330.  
  5331. /** 
  5332. * @since 1.1.0 
  5333. * 
  5334. * @return mixed 
  5335. */ 
  5336. function bp_group_invites() { 
  5337. global $invites_template; 
  5338.  
  5339. return $invites_template->invites(); 
  5340.  
  5341. /** 
  5342. * @since 1.1.0 
  5343. * 
  5344. * @return mixed 
  5345. */ 
  5346. function bp_group_the_invite() { 
  5347. global $invites_template; 
  5348.  
  5349. return $invites_template->the_invite(); 
  5350.  
  5351. /** 
  5352. * @since 1.1.0 
  5353. */ 
  5354. function bp_group_invite_item_id() { 
  5355. echo bp_get_group_invite_item_id(); 
  5356.  
  5357. /** 
  5358. * @since 1.1.0 
  5359. * 
  5360. * @return mixed|void 
  5361. */ 
  5362. function bp_get_group_invite_item_id() { 
  5363. global $invites_template; 
  5364.  
  5365. /** 
  5366. * Filters the group invite item ID. 
  5367. * 
  5368. * @since 1.1.0 
  5369. * 
  5370. * @param string $value Group invite item ID. 
  5371. */ 
  5372. return apply_filters( 'bp_get_group_invite_item_id', 'uid-' . $invites_template->invite->user->id ); 
  5373.  
  5374. /** 
  5375. * @since 1.1.0 
  5376. */ 
  5377. function bp_group_invite_user_avatar() { 
  5378. echo bp_get_group_invite_user_avatar(); 
  5379.  
  5380. /** 
  5381. * @since 1.1.0 
  5382. * 
  5383. * @return mixed|void 
  5384. */ 
  5385. function bp_get_group_invite_user_avatar() { 
  5386. global $invites_template; 
  5387.  
  5388. /** 
  5389. * Filters the group invite user avatar. 
  5390. * 
  5391. * @since 1.1.0 
  5392. * 
  5393. * @param string $value Group invite user avatar. 
  5394. */ 
  5395. return apply_filters( 'bp_get_group_invite_user_avatar', $invites_template->invite->user->avatar_thumb ); 
  5396.  
  5397. /** 
  5398. * @since 1.1.0 
  5399. */ 
  5400. function bp_group_invite_user_link() { 
  5401. echo bp_get_group_invite_user_link(); 
  5402.  
  5403. /** 
  5404. * @since 1.1.0 
  5405. * 
  5406. * @return mixed|void 
  5407. */ 
  5408. function bp_get_group_invite_user_link() { 
  5409. global $invites_template; 
  5410.  
  5411. /** 
  5412. * Filters the group invite user link. 
  5413. * 
  5414. * @since 1.1.0 
  5415. * 
  5416. * @param string $value Group invite user link. 
  5417. */ 
  5418. return apply_filters( 'bp_get_group_invite_user_link', bp_core_get_userlink( $invites_template->invite->user->id ) ); 
  5419.  
  5420. /** 
  5421. * @since 1.1.0 
  5422. */ 
  5423. function bp_group_invite_user_last_active() { 
  5424. echo bp_get_group_invite_user_last_active(); 
  5425.  
  5426. /** 
  5427. * @since 1.1.0 
  5428. * 
  5429. * @return mixed|void 
  5430. */ 
  5431. function bp_get_group_invite_user_last_active() { 
  5432. global $invites_template; 
  5433.  
  5434. /** 
  5435. * Filters the group invite user's last active time. 
  5436. * 
  5437. * @since 1.1.0 
  5438. * 
  5439. * @param string $value Group invite user's last active time. 
  5440. */ 
  5441. return apply_filters( 'bp_get_group_invite_user_last_active', $invites_template->invite->user->last_active ); 
  5442.  
  5443. /** 
  5444. * @since 1.1.0 
  5445. */ 
  5446. function bp_group_invite_user_remove_invite_url() { 
  5447. echo bp_get_group_invite_user_remove_invite_url(); 
  5448.  
  5449. /** 
  5450. * @since 1.1.0 
  5451. * 
  5452. * @return string 
  5453. */ 
  5454. function bp_get_group_invite_user_remove_invite_url() { 
  5455. global $invites_template; 
  5456.  
  5457. $user_id = intval( $invites_template->invite->user->id ); 
  5458.  
  5459. if ( bp_is_current_action( 'create' ) ) { 
  5460. $uninvite_url = bp_get_groups_directory_permalink() . 'create/step/group-invites/?user_id=' . $user_id; 
  5461. } else { 
  5462. $uninvite_url = bp_get_group_permalink( groups_get_current_group() ) . 'send-invites/remove/' . $user_id; 
  5463.  
  5464. return wp_nonce_url( $uninvite_url, 'groups_invite_uninvite_user' ); 
  5465.  
  5466. /** 
  5467. * Output pagination links for group invitations. 
  5468. * 
  5469. * @since 2.0.0 
  5470. */ 
  5471. function bp_group_invite_pagination_links() { 
  5472. echo bp_get_group_invite_pagination_links(); 
  5473.  
  5474. /** 
  5475. * Get pagination links for group invitations. 
  5476. * 
  5477. * @since 2.0.0 
  5478. * 
  5479. * @return string 
  5480. */ 
  5481. function bp_get_group_invite_pagination_links() { 
  5482. global $invites_template; 
  5483.  
  5484. /** 
  5485. * Filters the pagination links for group invitations. 
  5486. * 
  5487. * @since 2.0.0 
  5488. * 
  5489. * @param string $value Pagination links for group invitations. 
  5490. */ 
  5491. return apply_filters( 'bp_get_group_invite_pagination_links', $invites_template->pag_links ); 
  5492.  
  5493. /** 
  5494. * Output pagination count text for group invitations. 
  5495. * 
  5496. * @since 2.0.0 
  5497. */ 
  5498. function bp_group_invite_pagination_count() { 
  5499. echo bp_get_group_invite_pagination_count(); 
  5500. /** 
  5501. * Get pagination count text for group invitations. 
  5502. * 
  5503. * @since 2.0.0 
  5504. * 
  5505. * @return string 
  5506. */ 
  5507. function bp_get_group_invite_pagination_count() { 
  5508. global $invites_template; 
  5509.  
  5510. $start_num = intval( ( $invites_template->pag_page - 1 ) * $invites_template->pag_num ) + 1; 
  5511. $from_num = bp_core_number_format( $start_num ); 
  5512. $to_num = bp_core_number_format( ( $start_num + ( $invites_template->pag_num - 1 ) > $invites_template->total_invite_count ) ? $invites_template->total_invite_count : $start_num + ( $invites_template->pag_num - 1 ) ); 
  5513. $total = bp_core_number_format( $invites_template->total_invite_count ); 
  5514.  
  5515. if ( 1 == $invites_template->total_invite_count ) { 
  5516. $message = __( 'Viewing 1 invitation', 'buddypress' ); 
  5517. } else { 
  5518. $message = sprintf( _n( 'Viewing %1$s - %2$s of %3$s invitation', 'Viewing %1$s - %2$s of %3$s invitations', $invites_template->total_invite_count, 'buddypress' ), $from_num, $to_num, $total ); 
  5519.  
  5520. /** This filter is documented in bp-groups/bp-groups-template.php */ 
  5521. return apply_filters( 'bp_get_groups_pagination_count', $message, $from_num, $to_num, $total ); 
  5522.  
  5523. /** Group RSS *****************************************************************/ 
  5524.  
  5525. /** 
  5526. * Hook group activity feed to <head>. 
  5527. * 
  5528. * @since 1.5.0 
  5529. */ 
  5530. function bp_groups_activity_feed() { 
  5531.  
  5532. // Bail if not viewing a single group or activity is not active. 
  5533. if ( ! bp_is_active( 'groups' ) || ! bp_is_active( 'activity' ) || ! bp_is_group() ) { 
  5534. return; 
  5535. } ?> 
  5536.  
  5537. <link rel="alternate" type="application/rss+xml" title="<?php bloginfo( 'name' ) ?> | <?php bp_current_group_name() ?> | <?php _e( 'Group Activity RSS Feed', 'buddypress' ) ?>" href="<?php bp_group_activity_feed_link() ?>" /> 
  5538.  
  5539. <?php 
  5540. add_action( 'bp_head', 'bp_groups_activity_feed' ); 
  5541.  
  5542. /** 
  5543. * Output the current group activity-stream RSS URL. 
  5544. * 
  5545. * @since 1.5.0 
  5546. */ 
  5547. function bp_group_activity_feed_link() { 
  5548. echo bp_get_group_activity_feed_link(); 
  5549. /** 
  5550. * Return the current group activity-stream RSS URL. 
  5551. * 
  5552. * @since 1.5.0 
  5553. * 
  5554. * @return string 
  5555. */ 
  5556. function bp_get_group_activity_feed_link() { 
  5557. $current_group = groups_get_current_group(); 
  5558. $group_link = bp_get_group_permalink( $current_group ) . 'feed'; 
  5559. $feed_link = trailingslashit( $group_link ); 
  5560.  
  5561. /** 
  5562. * Filters the current group activity-stream RSS URL. 
  5563. * 
  5564. * @since 1.2.0 
  5565. * 
  5566. * @param string $feed_link Current group activity-stream RSS URL. 
  5567. */ 
  5568. return apply_filters( 'bp_get_group_activity_feed_link', $feed_link ); 
  5569.  
  5570. /** Current Group *************************************************************/ 
  5571.  
  5572. /** 
  5573. * Echoes the output of bp_get_current_group_id(). 
  5574. * 
  5575. * @since 1.5.0 
  5576. */ 
  5577. function bp_current_group_id() { 
  5578. echo bp_get_current_group_id(); 
  5579. /** 
  5580. * Returns the ID of the current group. 
  5581. * 
  5582. * @since 1.5.0 
  5583. * 
  5584. * @return int $current_group_id The id of the current group, if there is one. 
  5585. */ 
  5586. function bp_get_current_group_id() { 
  5587. $current_group = groups_get_current_group(); 
  5588. $current_group_id = isset( $current_group->id ) ? (int) $current_group->id : 0; 
  5589.  
  5590. /** 
  5591. * Filters the ID of the current group. 
  5592. * 
  5593. * @since 1.5.0 
  5594. * 
  5595. * @param int $current_group_id ID of the current group. 
  5596. * @param object $current_group Instance holding the current group. 
  5597. */ 
  5598. return apply_filters( 'bp_get_current_group_id', $current_group_id, $current_group ); 
  5599.  
  5600. /** 
  5601. * Echoes the output of bp_get_current_group_slug(). 
  5602. * 
  5603. * @since 1.5.0 
  5604. */ 
  5605. function bp_current_group_slug() { 
  5606. echo bp_get_current_group_slug(); 
  5607. /** 
  5608. * Returns the slug of the current group. 
  5609. * 
  5610. * @since 1.5.0 
  5611. * 
  5612. * @return string $current_group_slug The slug of the current group, if there is one. 
  5613. */ 
  5614. function bp_get_current_group_slug() { 
  5615. $current_group = groups_get_current_group(); 
  5616. $current_group_slug = isset( $current_group->slug ) ? $current_group->slug : ''; 
  5617.  
  5618. /** 
  5619. * Filters the slug of the current group. 
  5620. * 
  5621. * @since 1.5.0 
  5622. * 
  5623. * @param string $current_group_slug Slug of the current group. 
  5624. * @param object $current_group Instance holding the current group. 
  5625. */ 
  5626. return apply_filters( 'bp_get_current_group_slug', $current_group_slug, $current_group ); 
  5627.  
  5628. /** 
  5629. * Echoes the output of bp_get_current_group_name(). 
  5630. * 
  5631. * @since 1.5.0 
  5632. */ 
  5633. function bp_current_group_name() { 
  5634. echo bp_get_current_group_name(); 
  5635. /** 
  5636. * Returns the name of the current group. 
  5637. * 
  5638. * @since 1.5.0 
  5639. * 
  5640. * @return string The name of the current group, if there is one. 
  5641. */ 
  5642. function bp_get_current_group_name() { 
  5643. $current_group = groups_get_current_group(); 
  5644. $current_name = bp_get_group_name( $current_group ); 
  5645.  
  5646. /** 
  5647. * Filters the name of the current group. 
  5648. * 
  5649. * @since 1.2.0 
  5650. * 
  5651. * @param string $current_name Name of the current group. 
  5652. * @param object $current_group Instance holding the current group. 
  5653. */ 
  5654. return apply_filters( 'bp_get_current_group_name', $current_name, $current_group ); 
  5655.  
  5656. /** 
  5657. * Echoes the output of bp_get_current_group_description(). 
  5658. * 
  5659. * @since 2.1.0 
  5660. */ 
  5661. function bp_current_group_description() { 
  5662. echo bp_get_current_group_description(); 
  5663. /** 
  5664. * Returns the description of the current group. 
  5665. * 
  5666. * @since 2.1.0 
  5667. * this output. 
  5668. * 
  5669. * @return string The description of the current group, if there is one. 
  5670. */ 
  5671. function bp_get_current_group_description() { 
  5672. $current_group = groups_get_current_group(); 
  5673. $current_group_desc = isset( $current_group->description ) ? $current_group->description : ''; 
  5674.  
  5675. /** 
  5676. * Filters the description of the current group. 
  5677. * 
  5678. * This filter is used to apply extra filters related to formatting. 
  5679. * 
  5680. * @since 1.0.0 
  5681. * 
  5682. * @param string $current_group_desc Description of the current group. 
  5683. */ 
  5684. $desc = apply_filters( 'bp_get_group_description', $current_group_desc ); 
  5685.  
  5686. /** 
  5687. * Filters the description of the current group. 
  5688. * 
  5689. * @since 2.1.0 
  5690. * 
  5691. * @param string $desc Description of the current group. 
  5692. */ 
  5693. return apply_filters( 'bp_get_current_group_description', $desc ); 
  5694.  
  5695. /** 
  5696. * Output a URL for a group component action. 
  5697. * 
  5698. * @since 1.2.0 
  5699. * 
  5700. * @param string $action 
  5701. * @param string $query_args 
  5702. * @param bool $nonce 
  5703. * @return string 
  5704. */ 
  5705. function bp_groups_action_link( $action = '', $query_args = '', $nonce = false ) { 
  5706. echo bp_get_groups_action_link( $action, $query_args, $nonce ); 
  5707. /** 
  5708. * Get a URL for a group component action. 
  5709. * 
  5710. * @since 1.2.0 
  5711. * 
  5712. * @param string $action 
  5713. * @param string $query_args 
  5714. * @param bool $nonce 
  5715. * @return string 
  5716. */ 
  5717. function bp_get_groups_action_link( $action = '', $query_args = '', $nonce = false ) { 
  5718.  
  5719. $current_group = groups_get_current_group(); 
  5720. $url = ''; 
  5721.  
  5722. // Must be a group. 
  5723. if ( ! empty( $current_group->id ) ) { 
  5724.  
  5725. // Append $action to $url if provided 
  5726. if ( !empty( $action ) ) { 
  5727. $url = bp_get_group_permalink( $current_group ) . $action; 
  5728. } else { 
  5729. $url = bp_get_group_permalink( $current_group ); 
  5730.  
  5731. // Add a slash at the end of our user url. 
  5732. $url = trailingslashit( $url ); 
  5733.  
  5734. // Add possible query args. 
  5735. if ( !empty( $query_args ) && is_array( $query_args ) ) { 
  5736. $url = add_query_arg( $query_args, $url ); 
  5737.  
  5738. // To nonce, or not to nonce... 
  5739. if ( true === $nonce ) { 
  5740. $url = wp_nonce_url( $url ); 
  5741. } elseif ( is_string( $nonce ) ) { 
  5742. $url = wp_nonce_url( $url, $nonce ); 
  5743.  
  5744. /** 
  5745. * Filters a URL for a group component action. 
  5746. * 
  5747. * @since 2.1.0 
  5748. * 
  5749. * @param string $url URL for a group component action. 
  5750. * @param string $action Action being taken for the group. 
  5751. * @param string $query_args Query arguments being passed. 
  5752. * @param bool $nonce Whether or not to add a nonce. 
  5753. */ 
  5754. return apply_filters( 'bp_get_groups_action_link', $url, $action, $query_args, $nonce ); 
  5755.  
  5756. /** Stats **********************************************************************/ 
  5757.  
  5758. /** 
  5759. * Display the number of groups in user's profile. 
  5760. * 
  5761. * @since 2.0.0 
  5762. * 
  5763. * @param array|string $args before|after|user_id 
  5764. * 
  5765. */ 
  5766. function bp_groups_profile_stats( $args = '' ) { 
  5767. echo bp_groups_get_profile_stats( $args ); 
  5768. add_action( 'bp_members_admin_user_stats', 'bp_groups_profile_stats', 8, 1 ); 
  5769.  
  5770. /** 
  5771. * Return the number of groups in user's profile. 
  5772. * 
  5773. * @since 2.0.0 
  5774. * 
  5775. * @param array|string $args before|after|user_id 
  5776. * @return string HTML for stats output. 
  5777. */ 
  5778. function bp_groups_get_profile_stats( $args = '' ) { 
  5779.  
  5780. // Parse the args 
  5781. $r = bp_parse_args( $args, array( 
  5782. 'before' => '<li class="bp-groups-profile-stats">',  
  5783. 'after' => '</li>',  
  5784. 'user_id' => bp_displayed_user_id(),  
  5785. 'groups' => 0,  
  5786. 'output' => '' 
  5787. ), 'groups_get_profile_stats' ); 
  5788.  
  5789. // Allow completely overloaded output 
  5790. if ( empty( $r['output'] ) ) { 
  5791.  
  5792. // Only proceed if a user ID was passed 
  5793. if ( ! empty( $r['user_id'] ) ) { 
  5794.  
  5795. // Get the user groups 
  5796. if ( empty( $r['groups'] ) ) { 
  5797. $r['groups'] = absint( bp_get_total_group_count_for_user( $r['user_id'] ) ); 
  5798.  
  5799. // If groups exist, show some formatted output 
  5800. $r['output'] = $r['before'] . sprintf( _n( '%s group', '%s groups', $r['groups'], 'buddypress' ), '<strong>' . $r['groups'] . '</strong>' ) . $r['after']; 
  5801.  
  5802. /** 
  5803. * Filters the number of groups in user's profile. 
  5804. * 
  5805. * @since 2.0.0 
  5806. * 
  5807. * @param string $value HTML for stats output. 
  5808. * @param array $r Array of parsed arguments for query. 
  5809. */ 
  5810. return apply_filters( 'bp_groups_get_profile_stats', $r['output'], $r ); 
.