Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/05/2016 04:55:58 AM (10 years ago)
Author:
boonebgorges
Message:

Move bp-groups classes to their own files.

See #6870.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/classes/class-bp-groups-group-members-template.php

    r10515 r10520  
    11<?php
    22/**
    3  * BuddyPress Groups Template Functions.
     3 * BuddyPress Groups group members loop template class.
    44 *
    55 * @package BuddyPress
    6  * @subpackage GroupsTemplates
    7  * @since 1.5.0
     6 * @since 1.1.0
    87 */
    98
     
    1211
    1312/**
    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 group directory permalink.
    69  *
    70  * @since 1.5.0
    71  */
    72 function bp_groups_directory_permalink() {
    73         echo esc_url( bp_get_groups_directory_permalink() );
    74 }
    75         /**
    76          * Return group directory permalink.
    77          *
    78          * @since 1.5.0
    79          *
    80          * @return string
    81          */
    82         function bp_get_groups_directory_permalink() {
    83 
    84                 /**
    85                  * Filters the group directory permalink.
    86                  *
    87                  * @since 1.5.0
    88                  *
    89                  * @param string $value Permalink for the group directory.
    90                  */
    91                 return apply_filters( 'bp_get_groups_directory_permalink', trailingslashit( bp_get_root_domain() . '/' . bp_get_groups_root_slug() ) );
    92         }
    93 
    94 /**
    95  * The main Groups template loop class.
    96  *
    97  * Responsible for loading a group of groups into a loop for display.
    98  *
    99  * @since 1.2.0
    100  */
    101 class BP_Groups_Template {
    102 
    103         /**
    104          * The loop iterator.
    105          *
    106          * @var int
    107          * @since 1.2.0
    108          */
    109         public $current_group = -1;
    110 
    111         /**
    112          * The number of groups returned by the paged query.
    113          *
    114          * @var int
    115          * @since 1.2.0
    116          */
    117         public $group_count;
    118 
    119         /**
    120          * Array of groups located by the query.
    121          *
    122          * @var array
    123          * @since 1.2.0
    124          */
    125         public $groups;
    126 
    127         /**
    128          * The group object currently being iterated on.
    129          *
    130          * @var object
    131          * @since 1.2.0
    132          */
    133         public $group;
    134 
    135         /**
    136          * A flag for whether the loop is currently being iterated.
    137          *
    138          * @var bool
    139          * @since 1.2.0
    140          */
    141         public $in_the_loop;
    142 
    143         /**
    144          * The page number being requested.
    145          *
    146          * @var string
    147          * @since 1.2.0
    148          */
    149         public $pag_page;
    150 
    151         /**
    152          * The number of items being requested per page.
    153          *
    154          * @var string
    155          * @since 1.2.0
    156          */
    157         public $pag_num;
    158 
    159         /**
    160          * An HTML string containing pagination links.
    161          *
    162          * @var string
    163          * @since 1.2.0
    164          */
    165         public $pag_links;
    166 
    167         /**
    168          * The total number of groups matching the query parameters.
    169          *
    170          * @var int
    171          * @since 1.2.0
    172          */
    173         public $total_group_count;
    174 
    175         /**
    176          * Whether the template loop is for a single group page.
    177          *
    178          * @var bool
    179          * @since 1.2.0
    180          */
    181         public $single_group = false;
    182 
    183         /**
    184          * Field to sort by.
    185          *
    186          * @var string
    187          * @since 1.2.0
    188          */
    189         public $sort_by;
    190 
    191         /**
    192          * Sort order.
    193          *
    194          * @var string
    195          * @since 1.2.0
    196          */
    197         public $order;
    198 
    199         /**
    200          * Constructor method.
    201          *
    202          * @see BP_Groups_Group::get() for an in-depth description of arguments.
    203          *
    204          * @param array $args {
    205          *     Array of arguments. Accepts all arguments accepted by
    206          *     {@link BP_Groups_Group::get()}. In cases where the default
    207          *     values of the params differ, they have been discussed below.
    208          *     @type int $per_page Default: 20.
    209          *     @type int $page Default: 1.
    210          * }
    211          */
    212         function __construct( $args = array() ){
    213 
    214                 // Backward compatibility with old method of passing arguments.
    215                 if ( ! is_array( $args ) || func_num_args() > 1 ) {
    216                         _deprecated_argument( __METHOD__, '1.7', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) );
    217 
    218                         $old_args_keys = array(
    219                                 0  => 'user_id',
    220                                 1  => 'type',
    221                                 2  => 'page',
    222                                 3  => 'per_page',
    223                                 4  => 'max',
    224                                 5  => 'slug',
    225                                 6  => 'search_terms',
    226                                 7  => 'populate_extras',
    227                                 8  => 'include',
    228                                 9  => 'exclude',
    229                                 10 => 'show_hidden',
    230                                 11 => 'page_arg',
    231                         );
    232 
    233                         $func_args = func_get_args();
    234                         $args      = bp_core_parse_args_array( $old_args_keys, $func_args );
    235                 }
    236 
    237                 $defaults = array(
    238                         'page'              => 1,
    239                         'per_page'          => 20,
    240                         'page_arg'          => 'grpage',
    241                         'max'               => false,
    242                         'type'              => 'active',
    243                         'order'             => 'DESC',
    244                         'orderby'           => 'date_created',
    245                         'show_hidden'       => false,
    246                         'user_id'           => 0,
    247                         'slug'              => false,
    248                         'include'           => false,
    249                         'exclude'           => false,
    250                         'search_terms'      => '',
    251                         'meta_query'        => false,
    252                         'populate_extras'   => true,
    253                         'update_meta_cache' => true,
    254                 );
    255 
    256                 $r = wp_parse_args( $args, $defaults );
    257                 extract( $r );
    258 
    259                 $this->pag_arg  = sanitize_key( $r['page_arg'] );
    260                 $this->pag_page = bp_sanitize_pagination_arg( $this->pag_arg, $r['page']     );
    261                 $this->pag_num  = bp_sanitize_pagination_arg( 'num',          $r['per_page'] );
    262 
    263                 if ( bp_current_user_can( 'bp_moderate' ) || ( is_user_logged_in() && $user_id == bp_loggedin_user_id() ) ) {
    264                         $show_hidden = true;
    265                 }
    266 
    267                 if ( 'invites' == $type ) {
    268                         $this->groups = groups_get_invites_for_user( $user_id, $this->pag_num, $this->pag_page, $exclude );
    269                 } elseif ( 'single-group' == $type ) {
    270                         $this->single_group = true;
    271 
    272                         if ( groups_get_current_group() ) {
    273                                 $group = groups_get_current_group();
    274 
    275                         } else {
    276                                 $group = groups_get_group( array(
    277                                         'group_id'        => BP_Groups_Group::get_id_from_slug( $r['slug'] ),
    278                                         'populate_extras' => $r['populate_extras'],
    279                                 ) );
    280                         }
    281 
    282                         // Backwards compatibility - the 'group_id' variable is not part of the
    283                         // BP_Groups_Group object, but we add it here for devs doing checks against it
    284                         //
    285                         // @see https://buddypress.trac.wordpress.org/changeset/3540
    286                         //
    287                         // this is subject to removal in a future release; devs should check against
    288                         // $group->id instead.
    289                         $group->group_id = $group->id;
    290 
    291                         $this->groups = array( $group );
    292 
    293                 } else {
    294                         $this->groups = groups_get_groups( array(
    295                                 'type'              => $type,
    296                                 'order'             => $order,
    297                                 'orderby'           => $orderby,
    298                                 'per_page'          => $this->pag_num,
    299                                 'page'              => $this->pag_page,
    300                                 'user_id'           => $user_id,
    301                                 'search_terms'      => $search_terms,
    302                                 'meta_query'        => $meta_query,
    303                                 'include'           => $include,
    304                                 'exclude'           => $exclude,
    305                                 'populate_extras'   => $populate_extras,
    306                                 'update_meta_cache' => $update_meta_cache,
    307                                 'show_hidden'       => $show_hidden
    308                         ) );
    309                 }
    310 
    311                 if ( 'invites' == $type ) {
    312                         $this->total_group_count = (int) $this->groups['total'];
    313                         $this->group_count       = (int) $this->groups['total'];
    314                         $this->groups            = $this->groups['groups'];
    315                 } elseif ( 'single-group' == $type ) {
    316                         if ( empty( $group->id ) ) {
    317                                 $this->total_group_count = 0;
    318                                 $this->group_count       = 0;
    319                         } else {
    320                                 $this->total_group_count = 1;
    321                                 $this->group_count       = 1;
    322                         }
    323                 } else {
    324                         if ( empty( $max ) || $max >= (int) $this->groups['total'] ) {
    325                                 $this->total_group_count = (int) $this->groups['total'];
    326                         } else {
    327                                 $this->total_group_count = (int) $max;
    328                         }
    329 
    330                         $this->groups = $this->groups['groups'];
    331 
    332                         if ( !empty( $max ) ) {
    333                                 if ( $max >= count( $this->groups ) ) {
    334                                         $this->group_count = count( $this->groups );
    335                                 } else {
    336                                         $this->group_count = (int) $max;
    337                                 }
    338                         } else {
    339                                 $this->group_count = count( $this->groups );
    340                         }
    341                 }
    342 
    343                 // Build pagination links.
    344                 if ( (int) $this->total_group_count && (int) $this->pag_num ) {
    345                         $pag_args = array(
    346                                 $this->pag_arg => '%#%'
    347                         );
    348 
    349                         if ( defined( 'DOING_AJAX' ) && true === (bool) DOING_AJAX ) {
    350                                 $base = remove_query_arg( 's', wp_get_referer() );
    351                         } else {
    352                                 $base = '';
    353                         }
    354 
    355                         $add_args = array(
    356                                 'num'     => $this->pag_num,
    357                                 'sortby'  => $this->sort_by,
    358                                 'order'   => $this->order,
    359                         );
    360 
    361                         if ( ! empty( $search_terms ) ) {
    362                                 $query_arg = bp_core_get_component_search_query_arg( 'groups' );
    363                                 $add_args[ $query_arg ] = urlencode( $search_terms );
    364                         }
    365 
    366                         $this->pag_links = paginate_links( array(
    367                                 'base'      => add_query_arg( $pag_args, $base ),
    368                                 'format'    => '',
    369                                 'total'     => ceil( (int) $this->total_group_count / (int) $this->pag_num ),
    370                                 'current'   => $this->pag_page,
    371                                 'prev_text' => _x( '&larr;', 'Group pagination previous text', 'buddypress' ),
    372                                 'next_text' => _x( '&rarr;', 'Group pagination next text', 'buddypress' ),
    373                                 'mid_size'  => 1,
    374                                 'add_args'  => $add_args,
    375                         ) );
    376                 }
    377         }
    378 
    379         /**
    380          * Whether there are groups available in the loop.
    381          *
    382          * @since 1.2.0
    383          *
    384          * @see bp_has_groups()
    385          *
    386          * @return bool True if there are items in the loop, otherwise false.
    387          */
    388         function has_groups() {
    389                 if ( $this->group_count ) {
    390                         return true;
    391                 }
    392 
    393                 return false;
    394         }
    395 
    396         /**
    397          * Set up the next group and iterate index.
    398          *
    399          * @since 1.2.0
    400          *
    401          * @return object The next group to iterate over.
    402          */
    403         function next_group() {
    404                 $this->current_group++;
    405                 $this->group = $this->groups[$this->current_group];
    406 
    407                 return $this->group;
    408         }
    409 
    410         /**
    411          * Rewind the groups and reset member index.
    412          *
    413          * @since 1.2.0
    414          */
    415         function rewind_groups() {
    416                 $this->current_group = -1;
    417                 if ( $this->group_count > 0 ) {
    418                         $this->group = $this->groups[0];
    419                 }
    420         }
    421 
    422         /**
    423          * Whether there are groups left in the loop to iterate over.
    424          *
    425          * This method is used by {@link bp_groups()} as part of the while loop
    426          * that controls iteration inside the groups loop, eg:
    427          *     while ( bp_groups() ) { ...
    428          *
    429          * @since 1.2.0
    430          *
    431          * @see bp_groups()
    432          *
    433          * @return bool True if there are more groups to show, otherwise false.
    434          */
    435         function groups() {
    436                 if ( $this->current_group + 1 < $this->group_count ) {
    437                         return true;
    438                 } elseif ( $this->current_group + 1 == $this->group_count ) {
    439 
    440                         /**
    441                          * Fires right before the rewinding of groups list.
    442                          *
    443                          * @since 1.5.0
    444                          */
    445                         do_action('group_loop_end');
    446                         // Do some cleaning up after the loop.
    447                         $this->rewind_groups();
    448                 }
    449 
    450                 $this->in_the_loop = false;
    451                 return false;
    452         }
    453 
    454         /**
    455          * Set up the current group inside the loop.
    456          *
    457          * Used by {@link bp_the_group()} to set up the current group data
    458          * while looping, so that template tags used during that iteration make
    459          * reference to the current member.
    460          *
    461          * @since 1.2.0
    462          *
    463          * @see bp_the_group()
    464          */
    465         function the_group() {
    466                 $this->in_the_loop = true;
    467                 $this->group       = $this->next_group();
    468 
    469                 if ( 0 == $this->current_group ) {
    470 
    471                         /**
    472                          * Fires if the current group item is the first in the loop.
    473                          *
    474                          * @since 1.1.0
    475                          */
    476                         do_action( 'group_loop_start' );
    477                 }
    478         }
    479 }
    480 
    481 /**
    482  * Start the Groups Template Loop.
    483  *
    484  * @since 1.0.0
    485  *
    486  * @param array|string $args {
    487  *     Array of parameters. All items are optional.
    488  *     @type string       $type              Shorthand for certain orderby/
    489  *                                           order combinations. 'newest',
    490  *                                           'active', 'popular', 'alphabetical',
    491  *                                           'random'. When present, will override
    492  *                                           orderby and order params. Default: null.
    493  *     @type string       $order             Sort order. 'ASC' or 'DESC'.
    494  *                                           Default: 'DESC'.
    495  *     @type string       $orderby           Property to sort by.
    496  *                                           'date_created', 'last_activity', 'total_member_count',
    497  *                                           'name', 'random'. Default: 'last_activity'.
    498  *     @type int          $page              Page offset of results to return.
    499  *                                           Default: 1 (first page of results).
    500  *     @type int          $per_page          Number of items to return per page
    501  *                                           of results. Default: 20.
    502  *     @type int          $max               Does NOT affect query. May change the
    503  *                                           reported number of total groups found,
    504  *                                           but not the actual number of found
    505  *                                           groups. Default: false.
    506  *     @type bool         $show_hidden       Whether to include hidden groups in
    507  *                                           results. Default: false.
    508  *     @type string       $page_arg          Query argument used for pagination.
    509  *                                           Default: 'grpage'.
    510  *     @type int          $user_id           If provided, results will be limited
    511  *                                           to groups of which the specified user
    512  *                                           is a member.
    513  *                                           Default: value of bp_displayed_user_id().
    514  *     @type string       $slug              If provided, only the group with the
    515  *                                           matching slug will be returned.
    516  *                                           Default: false.
    517  *     @type string       $search_terms      If provided, only groups whose names or
    518  *                                           descriptions match the search terms will
    519  *                                           be returned. Default: value of
    520  *                                           `$_REQUEST['groups_search']` or
    521  *                                           `$_REQUEST['s']`, if present. Otherwise false.
    522  *     @type array        $meta_query        An array of meta_query conditions.
    523  *                                           See {@link WP_Meta_Query::queries} for description.
    524  *     @type array|string $include           Array or comma-separated list of
    525  *                                           group IDs. Results will be limited
    526  *                                           to groups within the list. Default: false.
    527  *     @type bool         $populate_extras   Whether to fetch additional information
    528  *                                           (such as member count) about groups.
    529  *                                           Default: true.
    530  *     @type array|string $exclude           Array or comma-separated list of group IDs.
    531  *                                           Results will exclude the listed groups.
    532  *                                           Default: false.
    533  *     @type bool         $update_meta_cache Whether to fetch groupmeta for queried groups.
    534  *                                           Default: true.
    535  * }
    536  * @return bool True if there are groups to display that match the params
    537  */
    538 function bp_has_groups( $args = '' ) {
    539         global $groups_template;
    540 
    541         /*
    542          * Defaults based on the current page & overridden by parsed $args
    543          */
    544         $slug         = false;
    545         $type         = '';
    546         $search_terms = false;
    547 
    548         // When looking your own groups, check for two action variables.
    549         if ( bp_is_current_action( 'my-groups' ) ) {
    550                 if ( bp_is_action_variable( 'most-popular', 0 ) ) {
    551                         $type = 'popular';
    552                 } elseif ( bp_is_action_variable( 'alphabetically', 0 ) ) {
    553                         $type = 'alphabetical';
    554                 }
    555 
    556         // When looking at invites, set type to invites.
    557         } elseif ( bp_is_current_action( 'invites' ) ) {
    558                 $type = 'invites';
    559 
    560         // When looking at a single group, set the type and slug.
    561         } elseif ( bp_get_current_group_slug() ) {
    562                 $type = 'single-group';
    563                 $slug = bp_get_current_group_slug();
    564         }
    565 
    566         // Default search string (too soon to escape here).
    567         $search_query_arg = bp_core_get_component_search_query_arg( 'groups' );
    568         if ( ! empty( $_REQUEST[ $search_query_arg ] ) ) {
    569                 $search_terms = stripslashes( $_REQUEST[ $search_query_arg ] );
    570         } elseif ( ! empty( $_REQUEST['group-filter-box'] ) ) {
    571                 $search_terms = $_REQUEST['group-filter-box'];
    572         } elseif ( !empty( $_REQUEST['s'] ) ) {
    573                 $search_terms = $_REQUEST['s'];
    574         }
    575 
    576         // Parse defaults and requested arguments.
    577         $r = bp_parse_args( $args, array(
    578                 'type'              => $type,
    579                 'order'             => 'DESC',
    580                 'orderby'           => 'last_activity',
    581                 'page'              => 1,
    582                 'per_page'          => 20,
    583                 'max'               => false,
    584                 'show_hidden'       => false,
    585                 'page_arg'          => 'grpage',
    586                 'user_id'           => bp_displayed_user_id(),
    587                 'slug'              => $slug,
    588                 'search_terms'      => $search_terms,
    589                 'meta_query'        => false,
    590                 'include'           => false,
    591                 'exclude'           => false,
    592                 'populate_extras'   => true,
    593                 'update_meta_cache' => true,
    594         ), 'has_groups' );
    595 
    596         // Setup the Groups template global.
    597         $groups_template = new BP_Groups_Template( array(
    598                 'type'              => $r['type'],
    599                 'order'             => $r['order'],
    600                 'orderby'           => $r['orderby'],
    601                 'page'              => (int) $r['page'],
    602                 'per_page'          => (int) $r['per_page'],
    603                 'max'               => (int) $r['max'],
    604                 'show_hidden'       => $r['show_hidden'],
    605                 'page_arg'          => $r['page_arg'],
    606                 'user_id'           => (int) $r['user_id'],
    607                 'slug'              => $r['slug'],
    608                 'search_terms'      => $r['search_terms'],
    609                 'meta_query'        => $r['meta_query'],
    610                 'include'           => $r['include'],
    611                 'exclude'           => $r['exclude'],
    612                 'populate_extras'   => (bool) $r['populate_extras'],
    613                 'update_meta_cache' => (bool) $r['update_meta_cache'],
    614         ) );
    615 
    616         /**
    617          * Filters whether or not there are groups to iterate over for the groups loop.
    618          *
    619          * @since 1.1.0
    620          *
    621          * @param bool               $value           Whether or not there are groups to iterate over.
    622          * @param BP_Groups_Template $groups_template BP_Groups_Template object based on parsed arguments.
    623          * @param array              $r               Array of parsed arguments for the query.
    624          */
    625         return apply_filters( 'bp_has_groups', $groups_template->has_groups(), $groups_template, $r );
    626 }
    627 
    628 /**
    629  * Check whether there are more groups to iterate over.
    630  *
    631  * @since 1.0.0
    632  *
    633  * @return bool
    634  */
    635 function bp_groups() {
    636         global $groups_template;
    637         return $groups_template->groups();
    638 }
    639 
    640 /**
    641  * Set up the current group inside the loop.
    642  *
    643  * @since 1.0.0
    644  *
    645  * @return object
    646  */
    647 function bp_the_group() {
    648         global $groups_template;
    649         return $groups_template->the_group();
    650 }
    651 
    652 /**
    653  * Is the group visible to the currently logged-in user?
    654  *
    655  * @since 1.0.0
    656  *
    657  * @param object|bool $group Optional. Group object. Default: current group in loop.
    658  * @return bool
    659  */
    660 function bp_group_is_visible( $group = false ) {
    661         global $groups_template;
    662 
    663         if ( bp_current_user_can( 'bp_moderate' ) ) {
    664                 return true;
    665         }
    666 
    667         if ( empty( $group ) ) {
    668                 $group =& $groups_template->group;
    669         }
    670 
    671         if ( 'public' == $group->status ) {
    672                 return true;
    673         } else {
    674                 if ( groups_is_user_member( bp_loggedin_user_id(), $group->id ) ) {
    675                         return true;
    676                 }
    677         }
    678 
    679         return false;
    680 }
    681 
    682 /**
    683  * Output the ID of the current group in the loop.
    684  *
    685  * @since 1.0.0
    686  *
    687  * @param object|bool $group Optional. Group object. Default: current group in loop.
    688  */
    689 function bp_group_id( $group = false ) {
    690         echo bp_get_group_id( $group );
    691 }
    692         /**
    693          * Get the ID of the current group in the loop.
    694          *
    695          * @since 1.0.0
    696          *
    697          * @param object|bool $group Optional. Group object.
    698          *                           Default: current group in loop.
    699          * @return int
    700          */
    701         function bp_get_group_id( $group = false ) {
    702                 global $groups_template;
    703 
    704                 if ( empty( $group ) ) {
    705                         $group =& $groups_template->group;
    706                 }
    707 
    708                 /**
    709                  * Filters the ID of the current group in the loop.
    710                  *
    711                  * @since 1.0.0
    712                  * @since 2.5.0 Added the `$group` parameter.
    713                  *
    714                  * @param int    $id    ID of the current group in the loop.
    715                  * @param object $group Group object.
    716                  */
    717                 return apply_filters( 'bp_get_group_id', $group->id, $group );
    718         }
    719 
    720 /**
    721  * Output the row class of the current group in the loop.
    722  *
    723  * @since 1.7.0
    724  *
    725  * @param array $classes Array of custom classes.
    726  */
    727 function bp_group_class( $classes = array() ) {
    728         echo bp_get_group_class( $classes );
    729 }
    730         /**
    731          * Get the row class of the current group in the loop.
    732          *
    733          * @since 1.7.0
    734          *
    735          * @param array $classes Array of custom classes.
    736          * @return string Row class of the group.
    737          */
    738         function bp_get_group_class( $classes = array() ) {
    739                 global $groups_template;
    740 
    741                 // Add even/odd classes, but only if there's more than 1 group.
    742                 if ( $groups_template->group_count > 1 ) {
    743                         $pos_in_loop = (int) $groups_template->current_group;
    744                         $classes[]   = ( $pos_in_loop % 2 ) ? 'even' : 'odd';
    745 
    746                 // If we've only one group in the loop, don't bother with odd and even.
    747                 } else {
    748                         $classes[] = 'bp-single-group';
    749                 }
    750 
    751                 // Group type - public, private, hidden.
    752                 $classes[] = sanitize_key( $groups_template->group->status );
    753 
    754                 // User's group role.
    755                 if ( bp_is_user_active() ) {
    756 
    757                         // Admin.
    758                         if ( bp_group_is_admin() ) {
    759                                 $classes[] = 'is-admin';
    760                         }
    761 
    762                         // Moderator.
    763                         if ( bp_group_is_mod() ) {
    764                                 $classes[] = 'is-mod';
    765                         }
    766 
    767                         // Member.
    768                         if ( bp_group_is_member() ) {
    769                                 $classes[] = 'is-member';
    770                         }
    771                 }
    772 
    773                 // Whether a group avatar will appear.
    774                 if ( bp_disable_group_avatar_uploads() || ! buddypress()->avatar->show_avatars ) {
    775                         $classes[] = 'group-no-avatar';
    776                 } else {
    777                         $classes[] = 'group-has-avatar';
    778                 }
    779 
    780                 /**
    781                  * Filters classes that will be applied to row class of the current group in the loop.
    782                  *
    783                  * @since 1.7.0
    784                  *
    785                  * @param array $classes Array of determined classes for the row.
    786                  */
    787                 $classes = apply_filters( 'bp_get_group_class', $classes );
    788                 $classes = array_merge( $classes, array() );
    789                 $retval = 'class="' . join( ' ', $classes ) . '"';
    790 
    791                 return $retval;
    792         }
    793 
    794 /**
    795  * Output the name of the current group in the loop.
    796  *
    797  * @since 1.0.0
    798  *
    799  * @param object|bool $group Optional. Group object.
    800  *                           Default: current group in loop.
    801  */
    802 function bp_group_name( $group = false ) {
    803         echo bp_get_group_name( $group );
    804 }
    805         /**
    806          * Get the name of the current group in the loop.
    807          *
    808          * @since 1.0.0
    809          *
    810          * @param object|bool $group Optional. Group object.
    811          *                           Default: current group in loop.
    812          * @return string
    813          */
    814         function bp_get_group_name( $group = false ) {
    815                 global $groups_template;
    816 
    817                 if ( empty( $group ) ) {
    818                         $group =& $groups_template->group;
    819                 }
    820 
    821                 /**
    822                  * Filters the name of the current group in the loop.
    823                  *
    824                  * @since 1.0.0
    825                  * @since 2.5.0 Added the `$group` parameter.
    826                  *
    827                  * @param string $name  Name of the current group in the loop.
    828                  * @param object $group Group object.
    829                  */
    830                 return apply_filters( 'bp_get_group_name', $group->name, $group );
    831         }
    832 
    833 /**
    834  * Output the type of the current group in the loop.
    835  *
    836  * @since 1.0.0
    837  *
    838  * @param object|bool $group Optional. Group object.
    839  *                           Default: current group in loop.
    840  */
    841 function bp_group_type( $group = false ) {
    842         echo bp_get_group_type( $group );
    843 }
    844 
    845 /**
    846  * Get the type of the current group in the loop.
    847  *
    848  * @since 1.0.0
    849  *
    850  * @param object|bool $group Optional. Group object.
    851  *                           Default: current group in loop.
    852  * @return string
    853  */
    854 function bp_get_group_type( $group = false ) {
    855         global $groups_template;
    856 
    857         if ( empty( $group ) ) {
    858                 $group =& $groups_template->group;
    859         }
    860 
    861         if ( 'public' == $group->status ) {
    862                 $type = __( "Public Group", "buddypress" );
    863         } elseif ( 'hidden' == $group->status ) {
    864                 $type = __( "Hidden Group", "buddypress" );
    865         } elseif ( 'private' == $group->status ) {
    866                 $type = __( "Private Group", "buddypress" );
    867         } else {
    868                 $type = ucwords( $group->status ) . ' ' . __( 'Group', 'buddypress' );
    869         }
    870 
    871         /**
    872          * Filters the type for the current group in the loop.
    873          *
    874          * @since 1.0.0
    875          * @since 2.5.0 Added the `$group` parameter.
    876          *
    877          * @param string $type  Type for the current group in the loop.
    878          * @param object $group Group object.
    879          */
    880         return apply_filters( 'bp_get_group_type', $type, $group );
    881 }
    882 /**
    883  * Output the status of the current group in the loop.
    884  *
    885  * @since 1.1.0
    886  *
    887  * @param object|bool $group Optional. Group object.
    888  *                           Default: current group in loop.
    889  */
    890 function bp_group_status( $group = false ) {
    891         echo bp_get_group_status( $group );
    892 }
    893         /**
    894          * Get the status of the current group in the loop.
    895          *
    896          * @since 1.1.0
    897          *
    898          * @param object|bool $group Optional. Group object.
    899          *                           Default: current group in loop.
    900          * @return string
    901          */
    902         function bp_get_group_status( $group = false ) {
    903                 global $groups_template;
    904 
    905                 if ( empty( $group ) ) {
    906                         $group =& $groups_template->group;
    907                 }
    908 
    909                 /**
    910                  * Filters the status of the current group in the loop.
    911                  *
    912                  * @since 1.0.0
    913                  * @since 2.5.0 Added the `$group` parameter.
    914                  *
    915                  * @param string $status Status of the current group in the loop.
    916                  * @param object $group  Group object.
    917                  */
    918                 return apply_filters( 'bp_get_group_status', $group->status, $group );
    919         }
    920 
    921 /**
    922  * Output the group avatar while in the groups loop.
    923  *
    924  * @since 1.0.0
    925  *
    926  * @param array|string $args {
    927  *      See {@link bp_get_group_avatar()} for description of arguments.
    928  * }
    929  */
    930 function bp_group_avatar( $args = '' ) {
    931         echo bp_get_group_avatar( $args );
    932 }
    933         /**
    934          * Get a group's avatar.
    935          *
    936          * @since 1.0.0
    937          *
    938          * @see bp_core_fetch_avatar() For a description of arguments and return values.
    939 
    940          * @param array|string $args {
    941          *     Arguments are listed here with an explanation of their defaults.
    942          *     For more information about the arguments, see {@link bp_core_fetch_avatar()}.
    943          *
    944          *     @type string   $alt     Default: 'Group logo of [group name]'.
    945          *     @type string   $class   Default: 'avatar'.
    946          *     @type string   $type    Default: 'full'.
    947          *     @type int|bool $width   Default: false.
    948          *     @type int|bool $height  Default: false.
    949          *     @type bool     $id      Passed to `$css_id` parameter.
    950          * }
    951          * @return string Group avatar string.
    952          */
    953         function bp_get_group_avatar( $args = '' ) {
    954                 global $groups_template;
    955 
    956                 // Bail if avatars are turned off.
    957                 if ( bp_disable_group_avatar_uploads() || ! buddypress()->avatar->show_avatars ) {
    958                         return false;
    959                 }
    960 
    961                 // Parse the arguments.
    962                 $r = bp_parse_args( $args, array(
    963                         'type'   => 'full',
    964                         'width'  => false,
    965                         'height' => false,
    966                         'class'  => 'avatar',
    967                         'id'     => false,
    968                         'alt'    => sprintf( __( 'Group logo of %s', 'buddypress' ), $groups_template->group->name )
    969                 ) );
    970 
    971                 // Fetch the avatar from the folder.
    972                 $avatar = bp_core_fetch_avatar( array(
    973                         'item_id'    => $groups_template->group->id,
    974                         'title'      => $groups_template->group->name,
    975                         'avatar_dir' => 'group-avatars',
    976                         'object'     => 'group',
    977                         'type'       => $r['type'],
    978                         'alt'        => $r['alt'],
    979                         'css_id'     => $r['id'],
    980                         'class'      => $r['class'],
    981                         'width'      => $r['width'],
    982                         'height'     => $r['height']
    983                 ) );
    984 
    985                 // If No avatar found, provide some backwards compatibility.
    986                 if ( empty( $avatar ) ) {
    987                         $avatar = '<img src="' . esc_url( $groups_template->group->avatar_thumb ) . '" class="avatar" alt="' . esc_attr( $groups_template->group->name ) . '" />';
    988                 }
    989 
    990                 /**
    991                  * Filters the group avatar while in the groups loop.
    992                  *
    993                  * @since 1.0.0
    994                  *
    995                  * @param string $avatar HTML image element holding the group avatar.
    996                  * @param array  $r      Array of parsed arguments for the group avatar.
    997                  */
    998                 return apply_filters( 'bp_get_group_avatar', $avatar, $r );
    999         }
    1000 
    1001 /**
    1002  * Output the group avatar thumbnail while in the groups loop.
    1003  *
    1004  * @since 1.0.0
    1005  *
    1006  * @param object|bool $group Optional. Group object.
    1007  *                           Default: current group in loop.
    1008  */
    1009 function bp_group_avatar_thumb( $group = false ) {
    1010         echo bp_get_group_avatar_thumb( $group );
    1011 }
    1012         /**
    1013          * Return the group avatar thumbnail while in the groups loop.
    1014          *
    1015          * @since 1.0.0
    1016          *
    1017          * @param object|bool $group Optional. Group object.
    1018          *                           Default: current group in loop.
    1019          * @return string
    1020          */
    1021         function bp_get_group_avatar_thumb( $group = false ) {
    1022                 return bp_get_group_avatar( array(
    1023                         'type' => 'thumb',
    1024                         'id'   => ! empty( $group->id ) ? $group->id : false
    1025                 ) );
    1026         }
    1027 
    1028 /**
    1029  * Output the miniature group avatar thumbnail while in the groups loop.
    1030  *
    1031  * @since 1.0.0
    1032  *
    1033  * @param object|bool $group Optional. Group object.
    1034  *                           Default: current group in loop.
    1035  */
    1036 function bp_group_avatar_mini( $group = false ) {
    1037         echo bp_get_group_avatar_mini( $group );
    1038 }
    1039         /**
    1040          * Return the miniature group avatar thumbnail while in the groups loop.
    1041          *
    1042          * @since 1.0.0
    1043          *
    1044          * @param object|bool $group Optional. Group object.
    1045          *                           Default: current group in loop.
    1046          * @return string
    1047          */
    1048         function bp_get_group_avatar_mini( $group = false ) {
    1049                 return bp_get_group_avatar( array(
    1050                         'type'   => 'thumb',
    1051                         'width'  => 30,
    1052                         'height' => 30,
    1053                         'id'     => ! empty( $group->id ) ? $group->id : false
    1054                 ) );
    1055         }
    1056 
    1057 /** Group cover image *********************************************************/
    1058 
    1059 /**
    1060  * Should we use the group's cover image header.
    1061  *
    1062  * @since 2.4.0
    1063  *
    1064  * @return bool True if the displayed user has a cover image,
    1065  *              False otherwise
    1066  */
    1067 function bp_group_use_cover_image_header() {
    1068         return (bool) bp_is_active( 'groups', 'cover_image' ) && ! bp_disable_group_cover_image_uploads() && bp_attachments_is_wp_version_supported();
    1069 }
    1070 
    1071 /**
    1072  * Output the 'last active' string for the current group in the loop.
    1073  *
    1074  * @since 1.0.0
    1075  *
    1076  * @param object|bool $group Optional. Group object.
    1077  *                           Default: current group in loop.
    1078  */
    1079 function bp_group_last_active( $group = false ) {
    1080         echo bp_get_group_last_active( $group );
    1081 }
    1082         /**
    1083          * Return the 'last active' string for the current group in the loop.
    1084          *
    1085          * @since 1.0.0
    1086          *
    1087          * @param object|bool $group Optional. Group object.
    1088          *                           Default: current group in loop.
    1089          * @return string
    1090          */
    1091         function bp_get_group_last_active( $group = false ) {
    1092                 global $groups_template;
    1093 
    1094                 if ( empty( $group ) ) {
    1095                         $group =& $groups_template->group;
    1096                 }
    1097 
    1098                 $last_active = $group->last_activity;
    1099 
    1100                 if ( !$last_active ) {
    1101                         $last_active = groups_get_groupmeta( $group->id, 'last_activity' );
    1102                 }
    1103 
    1104                 if ( empty( $last_active ) ) {
    1105                         return __( 'not yet active', 'buddypress' );
    1106                 } else {
    1107 
    1108                         /**
    1109                          * Filters the 'last active' string for the current gorup in the loop.
    1110                          *
    1111                          * @since 1.0.0
    1112                          * @since 2.5.0 Added the `$group` parameter.
    1113                          *
    1114                          * @param string $value Determined last active value for the current group.
    1115                          * @param object $group Group object.
    1116                          */
    1117                         return apply_filters( 'bp_get_group_last_active', bp_core_time_since( $last_active ), $group );
    1118                 }
    1119         }
    1120 
    1121 /**
    1122  * Output the permalink for the current group in the loop.
    1123  *
    1124  * @since 1.0.0
    1125  *
    1126  * @param object|bool $group Optional. Group object.
    1127  *                           Default: current group in loop.
    1128  */
    1129 function bp_group_permalink( $group = false ) {
    1130         echo bp_get_group_permalink( $group );
    1131 }
    1132         /**
    1133          * Return the permalink for the current group in the loop.
    1134          *
    1135          * @since 1.0.0
    1136          *
    1137          * @param object|bool $group Optional. Group object.
    1138          *                           Default: current group in loop.
    1139          * @return string
    1140          */
    1141         function bp_get_group_permalink( $group = false ) {
    1142                 global $groups_template;
    1143 
    1144                 if ( empty( $group ) ) {
    1145                         $group =& $groups_template->group;
    1146                 }
    1147 
    1148                 /**
    1149                  * Filters the permalink 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 Permalink for the current group in the loop.
    1155                  * @param object $group Group object.
    1156                  */
    1157                 return apply_filters( 'bp_get_group_permalink', trailingslashit( bp_get_groups_directory_permalink() . $group->slug . '/' ), $group );
    1158         }
    1159 
    1160 /**
    1161  * Output the permalink for the admin section of the current group in the loop.
    1162  *
    1163  * @since 1.0.0
    1164  *
    1165  * @param object|bool $group Optional. Group object.
    1166  *                           Default: current group in loop.
    1167  */
    1168 function bp_group_admin_permalink( $group = false ) {
    1169         echo bp_get_group_admin_permalink( $group );
    1170 }
    1171         /**
    1172          * Return the permalink for the admin section of the current group in the loop.
    1173          *
    1174          * @since 1.0.0
    1175          *
    1176          * @param object|bool $group Optional. Group object.
    1177          *                           Default: current group in loop.
    1178          * @return string
    1179          */
    1180         function bp_get_group_admin_permalink( $group = false ) {
    1181                 global $groups_template;
    1182 
    1183                 if ( empty( $group ) ) {
    1184                         $group =& $groups_template->group;
    1185                 }
    1186 
    1187                 /**
    1188                  * Filters the permalink for the admin section of the current group in the loop.
    1189                  *
    1190                  * @since 1.0.0
    1191                  * @since 2.5.0 Added the `$group` parameter.
    1192                  *
    1193                  * @param string $value Permalink for the admin section of the current group in the loop.
    1194                  * @param object $group Group object.
    1195                  */
    1196                 return apply_filters( 'bp_get_group_admin_permalink', trailingslashit( bp_get_group_permalink( $group ) . 'admin' ), $group );
    1197         }
    1198 
    1199 /**
    1200  * Return the slug for the current group in the loop.
    1201  *
    1202  * @since 1.0.0
    1203  *
    1204  * @param object|bool $group Optional. Group object.
    1205  *                           Default: current group in loop.
    1206  */
    1207 function bp_group_slug( $group = false ) {
    1208         echo bp_get_group_slug( $group );
    1209 }
    1210         /**
    1211          * Return the slug for the current group in the loop.
    1212          *
    1213          * @since 1.0.0
    1214          *
    1215          * @param object|bool $group Optional. Group object.
    1216          *                           Default: current group in loop.
    1217          * @return string
    1218          */
    1219         function bp_get_group_slug( $group = false ) {
    1220                 global $groups_template;
    1221 
    1222                 if ( empty( $group ) ) {
    1223                         $group =& $groups_template->group;
    1224                 }
    1225 
    1226                 /**
    1227                  * Filters the slug for the current group in the loop.
    1228                  *
    1229                  * @since 1.0.0
    1230                  * @since 2.5.0 Added the `$group` parameter.
    1231                  *
    1232                  * @param string $slug  Slug for the current group in the loop.
    1233                  * @param object $group Group object.
    1234                  */
    1235                 return apply_filters( 'bp_get_group_slug', $group->slug, $group );
    1236         }
    1237 
    1238 /**
    1239  * Output the description for the current group in the loop.
    1240  *
    1241  * @since 1.0.0
    1242  *
    1243  * @param object|bool $group Optional. Group object.
    1244  *                           Default: current group in loop.
    1245  */
    1246 function bp_group_description( $group = false ) {
    1247         echo bp_get_group_description( $group );
    1248 }
    1249         /**
    1250          * Return the description for the current group in the loop.
    1251          *
    1252          * @since 1.0.0
    1253          *
    1254          * @param object|bool $group Optional. Group object.
    1255          *                           Default: current group in loop.
    1256          * @return string
    1257          */
    1258         function bp_get_group_description( $group = false ) {
    1259                 global $groups_template;
    1260 
    1261                 if ( empty( $group ) ) {
    1262                         $group =& $groups_template->group;
    1263                 }
    1264 
    1265                 /**
    1266                  * Filters the description for the current group in the loop.
    1267                  *
    1268                  * @since 1.0.0
    1269                  * @since 2.5.0 Added the `$group` parameter.
    1270                  *
    1271                  * @param string $value Description for the current group.
    1272                  * @param object $group Group object.
    1273                  */
    1274                 return apply_filters( 'bp_get_group_description', stripslashes( $group->description ), $group );
    1275         }
    1276 
    1277 /**
    1278  * Output the description for the current group in the loop, for use in a textarea.
    1279  *
    1280  * @since 1.0.0
    1281  *
    1282  * @param object|bool $group Optional. Group object.
    1283  *                           Default: current group in loop.
    1284  */
    1285 function bp_group_description_editable( $group = false ) {
    1286         echo bp_get_group_description_editable( $group );
    1287 }
    1288         /**
    1289          * Return the permalink for the current group in the loop, for use in a textarea.
    1290          *
    1291          * 'bp_get_group_description_editable' does not have the formatting
    1292          * filters that 'bp_get_group_description' has, which makes it
    1293          * appropriate for "raw" editing.
    1294          *
    1295          * @since 1.0.0
    1296          *
    1297          * @param object|bool $group Optional. Group object.
    1298          *                           Default: current group in loop.
    1299          * @return string
    1300          */
    1301         function bp_get_group_description_editable( $group = false ) {
    1302                 global $groups_template;
    1303 
    1304                 if ( empty( $group ) ) {
    1305                         $group =& $groups_template->group;
    1306                 }
    1307 
    1308                 /**
    1309                  * Filters the permalink for the current group in the loop, for use in a textarea.
    1310                  *
    1311                  * 'bp_get_group_description_editable' does not have the formatting filters that
    1312                  * 'bp_get_group_description' has, which makes it appropriate for "raw" editing.
    1313                  *
    1314                  * @since 1.0.0
    1315                  * @since 2.5.0 Added the `$group` parameter.
    1316                  *
    1317                  * @param string $description Description for the current group in the loop.
    1318                  * @param object $group       Group object.
    1319                  */
    1320                 return apply_filters( 'bp_get_group_description_editable', $group->description, $group );
    1321         }
    1322 
    1323 /**
    1324  * Output an excerpt of the group description.
    1325  *
    1326  * @since 1.0.0
    1327  *
    1328  * @param object|bool $group Optional. The group being referenced.
    1329  *                           Defaults to the group currently being
    1330  *                           iterated on in the groups loop.
    1331  */
    1332 function bp_group_description_excerpt( $group = false ) {
    1333         echo bp_get_group_description_excerpt( $group );
    1334 }
    1335         /**
    1336          * Get an excerpt of a group description.
    1337          *
    1338          * @since 1.0.0
    1339          *
    1340          * @param object|bool $group Optional. The group being referenced.
    1341          *                           Defaults to the group currently being
    1342          *                           iterated on in the groups loop.
    1343          * @return string Excerpt.
    1344          */
    1345         function bp_get_group_description_excerpt( $group = false ) {
    1346                 global $groups_template;
    1347 
    1348                 if ( empty( $group ) ) {
    1349                         $group =& $groups_template->group;
    1350                 }
    1351 
    1352                 /**
    1353                  * Filters the excerpt of a group description.
    1354                  *
    1355                  * @since 1.0.0
    1356                  *
    1357                  * @param string $value Excerpt of a group description.
    1358                  * @param object $group Object for group whose description is made into an excerpt.
    1359                  */
    1360                 return apply_filters( 'bp_get_group_description_excerpt', bp_create_excerpt( $group->description ), $group );
    1361         }
    1362 
    1363 /**
    1364  * Output the status of the current group in the loop.
    1365  *
    1366  * Either 'Public' or 'Private'.
    1367  *
    1368  * @since 1.0.0
    1369  *
    1370  * @param object|bool $group Optional. Group object.
    1371  *                           Default: current group in loop.
    1372  */
    1373 function bp_group_public_status( $group = false ) {
    1374         echo bp_get_group_public_status( $group );
    1375 }
    1376         /**
    1377          * Return the status of the current group in the loop.
    1378          *
    1379          * Either 'Public' or 'Private'.
    1380          *
    1381          * @since 1.0.0
    1382          *
    1383          * @param object|bool $group Optional. Group object.
    1384          *                           Default: current group in loop.
    1385          * @return string
    1386          */
    1387         function bp_get_group_public_status( $group = false ) {
    1388                 global $groups_template;
    1389 
    1390                 if ( empty( $group ) ) {
    1391                         $group =& $groups_template->group;
    1392                 }
    1393 
    1394                 if ( $group->is_public ) {
    1395                         return __( 'Public', 'buddypress' );
    1396                 } else {
    1397                         return __( 'Private', 'buddypress' );
    1398                 }
    1399         }
    1400 
    1401 /**
    1402  * Output whether the current group in the loop is public.
    1403  *
    1404  * No longer used in BuddyPress.
    1405  *
    1406  * @param object|bool $group Optional. Group object.
    1407  *                           Default: current group in loop.
    1408  */
    1409 function bp_group_is_public( $group = false ) {
    1410         echo bp_get_group_is_public( $group );
    1411 }
    1412         /**
    1413          * Return whether the current group in the loop is public.
    1414          *
    1415          * No longer used in BuddyPress.
    1416          *
    1417          * @param object|bool $group Optional. Group object.
    1418          *                           Default: current group in loop.
    1419          * @return mixed
    1420          */
    1421         function bp_get_group_is_public( $group = false ) {
    1422                 global $groups_template;
    1423 
    1424                 if ( empty( $group ) ) {
    1425                         $group =& $groups_template->group;
    1426                 }
    1427 
    1428                 /**
    1429                  * Filters whether the current group in the loop is public.
    1430                  *
    1431                  * @since 2.5.0 Added the `$group` parameter.
    1432                  *
    1433                  * @param bool   $public True if the group is public.
    1434                  * @param object $group Group object.
    1435                  */
    1436                 return apply_filters( 'bp_get_group_is_public', $group->is_public, $group );
    1437         }
    1438 
    1439 /**
    1440  * Output the created date of the current group in the loop.
    1441  *
    1442  * @since 1.0.0
    1443  *
    1444  * @param object|bool $group Optional. Group object.
    1445  *                           Default: current group in loop.
    1446  */
    1447 function bp_group_date_created( $group = false ) {
    1448         echo bp_get_group_date_created( $group );
    1449 }
    1450         /**
    1451          * Return the created date of the current group in the loop.
    1452          *
    1453          * @since 1.0.0
    1454          *
    1455          * @param object|bool $group Optional. Group object.
    1456          *                           Default: current group in loop.
    1457          * @return string
    1458          */
    1459         function bp_get_group_date_created( $group = false ) {
    1460                 global $groups_template;
    1461 
    1462                 if ( empty( $group ) ) {
    1463                         $group =& $groups_template->group;
    1464                 }
    1465 
    1466                 /**
    1467                  * Filters the created date of the current group in the loop.
    1468                  *
    1469                  * @since 1.0.0
    1470                  * @since 2.5.0 Added the `$group` parameter.
    1471                  *
    1472                  * @param string $value Created date for the current group.
    1473                  * @param object $group Group object.
    1474                  */
    1475                 return apply_filters( 'bp_get_group_date_created', bp_core_time_since( strtotime( $group->date_created ) ), $group );
    1476         }
    1477 
    1478 /**
    1479  * Output the username of the creator of the current group in the loop.
    1480  *
    1481  * @since 1.7.0
    1482  *
    1483  * @param object|bool $group Optional. Group object.
    1484  *                           Default: current group in loop.
    1485  */
    1486 function bp_group_creator_username( $group = false ) {
    1487         echo bp_get_group_creator_username( $group );
    1488 }
    1489         /**
    1490          * Return the username of the creator of the current group in the loop.
    1491          *
    1492          * @since 1.7.0
    1493          *
    1494          * @param object|bool $group Optional. Group object.
    1495          *                           Default: current group in loop.
    1496          * @return string
    1497          */
    1498         function bp_get_group_creator_username( $group = false ) {
    1499                 global $groups_template;
    1500 
    1501                 if ( empty( $group ) ) {
    1502                         $group =& $groups_template->group;
    1503                 }
    1504 
    1505                 /**
    1506                  * Filters the username of the creator of the current group in the loop.
    1507                  *
    1508                  * @since 1.7.0
    1509                  * @since 2.5.0 Added the `$group` parameter.
    1510                  *
    1511                  * @param string $value Username of the group creator.
    1512                  * @param object $group Group object.
    1513                  */
    1514                 return apply_filters( 'bp_get_group_creator_username', bp_core_get_user_displayname( $group->creator_id ), $group );
    1515         }
    1516 
    1517 /**
    1518  * Output the user ID of the creator of the current group in the loop.
    1519  *
    1520  * @since 1.7.0
    1521  *
    1522  * @param object|bool $group Optional. Group object.
    1523  *                           Default: current group in loop.
    1524  */
    1525 function bp_group_creator_id( $group = false ) {
    1526         echo bp_get_group_creator_id( $group );
    1527 }
    1528         /**
    1529          * Return the user ID of the creator of the current group in the loop.
    1530          *
    1531          * @since 1.7.0
    1532          *
    1533          * @param object|bool $group Optional. Group object.
    1534          *                           Default: current group in loop.
    1535          * @return int
    1536          */
    1537         function bp_get_group_creator_id( $group = false ) {
    1538                 global $groups_template;
    1539 
    1540                 if ( empty( $group ) ) {
    1541                         $group =& $groups_template->group;
    1542                 }
    1543 
    1544                 /**
    1545                  * Filters the user ID of the creator of the current group in the loop.
    1546                  *
    1547                  * @since 1.7.0
    1548                  * @since 2.5.0 Added the `$group` parameter.
    1549                  *
    1550                  * @param int $creator_id User ID of the group creator.
    1551                  * @param object $group Group object.
    1552                  */
    1553                 return apply_filters( 'bp_get_group_creator_id', $group->creator_id, $group );
    1554         }
    1555 
    1556 /**
    1557  * Output the permalink of the creator of the current group in the loop.
    1558  *
    1559  * @since 1.7.0
    1560  *
    1561  * @param object|bool $group Optional. Group object.
    1562  *                           Default: current group in loop.
    1563  */
    1564 function bp_group_creator_permalink( $group = false ) {
    1565         echo bp_get_group_creator_permalink( $group );
    1566 }
    1567         /**
    1568          * Return the permalink of the creator of the current group in the loop.
    1569          *
    1570          * @since 1.7.0
    1571          *
    1572          * @param object|bool $group Optional. Group object.
    1573          *                           Default: current group in loop.
    1574          * @return string
    1575          */
    1576         function bp_get_group_creator_permalink( $group = false ) {
    1577                 global $groups_template;
    1578 
    1579                 if ( empty( $group ) ) {
    1580                         $group =& $groups_template->group;
    1581                 }
    1582 
    1583                 /**
    1584                  * Filters the permalink of the creator of the current group in the loop.
    1585                  *
    1586                  * @since 1.7.0
    1587                  * @since 2.5.0 Added the `$group` parameter.
    1588                  *
    1589                  * @param string $value Permalink of the group creator.
    1590                  * @param object $group Group object.
    1591                  */
    1592                 return apply_filters( 'bp_get_group_creator_permalink', bp_core_get_user_domain( $group->creator_id ), $group );
    1593         }
    1594 
    1595 /**
    1596  * Determine whether a user is the creator of the current group in the loop.
    1597  *
    1598  * @since 1.7.0
    1599  *
    1600  * @param object|bool $group   Optional. Group object.
    1601  *                             Default: current group in loop.
    1602  * @param int         $user_id ID of the user.
    1603  * @return bool
    1604  */
    1605 function bp_is_group_creator( $group = false, $user_id = 0 ) {
    1606         global $groups_template;
    1607 
    1608         if ( empty( $group ) ) {
    1609                 $group =& $groups_template->group;
    1610         }
    1611 
    1612         if ( empty( $user_id ) ) {
    1613                 $user_id = bp_loggedin_user_id();
    1614         }
    1615 
    1616         return (bool) ( $group->creator_id == $user_id );
    1617 }
    1618 
    1619 /**
    1620  * Output the avatar of the creator of the current group in the loop.
    1621  *
    1622  * @since 1.7.0
    1623  *
    1624  * @param object|bool $group Optional. Group object.
    1625  *                           Default: current group in loop.
    1626  * @param array       $args {
    1627  *     Array of optional arguments. See {@link bp_get_group_creator_avatar()}
    1628  *     for description.
    1629  * }
    1630  */
    1631 function bp_group_creator_avatar( $group = false, $args = array() ) {
    1632         echo bp_get_group_creator_avatar( $group, $args );
    1633 }
    1634         /**
    1635          * Return the avatar of the creator of the current group in the loop.
    1636          *
    1637          * @since 1.7.0
    1638          *
    1639          * @param object|bool $group Optional. Group object.
    1640          *                           Default: current group in loop.
    1641          * @param array       $args {
    1642          *     Array of optional arguments. See {@link bp_core_fetch_avatar()}
    1643          *     for detailed description of arguments.
    1644          *     @type string $type   Default: 'full'.
    1645          *     @type int    $width  Default: false.
    1646          *     @type int    $height Default: false.
    1647          *     @type int    $class  Default: 'avatar'.
    1648          *     @type string $id     Passed to 'css_id'. Default: false.
    1649          *     @type string $alt    Alt text. Default: 'Group creator profile
    1650          *                          photo of [user display name]'.
    1651          * }
    1652          * @return string
    1653          */
    1654         function bp_get_group_creator_avatar( $group = false, $args = array() ) {
    1655                 global $groups_template;
    1656 
    1657                 if ( empty( $group ) ) {
    1658                         $group =& $groups_template->group;
    1659                 }
    1660 
    1661                 $defaults = array(
    1662                         'type'   => 'full',
    1663                         'width'  => false,
    1664                         'height' => false,
    1665                         'class'  => 'avatar',
    1666                         'id'     => false,
    1667                         'alt'    => sprintf( __( 'Group creator profile photo of %s', 'buddypress' ),  bp_core_get_user_displayname( $group->creator_id ) )
    1668                 );
    1669 
    1670                 $r = wp_parse_args( $args, $defaults );
    1671                 extract( $r, EXTR_SKIP );
    1672 
    1673                 $avatar = bp_core_fetch_avatar( array( 'item_id' => $group->creator_id, 'type' => $type, 'css_id' => $id, 'class' => $class, 'width' => $width, 'height' => $height, 'alt' => $alt ) );
    1674 
    1675                 /**
    1676                  * Filters the avatar of the creator of the current group in the loop.
    1677                  *
    1678                  * @since 1.7.0
    1679                  * @since 2.5.0 Added the `$group` parameter.
    1680                  *
    1681                  * @param string $avatar Avatar of the group creator.
    1682                  * @param object $group  Group object.
    1683                  */
    1684                 return apply_filters( 'bp_get_group_creator_avatar', $avatar, $group );
    1685         }
    1686 
    1687 /**
    1688  * Determine whether the current user is the admin of the current group.
    1689  *
    1690  * Alias of {@link bp_is_item_admin()}.
    1691  *
    1692  * @since 1.1.0
    1693  *
    1694  * @return bool
    1695  */
    1696 function bp_group_is_admin() {
    1697         return bp_is_item_admin();
    1698 }
    1699 
    1700 /**
    1701  * Determine whether the current user is a mod of the current group.
    1702  *
    1703  * Alias of {@link bp_is_item_mod()}.
    1704  *
    1705  * @since 1.1.0
    1706  *
    1707  * @return bool
    1708  */
    1709 function bp_group_is_mod() {
    1710         return bp_is_item_mod();
    1711 }
    1712 
    1713 /**
    1714  * Output markup listing group admins.
    1715  *
    1716  * @since 1.0.0
    1717  *
    1718  * @param object|bool $group Optional. Group object.
    1719  *                           Default: current group in loop.
    1720  */
    1721 function bp_group_list_admins( $group = false ) {
    1722         global $groups_template;
    1723 
    1724         if ( empty( $group ) ) {
    1725                 $group =& $groups_template->group;
    1726         }
    1727 
    1728         // Fetch group admins if 'populate_extras' flag is false.
    1729         if ( empty( $group->args['populate_extras'] ) ) {
    1730                 $query = new BP_Group_Member_Query( array(
    1731                         'group_id'   => $group->id,
    1732                         'group_role' => 'admin',
    1733                         'type'       => 'first_joined',
    1734                 ) );
    1735 
    1736                 if ( ! empty( $query->results ) ) {
    1737                         $group->admins = $query->results;
    1738                 }
    1739         }
    1740 
    1741         if ( ! empty( $group->admins ) ) { ?>
    1742                 <ul id="group-admins">
    1743                         <?php foreach( (array) $group->admins as $admin ) { ?>
    1744                                 <li>
    1745                                         <a href="<?php echo bp_core_get_user_domain( $admin->user_id, $admin->user_nicename, $admin->user_login ) ?>"><?php echo bp_core_fetch_avatar( array( 'item_id' => $admin->user_id, 'email' => $admin->user_email, 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_core_get_user_displayname( $admin->user_id ) ) ) ) ?></a>
    1746                                 </li>
    1747                         <?php } ?>
    1748                 </ul>
    1749         <?php } else { ?>
    1750                 <span class="activity"><?php _e( 'No Admins', 'buddypress' ) ?></span>
    1751         <?php } ?>
    1752 <?php
    1753 }
    1754 
    1755 /**
    1756  * Output markup listing group mod.
    1757  *
    1758  * @since 1.0.0
    1759  *
    1760  * @param object|bool $group Optional. Group object.
    1761  *                           Default: current group in loop.
    1762  */
    1763 function bp_group_list_mods( $group = false ) {
    1764         global $groups_template;
    1765 
    1766         if ( empty( $group ) ) {
    1767                 $group =& $groups_template->group;
    1768         }
    1769 
    1770         // Fetch group mods if 'populate_extras' flag is false.
    1771         if ( empty( $group->args['populate_extras'] ) ) {
    1772                 $query = new BP_Group_Member_Query( array(
    1773                         'group_id'   => $group->id,
    1774                         'group_role' => 'mod',
    1775                         'type'       => 'first_joined',
    1776                 ) );
    1777 
    1778                 if ( ! empty( $query->results ) ) {
    1779                         $group->mods = $query->results;
    1780                 }
    1781         }
    1782 
    1783         if ( ! empty( $group->mods ) ) : ?>
    1784 
    1785                 <ul id="group-mods">
    1786 
    1787                         <?php foreach( (array) $group->mods as $mod ) { ?>
    1788 
    1789                                 <li>
    1790                                         <a href="<?php echo bp_core_get_user_domain( $mod->user_id, $mod->user_nicename, $mod->user_login ) ?>"><?php echo bp_core_fetch_avatar( array( 'item_id' => $mod->user_id, 'email' => $mod->user_email, 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_core_get_user_displayname( $mod->user_id ) ) ) ) ?></a>
    1791                                 </li>
    1792 
    1793                         <?php } ?>
    1794 
    1795                 </ul>
    1796 
    1797 <?php else : ?>
    1798 
    1799                 <span class="activity"><?php _e( 'No Mods', 'buddypress' ) ?></span>
    1800 
    1801 <?php endif;
    1802 
    1803 }
    1804 
    1805 /**
    1806  * Return a list of user IDs for a group's admins.
    1807  *
    1808  * @since 1.5.0
    1809  *
    1810  * @param BP_Groups_Group|bool $group     Optional. The group being queried. Defaults
    1811  *                                        to the current group in the loop.
    1812  * @param string               $format    Optional. 'string' to get a comma-separated string,
    1813  *                                        'array' to get an array.
    1814  * @return mixed               $admin_ids A string or array of user IDs.
    1815  */
    1816 function bp_group_admin_ids( $group = false, $format = 'string' ) {
    1817         global $groups_template;
    1818 
    1819         if ( empty( $group ) ) {
    1820                 $group =& $groups_template->group;
    1821         }
    1822 
    1823         $admin_ids = array();
    1824 
    1825         if ( $group->admins ) {
    1826                 foreach( $group->admins as $admin ) {
    1827                         $admin_ids[] = $admin->user_id;
    1828                 }
    1829         }
    1830 
    1831         if ( 'string' == $format ) {
    1832                 $admin_ids = implode( ',', $admin_ids );
    1833         }
    1834 
    1835         /**
    1836          * Filters a list of user IDs for a group's admins.
    1837          *
    1838          * This filter may return either an array or a comma separated string.
    1839          *
    1840          * @since 1.5.0
    1841          * @since 2.5.0 Added the `$group` parameter.
    1842          *
    1843          * @param array|string $admin_ids List of user IDs for a group's admins.
    1844          * @param object       $group     Group object.
    1845          */
    1846         return apply_filters( 'bp_group_admin_ids', $admin_ids, $group );
    1847 }
    1848 
    1849 /**
    1850  * Return a list of user IDs for a group's moderators.
    1851  *
    1852  * @since 1.5.0
    1853  *
    1854  * @param BP_Groups_Group|bool $group   Optional. The group being queried.
    1855  *                                      Defaults to the current group in the loop.
    1856  * @param string               $format  Optional. 'string' to get a comma-separated string,
    1857  *                                      'array' to get an array.
    1858  * @return mixed               $mod_ids A string or array of user IDs.
    1859  */
    1860 function bp_group_mod_ids( $group = false, $format = 'string' ) {
    1861         global $groups_template;
    1862 
    1863         if ( empty( $group ) ) {
    1864                 $group =& $groups_template->group;
    1865         }
    1866 
    1867         $mod_ids = array();
    1868 
    1869         if ( $group->mods ) {
    1870                 foreach( $group->mods as $mod ) {
    1871                         $mod_ids[] = $mod->user_id;
    1872                 }
    1873         }
    1874 
    1875         if ( 'string' == $format ) {
    1876                 $mod_ids = implode( ',', $mod_ids );
    1877         }
    1878 
    1879         /**
    1880          * Filters a list of user IDs for a group's moderators.
    1881          *
    1882          * This filter may return either an array or a comma separated string.
    1883          *
    1884          * @since 1.5.0
    1885          * @since 2.5.0 Added the `$group` parameter.
    1886          *
    1887          * @param array|string $admin_ids List of user IDs for a group's moderators.
    1888          * @param object       $group     Group object.
    1889          */
    1890         return apply_filters( 'bp_group_mod_ids', $mod_ids, $group );
    1891 }
    1892 
    1893 /**
    1894  * Output the permalink of the current group's Members page.
    1895  *
    1896  * @since 1.0.0
    1897  */
    1898 function bp_group_all_members_permalink() {
    1899         echo bp_get_group_all_members_permalink();
    1900 }
    1901         /**
    1902          * Return the permalink of the Members page of the current group in the loop.
    1903          *
    1904          * @since 1.0.0
    1905          *
    1906          * @param object|bool $group Optional. Group object.
    1907          *                           Default: current group in loop.
    1908          * @return string
    1909          */
    1910         function bp_get_group_all_members_permalink( $group = false ) {
    1911                 global $groups_template;
    1912 
    1913                 if ( empty( $group ) ) {
    1914                         $group =& $groups_template->group;
    1915                 }
    1916 
    1917                 /**
    1918                  * Filters the permalink of the Members page for the current group in the loop.
    1919                  *
    1920                  * @since 1.0.0
    1921                  * @since 2.5.0 Added the `$group` parameter.
    1922                  *
    1923                  * @param string $value Permalink of the Members page for the current group.
    1924                  * @param object $group Group object.
    1925                  */
    1926                 return apply_filters( 'bp_get_group_all_members_permalink', bp_get_group_permalink( $group ) . 'members', $group );
    1927         }
    1928 
    1929 /**
    1930  * Display a Groups search form.
    1931  *
    1932  * No longer used in BuddyPress.
    1933  *
    1934  * @todo Deprecate.
    1935  */
    1936 function bp_group_search_form() {
    1937 
    1938         $action = bp_displayed_user_domain() . bp_get_groups_slug() . '/my-groups/search/';
    1939         $label = __('Filter Groups', 'buddypress');
    1940         $name = 'group-filter-box';
    1941 
    1942         $search_form_html = '<form action="' . $action . '" id="group-search-form" method="post">
    1943                 <label for="'. $name .'" id="'. $name .'-label">'. $label .'</label>
    1944                 <input type="search" name="'. $name . '" id="'. $name .'" value="'. $value .'"'.  $disabled .' />
    1945 
    1946                 '. wp_nonce_field( 'group-filter-box', '_wpnonce_group_filter', true, false ) .'
    1947                 </form>';
    1948 
    1949         echo apply_filters( 'bp_group_search_form', $search_form_html );
    1950 }
    1951 
    1952 /**
    1953  * Determine whether the displayed user has no groups.
    1954  *
    1955  * No longer used in BuddyPress.
    1956  *
    1957  * @todo Deprecate.
    1958  *
    1959  * @return bool True if the displayed user has no groups, otherwise false.
    1960  */
    1961 function bp_group_show_no_groups_message() {
    1962         if ( !groups_total_groups_for_user( bp_displayed_user_id() ) ) {
    1963                 return true;
    1964         }
    1965 
    1966         return false;
    1967 }
    1968 
    1969 /**
    1970  * Determine whether the current page is a group activity permalink.
    1971  *
    1972  * No longer used in BuddyPress.
    1973  *
    1974  * @todo Deprecate.
    1975  *
    1976  * @return bool True if this is a group activity permalink, otherwise false.
    1977  */
    1978 function bp_group_is_activity_permalink() {
    1979 
    1980         if ( !bp_is_single_item() || !bp_is_groups_component() || !bp_is_current_action( bp_get_activity_slug() ) ) {
    1981                 return false;
    1982         }
    1983 
    1984         return true;
    1985 }
    1986 
    1987 /**
    1988  * Output the pagination HTML for a group loop.
    1989  *
    1990  * @since 1.2.0
    1991  */
    1992 function bp_groups_pagination_links() {
    1993         echo bp_get_groups_pagination_links();
    1994 }
    1995         /**
    1996          * Get the pagination HTML for a group loop.
    1997          *
    1998          * @since 1.2.0
    1999          *
    2000          * @return string
    2001          */
    2002         function bp_get_groups_pagination_links() {
    2003                 global $groups_template;
    2004 
    2005                 /**
    2006                  * Filters the pagination HTML for a group loop.
    2007                  *
    2008                  * @since 1.2.0
    2009                  *
    2010                  * @param string $pag_links HTML markup for the pagination links.
    2011                  */
    2012                 return apply_filters( 'bp_get_groups_pagination_links', $groups_template->pag_links );
    2013         }
    2014 
    2015 /**
    2016  * Output the "Viewing x-y of z groups" pagination message.
    2017  *
    2018  * @since 1.2.0
    2019  */
    2020 function bp_groups_pagination_count() {
    2021         echo bp_get_groups_pagination_count();
    2022 }
    2023         /**
    2024          * Generate the "Viewing x-y of z groups" pagination message.
    2025          *
    2026          * @since 1.5.0
    2027          *
    2028          * @return string
    2029          */
    2030         function bp_get_groups_pagination_count() {
    2031                 global $groups_template;
    2032 
    2033                 $start_num = intval( ( $groups_template->pag_page - 1 ) * $groups_template->pag_num ) + 1;
    2034                 $from_num  = bp_core_number_format( $start_num );
    2035                 $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 ) );
    2036                 $total     = bp_core_number_format( $groups_template->total_group_count );
    2037 
    2038                 if ( 1 == $groups_template->total_group_count ) {
    2039                         $message = __( 'Viewing 1 group', 'buddypress' );
    2040                 } else {
    2041                         $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 );
    2042                 }
    2043 
    2044                 /**
    2045                  * Filters the "Viewing x-y of z groups" pagination message.
    2046                  *
    2047                  * @since 1.5.0
    2048                  *
    2049                  * @param string $message  "Viewing x-y of z groups" text.
    2050                  * @param string $from_num Total amount for the low value in the range.
    2051                  * @param string $to_num   Total amount for the high value in the range.
    2052                  * @param string $total    Total amount of groups found.
    2053                  */
    2054                 return apply_filters( 'bp_get_groups_pagination_count', $message, $from_num, $to_num, $total );
    2055         }
    2056 
    2057 /**
    2058  * Determine whether groups auto-join is enabled.
    2059  *
    2060  * "Auto-join" is the toggle that determines whether users are joined to a
    2061  * public group automatically when creating content in that group.
    2062  *
    2063  * @since 1.2.6
    2064  *
    2065  * @return bool
    2066  */
    2067 function bp_groups_auto_join() {
    2068 
    2069         /**
    2070          * Filters whether groups auto-join is enabled.
    2071          *
    2072          * @since 1.2.6
    2073          *
    2074          * @param bool $value Enabled status.
    2075          */
    2076         return apply_filters( 'bp_groups_auto_join', (bool) buddypress()->groups->auto_join );
    2077 }
    2078 
    2079 /**
    2080  * Output the total member count for a group.
    2081  *
    2082  * @since 1.0.0
    2083  *
    2084  * @param object|bool $group Optional. Group object. Default: current group in loop.
    2085  */
    2086 function bp_group_total_members( $group = false ) {
    2087         echo bp_get_group_total_members( $group );
    2088 }
    2089         /**
    2090          * Get the total member count for a group.
    2091          *
    2092          * @since 1.0.0
    2093          *
    2094          * @param object|bool $group Optional. Group object.
    2095          *                           Default: current group in loop.
    2096          * @return int
    2097          */
    2098         function bp_get_group_total_members( $group = false ) {
    2099                 global $groups_template;
    2100 
    2101                 if ( empty( $group ) ) {
    2102                         $group =& $groups_template->group;
    2103                 }
    2104 
    2105                 /**
    2106                  * Filters the total member count for a group.
    2107                  *
    2108                  * @since 1.0.0
    2109                  * @since 2.5.0 Added the `$group` parameter.
    2110                  *
    2111                  * @param int    $total_member_count Total member count for a group.
    2112                  * @param object $group              Group object.
    2113                  */
    2114                 return apply_filters( 'bp_get_group_total_members', $group->total_member_count, $group );
    2115         }
    2116 
    2117 /**
    2118  * Output the "x members" count string for a group.
    2119  *
    2120  * @since 1.2.0
    2121  */
    2122 function bp_group_member_count() {
    2123         echo bp_get_group_member_count();
    2124 }
    2125         /**
    2126          * Generate the "x members" count string for a group.
    2127          *
    2128          * @since 1.2.0
    2129          *
    2130          * @return string
    2131          */
    2132         function bp_get_group_member_count() {
    2133                 global $groups_template;
    2134 
    2135                 if ( isset( $groups_template->group->total_member_count ) ) {
    2136                         $count = (int) $groups_template->group->total_member_count;
    2137                 } else {
    2138                         $count = 0;
    2139                 }
    2140 
    2141                 $count_string = sprintf( _n( '%s member', '%s members', $count, 'buddypress' ), bp_core_number_format( $count ) );
    2142 
    2143                 /**
    2144                  * Filters the "x members" count string for a group.
    2145                  *
    2146                  * @since 1.2.0
    2147                  *
    2148                  * @param string $count_string The "x members" count string for a group.
    2149                  */
    2150                 return apply_filters( 'bp_get_group_member_count', $count_string );
    2151         }
    2152 
    2153 /**
    2154  * Output the URL of the Forum page of the current group in the loop.
    2155  *
    2156  * @since 1.0.0
    2157  */
    2158 function bp_group_forum_permalink() {
    2159         echo bp_get_group_forum_permalink();
    2160 }
    2161         /**
    2162          * Generate the URL of the Forum page of a group.
    2163          *
    2164          * @since 1.0.0
    2165          *
    2166          * @param object|bool $group Optional. Group object.
    2167          *                           Default: current group in loop.
    2168          * @return string
    2169          */
    2170         function bp_get_group_forum_permalink( $group = false ) {
    2171                 global $groups_template;
    2172 
    2173                 if ( empty( $group ) ) {
    2174                         $group =& $groups_template->group;
    2175                 }
    2176 
    2177                 /**
    2178                  * Filters the URL of the Forum page of a group.
    2179                  *
    2180                  * @since 1.0.0
    2181                  * @since 2.5.0 Added the `$group` parameter.
    2182                  *
    2183                  * @param string $value URL permalink for the Forum Page.
    2184                  * @param object $group Group object.
    2185                  */
    2186                 return apply_filters( 'bp_get_group_forum_permalink', bp_get_group_permalink( $group ) . 'forum', $group );
    2187         }
    2188 
    2189 /**
    2190  * Output the topic count for a group forum.
    2191  *
    2192  * @since 1.2.0
    2193  *
    2194  * @param array|string $args See {@link bp_get_group_forum_topic_count()}.
    2195  */
    2196 function bp_group_forum_topic_count( $args = '' ) {
    2197         echo bp_get_group_forum_topic_count( $args );
    2198 }
    2199         /**
    2200          * Generate the topic count string for a group forum.
    2201          *
    2202          * @since 1.2.0
    2203          *
    2204          * @param array|string $args {
    2205          *     Array of arguments.
    2206          *     @type bool $showtext Optional. If true, result will be formatted as "x topics".
    2207          *                          If false, just a number will be returned.
    2208          *                          Default: false.
    2209          * }
    2210          * @return string|int
    2211          */
    2212         function bp_get_group_forum_topic_count( $args = '' ) {
    2213                 global $groups_template;
    2214 
    2215                 $defaults = array(
    2216                         'showtext' => false
    2217                 );
    2218 
    2219                 $r = wp_parse_args( $args, $defaults );
    2220                 extract( $r, EXTR_SKIP );
    2221 
    2222                 if ( !$forum_id = groups_get_groupmeta( $groups_template->group->id, 'forum_id' ) ) {
    2223                         return false;
    2224                 }
    2225 
    2226                 if ( !bp_is_active( 'forums' ) ) {
    2227                         return false;
    2228                 }
    2229 
    2230                 if ( !$groups_template->group->forum_counts ) {
    2231                         $groups_template->group->forum_counts = bp_forums_get_forum_topicpost_count( (int) $forum_id );
    2232                 }
    2233 
    2234                 if ( (bool) $showtext ) {
    2235                         if ( 1 == (int) $groups_template->group->forum_counts[0]->topics ) {
    2236                                 $total_topics = sprintf( __( '%d topic', 'buddypress' ), (int) $groups_template->group->forum_counts[0]->topics );
    2237                         } else {
    2238                                 $total_topics = sprintf( __( '%d topics', 'buddypress' ), (int) $groups_template->group->forum_counts[0]->topics );
    2239                         }
    2240                 } else {
    2241                         $total_topics = (int) $groups_template->group->forum_counts[0]->topics;
    2242                 }
    2243 
    2244                 /**
    2245                  * Filters the topic count string for a group forum.
    2246                  *
    2247                  * @since 1.2.0
    2248                  *
    2249                  * @param string $total_topics Total topic count string.
    2250                  * @param bool   $showtext     Whether or not to return as formatted string.
    2251                  */
    2252                 return apply_filters( 'bp_get_group_forum_topic_count', $total_topics, (bool)$showtext );
    2253         }
    2254 
    2255 /**
    2256  * Output the post count for a group forum.
    2257  *
    2258  * @since 1.2.0
    2259  *
    2260  * @param array|string $args See {@link bp_get_group_forum_post_count()}.
    2261  */
    2262 function bp_group_forum_post_count( $args = '' ) {
    2263         echo bp_get_group_forum_post_count( $args );
    2264 }
    2265         /**
    2266          * Generate the post count string for a group forum.
    2267          *
    2268          * @since 1.2.0
    2269          *
    2270          * @param array|string $args {
    2271          *     Array of arguments.
    2272          *     @type bool $showtext Optional. If true, result will be formatted as "x posts".
    2273          *                          If false, just a number will be returned.
    2274          *                          Default: false.
    2275          * }
    2276          * @return string|int
    2277          */
    2278         function bp_get_group_forum_post_count( $args = '' ) {
    2279                 global $groups_template;
    2280 
    2281                 $defaults = array(
    2282                         'showtext' => false
    2283                 );
    2284 
    2285                 $r = wp_parse_args( $args, $defaults );
    2286                 extract( $r, EXTR_SKIP );
    2287 
    2288                 if ( !$forum_id = groups_get_groupmeta( $groups_template->group->id, 'forum_id' ) ) {
    2289                         return false;
    2290                 }
    2291 
    2292                 if ( !bp_is_active( 'forums' ) ) {
    2293                         return false;
    2294                 }
    2295 
    2296                 if ( !$groups_template->group->forum_counts ) {
    2297                         $groups_template->group->forum_counts = bp_forums_get_forum_topicpost_count( (int) $forum_id );
    2298                 }
    2299 
    2300                 if ( (bool) $showtext ) {
    2301                         if ( 1 == (int) $groups_template->group->forum_counts[0]->posts ) {
    2302                                 $total_posts = sprintf( __( '%d post', 'buddypress' ), (int) $groups_template->group->forum_counts[0]->posts );
    2303                         } else {
    2304                                 $total_posts = sprintf( __( '%d posts', 'buddypress' ), (int) $groups_template->group->forum_counts[0]->posts );
    2305                         }
    2306                 } else {
    2307                         $total_posts = (int) $groups_template->group->forum_counts[0]->posts;
    2308                 }
    2309 
    2310                 /**
    2311                  * Filters the post count string for a group forum.
    2312                  *
    2313                  * @since 1.2.0
    2314                  *
    2315                  * @param string $total_posts Total post count string.
    2316                  * @param bool   $showtext    Whether or not to return as formatted string.
    2317                  */
    2318                 return apply_filters( 'bp_get_group_forum_post_count', $total_posts, (bool)$showtext );
    2319         }
    2320 
    2321 /**
    2322  * Determine whether forums are enabled for a group.
    2323  *
    2324  * @since 1.0.0
    2325  *
    2326  * @param object|bool $group Optional. Group object. Default: current group in loop.
    2327  * @return bool
    2328  */
    2329 function bp_group_is_forum_enabled( $group = false ) {
    2330         global $groups_template;
    2331 
    2332         if ( empty( $group ) ) {
    2333                 $group =& $groups_template->group;
    2334         }
    2335 
    2336         if ( ! empty( $group->enable_forum ) ) {
    2337                 return true;
    2338         }
    2339 
    2340         return false;
    2341 }
    2342 
    2343 /**
    2344  * Output the 'checked' attribute for the group forums settings UI.
    2345  *
    2346  * @since 1.0.0
    2347  *
    2348  * @param object|bool $group Optional. Group object. Default: current group in loop.
    2349  */
    2350 function bp_group_show_forum_setting( $group = false ) {
    2351         global $groups_template;
    2352 
    2353         if ( empty( $group ) ) {
    2354                 $group =& $groups_template->group;
    2355         }
    2356 
    2357         if ( $group->enable_forum ) {
    2358                 echo ' checked="checked"';
    2359         }
    2360 }
    2361 
    2362 /**
    2363  * Output the 'checked' attribute for a given status in the settings UI.
    2364  *
    2365  * @since 1.0.0
    2366  *
    2367  * @param string      $setting Group status. 'public', 'private', 'hidden'.
    2368  * @param object|bool $group   Optional. Group object. Default: current group in loop.
    2369  */
    2370 function bp_group_show_status_setting( $setting, $group = false ) {
    2371         global $groups_template;
    2372 
    2373         if ( empty( $group ) ) {
    2374                 $group =& $groups_template->group;
    2375         }
    2376 
    2377         if ( $setting == $group->status ) {
    2378                 echo ' checked="checked"';
    2379         }
    2380 }
    2381 
    2382 /**
    2383  * Output the 'checked' value, if needed, for a given invite_status on the group create/admin screens
    2384  *
    2385  * @since 1.5.0
    2386  *
    2387  * @param string      $setting The setting you want to check against ('members',
    2388  *                             'mods', or 'admins').
    2389  * @param object|bool $group   Optional. Group object. Default: current group in loop.
    2390  */
    2391 function bp_group_show_invite_status_setting( $setting, $group = false ) {
    2392         $group_id = isset( $group->id ) ? $group->id : false;
    2393 
    2394         $invite_status = bp_group_get_invite_status( $group_id );
    2395 
    2396         if ( $setting == $invite_status ) {
    2397                 echo ' checked="checked"';
    2398         }
    2399 }
    2400 
    2401 /**
    2402  * Get the invite status of a group.
    2403  *
    2404  * 'invite_status' became part of BuddyPress in BP 1.5. In order to provide
    2405  * backward compatibility with earlier installations, groups without a status
    2406  * set will default to 'members', ie all members in a group can send
    2407  * invitations. Filter 'bp_group_invite_status_fallback' to change this
    2408  * fallback behavior.
    2409  *
    2410  * This function can be used either in or out of the loop.
    2411  *
    2412  * @since 1.5.0
    2413  *
    2414  * @param int|bool $group_id Optional. The ID of the group whose status you want to
    2415  *                           check. Default: the displayed group, or the current group
    2416  *                           in the loop.
    2417  * @return bool|string Returns false when no group can be found. Otherwise
    2418  *                     returns the group invite status, from among 'members',
    2419  *                     'mods', and 'admins'.
    2420  */
    2421 function bp_group_get_invite_status( $group_id = false ) {
    2422         global $groups_template;
    2423 
    2424         if ( !$group_id ) {
    2425                 $bp = buddypress();
    2426 
    2427                 if ( isset( $bp->groups->current_group->id ) ) {
    2428                         // Default to the current group first.
    2429                         $group_id = $bp->groups->current_group->id;
    2430                 } elseif ( isset( $groups_template->group->id ) ) {
    2431                         // Then see if we're in the loop.
    2432                         $group_id = $groups_template->group->id;
    2433                 } else {
    2434                         return false;
    2435                 }
    2436         }
    2437 
    2438         $invite_status = groups_get_groupmeta( $group_id, 'invite_status' );
    2439 
    2440         // Backward compatibility. When 'invite_status' is not set, fall back to a default value.
    2441         if ( !$invite_status ) {
    2442                 $invite_status = apply_filters( 'bp_group_invite_status_fallback', 'members' );
    2443         }
    2444 
    2445         /**
    2446          * Filters the invite status of a group.
    2447          *
    2448          * Invite status in this case means who from the group can send invites.
    2449          *
    2450          * @since 1.5.0
    2451          *
    2452          * @param string $invite_status Membership level needed to send an invite.
    2453          * @param int    $group_id      ID of the group whose status is being checked.
    2454          */
    2455         return apply_filters( 'bp_group_get_invite_status', $invite_status, $group_id );
    2456 }
    2457 
    2458 /**
    2459  * Can a user send invitations in the specified group?
    2460  *
    2461  * @since 1.5.0
    2462  * @since 2.2.0 Added the $user_id parameter.
    2463  *
    2464  * @param int $group_id The group ID to check.
    2465  * @param int $user_id  The user ID to check.
    2466  * @return bool
    2467  */
    2468 function bp_groups_user_can_send_invites( $group_id = 0, $user_id = 0 ) {
    2469         $can_send_invites = false;
    2470         $invite_status    = false;
    2471 
    2472         // If $user_id isn't specified, we check against the logged-in user.
    2473         if ( ! $user_id ) {
    2474                 $user_id = bp_loggedin_user_id();
    2475         }
    2476 
    2477         // If $group_id isn't specified, use existing one if available.
    2478         if ( ! $group_id ) {
    2479                 $group_id = bp_get_current_group_id();
    2480         }
    2481 
    2482         if ( $user_id ) {
    2483                 // Users with the 'bp_moderate' cap can always send invitations.
    2484                 if ( user_can( $user_id, 'bp_moderate' ) ) {
    2485                         $can_send_invites = true;
    2486                 } else {
    2487                         $invite_status = bp_group_get_invite_status( $group_id );
    2488 
    2489                         switch ( $invite_status ) {
    2490                                 case 'admins' :
    2491                                         if ( groups_is_user_admin( $user_id, $group_id ) ) {
    2492                                                 $can_send_invites = true;
    2493                                         }
    2494                                         break;
    2495 
    2496                                 case 'mods' :
    2497                                         if ( groups_is_user_mod( $user_id, $group_id ) || groups_is_user_admin( $user_id, $group_id ) ) {
    2498                                                 $can_send_invites = true;
    2499                                         }
    2500                                         break;
    2501 
    2502                                 case 'members' :
    2503                                         if ( groups_is_user_member( $user_id, $group_id ) ) {
    2504                                                 $can_send_invites = true;
    2505                                         }
    2506                                         break;
    2507                         }
    2508                 }
    2509         }
    2510 
    2511         /**
    2512          * Filters whether a user can send invites in a group.
    2513          *
    2514          * @since 1.5.0
    2515          * @since 2.2.0 Added the $user_id parameter.
    2516          *
    2517          * @param bool $can_send_invites Whether the user can send invites
    2518          * @param int  $group_id         The group ID being checked
    2519          * @param bool $invite_status    The group's current invite status
    2520          * @param int  $user_id          The user ID being checked
    2521          */
    2522         return apply_filters( 'bp_groups_user_can_send_invites', $can_send_invites, $group_id, $invite_status, $user_id );
    2523 }
    2524 
    2525 /**
    2526  * Since BuddyPress 1.0, this generated the group settings admin/member screen.
    2527  * As of BuddyPress 1.5 (r4489), and because this function outputs HTML, it was moved into /bp-default/groups/single/admin.php.
    2528  *
    2529  * @deprecated 1.5
    2530  * @deprecated No longer used.
    2531  * @since 1.0.0
    2532  * @todo Remove in 1.4
    2533  *
    2534  * @param bool $admin_list
    2535  * @param bool $group
    2536  */
    2537 function bp_group_admin_memberlist( $admin_list = false, $group = false ) {
    2538         global $groups_template;
    2539 
    2540         _deprecated_function( __FUNCTION__, '1.5', 'No longer used. See /bp-default/groups/single/admin.php' );
    2541 
    2542         if ( empty( $group ) ) {
    2543                 $group =& $groups_template->group;
    2544         }
    2545 
    2546 
    2547         if ( $admins = groups_get_group_admins( $group->id ) ) : ?>
    2548 
    2549                 <ul id="admins-list" class="item-list<?php if ( !empty( $admin_list ) ) : ?> single-line<?php endif; ?>">
    2550 
    2551                 <?php foreach ( (array) $admins as $admin ) { ?>
    2552 
    2553                         <?php if ( !empty( $admin_list ) ) : ?>
    2554 
    2555                         <li>
    2556 
    2557                                 <?php echo bp_core_fetch_avatar( array( 'item_id' => $admin->user_id, 'type' => 'thumb', 'width' => 30, 'height' => 30, 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_core_get_user_displayname( $admin->user_id ) ) ) ) ?>
    2558 
    2559                                 <h5>
    2560 
    2561                                         <?php echo bp_core_get_userlink( $admin->user_id ); ?>
    2562 
    2563                                         <span class="small">
    2564                                                 <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>
    2565                                         </span>
    2566                                 </h5>
    2567                         </li>
    2568 
    2569                         <?php else : ?>
    2570 
    2571                         <li>
    2572 
    2573                                 <?php echo bp_core_fetch_avatar( array( 'item_id' => $admin->user_id, 'type' => 'thumb', 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_core_get_user_displayname( $admin->user_id ) ) ) ) ?>
    2574 
    2575                                 <h5><?php echo bp_core_get_userlink( $admin->user_id ) ?></h5>
    2576                                 <span class="activity">
    2577                                         <?php echo bp_core_get_last_activity( strtotime( $admin->date_modified ), __( 'joined %s', 'buddypress') ); ?>
    2578                                 </span>
    2579 
    2580                                 <?php if ( bp_is_active( 'friends' ) ) : ?>
    2581 
    2582                                         <div class="action">
    2583 
    2584                                                 <?php bp_add_friend_button( $admin->user_id ); ?>
    2585 
    2586                                         </div>
    2587 
    2588                                 <?php endif; ?>
    2589 
    2590                         </li>
    2591 
    2592                         <?php endif;
    2593                 } ?>
    2594 
    2595                 </ul>
    2596 
    2597         <?php else : ?>
    2598 
    2599                 <div id="message" class="info">
    2600                         <p><?php _e( 'This group has no administrators', 'buddypress' ); ?></p>
    2601                 </div>
    2602 
    2603         <?php endif;
    2604 }
    2605 
    2606 /**
    2607  * Generate the HTML for a list of group moderators.
    2608  *
    2609  * No longer used.
    2610  *
    2611  * @todo Deprecate.
    2612  *
    2613  * @param bool $admin_list
    2614  * @param bool $group
    2615  */
    2616 function bp_group_mod_memberlist( $admin_list = false, $group = false ) {
    2617         global $groups_template;
    2618 
    2619         if ( empty( $group ) ) {
    2620                 $group =& $groups_template->group;
    2621         }
    2622 
    2623         if ( $group_mods = groups_get_group_mods( $group->id ) ) { ?>
    2624 
    2625                 <ul id="mods-list" class="item-list<?php if ( $admin_list ) { ?> single-line<?php } ?>">
    2626 
    2627                 <?php foreach ( (array) $group_mods as $mod ) { ?>
    2628 
    2629                         <?php if ( !empty( $admin_list ) ) { ?>
    2630 
    2631                         <li>
    2632 
    2633                                 <?php echo bp_core_fetch_avatar( array( 'item_id' => $mod->user_id, 'type' => 'thumb', 'width' => 30, 'height' => 30, 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_core_get_user_displayname( $mod->user_id ) ) ) ) ?>
    2634 
    2635                                 <h5>
    2636                                         <?php echo bp_core_get_userlink( $mod->user_id ); ?>
    2637 
    2638                                         <span class="small">
    2639                                                 <a href="<?php bp_group_member_promote_admin_link( array( 'user_id' => $mod->user_id ) ) ?>" class="button confirm mod-promote-to-admin" title="<?php esc_attr_e( 'Promote to Admin', 'buddypress' ); ?>"><?php _e( 'Promote to Admin', 'buddypress' ); ?></a>
    2640                                                 <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>
    2641                                         </span>
    2642                                 </h5>
    2643                         </li>
    2644 
    2645                         <?php } else { ?>
    2646 
    2647                         <li>
    2648 
    2649                                 <?php echo bp_core_fetch_avatar( array( 'item_id' => $mod->user_id, 'type' => 'thumb', 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_core_get_user_displayname( $mod->user_id ) ) ) ) ?>
    2650 
    2651                                 <h5><?php echo bp_core_get_userlink( $mod->user_id ) ?></h5>
    2652 
    2653                                 <span class="activity"><?php echo bp_core_get_last_activity( strtotime( $mod->date_modified ), __( 'joined %s', 'buddypress') ); ?></span>
    2654 
    2655                                 <?php if ( bp_is_active( 'friends' ) ) : ?>
    2656 
    2657                                         <div class="action">
    2658                                                 <?php bp_add_friend_button( $mod->user_id ) ?>
    2659                                         </div>
    2660 
    2661                                 <?php endif; ?>
    2662 
    2663                         </li>
    2664 
    2665                         <?php } ?>
    2666                 <?php } ?>
    2667 
    2668                 </ul>
    2669 
    2670         <?php } else { ?>
    2671 
    2672                 <div id="message" class="info">
    2673                         <p><?php _e( 'This group has no moderators', 'buddypress' ); ?></p>
    2674                 </div>
    2675 
    2676         <?php }
    2677 }
    2678 
    2679 /**
    2680  * Determine whether a group has moderators.
    2681  *
    2682  * @since 1.0.0
    2683  *
    2684  * @param object|bool $group Optional. Group object. Default: current group in loop.
    2685  * @return array Info about group admins (user_id + date_modified).
    2686  */
    2687 function bp_group_has_moderators( $group = false ) {
    2688         global $groups_template;
    2689 
    2690         if ( empty( $group ) ) {
    2691                 $group =& $groups_template->group;
    2692         }
    2693 
    2694         /**
    2695          * Filters whether a group has moderators.
    2696          *
    2697          * @since 1.0.0
    2698          * @since 2.5.0 Added the `$group` parameter.
    2699          *
    2700          * @param array  $value Array of user IDs who are a moderator of the provided group.
    2701          * @param object $group Group object.
    2702          */
    2703         return apply_filters( 'bp_group_has_moderators', groups_get_group_mods( $group->id ), $group );
    2704 }
    2705 
    2706 /**
    2707  * Output a URL for promoting a user to moderator.
    2708  *
    2709  * @since 1.1.0
    2710  *
    2711  * @param array|string $args See {@link bp_get_group_member_promote_mod_link()}.
    2712  */
    2713 function bp_group_member_promote_mod_link( $args = '' ) {
    2714         echo bp_get_group_member_promote_mod_link( $args );
    2715 }
    2716         /**
    2717          * Generate a URL for promoting a user to moderator.
    2718          *
    2719          * @since 1.1.0
    2720          *
    2721          * @param array|string $args {
    2722          *     @type int    $user_id ID of the member to promote. Default:
    2723          *                           current member in a group member loop.
    2724          *     @type object $group   Group object. Default: current group.
    2725          * }
    2726          * @return string
    2727          */
    2728         function bp_get_group_member_promote_mod_link( $args = '' ) {
    2729                 global $members_template, $groups_template;
    2730 
    2731                 $defaults = array(
    2732                         'user_id' => $members_template->member->user_id,
    2733                         'group'   => &$groups_template->group
    2734                 );
    2735 
    2736                 $r = wp_parse_args( $args, $defaults );
    2737                 extract( $r, EXTR_SKIP );
    2738 
    2739                 /**
    2740                  * Filters a URL for promoting a user to moderator.
    2741                  *
    2742                  * @since 1.1.0
    2743                  *
    2744                  * @param string $value URL to use for promoting a user to moderator.
    2745                  */
    2746                 return apply_filters( 'bp_get_group_member_promote_mod_link', wp_nonce_url( bp_get_group_permalink( $group ) . 'admin/manage-members/promote/mod/' . $user_id, 'groups_promote_member' ) );
    2747         }
    2748 
    2749 /**
    2750  * Output a URL for promoting a user to admin.
    2751  *
    2752  * @since 1.1.0
    2753  *
    2754  * @param array|string $args See {@link bp_get_group_member_promote_admin_link()}.
    2755  */
    2756 function bp_group_member_promote_admin_link( $args = '' ) {
    2757         echo bp_get_group_member_promote_admin_link( $args );
    2758 }
    2759         /**
    2760          * Generate a URL for promoting a user to admin.
    2761          *
    2762          * @since 1.1.0
    2763          *
    2764          * @param array|string $args {
    2765          *     @type int    $user_id ID of the member to promote. Default:
    2766          *                           current member in a group member loop.
    2767          *     @type object $group   Group object. Default: current group.
    2768          * }
    2769          * @return string
    2770          */
    2771         function bp_get_group_member_promote_admin_link( $args = '' ) {
    2772                 global $members_template, $groups_template;
    2773 
    2774                 $defaults = array(
    2775                         'user_id' => !empty( $members_template->member->user_id ) ? $members_template->member->user_id : false,
    2776                         'group'   => &$groups_template->group
    2777                 );
    2778 
    2779                 $r = wp_parse_args( $args, $defaults );
    2780                 extract( $r, EXTR_SKIP );
    2781 
    2782                 /**
    2783                  * Filters a URL for promoting a user to admin.
    2784                  *
    2785                  * @since 1.1.0
    2786                  *
    2787                  * @param string $value URL to use for promoting a user to admin.
    2788                  */
    2789                 return apply_filters( 'bp_get_group_member_promote_admin_link', wp_nonce_url( bp_get_group_permalink( $group ) . 'admin/manage-members/promote/admin/' . $user_id, 'groups_promote_member' ) );
    2790         }
    2791 
    2792 /**
    2793  * Output a URL for demoting a user to member.
    2794  *
    2795  * @since 1.0.0
    2796  *
    2797  * @param int $user_id ID of the member to demote. Default: current member in
    2798  *                     a member loop.
    2799  */
    2800 function bp_group_member_demote_link( $user_id = 0 ) {
    2801         global $members_template;
    2802 
    2803         if ( !$user_id ) {
    2804                 $user_id = $members_template->member->user_id;
    2805         }
    2806 
    2807         echo bp_get_group_member_demote_link( $user_id );
    2808 }
    2809         /**
    2810          * Generate a URL for demoting a user to member.
    2811          *
    2812          * @since 1.0.0
    2813          *
    2814          * @param int         $user_id ID of the member to demote. Default: current
    2815          *                             member in a member loop.
    2816          * @param object|bool $group   Optional. Group object. Default: current group.
    2817          * @return string
    2818          */
    2819         function bp_get_group_member_demote_link( $user_id = 0, $group = false ) {
    2820                 global $members_template, $groups_template;
    2821 
    2822                 if ( empty( $group ) ) {
    2823                         $group =& $groups_template->group;
    2824                 }
    2825 
    2826                 if ( !$user_id ) {
    2827                         $user_id = $members_template->member->user_id;
    2828                 }
    2829 
    2830                 /**
    2831                  * Filters a URL for demoting a user to member.
    2832                  *
    2833                  * @since 1.0.0
    2834                  * @since 2.5.0 Added the `$group` parameter.
    2835                  *
    2836                  * @param string $value URL to use for demoting a user to member.
    2837                  * @param object $group Group object.
    2838                  */
    2839                 return apply_filters( 'bp_get_group_member_demote_link', wp_nonce_url( bp_get_group_permalink( $group ) . 'admin/manage-members/demote/' . $user_id, 'groups_demote_member' ), $group );
    2840         }
    2841 
    2842 /**
    2843  * Output a URL for banning a member from a group.
    2844  *
    2845  * @since 1.0.0
    2846  *
    2847  * @param int $user_id ID of the member to ban.
    2848  *                     Default: current member in a member loop.
    2849  */
    2850 function bp_group_member_ban_link( $user_id = 0 ) {
    2851         global $members_template;
    2852 
    2853         if ( !$user_id ) {
    2854                 $user_id = $members_template->member->user_id;
    2855         }
    2856 
    2857         echo bp_get_group_member_ban_link( $user_id );
    2858 }
    2859         /**
    2860          * Generate a URL for banning a member from a group.
    2861          *
    2862          * @since 1.0.0
    2863          *
    2864          * @param int         $user_id ID of the member to ban.
    2865          *                             Default: current member in a member loop.
    2866          * @param object|bool $group   Optional. Group object. Default: current group.
    2867          * @return string
    2868          */
    2869         function bp_get_group_member_ban_link( $user_id = 0, $group = false ) {
    2870                 global $groups_template;
    2871 
    2872                 if ( empty( $group ) ) {
    2873                         $group =& $groups_template->group;
    2874                 }
    2875 
    2876                 /**
    2877                  * Filters a URL for banning a member from a group.
    2878                  *
    2879                  * @since 1.0.0
    2880                  *
    2881                  * @param string $value URL to use for banning a member.
    2882                  */
    2883                 return apply_filters( 'bp_get_group_member_ban_link', wp_nonce_url( bp_get_group_permalink( $group ) . 'admin/manage-members/ban/' . $user_id, 'groups_ban_member' ) );
    2884         }
    2885 
    2886 /**
    2887  * Output a URL for unbanning a member from a group.
    2888  *
    2889  * @since 1.0.0
    2890  *
    2891  * @param int $user_id ID of the member to unban.
    2892  *                     Default: current member in a member loop.
    2893  */
    2894 function bp_group_member_unban_link( $user_id = 0 ) {
    2895         global $members_template;
    2896 
    2897         if ( !$user_id ) {
    2898                 $user_id = $members_template->member->user_id;
    2899         }
    2900 
    2901         echo bp_get_group_member_unban_link( $user_id );
    2902 }
    2903         /**
    2904          * Generate a URL for unbanning a member from a group.
    2905          *
    2906          * @since 1.0.0
    2907          *
    2908          * @param int         $user_id ID of the member to unban.
    2909          *                             Default: current member in a member loop.
    2910          * @param object|bool $group   Optional. Group object. Default: current group.
    2911          * @return string
    2912          */
    2913         function bp_get_group_member_unban_link( $user_id = 0, $group = false ) {
    2914                 global $members_template, $groups_template;
    2915 
    2916                 if ( !$user_id ) {
    2917                         $user_id = $members_template->member->user_id;
    2918                 }
    2919 
    2920                 if ( empty( $group ) ) {
    2921                         $group =& $groups_template->group;
    2922                 }
    2923 
    2924                 /**
    2925                  * Filters a URL for unbanning a member from a group.
    2926                  *
    2927                  * @since 1.0.0
    2928                  *
    2929                  * @param string $value URL to use for unbanning a member.
    2930                  */
    2931                 return apply_filters( 'bp_get_group_member_unban_link', wp_nonce_url( bp_get_group_permalink( $group ) . 'admin/manage-members/unban/' . $user_id, 'groups_unban_member' ) );
    2932         }
    2933 
    2934 /**
    2935  * Output a URL for removing a member from a group.
    2936  *
    2937  * @since 1.2.6
    2938  *
    2939  * @param int $user_id ID of the member to remove.
    2940  *                     Default: current member in a member loop.
    2941  */
    2942 function bp_group_member_remove_link( $user_id = 0 ) {
    2943         global $members_template;
    2944 
    2945         if ( !$user_id ) {
    2946                 $user_id = $members_template->member->user_id;
    2947         }
    2948 
    2949         echo bp_get_group_member_remove_link( $user_id );
    2950 }
    2951         /**
    2952          * Generate a URL for removing a member from a group.
    2953          *
    2954          * @since 1.2.6
    2955          *
    2956          * @param int         $user_id ID of the member to remove.
    2957          *                             Default: current member in a member loop.
    2958          * @param object|bool $group   Optional. Group object. Default: current group.
    2959          * @return string
    2960          */
    2961         function bp_get_group_member_remove_link( $user_id = 0, $group = false ) {
    2962                 global $groups_template;
    2963 
    2964                 if ( empty( $group ) ) {
    2965                         $group =& $groups_template->group;
    2966                 }
    2967 
    2968                 /**
    2969                  * Filters a URL for removing a member from a group.
    2970                  *
    2971                  * @since 1.2.6
    2972                  * @since 2.5.0 Added the `$group` parameter.
    2973                  *
    2974                  * @param string $value URL to use for removing a member.
    2975                  * @param object $group Group object.
    2976                  */
    2977                 return apply_filters( 'bp_get_group_member_remove_link', wp_nonce_url( bp_get_group_permalink( $group ) . 'admin/manage-members/remove/' . $user_id, 'groups_remove_member' ), $group );
    2978         }
    2979 
    2980 /**
    2981  * HTML admin subnav items for group pages.
    2982  *
    2983  * @since 1.0.0
    2984  *
    2985  * @param object|bool $group Optional. Group object.
    2986  *                           Default: current group in the loop.
    2987  */
    2988 function bp_group_admin_tabs( $group = false ) {
    2989         global $groups_template;
    2990 
    2991         if ( empty( $group ) ) {
    2992                 $group = ( $groups_template->group ) ? $groups_template->group : groups_get_current_group();
    2993         }
    2994 
    2995         $css_id = 'manage-members';
    2996 
    2997         if ( 'private' == $group->status ) {
    2998                 $css_id = 'membership-requests';
    2999         }
    3000 
    3001         add_filter( "bp_get_options_nav_{$css_id}", 'bp_group_admin_tabs_backcompat', 10, 3 );
    3002 
    3003         bp_get_options_nav( $group->slug . '_manage' );
    3004 
    3005         remove_filter( "bp_get_options_nav_{$css_id}", 'bp_group_admin_tabs_backcompat', 10, 3 );
    3006 }
    3007 
    3008 /**
    3009  * BackCompat for plugins/themes directly hooking groups_admin_tabs
    3010  * without using the Groups Extension API.
    3011  *
    3012  * @since 2.2.0
    3013  *
    3014  * @param  string $subnav_output Subnav item output.
    3015  * @param  string $subnav_item   subnav item params.
    3016  * @param  string $selected_item Surrent selected tab.
    3017  * @return string HTML output
    3018  */
    3019 function bp_group_admin_tabs_backcompat( $subnav_output = '', $subnav_item = '', $selected_item = '' ) {
    3020         if ( ! has_action( 'groups_admin_tabs' ) ) {
    3021                 return $subnav_output;
    3022         }
    3023 
    3024         $group = groups_get_current_group();
    3025 
    3026         ob_start();
    3027 
    3028         do_action( 'groups_admin_tabs', $selected_item, $group->slug );
    3029 
    3030         $admin_tabs_backcompat = trim( ob_get_contents() );
    3031         ob_end_clean();
    3032 
    3033         if ( ! empty( $admin_tabs_backcompat ) ) {
    3034                 _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' );
    3035                 $subnav_output .= $admin_tabs_backcompat;
    3036         }
    3037 
    3038         return $subnav_output;
    3039 }
    3040 
    3041 /**
    3042  * Output the group count for the displayed user.
    3043  *
    3044  * @since 1.1.0
    3045  */
    3046 function bp_group_total_for_member() {
    3047         echo bp_get_group_total_for_member();
    3048 }
    3049         /**
    3050          * Get the group count for the displayed user.
    3051          *
    3052          * @since 1.1.0
    3053          *
    3054          * @return string
    3055          */
    3056         function bp_get_group_total_for_member() {
    3057 
    3058                 /**
    3059                  * FIlters the group count for a displayed user.
    3060                  *
    3061                  * @since 1.1.0
    3062                  *
    3063                  * @param int $value Total group count for a displayed user.
    3064                  */
    3065                 return apply_filters( 'bp_get_group_total_for_member', BP_Groups_Member::total_group_count() );
    3066         }
    3067 
    3068 /**
    3069  * Output the 'action' attribute for a group form.
    3070  *
    3071  * @since 1.0.0
    3072  *
    3073  * @param string $page Page slug.
    3074  */
    3075 function bp_group_form_action( $page ) {
    3076         echo bp_get_group_form_action( $page );
    3077 }
    3078         /**
    3079          * Generate the 'action' attribute for a group form.
    3080          *
    3081          * @since 1.0.0
    3082          *
    3083          * @param string      $page  Page slug.
    3084          * @param object|bool $group Optional. Group object.
    3085          *                           Default: current group in the loop.
    3086          * @return string
    3087          */
    3088         function bp_get_group_form_action( $page, $group = false ) {
    3089                 global $groups_template;
    3090 
    3091                 if ( empty( $group ) ) {
    3092                         $group =& $groups_template->group;
    3093                 }
    3094 
    3095                 /**
    3096                  * Filters the 'action' attribute for a group form.
    3097                  *
    3098                  * @since 1.0.0
    3099                  * @since 2.5.0 Added the `$group` parameter.
    3100                  *
    3101                  * @param string $value Action attribute for a group form.
    3102                  * @param object $group Group object.
    3103                  */
    3104                 return apply_filters( 'bp_group_form_action', bp_get_group_permalink( $group ) . $page, $group );
    3105         }
    3106 
    3107 /**
    3108  * Output the 'action' attribute for a group admin form.
    3109  *
    3110  * @since 1.0.0
    3111  *
    3112  * @param string|bool $page Optional. Page slug.
    3113  */
    3114 function bp_group_admin_form_action( $page = false ) {
    3115         echo bp_get_group_admin_form_action( $page );
    3116 }
    3117         /**
    3118          * Generate the 'action' attribute for a group admin form.
    3119          *
    3120          * @since 1.0.0
    3121          *
    3122          * @param string|bool $page  Optional. Page slug.
    3123          * @param object|bool $group Optional. Group object.
    3124          *                           Default: current group in the loop.
    3125          * @return string
    3126          */
    3127         function bp_get_group_admin_form_action( $page = false, $group = false ) {
    3128                 global $groups_template;
    3129 
    3130                 if ( empty( $group ) ) {
    3131                         $group =& $groups_template->group;
    3132                 }
    3133 
    3134                 if ( empty( $page ) ) {
    3135                         $page = bp_action_variable( 0 );
    3136                 }
    3137 
    3138                 /**
    3139                  * Filters the 'action' attribute for a group admin form.
    3140                  *
    3141                  * @since 1.0.0
    3142                  * @since 2.5.0 Added the `$group` parameter.
    3143                  *
    3144                  * @param string $value Action attribute for a group admin form.
    3145                  * @param object $group Group object.
    3146                  */
    3147                 return apply_filters( 'bp_group_admin_form_action', bp_get_group_permalink( $group ) . 'admin/' . $page, $group );
    3148         }
    3149 
    3150 /**
    3151  * Determine whether the logged-in user has requested membership to a group.
    3152  *
    3153  * @since 1.0.0
    3154  *
    3155  * @param object|bool $group Optional. Group object.
    3156  *                           Default: current group in the loop.
    3157  * @return bool
    3158  */
    3159 function bp_group_has_requested_membership( $group = false ) {
    3160         global $groups_template;
    3161 
    3162         if ( empty( $group ) ) {
    3163                 $group =& $groups_template->group;
    3164         }
    3165 
    3166         if ( groups_check_for_membership_request( bp_loggedin_user_id(), $group->id ) ) {
    3167                 return true;
    3168         }
    3169 
    3170         return false;
    3171 }
    3172 
    3173 /**
    3174  * Check if current user is member of a group.
    3175  *
    3176  * @since 1.0.0
    3177  *
    3178  * @global object $groups_template
    3179  *
    3180  * @param object|bool $group Optional. Group to check is_member.
    3181  *                           Default: current group in the loop.
    3182  * @return bool If user is member of group or not.
    3183  */
    3184 function bp_group_is_member( $group = false ) {
    3185         global $groups_template;
    3186 
    3187         // Site admins always have access.
    3188         if ( bp_current_user_can( 'bp_moderate' ) ) {
    3189                 return true;
    3190         }
    3191 
    3192         if ( empty( $group ) ) {
    3193                 $group =& $groups_template->group;
    3194         }
    3195 
    3196         /**
    3197          * Filters whether current user is member of a group.
    3198          *
    3199          * @since 1.2.4
    3200          * @since 2.5.0 Added the `$group` parameter.
    3201          *
    3202          * @param bool   $is_member If user is a member of group or not.
    3203          * @param object $group     Group object.
    3204          */
    3205         return apply_filters( 'bp_group_is_member', ! empty( $group->is_member ), $group );
    3206 }
    3207 
    3208 /**
    3209  * Check whether the current user has an outstanding invite to the current group in the loop.
    3210  *
    3211  * @since 2.1.0
    3212  *
    3213  * @param object|bool $group Optional. Group data object.
    3214  *                           Default: the current group in the groups loop.
    3215  * @return bool True if the user has an outstanding invite, otherwise false.
    3216  */
    3217 function bp_group_is_invited( $group = false ) {
    3218         global $groups_template;
    3219 
    3220         if ( empty( $group ) ) {
    3221                 $group =& $groups_template->group;
    3222         }
    3223 
    3224         /**
    3225          * Filters whether current user has an outstanding invite to current group in loop.
    3226          *
    3227          * @since 2.1.0
    3228          * @since 2.5.0 Added the `$group` parameter.
    3229          *
    3230          * @param bool   $is_invited If user has an outstanding group invite.
    3231          * @param object $group      Group object.
    3232          */
    3233         return apply_filters( 'bp_group_is_invited', ! empty( $group->is_invited ), $group );
    3234 }
    3235 
    3236 /**
    3237  * Check if a user is banned from a group.
    3238  *
    3239  * If this function is invoked inside the groups template loop, then we check
    3240  * $groups_template->group->is_banned instead of using {@link groups_is_user_banned()}
    3241  * and making another SQL query.
    3242  *
    3243  * In BuddyPress 2.1, to standardize this function, we are defaulting the
    3244  * return value to a boolean.  In previous versions, using this function would
    3245  * return either a string of the integer (0 or 1) or null if a result couldn't
    3246  * be found from the database.  If the logged-in user had the 'bp_moderate'
    3247  * capability, the return value would be boolean false.
    3248  *
    3249  * @since 1.5.0
    3250  *
    3251  * @global BP_Groups_Template $groups_template Group template loop object.
    3252  *
    3253  * @param BP_Groups_Group|bool $group   Group to check if user is banned.
    3254  * @param int                  $user_id The user ID to check.
    3255  * @return bool True if user is banned.  False if user isn't banned.
    3256  */
    3257 function bp_group_is_user_banned( $group = false, $user_id = 0 ) {
    3258         global $groups_template;
    3259 
    3260         // Site admins always have access.
    3261         if ( bp_current_user_can( 'bp_moderate' ) ) {
    3262                 return false;
    3263         }
    3264 
    3265         // Check groups loop first
    3266         // @see BP_Groups_Group::get_group_extras().
    3267         if ( ! empty( $groups_template->in_the_loop ) && isset( $groups_template->group->is_banned ) ) {
    3268                 $retval = $groups_template->group->is_banned;
    3269 
    3270         // Not in loop.
    3271         } else {
    3272                 // Default to not banned.
    3273                 $retval = false;
    3274 
    3275                 if ( empty( $group ) ) {
    3276                         $group = $groups_template->group;
    3277                 }
    3278 
    3279                 if ( empty( $user_id ) ) {
    3280                         $user_id = bp_loggedin_user_id();
    3281                 }
    3282 
    3283                 if ( ! empty( $user_id ) && ! empty( $group->id ) ) {
    3284                         $retval = groups_is_user_banned( $user_id, $group->id );
    3285                 }
    3286         }
    3287 
    3288         /**
    3289          * Filters whether current user has been banned from current group in loop.
    3290          *
    3291          * @since 1.5.0
    3292          * @since 2.5.0 Added the `$group` parameter.
    3293          *
    3294          * @param bool   $is_invited If user has been from current group.
    3295          * @param object $group      Group object.
    3296          */
    3297         return (bool) apply_filters( 'bp_group_is_user_banned', $retval, $group );
    3298 }
    3299 
    3300 /**
    3301  * Output the URL for accepting an invitation to the current group in the loop.
    3302  *
    3303  * @since 1.0.0
    3304  */
    3305 function bp_group_accept_invite_link() {
    3306         echo bp_get_group_accept_invite_link();
    3307 }
    3308         /**
    3309          * Generate the URL for accepting an invitation to a group.
    3310          *
    3311          * @since 1.0.0
    3312          *
    3313          * @param object|bool $group Optional. Group object.
    3314          *                           Default: Current group in the loop.
    3315          * @return string
    3316          */
    3317         function bp_get_group_accept_invite_link( $group = false ) {
    3318                 global $groups_template;
    3319 
    3320                 if ( empty( $group ) ) {
    3321                         $group =& $groups_template->group;
    3322                 }
    3323 
    3324                 $bp = buddypress();
    3325 
    3326                 /**
    3327                  * Filters the URL for accepting an invitation to a group.
    3328                  *
    3329                  * @since 1.0.0
    3330                  * @since 2.5.0 Added the `$group` parameter.
    3331                  *
    3332                  * @param string $value URL for accepting an invitation to a group.
    3333                  * @param object $group Group object.
    3334                  */
    3335                 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 );
    3336         }
    3337 
    3338 /**
    3339  * Output the URL for accepting an invitation to the current group in the loop.
    3340  *
    3341  * @since 1.0.0
    3342  */
    3343 function bp_group_reject_invite_link() {
    3344         echo bp_get_group_reject_invite_link();
    3345 }
    3346         /**
    3347          * Generate the URL for rejecting an invitation to a group.
    3348          *
    3349          * @since 1.0.0
    3350          *
    3351          * @param object|bool $group Optional. Group object.
    3352          *                           Default: Current group in the loop.
    3353          * @return string
    3354          */
    3355         function bp_get_group_reject_invite_link( $group = false ) {
    3356                 global $groups_template;
    3357 
    3358                 if ( empty( $group ) ) {
    3359                         $group =& $groups_template->group;
    3360                 }
    3361 
    3362                 $bp = buddypress();
    3363 
    3364                 /**
    3365                  * Filters the URL for rejecting an invitation to a group.
    3366                  *
    3367                  * @since 1.0.0
    3368                  * @since 2.5.0 Added the `$group` parameter.
    3369                  *
    3370                  * @param string $value URL for rejecting an invitation to a group.
    3371                  * @param object $group Group object.
    3372                  */
    3373                 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 );
    3374         }
    3375 
    3376 /**
    3377  * Output the URL for confirming a request to leave a group.
    3378  *
    3379  * @since 1.0.0
    3380  */
    3381 function bp_group_leave_confirm_link() {
    3382         echo bp_get_group_leave_confirm_link();
    3383 }
    3384         /**
    3385          * Generate the URL for confirming a request to leave a group.
    3386          *
    3387          * @since 1.0.0
    3388          *
    3389          * @param object|bool $group Optional. Group object.
    3390          *                           Default: Current group in the loop.
    3391          * @return string
    3392          */
    3393         function bp_get_group_leave_confirm_link( $group = false ) {
    3394                 global $groups_template;
    3395 
    3396                 if ( empty( $group ) ) {
    3397                         $group =& $groups_template->group;
    3398                 }
    3399 
    3400                 /**
    3401                  * Filters the URL for confirming a request to leave a group.
    3402                  *
    3403                  * @since 1.0.0
    3404                  * @since 2.5.0 Added the `$group` parameter.
    3405                  *
    3406                  * @param string $value URL for confirming a request to leave a group.
    3407                  * @param object $group Group object.
    3408                  */
    3409                 return apply_filters( 'bp_group_leave_confirm_link', wp_nonce_url( bp_get_group_permalink( $group ) . 'leave-group/yes', 'groups_leave_group' ), $group );
    3410         }
    3411 
    3412 /**
    3413  * Output the URL for rejecting a request to leave a group.
    3414  *
    3415  * @since 1.0.0
    3416  */
    3417 function bp_group_leave_reject_link() {
    3418         echo bp_get_group_leave_reject_link();
    3419 }
    3420         /**
    3421          * Generate the URL for rejecting a request to leave a group.
    3422          *
    3423          * @since 1.0.0
    3424          *
    3425          * @param object|bool $group Optional. Group object.
    3426          *                           Default: Current group in the loop.
    3427          * @return string
    3428          */
    3429         function bp_get_group_leave_reject_link( $group = false ) {
    3430                 global $groups_template;
    3431 
    3432                 if ( empty( $group ) ) {
    3433                         $group =& $groups_template->group;
    3434                 }
    3435 
    3436                 /**
    3437                  * Filters the URL for rejecting a request to leave a group.
    3438                  *
    3439                  * @since 1.0.0
    3440                  * @since 2.5.0 Added the `$group` parameter.
    3441                  *
    3442                  * @param string $value URL for rejecting a request to leave a group.
    3443                  * @param object $group Group object.
    3444                  */
    3445                 return apply_filters( 'bp_get_group_leave_reject_link', bp_get_group_permalink( $group ), $group );
    3446         }
    3447 
    3448 /**
    3449  * Output the 'action' attribute for a group send invite form.
    3450  *
    3451  * @since 1.0.0
    3452  */
    3453 function bp_group_send_invite_form_action() {
    3454         echo bp_get_group_send_invite_form_action();
    3455 }
    3456         /**
    3457          * Output the 'action' attribute for a group send invite form.
    3458          *
    3459          * @since 1.0.0
    3460          *
    3461          * @param object|bool $group Optional. Group object.
    3462          *                           Default: current group in the loop.
    3463          * @return string
    3464          */
    3465         function bp_get_group_send_invite_form_action( $group = false ) {
    3466                 global $groups_template;
    3467 
    3468                 if ( empty( $group ) ) {
    3469                         $group =& $groups_template->group;
    3470                 }
    3471 
    3472                 /**
    3473                  * Filters the 'action' attribute for a group send invite form.
    3474                  *
    3475                  * @since 1.0.0
    3476                  * @since 2.5.0 Added the `$group` parameter.
    3477                  *
    3478                  * @param string $value Action attribute for a group send invite form.
    3479                  * @param object $group Group object.
    3480                  */
    3481                 return apply_filters( 'bp_group_send_invite_form_action', bp_get_group_permalink( $group ) . 'send-invites/send', $group );
    3482         }
    3483 
    3484 /**
    3485  * Determine whether the current user has friends to invite to a group.
    3486  *
    3487  * @since 1.0.0
    3488  *
    3489  * @param object|bool $group Optional. Group object.
    3490  *                           Default: current group in the loop.
    3491  * @return bool
    3492  */
    3493 function bp_has_friends_to_invite( $group = false ) {
    3494         global $groups_template;
    3495 
    3496         if ( !bp_is_active( 'friends' ) ) {
    3497                 return false;
    3498         }
    3499 
    3500         if ( empty( $group ) ) {
    3501                 $group =& $groups_template->group;
    3502         }
    3503 
    3504         if ( !friends_check_user_has_friends( bp_loggedin_user_id() ) || !friends_count_invitable_friends( bp_loggedin_user_id(), $group->id ) ) {
    3505                 return false;
    3506         }
    3507 
    3508         return true;
    3509 }
    3510 
    3511 /**
    3512  * Output a 'New Topic' button for a group.
    3513  *
    3514  * @since 1.2.7
    3515  *
    3516  * @param BP_Groups_Group|bool $group The BP Groups_Group object if passed,
    3517  *                                    boolean false if not passed.
    3518  */
    3519 function bp_group_new_topic_button( $group = false ) {
    3520         echo bp_get_group_new_topic_button( $group );
    3521 }
    3522 
    3523         /**
    3524          * Returns a 'New Topic' button for a group.
    3525          *
    3526          * @since 1.2.7
    3527          *
    3528          * @param BP_Groups_Group|bool $group The BP Groups_Group object if
    3529          *                                    passed, boolean false if not passed.
    3530          * @return string HTML code for the button.
    3531          */
    3532         function bp_get_group_new_topic_button( $group = false ) {
    3533                 global $groups_template;
    3534 
    3535                 if ( empty( $group ) ) {
    3536                         $group =& $groups_template->group;
    3537                 }
    3538 
    3539                 if ( !is_user_logged_in() || bp_group_is_user_banned() || !bp_is_group_forum() || bp_is_group_forum_topic() ) {
    3540                         return false;
    3541                 }
    3542 
    3543                 $button = array(
    3544                         'id'                => 'new_topic',
    3545                         'component'         => 'groups',
    3546                         'must_be_logged_in' => true,
    3547                         'block_self'        => true,
    3548                         'wrapper_class'     => 'group-button',
    3549                         'link_href'         => '#post-new',
    3550                         'link_class'        => 'group-button show-hide-new',
    3551                         'link_id'           => 'new-topic-button',
    3552                         'link_text'         => __( 'New Topic', 'buddypress' ),
    3553                         'link_title'        => __( 'New Topic', 'buddypress' ),
    3554                 );
    3555 
    3556                 /**
    3557                  * Filters the HTML button for creating a new topic in a group.
    3558                  *
    3559                  * @since 1.5.0
    3560                  * @since 2.5.0 Added the `$group` parameter.
    3561                  *
    3562                  * @param string $button HTML button for a new topic.
    3563                  * @param object $group  Group object.
    3564                  */
    3565                 return bp_get_button( apply_filters( 'bp_get_group_new_topic_button', $button, $group ) );
    3566         }
    3567 
    3568 /**
    3569  * Output button to join a group.
    3570  *
    3571  * @since 1.0.0
    3572  *
    3573  * @param object|bool $group Single group object.
    3574  */
    3575 function bp_group_join_button( $group = false ) {
    3576         echo bp_get_group_join_button( $group );
    3577 }
    3578         /**
    3579          * Return button to join a group.
    3580          *
    3581          * @since 1.0.0
    3582          *
    3583          * @param object|bool $group Single group object.
    3584          * @return mixed
    3585          */
    3586         function bp_get_group_join_button( $group = false ) {
    3587                 global $groups_template;
    3588 
    3589                 // Set group to current loop group if none passed.
    3590                 if ( empty( $group ) ) {
    3591                         $group =& $groups_template->group;
    3592                 }
    3593 
    3594                 // Don't show button if not logged in or previously banned.
    3595                 if ( ! is_user_logged_in() || bp_group_is_user_banned( $group ) ) {
    3596                         return false;
    3597                 }
    3598 
    3599                 // Group creation was not completed or status is unknown.
    3600                 if ( empty( $group->status ) ) {
    3601                         return false;
    3602                 }
    3603 
    3604                 // Already a member.
    3605                 if ( ! empty( $group->is_member ) ) {
    3606 
    3607                         // Stop sole admins from abandoning their group.
    3608                         $group_admins = groups_get_group_admins( $group->id );
    3609                         if ( ( 1 == count( $group_admins ) ) && ( bp_loggedin_user_id() === (int) $group_admins[0]->user_id ) ) {
    3610                                 return false;
    3611                         }
    3612 
    3613                         // Setup button attributes.
    3614                         $button = array(
    3615                                 'id'                => 'leave_group',
    3616                                 'component'         => 'groups',
    3617                                 'must_be_logged_in' => true,
    3618                                 'block_self'        => false,
    3619                                 'wrapper_class'     => 'group-button ' . $group->status,
    3620                                 'wrapper_id'        => 'groupbutton-' . $group->id,
    3621                                 'link_href'         => wp_nonce_url( bp_get_group_permalink( $group ) . 'leave-group', 'groups_leave_group' ),
    3622                                 'link_text'         => __( 'Leave Group', 'buddypress' ),
    3623                                 'link_title'        => __( 'Leave Group', 'buddypress' ),
    3624                                 'link_class'        => 'group-button leave-group',
    3625                         );
    3626 
    3627                 // Not a member.
    3628                 } else {
    3629 
    3630                         // Show different buttons based on group status.
    3631                         switch ( $group->status ) {
    3632                                 case 'hidden' :
    3633                                         return false;
    3634 
    3635                                 case 'public':
    3636                                         $button = array(
    3637                                                 'id'                => 'join_group',
    3638                                                 'component'         => 'groups',
    3639                                                 'must_be_logged_in' => true,
    3640                                                 'block_self'        => false,
    3641                                                 'wrapper_class'     => 'group-button ' . $group->status,
    3642                                                 'wrapper_id'        => 'groupbutton-' . $group->id,
    3643                                                 'link_href'         => wp_nonce_url( bp_get_group_permalink( $group ) . 'join', 'groups_join_group' ),
    3644                                                 'link_text'         => __( 'Join Group', 'buddypress' ),
    3645                                                 'link_title'        => __( 'Join Group', 'buddypress' ),
    3646                                                 'link_class'        => 'group-button join-group',
    3647                                         );
    3648                                         break;
    3649 
    3650                                 case 'private' :
    3651 
    3652                                         // Member has outstanding invitation -
    3653                                         // show an "Accept Invitation" button.
    3654                                         if ( $group->is_invited ) {
    3655                                                 $button = array(
    3656                                                         'id'                => 'accept_invite',
    3657                                                         'component'         => 'groups',
    3658                                                         'must_be_logged_in' => true,
    3659                                                         'block_self'        => false,
    3660                                                         'wrapper_class'     => 'group-button ' . $group->status,
    3661                                                         'wrapper_id'        => 'groupbutton-' . $group->id,
    3662                                                         'link_href'         => add_query_arg( 'redirect_to', bp_get_group_permalink( $group ), bp_get_group_accept_invite_link( $group ) ),
    3663                                                         'link_text'         => __( 'Accept Invitation', 'buddypress' ),
    3664                                                         'link_title'        => __( 'Accept Invitation', 'buddypress' ),
    3665                                                         'link_class'        => 'group-button accept-invite',
    3666                                                 );
    3667 
    3668                                         // Member has requested membership but request is pending -
    3669                                         // show a "Request Sent" button.
    3670                                         } elseif ( $group->is_pending ) {
    3671                                                 $button = array(
    3672                                                         'id'                => 'membership_requested',
    3673                                                         'component'         => 'groups',
    3674                                                         'must_be_logged_in' => true,
    3675                                                         'block_self'        => false,
    3676                                                         'wrapper_class'     => 'group-button pending ' . $group->status,
    3677                                                         'wrapper_id'        => 'groupbutton-' . $group->id,
    3678                                                         'link_href'         => bp_get_group_permalink( $group ),
    3679                                                         'link_text'         => __( 'Request Sent', 'buddypress' ),
    3680                                                         'link_title'        => __( 'Request Sent', 'buddypress' ),
    3681                                                         'link_class'        => 'group-button pending membership-requested',
    3682                                                 );
    3683 
    3684                                         // Member has not requested membership yet -
    3685                                         // show a "Request Membership" button.
    3686                                         } else {
    3687                                                 $button = array(
    3688                                                         'id'                => 'request_membership',
    3689                                                         'component'         => 'groups',
    3690                                                         'must_be_logged_in' => true,
    3691                                                         'block_self'        => false,
    3692                                                         'wrapper_class'     => 'group-button ' . $group->status,
    3693                                                         'wrapper_id'        => 'groupbutton-' . $group->id,
    3694                                                         'link_href'         => wp_nonce_url( bp_get_group_permalink( $group ) . 'request-membership', 'groups_request_membership' ),
    3695                                                         'link_text'         => __( 'Request Membership', 'buddypress' ),
    3696                                                         'link_title'        => __( 'Request Membership', 'buddypress' ),
    3697                                                         'link_class'        => 'group-button request-membership',
    3698                                                 );
    3699                                         }
    3700 
    3701                                         break;
    3702                         }
    3703                 }
    3704 
    3705                 /**
    3706                  * Filters the HTML button for joining a group.
    3707                  *
    3708                  * @since 1.2.6
    3709                  * @since 2.4.0 Added $group parameter to filter args.
    3710                  *
    3711                  * @param string $button HTML button for joining a group.
    3712                  * @param object $group BuddyPress group object
    3713                  */
    3714                 return bp_get_button( apply_filters( 'bp_get_group_join_button', $button, $group ) );
    3715         }
    3716 
    3717 /**
    3718  * Output the Create a Group button.
    3719  *
    3720  * @since 2.0.0
    3721  */
    3722 function bp_group_create_button() {
    3723         echo bp_get_group_create_button();
    3724 }
    3725         /**
    3726          * Get the Create a Group button.
    3727          *
    3728          * @since 2.0.0
    3729          *
    3730          * @return string
    3731          */
    3732         function bp_get_group_create_button() {
    3733                 if ( ! is_user_logged_in() ) {
    3734                         return false;
    3735                 }
    3736 
    3737                 if ( ! bp_user_can_create_groups() ) {
    3738                         return false;
    3739                 }
    3740 
    3741                 $button_args = array(
    3742                         'id'         => 'create_group',
    3743                         'component'  => 'groups',
    3744                         'link_text'  => __( 'Create a Group', 'buddypress' ),
    3745                         'link_title' => __( 'Create a Group', 'buddypress' ),
    3746                         'link_class' => 'group-create no-ajax',
    3747                         'link_href'  => trailingslashit( bp_get_groups_directory_permalink() . 'create' ),
    3748                         'wrapper'    => false,
    3749                         'block_self' => false,
    3750                 );
    3751 
    3752                 /**
    3753                  * Filters the HTML button for creating a group.
    3754                  *
    3755                  * @since 2.0.0
    3756                  *
    3757                  * @param string $button HTML button for creating a group.
    3758                  */
    3759                 return bp_get_button( apply_filters( 'bp_get_group_create_button', $button_args ) );
    3760         }
    3761 
    3762 /**
    3763  * Output the Create a Group nav item.
    3764  *
    3765  * @since 2.2.0
    3766  */
    3767 function bp_group_create_nav_item() {
    3768         echo bp_get_group_create_nav_item();
    3769 }
    3770 
    3771         /**
    3772          * Get the Create a Group nav item.
    3773          *
    3774          * @since 2.2.0
    3775          *
    3776          * @return string
    3777          */
    3778         function bp_get_group_create_nav_item() {
    3779                 // Get the create a group button.
    3780                 $create_group_button = bp_get_group_create_button();
    3781 
    3782                 // Make sure the button is available.
    3783                 if ( empty( $create_group_button ) ) {
    3784                         return;
    3785                 }
    3786 
    3787                 $output = '<li id="group-create-nav">' . $create_group_button . '</li>';
    3788 
    3789                 /**
    3790                  * Filters the Create a Group nav item.
    3791                  *
    3792                  * @since 2.2.0
    3793                  *
    3794                  * @param string $output HTML output for nav item.
    3795                  */
    3796                 return apply_filters( 'bp_get_group_create_nav_item', $output );
    3797         }
    3798 
    3799 /**
    3800  * Checks if a specific theme is still filtering the Groups directory title
    3801  * if so, transform the title button into a Groups directory nav item.
    3802  *
    3803  * @since 2.2.0
    3804  *
    3805  * @uses bp_group_create_nav_item() to output the create a Group nav item.
    3806  *
    3807  * @return string HTML Output
    3808  */
    3809 function bp_group_backcompat_create_nav_item() {
    3810         // Bail if the Groups nav item is already used by bp-legacy.
    3811         if ( has_action( 'bp_groups_directory_group_filter', 'bp_legacy_theme_group_create_nav', 999 ) ) {
    3812                 return;
    3813         }
    3814 
    3815         // Bail if the theme is not filtering the Groups directory title.
    3816         if ( ! has_filter( 'bp_groups_directory_header' ) ) {
    3817                 return;
    3818         }
    3819 
    3820         bp_group_create_nav_item();
    3821 }
    3822 add_action( 'bp_groups_directory_group_filter', 'bp_group_backcompat_create_nav_item', 1000 );
    3823 
    3824 /**
    3825  * Prints a message if the group is not visible to the current user (it is a
    3826  * hidden or private group, and the user does not have access).
    3827  *
    3828  * @since 1.0.0
    3829  *
    3830  * @global BP_Groups_Template $groups_template Groups template object.
    3831  *
    3832  * @param object|null $group Group to get status message for. Optional; defaults to current group.
    3833  */
    3834 function bp_group_status_message( $group = null ) {
    3835         global $groups_template;
    3836 
    3837         // Group not passed so look for loop.
    3838         if ( empty( $group ) ) {
    3839                 $group =& $groups_template->group;
    3840         }
    3841 
    3842         // Group status is not set (maybe outside of group loop?).
    3843         if ( empty( $group->status ) ) {
    3844                 $message = __( 'This group is not currently accessible.', 'buddypress' );
    3845 
    3846         // Group has a status.
    3847         } else {
    3848                 switch( $group->status ) {
    3849 
    3850                         // Private group.
    3851                         case 'private' :
    3852                                 if ( ! bp_group_has_requested_membership( $group ) ) {
    3853                                         if ( is_user_logged_in() ) {
    3854                                                 if ( bp_group_is_invited( $group ) ) {
    3855                                                         $message = __( 'You must accept your pending invitation before you can access this private group.', 'buddypress' );
    3856                                                 } else {
    3857                                                         $message = __( 'This is a private group and you must request group membership in order to join.', 'buddypress' );
    3858                                                 }
    3859                                         } else {
    3860                                                 $message = __( 'This is a private group. To join you must be a registered site member and request group membership.', 'buddypress' );
    3861                                         }
    3862                                 } else {
    3863                                         $message = __( 'This is a private group. Your membership request is awaiting approval from the group administrator.', 'buddypress' );
    3864                                 }
    3865 
    3866                                 break;
    3867 
    3868                         // Hidden group.
    3869                         case 'hidden' :
    3870                         default :
    3871                                 $message = __( 'This is a hidden group and only invited members can join.', 'buddypress' );
    3872                                 break;
    3873                 }
    3874         }
    3875 
    3876         /**
    3877          * Filters a message if the group is not visible to the current user.
    3878          *
    3879          * This will be true if it is a hidden or private group, and the user does not have access.
    3880          *
    3881          * @since 1.6.0
    3882          *
    3883          * @param string $message Message to display to the current user.
    3884          * @param object $group   Group to get status message for.
    3885          */
    3886         echo apply_filters( 'bp_group_status_message', $message, $group );
    3887 }
    3888 
    3889 /**
    3890  * Output hidden form fields for group.
    3891  *
    3892  * This function is no longer used, but may still be used by older themes.
    3893  *
    3894  * @since 1.0.0
    3895  */
    3896 function bp_group_hidden_fields() {
    3897         $query_arg = bp_core_get_component_search_query_arg( 'groups' );
    3898 
    3899         if ( isset( $_REQUEST[ $query_arg ] ) ) {
    3900                 echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST[ $query_arg ] ) . '" name="search_terms" />';
    3901         }
    3902 
    3903         if ( isset( $_REQUEST['letter'] ) ) {
    3904                 echo '<input type="hidden" id="selected_letter" value="' . esc_attr( $_REQUEST['letter'] ) . '" name="selected_letter" />';
    3905         }
    3906 
    3907         if ( isset( $_REQUEST['groups_search'] ) ) {
    3908                 echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['groups_search'] ) . '" name="search_terms" />';
    3909         }
    3910 }
    3911 
    3912 /**
    3913  * Output the total number of groups.
    3914  *
    3915  * @since 1.0.0
    3916  */
    3917 function bp_total_group_count() {
    3918         echo bp_get_total_group_count();
    3919 }
    3920         /**
    3921          * Return the total number of groups.
    3922          *
    3923          * @since 1.0.0
    3924          *
    3925          * @return type
    3926          */
    3927         function bp_get_total_group_count() {
    3928 
    3929                 /**
    3930                  * Filters the total number of groups.
    3931                  *
    3932                  * @since 1.0.0
    3933                  *
    3934                  * @param int $value Total number of groups found.
    3935                  */
    3936                 return apply_filters( 'bp_get_total_group_count', groups_get_total_group_count() );
    3937         }
    3938 
    3939 /**
    3940  * Output the total number of groups a user belongs to.
    3941  *
    3942  * @since 1.0.0
    3943  *
    3944  * @param int $user_id User ID to get group membership count.
    3945  */
    3946 function bp_total_group_count_for_user( $user_id = 0 ) {
    3947         echo bp_get_total_group_count_for_user( $user_id );
    3948 }
    3949         /**
    3950          * Return the total number of groups a user belongs to.
    3951          *
    3952          * Filtered by `bp_core_number_format()` by default
    3953          *
    3954          * @since 1.0.0
    3955          *
    3956          * @param int $user_id User ID to get group membership count.
    3957          * @return string
    3958          */
    3959         function bp_get_total_group_count_for_user( $user_id = 0 ) {
    3960                 $count = groups_total_groups_for_user( $user_id );
    3961 
    3962                 /**
    3963                  * Filters the total number of groups a user belongs to.
    3964                  *
    3965                  * @since 1.2.0
    3966                  *
    3967                  * @param int $count   Total number of groups for the user.
    3968                  * @param int $user_id ID of the user being checked.
    3969                  */
    3970                 return apply_filters( 'bp_get_total_group_count_for_user', $count, $user_id );
    3971         }
    3972 
    3973 /* Group Members *************************************************************/
    3974 
    3975 /**
    3976  * Class BP_Groups_Group_Members_Template
     13 * Group Members Loop template class.
    397714 *
    397815 * @since 1.0.0
     
    4240277        }
    4241278}
    4242 
    4243 /**
    4244  * Initialize a group member query loop.
    4245  *
    4246  * @since 1.0.0
    4247  *
    4248  * @param array|string $args {
    4249  *     An array of optional arguments.
    4250  *     @type int      $group_id           ID of the group whose members are being queried.
    4251  *                                        Default: current group ID.
    4252  *     @type int      $page               Page of results to be queried. Default: 1.
    4253  *     @type int      $per_page           Number of items to return per page of results.
    4254  *                                        Default: 20.
    4255  *     @type int      $max                Optional. Max number of items to return.
    4256  *     @type array    $exclude            Optional. Array of user IDs to exclude.
    4257  *     @type bool|int $exclude_admin_mods True (or 1) to exclude admins and mods from results.
    4258  *                                        Default: 1.
    4259  *     @type bool|int $exclude_banned     True (or 1) to exclude banned users from results.
    4260  *                                        Default: 1.
    4261  *     @type array    $group_role         Optional. Array of group roles to include.
    4262  *     @type string   $type               Optional. Sort order of results. 'last_joined',
    4263  *                                        'first_joined', or any of the $type params available in
    4264  *                                        {@link BP_User_Query}. Default: 'last_joined'.
    4265  *     @type string   $search_terms       Optional. Search terms to match. Pass an
    4266  *                                        empty string to force-disable search, even in
    4267  *                                        the presence of $_REQUEST['s']. Default: null.
    4268  * }
    4269  *
    4270  * @return bool
    4271  */
    4272 function bp_group_has_members( $args = '' ) {
    4273         global $members_template;
    4274 
    4275         $exclude_admins_mods = 1;
    4276 
    4277         if ( bp_is_group_members() ) {
    4278                 $exclude_admins_mods = 0;
    4279         }
    4280 
    4281         $r = wp_parse_args( $args, array(
    4282                 'group_id'            => bp_get_current_group_id(),
    4283                 'page'                => 1,
    4284                 'per_page'            => 20,
    4285                 'max'                 => false,
    4286                 'exclude'             => false,
    4287                 'exclude_admins_mods' => $exclude_admins_mods,
    4288                 'exclude_banned'      => 1,
    4289                 'group_role'          => false,
    4290                 'search_terms'        => null,
    4291                 'type'                => 'last_joined',
    4292         ) );
    4293 
    4294         if ( is_null( $r['search_terms'] ) && ! empty( $_REQUEST['s'] ) ) {
    4295                 $r['search_terms'] = $_REQUEST['s'];
    4296         }
    4297 
    4298         $members_template = new BP_Groups_Group_Members_Template( $r );
    4299 
    4300         /**
    4301          * Filters whether or not a group member query has members to display.
    4302          *
    4303          * @since 1.1.0
    4304          *
    4305          * @param bool                             $value            Whether there are members to display.
    4306          * @param BP_Groups_Group_Members_Template $members_template Object holding the member query results.
    4307          */
    4308         return apply_filters( 'bp_group_has_members', $members_template->has_members(), $members_template );
    4309 }
    4310 
    4311 /**
    4312  * @since 1.0.0
    4313  *
    4314  * @return mixed
    4315  */
    4316 function bp_group_members() {
    4317         global $members_template;
    4318 
    4319         return $members_template->members();
    4320 }
    4321 
    4322 /**
    4323  * @since 1.0.0
    4324  *
    4325  * @return mixed
    4326  */
    4327 function bp_group_the_member() {
    4328         global $members_template;
    4329 
    4330         return $members_template->the_member();
    4331 }
    4332 
    4333 /**
    4334  * Output the group member avatar while in the groups members loop.
    4335  *
    4336  * @since 1.0.0
    4337  *
    4338  * @param array|string $args {@see bp_core_fetch_avatar()}.
    4339  */
    4340 function bp_group_member_avatar( $args = '' ) {
    4341         echo bp_get_group_member_avatar( $args );
    4342 }
    4343         /**
    4344          * Return the group member avatar while in the groups members loop.
    4345          *
    4346          * @since 1.0.0
    4347          *
    4348          * @param array|string $args {@see bp_core_fetch_avatar()}.
    4349          * @return string
    4350          */
    4351         function bp_get_group_member_avatar( $args = '' ) {
    4352                 global $members_template;
    4353 
    4354                 $r = bp_parse_args( $args, array(
    4355                         'item_id' => $members_template->member->user_id,
    4356                         'type'    => 'full',
    4357                         'email'   => $members_template->member->user_email,
    4358                         'alt'     => sprintf( __( 'Profile picture of %s', 'buddypress' ), $members_template->member->display_name )
    4359                 ) );
    4360 
    4361                 /**
    4362                  * Filters the group member avatar while in the groups members loop.
    4363                  *
    4364                  * @since 1.0.0
    4365                  *
    4366                  * @param string $value HTML markup for group member avatar.
    4367                  * @param array  $r     Parsed args used for the avatar query.
    4368                  */
    4369                 return apply_filters( 'bp_get_group_member_avatar', bp_core_fetch_avatar( $r ), $r );
    4370         }
    4371 
    4372 /**
    4373  * Output the group member avatar while in the groups members loop.
    4374  *
    4375  * @since 1.0.0
    4376  *
    4377  * @param array|string $args {@see bp_core_fetch_avatar()}.
    4378  */
    4379 function bp_group_member_avatar_thumb( $args = '' ) {
    4380         echo bp_get_group_member_avatar_thumb( $args );
    4381 }
    4382         /**
    4383          * Return the group member avatar while in the groups members loop.
    4384          *
    4385          * @since 1.0.0
    4386          *
    4387          * @param array|string $args {@see bp_core_fetch_avatar()}.
    4388          * @return string
    4389          */
    4390         function bp_get_group_member_avatar_thumb( $args = '' ) {
    4391                 global $members_template;
    4392 
    4393                 $r = bp_parse_args( $args, array(
    4394                         'item_id' => $members_template->member->user_id,
    4395                         'type'    => 'thumb',
    4396                         'email'   => $members_template->member->user_email,
    4397                         'alt'     => sprintf( __( 'Profile picture of %s', 'buddypress' ), $members_template->member->display_name )
    4398                 ) );
    4399 
    4400                 /**
    4401                  * Filters the group member avatar thumb while in the groups members loop.
    4402                  *
    4403                  * @since 1.1.0
    4404                  *
    4405                  * @param string $value HTML markup for group member avatar thumb.
    4406                  * @param array  $r     Parsed args used for the avatar query.
    4407                  */
    4408                 return apply_filters( 'bp_get_group_member_avatar_thumb', bp_core_fetch_avatar( $r ), $r );
    4409         }
    4410 
    4411 /**
    4412  * Output the group member avatar while in the groups members loop.
    4413  *
    4414  * @since 1.0.0
    4415  *
    4416  * @param int $width  Width of avatar to fetch.
    4417  * @param int $height Height of avatar to fetch.
    4418  */
    4419 function bp_group_member_avatar_mini( $width = 30, $height = 30 ) {
    4420         echo bp_get_group_member_avatar_mini( $width, $height );
    4421 }
    4422         /**
    4423          * Output the group member avatar while in the groups members loop.
    4424          *
    4425          * @since 1.0.0
    4426          *
    4427          * @param int $width  Width of avatar to fetch.
    4428          * @param int $height Height of avatar to fetch.
    4429          * @return string
    4430          */
    4431         function bp_get_group_member_avatar_mini( $width = 30, $height = 30 ) {
    4432                 global $members_template;
    4433 
    4434                 $r = bp_parse_args( array(), array(
    4435                         'item_id' => $members_template->member->user_id,
    4436                         'type'    => 'thumb',
    4437                         'email'   => $members_template->member->user_email,
    4438                         'alt'     => sprintf( __( 'Profile picture of %s', 'buddypress' ), $members_template->member->display_name ),
    4439                         'width'   => absint( $width ),
    4440                         'height'  => absint( $height )
    4441                 ) );
    4442 
    4443                 /**
    4444                  * Filters the group member avatar mini while in the groups members loop.
    4445                  *
    4446                  * @since 1.0.0
    4447                  *
    4448                  * @param string $value HTML markup for group member avatar mini.
    4449                  * @param array  $r     Parsed args used for the avatar query.
    4450                  */
    4451                 return apply_filters( 'bp_get_group_member_avatar_mini', bp_core_fetch_avatar( $r ), $r );
    4452         }
    4453 
    4454 /**
    4455  * @since 1.0.0
    4456  */
    4457 function bp_group_member_name() {
    4458         echo bp_get_group_member_name();
    4459 }
    4460 
    4461         /**
    4462          * @since 1.0.0
    4463          *
    4464          * @return mixed|void
    4465          */
    4466         function bp_get_group_member_name() {
    4467                 global $members_template;
    4468 
    4469                 /**
    4470                  * Filters the group member display name of the current user in the loop.
    4471                  *
    4472                  * @since 1.0.0
    4473                  *
    4474                  * @param string $display_name Display name of the current user.
    4475                  */
    4476                 return apply_filters( 'bp_get_group_member_name', $members_template->member->display_name );
    4477         }
    4478 
    4479 /**
    4480  * @since 1.0.0
    4481  */
    4482 function bp_group_member_url() {
    4483         echo bp_get_group_member_url();
    4484 }
    4485 
    4486         /**
    4487          * @since 1.0.0
    4488          *
    4489          * @return mixed|void
    4490          */
    4491         function bp_get_group_member_url() {
    4492                 global $members_template;
    4493 
    4494                 /**
    4495                  * Filters the group member url for the current user in the loop.
    4496                  *
    4497                  * @since 1.0.0
    4498                  *
    4499                  * @param string $value URL for the current user.
    4500                  */
    4501                 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 ) );
    4502         }
    4503 
    4504 /**
    4505  * @since 1.0.0
    4506  */
    4507 function bp_group_member_link() {
    4508         echo bp_get_group_member_link();
    4509 }
    4510 
    4511         /**
    4512          * @since 1.0.0
    4513          *
    4514          * @return mixed|void
    4515          */
    4516         function bp_get_group_member_link() {
    4517                 global $members_template;
    4518 
    4519                 /**
    4520                  * Filters the group member HTML link for the current user in the loop.
    4521                  *
    4522                  * @since 1.0.0
    4523                  *
    4524                  * @param string $value HTML link for the current user.
    4525                  */
    4526                 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>' );
    4527         }
    4528 
    4529 /**
    4530  * @since 1.2.0
    4531  */
    4532 function bp_group_member_domain() {
    4533         echo bp_get_group_member_domain();
    4534 }
    4535 
    4536         /**
    4537          * @since 1.2.0
    4538          *
    4539          * @return mixed|void
    4540          */
    4541         function bp_get_group_member_domain() {
    4542                 global $members_template;
    4543 
    4544                 /**
    4545                  * Filters the group member domain for the current user in the loop.
    4546                  *
    4547                  * @since 1.2.0
    4548                  *
    4549                  * @param string $value Domain for the current user.
    4550                  */
    4551                 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 ) );
    4552         }
    4553 
    4554 /**
    4555  * @since 1.2.0
    4556  */
    4557 function bp_group_member_is_friend() {
    4558         echo bp_get_group_member_is_friend();
    4559 }
    4560 
    4561         /**
    4562          * @since 1.2.0
    4563          *
    4564          * @return mixed|void
    4565          */
    4566         function bp_get_group_member_is_friend() {
    4567                 global $members_template;
    4568 
    4569                 if ( !isset( $members_template->member->is_friend ) ) {
    4570                         $friend_status = 'not_friends';
    4571                 } else {
    4572                         $friend_status = ( 0 == $members_template->member->is_friend )
    4573                                 ? 'pending'
    4574                                 : 'is_friend';
    4575                 }
    4576 
    4577                 /**
    4578                  * Filters the friendship status between current user and displayed user in group member loop.
    4579                  *
    4580                  * @since 1.2.0
    4581                  *
    4582                  * @param string $friend_status Current status of the friendship.
    4583                  */
    4584                 return apply_filters( 'bp_get_group_member_is_friend', $friend_status );
    4585         }
    4586 
    4587 /**
    4588  * @since 1.0.0
    4589  */
    4590 function bp_group_member_is_banned() {
    4591         echo bp_get_group_member_is_banned();
    4592 }
    4593 
    4594         /**
    4595          * @since 1.0.0
    4596          *
    4597          * @return mixed|void
    4598          */
    4599         function bp_get_group_member_is_banned() {
    4600                 global $members_template;
    4601 
    4602                 /**
    4603                  * Filters whether the member is banned from the current group.
    4604                  *
    4605                  * @since 1.0.0
    4606                  *
    4607                  * @param bool $is_banned Whether or not the member is banned.
    4608                  */
    4609                 return apply_filters( 'bp_get_group_member_is_banned', $members_template->member->is_banned );
    4610         }
    4611 
    4612 /**
    4613  * @since 1.2.6
    4614  */
    4615 function bp_group_member_css_class() {
    4616         global $members_template;
    4617 
    4618         if ( $members_template->member->is_banned ) {
    4619 
    4620                 /**
    4621                  * Filters the class to add to the HTML if member is banned.
    4622                  *
    4623                  * @since 1.2.6
    4624                  *
    4625                  * @param string $value HTML class to add.
    4626                  */
    4627                 echo apply_filters( 'bp_group_member_css_class', 'banned-user' );
    4628         }
    4629 }
    4630 
    4631 /**
    4632  * @since 1.0.0
    4633  */
    4634 function bp_group_member_joined_since() {
    4635         echo bp_get_group_member_joined_since();
    4636 }
    4637 
    4638         /**
    4639          * @since 1.0.0
    4640          *
    4641          * @return mixed|void
    4642          */
    4643         function bp_get_group_member_joined_since() {
    4644                 global $members_template;
    4645 
    4646                 /**
    4647                  * Filters the joined since time for the current member in the loop.
    4648                  *
    4649                  * @since 1.0.0
    4650                  *
    4651                  * @param string $value Joined since time.
    4652                  */
    4653                 return apply_filters( 'bp_get_group_member_joined_since', bp_core_get_last_activity( $members_template->member->date_modified, __( 'joined %s', 'buddypress') ) );
    4654         }
    4655 
    4656 /**
    4657  * @since 1.0.0
    4658  */
    4659 function bp_group_member_id() {
    4660         echo bp_get_group_member_id();
    4661 }
    4662 
    4663         /**
    4664          * @since 1.0.0
    4665          *
    4666          * @return mixed|void
    4667          */
    4668         function bp_get_group_member_id() {
    4669                 global $members_template;
    4670 
    4671                 /**
    4672                  * Filters the member's user ID for group members loop.
    4673                  *
    4674                  * @since 1.0.0
    4675                  *
    4676                  * @param int $user_id User ID of the member.
    4677                  */
    4678                 return apply_filters( 'bp_get_group_member_id', $members_template->member->user_id );
    4679         }
    4680 
    4681 /**
    4682  * @since 1.0.0
    4683  *
    4684  * @return bool
    4685  */
    4686 function bp_group_member_needs_pagination() {
    4687         global $members_template;
    4688 
    4689         if ( $members_template->total_member_count > $members_template->pag_num ) {
    4690                 return true;
    4691         }
    4692 
    4693         return false;
    4694 }
    4695 
    4696 /**
    4697  * @since 1.0.0
    4698  */
    4699 function bp_group_pag_id() {
    4700         echo bp_get_group_pag_id();
    4701 }
    4702 
    4703         /**
    4704          * @since 1.0.0
    4705          *
    4706          * @return mixed|void
    4707          */
    4708         function bp_get_group_pag_id() {
    4709 
    4710                 /**
    4711                  * Filters the string to be used as the group pag id.
    4712                  *
    4713                  * @since 1.0.0
    4714                  *
    4715                  * @param string $value Value to use for the pag id.
    4716                  */
    4717                 return apply_filters( 'bp_get_group_pag_id', 'pag' );
    4718         }
    4719 
    4720 /**
    4721  * @since 1.0.0
    4722  */
    4723 function bp_group_member_pagination() {
    4724         echo bp_get_group_member_pagination();
    4725         wp_nonce_field( 'bp_groups_member_list', '_member_pag_nonce' );
    4726 }
    4727 
    4728         /**
    4729          * @since 1.0.0
    4730          *
    4731          * @return mixed|void
    4732          */
    4733         function bp_get_group_member_pagination() {
    4734                 global $members_template;
    4735 
    4736                 /**
    4737                  * Filters the HTML markup to be used for group member listing pagination.
    4738                  *
    4739                  * @since 1.0.0
    4740                  *
    4741                  * @param string $pag_links HTML markup for the pagination.
    4742                  */
    4743                 return apply_filters( 'bp_get_group_member_pagination', $members_template->pag_links );
    4744         }
    4745 
    4746 /**
    4747  * @since 1.0.0
    4748  */
    4749 function bp_group_member_pagination_count() {
    4750         echo bp_get_group_member_pagination_count();
    4751 }
    4752 
    4753         /**
    4754          * @since 1.0.0
    4755          *
    4756          * @return mixed|void
    4757          */
    4758         function bp_get_group_member_pagination_count() {
    4759                 global $members_template;
    4760 
    4761                 $start_num = intval( ( $members_template->pag_page - 1 ) * $members_template->pag_num ) + 1;
    4762                 $from_num  = bp_core_number_format( $start_num );
    4763                 $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 ) );
    4764                 $total     = bp_core_number_format( $members_template->total_member_count );
    4765 
    4766                 if ( 1 == $members_template->total_member_count ) {
    4767                         $message = __( 'Viewing 1 member', 'buddypress' );
    4768                 } else {
    4769                         $message = sprintf( _n( 'Viewing %1$s - %2$s of %3$s member', 'Viewing %1$s - %2$s of %3$s members', $members_template->total_member_count, 'buddypress' ), $from_num, $to_num, $total );
    4770                 }
    4771 
    4772                 /**
    4773                  * Filters the "Viewing x-y of z members" pagination message.
    4774                  *
    4775                  * @since 1.0.0
    4776                  *
    4777                  * @param string $value    "Viewing x-y of z members" text.
    4778                  * @param string $from_num Total amount for the low value in the range.
    4779                  * @param string $to_num   Total amount for the high value in the range.
    4780                  * @param string $total    Total amount of members found.
    4781                  */
    4782                 return apply_filters( 'bp_get_group_member_pagination_count', $message, $from_num, $to_num, $total );
    4783         }
    4784 
    4785 /**
    4786  * @since 1.0.0
    4787  */
    4788 function bp_group_member_admin_pagination() {
    4789         echo bp_get_group_member_admin_pagination();
    4790         wp_nonce_field( 'bp_groups_member_admin_list', '_member_admin_pag_nonce' );
    4791 }
    4792 
    4793         /**
    4794          * @since 1.0.0
    4795          *
    4796          * @return mixed
    4797          */
    4798         function bp_get_group_member_admin_pagination() {
    4799                 global $members_template;
    4800 
    4801                 return $members_template->pag_links;
    4802         }
    4803 
    4804 /**
    4805  * Output the contents of the current group's home page.
    4806  *
    4807  * You should only use this when on a single group page.
    4808  *
    4809  * @since 2.4.0
    4810  */
    4811 function bp_groups_front_template_part() {
    4812         $located = bp_groups_get_front_template();
    4813 
    4814         if ( false !== $located ) {
    4815                 $slug = str_replace( '.php', '', $located );
    4816 
    4817                 /**
    4818                  * Let plugins adding an action to bp_get_template_part get it from here
    4819                  *
    4820                  * @param string $slug Template part slug requested.
    4821                  * @param string $name Template part name requested.
    4822                  */
    4823                 do_action( 'get_template_part_' . $slug, $slug, false );
    4824 
    4825                 load_template( $located, true );
    4826 
    4827         } else if ( bp_is_active( 'activity' ) ) {
    4828                 bp_get_template_part( 'groups/single/activity' );
    4829 
    4830         } else if ( bp_is_active( 'members'  ) ) {
    4831                 bp_groups_members_template_part();
    4832         }
    4833 
    4834         return $located;
    4835 }
    4836 
    4837 /**
    4838  * Locate a custom group front template if it exists.
    4839  *
    4840  * @since 2.4.0
    4841  *
    4842  * @param  BP_Groups_Group|null $group Optional. Falls back to current group if not passed.
    4843  * @return string|bool                 Path to front template on success; boolean false on failure.
    4844  */
    4845 function bp_groups_get_front_template( $group = null ) {
    4846         if ( ! is_a( $group, 'BP_Groups_Group' ) ) {
    4847                 $group = groups_get_current_group();
    4848         }
    4849 
    4850         if ( ! isset( $group->id ) ) {
    4851                 return false;
    4852         }
    4853 
    4854         if ( isset( $group->front_template ) ) {
    4855                 return $group->front_template;
    4856         }
    4857 
    4858         /**
    4859          * Filters the hierarchy of group front templates corresponding to a specific group.
    4860          *
    4861          * @since 2.4.0
    4862          * @since 2.5.0 Added the `$group` parameter.
    4863          *
    4864          * @param array  $template_names Array of template paths.
    4865          * @param object $group          Group object.
    4866          */
    4867         $template_names = apply_filters( 'bp_groups_get_front_template', array(
    4868                 'groups/single/front-id-'     . sanitize_file_name( $group->id )     . '.php',
    4869                 'groups/single/front-slug-'   . sanitize_file_name( $group->slug )   . '.php',
    4870                 'groups/single/front-status-' . sanitize_file_name( $group->status ) . '.php',
    4871                 'groups/single/front.php'
    4872         ) );
    4873 
    4874         return bp_locate_template( $template_names, false, true );
    4875 }
    4876 
    4877 /**
    4878  * Output the Group members template
    4879  *
    4880  * @since 2.0.0
    4881  */
    4882 function bp_groups_members_template_part() {
    4883         ?>
    4884         <div class="item-list-tabs" id="subnav" role="navigation">
    4885                 <ul>
    4886                         <li class="groups-members-search" role="search">
    4887                                 <?php bp_directory_members_search_form(); ?>
    4888                         </li>
    4889 
    4890                         <?php bp_groups_members_filter(); ?>
    4891                         <?php
    4892 
    4893                         /**
    4894                          * Fires at the end of the group members search unordered list.
    4895                          *
    4896                          * Part of bp_groups_members_template_part().
    4897                          *
    4898                          * @since 1.5.0
    4899                          */
    4900                         do_action( 'bp_members_directory_member_sub_types' ); ?>
    4901 
    4902                 </ul>
    4903         </div>
    4904 
    4905         <div id="members-group-list" class="group_members dir-list">
    4906 
    4907                 <?php bp_get_template_part( 'groups/single/members' ); ?>
    4908 
    4909         </div>
    4910         <?php
    4911 }
    4912 
    4913 /**
    4914  * Output the Group members filters
    4915  *
    4916  * @since 2.0.0
    4917  */
    4918 function bp_groups_members_filter() {
    4919         ?>
    4920         <li id="group_members-order-select" class="last filter">
    4921                 <label for="group_members-order-by"><?php _e( 'Order By:', 'buddypress' ); ?></label>
    4922                 <select id="group_members-order-by">
    4923                         <option value="last_joined"><?php _e( 'Newest', 'buddypress' ); ?></option>
    4924                         <option value="first_joined"><?php _e( 'Oldest', 'buddypress' ); ?></option>
    4925 
    4926                         <?php if ( bp_is_active( 'activity' ) ) : ?>
    4927                                 <option value="group_activity"><?php _e( 'Group Activity', 'buddypress' ); ?></option>
    4928                         <?php endif; ?>
    4929 
    4930                         <option value="alphabetical"><?php _e( 'Alphabetical', 'buddypress' ); ?></option>
    4931 
    4932                         <?php
    4933 
    4934                         /**
    4935                          * Fires at the end of the Group members filters select input.
    4936                          *
    4937                          * Useful for plugins to add more filter options.
    4938                          *
    4939                          * @since 2.0.0
    4940                          */
    4941                         do_action( 'bp_groups_members_order_options' ); ?>
    4942 
    4943                 </select>
    4944         </li>
    4945         <?php
    4946 }
    4947 
    4948 /*
    4949  * Group Creation Process Template Tags
    4950  */
    4951 
    4952 /**
    4953  * Determine if the current logged in user can create groups.
    4954  *
    4955  * @since 1.5.0
    4956  *
    4957  * @uses apply_filters() To call 'bp_user_can_create_groups'.
    4958  * @uses bp_get_option() To retrieve value of 'bp_restrict_group_creation'. Defaults to 0.
    4959  * @uses bp_current_user_can() To determine if current user if super admin.
    4960  * @return bool True if user can create groups. False otherwise.
    4961  */
    4962 function bp_user_can_create_groups() {
    4963 
    4964         // Super admin can always create groups.
    4965         if ( bp_current_user_can( 'bp_moderate' ) ) {
    4966                 return true;
    4967         }
    4968 
    4969         // Get group creation option, default to 0 (allowed).
    4970         $restricted = (int) bp_get_option( 'bp_restrict_group_creation', 0 );
    4971 
    4972         // Allow by default.
    4973         $can_create = true;
    4974 
    4975         // Are regular users restricted?
    4976         if ( $restricted ) {
    4977                 $can_create = false;
    4978         }
    4979 
    4980         /**
    4981          * Filters if the current logged in user can create groups.
    4982          *
    4983          * @since 1.5.0
    4984          *
    4985          * @param bool $can_create Whether the person can create groups.
    4986          * @param int  $restricted Whether or not group creation is restricted.
    4987          */
    4988         return apply_filters( 'bp_user_can_create_groups', $can_create, $restricted );
    4989 }
    4990 
    4991 /**
    4992  * @since 1.0.0
    4993  *
    4994  * @return bool
    4995  */
    4996 function bp_group_creation_tabs() {
    4997         $bp = buddypress();
    4998 
    4999         if ( !is_array( $bp->groups->group_creation_steps ) ) {
    5000                 return false;
    5001         }
    5002 
    5003         if ( !bp_get_groups_current_create_step() ) {
    5004                 $keys = array_keys( $bp->groups->group_creation_steps );
    5005                 $bp->groups->current_create_step = array_shift( $keys );
    5006         }
    5007 
    5008         $counter = 1;
    5009 
    5010         foreach ( (array) $bp->groups->group_creation_steps as $slug => $step ) {
    5011                 $is_enabled = bp_are_previous_group_creation_steps_complete( $slug ); ?>
    5012 
    5013                 <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
    5014                 $counter++;
    5015         }
    5016 
    5017         unset( $is_enabled );
    5018 
    5019         /**
    5020          * Fires at the end of the creation of the group tabs.
    5021          *
    5022          * @since 1.0.0
    5023          */
    5024         do_action( 'groups_creation_tabs' );
    5025 }
    5026 
    5027 /**
    5028  * @since 1.0.0
    5029  */
    5030 function bp_group_creation_stage_title() {
    5031         $bp = buddypress();
    5032 
    5033         /**
    5034          * Filters the group creation stage title.
    5035          *
    5036          * @since 1.1.0
    5037          *
    5038          * @param string $value HTML markup for the group creation stage title.
    5039          */
    5040         echo apply_filters( 'bp_group_creation_stage_title', '<span>&mdash; ' . $bp->groups->group_creation_steps[bp_get_groups_current_create_step()]['name'] . '</span>' );
    5041 }
    5042 
    5043 /**
    5044  * @since 1.1.0
    5045  */
    5046 function bp_group_creation_form_action() {
    5047         echo bp_get_group_creation_form_action();
    5048 }
    5049 
    5050 /**
    5051  * @since 1.1.0
    5052  *
    5053  * @return mixed|void
    5054  */
    5055         function bp_get_group_creation_form_action() {
    5056                 $bp = buddypress();
    5057 
    5058                 if ( !bp_action_variable( 1 ) ) {
    5059                         $keys = array_keys( $bp->groups->group_creation_steps );
    5060                         $bp->action_variables[1] = array_shift( $keys );
    5061                 }
    5062 
    5063                 /**
    5064                  * Filters the group creation form action.
    5065                  *
    5066                  * @since 1.1.0
    5067                  *
    5068                  * @param string $value Action to be used with group creation form.
    5069                  */
    5070                 return apply_filters( 'bp_get_group_creation_form_action', trailingslashit( bp_get_groups_directory_permalink() . 'create/step/' . bp_action_variable( 1 ) ) );
    5071         }
    5072 
    5073 /**
    5074  * @since 1.1.0
    5075  *
    5076  * @param string $step_slug
    5077  *
    5078  * @return bool
    5079  */
    5080 function bp_is_group_creation_step( $step_slug ) {
    5081 
    5082         // Make sure we are in the groups component.
    5083         if ( ! bp_is_groups_component() || ! bp_is_current_action( 'create' ) ) {
    5084                 return false;
    5085         }
    5086 
    5087         $bp = buddypress();
    5088 
    5089         // If this the first step, we can just accept and return true.
    5090         $keys = array_keys( $bp->groups->group_creation_steps );
    5091         if ( !bp_action_variable( 1 ) && array_shift( $keys ) == $step_slug ) {
    5092                 return true;
    5093         }
    5094 
    5095         // Before allowing a user to see a group creation step we must make sure
    5096         // previous steps are completed.
    5097         if ( !bp_is_first_group_creation_step() ) {
    5098                 if ( !bp_are_previous_group_creation_steps_complete( $step_slug ) ) {
    5099                         return false;
    5100                 }
    5101         }
    5102 
    5103         // Check the current step against the step parameter.
    5104         if ( bp_is_action_variable( $step_slug ) ) {
    5105                 return true;
    5106         }
    5107 
    5108         return false;
    5109 }
    5110 
    5111 /**
    5112  * @since 1.1.0
    5113  *
    5114  * @param array $step_slugs
    5115  *
    5116  * @return bool
    5117  */
    5118 function bp_is_group_creation_step_complete( $step_slugs ) {
    5119         $bp = buddypress();
    5120 
    5121         if ( !isset( $bp->groups->completed_create_steps ) ) {
    5122                 return false;
    5123         }
    5124 
    5125         if ( is_array( $step_slugs ) ) {
    5126                 $found = true;
    5127 
    5128                 foreach ( (array) $step_slugs as $step_slug ) {
    5129                         if ( !in_array( $step_slug, $bp->groups->completed_create_steps ) ) {
    5130                                 $found = false;
    5131                         }
    5132                 }
    5133 
    5134                 return $found;
    5135         } else {
    5136                 return in_array( $step_slugs, $bp->groups->completed_create_steps );
    5137         }
    5138 
    5139         return true;
    5140 }
    5141 
    5142 /**
    5143  * @since 1.1.0
    5144  *
    5145  * @param string $step_slug
    5146  *
    5147  * @return bool
    5148  */
    5149 function bp_are_previous_group_creation_steps_complete( $step_slug ) {
    5150         $bp = buddypress();
    5151 
    5152         // If this is the first group creation step, return true.
    5153         $keys = array_keys( $bp->groups->group_creation_steps );
    5154         if ( array_shift( $keys ) == $step_slug ) {
    5155                 return true;
    5156         }
    5157 
    5158         reset( $bp->groups->group_creation_steps );
    5159 
    5160         $previous_steps = array();
    5161 
    5162         // Get previous steps.
    5163         foreach ( (array) $bp->groups->group_creation_steps as $slug => $name ) {
    5164                 if ( $slug === $step_slug ) {
    5165                         break;
    5166                 }
    5167 
    5168                 $previous_steps[] = $slug;
    5169         }
    5170 
    5171         return bp_is_group_creation_step_complete( $previous_steps );
    5172 }
    5173 
    5174 /**
    5175  * @since 1.1.0
    5176  */
    5177 function bp_new_group_id() {
    5178         echo bp_get_new_group_id();
    5179 }
    5180 
    5181         /**
    5182          * @since 1.1.0
    5183          *
    5184          * @return mixed|void
    5185          */
    5186         function bp_get_new_group_id() {
    5187                 $bp           = buddypress();
    5188                 $new_group_id = isset( $bp->groups->new_group_id )
    5189                         ? $bp->groups->new_group_id
    5190                         : 0;
    5191 
    5192                 /**
    5193                  * Filters the new group ID.
    5194                  *
    5195                  * @since 1.1.0
    5196                  *
    5197                  * @param int $new_group_id ID of the new group.
    5198                  */
    5199                 return apply_filters( 'bp_get_new_group_id', $new_group_id );
    5200         }
    5201 
    5202 /**
    5203  * @since 1.1.0
    5204  */
    5205 function bp_new_group_name() {
    5206         echo bp_get_new_group_name();
    5207 }
    5208 
    5209         /**
    5210          * @since 1.1.0
    5211          *
    5212          * @return mixed|void
    5213          */
    5214         function bp_get_new_group_name() {
    5215                 $bp   = buddypress();
    5216                 $name = isset( $bp->groups->current_group->name )
    5217                         ? $bp->groups->current_group->name
    5218                         : '';
    5219 
    5220                 /**
    5221                  * Filters the new group name.
    5222                  *
    5223                  * @since 1.1.0
    5224                  *
    5225                  * @param string $name Name of the new group.
    5226                  */
    5227                 return apply_filters( 'bp_get_new_group_name', $name );
    5228         }
    5229 
    5230 /**
    5231  * @since 1.1.0
    5232  */
    5233 function bp_new_group_description() {
    5234         echo bp_get_new_group_description();
    5235 }
    5236 
    5237         /**
    5238          * @since 1.1.0
    5239          *
    5240          * @return mixed|void
    5241          */
    5242         function bp_get_new_group_description() {
    5243                 $bp          = buddypress();
    5244                 $description = isset( $bp->groups->current_group->description )
    5245                         ? $bp->groups->current_group->description
    5246                         : '';
    5247 
    5248                 /**
    5249                  * Filters the new group description.
    5250                  *
    5251                  * @since 1.1.0
    5252                  *
    5253                  * @param string $name Description of the new group.
    5254                  */
    5255                 return apply_filters( 'bp_get_new_group_description', $description );
    5256         }
    5257 
    5258 /**
    5259  * @since 1.1.0
    5260  */
    5261 function bp_new_group_enable_forum() {
    5262         echo bp_get_new_group_enable_forum();
    5263 }
    5264 
    5265         /**
    5266          * @since 1.1.0
    5267          *
    5268          * @return int
    5269          */
    5270         function bp_get_new_group_enable_forum() {
    5271                 $bp    = buddypress();
    5272                 $forum = isset( $bp->groups->current_group->enable_forum )
    5273                         ? $bp->groups->current_group->enable_forum
    5274                         : false;
    5275 
    5276                 /**
    5277                  * Filters whether or not to enable forums for the new group.
    5278                  *
    5279                  * @since 1.1.0
    5280                  *
    5281                  * @param int $forum Whether or not to enable forums.
    5282                  */
    5283                 return (int) apply_filters( 'bp_get_new_group_enable_forum', $forum );
    5284         }
    5285 
    5286 /**
    5287  * @since 1.1.0
    5288  */
    5289 function bp_new_group_status() {
    5290         echo bp_get_new_group_status();
    5291 }
    5292 
    5293         /**
    5294          * @since 1.1.0
    5295          *
    5296          * @return mixed|void
    5297          */
    5298         function bp_get_new_group_status() {
    5299                 $bp     = buddypress();
    5300                 $status = isset( $bp->groups->current_group->status )
    5301                         ? $bp->groups->current_group->status
    5302                         : 'public';
    5303 
    5304                 /**
    5305                  * Filters the new group status.
    5306                  *
    5307                  * @since 1.1.0
    5308                  *
    5309                  * @param string $status Status for the new group.
    5310                  */
    5311                 return apply_filters( 'bp_get_new_group_status', $status );
    5312         }
    5313 
    5314 /**
    5315  * Output the avatar for the group currently being created
    5316  *
    5317  * @since 1.1.0
    5318  *
    5319  * @see bp_core_fetch_avatar() For more information on accepted arguments
    5320  *
    5321  * @param array|string $args See bp_core_fetch_avatar().
    5322  */
    5323 function bp_new_group_avatar( $args = '' ) {
    5324         echo bp_get_new_group_avatar( $args );
    5325 }
    5326         /**
    5327          * Return the avatar for the group currently being created
    5328          *
    5329          * @since 1.1.0
    5330          *
    5331          * @see bp_core_fetch_avatar() For a description of arguments and return values.
    5332          *
    5333          * @param array|string $args {
    5334          *     Arguments are listed here with an explanation of their defaults.
    5335          *     For more information about the arguments, see {@link bp_core_fetch_avatar()}.
    5336          *
    5337          *     @type string   $alt     Default: 'Group photo'.
    5338          *     @type string   $class   Default: 'avatar'.
    5339          *     @type string   $type    Default: 'full'.
    5340          *     @type int|bool $width   Default: false.
    5341          *     @type int|bool $height  Default: false.
    5342          *     @type string   $id      Passed to $css_id parameter. Default: 'avatar-crop-preview'.
    5343          * }
    5344          * @return string       The avatar for the group being created
    5345          */
    5346         function bp_get_new_group_avatar( $args = '' ) {
    5347 
    5348                 // Parse arguments.
    5349                 $r = bp_parse_args( $args, array(
    5350                         'type'    => 'full',
    5351                         'width'   => false,
    5352                         'height'  => false,
    5353                         'class'   => 'avatar',
    5354                         'id'      => 'avatar-crop-preview',
    5355                         'alt'     => __( 'Group photo', 'buddypress' ),
    5356                         'no_grav' => false
    5357                 ), 'get_new_group_avatar' );
    5358 
    5359                 // Merge parsed arguments with object specific data.
    5360                 $r = array_merge( $r, array(
    5361                         'item_id'    => bp_get_current_group_id(),
    5362                         'object'     => 'group',
    5363                         'avatar_dir' => 'group-avatars',
    5364                 ) );
    5365 
    5366                 // Get the avatar.
    5367                 $avatar = bp_core_fetch_avatar( $r );
    5368 
    5369                 /**
    5370                  * Filters the new group avatar.
    5371                  *
    5372                  * @since 1.1.0
    5373                  *
    5374                  * @param string $avatar HTML markup for the new group avatar.
    5375                  * @param array  $r      Array of parsed arguments for the group avatar.
    5376                  * @param array  $args   Array of original arguments passed to the function.
    5377                  */
    5378                 return apply_filters( 'bp_get_new_group_avatar', $avatar, $r, $args );
    5379         }
    5380 
    5381 /**
    5382  * Escape & output the URL to the previous group creation step
    5383  *
    5384  * @since 1.1.0
    5385  */
    5386 function bp_group_creation_previous_link() {
    5387         echo esc_url( bp_get_group_creation_previous_link() );
    5388 }
    5389         /**
    5390          * Return the URL to the previous group creation step
    5391          *
    5392          * @since 1.1.0
    5393          *
    5394          * @return string
    5395          */
    5396         function bp_get_group_creation_previous_link() {
    5397                 $bp    = buddypress();
    5398                 $steps = array_keys( $bp->groups->group_creation_steps );
    5399 
    5400                 // Loop through steps.
    5401                 foreach ( $steps as $slug ) {
    5402 
    5403                         // Break when the current step is found.
    5404                         if ( bp_is_action_variable( $slug ) ) {
    5405                                 break;
    5406                         }
    5407 
    5408                         // Add slug to previous steps.
    5409                         $previous_steps[] = $slug;
    5410                 }
    5411 
    5412                 // Generate the URL for the previous step.
    5413                 $group_directory = bp_get_groups_directory_permalink();
    5414                 $create_step     = 'create/step/';
    5415                 $previous_step   = array_pop( $previous_steps );
    5416                 $url             = trailingslashit( $group_directory . $create_step . $previous_step );
    5417 
    5418                 /**
    5419                  * Filters the permalink for the previous step with the group creation process.
    5420                  *
    5421                  * @since 1.1.0
    5422                  *
    5423                  * @param string $url Permalink for the previous step.
    5424                  */
    5425                 return apply_filters( 'bp_get_group_creation_previous_link', $url );
    5426         }
    5427 
    5428 /**
    5429  * Echoes the current group creation step.
    5430  *
    5431  * @since 1.6.0
    5432  */
    5433 function bp_groups_current_create_step() {
    5434         echo bp_get_groups_current_create_step();
    5435 }
    5436         /**
    5437          * Returns the current group creation step. If none is found, returns an empty string.
    5438          *
    5439          * @since 1.6.0
    5440          *
    5441          * @uses apply_filters() Filter bp_get_groups_current_create_step to modify.
    5442          *
    5443          * @return string $current_create_step
    5444          */
    5445         function bp_get_groups_current_create_step() {
    5446                 $bp = buddypress();
    5447 
    5448                 if ( !empty( $bp->groups->current_create_step ) ) {
    5449                         $current_create_step = $bp->groups->current_create_step;
    5450                 } else {
    5451                         $current_create_step = '';
    5452                 }
    5453 
    5454                 /**
    5455                  * Filters the current group creation step.
    5456                  *
    5457                  * If none is found, returns an empty string.
    5458                  *
    5459                  * @since 1.6.0
    5460                  *
    5461                  * @param string $current_create_step Current step in the group creation process.
    5462                  */
    5463                 return apply_filters( 'bp_get_groups_current_create_step', $current_create_step );
    5464         }
    5465 
    5466 /**
    5467  * Is the user looking at the last step in the group creation process.
    5468  *
    5469  * @since 1.1.0
    5470  *
    5471  * @param string $step Step to compare.
    5472  * @return bool True if yes, False if no
    5473  */
    5474 function bp_is_last_group_creation_step( $step = '' ) {
    5475 
    5476         // Use current step, if no step passed.
    5477         if ( empty( $step ) ) {
    5478                 $step = bp_get_groups_current_create_step();
    5479         }
    5480 
    5481         // Get the last step.
    5482         $bp     = buddypress();
    5483         $steps  = array_keys( $bp->groups->group_creation_steps );
    5484         $l_step = array_pop( $steps );
    5485 
    5486         // Compare last step to step.
    5487         $retval = ( $l_step === $step );
    5488 
    5489         /**
    5490          * Filters whether or not user is looking at last step in group creation process.
    5491          *
    5492          * @since 2.4.0
    5493          *
    5494          * @param bool   $retval Whether or not we are looking at last step.
    5495          * @param array  $steps  Array of steps from the group creation process.
    5496          * @param string $step   Step to compare.
    5497          */
    5498         return (bool) apply_filters( 'bp_is_last_group_creation_step', $retval, $steps, $step );
    5499 }
    5500 
    5501 /**
    5502  * Is the user looking at the first step in the group creation process
    5503  *
    5504  * @since 1.1.0
    5505  *
    5506  * @param string $step Step to compare.
    5507  * @return bool True if yes, False if no
    5508  */
    5509 function bp_is_first_group_creation_step( $step = '' ) {
    5510 
    5511         // Use current step, if no step passed.
    5512         if ( empty( $step ) ) {
    5513                 $step = bp_get_groups_current_create_step();
    5514         }
    5515 
    5516         // Get the first step.
    5517         $bp     = buddypress();
    5518         $steps  = array_keys( $bp->groups->group_creation_steps );
    5519         $f_step = array_shift( $steps );
    5520 
    5521         // Compare first step to step.
    5522         $retval = ( $f_step === $step );
    5523 
    5524         /**
    5525          * Filters whether or not user is looking at first step in group creation process.
    5526          *
    5527          * @since 2.4.0
    5528          *
    5529          * @param bool   $retval Whether or not we are looking at first step.
    5530          * @param array  $steps  Array of steps from the group creation process.
    5531          * @param string $step   Step to compare.
    5532          */
    5533         return (bool) apply_filters( 'bp_is_first_group_creation_step', $retval, $steps, $step );
    5534 }
    5535 
    5536 /**
    5537  * Output a list of friends who can be invited to a group
    5538  *
    5539  * @since 1.0.0
    5540  *
    5541  * @param array $args Array of arguments for friends list output.
    5542  */
    5543 function bp_new_group_invite_friend_list( $args = array() ) {
    5544         echo bp_get_new_group_invite_friend_list( $args );
    5545 }
    5546         /**
    5547          * Return a list of friends who can be invited to a group
    5548          *
    5549          * @since 1.0.0
    5550          *
    5551          * @param array $args Array of arguments for friends list output.
    5552          * @return mixed HTML list of checkboxes, or false
    5553          */
    5554         function bp_get_new_group_invite_friend_list( $args = array() ) {
    5555 
    5556                 // Bail if no friends component.
    5557                 if ( ! bp_is_active( 'friends' ) ) {
    5558                         return false;
    5559                 }
    5560 
    5561                 // Parse arguments.
    5562                 $r = wp_parse_args( $args, array(
    5563                         'user_id'   => bp_loggedin_user_id(),
    5564                         'group_id'  => false,
    5565                         'separator' => 'li'
    5566                 ) );
    5567 
    5568                 // No group passed, so look for new or current group ID's.
    5569                 if ( empty( $r['group_id'] ) ) {
    5570                         $bp            = buddypress();
    5571                         $r['group_id'] = ! empty( $bp->groups->new_group_id )
    5572                                 ? $bp->groups->new_group_id
    5573                                 : $bp->groups->current_group->id;
    5574                 }
    5575 
    5576                 // Setup empty items array.
    5577                 $items = array();
    5578 
    5579                 // Get user's friends who are not in this group already.
    5580                 $friends = friends_get_friends_invite_list( $r['user_id'], $r['group_id'] );
    5581 
    5582                 if ( ! empty( $friends ) ) {
    5583 
    5584                         // Get already invited users.
    5585                         $invites = groups_get_invites_for_group( $r['user_id'], $r['group_id'] );
    5586 
    5587                         for ( $i = 0, $count = count( $friends ); $i < $count; ++$i ) {
    5588                                 $checked = in_array( (int) $friends[ $i ]['id'], (array) $invites );
    5589                                 $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'] . '>';
    5590                         }
    5591                 }
    5592 
    5593                 /**
    5594                  * Filters the array of friends who can be invited to a group.
    5595                  *
    5596                  * @since 2.4.0
    5597                  *
    5598                  * @param array $items Array of friends.
    5599                  * @param array $r     Parsed arguments from bp_get_new_group_invite_friend_list()
    5600                  * @param array $args  Unparsed arguments from bp_get_new_group_invite_friend_list()
    5601                  */
    5602                 $invitable_friends = apply_filters( 'bp_get_new_group_invite_friend_list', $items, $r, $args );
    5603 
    5604                 if ( ! empty( $invitable_friends ) && is_array( $invitable_friends ) ) {
    5605                         $retval = implode( "\n", $invitable_friends );
    5606                 } else {
    5607                         $retval = false;
    5608                 }
    5609 
    5610                 return $retval;
    5611         }
    5612 
    5613 /**
    5614  * @since 1.0.0
    5615  */
    5616 function bp_directory_groups_search_form() {
    5617 
    5618         $query_arg = bp_core_get_component_search_query_arg( 'groups' );
    5619 
    5620         if ( ! empty( $_REQUEST[ $query_arg ] ) ) {
    5621                 $search_value = stripslashes( $_REQUEST[ $query_arg ] );
    5622         } else {
    5623                 $search_value = bp_get_search_default_text( 'groups' );
    5624         }
    5625 
    5626         $search_form_html = '<form action="" method="get" id="search-groups-form">
    5627                 <label for="groups_search"><input type="text" name="' . esc_attr( $query_arg ) . '" id="groups_search" placeholder="'. esc_attr( $search_value ) .'" /></label>
    5628                 <input type="submit" id="groups_search_submit" name="groups_search_submit" value="'. __( 'Search', 'buddypress' ) .'" />
    5629         </form>';
    5630 
    5631         /**
    5632          * Filters the HTML markup for the groups search form.
    5633          *
    5634          * @since 1.9.0
    5635          *
    5636          * @param string $search_form_html HTML markup for the search form.
    5637          */
    5638         echo apply_filters( 'bp_directory_groups_search_form', $search_form_html );
    5639 
    5640 }
    5641 
    5642 /**
    5643  * Displays group header tabs.
    5644  *
    5645  * @since 1.0.0
    5646  *
    5647  * @todo Deprecate?
    5648  */
    5649 function bp_groups_header_tabs() {
    5650         $user_groups = bp_displayed_user_domain() . bp_get_groups_slug(); ?>
    5651 
    5652         <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>
    5653         <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>
    5654         <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>
    5655         <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>
    5656         <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>
    5657         <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>
    5658 
    5659 <?php
    5660         do_action( 'groups_header_tabs' );
    5661 }
    5662 
    5663 /**
    5664  * Displays group filter titles.
    5665  *
    5666  * @since 1.0.0
    5667  *
    5668  * @todo Deprecate?
    5669  */
    5670 function bp_groups_filter_title() {
    5671         $current_filter = bp_action_variable( 0 );
    5672 
    5673         switch ( $current_filter ) {
    5674                 case 'recently-active': default:
    5675                         _e( 'Recently Active', 'buddypress' );
    5676                         break;
    5677                 case 'recently-joined':
    5678                         _e( 'Recently Joined', 'buddypress' );
    5679                         break;
    5680                 case 'most-popular':
    5681                         _e( 'Most Popular', 'buddypress' );
    5682                         break;
    5683                 case 'admin-of':
    5684                         _e( 'Administrator Of', 'buddypress' );
    5685                         break;
    5686                 case 'mod-of':
    5687                         _e( 'Moderator Of', 'buddypress' );
    5688                         break;
    5689                 case 'alphabetically':
    5690                         _e( 'Alphabetically', 'buddypress' );
    5691                 break;
    5692         }
    5693         do_action( 'bp_groups_filter_title' );
    5694 }
    5695 
    5696 /**
    5697  * Is the current page a specific group admin screen?
    5698  *
    5699  * @since 1.1.0
    5700  *
    5701  * @param string $slug Admin screen slug.
    5702  * @return bool
    5703  */
    5704 function bp_is_group_admin_screen( $slug = '' ) {
    5705         return (bool) ( bp_is_group_admin_page() && bp_is_action_variable( $slug ) );
    5706 }
    5707 
    5708 /**
    5709  * Echoes the current group admin tab slug.
    5710  *
    5711  * @since 1.6.0
    5712  */
    5713 function bp_group_current_admin_tab() {
    5714         echo bp_get_group_current_admin_tab();
    5715 }
    5716         /**
    5717          * Returns the current group admin tab slug.
    5718          *
    5719          * @since 1.6.0
    5720          *
    5721          * @uses apply_filters() Filter bp_get_current_group_admin_tab to modify return value.
    5722          *
    5723          * @return string $tab The current tab's slug.
    5724          */
    5725         function bp_get_group_current_admin_tab() {
    5726                 if ( bp_is_groups_component() && bp_is_current_action( 'admin' ) ) {
    5727                         $tab = bp_action_variable( 0 );
    5728                 } else {
    5729                         $tab = '';
    5730                 }
    5731 
    5732                 /**
    5733                  * Filters the current group admin tab slug.
    5734                  *
    5735                  * @since 1.6.0
    5736                  *
    5737                  * @param string $tab Current group admin tab slug.
    5738                  */
    5739                 return apply_filters( 'bp_get_current_group_admin_tab', $tab );
    5740         }
    5741 
    5742 /** Group Avatar Template Tags ************************************************/
    5743 
    5744 /**
    5745  * Outputs the current group avatar.
    5746  *
    5747  * @since 1.0.0
    5748  *
    5749  * @uses bp_get_group_current_avatar() to get the avatar of the current group.
    5750  *
    5751  * @param string $type Thumb or full.
    5752  */
    5753 function bp_group_current_avatar( $type = 'thumb' ) {
    5754         echo bp_get_group_current_avatar( $type );
    5755 }
    5756         /**
    5757          * Returns the current group avatar.
    5758          *
    5759          * @since 2.0.0
    5760          *
    5761          * @param string $type Thumb or full.
    5762          * @return string $tab The current tab's slug.
    5763          */
    5764         function bp_get_group_current_avatar( $type = 'thumb' ) {
    5765 
    5766                 $group_avatar = bp_core_fetch_avatar( array(
    5767                         'item_id'    => bp_get_current_group_id(),
    5768                         'object'     => 'group',
    5769                         'type'       => $type,
    5770                         'avatar_dir' => 'group-avatars',
    5771                         'alt'        => __( 'Group avatar', 'buddypress' ),
    5772                         'class'      => 'avatar'
    5773                 ) );
    5774 
    5775                 /**
    5776                  * Filters the current group avatar.
    5777                  *
    5778                  * @since 2.0.0
    5779                  *
    5780                  * @param string $group_avatar HTML markup for current group avatar.
    5781                  */
    5782                 return apply_filters( 'bp_get_group_current_avatar', $group_avatar );
    5783         }
    5784 
    5785 /**
    5786  * Return whether a group has an avatar.
    5787  *
    5788  * @since 1.1.0
    5789  *
    5790  * @param int|bool $group_id Group ID to check.
    5791  * @return boolean
    5792  */
    5793 function bp_get_group_has_avatar( $group_id = false ) {
    5794 
    5795         if ( false === $group_id ) {
    5796                 $group_id = bp_get_current_group_id();
    5797         }
    5798 
    5799         $group_avatar = bp_core_fetch_avatar( array(
    5800                 'item_id' => $group_id,
    5801                 'object'  => 'group',
    5802                 'no_grav' => true,
    5803                 'html'    => false,
    5804         ) );
    5805 
    5806         if ( bp_core_avatar_default( 'local' ) === $group_avatar ) {
    5807                 return false;
    5808         }
    5809 
    5810         return true;
    5811 }
    5812 
    5813 /**
    5814  * @since 1.1.0
    5815  */
    5816 function bp_group_avatar_delete_link() {
    5817         echo bp_get_group_avatar_delete_link();
    5818 }
    5819 
    5820         /**
    5821          * @since 1.1.0
    5822          *
    5823          * @return mixed|void
    5824          */
    5825         function bp_get_group_avatar_delete_link() {
    5826                 $bp = buddypress();
    5827 
    5828                 /**
    5829                  * Filters the URL to delete the group avatar.
    5830                  *
    5831                  * @since 1.1.0
    5832                  *
    5833                  * @param string $value URL to delete the group avatar.
    5834                  */
    5835                 return apply_filters( 'bp_get_group_avatar_delete_link', wp_nonce_url( bp_get_group_permalink( $bp->groups->current_group ) . 'admin/group-avatar/delete', 'bp_group_avatar_delete' ) );
    5836         }
    5837 
    5838 /**
    5839  * @since 1.0.0
    5840  */
    5841 function bp_custom_group_boxes() {
    5842         do_action( 'groups_custom_group_boxes' );
    5843 }
    5844 
    5845 /**
    5846  * @since 1.0.0
    5847  */
    5848 function bp_custom_group_admin_tabs() {
    5849         do_action( 'groups_custom_group_admin_tabs' );
    5850 }
    5851 
    5852 /**
    5853  * @since 1.0.0
    5854  */
    5855 function bp_custom_group_fields_editable() {
    5856         do_action( 'groups_custom_group_fields_editable' );
    5857 }
    5858 
    5859 /**
    5860  * @since 1.0.0
    5861  */
    5862 function bp_custom_group_fields() {
    5863         do_action( 'groups_custom_group_fields' );
    5864 }
    5865 
    5866 /* Group Membership Requests *************************************************/
    5867 
    5868 /**
    5869  * Class BP_Groups_Membership_Requests_Template
    5870  *
    5871  * @since 1.0.0
    5872  */
    5873 class BP_Groups_Membership_Requests_Template {
    5874 
    5875         /**
    5876          * @since 1.0.0
    5877          * @var int
    5878          */
    5879         public $current_request = -1;
    5880 
    5881         /**
    5882          * @since 1.0.0
    5883          * @var int
    5884          */
    5885         public $request_count;
    5886 
    5887         /**
    5888          * @since 1.0.0
    5889          * @var array
    5890          */
    5891         public $requests;
    5892 
    5893         /**
    5894          * @since 1.0.0
    5895          * @var object
    5896          */
    5897         public $request;
    5898 
    5899         /**
    5900          * @sine 1.0.0
    5901          * @var bool
    5902          */
    5903         public $in_the_loop;
    5904 
    5905         /**
    5906          * @since 1.0.0
    5907          * @var int
    5908          */
    5909         public $pag_page;
    5910 
    5911         /**
    5912          * @since 1.0.0
    5913          * @var int
    5914          */
    5915         public $pag_num;
    5916 
    5917         /**
    5918          * @since 1.0.0
    5919          * @var array|string|void
    5920          */
    5921         public $pag_links;
    5922 
    5923         /**
    5924          * @since 1.0.0
    5925          * @var int
    5926          */
    5927         public $total_request_count;
    5928 
    5929         /**
    5930          * Constructor method.
    5931          *
    5932          * @since 1.5.0
    5933          *
    5934          * @param array $args {
    5935          *     @type int $group_id ID of the group whose membership requests
    5936          *                         are being queried. Default: current group id.
    5937          *     @type int $per_page Number of records to return per page of
    5938          *                         results. Default: 10.
    5939          *     @type int $page     Page of results to show. Default: 1.
    5940          *     @type int $max      Max items to return. Default: false (show all)
    5941          * }
    5942          */
    5943         public function __construct( $args = array() ) {
    5944 
    5945                 // Backward compatibility with old method of passing arguments.
    5946                 if ( ! is_array( $args ) || func_num_args() > 1 ) {
    5947                         _deprecated_argument( __METHOD__, '2.0.0', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) );
    5948 
    5949                         $old_args_keys = array(
    5950                                 0 => 'group_id',
    5951                                 1 => 'per_page',
    5952                                 2 => 'max',
    5953                         );
    5954 
    5955                         $func_args = func_get_args();
    5956                         $args      = bp_core_parse_args_array( $old_args_keys, $func_args );
    5957                 }
    5958 
    5959                 $r = wp_parse_args( $args, array(
    5960                         'page'     => 1,
    5961                         'per_page' => 10,
    5962                         'page_arg' => 'mrpage',
    5963                         'max'      => false,
    5964                         'type'     => 'first_joined',
    5965                         'group_id' => bp_get_current_group_id(),
    5966                 ) );
    5967 
    5968                 $this->pag_arg  = sanitize_key( $r['page_arg'] );
    5969                 $this->pag_page = bp_sanitize_pagination_arg( $this->pag_arg, $r['page']     );
    5970                 $this->pag_num  = bp_sanitize_pagination_arg( 'num',          $r['per_page'] );
    5971 
    5972                 $mquery = new BP_Group_Member_Query( array(
    5973                         'group_id' => $r['group_id'],
    5974                         'type'     => $r['type'],
    5975                         'per_page' => $this->pag_num,
    5976                         'page'     => $this->pag_page,
    5977 
    5978                         // These filters ensure we only get pending requests.
    5979                         'is_confirmed' => false,
    5980                         'inviter_id'   => 0,
    5981                 ) );
    5982 
    5983                 $this->requests      = array_values( $mquery->results );
    5984                 $this->request_count = count( $this->requests );
    5985 
    5986                 // Compatibility with legacy format of request data objects.
    5987                 foreach ( $this->requests as $rk => $rv ) {
    5988                         // For legacy reasons, the 'id' property of each
    5989                         // request must match the membership id, not the ID of
    5990                         // the user (as it's returned by BP_Group_Member_Query).
    5991                         $this->requests[ $rk ]->user_id = $rv->ID;
    5992                         $this->requests[ $rk ]->id      = $rv->membership_id;
    5993 
    5994                         // Miscellaneous values.
    5995                         $this->requests[ $rk ]->group_id   = $r['group_id'];
    5996                 }
    5997 
    5998                 if ( empty( $r['max'] ) || ( $r['max'] >= (int) $mquery->total_users ) ) {
    5999                         $this->total_request_count = (int) $mquery->total_users;
    6000                 } else {
    6001                         $this->total_request_count = (int) $r['max'];
    6002                 }
    6003 
    6004                 if ( empty( $r['max'] ) || ( $r['max'] >= count( $this->requests ) ) ) {
    6005                         $this->request_count = count( $this->requests );
    6006                 } else {
    6007                         $this->request_count = (int) $r['max'];
    6008                 }
    6009 
    6010                 $this->pag_links = paginate_links( array(
    6011                         'base'      => add_query_arg( $this->pag_arg, '%#%' ),
    6012                         'format'    => '',
    6013                         'total'     => ceil( $this->total_request_count / $this->pag_num ),
    6014                         'current'   => $this->pag_page,
    6015                         'prev_text' => '&larr;',
    6016                         'next_text' => '&rarr;',
    6017                         'mid_size'  => 1,
    6018                         'add_args'  => array(),
    6019                 ) );
    6020         }
    6021 
    6022         /**
    6023          * Whether or not there are requests to show.
    6024          *
    6025          * @since 1.0.0
    6026          *
    6027          * @return bool
    6028          */
    6029         public function has_requests() {
    6030                 if ( ! empty( $this->request_count ) ) {
    6031                         return true;
    6032                 }
    6033 
    6034                 return false;
    6035         }
    6036 
    6037         /**
    6038          * Moves up to the next request.
    6039          *
    6040          * @since 1.0.0
    6041          *
    6042          * @return object
    6043          */
    6044         public function next_request() {
    6045                 $this->current_request++;
    6046                 $this->request = $this->requests[ $this->current_request ];
    6047 
    6048                 return $this->request;
    6049         }
    6050 
    6051         /**
    6052          * Rewinds the requests to the first in the list.
    6053          *
    6054          * @since 1.0.0
    6055          */
    6056         public function rewind_requests() {
    6057                 $this->current_request = -1;
    6058 
    6059                 if ( $this->request_count > 0 ) {
    6060                         $this->request = $this->requests[0];
    6061                 }
    6062         }
    6063 
    6064         /**
    6065          * Finishes up the requests to display.
    6066          *
    6067          * @since 1.0.0
    6068          *
    6069          * @return bool
    6070          */
    6071         public function requests() {
    6072                 $tick = intval( $this->current_request + 1 );
    6073                 if ( $tick < $this->request_count ) {
    6074                         return true;
    6075                 } elseif ( $tick == $this->request_count ) {
    6076 
    6077                         /**
    6078                          * Fires right before the rewinding of group membership requests list.
    6079                          *
    6080                          * @since 1.5.0
    6081                          */
    6082                         do_action( 'group_request_loop_end' );
    6083                         // Do some cleaning up after the loop.
    6084                         $this->rewind_requests();
    6085                 }
    6086 
    6087                 $this->in_the_loop = false;
    6088                 return false;
    6089         }
    6090 
    6091         /**
    6092          * Sets up the request to display.
    6093          *
    6094          * @since 1.0.0
    6095          */
    6096         public function the_request() {
    6097                 $this->in_the_loop = true;
    6098                 $this->request     = $this->next_request();
    6099 
    6100                 // Loop has just started.
    6101                 if ( 0 == $this->current_request ) {
    6102 
    6103                         /**
    6104                          * Fires if the current group membership request item is the first in the loop.
    6105                          *
    6106                          * @since 1.1.0
    6107                          */
    6108                         do_action( 'group_request_loop_start' );
    6109                 }
    6110         }
    6111 }
    6112 
    6113 /**
    6114  * Initialize a group membership request template loop.
    6115  *
    6116  * @since 1.0.0
    6117  *
    6118  * @param array|string $args {
    6119  *     @type int $group_id ID of the group. Defaults to current group.
    6120  *     @type int $per_page Number of records to return per page. Default: 10.
    6121  *     @type int $page     Page of results to return. Default: 1.
    6122  *     @type int $max      Max number of items to return. Default: false.
    6123  * }
    6124  * @return bool True if there are requests, otherwise false.
    6125  */
    6126 function bp_group_has_membership_requests( $args = '' ) {
    6127         global $requests_template;
    6128 
    6129         $defaults = array(
    6130                 'group_id' => bp_get_current_group_id(),
    6131                 'per_page' => 10,
    6132                 'page'     => 1,
    6133                 'max'      => false
    6134         );
    6135 
    6136         $r = wp_parse_args( $args, $defaults );
    6137 
    6138         $requests_template = new BP_Groups_Membership_Requests_Template( $r );
    6139 
    6140         /**
    6141          * Filters whether or not a group membership query has requests to display.
    6142          *
    6143          * @since 1.1.0
    6144          *
    6145          * @param bool                                   $value             Whether there are requests to display.
    6146          * @param BP_Groups_Membership_Requests_Template $requests_template Object holding the requests query results.
    6147          */
    6148         return apply_filters( 'bp_group_has_membership_requests', $requests_template->has_requests(), $requests_template );
    6149 }
    6150 
    6151 /**
    6152  * @since 1.0.0
    6153  *
    6154  * @return mixed
    6155  */
    6156 function bp_group_membership_requests() {
    6157         global $requests_template;
    6158 
    6159         return $requests_template->requests();
    6160 }
    6161 
    6162 /**
    6163  * @since 1.0.0
    6164  *
    6165  * @return mixed
    6166  */
    6167 function bp_group_the_membership_request() {
    6168         global $requests_template;
    6169 
    6170         return $requests_template->the_request();
    6171 }
    6172 
    6173 /**
    6174  * @since 1.0.0
    6175  */
    6176 function bp_group_request_user_avatar_thumb() {
    6177         global $requests_template;
    6178 
    6179         /**
    6180          * Filters the requesting user's avatar thumbnail.
    6181          *
    6182          * @since 1.0.0
    6183          *
    6184          * @param string $value HTML markup for the user's avatar thumbnail.
    6185          */
    6186         echo apply_filters( 'bp_group_request_user_avatar_thumb', bp_core_fetch_avatar( array( 'item_id' => $requests_template->request->user_id, 'type' => 'thumb', 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_core_get_user_displayname( $requests_template->request->user_id ) ) ) ) );
    6187 }
    6188 
    6189 /**
    6190  * @since 1.0.0
    6191  */
    6192 function bp_group_request_reject_link() {
    6193         echo bp_get_group_request_reject_link();
    6194 }
    6195 
    6196         /**
    6197          * @since 1.2.6
    6198          *
    6199          * @return mixed|void
    6200          */
    6201         function bp_get_group_request_reject_link() {
    6202                 global $requests_template;
    6203 
    6204                 /**
    6205                  * Filters the URL to use to reject a membership request.
    6206                  *
    6207                  * @since 1.2.6
    6208                  *
    6209                  * @param string $value URL to use to reject a membership request.
    6210                  */
    6211                 return apply_filters( 'bp_get_group_request_reject_link', wp_nonce_url( bp_get_group_permalink( groups_get_current_group() ) . 'admin/membership-requests/reject/' . $requests_template->request->membership_id, 'groups_reject_membership_request' ) );
    6212         }
    6213 
    6214 /**
    6215  * @since 1.0.0
    6216  */
    6217 function bp_group_request_accept_link() {
    6218         echo bp_get_group_request_accept_link();
    6219 }
    6220 
    6221         /**
    6222          * @since 1.2.6
    6223          * @return mixed|void
    6224          */
    6225         function bp_get_group_request_accept_link() {
    6226                 global $requests_template;
    6227 
    6228                 /**
    6229                  * Filters the URL to use to accept a membership request.
    6230                  *
    6231                  * @since 1.2.6
    6232                  *
    6233                  * @param string $value URL to use to accept a membership request.
    6234                  */
    6235                 return apply_filters( 'bp_get_group_request_accept_link', wp_nonce_url( bp_get_group_permalink( groups_get_current_group() ) . 'admin/membership-requests/accept/' . $requests_template->request->membership_id, 'groups_accept_membership_request' ) );
    6236         }
    6237 
    6238 /**
    6239  * @since 1.0.0
    6240  */
    6241 function bp_group_request_user_link() {
    6242         echo bp_get_group_request_user_link();
    6243 }
    6244 
    6245         /**
    6246          * @since 1.2.6
    6247          *
    6248          * @return mixed|void
    6249          */
    6250         function bp_get_group_request_user_link() {
    6251                 global $requests_template;
    6252 
    6253                 /**
    6254                  * Filters the URL for the user requesting membership.
    6255                  *
    6256                  * @since 1.2.6
    6257                  *
    6258                  * @param string $value URL for the user requestion membership.
    6259                  */
    6260                 return apply_filters( 'bp_get_group_request_user_link', bp_core_get_userlink( $requests_template->request->user_id ) );
    6261         }
    6262 
    6263 /**
    6264  * @since 1.0.0
    6265  */
    6266 function bp_group_request_time_since_requested() {
    6267         global $requests_template;
    6268 
    6269         /**
    6270          * Filters the formatted time since membership was requested.
    6271          *
    6272          * @since 1.0.0
    6273          *
    6274          * @param string $value Formatted time since membership was requested.
    6275          */
    6276         echo apply_filters( 'bp_group_request_time_since_requested', sprintf( __( 'requested %s', 'buddypress' ), bp_core_time_since( strtotime( $requests_template->request->date_modified ) ) ) );
    6277 }
    6278 
    6279 /**
    6280  * @since 1.0.0
    6281  */
    6282 function bp_group_request_comment() {
    6283         global $requests_template;
    6284 
    6285         /**
    6286          * Filters the membership request comment left by user.
    6287          *
    6288          * @since 1.0.0
    6289          *
    6290          * @param string $value Membership request comment left by user.
    6291          */
    6292         echo apply_filters( 'bp_group_request_comment', strip_tags( stripslashes( $requests_template->request->comments ) ) );
    6293 }
    6294 
    6295 /**
    6296  * Output pagination links for group membership requests.
    6297  *
    6298  * @since 2.0.0
    6299  */
    6300 function bp_group_requests_pagination_links() {
    6301         echo bp_get_group_requests_pagination_links();
    6302 }
    6303         /**
    6304          * Get pagination links for group membership requests.
    6305          *
    6306          * @since 2.0.0
    6307          *
    6308          * @return string
    6309          */
    6310         function bp_get_group_requests_pagination_links() {
    6311                 global $requests_template;
    6312 
    6313                 /**
    6314                  * Filters pagination links for group membership requests.
    6315                  *
    6316                  * @since 2.0.0
    6317                  *
    6318                  * @param string $value Pagination links for group membership requests.
    6319                  */
    6320                 return apply_filters( 'bp_get_group_requests_pagination_links', $requests_template->pag_links );
    6321         }
    6322 
    6323 /**
    6324  * Output pagination count text for group membership requests.
    6325  *
    6326  * @since 2.0.0
    6327  */
    6328 function bp_group_requests_pagination_count() {
    6329         echo bp_get_group_requests_pagination_count();
    6330 }
    6331         /**
    6332          * Get pagination count text for group membership requests.
    6333          *
    6334          * @since 2.0.0
    6335          *
    6336          * @return string
    6337          */
    6338         function bp_get_group_requests_pagination_count() {
    6339                 global $requests_template;
    6340 
    6341                 $start_num = intval( ( $requests_template->pag_page - 1 ) * $requests_template->pag_num ) + 1;
    6342                 $from_num  = bp_core_number_format( $start_num );
    6343                 $to_num    = bp_core_number_format( ( $start_num + ( $requests_template->pag_num - 1 ) > $requests_template->total_request_count ) ? $requests_template->total_request_count : $start_num + ( $requests_template->pag_num - 1 ) );
    6344                 $total     = bp_core_number_format( $requests_template->total_request_count );
    6345 
    6346                 if ( 1 == $requests_template->total_request_count ) {
    6347                         $message = __( 'Viewing 1 request', 'buddypress' );
    6348                 } else {
    6349                         $message = sprintf( _n( 'Viewing %1$s - %2$s of %3$s request', 'Viewing %1$s - %2$s of %3$s requests', $requests_template->total_request_count, 'buddypress' ), $from_num, $to_num, $total );
    6350                 }
    6351 
    6352                 /**
    6353                  * Filters pagination count text for group membership requests.
    6354                  *
    6355                  * @since 2.0.0
    6356                  *
    6357                  * @param string $message  Pagination count text for group membership requests.
    6358                  * @param string $from_num Total amount for the low value in the range.
    6359                  * @param string $to_num   Total amount for the high value in the range.
    6360                  * @param string $total    Total amount of members found.
    6361                  */
    6362                 return apply_filters( 'bp_get_group_requests_pagination_count', $message, $from_num, $to_num, $total );
    6363         }
    6364 
    6365 /** Group Invitations *********************************************************/
    6366 
    6367 /**
    6368  * Class BP_Groups_Invite_Template
    6369  *
    6370  * @since 1.1.0
    6371  */
    6372 class BP_Groups_Invite_Template {
    6373 
    6374         /**
    6375          * @since 1.1.0
    6376          * @var int
    6377          */
    6378         public $current_invite = -1;
    6379 
    6380         /**
    6381          * @since 1.1.0
    6382          * @var int
    6383          */
    6384         public $invite_count;
    6385 
    6386         /**
    6387          * @since 1.1.0
    6388          * @var array
    6389          */
    6390         public $invites;
    6391 
    6392         /**
    6393          * @since 1.1.0
    6394          * @var object
    6395          */
    6396         public $invite;
    6397 
    6398         /**
    6399          * @since 1.1.0
    6400          * @var bool
    6401          */
    6402         public $in_the_loop;
    6403 
    6404         /**
    6405          * @since 1.1.0
    6406          * @var int
    6407          */
    6408         public $pag_page;
    6409 
    6410         /**
    6411          * @since 1.1.0
    6412          * @var int
    6413          */
    6414         public $pag_num;
    6415 
    6416         /**
    6417          * @since 1.1.0
    6418          * @var string
    6419          */
    6420         public $pag_links;
    6421 
    6422         /**
    6423          * @since 1.1.0
    6424          * @var int
    6425          */
    6426         public $total_invite_count;
    6427 
    6428         /**
    6429          * BP_Groups_Invite_Template constructor.
    6430          *
    6431          * @since 1.5.0
    6432          *
    6433          * @param array $args
    6434          */
    6435         public function __construct( $args = array() ) {
    6436 
    6437                 // Backward compatibility with old method of passing arguments.
    6438                 if ( ! is_array( $args ) || func_num_args() > 1 ) {
    6439                         _deprecated_argument( __METHOD__, '2.0.0', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) );
    6440 
    6441                         $old_args_keys = array(
    6442                                 0  => 'user_id',
    6443                                 1  => 'group_id',
    6444                         );
    6445 
    6446                         $func_args = func_get_args();
    6447                         $args      = bp_core_parse_args_array( $old_args_keys, $func_args );
    6448                 }
    6449 
    6450                 $r = wp_parse_args( $args, array(
    6451                         'page'     => 1,
    6452                         'per_page' => 10,
    6453                         'page_arg' => 'invitepage',
    6454                         'user_id'  => bp_loggedin_user_id(),
    6455                         'group_id' => bp_get_current_group_id(),
    6456                 ) );
    6457 
    6458                 $this->pag_arg  = sanitize_key( $r['page_arg'] );
    6459                 $this->pag_page = bp_sanitize_pagination_arg( $this->pag_arg, $r['page']     );
    6460                 $this->pag_num  = bp_sanitize_pagination_arg( 'num',          $r['per_page'] );
    6461 
    6462                 $iquery = new BP_Group_Member_Query( array(
    6463                         'group_id' => $r['group_id'],
    6464                         'type'     => 'first_joined',
    6465                         'per_page' => $this->pag_num,
    6466                         'page'     => $this->pag_page,
    6467 
    6468                         // These filters ensure we get only pending invites.
    6469                         'is_confirmed' => false,
    6470                         'inviter_id'   => $r['user_id'],
    6471                 ) );
    6472 
    6473                 $this->invite_data        = $iquery->results;
    6474                 $this->total_invite_count = $iquery->total_users;
    6475                 $this->invites            = array_values( wp_list_pluck( $this->invite_data, 'ID' ) );
    6476                 $this->invite_count       = count( $this->invites );
    6477 
    6478                 // If per_page is set to 0 (show all results), don't generate
    6479                 // pag_links.
    6480                 if ( ! empty( $this->pag_num ) ) {
    6481                         $this->pag_links = paginate_links( array(
    6482                                 'base'      => add_query_arg( $this->pag_arg, '%#%' ),
    6483                                 'format'    => '',
    6484                                 'total'     => ceil( $this->total_invite_count / $this->pag_num ),
    6485                                 'current'   => $this->pag_page,
    6486                                 'prev_text' => '&larr;',
    6487                                 'next_text' => '&rarr;',
    6488                                 'mid_size'  => 1,
    6489                                 'add_args'  => array(),
    6490                         ) );
    6491                 } else {
    6492                         $this->pag_links = '';
    6493                 }
    6494         }
    6495 
    6496         /**
    6497          * Whether or not there are invites to show.
    6498          *
    6499          * @since 1.1.0
    6500          *
    6501          * @return bool
    6502          */
    6503         public function has_invites() {
    6504                 if ( ! empty( $this->invite_count ) ) {
    6505                         return true;
    6506                 }
    6507 
    6508                 return false;
    6509         }
    6510 
    6511         /**
    6512          * Increments up to the next invite to show.
    6513          *
    6514          * @since 1.1.0
    6515          *
    6516          * @return object
    6517          */
    6518         public function next_invite() {
    6519                 $this->current_invite++;
    6520                 $this->invite = $this->invites[ $this->current_invite ];
    6521 
    6522                 return $this->invite;
    6523         }
    6524 
    6525         /**
    6526          * Rewinds to the first invite to show.
    6527          *
    6528          * @since 1.1.0
    6529          */
    6530         public function rewind_invites() {
    6531                 $this->current_invite = -1;
    6532                 if ( $this->invite_count > 0 ) {
    6533                         $this->invite = $this->invites[0];
    6534                 }
    6535         }
    6536 
    6537         /**
    6538          * Finishes up the invites to show.
    6539          *
    6540          * @since 1.1.0
    6541          *
    6542          * @return bool
    6543          */
    6544         public function invites() {
    6545                 $tick = intval( $this->current_invite + 1 );
    6546                 if ( $tick < $this->invite_count ) {
    6547                         return true;
    6548                 } elseif ( $tick == $this->invite_count ) {
    6549 
    6550                         /**
    6551                          * Fires right before the rewinding of invites list.
    6552                          *
    6553                          * @since 1.1.0
    6554                          * @since 2.3.0 `$this` parameter added.
    6555                          *
    6556                          * @param BP_Groups_Invite_Template $this Instance of the current Invites template.
    6557                          */
    6558                         do_action( 'loop_end', $this );
    6559 
    6560                         // Do some cleaning up after the loop
    6561                         $this->rewind_invites();
    6562                 }
    6563 
    6564                 $this->in_the_loop = false;
    6565                 return false;
    6566         }
    6567 
    6568         /**
    6569          * Sets up the invite to show.
    6570          *
    6571          * @since 1.1.0
    6572          */
    6573         public function the_invite() {
    6574                 global $group_id;
    6575 
    6576                 $this->in_the_loop  = true;
    6577                 $user_id            = $this->next_invite();
    6578 
    6579                 $this->invite       = new stdClass;
    6580                 $this->invite->user = $this->invite_data[ $user_id ];
    6581 
    6582                 // This method previously populated the user object with
    6583                 // BP_Core_User. We manually configure BP_Core_User data for
    6584                 // backward compatibility.
    6585                 if ( bp_is_active( 'xprofile' ) ) {
    6586                         $this->invite->user->profile_data = BP_XProfile_ProfileData::get_all_for_user( $user_id );
    6587                 }
    6588 
    6589                 $this->invite->user->avatar       = bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'full',  'alt' => sprintf( __( 'Profile photo of %s', 'buddypress' ), $this->invite->user->fullname ) ) );
    6590                 $this->invite->user->avatar_thumb = bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'thumb', 'alt' => sprintf( __( 'Profile photo of %s', 'buddypress' ), $this->invite->user->fullname ) ) );
    6591                 $this->invite->user->avatar_mini  = bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'thumb', 'alt' => sprintf( __( 'Profile photo of %s', 'buddypress' ), $this->invite->user->fullname ), 'width' => 30, 'height' => 30 ) );
    6592                 $this->invite->user->email        = $this->invite->user->user_email;
    6593                 $this->invite->user->user_url     = bp_core_get_user_domain( $user_id, $this->invite->user->user_nicename, $this->invite->user->user_login );
    6594                 $this->invite->user->user_link    = "<a href='{$this->invite->user->user_url}' title='{$this->invite->user->fullname}'>{$this->invite->user->fullname}</a>";
    6595                 $this->invite->user->last_active  = bp_core_get_last_activity( $this->invite->user->last_activity, __( 'active %s', 'buddypress' ) );
    6596 
    6597                 if ( bp_is_active( 'groups' ) ) {
    6598                         $total_groups = BP_Groups_Member::total_group_count( $user_id );
    6599                         $this->invite->user->total_groups = sprintf( _n( '%d group', '%d groups', $total_groups, 'buddypress' ), $total_groups );
    6600                 }
    6601 
    6602                 if ( bp_is_active( 'friends' ) ) {
    6603                         $this->invite->user->total_friends = BP_Friends_Friendship::total_friend_count( $user_id );
    6604                 }
    6605 
    6606                 $this->invite->user->total_blogs = null;
    6607 
    6608                 // Global'ed in bp_group_has_invites()
    6609                 $this->invite->group_id = $group_id;
    6610 
    6611                 // loop has just started
    6612                 if ( 0 == $this->current_invite ) {
    6613 
    6614                         /**
    6615                          * Fires if the current invite item is the first in the loop.
    6616                          *
    6617                          * @since 1.1.0
    6618                          * @since 2.3.0 `$this` parameter added.
    6619                          *
    6620                          * @param BP_Groups_Invite_Template $this Instance of the current Invites template.
    6621                          */
    6622                         do_action( 'loop_start', $this );
    6623                 }
    6624         }
    6625 }
    6626 
    6627 /**
    6628  * Whether or not there are invites.
    6629  *
    6630  * @since 1.1.0
    6631  *
    6632  * @param string $args
    6633  * @return bool|mixed|void
    6634  */
    6635 function bp_group_has_invites( $args = '' ) {
    6636         global $invites_template, $group_id;
    6637 
    6638         $r = wp_parse_args( $args, array(
    6639                 'group_id' => false,
    6640                 'user_id'  => bp_loggedin_user_id(),
    6641                 'per_page' => false,
    6642                 'page'     => 1,
    6643         ) );
    6644 
    6645         if ( empty( $r['group_id'] ) ) {
    6646                 if ( groups_get_current_group() ) {
    6647                         $r['group_id'] = bp_get_current_group_id();
    6648                 } elseif ( ! empty( buddypress()->groups->new_group_id ) ) {
    6649                         $r['group_id'] = buddypress()->groups->new_group_id;
    6650                 }
    6651         }
    6652 
    6653         // Set the global (for use in BP_Groups_Invite_Template::the_invite()).
    6654         if ( empty( $group_id ) ) {
    6655                 $group_id = $r['group_id'];
    6656         }
    6657 
    6658         if ( ! $group_id ) {
    6659                 return false;
    6660         }
    6661 
    6662         $invites_template = new BP_Groups_Invite_Template( $r );
    6663 
    6664         /**
    6665          * Filters whether or not a group invites query has invites to display.
    6666          *
    6667          * @since 1.1.0
    6668          *
    6669          * @param bool                      $value            Whether there are requests to display.
    6670          * @param BP_Groups_Invite_Template $invites_template Object holding the invites query results.
    6671          */
    6672         return apply_filters( 'bp_group_has_invites', $invites_template->has_invites(), $invites_template );
    6673 }
    6674 
    6675 /**
    6676  * @since 1.1.0
    6677  *
    6678  * @return mixed
    6679  */
    6680 function bp_group_invites() {
    6681         global $invites_template;
    6682 
    6683         return $invites_template->invites();
    6684 }
    6685 
    6686 /**
    6687  * @since 1.1.0
    6688  *
    6689  * @return mixed
    6690  */
    6691 function bp_group_the_invite() {
    6692         global $invites_template;
    6693 
    6694         return $invites_template->the_invite();
    6695 }
    6696 
    6697 /**
    6698  * @since 1.1.0
    6699  */
    6700 function bp_group_invite_item_id() {
    6701         echo bp_get_group_invite_item_id();
    6702 }
    6703 
    6704         /**
    6705          * @since 1.1.0
    6706          *
    6707          * @return mixed|void
    6708          */
    6709         function bp_get_group_invite_item_id() {
    6710                 global $invites_template;
    6711 
    6712                 /**
    6713                  * Filters the group invite item ID.
    6714                  *
    6715                  * @since 1.1.0
    6716                  *
    6717                  * @param string $value Group invite item ID.
    6718                  */
    6719                 return apply_filters( 'bp_get_group_invite_item_id', 'uid-' . $invites_template->invite->user->id );
    6720         }
    6721 
    6722 /**
    6723  * @since 1.1.0
    6724  */
    6725 function bp_group_invite_user_avatar() {
    6726         echo bp_get_group_invite_user_avatar();
    6727 }
    6728 
    6729         /**
    6730          * @since 1.1.0
    6731          *
    6732          * @return mixed|void
    6733          */
    6734         function bp_get_group_invite_user_avatar() {
    6735                 global $invites_template;
    6736 
    6737                 /**
    6738                  * Filters the group invite user avatar.
    6739                  *
    6740                  * @since 1.1.0
    6741                  *
    6742                  * @param string $value Group invite user avatar.
    6743                  */
    6744                 return apply_filters( 'bp_get_group_invite_user_avatar', $invites_template->invite->user->avatar_thumb );
    6745         }
    6746 
    6747 /**
    6748  * @since 1.1.0
    6749  */
    6750 function bp_group_invite_user_link() {
    6751         echo bp_get_group_invite_user_link();
    6752 }
    6753 
    6754         /**
    6755          * @since 1.1.0
    6756          *
    6757          * @return mixed|void
    6758          */
    6759         function bp_get_group_invite_user_link() {
    6760                 global $invites_template;
    6761 
    6762                 /**
    6763                  * Filters the group invite user link.
    6764                  *
    6765                  * @since 1.1.0
    6766                  *
    6767                  * @param string $value Group invite user link.
    6768                  */
    6769                 return apply_filters( 'bp_get_group_invite_user_link', bp_core_get_userlink( $invites_template->invite->user->id ) );
    6770         }
    6771 
    6772 /**
    6773  * @since 1.1.0
    6774  */
    6775 function bp_group_invite_user_last_active() {
    6776         echo bp_get_group_invite_user_last_active();
    6777 }
    6778 
    6779         /**
    6780          * @since 1.1.0
    6781          *
    6782          * @return mixed|void
    6783          */
    6784         function bp_get_group_invite_user_last_active() {
    6785                 global $invites_template;
    6786 
    6787                 /**
    6788                  * Filters the group invite user's last active time.
    6789                  *
    6790                  * @since 1.1.0
    6791                  *
    6792                  * @param string $value Group invite user's last active time.
    6793                  */
    6794                 return apply_filters( 'bp_get_group_invite_user_last_active', $invites_template->invite->user->last_active );
    6795         }
    6796 
    6797 /**
    6798  * @since 1.1.0
    6799  */
    6800 function bp_group_invite_user_remove_invite_url() {
    6801         echo bp_get_group_invite_user_remove_invite_url();
    6802 }
    6803 
    6804         /**
    6805          * @since 1.1.0
    6806          *
    6807          * @return string
    6808          */
    6809         function bp_get_group_invite_user_remove_invite_url() {
    6810                 global $invites_template;
    6811 
    6812                 $user_id = intval( $invites_template->invite->user->id );
    6813 
    6814                 if ( bp_is_current_action( 'create' ) ) {
    6815                         $uninvite_url = bp_get_groups_directory_permalink() . 'create/step/group-invites/?user_id=' . $user_id;
    6816                 } else {
    6817                         $uninvite_url = bp_get_group_permalink( groups_get_current_group() ) . 'send-invites/remove/' . $user_id;
    6818                 }
    6819 
    6820                 return wp_nonce_url( $uninvite_url, 'groups_invite_uninvite_user' );
    6821         }
    6822 
    6823 /**
    6824  * Output pagination links for group invitations.
    6825  *
    6826  * @since 2.0.0
    6827  */
    6828 function bp_group_invite_pagination_links() {
    6829         echo bp_get_group_invite_pagination_links();
    6830 }
    6831 
    6832         /**
    6833          * Get pagination links for group invitations.
    6834          *
    6835          * @since 2.0.0
    6836          *
    6837          * @return string
    6838          */
    6839         function bp_get_group_invite_pagination_links() {
    6840                 global $invites_template;
    6841 
    6842                 /**
    6843                  * Filters the pagination links for group invitations.
    6844                  *
    6845                  * @since 2.0.0
    6846                  *
    6847                  * @param string $value Pagination links for group invitations.
    6848                  */
    6849                 return apply_filters( 'bp_get_group_invite_pagination_links', $invites_template->pag_links );
    6850         }
    6851 
    6852 /**
    6853  * Output pagination count text for group invitations.
    6854  *
    6855  * @since 2.0.0
    6856  */
    6857 function bp_group_invite_pagination_count() {
    6858         echo bp_get_group_invite_pagination_count();
    6859 }
    6860         /**
    6861          * Get pagination count text for group invitations.
    6862          *
    6863          * @since 2.0.0
    6864          *
    6865          * @return string
    6866          */
    6867         function bp_get_group_invite_pagination_count() {
    6868                 global $invites_template;
    6869 
    6870                 $start_num = intval( ( $invites_template->pag_page - 1 ) * $invites_template->pag_num ) + 1;
    6871                 $from_num  = bp_core_number_format( $start_num );
    6872                 $to_num    = bp_core_number_format( ( $start_num + ( $invites_template->pag_num - 1 ) > $invites_template->total_invite_count ) ? $invites_template->total_invite_count : $start_num + ( $invites_template->pag_num - 1 ) );
    6873                 $total     = bp_core_number_format( $invites_template->total_invite_count );
    6874 
    6875                 if ( 1 == $invites_template->total_invite_count ) {
    6876                         $message = __( 'Viewing 1 invitation', 'buddypress' );
    6877                 } else {
    6878                         $message = sprintf( _n( 'Viewing %1$s - %2$s of %3$s invitation', 'Viewing %1$s - %2$s of %3$s invitations', $invites_template->total_invite_count, 'buddypress' ), $from_num, $to_num, $total );
    6879                 }
    6880 
    6881                 /** This filter is documented in bp-groups/bp-groups-template.php */
    6882                 return apply_filters( 'bp_get_groups_pagination_count', $message, $from_num, $to_num, $total );
    6883         }
    6884 
    6885 /** Group RSS *****************************************************************/
    6886 
    6887 /**
    6888  * Hook group activity feed to <head>.
    6889  *
    6890  * @since 1.5.0
    6891  */
    6892 function bp_groups_activity_feed() {
    6893 
    6894         // Bail if not viewing a single group or activity is not active.
    6895         if ( ! bp_is_active( 'groups' ) || ! bp_is_active( 'activity' ) || ! bp_is_group() ) {
    6896                 return;
    6897         } ?>
    6898 
    6899         <link rel="alternate" type="application/rss+xml" title="<?php bloginfo( 'name' ) ?> | <?php bp_current_group_name() ?> | <?php _e( 'Group Activity RSS Feed', 'buddypress' ) ?>" href="<?php bp_group_activity_feed_link() ?>" />
    6900 
    6901 <?php
    6902 }
    6903 add_action( 'bp_head', 'bp_groups_activity_feed' );
    6904 
    6905 /**
    6906  * Output the current group activity-stream RSS URL.
    6907  *
    6908  * @since 1.5.0
    6909  */
    6910 function bp_group_activity_feed_link() {
    6911         echo bp_get_group_activity_feed_link();
    6912 }
    6913         /**
    6914          * Return the current group activity-stream RSS URL.
    6915          *
    6916          * @since 1.5.0
    6917          *
    6918          * @return string
    6919          */
    6920         function bp_get_group_activity_feed_link() {
    6921                 $current_group = groups_get_current_group();
    6922                 $group_link    = bp_get_group_permalink( $current_group ) . 'feed';
    6923                 $feed_link     = trailingslashit( $group_link );
    6924 
    6925                 /**
    6926                  * Filters the current group activity-stream RSS URL.
    6927                  *
    6928                  * @since 1.2.0
    6929                  *
    6930                  * @param string $feed_link Current group activity-stream RSS URL.
    6931                  */
    6932                 return apply_filters( 'bp_get_group_activity_feed_link', $feed_link );
    6933         }
    6934 
    6935 /** Current Group *************************************************************/
    6936 
    6937 /**
    6938  * Echoes the output of bp_get_current_group_id().
    6939  *
    6940  * @since 1.5.0
    6941  */
    6942 function bp_current_group_id() {
    6943         echo bp_get_current_group_id();
    6944 }
    6945         /**
    6946          * Returns the ID of the current group.
    6947          *
    6948          * @since 1.5.0
    6949          * @uses apply_filters() Filter bp_get_current_group_id to modify this output.
    6950          *
    6951          * @return int $current_group_id The id of the current group, if there is one.
    6952          */
    6953         function bp_get_current_group_id() {
    6954                 $current_group    = groups_get_current_group();
    6955                 $current_group_id = isset( $current_group->id ) ? (int) $current_group->id : 0;
    6956 
    6957                 /**
    6958                  * Filters the ID of the current group.
    6959                  *
    6960                  * @since 1.5.0
    6961                  *
    6962                  * @param int    $current_group_id ID of the current group.
    6963                  * @param object $current_group    Instance holding the current group.
    6964                  */
    6965                 return apply_filters( 'bp_get_current_group_id', $current_group_id, $current_group );
    6966         }
    6967 
    6968 /**
    6969  * Echoes the output of bp_get_current_group_slug().
    6970  *
    6971  * @since 1.5.0
    6972  */
    6973 function bp_current_group_slug() {
    6974         echo bp_get_current_group_slug();
    6975 }
    6976         /**
    6977          * Returns the slug of the current group.
    6978          *
    6979          * @since 1.5.0
    6980          * @uses apply_filters() Filter bp_get_current_group_slug to modify this output.
    6981          *
    6982          * @return string $current_group_slug The slug of the current group, if there is one.
    6983          */
    6984         function bp_get_current_group_slug() {
    6985                 $current_group      = groups_get_current_group();
    6986                 $current_group_slug = isset( $current_group->slug ) ? $current_group->slug : '';
    6987 
    6988                 /**
    6989                  * Filters the slug of the current group.
    6990                  *
    6991                  * @since 1.5.0
    6992                  *
    6993                  * @param string $current_group_slug Slug of the current group.
    6994                  * @param object $current_group      Instance holding the current group.
    6995                  */
    6996                 return apply_filters( 'bp_get_current_group_slug', $current_group_slug, $current_group );
    6997         }
    6998 
    6999 /**
    7000  * Echoes the output of bp_get_current_group_name().
    7001  *
    7002  * @since 1.5.0
    7003  */
    7004 function bp_current_group_name() {
    7005         echo bp_get_current_group_name();
    7006 }
    7007         /**
    7008          * Returns the name of the current group.
    7009          *
    7010          * @since 1.5.0
    7011          * @uses apply_filters() Filter bp_get_current_group_name to modify this output.
    7012          *
    7013          * @return string The name of the current group, if there is one.
    7014          */
    7015         function bp_get_current_group_name() {
    7016                 $current_group      = groups_get_current_group();
    7017                 $current_group_name = isset( $current_group->name ) ? $current_group->name : '';
    7018 
    7019                 /** This filter is documented in bp-groups/bp-groups-template.php */
    7020                 $name               = apply_filters( 'bp_get_group_name', $current_group_name );
    7021 
    7022                 /**
    7023                  * Filters the name of the current group.
    7024                  *
    7025                  * @since 1.2.0
    7026                  *
    7027                  * @param string $name          Name of the current group.
    7028                  * @param object $current_group Instance holding the current group.
    7029                  */
    7030                 return apply_filters( 'bp_get_current_group_name', $name, $current_group );
    7031         }
    7032 
    7033 /**
    7034  * Echoes the output of bp_get_current_group_description().
    7035  *
    7036  * @since 2.1.0
    7037  */
    7038 function bp_current_group_description() {
    7039         echo bp_get_current_group_description();
    7040 }
    7041         /**
    7042          * Returns the description of the current group.
    7043          *
    7044          * @since 2.1.0
    7045          * @uses apply_filters() Filter bp_get_current_group_description to modify
    7046          *                       this output.
    7047          *
    7048          * @return string The description of the current group, if there is one.
    7049          */
    7050         function bp_get_current_group_description() {
    7051                 $current_group      = groups_get_current_group();
    7052                 $current_group_desc = isset( $current_group->description ) ? $current_group->description : '';
    7053 
    7054                 /**
    7055                  * Filters the description of the current group.
    7056                  *
    7057                  * This filter is used to apply extra filters related to formatting.
    7058                  *
    7059                  * @since 1.0.0
    7060                  *
    7061                  * @param string $current_group_desc Description of the current group.
    7062                  */
    7063                 $desc               = apply_filters( 'bp_get_group_description', $current_group_desc );
    7064 
    7065                 /**
    7066                  * Filters the description of the current group.
    7067                  *
    7068                  * @since 2.1.0
    7069                  *
    7070                  * @param string $desc Description of the current group.
    7071                  */
    7072                 return apply_filters( 'bp_get_current_group_description', $desc );
    7073         }
    7074 
    7075 /**
    7076  * Output a URL for a group component action.
    7077  *
    7078  * @since 1.2.0
    7079  *
    7080  * @param string $action
    7081  * @param string $query_args
    7082  * @param bool $nonce
    7083  * @return string
    7084  */
    7085 function bp_groups_action_link( $action = '', $query_args = '', $nonce = false ) {
    7086         echo bp_get_groups_action_link( $action, $query_args, $nonce );
    7087 }
    7088         /**
    7089          * Get a URL for a group component action.
    7090          *
    7091          * @since 1.2.0
    7092          *
    7093          * @param string $action
    7094          * @param string $query_args
    7095          * @param bool $nonce
    7096          * @return string
    7097          */
    7098         function bp_get_groups_action_link( $action = '', $query_args = '', $nonce = false ) {
    7099 
    7100                 $current_group = groups_get_current_group();
    7101                 $url           = '';
    7102 
    7103                 // Must be a group.
    7104                 if ( ! empty( $current_group->id ) ) {
    7105 
    7106                         // Append $action to $url if provided
    7107                         if ( !empty( $action ) ) {
    7108                                 $url = bp_get_group_permalink( $current_group ) . $action;
    7109                         } else {
    7110                                 $url = bp_get_group_permalink( $current_group );
    7111                         }
    7112 
    7113                         // Add a slash at the end of our user url.
    7114                         $url = trailingslashit( $url );
    7115 
    7116                         // Add possible query args.
    7117                         if ( !empty( $query_args ) && is_array( $query_args ) ) {
    7118                                 $url = add_query_arg( $query_args, $url );
    7119                         }
    7120 
    7121                         // To nonce, or not to nonce...
    7122                         if ( true === $nonce ) {
    7123                                 $url = wp_nonce_url( $url );
    7124                         } elseif ( is_string( $nonce ) ) {
    7125                                 $url = wp_nonce_url( $url, $nonce );
    7126                         }
    7127                 }
    7128 
    7129                 /**
    7130                  * Filters a URL for a group component action.
    7131                  *
    7132                  * @since 2.1.0
    7133                  *
    7134                  * @param string $url        URL for a group component action.
    7135                  * @param string $action     Action being taken for the group.
    7136                  * @param string $query_args Query arguments being passed.
    7137                  * @param bool   $nonce      Whether or not to add a nonce.
    7138                  */
    7139                 return apply_filters( 'bp_get_groups_action_link', $url, $action, $query_args, $nonce );
    7140         }
    7141 
    7142 /** Stats **********************************************************************/
    7143 
    7144 /**
    7145  * Display the number of groups in user's profile.
    7146  *
    7147  * @since 2.0.0
    7148  *
    7149  * @param array|string $args before|after|user_id
    7150  *
    7151  * @uses bp_groups_get_profile_stats() to get the stats.
    7152  */
    7153 function bp_groups_profile_stats( $args = '' ) {
    7154         echo bp_groups_get_profile_stats( $args );
    7155 }
    7156 add_action( 'bp_members_admin_user_stats', 'bp_groups_profile_stats', 8, 1 );
    7157 
    7158 /**
    7159  * Return the number of groups in user's profile.
    7160  *
    7161  * @since 2.0.0
    7162  *
    7163  * @param array|string $args before|after|user_id
    7164  * @return string HTML for stats output.
    7165  */
    7166 function bp_groups_get_profile_stats( $args = '' ) {
    7167 
    7168         // Parse the args
    7169         $r = bp_parse_args( $args, array(
    7170                 'before'  => '<li class="bp-groups-profile-stats">',
    7171                 'after'   => '</li>',
    7172                 'user_id' => bp_displayed_user_id(),
    7173                 'groups'  => 0,
    7174                 'output'  => ''
    7175         ), 'groups_get_profile_stats' );
    7176 
    7177         // Allow completely overloaded output
    7178         if ( empty( $r['output'] ) ) {
    7179 
    7180                 // Only proceed if a user ID was passed
    7181                 if ( ! empty( $r['user_id'] ) ) {
    7182 
    7183                         // Get the user groups
    7184                         if ( empty( $r['groups'] ) ) {
    7185                                 $r['groups'] = absint( bp_get_total_group_count_for_user( $r['user_id'] ) );
    7186                         }
    7187 
    7188                         // If groups exist, show some formatted output
    7189                         $r['output'] = $r['before'] . sprintf( _n( '%s group', '%s groups', $r['groups'], 'buddypress' ), '<strong>' . $r['groups'] . '</strong>' ) . $r['after'];
    7190                 }
    7191         }
    7192 
    7193         /**
    7194          * Filters the number of groups in user's profile.
    7195          *
    7196          * @since 2.0.0
    7197          *
    7198          * @param string $value HTML for stats output.
    7199          * @param array  $r     Array of parsed arguments for query.
    7200          */
    7201         return apply_filters( 'bp_groups_get_profile_stats', $r['output'], $r );
    7202 }
Note: See TracChangeset for help on using the changeset viewer.