[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-groups/ -> bp-groups-template.php (source)

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