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