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