[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

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