[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

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