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