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