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