Skip to:
Content

BuddyPress.org

Changeset 10520


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

Move bp-groups classes to their own files.

See #6870.

Location:
trunk/src/bp-groups
Files:
5 edited
8 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/bp-groups-admin.php

    r10462 r10520  
    1616// Include WP's list table class.
    1717if ( !class_exists( 'WP_List_Table' ) ) require( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
     18
     19require dirname( __FILE__ ) . '/classes/class-bp-groups-list-table.php';
    1820
    1921// The per_page screen option. Has to be hooked in extremely early.
     
    11261128}
    11271129add_action( 'wp_ajax_bp_group_admin_member_autocomplete', 'bp_groups_admin_autocomplete_handler' );
    1128 
    1129 /**
    1130  * List table class for the Groups component admin page.
    1131  *
    1132  * @since 1.7.0
    1133  */
    1134 class BP_Groups_List_Table extends WP_List_Table {
    1135 
    1136     /**
    1137      * The type of view currently being displayed.
    1138      *
    1139      * E.g. "All", "Pending", "Approved", "Spam"...
    1140      *
    1141      * @since 1.7.0
    1142      * @var string
    1143      */
    1144     public $view = 'all';
    1145 
    1146     /**
    1147      * Group counts for each group type.
    1148      *
    1149      * @since 1.7.0
    1150      * @var int
    1151      */
    1152     public $group_counts = 0;
    1153 
    1154     /**
    1155      * Multidimensional array of group visibility types and their groups.
    1156      *
    1157      * @link https://buddypress.trac.wordpress.org/ticket/6277
    1158      * @var array
    1159      */
    1160     public $group_type_ids = array();
    1161 
    1162     /**
    1163      * Constructor
    1164      *
    1165      * @since 1.7.0
    1166      */
    1167     public function __construct() {
    1168 
    1169         // Define singular and plural labels, as well as whether we support AJAX.
    1170         parent::__construct( array(
    1171             'ajax'     => false,
    1172             'plural'   => 'groups',
    1173             'singular' => 'group',
    1174         ) );
    1175     }
    1176 
    1177     /**
    1178      * Set up items for display in the list table.
    1179      *
    1180      * Handles filtering of data, sorting, pagination, and any other data
    1181      * manipulation required prior to rendering.
    1182      *
    1183      * @since 1.7.0
    1184      */
    1185     public function prepare_items() {
    1186         global $groups_template;
    1187 
    1188         $screen = get_current_screen();
    1189 
    1190         // Option defaults.
    1191         $include_id   = false;
    1192         $search_terms = false;
    1193 
    1194         // Set current page.
    1195         $page = $this->get_pagenum();
    1196 
    1197         // Set per page from the screen options.
    1198         $per_page = $this->get_items_per_page( str_replace( '-', '_', "{$screen->id}_per_page" ) );
    1199 
    1200         // Sort order.
    1201         $order = 'DESC';
    1202         if ( !empty( $_REQUEST['order'] ) ) {
    1203             $order = ( 'desc' == strtolower( $_REQUEST['order'] ) ) ? 'DESC' : 'ASC';
    1204         }
    1205 
    1206         // Order by - default to newest.
    1207         $orderby = 'last_activity';
    1208         if ( ! empty( $_REQUEST['orderby'] ) ) {
    1209             switch ( $_REQUEST['orderby'] ) {
    1210                 case 'name' :
    1211                     $orderby = 'name';
    1212                     break;
    1213                 case 'id' :
    1214                     $orderby = 'date_created';
    1215                     break;
    1216                 case 'members' :
    1217                     $orderby = 'total_member_count';
    1218                     break;
    1219                 case 'last_active' :
    1220                     $orderby = 'last_activity';
    1221                     break;
    1222             }
    1223         }
    1224 
    1225         // Are we doing a search?
    1226         if ( !empty( $_REQUEST['s'] ) )
    1227             $search_terms = $_REQUEST['s'];
    1228 
    1229         // Check if user has clicked on a specific group (if so, fetch only that group).
    1230         if ( !empty( $_REQUEST['gid'] ) )
    1231             $include_id = (int) $_REQUEST['gid'];
    1232 
    1233         // Set the current view.
    1234         if ( isset( $_GET['group_status'] ) && in_array( $_GET['group_status'], array( 'public', 'private', 'hidden' ) ) ) {
    1235             $this->view = $_GET['group_status'];
    1236         }
    1237 
    1238         // We'll use the ids of group types for the 'include' param.
    1239         $this->group_type_ids = BP_Groups_Group::get_group_type_ids();
    1240 
    1241         // Pass a dummy array if there are no groups of this type.
    1242         $include = false;
    1243         if ( 'all' != $this->view && isset( $this->group_type_ids[ $this->view ] ) ) {
    1244             $include = ! empty( $this->group_type_ids[ $this->view ] ) ? $this->group_type_ids[ $this->view ] : array( 0 );
    1245         }
    1246 
    1247         // Get group type counts for display in the filter tabs.
    1248         $this->group_counts = array();
    1249         foreach ( $this->group_type_ids as $group_type => $group_ids ) {
    1250             $this->group_counts[ $group_type ] = count( $group_ids );
    1251         }
    1252 
    1253         // If we're viewing a specific group, flatten all activities into a single array.
    1254         if ( $include_id ) {
    1255             $groups = array( (array) groups_get_group( 'group_id=' . $include_id ) );
    1256         } else {
    1257             $groups_args = array(
    1258                 'include'  => $include,
    1259                 'per_page' => $per_page,
    1260                 'page'     => $page,
    1261                 'orderby'  => $orderby,
    1262                 'order'    => $order
    1263             );
    1264 
    1265             $groups = array();
    1266             if ( bp_has_groups( $groups_args ) ) {
    1267                 while ( bp_groups() ) {
    1268                     bp_the_group();
    1269                     $groups[] = (array) $groups_template->group;
    1270                 }
    1271             }
    1272         }
    1273 
    1274         // Set raw data to display.
    1275         $this->items = $groups;
    1276 
    1277         // Store information needed for handling table pagination.
    1278         $this->set_pagination_args( array(
    1279             'per_page'    => $per_page,
    1280             'total_items' => $groups_template->total_group_count,
    1281             'total_pages' => ceil( $groups_template->total_group_count / $per_page )
    1282         ) );
    1283     }
    1284 
    1285     /**
    1286      * Get an array of all the columns on the page.
    1287      *
    1288      * @since 1.7.0
    1289      *
    1290      * @return array Array of column headers.
    1291      */
    1292     public function get_column_info() {
    1293         $this->_column_headers = array(
    1294             $this->get_columns(),
    1295             array(),
    1296             $this->get_sortable_columns(),
    1297             $this->get_default_primary_column_name(),
    1298         );
    1299 
    1300         return $this->_column_headers;
    1301     }
    1302 
    1303     /**
    1304      * Get name of default primary column
    1305      *
    1306      * @since 2.3.3
    1307      *
    1308      * @return string
    1309      */
    1310     protected function get_default_primary_column_name() {
    1311         // Comment column is mapped to Group's name.
    1312         return 'comment';
    1313     }
    1314 
    1315     /**
    1316      * Display a message on screen when no items are found ("No groups found").
    1317      *
    1318      * @since 1.7.0
    1319      */
    1320     public function no_items() {
    1321         _e( 'No groups found.', 'buddypress' );
    1322     }
    1323 
    1324     /**
    1325      * Output the Groups data table.
    1326      *
    1327      * @since 1.7.0
    1328      */
    1329     public function display() {
    1330         $this->display_tablenav( 'top' ); ?>
    1331 
    1332         <h2 class="screen-reader-text"><?php _e( 'Groups list', 'buddypress' ); ?></h2>
    1333 
    1334         <table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>" cellspacing="0">
    1335             <thead>
    1336                 <tr>
    1337                     <?php $this->print_column_headers(); ?>
    1338                 </tr>
    1339             </thead>
    1340 
    1341             <tfoot>
    1342                 <tr>
    1343                     <?php $this->print_column_headers( false ); ?>
    1344                 </tr>
    1345             </tfoot>
    1346 
    1347             <tbody id="the-comment-list">
    1348                 <?php $this->display_rows_or_placeholder(); ?>
    1349             </tbody>
    1350         </table>
    1351         <?php
    1352 
    1353         $this->display_tablenav( 'bottom' );
    1354     }
    1355 
    1356     /**
    1357      * Generate content for a single row of the table.
    1358      *
    1359      * @since 1.7.0
    1360      *
    1361      * @param object|array $item The current group item in the loop.
    1362      */
    1363     public function single_row( $item = array() ) {
    1364         static $even = false;
    1365 
    1366         $row_classes = array();
    1367 
    1368         if ( $even ) {
    1369             $row_classes = array( 'even' );
    1370         } else {
    1371             $row_classes = array( 'alternate', 'odd' );
    1372         }
    1373 
    1374         /**
    1375          * Filters the classes applied to a single row in the groups list table.
    1376          *
    1377          * @since 1.9.0
    1378          *
    1379          * @param array  $row_classes Array of classes to apply to the row.
    1380          * @param string $value       ID of the current group being displayed.
    1381          */
    1382         $row_classes = apply_filters( 'bp_groups_admin_row_class', $row_classes, $item['id'] );
    1383         $row_class = ' class="' . implode( ' ', $row_classes ) . '"';
    1384 
    1385         echo '<tr' . $row_class . ' id="group-' . esc_attr( $item['id'] ) . '" data-parent_id="' . esc_attr( $item['id'] ) . '" data-root_id="' . esc_attr( $item['id'] ) . '">';
    1386         echo $this->single_row_columns( $item );
    1387         echo '</tr>';
    1388 
    1389         $even = ! $even;
    1390     }
    1391 
    1392     /**
    1393      * Get the list of views available on this table (e.g. "all", "public").
    1394      *
    1395      * @since 1.7.0
    1396      */
    1397     public function get_views() {
    1398         $url_base = bp_get_admin_url( 'admin.php?page=bp-groups' ); ?>
    1399 
    1400         <h2 class="screen-reader-text"><?php _e( 'Filter groups list', 'buddypress' ); ?></h2>
    1401 
    1402         <ul class="subsubsub">
    1403             <li class="all"><a href="<?php echo esc_url( $url_base ); ?>" class="<?php if ( 'all' == $this->view ) echo 'current'; ?>"><?php _e( 'All', 'buddypress' ); ?></a> |</li>
    1404             <li class="public"><a href="<?php echo esc_url( add_query_arg( 'group_status', 'public', $url_base ) ); ?>" class="<?php if ( 'public' == $this->view ) echo 'current'; ?>"><?php printf( _n( 'Public <span class="count">(%s)</span>', 'Public <span class="count">(%s)</span>', $this->group_counts['public'], 'buddypress' ), number_format_i18n( $this->group_counts['public'] ) ); ?></a> |</li>
    1405             <li class="private"><a href="<?php echo esc_url( add_query_arg( 'group_status', 'private', $url_base ) ); ?>" class="<?php if ( 'private' == $this->view ) echo 'current'; ?>"><?php printf( _n( 'Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>', $this->group_counts['private'], 'buddypress' ), number_format_i18n( $this->group_counts['private'] ) ); ?></a> |</li>
    1406             <li class="hidden"><a href="<?php echo esc_url( add_query_arg( 'group_status', 'hidden', $url_base ) ); ?>" class="<?php if ( 'hidden' == $this->view ) echo 'current'; ?>"><?php printf( _n( 'Hidden <span class="count">(%s)</span>', 'Hidden <span class="count">(%s)</span>', $this->group_counts['hidden'], 'buddypress' ), number_format_i18n( $this->group_counts['hidden'] ) ); ?></a></li>
    1407 
    1408             <?php
    1409 
    1410             /**
    1411              * Fires inside listing of views so plugins can add their own.
    1412              *
    1413              * @since 1.7.0
    1414              *
    1415              * @param string $url_base Current URL base for view.
    1416              * @param string $view     Current view being displayed.
    1417              */
    1418             do_action( 'bp_groups_list_table_get_views', $url_base, $this->view ); ?>
    1419         </ul>
    1420     <?php
    1421     }
    1422 
    1423     /**
    1424      * Get bulk actions for single group row.
    1425      *
    1426      * @since 1.7.0
    1427      *
    1428      * @return array Key/value pairs for the bulk actions dropdown.
    1429      */
    1430     public function get_bulk_actions() {
    1431 
    1432         /**
    1433          * Filters the list of bulk actions to display on a single group row.
    1434          *
    1435          * @since 1.7.0
    1436          *
    1437          * @param array $value Array of bulk actions to display.
    1438          */
    1439         return apply_filters( 'bp_groups_list_table_get_bulk_actions', array(
    1440             'delete' => __( 'Delete', 'buddypress' )
    1441         ) );
    1442     }
    1443 
    1444     /**
    1445      * Get the table column titles.
    1446      *
    1447      * @since 1.7.0
    1448      *
    1449      * @see WP_List_Table::single_row_columns()
    1450      *
    1451      * @return array Array of column titles.
    1452      */
    1453     public function get_columns() {
    1454 
    1455         /**
    1456          * Filters the titles for the columns for the groups list table.
    1457          *
    1458          * @since 2.0.0
    1459          *
    1460          * @param array $value Array of slugs and titles for the columns.
    1461          */
    1462         return apply_filters( 'bp_groups_list_table_get_columns', array(
    1463             'cb'          => '<input name type="checkbox" />',
    1464             'comment'     => _x( 'Name', 'Groups admin Group Name column header',               'buddypress' ),
    1465             'description' => _x( 'Description', 'Groups admin Group Description column header', 'buddypress' ),
    1466             'status'      => _x( 'Status', 'Groups admin Privacy Status column header',         'buddypress' ),
    1467             'members'     => _x( '# Members', 'Groups admin Members column header',             'buddypress' ),
    1468             'last_active' => _x( 'Last Active', 'Groups admin Last Active column header',       'buddypress' )
    1469         ) );
    1470     }
    1471 
    1472     /**
    1473      * Get the column names for sortable columns.
    1474      *
    1475      * Note: It's not documented in WP, but the second item in the
    1476      * nested arrays below is $desc_first. Normally, we would set
    1477      * last_active to be desc_first (since you're generally interested in
    1478      * the *most* recently active group, not the *least*). But because
    1479      * the default sort for the Groups admin screen is DESC by last_active,
    1480      * we want the first click on the Last Active column header to switch
    1481      * the sort order - ie, to make it ASC. Thus last_active is set to
    1482      * $desc_first = false.
    1483      *
    1484      * @since 1.7.0
    1485      *
    1486      * @return array Array of sortable column names.
    1487      */
    1488     public function get_sortable_columns() {
    1489         return array(
    1490             'gid'         => array( 'gid', false ),
    1491             'comment'     => array( 'name', false ),
    1492             'members'     => array( 'members', false ),
    1493             'last_active' => array( 'last_active', false ),
    1494         );
    1495     }
    1496 
    1497     /**
    1498      * Override WP_List_Table::row_actions().
    1499      *
    1500      * Basically a duplicate of the row_actions() method, but removes the
    1501      * unnecessary <button> addition.
    1502      *
    1503      * @since 2.3.3
    1504      * @since 2.3.4 Visibility set to public for compatibility with WP < 4.0.0.
    1505      *
    1506      * @param array $actions        The list of actions.
    1507      * @param bool  $always_visible Whether the actions should be always visible.
    1508      * @return string
    1509      */
    1510     public function row_actions( $actions, $always_visible = false ) {
    1511         $action_count = count( $actions );
    1512         $i = 0;
    1513 
    1514         if ( !$action_count )
    1515             return '';
    1516 
    1517         $out = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">';
    1518         foreach ( $actions as $action => $link ) {
    1519             ++$i;
    1520             ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
    1521             $out .= "<span class='$action'>$link$sep</span>";
    1522         }
    1523         $out .= '</div>';
    1524 
    1525         return $out;
    1526     }
    1527 
    1528     /**
    1529      * Markup for the Checkbox column.
    1530      *
    1531      * @since 1.7.0
    1532      *
    1533      * @see WP_List_Table::single_row_columns()
    1534      *
    1535      * @param array $item A singular item (one full row).
    1536      */
    1537     public function column_cb( $item = array() ) {
    1538         printf( '<label class="screen-reader-text" for="gid-%1$d">' . __( 'Select group %1$d', 'buddypress' ) . '</label><input type="checkbox" name="gid[]" value="%1$d" id="gid-%1$d" />', $item['id'] );
    1539     }
    1540 
    1541     /**
    1542      * Markup for the Group ID column.
    1543      *
    1544      * @since 1.7.0
    1545      *
    1546      * @see WP_List_Table::single_row_columns()
    1547      *
    1548      * @param array $item A singular item (one full row).
    1549      */
    1550     public function column_gid( $item = array() ) {
    1551         echo '<strong>' . absint( $item['id'] ) . '</strong>';
    1552     }
    1553 
    1554     /**
    1555      * Name column, and "quick admin" rollover actions.
    1556      *
    1557      * Called "comment" in the CSS so we can re-use some WP core CSS.
    1558      *
    1559      * @since 1.7.0
    1560      *
    1561      * @see WP_List_Table::single_row_columns()
    1562      *
    1563      * @param array $item A singular item (one full row).
    1564      */
    1565     public function column_comment( $item = array() ) {
    1566 
    1567         // Preorder items: Edit | Delete | View.
    1568         $actions = array(
    1569             'edit'   => '',
    1570             'delete' => '',
    1571             'view'   => '',
    1572         );
    1573 
    1574         // We need the group object for some BP functions.
    1575         $item_obj = (object) $item;
    1576 
    1577         // Build actions URLs.
    1578         $base_url   = bp_get_admin_url( 'admin.php?page=bp-groups&amp;gid=' . $item['id'] );
    1579         $delete_url = wp_nonce_url( $base_url . "&amp;action=delete", 'bp-groups-delete' );
    1580         $edit_url   = $base_url . '&amp;action=edit';
    1581         $view_url   = bp_get_group_permalink( $item_obj );
    1582 
    1583         /**
    1584          * Filters the group name for a group's column content.
    1585          *
    1586          * @since 1.7.0
    1587          *
    1588          * @param string $value Name of the group being rendered.
    1589          * @param array  $item  Array for the current group item.
    1590          */
    1591         $group_name = apply_filters_ref_array( 'bp_get_group_name', array( $item['name'] ), $item );
    1592 
    1593         // Rollover actions.
    1594         // Edit.
    1595         $actions['edit']   = sprintf( '<a href="%s">%s</a>', esc_url( $edit_url   ), __( 'Edit',   'buddypress' ) );
    1596 
    1597         // Delete.
    1598         $actions['delete'] = sprintf( '<a href="%s">%s</a>', esc_url( $delete_url ), __( 'Delete', 'buddypress' ) );
    1599 
    1600         // Visit.
    1601         $actions['view']   = sprintf( '<a href="%s">%s</a>', esc_url( $view_url   ), __( 'View',   'buddypress' ) );
    1602 
    1603         /**
    1604          * Filters the actions that will be shown for the column content.
    1605          *
    1606          * @since 1.7.0
    1607          *
    1608          * @param array $value Array of actions to be displayed for the column content.
    1609          * @param array $item  The current group item in the loop.
    1610          */
    1611         $actions = apply_filters( 'bp_groups_admin_comment_row_actions', array_filter( $actions ), $item );
    1612 
    1613         // Get group name and avatar.
    1614         $avatar = '';
    1615 
    1616         if ( buddypress()->avatar->show_avatars ) {
    1617             $avatar  = bp_core_fetch_avatar( array(
    1618                 'item_id'    => $item['id'],
    1619                 'object'     => 'group',
    1620                 'type'       => 'thumb',
    1621                 'avatar_dir' => 'group-avatars',
    1622                 'alt'        => sprintf( __( 'Group logo of %s', 'buddypress' ), $group_name ),
    1623                 'width'      => '32',
    1624                 'height'     => '32',
    1625                 'title'      => $group_name
    1626             ) );
    1627         }
    1628 
    1629         $content = sprintf( '<strong><a href="%s">%s</a></strong>', esc_url( $edit_url ), $group_name );
    1630 
    1631         echo $avatar . ' ' . $content . ' ' . $this->row_actions( $actions );
    1632     }
    1633 
    1634     /**
    1635      * Markup for the Description column.
    1636      *
    1637      * @since 1.7.0
    1638      *
    1639      * @param array $item Information about the current row.
    1640      */
    1641     public function column_description( $item = array() ) {
    1642 
    1643         /**
    1644          * Filters the markup for the Description column.
    1645          *
    1646          * @since 1.0.0
    1647          *
    1648          * @param string $value Markup for the Description column.
    1649          * @param array  $item  The current group item in the loop.
    1650          */
    1651         echo apply_filters_ref_array( 'bp_get_group_description', array( $item['description'], $item ) );
    1652     }
    1653 
    1654     /**
    1655      * Markup for the Status column.
    1656      *
    1657      * @since 1.7.0
    1658      *
    1659      * @param array $item Information about the current row.
    1660      */
    1661     public function column_status( $item = array() ) {
    1662         $status      = $item['status'];
    1663         $status_desc = '';
    1664 
    1665         // @todo This should be abstracted out somewhere for the whole
    1666         // Groups component.
    1667         switch ( $status ) {
    1668             case 'public' :
    1669                 $status_desc = __( 'Public', 'buddypress' );
    1670                 break;
    1671             case 'private' :
    1672                 $status_desc = __( 'Private', 'buddypress' );
    1673                 break;
    1674             case 'hidden' :
    1675                 $status_desc = __( 'Hidden', 'buddypress' );
    1676                 break;
    1677         }
    1678 
    1679         /**
    1680          * Filters the markup for the Status column.
    1681          *
    1682          * @since 1.7.0
    1683          *
    1684          * @param string $status_desc Markup for the Status column.
    1685          * @parma array  $item        The current group item in the loop.
    1686          */
    1687         echo apply_filters_ref_array( 'bp_groups_admin_get_group_status', array( $status_desc, $item ) );
    1688     }
    1689 
    1690     /**
    1691      * Markup for the Number of Members column.
    1692      *
    1693      * @since 1.7.0
    1694      *
    1695      * @param array $item Information about the current row.
    1696      */
    1697     public function column_members( $item = array() ) {
    1698         $count = groups_get_groupmeta( $item['id'], 'total_member_count' );
    1699 
    1700         /**
    1701          * Filters the markup for the number of Members column.
    1702          *
    1703          * @since 1.7.0
    1704          *
    1705          * @param int   $count Markup for the number of Members column.
    1706          * @parma array $item  The current group item in the loop.
    1707          */
    1708         echo apply_filters_ref_array( 'bp_groups_admin_get_group_member_count', array( (int) $count, $item ) );
    1709     }
    1710 
    1711     /**
    1712      * Markup for the Last Active column.
    1713      *
    1714      * @since 1.7.0
    1715      *
    1716      * @param array $item Information about the current row.
    1717      */
    1718     public function column_last_active( $item = array() ) {
    1719         $last_active = groups_get_groupmeta( $item['id'], 'last_activity' );
    1720 
    1721         /**
    1722          * Filters the markup for the Last Active column.
    1723          *
    1724          * @since 1.7.0
    1725          *
    1726          * @param string $last_active Markup for the Last Active column.
    1727          * @parma array  $item        The current group item in the loop.
    1728          */
    1729         echo apply_filters_ref_array( 'bp_groups_admin_get_group_last_active', array( $last_active, $item ) );
    1730     }
    1731 
    1732     /**
    1733      * Allow plugins to add their custom column.
    1734      *
    1735      * @since 2.0.0
    1736      *
    1737      * @param array  $item        Information about the current row.
    1738      * @param string $column_name The column name.
    1739      * @return string
    1740      */
    1741     public function column_default( $item = array(), $column_name = '' ) {
    1742 
    1743         /**
    1744          * Filters a string to allow plugins to add custom column content.
    1745          *
    1746          * @since 2.0.0
    1747          *
    1748          * @param string $value       Empty string.
    1749          * @param string $column_name Name of the column being rendered.
    1750          * @param array  $item        The current group item in the loop.
    1751          */
    1752         return apply_filters( 'bp_groups_admin_get_group_custom_column', '', $column_name, $item );
    1753     }
    1754 }
  • trunk/src/bp-groups/bp-groups-loader.php

    r10454 r10520  
    1515defined( 'ABSPATH' ) || exit;
    1616
    17 /**
    18  * Creates our Groups component.
    19  *
    20  * @since 1.5.0
    21  */
    22 class BP_Groups_Component extends BP_Component {
    23 
    24     /**
    25      * Auto-join group when non group member performs group activity.
    26      *
    27      * @since 1.5.0
    28      * @var bool
    29      */
    30     public $auto_join;
    31 
    32     /**
    33      * The group being currently accessed.
    34      *
    35      * @since 1.5.0
    36      * @var BP_Groups_Group
    37      */
    38     public $current_group;
    39 
    40     /**
    41      * Default group extension.
    42      *
    43      * @since 1.6.0
    44      * @todo Is this used anywhere? Is this a duplicate of $default_extension?
    45      * @var string
    46      */
    47     var $default_component;
    48 
    49     /**
    50      * Default group extension.
    51      *
    52      * @since 1.6.0
    53      * @var string
    54      */
    55     public $default_extension;
    56 
    57     /**
    58      * Illegal group names/slugs.
    59      *
    60      * @since 1.5.0
    61      * @var array
    62      */
    63     public $forbidden_names;
    64 
    65     /**
    66      * Group creation/edit steps (e.g. Details, Settings, Avatar, Invites).
    67      *
    68      * @since 1.5.0
    69      * @var array
    70      */
    71     public $group_creation_steps;
    72 
    73     /**
    74      * Types of group statuses (Public, Private, Hidden).
    75      *
    76      * @since 1.5.0
    77      * @var array
    78      */
    79     public $valid_status;
    80 
    81     /**
    82      * Start the groups component creation process.
    83      *
    84      * @since 1.5.0
    85      */
    86     public function __construct() {
    87         parent::start(
    88             'groups',
    89             _x( 'User Groups', 'Group screen page <title>', 'buddypress' ),
    90             buddypress()->plugin_dir,
    91             array(
    92                 'adminbar_myaccount_order' => 70,
    93                 'search_query_arg' => 'groups_search',
    94             )
    95         );
    96     }
    97 
    98     /**
    99      * Include Groups component files.
    100      *
    101      * @since 1.5.0
    102      *
    103      * @see BP_Component::includes() for a description of arguments.
    104      *
    105      * @param array $includes See BP_Component::includes() for a description.
    106      */
    107     public function includes( $includes = array() ) {
    108         $includes = array(
    109             'cache',
    110             'forums',
    111             'actions',
    112             'filters',
    113             'screens',
    114             'classes',
    115             'widgets',
    116             'activity',
    117             'template',
    118             'adminbar',
    119             'functions',
    120             'notifications'
    121         );
    122 
    123         if ( is_admin() ) {
    124             $includes[] = 'admin';
    125         }
    126 
    127         parent::includes( $includes );
    128     }
    129 
    130     /**
    131      * Set up component global data.
    132      *
    133      * The BP_GROUPS_SLUG constant is deprecated, and only used here for
    134      * backwards compatibility.
    135      *
    136      * @since 1.5.0
    137      *
    138      * @see BP_Component::setup_globals() for a description of arguments.
    139      *
    140      * @param array $args See BP_Component::setup_globals() for a description.
    141      */
    142     public function setup_globals( $args = array() ) {
    143         $bp = buddypress();
    144 
    145         // Define a slug, if necessary.
    146         if ( ! defined( 'BP_GROUPS_SLUG' ) ) {
    147             define( 'BP_GROUPS_SLUG', $this->id );
    148         }
    149 
    150         // Global tables for groups component.
    151         $global_tables = array(
    152             'table_name'           => $bp->table_prefix . 'bp_groups',
    153             'table_name_members'   => $bp->table_prefix . 'bp_groups_members',
    154             'table_name_groupmeta' => $bp->table_prefix . 'bp_groups_groupmeta'
    155         );
    156 
    157         // Metadata tables for groups component.
    158         $meta_tables = array(
    159             'group' => $bp->table_prefix . 'bp_groups_groupmeta',
    160         );
    161 
    162         // All globals for groups component.
    163         // Note that global_tables is included in this array.
    164         $args = array(
    165             'slug'                  => BP_GROUPS_SLUG,
    166             'root_slug'             => isset( $bp->pages->groups->slug ) ? $bp->pages->groups->slug : BP_GROUPS_SLUG,
    167             'has_directory'         => true,
    168             'directory_title'       => _x( 'Groups', 'component directory title', 'buddypress' ),
    169             'notification_callback' => 'groups_format_notifications',
    170             'search_string'         => _x( 'Search Groups...', 'Component directory search', 'buddypress' ),
    171             'global_tables'         => $global_tables,
    172             'meta_tables'           => $meta_tables,
    173         );
    174 
    175         parent::setup_globals( $args );
    176 
    177         /* Single Group Globals **********************************************/
    178 
    179         // Are we viewing a single group?
    180         if ( bp_is_groups_component() && $group_id = BP_Groups_Group::group_exists( bp_current_action() ) ) {
    181 
    182             $bp->is_single_item  = true;
    183 
    184             /**
    185              * Filters the current PHP Class being used.
    186              *
    187              * @since 1.5.0
    188              *
    189              * @param string $value Name of the class being used.
    190              */
    191             $current_group_class = apply_filters( 'bp_groups_current_group_class', 'BP_Groups_Group' );
    192 
    193             if ( $current_group_class == 'BP_Groups_Group' ) {
    194                 $this->current_group = groups_get_group( array(
    195                     'group_id'        => $group_id,
    196                     'populate_extras' => true,
    197                 ) );
    198 
    199             } else {
    200 
    201                 /**
    202                  * Filters the current group object being instantiated from previous filter.
    203                  *
    204                  * @since 1.5.0
    205                  *
    206                  * @param object $value Newly instantiated object for the group.
    207                  */
    208                 $this->current_group = apply_filters( 'bp_groups_current_group_object', new $current_group_class( $group_id ) );
    209             }
    210 
    211             // When in a single group, the first action is bumped down one because of the
    212             // group name, so we need to adjust this and set the group name to current_item.
    213             $bp->current_item   = bp_current_action();
    214             $bp->current_action = bp_action_variable( 0 );
    215             array_shift( $bp->action_variables );
    216 
    217             // Using "item" not "group" for generic support in other components.
    218             if ( bp_current_user_can( 'bp_moderate' ) ) {
    219                 bp_update_is_item_admin( true, 'groups' );
    220             } else {
    221                 bp_update_is_item_admin( groups_is_user_admin( bp_loggedin_user_id(), $this->current_group->id ), 'groups' );
    222             }
    223 
    224             // If the user is not an admin, check if they are a moderator.
    225             if ( ! bp_is_item_admin() ) {
    226                 bp_update_is_item_mod  ( groups_is_user_mod  ( bp_loggedin_user_id(), $this->current_group->id ), 'groups' );
    227             }
    228 
    229             // Is the logged in user a member of the group?
    230             if ( ( is_user_logged_in() && groups_is_user_member( bp_loggedin_user_id(), $this->current_group->id ) ) ) {
    231                 $this->current_group->is_user_member = true;
    232             } else {
    233                 $this->current_group->is_user_member = false;
    234             }
    235 
    236             // Should this group be visible to the logged in user?
    237             if ( 'public' == $this->current_group->status || $this->current_group->is_user_member ) {
    238                 $this->current_group->is_visible = true;
    239             } else {
    240                 $this->current_group->is_visible = false;
    241             }
    242 
    243             // If this is a private or hidden group, does the user have access?
    244             if ( 'private' == $this->current_group->status || 'hidden' == $this->current_group->status ) {
    245                 if ( $this->current_group->is_user_member && is_user_logged_in() || bp_current_user_can( 'bp_moderate' ) ) {
    246                     $this->current_group->user_has_access = true;
    247                 } else {
    248                     $this->current_group->user_has_access = false;
    249                 }
    250             } else {
    251                 $this->current_group->user_has_access = true;
    252             }
    253 
    254             // Check once if the current group has a custom front template.
    255             $this->current_group->front_template = bp_groups_get_front_template( $this->current_group );
    256 
    257         // Set current_group to 0 to prevent debug errors.
    258         } else {
    259             $this->current_group = 0;
    260         }
    261 
    262         /**
    263          * Filters the list of illegal groups names/slugs.
    264          *
    265          * @since 1.0.0
    266          *
    267          * @param array $value Array of illegal group names/slugs.
    268          */
    269         $this->forbidden_names = apply_filters( 'groups_forbidden_names', array(
    270             'my-groups',
    271             'create',
    272             'invites',
    273             'send-invites',
    274             'forum',
    275             'delete',
    276             'add',
    277             'admin',
    278             'request-membership',
    279             'members',
    280             'settings',
    281             'avatar',
    282             $this->slug,
    283             $this->root_slug,
    284         ) );
    285 
    286         // If the user was attempting to access a group, but no group by that name was found, 404.
    287         if ( bp_is_groups_component() && empty( $this->current_group ) && bp_current_action() && !in_array( bp_current_action(), $this->forbidden_names ) ) {
    288             bp_do_404();
    289             return;
    290         }
    291 
    292         /**
    293          * Filters the preconfigured groups creation steps.
    294          *
    295          * @since 1.1.0
    296          *
    297          * @param array $value Array of preconfigured group creation steps.
    298          */
    299         $this->group_creation_steps = apply_filters( 'groups_create_group_steps', array(
    300             'group-details'  => array(
    301                 'name'       => _x( 'Details', 'Group screen nav', 'buddypress' ),
    302                 'position'   => 0
    303             ),
    304             'group-settings' => array(
    305                 'name'       => _x( 'Settings', 'Group screen nav', 'buddypress' ),
    306                 'position'   => 10
    307             )
    308         ) );
    309 
    310         // If avatar uploads are not disabled, add avatar option.
    311         $disabled_avatar_uploads = (int) bp_disable_group_avatar_uploads();
    312         if ( ! $disabled_avatar_uploads && $bp->avatar->show_avatars ) {
    313             $this->group_creation_steps['group-avatar'] = array(
    314                 'name'     => _x( 'Photo', 'Group screen nav', 'buddypress' ),
    315                 'position' => 20
    316             );
    317         }
    318 
    319         if ( bp_group_use_cover_image_header() ) {
    320             $this->group_creation_steps['group-cover-image'] = array(
    321                 'name'     => _x( 'Cover Image', 'Group screen nav', 'buddypress' ),
    322                 'position' => 25
    323             );
    324         }
    325 
    326         // If friends component is active, add invitations.
    327         if ( bp_is_active( 'friends' ) ) {
    328             $this->group_creation_steps['group-invites'] = array(
    329                 'name'     => _x( 'Invites',  'Group screen nav', 'buddypress' ),
    330                 'position' => 30
    331             );
    332         }
    333 
    334         /**
    335          * Filters the list of valid groups statuses.
    336          *
    337          * @since 1.1.0
    338          *
    339          * @param array $value Array of valid group statuses.
    340          */
    341         $this->valid_status = apply_filters( 'groups_valid_status', array(
    342             'public',
    343             'private',
    344             'hidden'
    345         ) );
    346 
    347         // Auto join group when non group member performs group activity.
    348         $this->auto_join = defined( 'BP_DISABLE_AUTO_GROUP_JOIN' ) && BP_DISABLE_AUTO_GROUP_JOIN ? false : true;
    349     }
    350 
    351     /**
    352      * Set up canonical stack for this component.
    353      *
    354      * @since 2.1.0
    355      */
    356     public function setup_canonical_stack() {
    357         if ( ! bp_is_groups_component() ) {
    358             return;
    359         }
    360 
    361         if ( empty( $this->current_group ) ) {
    362             return;
    363         }
    364 
    365         /**
    366          * Filters the default groups extension.
    367          *
    368          * @since 1.6.0
    369          *
    370          * @param string $value BP_GROUPS_DEFAULT_EXTENSION constant if defined,
    371          *                      else 'home'.
    372          */
    373         $this->default_extension = apply_filters( 'bp_groups_default_extension', defined( 'BP_GROUPS_DEFAULT_EXTENSION' ) ? BP_GROUPS_DEFAULT_EXTENSION : 'home' );
    374 
    375         $bp = buddypress();
    376 
    377         // If the activity component is not active and the current group has no custom front, members are displayed in the home nav.
    378         if ( 'members' === $this->default_extension && ! bp_is_active( 'activity' ) && ! $this->current_group->front_template ) {
    379             $this->default_extension = 'home';
    380         }
    381 
    382         if ( ! bp_current_action() ) {
    383             $bp->current_action = $this->default_extension;
    384         }
    385 
    386         // Prepare for a redirect to the canonical URL.
    387         $bp->canonical_stack['base_url'] = bp_get_group_permalink( $this->current_group );
    388 
    389         if ( bp_current_action() ) {
    390             $bp->canonical_stack['action'] = bp_current_action();
    391         }
    392 
    393         /**
    394          * If there's no custom front.php template for the group, we need to make sure the canonical stack action
    395          * is set to 'home' in these 2 cases:
    396          *
    397          * - the current action is 'activity' (eg: site.url/groups/single/activity) and the Activity component is active
    398          * - the current action is 'members' (eg: site.url/groups/single/members) and the Activity component is *not* active.
    399          */
    400         if ( ! $this->current_group->front_template && ( bp_is_current_action( 'activity' ) || ( ! bp_is_active( 'activity' ) && bp_is_current_action( 'members' ) ) ) ) {
    401             $bp->canonical_stack['action'] = 'home';
    402         }
    403 
    404         if ( ! empty( $bp->action_variables ) ) {
    405             $bp->canonical_stack['action_variables'] = bp_action_variables();
    406         }
    407 
    408         // When viewing the default extension, the canonical URL should not have
    409         // that extension's slug, unless more has been tacked onto the URL via
    410         // action variables.
    411         if ( bp_is_current_action( $this->default_extension ) && empty( $bp->action_variables ) )  {
    412             unset( $bp->canonical_stack['action'] );
    413         }
    414     }
    415 
    416     /**
    417      * Set up component navigation.
    418      *
    419      * @since 1.5.0
    420      *
    421      * @see BP_Component::setup_nav() for a description of arguments.
    422      *
    423      * @param array $main_nav Optional. See BP_Component::setup_nav() for description.
    424      * @param array $sub_nav  Optional. See BP_Component::setup_nav() for description.
    425      */
    426     public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
    427 
    428         // Determine user to use.
    429         if ( bp_displayed_user_domain() ) {
    430             $user_domain = bp_displayed_user_domain();
    431         } elseif ( bp_loggedin_user_domain() ) {
    432             $user_domain = bp_loggedin_user_domain();
    433         } else {
    434             $user_domain = false;
    435         }
    436 
    437         // Only grab count if we're on a user page.
    438         if ( bp_is_user() ) {
    439             $class    = ( 0 === groups_total_groups_for_user( bp_displayed_user_id() ) ) ? 'no-count' : 'count';
    440             $nav_name = sprintf( _x( 'Groups <span class="%s">%s</span>', 'Group screen nav with counter', 'buddypress' ), esc_attr( $class ), bp_get_total_group_count_for_user() );
    441         } else {
    442             $nav_name = _x( 'Groups', 'Group screen nav without counter', 'buddypress' );
    443         }
    444 
    445         $slug = bp_get_groups_slug();
    446 
    447         // Add 'Groups' to the main navigation.
    448         $main_nav = array(
    449             'name'                => $nav_name,
    450             'slug'                => $slug,
    451             'position'            => 70,
    452             'screen_function'     => 'groups_screen_my_groups',
    453             'default_subnav_slug' => 'my-groups',
    454             'item_css_id'         => $this->id
    455         );
    456 
    457         if ( ! empty( $user_domain ) ) {
    458             $access      = bp_core_can_edit_settings();
    459             $groups_link = trailingslashit( $user_domain . $slug );
    460 
    461             // Add the My Groups nav item.
    462             $sub_nav[] = array(
    463                 'name'            => __( 'Memberships', 'buddypress' ),
    464                 'slug'            => 'my-groups',
    465                 'parent_url'      => $groups_link,
    466                 'parent_slug'     => $slug,
    467                 'screen_function' => 'groups_screen_my_groups',
    468                 'position'        => 10,
    469                 'item_css_id'     => 'groups-my-groups'
    470             );
    471 
    472             // Add the Group Invites nav item.
    473             $sub_nav[] = array(
    474                 'name'            => __( 'Invitations', 'buddypress' ),
    475                 'slug'            => 'invites',
    476                 'parent_url'      => $groups_link,
    477                 'parent_slug'     => $slug,
    478                 'screen_function' => 'groups_screen_group_invites',
    479                 'user_has_access' => $access,
    480                 'position'        => 30
    481             );
    482 
    483             parent::setup_nav( $main_nav, $sub_nav );
    484         }
    485 
    486         if ( bp_is_groups_component() && bp_is_single_item() ) {
    487 
    488             // Reset sub nav.
    489             $sub_nav = array();
    490 
    491             // Add 'Groups' to the main navigation.
    492             $main_nav = array(
    493                 'name'                => __( 'Memberships', 'buddypress' ),
    494                 'slug'                => $this->current_group->slug,
    495                 'position'            => -1, // Do not show in BuddyBar.
    496                 'screen_function'     => 'groups_screen_group_home',
    497                 'default_subnav_slug' => $this->default_extension,
    498                 'item_css_id'         => $this->id
    499             );
    500 
    501             $group_link = bp_get_group_permalink( $this->current_group );
    502 
    503             // Add the "Home" subnav item, as this will always be present.
    504             $sub_nav[] = array(
    505                 'name'            =>  _x( 'Home', 'Group screen navigation title', 'buddypress' ),
    506                 'slug'            => 'home',
    507                 'parent_url'      => $group_link,
    508                 'parent_slug'     => $this->current_group->slug,
    509                 'screen_function' => 'groups_screen_group_home',
    510                 'position'        => 10,
    511                 'item_css_id'     => 'home'
    512             );
    513 
    514             // If this is a private group, and the user is not a
    515             // member and does not have an outstanding invitation,
    516             // show a "Request Membership" nav item.
    517             if ( is_user_logged_in() &&
    518                  ! $this->current_group->is_user_member &&
    519                  ! groups_check_for_membership_request( bp_loggedin_user_id(), $this->current_group->id ) &&
    520                  $this->current_group->status == 'private' &&
    521                  ! groups_check_user_has_invite( bp_loggedin_user_id(), $this->current_group->id )
    522                 ) {
    523 
    524                 $sub_nav[] = array(
    525                     'name'            => _x( 'Request Membership','Group screen nav', 'buddypress' ),
    526                     'slug'            => 'request-membership',
    527                     'parent_url'      => $group_link,
    528                     'parent_slug'     => $this->current_group->slug,
    529                     'screen_function' => 'groups_screen_group_request_membership',
    530                     'position'        => 30
    531                 );
    532             }
    533 
    534             // Forums are enabled and turned on.
    535             if ( $this->current_group->enable_forum && bp_is_active( 'forums' ) ) {
    536                 $sub_nav[] = array(
    537                     'name'            => _x( 'Forum', 'My Group screen nav', 'buddypress' ),
    538                     'slug'            => 'forum',
    539                     'parent_url'      => $group_link,
    540                     'parent_slug'     => $this->current_group->slug,
    541                     'screen_function' => 'groups_screen_group_forum',
    542                     'position'        => 40,
    543                     'user_has_access' => $this->current_group->user_has_access,
    544                     'item_css_id'     => 'forums'
    545                 );
    546             }
    547 
    548             if ( $this->current_group->front_template || bp_is_active( 'activity' ) ) {
    549                 /**
    550                  * If the theme is using a custom front, create activity subnav.
    551                  */
    552                 if ( $this->current_group->front_template && bp_is_active( 'activity' ) ) {
    553                     $sub_nav[] = array(
    554                         'name'            => _x( 'Activity', 'My Group screen nav', 'buddypress' ),
    555                         'slug'            => 'activity',
    556                         'parent_url'      => $group_link,
    557                         'parent_slug'     => $this->current_group->slug,
    558                         'screen_function' => 'groups_screen_group_activity',
    559                         'position'        => 11,
    560                         'user_has_access' => $this->current_group->user_has_access,
    561                         'item_css_id'     => 'activity',
    562                         'no_access_url'   => $group_link,
    563                     );
    564                 }
    565 
    566                 /**
    567                  * Only add the members subnav if it's not the home's nav.
    568                  */
    569                 $sub_nav[] = array(
    570                     'name'            => sprintf( _x( 'Members %s', 'My Group screen nav', 'buddypress' ), '<span>' . number_format( $this->current_group->total_member_count ) . '</span>' ),
    571                     'slug'            => 'members',
    572                     'parent_url'      => $group_link,
    573                     'parent_slug'     => $this->current_group->slug,
    574                     'screen_function' => 'groups_screen_group_members',
    575                     'position'        => 60,
    576                     'user_has_access' => $this->current_group->user_has_access,
    577                     'item_css_id'     => 'members',
    578                     'no_access_url'   => $group_link,
    579                 );
    580             }
    581 
    582             if ( bp_is_active( 'friends' ) && bp_groups_user_can_send_invites() ) {
    583                 $sub_nav[] = array(
    584                     'name'            => _x( 'Send Invites', 'My Group screen nav', 'buddypress' ),
    585                     'slug'            => 'send-invites',
    586                     'parent_url'      => $group_link,
    587                     'parent_slug'     => $this->current_group->slug,
    588                     'screen_function' => 'groups_screen_group_invite',
    589                     'item_css_id'     => 'invite',
    590                     'position'        => 70,
    591                     'user_has_access' => $this->current_group->user_has_access,
    592                     'no_access_url'   => $group_link,
    593                 );
    594             }
    595 
    596             // If the user is a group admin, then show the group admin nav item.
    597             if ( bp_is_item_admin() ) {
    598                 $sub_nav[] = array(
    599                     'name'            => _x( 'Manage', 'My Group screen nav', 'buddypress' ),
    600                     'slug'            => 'admin',
    601                     'parent_url'      => $group_link,
    602                     'parent_slug'     => $this->current_group->slug,
    603                     'screen_function' => 'groups_screen_group_admin',
    604                     'position'        => 1000,
    605                     'user_has_access' => true,
    606                     'item_css_id'     => 'admin',
    607                     'no_access_url'   => $group_link,
    608                 );
    609 
    610                 $admin_link = trailingslashit( $group_link . 'admin' );
    611 
    612                 // Common params to all nav items.
    613                 $default_params = array(
    614                     'parent_url'        => $admin_link,
    615                     'parent_slug'       => $this->current_group->slug . '_manage',
    616                     'screen_function'   => 'groups_screen_group_admin',
    617                     'user_has_access'   => bp_is_item_admin(),
    618                     'show_in_admin_bar' => true,
    619                 );
    620 
    621                 $sub_nav[] = array_merge( array(
    622                     'name'     => __( 'Details', 'buddypress' ),
    623                     'slug'     => 'edit-details',
    624                     'position' => 0,
    625                 ), $default_params );
    626 
    627                 $sub_nav[] = array_merge( array(
    628                     'name'     => __( 'Settings', 'buddypress' ),
    629                     'slug'     => 'group-settings',
    630                     'position' => 10,
    631                 ), $default_params );
    632 
    633                 if ( ! bp_disable_group_avatar_uploads() && buddypress()->avatar->show_avatars ) {
    634                     $sub_nav[] = array_merge( array(
    635                         'name'     => __( 'Photo', 'buddypress' ),
    636                         'slug'     => 'group-avatar',
    637                         'position' => 20,
    638                     ), $default_params );
    639                 }
    640 
    641                 if ( bp_group_use_cover_image_header() ) {
    642                     $sub_nav[] = array_merge( array(
    643                         'name'     => __( 'Cover Image', 'buddypress' ),
    644                         'slug'     => 'group-cover-image',
    645                         'position' => 25,
    646                     ), $default_params );
    647                 }
    648 
    649                 $sub_nav[] = array_merge( array(
    650                     'name'     => __( 'Members', 'buddypress' ),
    651                     'slug'     => 'manage-members',
    652                     'position' => 30,
    653                 ), $default_params );
    654 
    655                 if ( 'private' == $this->current_group->status ) {
    656                     $sub_nav[] = array_merge( array(
    657                         'name'     => __( 'Requests', 'buddypress' ),
    658                         'slug'     => 'membership-requests',
    659                         'position' => 40,
    660                     ), $default_params );
    661                 }
    662 
    663                 $sub_nav[] = array_merge( array(
    664                     'name'     => __( 'Delete', 'buddypress' ),
    665                     'slug'     => 'delete-group',
    666                     'position' => 1000,
    667                 ), $default_params );
    668             }
    669 
    670             parent::setup_nav( $main_nav, $sub_nav );
    671         }
    672 
    673         if ( isset( $this->current_group->user_has_access ) ) {
    674 
    675             /**
    676              * Fires at the end of the groups navigation setup if user has access.
    677              *
    678              * @since 1.0.2
    679              *
    680              * @param bool $user_has_access Whether or not user has access.
    681              */
    682             do_action( 'groups_setup_nav', $this->current_group->user_has_access );
    683         } else {
    684 
    685             /** This action is documented in bp-groups/bp-groups-loader.php */
    686             do_action( 'groups_setup_nav');
    687         }
    688     }
    689 
    690     /**
    691      * Set up the component entries in the WordPress Admin Bar.
    692      *
    693      * @since 1.5.0
    694      *
    695      * @see BP_Component::setup_nav() for a description of the $wp_admin_nav
    696      *      parameter array.
    697      *
    698      * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a description.
    699      */
    700     public function setup_admin_bar( $wp_admin_nav = array() ) {
    701 
    702         // Menus for logged in user.
    703         if ( is_user_logged_in() ) {
    704 
    705             // Setup the logged in user variables.
    706             $groups_link = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() );
    707 
    708             // Pending group invites.
    709             $count   = groups_get_invite_count_for_user();
    710             $title   = _x( 'Groups', 'My Account Groups', 'buddypress' );
    711             $pending = _x( 'No Pending Invites', 'My Account Groups sub nav', 'buddypress' );
    712 
    713             if ( ! empty( $count['total'] ) ) {
    714                 $title   = sprintf( _x( 'Groups <span class="count">%s</span>',          'My Account Groups nav',     'buddypress' ), bp_core_number_format( $count ) );
    715                 $pending = sprintf( _x( 'Pending Invites <span class="count">%s</span>', 'My Account Groups sub nav', 'buddypress' ), bp_core_number_format( $count ) );
    716             }
    717 
    718             // Add the "My Account" sub menus.
    719             $wp_admin_nav[] = array(
    720                 'parent' => buddypress()->my_account_menu_id,
    721                 'id'     => 'my-account-' . $this->id,
    722                 'title'  => $title,
    723                 'href'   => $groups_link
    724             );
    725 
    726             // My Groups.
    727             $wp_admin_nav[] = array(
    728                 'parent' => 'my-account-' . $this->id,
    729                 'id'     => 'my-account-' . $this->id . '-memberships',
    730                 'title'  => _x( 'Memberships', 'My Account Groups sub nav', 'buddypress' ),
    731                 'href'   => $groups_link
    732             );
    733 
    734             // Invitations.
    735             $wp_admin_nav[] = array(
    736                 'parent' => 'my-account-' . $this->id,
    737                 'id'     => 'my-account-' . $this->id . '-invites',
    738                 'title'  => $pending,
    739                 'href'   => trailingslashit( $groups_link . 'invites' )
    740             );
    741 
    742             // Create a Group.
    743             if ( bp_user_can_create_groups() ) {
    744                 $wp_admin_nav[] = array(
    745                     'parent' => 'my-account-' . $this->id,
    746                     'id'     => 'my-account-' . $this->id . '-create',
    747                     'title'  => _x( 'Create a Group', 'My Account Groups sub nav', 'buddypress' ),
    748                     'href'   => trailingslashit( bp_get_groups_directory_permalink() . 'create' )
    749                 );
    750             }
    751         }
    752 
    753         parent::setup_admin_bar( $wp_admin_nav );
    754     }
    755 
    756     /**
    757      * Set up the title for pages and <title>.
    758      *
    759      * @since 1.5.0
    760      */
    761     public function setup_title() {
    762 
    763         if ( bp_is_groups_component() ) {
    764             $bp = buddypress();
    765 
    766             if ( bp_is_my_profile() && !bp_is_single_item() ) {
    767                 $bp->bp_options_title = _x( 'Memberships', 'My Groups page <title>', 'buddypress' );
    768 
    769             } elseif ( !bp_is_my_profile() && !bp_is_single_item() ) {
    770                 $bp->bp_options_avatar = bp_core_fetch_avatar( array(
    771                     'item_id' => bp_displayed_user_id(),
    772                     'type'    => 'thumb',
    773                     'alt'     => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_get_displayed_user_fullname() )
    774                 ) );
    775                 $bp->bp_options_title = bp_get_displayed_user_fullname();
    776 
    777             // We are viewing a single group, so set up the
    778             // group navigation menu using the $this->current_group global.
    779             } elseif ( bp_is_single_item() ) {
    780                 $bp->bp_options_title  = $this->current_group->name;
    781                 $bp->bp_options_avatar = bp_core_fetch_avatar( array(
    782                     'item_id'    => $this->current_group->id,
    783                     'object'     => 'group',
    784                     'type'       => 'thumb',
    785                     'avatar_dir' => 'group-avatars',
    786                     'alt'        => __( 'Group Profile Photo', 'buddypress' )
    787                 ) );
    788 
    789                 if ( empty( $bp->bp_options_avatar ) ) {
    790                     $bp->bp_options_avatar = '<img src="' . esc_url( bp_core_avatar_default_thumb() ) . '" alt="' . esc_attr__( 'No Group Profile Photo', 'buddypress' ) . '" class="avatar" />';
    791                 }
    792             }
    793         }
    794 
    795         parent::setup_title();
    796     }
    797 
    798     /**
    799      * Setup cache groups
    800      *
    801      * @since 2.2.0
    802      */
    803     public function setup_cache_groups() {
    804 
    805         // Global groups.
    806         wp_cache_add_global_groups( array(
    807             'bp_groups',
    808             'bp_group_admins',
    809             'bp_group_invite_count',
    810             'group_meta'
    811         ) );
    812 
    813         parent::setup_cache_groups();
    814     }
    815 }
     17require dirname( __FILE__ ) . '/classes/class-bp-groups-component.php';
    81618
    81719/**
  • trunk/src/bp-groups/bp-groups-screens.php

    r10454 r10520  
    1414// Exit if accessed directly.
    1515defined( 'ABSPATH' ) || exit;
     16
     17require dirname( __FILE__ ) . '/classes/class-bp-groups-theme-compat.php';
    1618
    1719/**
     
    14761478/** Theme Compatibility *******************************************************/
    14771479
    1478 /**
    1479  * The main theme compat class for BuddyPress Groups.
    1480  *
    1481  * This class sets up the necessary theme compatibility actions to safely output
    1482  * group template parts to the_title and the_content areas of a theme.
    1483  *
    1484  * @since 1.7.0
    1485  */
    1486 class BP_Groups_Theme_Compat {
    1487 
    1488     /**
    1489      * Set up theme compatibility for the Groups component.
    1490      *
    1491      * @since 1.7.0
    1492      */
    1493     public function __construct() {
    1494         add_action( 'bp_setup_theme_compat', array( $this, 'is_group' ) );
    1495     }
    1496 
    1497     /**
    1498      * Are we looking at something that needs group theme compatibility?
    1499      *
    1500      * @since 1.7.0
    1501      */
    1502     public function is_group() {
    1503 
    1504         // Bail if not looking at a group.
    1505         if ( ! bp_is_groups_component() )
    1506             return;
    1507 
    1508         // Group Directory.
    1509         if ( ! bp_current_action() && ! bp_current_item() ) {
    1510             bp_update_is_directory( true, 'groups' );
    1511 
    1512             /**
    1513              * Fires at the start of the group theme compatibility setup.
    1514              *
    1515              * @since 1.1.0
    1516              */
    1517             do_action( 'groups_directory_groups_setup' );
    1518 
    1519             add_filter( 'bp_get_buddypress_template',                array( $this, 'directory_template_hierarchy' ) );
    1520             add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'directory_dummy_post' ) );
    1521             add_filter( 'bp_replace_the_content',                    array( $this, 'directory_content'    ) );
    1522 
    1523         // Creating a group.
    1524         } elseif ( bp_is_groups_component() && bp_is_current_action( 'create' ) ) {
    1525             add_filter( 'bp_get_buddypress_template',                array( $this, 'create_template_hierarchy' ) );
    1526             add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'create_dummy_post' ) );
    1527             add_filter( 'bp_replace_the_content',                    array( $this, 'create_content'    ) );
    1528 
    1529         // Group page.
    1530         } elseif ( bp_is_single_item() ) {
    1531             add_filter( 'bp_get_buddypress_template',                array( $this, 'single_template_hierarchy' ) );
    1532             add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'single_dummy_post' ) );
    1533             add_filter( 'bp_replace_the_content',                    array( $this, 'single_content'    ) );
    1534 
    1535         }
    1536     }
    1537 
    1538     /** Directory *********************************************************/
    1539 
    1540     /**
    1541      * Add template hierarchy to theme compat for the group directory page.
    1542      *
    1543      * This is to mirror how WordPress has
    1544      * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
    1545      *
    1546      * @since 1.8.0
    1547      *
    1548      * @param string $templates The templates from bp_get_theme_compat_templates().
    1549      * @return array $templates Array of custom templates to look for.
    1550      */
    1551     public function directory_template_hierarchy( $templates ) {
    1552 
    1553         /**
    1554          * Filters the Groups directory page template hierarchy based on priority.
    1555          *
    1556          * @since 1.8.0
    1557          *
    1558          * @param array $value Array of default template files to use.
    1559          */
    1560         $new_templates = apply_filters( 'bp_template_hierarchy_groups_directory', array(
    1561             'groups/index-directory.php'
    1562         ) );
    1563 
    1564         // Merge new templates with existing stack.
    1565         // @see bp_get_theme_compat_templates().
    1566         $templates = array_merge( (array) $new_templates, $templates );
    1567 
    1568         return $templates;
    1569     }
    1570 
    1571     /**
    1572      * Update the global $post with directory data.
    1573      *
    1574      * @since 1.7.0
    1575      */
    1576     public function directory_dummy_post() {
    1577         bp_theme_compat_reset_post( array(
    1578             'ID'             => 0,
    1579             'post_title'     => bp_get_directory_title( 'groups' ),
    1580             'post_author'    => 0,
    1581             'post_date'      => 0,
    1582             'post_content'   => '',
    1583             'post_type'      => 'page',
    1584             'post_status'    => 'publish',
    1585             'is_page'        => true,
    1586             'comment_status' => 'closed'
    1587         ) );
    1588     }
    1589 
    1590     /**
    1591      * Filter the_content with the groups index template part.
    1592      *
    1593      * @since 1.7.0
    1594      */
    1595     public function directory_content() {
    1596         return bp_buffer_template_part( 'groups/index', null, false );
    1597     }
    1598 
    1599     /** Create ************************************************************/
    1600 
    1601     /**
    1602      * Add custom template hierarchy to theme compat for the group create page.
    1603      *
    1604      * This is to mirror how WordPress has
    1605      * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
    1606      *
    1607      * @since 1.8.0
    1608      *
    1609      * @param string $templates The templates from bp_get_theme_compat_templates().
    1610      * @return array $templates Array of custom templates to look for.
    1611      */
    1612     public function create_template_hierarchy( $templates ) {
    1613 
    1614         /**
    1615          * Filters the Groups create page template hierarchy based on priority.
    1616          *
    1617          * @since 1.8.0
    1618          *
    1619          * @param array $value Array of default template files to use.
    1620          */
    1621         $new_templates = apply_filters( 'bp_template_hierarchy_groups_create', array(
    1622             'groups/index-create.php'
    1623         ) );
    1624 
    1625         // Merge new templates with existing stack.
    1626         // @see bp_get_theme_compat_templates().
    1627         $templates = array_merge( $new_templates, $templates );
    1628 
    1629         return $templates;
    1630     }
    1631 
    1632     /**
    1633      * Update the global $post with create screen data.
    1634      *
    1635      * @since 1.7.0
    1636      */
    1637     public function create_dummy_post() {
    1638 
    1639         $title = _x( 'Groups', 'Group creation page', 'buddypress' );
    1640 
    1641         bp_theme_compat_reset_post( array(
    1642             'ID'             => 0,
    1643             'post_title'     => $title,
    1644             'post_author'    => 0,
    1645             'post_date'      => 0,
    1646             'post_content'   => '',
    1647             'post_type'      => 'page',
    1648             'post_status'    => 'publish',
    1649             'is_page'        => true,
    1650             'comment_status' => 'closed'
    1651         ) );
    1652     }
    1653 
    1654     /**
    1655      * Filter the_content with the create screen template part.
    1656      *
    1657      * @since 1.7.0
    1658      */
    1659     public function create_content() {
    1660         return bp_buffer_template_part( 'groups/create', null, false );
    1661     }
    1662 
    1663     /** Single ************************************************************/
    1664 
    1665     /**
    1666      * Add custom template hierarchy to theme compat for group pages.
    1667      *
    1668      * This is to mirror how WordPress has
    1669      * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
    1670      *
    1671      * @since 1.8.0
    1672      *
    1673      * @param string $templates The templates from bp_get_theme_compat_templates().
    1674      * @return array $templates Array of custom templates to look for.
    1675      */
    1676     public function single_template_hierarchy( $templates ) {
    1677         // Setup some variables we're going to reference in our custom templates.
    1678         $group = groups_get_current_group();
    1679 
    1680         /**
    1681          * Filters the Groups single pages template hierarchy based on priority.
    1682          *
    1683          * @since 1.8.0
    1684          *
    1685          * @param array $value Array of default template files to use.
    1686          */
    1687         $new_templates = apply_filters( 'bp_template_hierarchy_groups_single_item', array(
    1688             'groups/single/index-id-'     . sanitize_file_name( bp_get_current_group_id() )   . '.php',
    1689             'groups/single/index-slug-'   . sanitize_file_name( bp_get_current_group_slug() ) . '.php',
    1690             'groups/single/index-action-' . sanitize_file_name( bp_current_action() )         . '.php',
    1691             'groups/single/index-status-' . sanitize_file_name( $group->status )              . '.php',
    1692             'groups/single/index.php'
    1693         ) );
    1694 
    1695         // Merge new templates with existing stack.
    1696         // @see bp_get_theme_compat_templates().
    1697         $templates = array_merge( (array) $new_templates, $templates );
    1698 
    1699         return $templates;
    1700     }
    1701 
    1702     /**
    1703      * Update the global $post with single group data.
    1704      *
    1705      * @since 1.7.0
    1706      */
    1707     public function single_dummy_post() {
    1708         bp_theme_compat_reset_post( array(
    1709             'ID'             => 0,
    1710             'post_title'     => bp_get_current_group_name(),
    1711             'post_author'    => 0,
    1712             'post_date'      => 0,
    1713             'post_content'   => '',
    1714             'post_type'      => 'page',
    1715             'post_status'    => 'publish',
    1716             'is_page'        => true,
    1717             'comment_status' => 'closed'
    1718         ) );
    1719     }
    1720 
    1721     /**
    1722      * Filter the_content with the single group template part.
    1723      *
    1724      * @since 1.7.0
    1725      */
    1726     public function single_content() {
    1727         return bp_buffer_template_part( 'groups/single/home', null, false );
    1728     }
    1729 }
    17301480new BP_Groups_Theme_Compat();
  • trunk/src/bp-groups/bp-groups-template.php

    r10454 r10520  
    1111defined( 'ABSPATH' ) || exit;
    1212
     13require dirname( __FILE__ ) . '/classes/class-bp-groups-template.php';
     14require dirname( __FILE__ ) . '/classes/class-bp-groups-group-members-template.php';
     15require dirname( __FILE__ ) . '/classes/class-bp-groups-memberships-requests-template.php';
     16require dirname( __FILE__ ) . '/classes/class-bp-groups-invite-template.php';
     17
    1318/**
    1419 * Output the groups component slug.
     
    9196        return apply_filters( 'bp_get_groups_directory_permalink', trailingslashit( bp_get_root_domain() . '/' . bp_get_groups_root_slug() ) );
    9297    }
    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 }
    48098
    48199/**
     
    39743592
    39753593/**
    3976  * Class BP_Groups_Group_Members_Template
    3977  *
    3978  * @since 1.0.0
    3979  */
    3980 class BP_Groups_Group_Members_Template {
    3981 
    3982     /**
    3983      * @since 1.0.0
    3984      * @var int
    3985      */
    3986     public $current_member = -1;
    3987 
    3988     /**
    3989      * @since 1.0.0
    3990      * @var int
    3991      */
    3992     public $member_count;
    3993 
    3994     /**
    3995      * @since 1.0.0
    3996      * @var array
    3997      */
    3998     public $members;
    3999 
    4000     /**
    4001      * @since 1.0.0
    4002      * @var object
    4003      */
    4004     public $member;
    4005 
    4006     /**
    4007      * @since 1.0.0
    4008      * @var bool
    4009      */
    4010     public $in_the_loop;
    4011 
    4012     /**
    4013      * @since 1.0.0
    4014      * @var int
    4015      */
    4016     public $pag_page;
    4017 
    4018     /**
    4019      * @since 1.0.0
    4020      * @var int
    4021      */
    4022     public $pag_num;
    4023 
    4024     /**
    4025      * @since 1.0.0
    4026      * @var array|string|void
    4027      */
    4028     public $pag_links;
    4029 
    4030     /**
    4031      * @since 1.0.0
    4032      * @var int
    4033      */
    4034     public $total_group_count;
    4035 
    4036     /**
    4037      * Constructor.
    4038      *
    4039      * @since 1.5.0
    4040      *
    4041      * @param array $args {
    4042      *     An array of optional arguments.
    4043      *     @type int      $group_id           ID of the group whose members are being
    4044      *                                        queried. Default: current group ID.
    4045      *     @type int      $page               Page of results to be queried. Default: 1.
    4046      *     @type int      $per_page           Number of items to return per page of
    4047      *                                        results. Default: 20.
    4048      *     @type int      $max                Optional. Max number of items to return.
    4049      *     @type array    $exclude            Optional. Array of user IDs to exclude.
    4050      *     @type bool|int $exclude_admin_mods True (or 1) to exclude admins and mods from
    4051      *                                        results. Default: 1.
    4052      *     @type bool|int $exclude_banned     True (or 1) to exclude banned users from results.
    4053      *                                        Default: 1.
    4054      *     @type array    $group_role         Optional. Array of group roles to include.
    4055      *     @type string   $search_terms       Optional. Search terms to match.
    4056      * }
    4057      */
    4058     public function __construct( $args = array() ) {
    4059 
    4060         // Backward compatibility with old method of passing arguments.
    4061         if ( ! is_array( $args ) || func_num_args() > 1 ) {
    4062             _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__ ) );
    4063 
    4064             $old_args_keys = array(
    4065                 0 => 'group_id',
    4066                 1 => 'per_page',
    4067                 2 => 'max',
    4068                 3 => 'exclude_admins_mods',
    4069                 4 => 'exclude_banned',
    4070                 5 => 'exclude',
    4071                 6 => 'group_role',
    4072             );
    4073 
    4074             $func_args = func_get_args();
    4075             $args      = bp_core_parse_args_array( $old_args_keys, $func_args );
    4076         }
    4077 
    4078         $r = wp_parse_args( $args, array(
    4079             'group_id'            => bp_get_current_group_id(),
    4080             'page'                => 1,
    4081             'per_page'            => 20,
    4082             'page_arg'            => 'mlpage',
    4083             'max'                 => false,
    4084             'exclude'             => false,
    4085             'exclude_admins_mods' => 1,
    4086             'exclude_banned'      => 1,
    4087             'group_role'          => false,
    4088             'search_terms'        => false,
    4089             'type'                => 'last_joined',
    4090         ) );
    4091 
    4092         $this->pag_arg  = sanitize_key( $r['page_arg'] );
    4093         $this->pag_page = bp_sanitize_pagination_arg( $this->pag_arg, $r['page']     );
    4094         $this->pag_num  = bp_sanitize_pagination_arg( 'num',          $r['per_page'] );
    4095 
    4096         /**
    4097          * Check the current group is the same as the supplied group ID.
    4098          * It can differ when using {@link bp_group_has_members()} outside the Groups screens.
    4099          */
    4100         $current_group = groups_get_current_group();
    4101         if ( empty( $current_group ) || ( $current_group && $current_group->id !== bp_get_current_group_id() ) ) {
    4102             $current_group = groups_get_group( array( 'group_id' => $r['group_id'] ) );
    4103         }
    4104 
    4105         // Assemble the base URL for pagination.
    4106         $base_url = trailingslashit( bp_get_group_permalink( $current_group ) . bp_current_action() );
    4107         if ( bp_action_variable() ) {
    4108             $base_url = trailingslashit( $base_url . bp_action_variable() );
    4109         }
    4110 
    4111         $members_args = $r;
    4112 
    4113         $members_args['page']     = $this->pag_page;
    4114         $members_args['per_page'] = $this->pag_num;
    4115 
    4116         // Get group members for this loop.
    4117         $this->members = groups_get_group_members( $members_args );
    4118 
    4119         if ( empty( $r['max'] ) || ( $r['max'] >= (int) $this->members['count'] ) ) {
    4120             $this->total_member_count = (int) $this->members['count'];
    4121         } else {
    4122             $this->total_member_count = (int) $r['max'];
    4123         }
    4124 
    4125         // Reset members array for subsequent looping.
    4126         $this->members = $this->members['members'];
    4127 
    4128         if ( empty( $r['max'] ) || ( $r['max'] >= count( $this->members ) ) ) {
    4129             $this->member_count = (int) count( $this->members );
    4130         } else {
    4131             $this->member_count = (int) $r['max'];
    4132         }
    4133 
    4134         $this->pag_links = paginate_links( array(
    4135             'base'      => add_query_arg( array( $this->pag_arg => '%#%' ), $base_url ),
    4136             'format'    => '',
    4137             'total'     => ! empty( $this->pag_num ) ? ceil( $this->total_member_count / $this->pag_num ) : $this->total_member_count,
    4138             'current'   => $this->pag_page,
    4139             'prev_text' => '&larr;',
    4140             'next_text' => '&rarr;',
    4141             'mid_size'  => 1,
    4142             'add_args'  => array(),
    4143         ) );
    4144     }
    4145 
    4146     /**
    4147      * Whether or not there are members to display.
    4148      *
    4149      * @since 1.0.0
    4150      *
    4151      * @return bool
    4152      */
    4153     public function has_members() {
    4154         if ( ! empty( $this->member_count ) ) {
    4155             return true;
    4156         }
    4157 
    4158         return false;
    4159     }
    4160 
    4161     /**
    4162      * Increments to the next member to display.
    4163      *
    4164      * @since 1.0.0
    4165      *
    4166      * @return object
    4167      */
    4168     public function next_member() {
    4169         $this->current_member++;
    4170         $this->member = $this->members[ $this->current_member ];
    4171 
    4172         return $this->member;
    4173     }
    4174 
    4175     /**
    4176      * Rewinds to the first member to display.
    4177      *
    4178      * @since 1.0.0
    4179      */
    4180     public function rewind_members() {
    4181         $this->current_member = -1;
    4182         if ( $this->member_count > 0 ) {
    4183             $this->member = $this->members[0];
    4184         }
    4185     }
    4186 
    4187     /**
    4188      * Finishes up the members for display.
    4189      *
    4190      * @since 1.0.0
    4191      *
    4192      * @return bool
    4193      */
    4194     public function members() {
    4195         $tick = intval( $this->current_member + 1 );
    4196         if ( $tick < $this->member_count ) {
    4197             return true;
    4198         } elseif ( $tick == $this->member_count ) {
    4199 
    4200             /**
    4201              * Fires right before the rewinding of members list.
    4202              *
    4203              * @since 1.0.0
    4204              * @since 2.3.0 `$this` parameter added.
    4205              *
    4206              * @param BP_Groups_Group_Members_Template $this Instance of the current Members template.
    4207              */
    4208             do_action( 'loop_end', $this );
    4209 
    4210             // Do some cleaning up after the loop.
    4211             $this->rewind_members();
    4212         }
    4213 
    4214         $this->in_the_loop = false;
    4215         return false;
    4216     }
    4217 
    4218     /**
    4219      * Sets up the member to display.
    4220      *
    4221      * @since 1.0.0
    4222      */
    4223     public function the_member() {
    4224         $this->in_the_loop = true;
    4225         $this->member      = $this->next_member();
    4226 
    4227         // Loop has just started.
    4228         if ( 0 == $this->current_member ) {
    4229 
    4230             /**
    4231              * Fires if the current member item is the first in the members list.
    4232              *
    4233              * @since 1.0.0
    4234              * @since 2.3.0 `$this` parameter added.
    4235              *
    4236              * @param BP_Groups_Group_Members_Template $this Instance of the current Members template.
    4237              */
    4238             do_action( 'loop_start', $this );
    4239         }
    4240     }
    4241 }
    4242 
    4243 /**
    42443594 * Initialize a group member query loop.
    42453595 *
     
    58675217
    58685218/**
    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 /**
    61145219 * Initialize a group membership request template loop.
    61155220 *
     
    63645469
    63655470/** 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 }
    66265471
    66275472/**
  • trunk/src/bp-groups/bp-groups-widgets.php

    r10454 r10520  
    1111defined( 'ABSPATH' ) || exit;
    1212
     13require dirname( __FILE__ ) . '/classes/class-bp-groups-widget.php';
     14
    1315/**
    1416 * Register widgets for groups component.
     
    2022}
    2123add_action( 'bp_register_widgets', 'groups_register_widgets' );
    22 
    23 /**
    24  * Groups widget.
    25  *
    26  * @since 1.0.3
    27  */
    28 class BP_Groups_Widget extends WP_Widget {
    29 
    30     /**
    31      * Working as a group, we get things done better.
    32      *
    33      * @since 1.0.3
    34      */
    35     public function __construct() {
    36         $widget_ops = array(
    37             'description' => __( 'A dynamic list of recently active, popular, and newest groups', 'buddypress' ),
    38             'classname' => 'widget_bp_groups_widget buddypress widget',
    39         );
    40         parent::__construct( false, _x( '(BuddyPress) Groups', 'widget name', 'buddypress' ), $widget_ops );
    41 
    42         if ( is_active_widget( false, false, $this->id_base ) && ! is_admin() && ! is_network_admin() ) {
    43             $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
    44             wp_enqueue_script( 'groups_widget_groups_list-js', buddypress()->plugin_url . "bp-groups/js/widget-groups{$min}.js", array( 'jquery' ), bp_get_version() );
    45         }
    46     }
    47 
    48     /**
    49      * Extends our frontend output method.
    50      *
    51      * @since 1.0.3
    52      *
    53      * @param array $args     Array of arguments for the widget.
    54      * @param array $instance Widget instance data.
    55      */
    56     public function widget( $args, $instance ) {
    57 
    58         /**
    59          * Filters the user ID to use with the widget instance.
    60          *
    61          * @since 1.5.0
    62          *
    63          * @param string $value Empty user ID.
    64          */
    65         $user_id = apply_filters( 'bp_group_widget_user_id', '0' );
    66 
    67         extract( $args );
    68 
    69         if ( empty( $instance['group_default'] ) ) {
    70             $instance['group_default'] = 'popular';
    71         }
    72 
    73         if ( empty( $instance['title'] ) ) {
    74             $instance['title'] = __( 'Groups', 'buddypress' );
    75         }
    76 
    77         /**
    78          * Filters the title of the Groups widget.
    79          *
    80          * @since 1.8.0
    81          * @since 2.3.0 Added 'instance' and 'id_base' to arguments passed to filter.
    82          *
    83          * @param string $title    The widget title.
    84          * @param array  $instance The settings for the particular instance of the widget.
    85          * @param string $id_base  Root ID for all widgets of this type.
    86          */
    87         $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
    88 
    89         /**
    90          * Filters the separator of the group widget links.
    91          *
    92          * @since 2.4.0
    93          *
    94          * @param string $separator Separator string. Default '|'.
    95          */
    96         $separator = apply_filters( 'bp_groups_widget_separator', '|' );
    97 
    98         echo $before_widget;
    99 
    100         $title = ! empty( $instance['link_title'] ) ? '<a href="' . bp_get_groups_directory_permalink() . '">' . $title . '</a>' : $title;
    101 
    102         echo $before_title . $title . $after_title;
    103 
    104         $max_groups = ! empty( $instance['max_groups'] ) ? (int) $instance['max_groups'] : 5;
    105 
    106         $group_args = array(
    107             'user_id'         => $user_id,
    108             'type'            => $instance['group_default'],
    109             'per_page'        => $max_groups,
    110             'max'             => $max_groups,
    111         );
    112 
    113         ?>
    114 
    115         <?php if ( bp_has_groups( $group_args ) ) : ?>
    116             <div class="item-options" id="groups-list-options">
    117                 <a href="<?php bp_groups_directory_permalink(); ?>" id="newest-groups"<?php if ( $instance['group_default'] == 'newest' ) : ?> class="selected"<?php endif; ?>><?php _e("Newest", 'buddypress') ?></a>
    118                 <span class="bp-separator" role="separator"><?php echo esc_html( $separator ); ?></span>
    119                 <a href="<?php bp_groups_directory_permalink(); ?>" id="recently-active-groups"<?php if ( $instance['group_default'] == 'active' ) : ?> class="selected"<?php endif; ?>><?php _e("Active", 'buddypress') ?></a>
    120                 <span class="bp-separator" role="separator"><?php echo esc_html( $separator ); ?></span>
    121                 <a href="<?php bp_groups_directory_permalink(); ?>" id="popular-groups" <?php if ( $instance['group_default'] == 'popular' ) : ?> class="selected"<?php endif; ?>><?php _e("Popular", 'buddypress') ?></a>
    122             </div>
    123 
    124             <ul id="groups-list" class="item-list">
    125                 <?php while ( bp_groups() ) : bp_the_group(); ?>
    126                     <li <?php bp_group_class(); ?>>
    127                         <div class="item-avatar">
    128                             <a href="<?php bp_group_permalink() ?>" title="<?php bp_group_name() ?>"><?php bp_group_avatar_thumb() ?></a>
    129                         </div>
    130 
    131                         <div class="item">
    132                             <div class="item-title"><a href="<?php bp_group_permalink() ?>" title="<?php bp_group_name() ?>"><?php bp_group_name() ?></a></div>
    133                             <div class="item-meta">
    134                                 <span class="activity">
    135                                 <?php
    136                                     if ( 'newest' == $instance['group_default'] ) {
    137                                         printf( __( 'created %s', 'buddypress' ), bp_get_group_date_created() );
    138                                     } elseif ( 'active' == $instance['group_default'] ) {
    139                                         printf( __( 'active %s', 'buddypress' ), bp_get_group_last_active() );
    140                                     } elseif ( 'popular' == $instance['group_default'] ) {
    141                                         bp_group_member_count();
    142                                     }
    143                                 ?>
    144                                 </span>
    145                             </div>
    146                         </div>
    147                     </li>
    148 
    149                 <?php endwhile; ?>
    150             </ul>
    151             <?php wp_nonce_field( 'groups_widget_groups_list', '_wpnonce-groups' ); ?>
    152             <input type="hidden" name="groups_widget_max" id="groups_widget_max" value="<?php echo esc_attr( $max_groups ); ?>" />
    153 
    154         <?php else: ?>
    155 
    156             <div class="widget-error">
    157                 <?php _e('There are no groups to display.', 'buddypress') ?>
    158             </div>
    159 
    160         <?php endif; ?>
    161 
    162         <?php echo $after_widget; ?>
    163     <?php
    164     }
    165 
    166     /**
    167      * Extends our update method.
    168      *
    169      * @since 1.0.3
    170      *
    171      * @param array $new_instance New instance data.
    172      * @param array $old_instance Original instance data.
    173      * @return array
    174      */
    175     public function update( $new_instance, $old_instance ) {
    176         $instance = $old_instance;
    177 
    178         $instance['title']         = strip_tags( $new_instance['title'] );
    179         $instance['max_groups']    = strip_tags( $new_instance['max_groups'] );
    180         $instance['group_default'] = strip_tags( $new_instance['group_default'] );
    181         $instance['link_title']    = (bool) $new_instance['link_title'];
    182 
    183         return $instance;
    184     }
    185 
    186     /**
    187      * Extends our form method.
    188      *
    189      * @since 1.0.3
    190      *
    191      * @param array $instance Current instance.
    192      * @return mixed
    193      */
    194     public function form( $instance ) {
    195         $defaults = array(
    196             'title'         => __( 'Groups', 'buddypress' ),
    197             'max_groups'    => 5,
    198             'group_default' => 'active',
    199             'link_title'    => false
    200         );
    201         $instance = wp_parse_args( (array) $instance, $defaults );
    202 
    203         $title         = strip_tags( $instance['title'] );
    204         $max_groups    = strip_tags( $instance['max_groups'] );
    205         $group_default = strip_tags( $instance['group_default'] );
    206         $link_title    = (bool) $instance['link_title'];
    207         ?>
    208 
    209         <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" style="width: 100%" /></label></p>
    210 
    211         <p><label for="<?php echo $this->get_field_id('link_title') ?>"><input type="checkbox" name="<?php echo $this->get_field_name('link_title') ?>" id="<?php echo $this->get_field_id('link_title') ?>" value="1" <?php checked( $link_title ) ?> /> <?php _e( 'Link widget title to Groups directory', 'buddypress' ) ?></label></p>
    212 
    213         <p><label for="<?php echo $this->get_field_id( 'max_groups' ); ?>"><?php _e('Max groups to show:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_groups' ); ?>" name="<?php echo $this->get_field_name( 'max_groups' ); ?>" type="text" value="<?php echo esc_attr( $max_groups ); ?>" style="width: 30%" /></label></p>
    214 
    215         <p>
    216             <label for="<?php echo $this->get_field_id( 'group_default' ); ?>"><?php _e('Default groups to show:', 'buddypress'); ?></label>
    217             <select name="<?php echo $this->get_field_name( 'group_default' ); ?>" id="<?php echo $this->get_field_id( 'group_default' ); ?>">
    218                 <option value="newest" <?php selected( $group_default, 'newest' ); ?>><?php _e( 'Newest', 'buddypress' ) ?></option>
    219                 <option value="active" <?php selected( $group_default, 'active' ); ?>><?php _e( 'Active', 'buddypress' ) ?></option>
    220                 <option value="popular"  <?php selected( $group_default, 'popular' ); ?>><?php _e( 'Popular', 'buddypress' ) ?></option>
    221             </select>
    222         </p>
    223     <?php
    224     }
    225 }
    22624
    22725/**
  • trunk/src/bp-groups/classes/class-bp-groups-component.php

    r10515 r10520  
    11<?php
    22/**
    3  * BuddyPress Groups Loader.
    4  *
    5  * A groups component, for users to group themselves together. Includes a
    6  * robust sub-component API that allows Groups to be extended.
    7  * Comes preconfigured with an activity stream, discussion forums, and settings.
     3 * BuddyPress Groups Component Class.
    84 *
    95 * @package BuddyPress
     
    814810    }
    815811}
    816 
    817 /**
    818  * Bootstrap the Notifications component.
    819  *
    820  * @since 1.5.0
    821  */
    822 function bp_setup_groups() {
    823     buddypress()->groups = new BP_Groups_Component();
    824 }
    825 add_action( 'bp_setup_components', 'bp_setup_groups', 6 );
  • 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 }
  • trunk/src/bp-groups/classes/class-bp-groups-invite-template.php

    r10515 r10520  
    11<?php
    22/**
    3  * BuddyPress Groups Template Functions.
     3 * BuddyPress Groups Invitation template loop 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
    3977  *
    3978  * @since 1.0.0
    3979  */
    3980 class BP_Groups_Group_Members_Template {
    3981 
    3982     /**
    3983      * @since 1.0.0
    3984      * @var int
    3985      */
    3986     public $current_member = -1;
    3987 
    3988     /**
    3989      * @since 1.0.0
    3990      * @var int
    3991      */
    3992     public $member_count;
    3993 
    3994     /**
    3995      * @since 1.0.0
    3996      * @var array
    3997      */
    3998     public $members;
    3999 
    4000     /**
    4001      * @since 1.0.0
    4002      * @var object
    4003      */
    4004     public $member;
    4005 
    4006     /**
    4007      * @since 1.0.0
    4008      * @var bool
    4009      */
    4010     public $in_the_loop;
    4011 
    4012     /**
    4013      * @since 1.0.0
    4014      * @var int
    4015      */
    4016     public $pag_page;
    4017 
    4018     /**
    4019      * @since 1.0.0
    4020      * @var int
    4021      */
    4022     public $pag_num;
    4023 
    4024     /**
    4025      * @since 1.0.0
    4026      * @var array|string|void
    4027      */
    4028     public $pag_links;
    4029 
    4030     /**
    4031      * @since 1.0.0
    4032      * @var int
    4033      */
    4034     public $total_group_count;
    4035 
    4036     /**
    4037      * Constructor.
    4038      *
    4039      * @since 1.5.0
    4040      *
    4041      * @param array $args {
    4042      *     An array of optional arguments.
    4043      *     @type int      $group_id           ID of the group whose members are being
    4044      *                                        queried. Default: current group ID.
    4045      *     @type int      $page               Page of results to be queried. Default: 1.
    4046      *     @type int      $per_page           Number of items to return per page of
    4047      *                                        results. Default: 20.
    4048      *     @type int      $max                Optional. Max number of items to return.
    4049      *     @type array    $exclude            Optional. Array of user IDs to exclude.
    4050      *     @type bool|int $exclude_admin_mods True (or 1) to exclude admins and mods from
    4051      *                                        results. Default: 1.
    4052      *     @type bool|int $exclude_banned     True (or 1) to exclude banned users from results.
    4053      *                                        Default: 1.
    4054      *     @type array    $group_role         Optional. Array of group roles to include.
    4055      *     @type string   $search_terms       Optional. Search terms to match.
    4056      * }
    4057      */
    4058     public function __construct( $args = array() ) {
    4059 
    4060         // Backward compatibility with old method of passing arguments.
    4061         if ( ! is_array( $args ) || func_num_args() > 1 ) {
    4062             _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__ ) );
    4063 
    4064             $old_args_keys = array(
    4065                 0 => 'group_id',
    4066                 1 => 'per_page',
    4067                 2 => 'max',
    4068                 3 => 'exclude_admins_mods',
    4069                 4 => 'exclude_banned',
    4070                 5 => 'exclude',
    4071                 6 => 'group_role',
    4072             );
    4073 
    4074             $func_args = func_get_args();
    4075             $args      = bp_core_parse_args_array( $old_args_keys, $func_args );
    4076         }
    4077 
    4078         $r = wp_parse_args( $args, array(
    4079             'group_id'            => bp_get_current_group_id(),
    4080             'page'                => 1,
    4081             'per_page'            => 20,
    4082             'page_arg'            => 'mlpage',
    4083             'max'                 => false,
    4084             'exclude'             => false,
    4085             'exclude_admins_mods' => 1,
    4086             'exclude_banned'      => 1,
    4087             'group_role'          => false,
    4088             'search_terms'        => false,
    4089             'type'                => 'last_joined',
    4090         ) );
    4091 
    4092         $this->pag_arg  = sanitize_key( $r['page_arg'] );
    4093         $this->pag_page = bp_sanitize_pagination_arg( $this->pag_arg, $r['page']     );
    4094         $this->pag_num  = bp_sanitize_pagination_arg( 'num',          $r['per_page'] );
    4095 
    4096         /**
    4097          * Check the current group is the same as the supplied group ID.
    4098          * It can differ when using {@link bp_group_has_members()} outside the Groups screens.
    4099          */
    4100         $current_group = groups_get_current_group();
    4101         if ( empty( $current_group ) || ( $current_group && $current_group->id !== bp_get_current_group_id() ) ) {
    4102             $current_group = groups_get_group( array( 'group_id' => $r['group_id'] ) );
    4103         }
    4104 
    4105         // Assemble the base URL for pagination.
    4106         $base_url = trailingslashit( bp_get_group_permalink( $current_group ) . bp_current_action() );
    4107         if ( bp_action_variable() ) {
    4108             $base_url = trailingslashit( $base_url . bp_action_variable() );
    4109         }
    4110 
    4111         $members_args = $r;
    4112 
    4113         $members_args['page']     = $this->pag_page;
    4114         $members_args['per_page'] = $this->pag_num;
    4115 
    4116         // Get group members for this loop.
    4117         $this->members = groups_get_group_members( $members_args );
    4118 
    4119         if ( empty( $r['max'] ) || ( $r['max'] >= (int) $this->members['count'] ) ) {
    4120             $this->total_member_count = (int) $this->members['count'];
    4121         } else {
    4122             $this->total_member_count = (int) $r['max'];
    4123         }
    4124 
    4125         // Reset members array for subsequent looping.
    4126         $this->members = $this->members['members'];
    4127 
    4128         if ( empty( $r['max'] ) || ( $r['max'] >= count( $this->members ) ) ) {
    4129             $this->member_count = (int) count( $this->members );
    4130         } else {
    4131             $this->member_count = (int) $r['max'];
    4132         }
    4133 
    4134         $this->pag_links = paginate_links( array(
    4135             'base'      => add_query_arg( array( $this->pag_arg => '%#%' ), $base_url ),
    4136             'format'    => '',
    4137             'total'     => ! empty( $this->pag_num ) ? ceil( $this->total_member_count / $this->pag_num ) : $this->total_member_count,
    4138             'current'   => $this->pag_page,
    4139             'prev_text' => '&larr;',
    4140             'next_text' => '&rarr;',
    4141             'mid_size'  => 1,
    4142             'add_args'  => array(),
    4143         ) );
    4144     }
    4145 
    4146     /**
    4147      * Whether or not there are members to display.
    4148      *
    4149      * @since 1.0.0
    4150      *
    4151      * @return bool
    4152      */
    4153     public function has_members() {
    4154         if ( ! empty( $this->member_count ) ) {
    4155             return true;
    4156         }
    4157 
    4158         return false;
    4159     }
    4160 
    4161     /**
    4162      * Increments to the next member to display.
    4163      *
    4164      * @since 1.0.0
    4165      *
    4166      * @return object
    4167      */
    4168     public function next_member() {
    4169         $this->current_member++;
    4170         $this->member = $this->members[ $this->current_member ];
    4171 
    4172         return $this->member;
    4173     }
    4174 
    4175     /**
    4176      * Rewinds to the first member to display.
    4177      *
    4178      * @since 1.0.0
    4179      */
    4180     public function rewind_members() {
    4181         $this->current_member = -1;
    4182         if ( $this->member_count > 0 ) {
    4183             $this->member = $this->members[0];
    4184         }
    4185     }
    4186 
    4187     /**
    4188      * Finishes up the members for display.
    4189      *
    4190      * @since 1.0.0
    4191      *
    4192      * @return bool
    4193      */
    4194     public function members() {
    4195         $tick = intval( $this->current_member + 1 );
    4196         if ( $tick < $this->member_count ) {
    4197             return true;
    4198         } elseif ( $tick == $this->member_count ) {
    4199 
    4200             /**
    4201              * Fires right before the rewinding of members list.
    4202              *
    4203              * @since 1.0.0
    4204              * @since 2.3.0 `$this` parameter added.
    4205              *
    4206              * @param BP_Groups_Group_Members_Template $this Instance of the current Members template.
    4207              */
    4208             do_action( 'loop_end', $this );
    4209 
    4210             // Do some cleaning up after the loop.
    4211             $this->rewind_members();
    4212         }
    4213 
    4214         $this->in_the_loop = false;
    4215         return false;
    4216     }
    4217 
    4218     /**
    4219      * Sets up the member to display.
    4220      *
    4221      * @since 1.0.0
    4222      */
    4223     public function the_member() {
    4224         $this->in_the_loop = true;
    4225         $this->member      = $this->next_member();
    4226 
    4227         // Loop has just started.
    4228         if ( 0 == $this->current_member ) {
    4229 
    4230             /**
    4231              * Fires if the current member item is the first in the members list.
    4232              *
    4233              * @since 1.0.0
    4234              * @since 2.3.0 `$this` parameter added.
    4235              *
    4236              * @param BP_Groups_Group_Members_Template $this Instance of the current Members template.
    4237              */
    4238             do_action( 'loop_start', $this );
    4239         }
    4240     }
    4241 }
    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
     13 * Group invitation template loop class.
    636914 *
    637015 * @since 1.1.0
     
    6624269    }
    6625270}
    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 }
  • trunk/src/bp-groups/classes/class-bp-groups-list-table.php

    r10515 r10520  
    11<?php
    22/**
    3  * BuddyPress Groups component admin screen.
     3 * BuddyPress Groups admin list table class.
    44 *
    55 * Props to WordPress core for the Comments admin screen, and its contextual
     
    1313// Exit if accessed directly.
    1414defined( 'ABSPATH' ) || exit;
    15 
    16 // Include WP's list table class.
    17 if ( !class_exists( 'WP_List_Table' ) ) require( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
    18 
    19 // The per_page screen option. Has to be hooked in extremely early.
    20 if ( is_admin() && ! empty( $_REQUEST['page'] ) && 'bp-groups' == $_REQUEST['page'] )
    21     add_filter( 'set-screen-option', 'bp_groups_admin_screen_options', 10, 3 );
    22 
    23 /**
    24  * Register the Groups component admin screen.
    25  *
    26  * @since 1.7.0
    27  */
    28 function bp_groups_add_admin_menu() {
    29 
    30     // Add our screen.
    31     $hook = add_menu_page(
    32         _x( 'Groups', 'Admin Groups page title', 'buddypress' ),
    33         _x( 'Groups', 'Admin Groups menu', 'buddypress' ),
    34         'bp_moderate',
    35         'bp-groups',
    36         'bp_groups_admin',
    37         'div'
    38     );
    39 
    40     // Hook into early actions to load custom CSS and our init handler.
    41     add_action( "load-$hook", 'bp_groups_admin_load' );
    42 }
    43 add_action( bp_core_admin_hook(), 'bp_groups_add_admin_menu' );
    44 
    45 /**
    46  * Add groups component to custom menus array.
    47  *
    48  * This ensures that the Groups menu item appears in the proper order on the
    49  * main Dashboard menu.
    50  *
    51  * @since 1.7.0
    52  *
    53  * @param array $custom_menus Array of BP top-level menu items.
    54  * @return array Menu item array, with Groups added.
    55  */
    56 function bp_groups_admin_menu_order( $custom_menus = array() ) {
    57     array_push( $custom_menus, 'bp-groups' );
    58     return $custom_menus;
    59 }
    60 add_filter( 'bp_admin_menu_order', 'bp_groups_admin_menu_order' );
    61 
    62 /**
    63  * Set up the Groups admin page.
    64  *
    65  * Loaded before the page is rendered, this function does all initial setup,
    66  * including: processing form requests, registering contextual help, and
    67  * setting up screen options.
    68  *
    69  * @since 1.7.0
    70  *
    71  * @global BP_Groups_List_Table $bp_groups_list_table Groups screen list table.
    72  */
    73 function bp_groups_admin_load() {
    74     global $bp_groups_list_table;
    75 
    76     // Build redirection URL.
    77     $redirect_to = remove_query_arg( array( 'action', 'action2', 'gid', 'deleted', 'error', 'updated', 'success_new', 'error_new', 'success_modified', 'error_modified' ), $_SERVER['REQUEST_URI'] );
    78 
    79     // Decide whether to load the dev version of the CSS and JavaScript.
    80     $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : 'min.';
    81 
    82     $doaction = bp_admin_list_table_current_bulk_action();
    83 
    84     /**
    85      * Fires at top of groups admin page.
    86      *
    87      * @since 1.7.0
    88      *
    89      * @param string $doaction Current $_GET action being performed in admin screen.
    90      */
    91     do_action( 'bp_groups_admin_load', $doaction );
    92 
    93     // Edit screen.
    94     if ( 'do_delete' == $doaction && ! empty( $_GET['gid'] ) ) {
    95 
    96         check_admin_referer( 'bp-groups-delete' );
    97 
    98         $group_ids = wp_parse_id_list( $_GET['gid'] );
    99 
    100         $count = 0;
    101         foreach ( $group_ids as $group_id ) {
    102             if ( groups_delete_group( $group_id ) ) {
    103                 $count++;
    104             }
    105         }
    106 
    107         $redirect_to = add_query_arg( 'deleted', $count, $redirect_to );
    108 
    109         bp_core_redirect( $redirect_to );
    110 
    111     } elseif ( 'edit' == $doaction && ! empty( $_GET['gid'] ) ) {
    112         // Columns screen option.
    113         add_screen_option( 'layout_columns', array( 'default' => 2, 'max' => 2, ) );
    114 
    115         get_current_screen()->add_help_tab( array(
    116             'id'      => 'bp-group-edit-overview',
    117             'title'   => __( 'Overview', 'buddypress' ),
    118             'content' =>
    119                 '<p>' . __( 'This page is a convenient way to edit the details associated with one of your groups.', 'buddypress' ) . '</p>' .
    120                 '<p>' . __( 'The Name and Description box is fixed in place, but you can reposition all the other boxes using drag and drop, and can minimize or expand them by clicking the title bar of each box. Use the Screen Options tab to hide or unhide, or to choose a 1- or 2-column layout for this screen.', 'buddypress' ) . '</p>'
    121         ) );
    122 
    123         // Help panel - sidebar links.
    124         get_current_screen()->set_help_sidebar(
    125             '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' .
    126             '<p><a href="https://buddypress.org/support">' . __( 'Support Forums', 'buddypress' ) . '</a></p>'
    127         );
    128 
    129         // Register metaboxes for the edit screen.
    130         add_meta_box( 'submitdiv', _x( 'Save', 'group admin edit screen', 'buddypress' ), 'bp_groups_admin_edit_metabox_status', get_current_screen()->id, 'side', 'high' );
    131         add_meta_box( 'bp_group_settings', _x( 'Settings', 'group admin edit screen', 'buddypress' ), 'bp_groups_admin_edit_metabox_settings', get_current_screen()->id, 'side', 'core' );
    132         add_meta_box( 'bp_group_add_members', _x( 'Add New Members', 'group admin edit screen', 'buddypress' ), 'bp_groups_admin_edit_metabox_add_new_members', get_current_screen()->id, 'normal', 'core' );
    133         add_meta_box( 'bp_group_members', _x( 'Manage Members', 'group admin edit screen', 'buddypress' ), 'bp_groups_admin_edit_metabox_members', get_current_screen()->id, 'normal', 'core' );
    134 
    135         /**
    136          * Fires after the registration of all of the default group meta boxes.
    137          *
    138          * @since 1.7.0
    139          */
    140         do_action( 'bp_groups_admin_meta_boxes' );
    141 
    142         // Enqueue JavaScript files.
    143         wp_enqueue_script( 'postbox' );
    144         wp_enqueue_script( 'dashboard' );
    145 
    146     // Index screen.
    147     } else {
    148         // Create the Groups screen list table.
    149         $bp_groups_list_table = new BP_Groups_List_Table();
    150 
    151         // The per_page screen option.
    152         add_screen_option( 'per_page', array( 'label' => _x( 'Groups', 'Groups per page (screen options)', 'buddypress' )) );
    153 
    154         // Help panel - overview text.
    155         get_current_screen()->add_help_tab( array(
    156             'id'      => 'bp-groups-overview',
    157             'title'   => __( 'Overview', 'buddypress' ),
    158             'content' =>
    159                 '<p>' . __( 'You can manage groups much like you can manage comments and other content. This screen is customizable in the same ways as other management screens, and you can act on groups by using the on-hover action links or the Bulk Actions.', 'buddypress' ) . '</p>',
    160         ) );
    161 
    162         get_current_screen()->add_help_tab( array(
    163             'id'      => 'bp-groups-overview-actions',
    164             'title'   => __( 'Group Actions', 'buddypress' ),
    165             'content' =>
    166                 '<p>' . __( 'Clicking "Visit" will take you to the group&#8217;s public page. Use this link to see what the group looks like on the front end of your site.', 'buddypress' ) . '</p>' .
    167                 '<p>' . __( 'Clicking "Edit" will take you to a Dashboard panel where you can manage various details about the group, such as its name and description, its members, and other settings.', 'buddypress' ) . '</p>' .
    168                 '<p>' . __( 'If you click "Delete" under a specific group, or select a number of groups and then choose Delete from the Bulk Actions menu, you will be led to a page where you&#8217;ll be asked to confirm the permanent deletion of the group(s).', 'buddypress' ) . '</p>',
    169         ) );
    170 
    171         // Help panel - sidebar links.
    172         get_current_screen()->set_help_sidebar(
    173             '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' .
    174             '<p>' . __( '<a href="https://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>'
    175         );
    176 
    177         // Add accessible hidden heading and text for Groups screen pagination.
    178         if ( bp_get_major_wp_version() >= 4.4 ) {
    179             get_current_screen()->set_screen_reader_content( array(
    180                 'heading_pagination' => __( 'Groups list navigation', 'buddypress' ),
    181             ) );
    182         }
    183     }
    184 
    185     $bp = buddypress();
    186 
    187     // Enqueue CSS and JavaScript.
    188     wp_enqueue_script( 'bp_groups_admin_js', $bp->plugin_url . "bp-groups/admin/js/admin.{$min}js", array( 'jquery', 'wp-ajax-response', 'jquery-ui-autocomplete' ), bp_get_version(), true );
    189     wp_localize_script( 'bp_groups_admin_js', 'BP_Group_Admin', array(
    190         'add_member_placeholder' => __( 'Start typing a username to add a new member.', 'buddypress' ),
    191         'warn_on_leave'          => __( 'If you leave this page, you will lose any unsaved changes you have made to the group.', 'buddypress' ),
    192     ) );
    193     wp_enqueue_style( 'bp_groups_admin_css', $bp->plugin_url . "bp-groups/admin/css/admin.{$min}css", array(), bp_get_version() );
    194 
    195     wp_style_add_data( 'bp_groups_admin_css', 'rtl', true );
    196     if ( $min ) {
    197         wp_style_add_data( 'bp_groups_admin_css', 'suffix', $min );
    198     }
    199 
    200 
    201     if ( $doaction && 'save' == $doaction ) {
    202         // Get group ID.
    203         $group_id = isset( $_REQUEST['gid'] ) ? (int) $_REQUEST['gid'] : '';
    204 
    205         $redirect_to = add_query_arg( array(
    206             'gid'    => (int) $group_id,
    207             'action' => 'edit'
    208         ), $redirect_to );
    209 
    210         // Check this is a valid form submission.
    211         check_admin_referer( 'edit-group_' . $group_id );
    212 
    213         // Get the group from the database.
    214         $group = groups_get_group( 'group_id=' . $group_id );
    215 
    216         // If the group doesn't exist, just redirect back to the index.
    217         if ( empty( $group->slug ) ) {
    218             wp_redirect( $redirect_to );
    219             exit;
    220         }
    221 
    222         // Check the form for the updated properties.
    223         // Store errors.
    224         $error = 0;
    225         $success_new = $error_new = $success_modified = $error_modified = array();
    226 
    227         // Group name and description are handled with
    228         // groups_edit_base_group_details().
    229         if ( !groups_edit_base_group_details( $group_id, $_POST['bp-groups-name'], $_POST['bp-groups-description'], 0 ) ) {
    230             $error = $group_id;
    231 
    232             // Using negative integers for different error messages... eek!
    233             if ( empty( $_POST['bp-groups-name'] ) && empty( $_POST['bp-groups-description'] ) ) {
    234                 $error = -3;
    235             } elseif ( empty( $_POST['bp-groups-name'] ) ) {
    236                 $error = -1;
    237             } elseif ( empty( $_POST['bp-groups-description'] ) ) {
    238                 $error = -2;
    239             }
    240         }
    241 
    242         // Enable discussion forum.
    243         $enable_forum   = ( isset( $_POST['group-show-forum'] ) ) ? 1 : 0;
    244 
    245         /**
    246          * Filters the allowed status values for the group.
    247          *
    248          * @since 1.0.2
    249          *
    250          * @param array $value Array of allowed group statuses.
    251          */
    252         $allowed_status = apply_filters( 'groups_allowed_status', array( 'public', 'private', 'hidden' ) );
    253         $status         = ( in_array( $_POST['group-status'], (array) $allowed_status ) ) ? $_POST['group-status'] : 'public';
    254 
    255         /**
    256          * Filters the allowed invite status values for the group.
    257          *
    258          * @since 1.5.0
    259          *
    260          * @param array $value Array of allowed invite statuses.
    261          */
    262         $allowed_invite_status = apply_filters( 'groups_allowed_invite_status', array( 'members', 'mods', 'admins' ) );
    263         $invite_status         = in_array( $_POST['group-invite-status'], (array) $allowed_invite_status ) ? $_POST['group-invite-status'] : 'members';
    264 
    265         if ( !groups_edit_group_settings( $group_id, $enable_forum, $status, $invite_status ) ) {
    266             $error = $group_id;
    267         }
    268 
    269         // Process new members.
    270         $user_names = array();
    271 
    272         if ( ! empty( $_POST['bp-groups-new-members'] ) ) {
    273             $user_names = array_merge( $user_names, explode( ',', $_POST['bp-groups-new-members'] ) );
    274         }
    275 
    276         if ( ! empty( $user_names ) ) {
    277 
    278             foreach( array_values( $user_names ) as $user_name ) {
    279                 $un = trim( $user_name );
    280 
    281                 // Make sure the user exists before attempting
    282                 // to add to the group.
    283                 $user = get_user_by( 'slug', $un );
    284 
    285                 if ( empty( $user ) ) {
    286                     $error_new[] = $un;
    287                 } else {
    288                     if ( ! groups_join_group( $group_id, $user->ID ) ) {
    289                         $error_new[]   = $un;
    290                     } else {
    291                         $success_new[] = $un;
    292                     }
    293                 }
    294             }
    295         }
    296 
    297         // Process member role changes.
    298         if ( ! empty( $_POST['bp-groups-role'] ) && ! empty( $_POST['bp-groups-existing-role'] ) ) {
    299 
    300             // Before processing anything, make sure you're not
    301             // attempting to remove the all user admins.
    302             $admin_count = 0;
    303             foreach ( (array) $_POST['bp-groups-role'] as $new_role ) {
    304                 if ( 'admin' == $new_role ) {
    305                     $admin_count++;
    306                     break;
    307                 }
    308             }
    309 
    310             if ( ! $admin_count ) {
    311 
    312                 $redirect_to = add_query_arg( 'no_admins', 1, $redirect_to );
    313                 $error = $group_id;
    314 
    315             } else {
    316 
    317                 // Process only those users who have had their roles changed.
    318                 foreach ( (array) $_POST['bp-groups-role'] as $user_id => $new_role ) {
    319                     $user_id = (int) $user_id;
    320 
    321                     $existing_role = isset( $_POST['bp-groups-existing-role'][$user_id] ) ? $_POST['bp-groups-existing-role'][$user_id] : '';
    322 
    323                     if ( $existing_role != $new_role ) {
    324                         $result = false;
    325 
    326                         switch ( $new_role ) {
    327                             case 'mod' :
    328                                 // Admin to mod is a demotion. Demote to
    329                                 // member, then fall through.
    330                                 if ( 'admin' == $existing_role ) {
    331                                     groups_demote_member( $user_id, $group_id );
    332                                 }
    333 
    334                             case 'admin' :
    335                                 // If the user was banned, we must
    336                                 // unban first.
    337                                 if ( 'banned' == $existing_role ) {
    338                                     groups_unban_member( $user_id, $group_id );
    339                                 }
    340 
    341                                 // At this point, each existing_role
    342                                 // is a member, so promote.
    343                                 $result = groups_promote_member( $user_id, $group_id, $new_role );
    344 
    345                                 break;
    346 
    347                             case 'member' :
    348 
    349                                 if ( 'admin' == $existing_role || 'mod' == $existing_role ) {
    350                                     $result = groups_demote_member( $user_id, $group_id );
    351                                 } elseif ( 'banned' == $existing_role ) {
    352                                     $result = groups_unban_member( $user_id, $group_id );
    353                                 }
    354 
    355                                 break;
    356 
    357                             case 'banned' :
    358 
    359                                 $result = groups_ban_member( $user_id, $group_id );
    360 
    361                                 break;
    362 
    363                             case 'remove' :
    364 
    365                                 $result = groups_remove_member( $user_id, $group_id );
    366 
    367                                 break;
    368                         }
    369 
    370                         // Store the success or failure.
    371                         if ( $result ) {
    372                             $success_modified[] = $user_id;
    373                         } else {
    374                             $error_modified[]   = $user_id;
    375                         }
    376                     }
    377                 }
    378             }
    379         }
    380 
    381         /**
    382          * Fires before redirect so plugins can do something first on save action.
    383          *
    384          * @since 1.6.0
    385          *
    386          * @param int $group_id ID of the group being edited.
    387          */
    388         do_action( 'bp_group_admin_edit_after', $group_id );
    389 
    390         // Create the redirect URL.
    391         if ( $error ) {
    392             // This means there was an error updating group details.
    393             $redirect_to = add_query_arg( 'error', (int) $error, $redirect_to );
    394         } else {
    395             // Group details were update successfully.
    396             $redirect_to = add_query_arg( 'updated', 1, $redirect_to );
    397         }
    398 
    399         if ( !empty( $success_new ) ) {
    400             $success_new = implode( ',', array_filter( $success_new, 'urlencode' ) );
    401             $redirect_to = add_query_arg( 'success_new', $success_new, $redirect_to );
    402         }
    403 
    404         if ( !empty( $error_new ) ) {
    405             $error_new = implode( ',', array_filter( $error_new, 'urlencode' ) );
    406             $redirect_to = add_query_arg( 'error_new', $error_new, $redirect_to );
    407         }
    408 
    409         if ( !empty( $success_modified ) ) {
    410             $success_modified = implode( ',', array_filter( $success_modified, 'urlencode' ) );
    411             $redirect_to = add_query_arg( 'success_modified', $success_modified, $redirect_to );
    412         }
    413 
    414         if ( !empty( $error_modified ) ) {
    415             $error_modified = implode( ',', array_filter( $error_modified, 'urlencode' ) );
    416             $redirect_to = add_query_arg( 'error_modified', $error_modified, $redirect_to );
    417         }
    418 
    419         /**
    420          * Filters the URL to redirect to after successfully editing a group.
    421          *
    422          * @since 1.7.0
    423          *
    424          * @param string $redirect_to URL to redirect user to.
    425          */
    426         wp_redirect( apply_filters( 'bp_group_admin_edit_redirect', $redirect_to ) );
    427         exit;
    428 
    429 
    430     // If a referrer and a nonce is supplied, but no action, redirect back.
    431     } elseif ( ! empty( $_GET['_wp_http_referer'] ) ) {
    432         wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), stripslashes( $_SERVER['REQUEST_URI'] ) ) );
    433         exit;
    434     }
    435 }
    436 
    437 /**
    438  * Handle save/update of screen options for the Groups component admin screen.
    439  *
    440  * @since 1.7.0
    441  *
    442  * @param string $value     Will always be false unless another plugin filters it first.
    443  * @param string $option    Screen option name.
    444  * @param string $new_value Screen option form value.
    445  * @return string Option value. False to abandon update.
    446  */
    447 function bp_groups_admin_screen_options( $value, $option, $new_value ) {
    448     if ( 'toplevel_page_bp_groups_per_page' != $option && 'toplevel_page_bp_groups_network_per_page' != $option )
    449         return $value;
    450 
    451     // Per page.
    452     $new_value = (int) $new_value;
    453     if ( $new_value < 1 || $new_value > 999 )
    454         return $value;
    455 
    456     return $new_value;
    457 }
    458 
    459 /**
    460  * Select the appropriate Groups admin screen, and output it.
    461  *
    462  * @since 1.7.0
    463  */
    464 function bp_groups_admin() {
    465     // Decide whether to load the index or edit screen.
    466     $doaction = bp_admin_list_table_current_bulk_action();
    467 
    468     // Display the single group edit screen.
    469     if ( 'edit' == $doaction && ! empty( $_GET['gid'] ) ) {
    470         bp_groups_admin_edit();
    471 
    472     // Display the group deletion confirmation screen.
    473     } elseif ( 'delete' == $doaction && ! empty( $_GET['gid'] ) ) {
    474         bp_groups_admin_delete();
    475 
    476     // Otherwise, display the groups index screen.
    477     } else {
    478         bp_groups_admin_index();
    479     }
    480 }
    481 
    482 /**
    483  * Display the single groups edit screen.
    484  *
    485  * @since 1.7.0
    486  */
    487 function bp_groups_admin_edit() {
    488 
    489     if ( ! current_user_can( 'bp_moderate' ) )
    490         die( '-1' );
    491 
    492     $messages = array();
    493 
    494     // If the user has just made a change to a group, build status messages.
    495     if ( !empty( $_REQUEST['no_admins'] ) || ! empty( $_REQUEST['error'] ) || ! empty( $_REQUEST['updated'] ) || ! empty( $_REQUEST['error_new'] ) || ! empty( $_REQUEST['success_new'] ) || ! empty( $_REQUEST['error_modified'] ) || ! empty( $_REQUEST['success_modified'] ) ) {
    496         $no_admins        = ! empty( $_REQUEST['no_admins']        ) ? 1                                             : 0;
    497         $errors           = ! empty( $_REQUEST['error']            ) ? $_REQUEST['error']                            : '';
    498         $updated          = ! empty( $_REQUEST['updated']          ) ? $_REQUEST['updated']                          : '';
    499         $error_new        = ! empty( $_REQUEST['error_new']        ) ? explode( ',', $_REQUEST['error_new'] )        : array();
    500         $success_new      = ! empty( $_REQUEST['success_new']      ) ? explode( ',', $_REQUEST['success_new'] )      : array();
    501         $error_modified   = ! empty( $_REQUEST['error_modified']   ) ? explode( ',', $_REQUEST['error_modified'] )   : array();
    502         $success_modified = ! empty( $_REQUEST['success_modified'] ) ? explode( ',', $_REQUEST['success_modified'] ) : array();
    503 
    504         if ( ! empty( $no_admins ) ) {
    505             $messages[] = __( 'You cannot remove all administrators from a group.', 'buddypress' );
    506         }
    507 
    508         if ( ! empty( $errors ) ) {
    509             switch ( $errors ) {
    510                 case -1 :
    511                     $messages[] = __( 'Group name cannot be empty.', 'buddypress' );
    512                     break;
    513 
    514                 case -2 :
    515                     $messages[] = __( 'Group description cannot be empty.', 'buddypress' );
    516                     break;
    517 
    518                 case -3 :
    519                     $messages[] = __( 'Group name and description cannot be empty.', 'buddypress' );
    520                     break;
    521 
    522                 default :
    523                     $messages[] = __( 'An error occurred when trying to update your group details.', 'buddypress' );
    524                     break;
    525             }
    526 
    527         } elseif ( ! empty( $updated ) ) {
    528             $messages[] = __( 'The group has been updated successfully.', 'buddypress' );
    529         }
    530 
    531         if ( ! empty( $error_new ) ) {
    532             $messages[] = sprintf( __( 'The following users could not be added to the group: %s', 'buddypress' ), '<em>' . esc_html( implode( ', ', $error_new ) ) . '</em>' );
    533         }
    534 
    535         if ( ! empty( $success_new ) ) {
    536             $messages[] = sprintf( __( 'The following users were successfully added to the group: %s', 'buddypress' ), '<em>' . esc_html( implode( ', ', $success_new ) ) . '</em>' );
    537         }
    538 
    539         if ( ! empty( $error_modified ) ) {
    540             $error_modified = bp_groups_admin_get_usernames_from_ids( $error_modified );
    541             $messages[] = sprintf( __( 'An error occurred when trying to modify the following members: %s', 'buddypress' ), '<em>' . esc_html( implode( ', ', $error_modified ) ) . '</em>' );
    542         }
    543 
    544         if ( ! empty( $success_modified ) ) {
    545             $success_modified = bp_groups_admin_get_usernames_from_ids( $success_modified );
    546             $messages[] = sprintf( __( 'The following members were successfully modified: %s', 'buddypress' ), '<em>' . esc_html( implode( ', ', $success_modified ) ) . '</em>' );
    547         }
    548     }
    549 
    550     $is_error = ! empty( $no_admins ) || ! empty( $errors ) || ! empty( $error_new ) || ! empty( $error_modified );
    551 
    552     // Get the group from the database.
    553     $group      = groups_get_group( 'group_id=' . (int) $_GET['gid'] );
    554 
    555     /** This filter is documented in bp-groups/bp-groups-template.php */
    556     $group_name = isset( $group->name ) ? apply_filters( 'bp_get_group_name', $group->name ) : '';
    557 
    558     // Construct URL for form.
    559     $form_url = remove_query_arg( array( 'action', 'deleted', 'no_admins', 'error', 'error_new', 'success_new', 'error_modified', 'success_modified' ), $_SERVER['REQUEST_URI'] );
    560     $form_url = add_query_arg( 'action', 'save', $form_url );
    561 
    562     /**
    563      * Fires before the display of the edit form.
    564      *
    565      * Useful for plugins to modify the group before display.
    566      *
    567      * @since 1.7.0
    568      *
    569      * @param BP_Groups_Group $this Instance of the current group being edited. Passed by reference.
    570      */
    571     do_action_ref_array( 'bp_groups_admin_edit', array( &$group ) ); ?>
    572 
    573     <div class="wrap">
    574         <h1><?php _e( 'Edit Group', 'buddypress' ); ?>
    575 
    576             <?php if ( is_user_logged_in() && bp_user_can_create_groups() ) : ?>
    577                 <a class="add-new-h2" href="<?php echo trailingslashit( bp_get_groups_directory_permalink() . 'create' ); ?>"><?php _e( 'Add New', 'buddypress' ); ?></a>
    578             <?php endif; ?>
    579 
    580         </h1>
    581 
    582         <?php // If the user has just made a change to an group, display the status messages. ?>
    583         <?php if ( !empty( $messages ) ) : ?>
    584             <div id="moderated" class="<?php echo ( $is_error ) ? 'error' : 'updated'; ?>"><p><?php echo implode( "</p><p>", $messages ); ?></p></div>
    585         <?php endif; ?>
    586 
    587         <?php if ( ! empty( $group ) ) : ?>
    588 
    589             <form action="<?php echo esc_url( $form_url ); ?>" id="bp-groups-edit-form" method="post">
    590                 <div id="poststuff">
    591 
    592                     <div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>">
    593                         <div id="post-body-content">
    594                             <div id="postdiv">
    595                                 <div id="bp_groups_name" class="postbox">
    596                                     <h2><?php _e( 'Name and Description', 'buddypress' ); ?></h2>
    597                                     <div class="inside">
    598                                         <label for="bp-groups-name" class="screen-reader-text"><?php _e( 'Group Name', 'buddypress' ); ?></label>
    599                                         <input type="text" name="bp-groups-name" id="bp-groups-name" value="<?php echo esc_attr( stripslashes( $group_name ) ) ?>" />
    600                                         <div id="bp-groups-permalink-box">
    601                                             <strong><?php esc_html_e( 'Permalink:', 'buddypress' ) ?></strong> <span id="sample-permalink"><?php bp_group_permalink( $group ) ?></span> <a href="<?php echo bp_group_permalink( $group ) ?>" class="button button-small" id="bp-groups-visit-group"><?php esc_html_e( 'Visit Group', 'buddypress' ) ?></a>
    602                                         </div>
    603 
    604                                         <label for="bp-groups-description" class="screen-reader-text"><?php _e( 'Group Description', 'buddypress' ); ?></label>
    605                                         <?php wp_editor( stripslashes( $group->description ), 'bp-groups-description', array( 'media_buttons' => false, 'teeny' => true, 'textarea_rows' => 5, 'quicktags' => array( 'buttons' => 'strong,em,link,block,del,ins,img,code,spell,close' ) ) ); ?>
    606                                     </div>
    607                                 </div>
    608                             </div>
    609                         </div><!-- #post-body-content -->
    610 
    611                         <div id="postbox-container-1" class="postbox-container">
    612                             <?php do_meta_boxes( get_current_screen()->id, 'side', $group ); ?>
    613                         </div>
    614 
    615                         <div id="postbox-container-2" class="postbox-container">
    616                             <?php do_meta_boxes( get_current_screen()->id, 'normal', $group ); ?>
    617                             <?php do_meta_boxes( get_current_screen()->id, 'advanced', $group ); ?>
    618                         </div>
    619                     </div><!-- #post-body -->
    620 
    621                 </div><!-- #poststuff -->
    622                 <?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?>
    623                 <?php wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); ?>
    624                 <?php wp_nonce_field( 'edit-group_' . $group->id ); ?>
    625             </form>
    626 
    627         <?php else : ?>
    628             <p><?php printf( __( 'No group found with this ID. <a href="%s">Go back and try again</a>.', 'buddypress' ), esc_url( bp_get_admin_url( 'admin.php?page=bp-groups' ) ) ); ?></p>
    629         <?php endif; ?>
    630 
    631     </div><!-- .wrap -->
    632 
    633 <?php
    634 }
    635 
    636 /**
    637  * Display the Group delete confirmation screen.
    638  *
    639  * We include a separate confirmation because group deletion is truly
    640  * irreversible.
    641  *
    642  * @since 1.7.0
    643  */
    644 function bp_groups_admin_delete() {
    645 
    646     if ( ! bp_current_user_can( 'bp_moderate' ) ) {
    647         die( '-1' );
    648     }
    649 
    650     $group_ids = isset( $_REQUEST['gid'] ) ? $_REQUEST['gid'] : 0;
    651     if ( ! is_array( $group_ids ) ) {
    652         $group_ids = explode( ',', $group_ids );
    653     }
    654     $group_ids = wp_parse_id_list( $group_ids );
    655     $groups    = groups_get_groups( array(
    656         'include'     => $group_ids,
    657         'show_hidden' => true,
    658         'per_page'    => null, // Return all results.
    659     ) );
    660 
    661     // Create a new list of group ids, based on those that actually exist.
    662     $gids = array();
    663     foreach ( $groups['groups'] as $group ) {
    664         $gids[] = $group->id;
    665     }
    666 
    667     $base_url  = remove_query_arg( array( 'action', 'action2', 'paged', 's', '_wpnonce', 'gid' ), $_SERVER['REQUEST_URI'] ); ?>
    668 
    669     <div class="wrap">
    670         <h1><?php _e( 'Delete Groups', 'buddypress' ) ?></h1>
    671         <p><?php _e( 'You are about to delete the following groups:', 'buddypress' ) ?></p>
    672 
    673         <ul class="bp-group-delete-list">
    674         <?php foreach ( $groups['groups'] as $group ) : ?>
    675             <li><?php echo esc_html( $group->name ) ?></li>
    676         <?php endforeach; ?>
    677         </ul>
    678 
    679         <p><strong><?php _e( 'This action cannot be undone.', 'buddypress' ) ?></strong></p>
    680 
    681         <a class="button-primary" href="<?php echo esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'do_delete', 'gid' => implode( ',', $gids ) ), $base_url ), 'bp-groups-delete' ) ); ?>"><?php _e( 'Delete Permanently', 'buddypress' ) ?></a>
    682         <a class="button" href="<?php echo esc_attr( $base_url ); ?>"><?php _e( 'Cancel', 'buddypress' ) ?></a>
    683     </div>
    684 
    685     <?php
    686 }
    687 
    688 /**
    689  * Display the Groups admin index screen.
    690  *
    691  * This screen contains a list of all BuddyPress groups.
    692  *
    693  * @since 1.7.0
    694  *
    695  * @global BP_Groups_List_Table $bp_groups_list_table Group screen list table.
    696  * @global string $plugin_page Currently viewed plugin page.
    697  */
    698 function bp_groups_admin_index() {
    699     global $bp_groups_list_table, $plugin_page;
    700 
    701     $messages = array();
    702 
    703     // If the user has just made a change to a group, build status messages.
    704     if ( ! empty( $_REQUEST['deleted'] ) ) {
    705         $deleted  = ! empty( $_REQUEST['deleted'] ) ? (int) $_REQUEST['deleted'] : 0;
    706 
    707         if ( $deleted > 0 ) {
    708             $messages[] = sprintf( _n( '%s group has been permanently deleted.', '%s groups have been permanently deleted.', $deleted, 'buddypress' ), number_format_i18n( $deleted ) );
    709         }
    710     }
    711 
    712     // Prepare the group items for display.
    713     $bp_groups_list_table->prepare_items();
    714 
    715     /**
    716      * Fires before the display of messages for the edit form.
    717      *
    718      * Useful for plugins to modify the messages before display.
    719      *
    720      * @since 1.7.0
    721      *
    722      * @param array $messages Array of messages to be displayed.
    723      */
    724     do_action( 'bp_groups_admin_index', $messages ); ?>
    725 
    726     <div class="wrap">
    727         <h1>
    728             <?php _e( 'Groups', 'buddypress' ); ?>
    729 
    730             <?php if ( is_user_logged_in() && bp_user_can_create_groups() ) : ?>
    731                 <a class="add-new-h2" href="<?php echo trailingslashit( bp_get_groups_directory_permalink() . 'create' ); ?>"><?php _e( 'Add New', 'buddypress' ); ?></a>
    732             <?php endif; ?>
    733 
    734             <?php if ( !empty( $_REQUEST['s'] ) ) : ?>
    735                 <span class="subtitle"><?php printf( __( 'Search results for &#8220;%s&#8221;', 'buddypress' ), wp_html_excerpt( esc_html( stripslashes( $_REQUEST['s'] ) ), 50 ) ); ?></span>
    736             <?php endif; ?>
    737         </h1>
    738 
    739         <?php // If the user has just made a change to an group, display the status messages. ?>
    740         <?php if ( !empty( $messages ) ) : ?>
    741             <div id="moderated" class="<?php echo ( ! empty( $_REQUEST['error'] ) ) ? 'error' : 'updated'; ?>"><p><?php echo implode( "<br/>\n", $messages ); ?></p></div>
    742         <?php endif; ?>
    743 
    744         <?php // Display each group on its own row. ?>
    745         <?php $bp_groups_list_table->views(); ?>
    746 
    747         <form id="bp-groups-form" action="" method="get">
    748             <?php $bp_groups_list_table->search_box( __( 'Search all Groups', 'buddypress' ), 'bp-groups' ); ?>
    749             <input type="hidden" name="page" value="<?php echo esc_attr( $plugin_page ); ?>" />
    750             <?php $bp_groups_list_table->display(); ?>
    751         </form>
    752 
    753     </div>
    754 
    755 <?php
    756 }
    757 
    758 /**
    759  * Markup for the single group's Settings metabox.
    760  *
    761  * @since 1.7.0
    762  *
    763  * @param object $item Information about the current group.
    764  */
    765 function bp_groups_admin_edit_metabox_settings( $item ) {
    766 
    767     $invite_status = groups_get_groupmeta( $item->id, 'invite_status' ); ?>
    768 
    769     <?php if ( bp_is_active( 'forums' ) ) : ?>
    770         <div class="bp-groups-settings-section" id="bp-groups-settings-section-forum">
    771             <label for="group-show-forum"><input type="checkbox" name="group-show-forum" id="group-show-forum" <?php checked( $item->enable_forum ) ?> /> <?php _e( 'Enable discussion forum', 'buddypress' ) ?><br />
    772         </div>
    773     <?php endif; ?>
    774 
    775     <div class="bp-groups-settings-section" id="bp-groups-settings-section-status">
    776         <fieldset>
    777             <legend><?php _e( 'Privacy', 'buddypress' ); ?></legend>
    778 
    779             <ul>
    780                 <li><input type="radio" name="group-status" id="bp-group-status-public" value="public" <?php checked( $item->status, 'public' ) ?> /><label for="bp-group-status-public"><?php _e( 'Public', 'buddypress' ) ?></label></li>
    781                 <li><input type="radio" name="group-status" id="bp-group-status-private" value="private" <?php checked( $item->status, 'private' ) ?> /><label for="bp-group-status-private"><?php _e( 'Private', 'buddypress' ) ?></label></li>
    782                 <li><input type="radio" name="group-status" id="bp-group-status-hidden" value="hidden" <?php checked( $item->status, 'hidden' ) ?> /><label for="bp-group-status-hidden"><?php _e( 'Hidden', 'buddypress' ) ?></label></li>
    783             </ul>
    784         </fieldset>
    785     </div>
    786 
    787     <div class="bp-groups-settings-section" id="bp-groups-settings-section-invite-status">
    788         <fieldset>
    789             <legend><?php _e( 'Who can invite others to this group?', 'buddypress' ); ?></legend>
    790 
    791             <ul>
    792                 <li><input type="radio" name="group-invite-status" id="bp-group-invite-status-members" value="members" <?php checked( $invite_status, 'members' ) ?> /><label for="bp-group-invite-status-members"><?php _e( 'All group members', 'buddypress' ) ?></label></li>
    793                 <li><input type="radio" name="group-invite-status" id="bp-group-invite-status-mods" value="mods" <?php checked( $invite_status, 'mods' ) ?> /><label for="bp-group-invite-status-mods"><?php _e( 'Group admins and mods only', 'buddypress' ) ?></label></li>
    794                 <li><input type="radio" name="group-invite-status" id="bp-group-invite-status-admins" value="admins" <?php checked( $invite_status, 'admins' ) ?> /><label for="bp-group-invite-status-admins"><?php _e( 'Group admins only', 'buddypress' ) ?></label></li>
    795             </ul>
    796         </fieldset>
    797     </div>
    798 
    799 <?php
    800 }
    801 
    802 /**
    803  * Output the markup for a single group's Add New Members metabox.
    804  *
    805  * @since 1.7.0
    806  *
    807  * @param BP_Groups_Group $item The BP_Groups_Group object for the current group.
    808  */
    809 function bp_groups_admin_edit_metabox_add_new_members( $item ) {
    810     ?>
    811 
    812     <label for="bp-groups-new-members" class="screen-reader-text"><?php _e( 'Add new members', 'buddypress' ); ?></label>
    813     <input name="bp-groups-new-members" id="bp-groups-new-members" class="bp-suggest-user" placeholder="<?php esc_attr_e( 'Enter a comma-separated list of user logins.', 'buddypress' ) ?>" />
    814     <ul id="bp-groups-new-members-list"></ul>
    815     <?php
    816 }
    817 
    818 /**
    819  * Renders the Members metabox on single group pages.
    820  *
    821  * @since 1.7.0
    822  *
    823  * @param BP_Groups_Group $item The BP_Groups_Group object for the current group.
    824  */
    825 function bp_groups_admin_edit_metabox_members( $item ) {
    826 
    827     // Pull up a list of group members, so we can separate out the types
    828     // We'll also keep track of group members here to place them into a
    829     // JavaScript variable, which will help with group member autocomplete.
    830     $members = array(
    831         'admin'  => array(),
    832         'mod'    => array(),
    833         'member' => array(),
    834         'banned' => array(),
    835     );
    836 
    837     $pagination = array(
    838         'admin'  => array(),
    839         'mod'    => array(),
    840         'member' => array(),
    841         'banned' => array(),
    842     );
    843 
    844     foreach ( $members as $type => &$member_type_users ) {
    845         $page_qs_key       = $type . '_page';
    846         $current_type_page = isset( $_GET[ $page_qs_key ] ) ? absint( $_GET[ $page_qs_key ] ) : 1;
    847         $member_type_query = new BP_Group_Member_Query( array(
    848             'group_id'   => $item->id,
    849             'group_role' => array( $type ),
    850             'type'       => 'alphabetical',
    851             'per_page'   => 10,
    852             'page'       => $current_type_page,
    853         ) );
    854 
    855         $member_type_users   = $member_type_query->results;
    856         $pagination[ $type ] = bp_groups_admin_create_pagination_links( $member_type_query, $type );
    857     }
    858 
    859     // Echo out the JavaScript variable.
    860     echo '<script type="text/javascript">var group_id = "' . esc_js( $item->id ) . '";</script>';
    861 
    862     // Loop through each member type.
    863     foreach ( $members as $member_type => $type_users ) : ?>
    864 
    865         <div class="bp-groups-member-type" id="bp-groups-member-type-<?php echo esc_attr( $member_type ) ?>">
    866 
    867             <h3><?php switch ( $member_type ) :
    868                     case 'admin'  : esc_html_e( 'Administrators', 'buddypress' ); break;
    869                     case 'mod'    : esc_html_e( 'Moderators',     'buddypress' ); break;
    870                     case 'member' : esc_html_e( 'Members',        'buddypress' ); break;
    871                     case 'banned' : esc_html_e( 'Banned Members', 'buddypress' ); break;
    872             endswitch; ?></h3>
    873 
    874             <div class="bp-group-admin-pagination table-top">
    875                 <?php echo $pagination[ $member_type ] ?>
    876             </div>
    877 
    878         <?php if ( !empty( $type_users ) ) : ?>
    879 
    880             <table class="widefat bp-group-members">
    881                 <thead>
    882                     <tr>
    883                         <th scope="col" class="uid-column"><?php _ex( 'ID', 'Group member user_id in group admin', 'buddypress' ); ?></th>
    884                         <th scope="col" class="uname-column"><?php _ex( 'Name', 'Group member name in group admin', 'buddypress' ); ?></th>
    885                         <th scope="col" class="urole-column"><?php _ex( 'Group Role', 'Group member role in group admin', 'buddypress' ); ?></th>
    886                     </tr>
    887                 </thead>
    888 
    889                 <tbody>
    890 
    891                 <?php foreach ( $type_users as $type_user ) : ?>
    892                     <tr>
    893                         <th scope="row" class="uid-column"><?php echo esc_html( $type_user->ID ); ?></th>
    894 
    895                         <td class="uname-column">
    896                             <a style="float: left;" href="<?php echo bp_core_get_user_domain( $type_user->ID ); ?>"><?php echo bp_core_fetch_avatar( array(
    897                                 'item_id' => $type_user->ID,
    898                                 'width'   => '32',
    899                                 'height'  => '32'
    900                             ) ); ?></a>
    901 
    902                             <span style="margin: 8px; float: left;"><?php echo bp_core_get_userlink( $type_user->ID ); ?></span>
    903                         </td>
    904 
    905                         <td class="urole-column">
    906                             <label for="bp-groups-role-<?php echo esc_attr( $type_user->ID ); ?>" class="screen-reader-text"><?php _e( 'Select group role for member', 'buddypress' ); ?></label>
    907                             <select class="bp-groups-role" id="bp-groups-role-<?php echo esc_attr( $type_user->ID ); ?>" name="bp-groups-role[<?php echo esc_attr( $type_user->ID ); ?>]">
    908                                 <optgroup label="<?php esc_attr_e( 'Roles', 'buddypress' ); ?>">
    909                                     <option class="admin"  value="admin"  <?php selected( 'admin',  $member_type ); ?>><?php esc_html_e( 'Administrator', 'buddypress' ); ?></option>
    910                                     <option class="mod"    value="mod"    <?php selected( 'mod',    $member_type ); ?>><?php esc_html_e( 'Moderator',     'buddypress' ); ?></option>
    911                                     <option class="member" value="member" <?php selected( 'member', $member_type ); ?>><?php esc_html_e( 'Member',        'buddypress' ); ?></option>
    912                                     <?php if ( 'banned' === $member_type ) : ?>
    913                                     <option class="banned" value="banned" <?php selected( 'banned', $member_type ); ?>><?php esc_html_e( 'Banned',        'buddypress' ); ?></option>
    914                                     <?php endif; ?>
    915                                 </optgroup>
    916                                 <optgroup label="<?php esc_attr_e( 'Actions', 'buddypress' ); ?>">
    917                                     <option class="remove" value="remove"><?php esc_html_e( 'Remove', 'buddypress' ); ?></option>
    918                                     <?php if ( 'banned' !== $member_type ) : ?>
    919                                         <option class="banned" value="banned"><?php esc_html_e( 'Ban', 'buddypress' ); ?></option>
    920                                     <?php endif; ?>
    921                                 </optgroup>
    922                             </select>
    923 
    924                             <?php
    925                             /**
    926                              * Store the current role for this user,
    927                              * so we can easily detect changes.
    928                              *
    929                              * @todo remove this, and do database detection on save
    930                              */
    931                             ?>
    932                             <input type="hidden" name="bp-groups-existing-role[<?php echo esc_attr( $type_user->ID ); ?>]" value="<?php echo esc_attr( $member_type ); ?>" />
    933                         </td>
    934                     </tr>
    935 
    936                     <?php if ( has_filter( 'bp_groups_admin_manage_member_row' ) ) : ?>
    937                         <tr>
    938                             <td colspan="3">
    939                                 <?php
    940 
    941                                 /**
    942                                  * Fires after the listing of a single row for members in a group on the group edit screen.
    943                                  *
    944                                  * @since 1.8.0
    945                                  *
    946                                  * @param int             $ID   ID of the user being rendered.
    947                                  * @param BP_Groups_Group $item Object for the current group.
    948                                  */
    949                                 do_action( 'bp_groups_admin_manage_member_row', $type_user->ID, $item ); ?>
    950                             </td>
    951                         </tr>
    952                     <?php endif; ?>
    953 
    954                 <?php endforeach; ?>
    955 
    956                 </tbody>
    957             </table>
    958 
    959             <div class="bp-group-admin-pagination table-bottom">
    960                 <?php echo $pagination[ $member_type ]; ?>
    961             </div>
    962 
    963         <?php else : ?>
    964 
    965             <p class="bp-groups-no-members description"><?php esc_html_e( 'No members of this type', 'buddypress' ); ?></p>
    966 
    967         <?php endif; ?>
    968 
    969         </div><!-- .bp-groups-member-type -->
    970 
    971     <?php endforeach;
    972 }
    973 
    974 /**
    975  * Renders the Status metabox for the Groups admin edit screen.
    976  *
    977  * @since 1.7.0
    978  *
    979  * @param object $item Information about the currently displayed group.
    980  */
    981 function bp_groups_admin_edit_metabox_status( $item ) {
    982     $base_url = add_query_arg( array(
    983         'page' => 'bp-groups',
    984         'gid'  => $item->id
    985     ), bp_get_admin_url( 'admin.php' ) ); ?>
    986 
    987     <div id="submitcomment" class="submitbox">
    988         <div id="major-publishing-actions">
    989             <div id="delete-action">
    990                 <a class="submitdelete deletion" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'action', 'delete', $base_url ), 'bp-groups-delete' ) ); ?>"><?php _e( 'Delete Group', 'buddypress' ) ?></a>
    991             </div>
    992 
    993             <div id="publishing-action">
    994                 <?php submit_button( __( 'Save Changes', 'buddypress' ), 'primary', 'save', false ); ?>
    995             </div>
    996             <div class="clear"></div>
    997         </div><!-- #major-publishing-actions -->
    998     </div><!-- #submitcomment -->
    999 
    1000 <?php
    1001 }
    1002 
    1003 /**
    1004  * Create pagination links out of a BP_Group_Member_Query.
    1005  *
    1006  * This function is intended to create pagination links for use under the
    1007  * Manage Members section of the Groups Admin Dashboard pages. It is a stopgap
    1008  * measure until a more general pagination solution is in place for BuddyPress.
    1009  * Plugin authors should not use this function, as it is likely to be
    1010  * deprecated soon.
    1011  *
    1012  * @since 1.8.0
    1013  *
    1014  * @param BP_Group_Member_Query $query       A BP_Group_Member_Query object.
    1015  * @param string                $member_type member|mod|admin|banned.
    1016  * @return string Pagination links HTML.
    1017  */
    1018 function bp_groups_admin_create_pagination_links( BP_Group_Member_Query $query, $member_type ) {
    1019     $pagination = '';
    1020 
    1021     if ( ! in_array( $member_type, array( 'admin', 'mod', 'member', 'banned' ) ) ) {
    1022         return $pagination;
    1023     }
    1024 
    1025     // The key used to paginate this member type in the $_GET global.
    1026     $qs_key = $member_type . '_page';
    1027     $url_base = remove_query_arg( array( $qs_key, 'updated', 'success_modified' ), $_SERVER['REQUEST_URI'] );
    1028 
    1029     $page     = isset( $_GET[ $qs_key ] ) ? absint( $_GET[ $qs_key ] ) : 1;
    1030     $per_page = 10; // @todo Make this customizable?
    1031 
    1032     // Don't show anything if there's no pagination.
    1033     if ( 1 === $page && $query->total_users <= $per_page ) {
    1034         return $pagination;
    1035     }
    1036 
    1037     $current_page_start = ( ( $page - 1 ) * $per_page ) + 1;
    1038     $current_page_end   = $page * $per_page > intval( $query->total_users ) ? $query->total_users : $page * $per_page;
    1039 
    1040     $pag_links = paginate_links( array(
    1041         'base'      => add_query_arg( $qs_key, '%#%', $url_base ),
    1042         'format'    => '',
    1043         'prev_text' => __( '&laquo;', 'buddypress' ),
    1044         'next_text' => __( '&raquo;', 'buddypress' ),
    1045         'total'     => ceil( $query->total_users / $per_page ),
    1046         'current'   => $page,
    1047     ) );
    1048 
    1049     if ( 1 == $query->total_users ) {
    1050         $viewing_text = __( 'Viewing 1 member', 'buddypress' );
    1051     } else {
    1052         $viewing_text = sprintf(
    1053             _n( 'Viewing %1$s - %2$s of %3$s member', 'Viewing %1$s - %2$s of %3$s members', $query->total_users, 'buddypress' ),
    1054             bp_core_number_format( $current_page_start ),
    1055             bp_core_number_format( $current_page_end ),
    1056             bp_core_number_format( $query->total_users )
    1057         );
    1058     }
    1059 
    1060     $pagination .= '<span class="bp-group-admin-pagination-viewing">' . $viewing_text . '</span>';
    1061     $pagination .= '<span class="bp-group-admin-pagination-links">' . $pag_links . '</span>';
    1062 
    1063     return $pagination;
    1064 }
    1065 
    1066 /**
    1067  * Get a set of usernames corresponding to a set of user IDs.
    1068  *
    1069  * @since 1.7.0
    1070  *
    1071  * @param array $user_ids Array of user IDs.
    1072  * @return array Array of user_logins corresponding to $user_ids.
    1073  */
    1074 function bp_groups_admin_get_usernames_from_ids( $user_ids = array() ) {
    1075 
    1076     $usernames = array();
    1077     $users     = new WP_User_Query( array( 'blog_id' => 0, 'include' => $user_ids ) );
    1078 
    1079     foreach ( (array) $users->results as $user ) {
    1080         $usernames[] = $user->user_login;
    1081     }
    1082 
    1083     return $usernames;
    1084 }
    1085 
    1086 /**
    1087  * AJAX handler for group member autocomplete requests.
    1088  *
    1089  * @since 1.7.0
    1090  */
    1091 function bp_groups_admin_autocomplete_handler() {
    1092 
    1093     // Bail if user user shouldn't be here, or is a large network.
    1094     if ( ! current_user_can( 'bp_moderate' ) || ( is_multisite() && wp_is_large_network( 'users' ) ) ) {
    1095         wp_die( -1 );
    1096     }
    1097 
    1098     $term     = isset( $_GET['term'] )     ? sanitize_text_field( $_GET['term'] ) : '';
    1099     $group_id = isset( $_GET['group_id'] ) ? absint( $_GET['group_id'] )          : 0;
    1100 
    1101     if ( ! $term || ! $group_id ) {
    1102         wp_die( -1 );
    1103     }
    1104 
    1105     $suggestions = bp_core_get_suggestions( array(
    1106         'group_id' => -$group_id,  // A negative value will exclude this group's members from the suggestions.
    1107         'limit'    => 10,
    1108         'term'     => $term,
    1109         'type'     => 'members',
    1110     ) );
    1111 
    1112     $matches = array();
    1113 
    1114     if ( $suggestions && ! is_wp_error( $suggestions ) ) {
    1115         foreach ( $suggestions as $user ) {
    1116 
    1117             $matches[] = array(
    1118                 // Translators: 1: user_login, 2: user_email.
    1119                 'label' => sprintf( __( '%1$s (%2$s)', 'buddypress' ), $user->name, $user->ID ),
    1120                 'value' => $user->ID,
    1121             );
    1122         }
    1123     }
    1124 
    1125     wp_die( json_encode( $matches ) );
    1126 }
    1127 add_action( 'wp_ajax_bp_group_admin_member_autocomplete', 'bp_groups_admin_autocomplete_handler' );
    112815
    112916/**
  • trunk/src/bp-groups/classes/class-bp-groups-memberships-requests-template.php

    r10515 r10520  
    11<?php
    22/**
    3  * BuddyPress Groups Template Functions.
     3 * BuddyPress Groups membership request template loop class.
    44 *
    55 * @package BuddyPress
    6  * @subpackage GroupsTemplates
    7  * @since 1.5.0
     6 * @since 1.0.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
    3977  *
    3978  * @since 1.0.0
    3979  */
    3980 class BP_Groups_Group_Members_Template {
    3981 
    3982     /**
    3983      * @since 1.0.0
    3984      * @var int
    3985      */
    3986     public $current_member = -1;
    3987 
    3988     /**
    3989      * @since 1.0.0
    3990      * @var int
    3991      */
    3992     public $member_count;
    3993 
    3994     /**
    3995      * @since 1.0.0
    3996      * @var array
    3997      */
    3998     public $members;
    3999 
    4000     /**
    4001      * @since 1.0.0
    4002      * @var object
    4003      */
    4004     public $member;
    4005 
    4006     /**
    4007      * @since 1.0.0
    4008      * @var bool
    4009      */
    4010     public $in_the_loop;
    4011 
    4012     /**
    4013      * @since 1.0.0
    4014      * @var int
    4015      */
    4016     public $pag_page;
    4017 
    4018     /**
    4019      * @since 1.0.0
    4020      * @var int
    4021      */
    4022     public $pag_num;
    4023 
    4024     /**
    4025      * @since 1.0.0
    4026      * @var array|string|void
    4027      */
    4028     public $pag_links;
    4029 
    4030     /**
    4031      * @since 1.0.0
    4032      * @var int
    4033      */
    4034     public $total_group_count;
    4035 
    4036     /**
    4037      * Constructor.
    4038      *
    4039      * @since 1.5.0
    4040      *
    4041      * @param array $args {
    4042      *     An array of optional arguments.
    4043      *     @type int      $group_id           ID of the group whose members are being
    4044      *                                        queried. Default: current group ID.
    4045      *     @type int      $page               Page of results to be queried. Default: 1.
    4046      *     @type int      $per_page           Number of items to return per page of
    4047      *                                        results. Default: 20.
    4048      *     @type int      $max                Optional. Max number of items to return.
    4049      *     @type array    $exclude            Optional. Array of user IDs to exclude.
    4050      *     @type bool|int $exclude_admin_mods True (or 1) to exclude admins and mods from
    4051      *                                        results. Default: 1.
    4052      *     @type bool|int $exclude_banned     True (or 1) to exclude banned users from results.
    4053      *                                        Default: 1.
    4054      *     @type array    $group_role         Optional. Array of group roles to include.
    4055      *     @type string   $search_terms       Optional. Search terms to match.
    4056      * }
    4057      */
    4058     public function __construct( $args = array() ) {
    4059 
    4060         // Backward compatibility with old method of passing arguments.
    4061         if ( ! is_array( $args ) || func_num_args() > 1 ) {
    4062             _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__ ) );
    4063 
    4064             $old_args_keys = array(
    4065                 0 => 'group_id',
    4066                 1 => 'per_page',
    4067                 2 => 'max',
    4068                 3 => 'exclude_admins_mods',
    4069                 4 => 'exclude_banned',
    4070                 5 => 'exclude',
    4071                 6 => 'group_role',
    4072             );
    4073 
    4074             $func_args = func_get_args();
    4075             $args      = bp_core_parse_args_array( $old_args_keys, $func_args );
    4076         }
    4077 
    4078         $r = wp_parse_args( $args, array(
    4079             'group_id'            => bp_get_current_group_id(),
    4080             'page'                => 1,
    4081             'per_page'            => 20,
    4082             'page_arg'            => 'mlpage',
    4083             'max'                 => false,
    4084             'exclude'             => false,
    4085             'exclude_admins_mods' => 1,
    4086             'exclude_banned'      => 1,
    4087             'group_role'          => false,
    4088             'search_terms'        => false,
    4089             'type'                => 'last_joined',
    4090         ) );
    4091 
    4092         $this->pag_arg  = sanitize_key( $r['page_arg'] );
    4093         $this->pag_page = bp_sanitize_pagination_arg( $this->pag_arg, $r['page']     );
    4094         $this->pag_num  = bp_sanitize_pagination_arg( 'num',          $r['per_page'] );
    4095 
    4096         /**
    4097          * Check the current group is the same as the supplied group ID.
    4098          * It can differ when using {@link bp_group_has_members()} outside the Groups screens.
    4099          */
    4100         $current_group = groups_get_current_group();
    4101         if ( empty( $current_group ) || ( $current_group && $current_group->id !== bp_get_current_group_id() ) ) {
    4102             $current_group = groups_get_group( array( 'group_id' => $r['group_id'] ) );
    4103         }
    4104 
    4105         // Assemble the base URL for pagination.
    4106         $base_url = trailingslashit( bp_get_group_permalink( $current_group ) . bp_current_action() );
    4107         if ( bp_action_variable() ) {
    4108             $base_url = trailingslashit( $base_url . bp_action_variable() );
    4109         }
    4110 
    4111         $members_args = $r;
    4112 
    4113         $members_args['page']     = $this->pag_page;
    4114         $members_args['per_page'] = $this->pag_num;
    4115 
    4116         // Get group members for this loop.
    4117         $this->members = groups_get_group_members( $members_args );
    4118 
    4119         if ( empty( $r['max'] ) || ( $r['max'] >= (int) $this->members['count'] ) ) {
    4120             $this->total_member_count = (int) $this->members['count'];
    4121         } else {
    4122             $this->total_member_count = (int) $r['max'];
    4123         }
    4124 
    4125         // Reset members array for subsequent looping.
    4126         $this->members = $this->members['members'];
    4127 
    4128         if ( empty( $r['max'] ) || ( $r['max'] >= count( $this->members ) ) ) {
    4129             $this->member_count = (int) count( $this->members );
    4130         } else {
    4131             $this->member_count = (int) $r['max'];
    4132         }
    4133 
    4134         $this->pag_links = paginate_links( array(
    4135             'base'      => add_query_arg( array( $this->pag_arg => '%#%' ), $base_url ),
    4136             'format'    => '',
    4137             'total'     => ! empty( $this->pag_num ) ? ceil( $this->total_member_count / $this->pag_num ) : $this->total_member_count,
    4138             'current'   => $this->pag_page,
    4139             'prev_text' => '&larr;',
    4140             'next_text' => '&rarr;',
    4141             'mid_size'  => 1,
    4142             'add_args'  => array(),
    4143         ) );
    4144     }
    4145 
    4146     /**
    4147      * Whether or not there are members to display.
    4148      *
    4149      * @since 1.0.0
    4150      *
    4151      * @return bool
    4152      */
    4153     public function has_members() {
    4154         if ( ! empty( $this->member_count ) ) {
    4155             return true;
    4156         }
    4157 
    4158         return false;
    4159     }
    4160 
    4161     /**
    4162      * Increments to the next member to display.
    4163      *
    4164      * @since 1.0.0
    4165      *
    4166      * @return object
    4167      */
    4168     public function next_member() {
    4169         $this->current_member++;
    4170         $this->member = $this->members[ $this->current_member ];
    4171 
    4172         return $this->member;
    4173     }
    4174 
    4175     /**
    4176      * Rewinds to the first member to display.
    4177      *
    4178      * @since 1.0.0
    4179      */
    4180     public function rewind_members() {
    4181         $this->current_member = -1;
    4182         if ( $this->member_count > 0 ) {
    4183             $this->member = $this->members[0];
    4184         }
    4185     }
    4186 
    4187     /**
    4188      * Finishes up the members for display.
    4189      *
    4190      * @since 1.0.0
    4191      *
    4192      * @return bool
    4193      */
    4194     public function members() {
    4195         $tick = intval( $this->current_member + 1 );
    4196         if ( $tick < $this->member_count ) {
    4197             return true;
    4198         } elseif ( $tick == $this->member_count ) {
    4199 
    4200             /**
    4201              * Fires right before the rewinding of members list.
    4202              *
    4203              * @since 1.0.0
    4204              * @since 2.3.0 `$this` parameter added.
    4205              *
    4206              * @param BP_Groups_Group_Members_Template $this Instance of the current Members template.
    4207              */
    4208             do_action( 'loop_end', $this );
    4209 
    4210             // Do some cleaning up after the loop.
    4211             $this->rewind_members();
    4212         }
    4213 
    4214         $this->in_the_loop = false;
    4215         return false;
    4216     }
    4217 
    4218     /**
    4219      * Sets up the member to display.
    4220      *
    4221      * @since 1.0.0
    4222      */
    4223     public function the_member() {
    4224         $this->in_the_loop = true;
    4225         $this->member      = $this->next_member();
    4226 
    4227         // Loop has just started.
    4228         if ( 0 == $this->current_member ) {
    4229 
    4230             /**
    4231              * Fires if the current member item is the first in the members list.
    4232              *
    4233              * @since 1.0.0
    4234              * @since 2.3.0 `$this` parameter added.
    4235              *
    4236              * @param BP_Groups_Group_Members_Template $this Instance of the current Members template.
    4237              */
    4238             do_action( 'loop_start', $this );
    4239         }
    4240     }
    4241 }
    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
     13 * Membership request template loop class.
    587014 *
    587115 * @since 1.0.0
     
    6110254    }
    6111255}
    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 }
  • trunk/src/bp-groups/classes/class-bp-groups-template.php

    r10515 r10520  
    11<?php
    22/**
    3  * BuddyPress Groups Template Functions.
     3 * BuddyPress Groups Template loop class.
    44 *
    55 * @package BuddyPress
    6  * @subpackage GroupsTemplates
    7  * @since 1.5.0
     6 * @since 1.2.0
    87 */
    98
    109// Exit if accessed directly.
    1110defined( 'ABSPATH' ) || exit;
    12 
    13 /**
    14  * Output the groups component slug.
    15  *
    16  * @since 1.5.0
    17  */
    18 function bp_groups_slug() {
    19     echo bp_get_groups_slug();
    20 }
    21     /**
    22      * Return the groups component slug.
    23      *
    24      * @since 1.5.0
    25      *
    26      * @return string
    27      */
    28     function bp_get_groups_slug() {
    29 
    30         /**
    31          * Filters the groups component slug.
    32          *
    33          * @since 1.5.0
    34          *
    35          * @param string $slug Groups component slug.
    36          */
    37         return apply_filters( 'bp_get_groups_slug', buddypress()->groups->slug );
    38     }
    39 
    40 /**
    41  * Output the groups component root slug.
    42  *
    43  * @since 1.5.0
    44  */
    45 function bp_groups_root_slug() {
    46     echo bp_get_groups_root_slug();
    47 }
    48     /**
    49      * Return the groups component root slug.
    50      *
    51      * @since 1.5.0
    52      *
    53      * @return string
    54      */
    55     function bp_get_groups_root_slug() {
    56 
    57         /**
    58          * Filters the groups component root slug.
    59          *
    60          * @since 1.5.0
    61          *
    62          * @param string $root_slug Groups component root slug.
    63          */
    64         return apply_filters( 'bp_get_groups_root_slug', buddypress()->groups->root_slug );
    65     }
    66 
    67 /**
    68  * Output 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     }
    9311
    9412/**
     
    478396    }
    479397}
    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
    3977  *
    3978  * @since 1.0.0
    3979  */
    3980 class BP_Groups_Group_Members_Template {
    3981 
    3982     /**
    3983      * @since 1.0.0
    3984      * @var int
    3985      */
    3986     public $current_member = -1;
    3987 
    3988     /**
    3989      * @since 1.0.0
    3990      * @var int
    3991      */
    3992     public $member_count;
    3993 
    3994     /**
    3995      * @since 1.0.0
    3996      * @var array
    3997      */
    3998     public $members;
    3999 
    4000     /**
    4001      * @since 1.0.0
    4002      * @var object
    4003      */
    4004     public $member;
    4005 
    4006     /**
    4007      * @since 1.0.0
    4008      * @var bool
    4009      */
    4010     public $in_the_loop;
    4011 
    4012     /**
    4013      * @since 1.0.0
    4014      * @var int
    4015      */
    4016     public $pag_page;
    4017 
    4018     /**
    4019      * @since 1.0.0
    4020      * @var int
    4021      */
    4022     public $pag_num;
    4023 
    4024     /**
    4025      * @since 1.0.0
    4026      * @var array|string|void
    4027      */
    4028     public $pag_links;
    4029 
    4030     /**
    4031      * @since 1.0.0
    4032      * @var int
    4033      */
    4034     public $total_group_count;
    4035 
    4036     /**
    4037      * Constructor.
    4038      *
    4039      * @since 1.5.0
    4040      *
    4041      * @param array $args {
    4042      *     An array of optional arguments.
    4043      *     @type int      $group_id           ID of the group whose members are being
    4044      *                                        queried. Default: current group ID.
    4045      *     @type int      $page               Page of results to be queried. Default: 1.
    4046      *     @type int      $per_page           Number of items to return per page of
    4047      *                                        results. Default: 20.
    4048      *     @type int      $max                Optional. Max number of items to return.
    4049      *     @type array    $exclude            Optional. Array of user IDs to exclude.
    4050      *     @type bool|int $exclude_admin_mods True (or 1) to exclude admins and mods from
    4051      *                                        results. Default: 1.
    4052      *     @type bool|int $exclude_banned     True (or 1) to exclude banned users from results.
    4053      *                                        Default: 1.
    4054      *     @type array    $group_role         Optional. Array of group roles to include.
    4055      *     @type string   $search_terms       Optional. Search terms to match.
    4056      * }
    4057      */
    4058     public function __construct( $args = array() ) {
    4059 
    4060         // Backward compatibility with old method of passing arguments.
    4061         if ( ! is_array( $args ) || func_num_args() > 1 ) {
    4062             _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__ ) );
    4063 
    4064             $old_args_keys = array(
    4065                 0 => 'group_id',
    4066                 1 => 'per_page',
    4067                 2 => 'max',
    4068                 3 => 'exclude_admins_mods',
    4069                 4 => 'exclude_banned',
    4070                 5 => 'exclude',
    4071                 6 => 'group_role',
    4072             );
    4073 
    4074             $func_args = func_get_args();
    4075             $args      = bp_core_parse_args_array( $old_args_keys, $func_args );
    4076         }
    4077 
    4078         $r = wp_parse_args( $args, array(
    4079             'group_id'            => bp_get_current_group_id(),
    4080             'page'                => 1,
    4081             'per_page'            => 20,
    4082             'page_arg'            => 'mlpage',
    4083             'max'                 => false,
    4084             'exclude'             => false,
    4085             'exclude_admins_mods' => 1,
    4086             'exclude_banned'      => 1,
    4087             'group_role'          => false,
    4088             'search_terms'        => false,
    4089             'type'                => 'last_joined',
    4090         ) );
    4091 
    4092         $this->pag_arg  = sanitize_key( $r['page_arg'] );
    4093         $this->pag_page = bp_sanitize_pagination_arg( $this->pag_arg, $r['page']     );
    4094         $this->pag_num  = bp_sanitize_pagination_arg( 'num',          $r['per_page'] );
    4095 
    4096         /**
    4097          * Check the current group is the same as the supplied group ID.
    4098          * It can differ when using {@link bp_group_has_members()} outside the Groups screens.
    4099          */
    4100         $current_group = groups_get_current_group();
    4101         if ( empty( $current_group ) || ( $current_group && $current_group->id !== bp_get_current_group_id() ) ) {
    4102             $current_group = groups_get_group( array( 'group_id' => $r['group_id'] ) );
    4103         }
    4104 
    4105         // Assemble the base URL for pagination.
    4106         $base_url = trailingslashit( bp_get_group_permalink( $current_group ) . bp_current_action() );
    4107         if ( bp_action_variable() ) {
    4108             $base_url = trailingslashit( $base_url . bp_action_variable() );
    4109         }
    4110 
    4111         $members_args = $r;
    4112 
    4113         $members_args['page']     = $this->pag_page;
    4114         $members_args['per_page'] = $this->pag_num;
    4115 
    4116         // Get group members for this loop.
    4117         $this->members = groups_get_group_members( $members_args );
    4118 
    4119         if ( empty( $r['max'] ) || ( $r['max'] >= (int) $this->members['count'] ) ) {
    4120             $this->total_member_count = (int) $this->members['count'];
    4121         } else {
    4122             $this->total_member_count = (int) $r['max'];
    4123         }
    4124 
    4125         // Reset members array for subsequent looping.
    4126         $this->members = $this->members['members'];
    4127 
    4128         if ( empty( $r['max'] ) || ( $r['max'] >= count( $this->members ) ) ) {
    4129             $this->member_count = (int) count( $this->members );
    4130         } else {
    4131             $this->member_count = (int) $r['max'];
    4132         }
    4133 
    4134         $this->pag_links = paginate_links( array(
    4135             'base'      => add_query_arg( array( $this->pag_arg => '%#%' ), $base_url ),
    4136             'format'    => '',
    4137             'total'     => ! empty( $this->pag_num ) ? ceil( $this->total_member_count / $this->pag_num ) : $this->total_member_count,
    4138             'current'   => $this->pag_page,
    4139             'prev_text' => '&larr;',
    4140             'next_text' => '&rarr;',
    4141             'mid_size'  => 1,
    4142             'add_args'  => array(),
    4143         ) );
    4144     }
    4145 
    4146     /**
    4147      * Whether or not there are members to display.
    4148      *
    4149      * @since 1.0.0
    4150      *
    4151      * @return bool
    4152      */
    4153     public function has_members() {
    4154         if ( ! empty( $this->member_count ) ) {
    4155             return true;
    4156         }
    4157 
    4158         return false;
    4159     }
    4160 
    4161     /**
    4162      * Increments to the next member to display.
    4163      *
    4164      * @since 1.0.0
    4165      *
    4166      * @return object
    4167      */
    4168     public function next_member() {
    4169         $this->current_member++;
    4170         $this->member = $this->members[ $this->current_member ];
    4171 
    4172         return $this->member;
    4173     }
    4174 
    4175     /**
    4176      * Rewinds to the first member to display.
    4177      *
    4178      * @since 1.0.0
    4179      */
    4180     public function rewind_members() {
    4181         $this->current_member = -1;
    4182         if ( $this->member_count > 0 ) {
    4183             $this->member = $this->members[0];
    4184         }
    4185     }
    4186 
    4187     /**
    4188      * Finishes up the members for display.
    4189      *
    4190      * @since 1.0.0
    4191      *
    4192      * @return bool
    4193      */
    4194     public function members() {
    4195         $tick = intval( $this->current_member + 1 );
    4196         if ( $tick < $this->member_count ) {
    4197             return true;
    4198         } elseif ( $tick == $this->member_count ) {
    4199 
    4200             /**
    4201              * Fires right before the rewinding of members list.
    4202              *
    4203              * @since 1.0.0
    4204              * @since 2.3.0 `$this` parameter added.
    4205              *
    4206              * @param BP_Groups_Group_Members_Template $this Instance of the current Members template.
    4207              */
    4208             do_action( 'loop_end', $this );
    4209 
    4210             // Do some cleaning up after the loop.
    4211             $this->rewind_members();
    4212         }
    4213 
    4214         $this->in_the_loop = false;
    4215         return false;
    4216     }
    4217 
    4218     /**
    4219      * Sets up the member to display.
    4220      *
    4221      * @since 1.0.0
    4222      */
    4223     public function the_member() {
    4224         $this->in_the_loop = true;
    4225         $this->member      = $this->next_member();
    4226 
    4227         // Loop has just started.
    4228         if ( 0 == $this->current_member ) {
    4229 
    4230             /**
    4231              * Fires if the current member item is the first in the members list.
    4232              *
    4233              * @since 1.0.0
    4234              * @since 2.3.0 `$this` parameter added.
    4235              *
    4236              * @param BP_Groups_Group_Members_Template $this Instance of the current Members template.
    4237              */
    4238             do_action( 'loop_start', $this );
    4239         }
    4240     }
    4241 }
    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 }
  • trunk/src/bp-groups/classes/class-bp-groups-theme-compat.php

    r10515 r10520  
    11<?php
    22/**
    3  * BuddyPress Groups Screen Functions
    4  *
    5  * Screen functions are the controllers of BuddyPress. They will execute when
    6  * their specific URL is caught. They will first save or manipulate data using
    7  * business functions, then pass on the user to a template file.
     3 * BuddyPress Groups Theme Compat.
    84 *
    95 * @package BuddyPress
    10  * @subpackage GroupsScreens
    11  * @since 1.5.0
     6 * @since 1.7.0
    127 */
    138
    149// Exit if accessed directly.
    1510defined( 'ABSPATH' ) || exit;
    16 
    17 /**
    18  * Handle the display of the Groups directory index.
    19  *
    20  * @since 1.0.0
    21  */
    22 function groups_directory_groups_setup() {
    23     if ( bp_is_groups_directory() ) {
    24         bp_update_is_directory( true, 'groups' );
    25 
    26         /**
    27          * Fires before the loading of the Groups directory index.
    28          *
    29          * @since 1.1.0
    30          */
    31         do_action( 'groups_directory_groups_setup' );
    32 
    33         /**
    34          * Filters the template to load for the Groups directory index.
    35          *
    36          * @since 1.0.0
    37          *
    38          * @param string $value Path to the groups directory index template to load.
    39          */
    40         bp_core_load_template( apply_filters( 'groups_template_directory_groups', 'groups/index' ) );
    41     }
    42 }
    43 add_action( 'bp_screens', 'groups_directory_groups_setup', 2 );
    44 
    45 /**
    46  * Handle the loading of the My Groups page.
    47  *
    48  * @since 1.0.0
    49  */
    50 function groups_screen_my_groups() {
    51 
    52     /**
    53      * Fires before the loading of the My Groups page.
    54      *
    55      * @since 1.1.0
    56      */
    57     do_action( 'groups_screen_my_groups' );
    58 
    59     /**
    60      * Filters the template to load for the My Groups page.
    61      *
    62      * @since 1.0.0
    63      *
    64      * @param string $value Path to the My Groups page template to load.
    65      */
    66     bp_core_load_template( apply_filters( 'groups_template_my_groups', 'members/single/home' ) );
    67 }
    68 
    69 /**
    70  * Handle the loading of a user's Groups > Invites page.
    71  *
    72  * @since 1.0.0
    73  */
    74 function groups_screen_group_invites() {
    75     $group_id = (int)bp_action_variable( 1 );
    76 
    77     if ( bp_is_action_variable( 'accept' ) && is_numeric( $group_id ) ) {
    78         // Check the nonce.
    79         if ( !check_admin_referer( 'groups_accept_invite' ) )
    80             return false;
    81 
    82         if ( !groups_accept_invite( bp_loggedin_user_id(), $group_id ) ) {
    83             bp_core_add_message( __('Group invite could not be accepted', 'buddypress'), 'error' );
    84         } else {
    85             bp_core_add_message( __('Group invite accepted', 'buddypress') );
    86 
    87             // Record this in activity streams.
    88             $group = groups_get_group( array( 'group_id' => $group_id ) );
    89 
    90             groups_record_activity( array(
    91                 'type'    => 'joined_group',
    92                 'item_id' => $group->id
    93             ) );
    94         }
    95 
    96         if ( isset( $_GET['redirect_to'] ) ) {
    97             $redirect_to = urldecode( $_GET['redirect_to'] );
    98         } else {
    99             $redirect_to = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() . '/' . bp_current_action() );
    100         }
    101 
    102         bp_core_redirect( $redirect_to );
    103 
    104     } elseif ( bp_is_action_variable( 'reject' ) && is_numeric( $group_id ) ) {
    105         // Check the nonce.
    106         if ( !check_admin_referer( 'groups_reject_invite' ) )
    107             return false;
    108 
    109         if ( !groups_reject_invite( bp_loggedin_user_id(), $group_id ) ) {
    110             bp_core_add_message( __( 'Group invite could not be rejected', 'buddypress' ), 'error' );
    111         } else {
    112             bp_core_add_message( __( 'Group invite rejected', 'buddypress' ) );
    113         }
    114 
    115         if ( isset( $_GET['redirect_to'] ) ) {
    116             $redirect_to = urldecode( $_GET['redirect_to'] );
    117         } else {
    118             $redirect_to = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() . '/' . bp_current_action() );
    119         }
    120 
    121         bp_core_redirect( $redirect_to );
    122     }
    123 
    124     /**
    125      * Fires before the loading of a users Groups > Invites template.
    126      *
    127      * @since 1.0.0
    128      *
    129      * @param int $group_id ID of the group being displayed
    130      */
    131     do_action( 'groups_screen_group_invites', $group_id );
    132 
    133     /**
    134      * Filters the template to load for a users Groups > Invites page.
    135      *
    136      * @since 1.0.0
    137      *
    138      * @param string $value Path to a users Groups > Invites page template.
    139      */
    140     bp_core_load_template( apply_filters( 'groups_template_group_invites', 'members/single/home' ) );
    141 }
    142 
    143 /**
    144  * Handle the loading of a single group's page.
    145  *
    146  * @since 1.0.0
    147  */
    148 function groups_screen_group_home() {
    149 
    150     if ( ! bp_is_single_item() ) {
    151         return false;
    152     }
    153 
    154     /**
    155      * Fires before the loading of a single group's page.
    156      *
    157      * @since 1.0.0
    158      */
    159     do_action( 'groups_screen_group_home' );
    160 
    161     /**
    162      * Filters the template to load for a single group's page.
    163      *
    164      * @since 1.0.0
    165      *
    166      * @param string $value Path to a single group's template to load.
    167      */
    168     bp_core_load_template( apply_filters( 'groups_template_group_home', 'groups/single/home' ) );
    169 }
    170 
    171 /**
    172  * This screen function handles actions related to group forums.
    173  *
    174  * @since 1.0.0
    175  */
    176 function groups_screen_group_forum() {
    177 
    178     if ( !bp_is_active( 'forums' ) || !bp_forums_is_installed_correctly() )
    179         return false;
    180 
    181     if ( bp_action_variable( 0 ) && !bp_is_action_variable( 'topic', 0 ) ) {
    182         bp_do_404();
    183         return;
    184     }
    185 
    186     $bp = buddypress();
    187 
    188     if ( !$bp->groups->current_group->user_has_access ) {
    189         bp_core_no_access();
    190         return;
    191     }
    192 
    193     if ( ! bp_is_single_item() )
    194         return false;
    195 
    196     // Fetch the details we need.
    197     $topic_slug = (string)bp_action_variable( 1 );
    198     $topic_id       = bp_forums_get_topic_id_from_slug( $topic_slug );
    199     $forum_id       = groups_get_groupmeta( $bp->groups->current_group->id, 'forum_id' );
    200     $user_is_banned = false;
    201 
    202     if ( !bp_current_user_can( 'bp_moderate' ) && groups_is_user_banned( bp_loggedin_user_id(), $bp->groups->current_group->id ) )
    203         $user_is_banned = true;
    204 
    205     if ( !empty( $topic_slug ) && !empty( $topic_id ) ) {
    206 
    207         // Posting a reply.
    208         if ( !$user_is_banned && !bp_action_variable( 2 ) && isset( $_POST['submit_reply'] ) ) {
    209             // Check the nonce.
    210             check_admin_referer( 'bp_forums_new_reply' );
    211 
    212             // Auto join this user if they are not yet a member of this group.
    213             if ( bp_groups_auto_join() && !bp_current_user_can( 'bp_moderate' ) && 'public' == $bp->groups->current_group->status && !groups_is_user_member( bp_loggedin_user_id(), $bp->groups->current_group->id ) ) {
    214                 groups_join_group( $bp->groups->current_group->id, bp_loggedin_user_id() );
    215             }
    216 
    217             $topic_page = isset( $_GET['topic_page'] ) ? $_GET['topic_page'] : false;
    218 
    219             // Don't allow reply flooding.
    220             if ( bp_forums_reply_exists( $_POST['reply_text'], $topic_id, bp_loggedin_user_id() ) ) {
    221                 bp_core_add_message( __( 'It looks like you\'ve already said that!', 'buddypress' ), 'error' );
    222             } else {
    223                 if ( !$post_id = groups_new_group_forum_post( $_POST['reply_text'], $topic_id, $topic_page ) ) {
    224                     bp_core_add_message( __( 'There was an error when replying to that topic', 'buddypress'), 'error' );
    225                 } else {
    226                     bp_core_add_message( __( 'Your reply was posted successfully', 'buddypress') );
    227                 }
    228             }
    229 
    230             $query_vars = isset( $_SERVER['QUERY_STRING'] ) ? '?' . $_SERVER['QUERY_STRING'] : '';
    231 
    232             $redirect = bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic_slug . '/' . $query_vars;
    233 
    234             if ( !empty( $post_id ) ) {
    235                 $redirect .= '#post-' . $post_id;
    236             }
    237 
    238             bp_core_redirect( $redirect );
    239         }
    240 
    241         // Sticky a topic.
    242         elseif ( bp_is_action_variable( 'stick', 2 ) && ( bp_is_item_admin() || bp_is_item_mod() ) ) {
    243             // Check the nonce.
    244             check_admin_referer( 'bp_forums_stick_topic' );
    245 
    246             if ( !bp_forums_sticky_topic( array( 'topic_id' => $topic_id ) ) ) {
    247                 bp_core_add_message( __( 'There was an error when making that topic a sticky', 'buddypress' ), 'error' );
    248             } else {
    249                 bp_core_add_message( __( 'The topic was made sticky successfully', 'buddypress' ) );
    250             }
    251 
    252             /**
    253              * Fires after a group forum topic has been stickied.
    254              *
    255              * @since 1.1.0
    256              *
    257              * @param int $topic_id ID of the topic being stickied.
    258              */
    259             do_action( 'groups_stick_forum_topic', $topic_id );
    260             bp_core_redirect( wp_get_referer() );
    261         }
    262 
    263         // Un-Sticky a topic.
    264         elseif ( bp_is_action_variable( 'unstick', 2 ) && ( bp_is_item_admin() || bp_is_item_mod() ) ) {
    265             // Check the nonce.
    266             check_admin_referer( 'bp_forums_unstick_topic' );
    267 
    268             if ( !bp_forums_sticky_topic( array( 'topic_id' => $topic_id, 'mode' => 'unstick' ) ) ) {
    269                 bp_core_add_message( __( 'There was an error when unsticking that topic', 'buddypress'), 'error' );
    270             } else {
    271                 bp_core_add_message( __( 'The topic was unstuck successfully', 'buddypress') );
    272             }
    273 
    274             /**
    275              * Fires after a group forum topic has been un-stickied.
    276              *
    277              * @since 1.1.0
    278              *
    279              * @param int $topic_id ID of the topic being un-stickied.
    280              */
    281             do_action( 'groups_unstick_forum_topic', $topic_id );
    282             bp_core_redirect( wp_get_referer() );
    283         }
    284 
    285         // Close a topic.
    286         elseif ( bp_is_action_variable( 'close', 2 ) && ( bp_is_item_admin() || bp_is_item_mod() ) ) {
    287             // Check the nonce.
    288             check_admin_referer( 'bp_forums_close_topic' );
    289 
    290             if ( !bp_forums_openclose_topic( array( 'topic_id' => $topic_id ) ) ) {
    291                 bp_core_add_message( __( 'There was an error when closing that topic', 'buddypress'), 'error' );
    292             } else {
    293                 bp_core_add_message( __( 'The topic was closed successfully', 'buddypress') );
    294             }
    295 
    296             /**
    297              * Fires after a group forum topic has been closed.
    298              *
    299              * @since 1.1.0
    300              *
    301              * @param int $topic_id ID of the topic being closed.
    302              */
    303             do_action( 'groups_close_forum_topic', $topic_id );
    304             bp_core_redirect( wp_get_referer() );
    305         }
    306 
    307         // Open a topic.
    308         elseif ( bp_is_action_variable( 'open', 2 ) && ( bp_is_item_admin() || bp_is_item_mod() ) ) {
    309             // Check the nonce.
    310             check_admin_referer( 'bp_forums_open_topic' );
    311 
    312             if ( !bp_forums_openclose_topic( array( 'topic_id' => $topic_id, 'mode' => 'open' ) ) ) {
    313                 bp_core_add_message( __( 'There was an error when opening that topic', 'buddypress'), 'error' );
    314             } else {
    315                 bp_core_add_message( __( 'The topic was opened successfully', 'buddypress') );
    316             }
    317 
    318             /**
    319              * Fires after a group forum topic has been opened.
    320              *
    321              * @since 1.1.0
    322              *
    323              * @param int $topic_id ID of the topic being opened.
    324              */
    325             do_action( 'groups_open_forum_topic', $topic_id );
    326             bp_core_redirect( wp_get_referer() );
    327         }
    328 
    329         // Delete a topic.
    330         elseif ( empty( $user_is_banned ) && bp_is_action_variable( 'delete', 2 ) && !bp_action_variable( 3 ) ) {
    331             // Fetch the topic.
    332             $topic = bp_forums_get_topic_details( $topic_id );
    333 
    334             /* Check the logged in user can delete this topic */
    335             if ( ! bp_is_item_admin() && ! bp_is_item_mod() && ( (int) bp_loggedin_user_id() != (int) $topic->topic_poster ) ) {
    336                 bp_core_redirect( wp_get_referer() );
    337             }
    338 
    339             // Check the nonce.
    340             check_admin_referer( 'bp_forums_delete_topic' );
    341 
    342             /**
    343              * Fires before a group forum topic is deleted.
    344              *
    345              * @since 1.5.0
    346              *
    347              * @param int $topic_id ID of the topic being deleted.
    348              */
    349             do_action( 'groups_before_delete_forum_topic', $topic_id );
    350 
    351             if ( !groups_delete_group_forum_topic( $topic_id ) ) {
    352                 bp_core_add_message( __( 'There was an error deleting the topic', 'buddypress' ), 'error' );
    353             } else {
    354                 bp_core_add_message( __( 'The topic was deleted successfully', 'buddypress' ) );
    355             }
    356 
    357             /**
    358              * Fires after a group forum topic has been deleted.
    359              *
    360              * @since 1.5.0
    361              *
    362              * @param int $topic_id ID of the topic being deleted.
    363              */
    364             do_action( 'groups_delete_forum_topic', $topic_id );
    365             bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'forum/' );
    366         }
    367 
    368         // Editing a topic.
    369         elseif ( empty( $user_is_banned ) && bp_is_action_variable( 'edit', 2 ) && !bp_action_variable( 3 ) ) {
    370             // Fetch the topic.
    371             $topic = bp_forums_get_topic_details( $topic_id );
    372 
    373             // Check the logged in user can edit this topic.
    374             if ( ! bp_is_item_admin() && ! bp_is_item_mod() && ( (int) bp_loggedin_user_id() != (int) $topic->topic_poster ) ) {
    375                 bp_core_redirect( wp_get_referer() );
    376             }
    377 
    378             if ( isset( $_POST['save_changes'] ) ) {
    379                 // Check the nonce.
    380                 check_admin_referer( 'bp_forums_edit_topic' );
    381 
    382                 $topic_tags = !empty( $_POST['topic_tags'] ) ? $_POST['topic_tags'] : false;
    383 
    384                 if ( !groups_update_group_forum_topic( $topic_id, $_POST['topic_title'], $_POST['topic_text'], $topic_tags ) ) {
    385                     bp_core_add_message( __( 'There was an error when editing that topic', 'buddypress'), 'error' );
    386                 } else {
    387                     bp_core_add_message( __( 'The topic was edited successfully', 'buddypress') );
    388                 }
    389 
    390                 /**
    391                  * Fires after a group forum topic has been edited.
    392                  *
    393                  * @since 1.1.0
    394                  *
    395                  * @param int $topic_id ID of the topic being edited.
    396                  */
    397                 do_action( 'groups_edit_forum_topic', $topic_id );
    398                 bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic_slug . '/' );
    399             }
    400 
    401             /**
    402              * Filters the template to load for a topic edit page.
    403              *
    404              * @since 1.1.0
    405              *
    406              * @param string $value Path to a topic edit template.
    407              */
    408             bp_core_load_template( apply_filters( 'groups_template_group_forum_topic_edit', 'groups/single/home' ) );
    409 
    410         // Delete a post.
    411         } elseif ( empty( $user_is_banned ) && bp_is_action_variable( 'delete', 2 ) && $post_id = bp_action_variable( 4 ) ) {
    412             // Fetch the post.
    413             $post = bp_forums_get_post( $post_id );
    414 
    415             // Check the logged in user can edit this topic.
    416             if ( ! bp_is_item_admin() && ! bp_is_item_mod() && ( (int) bp_loggedin_user_id() != (int) $post->poster_id ) ) {
    417                 bp_core_redirect( wp_get_referer() );
    418             }
    419 
    420             // Check the nonce.
    421             check_admin_referer( 'bp_forums_delete_post' );
    422 
    423             /**
    424              * Fires before the deletion of a group forum post.
    425              *
    426              * @since 1.5.0
    427              *
    428              * @param int $post_id ID of the forum post being deleted.
    429              */
    430             do_action( 'groups_before_delete_forum_post', $post_id );
    431 
    432             if ( !groups_delete_group_forum_post( $post_id ) ) {
    433                 bp_core_add_message( __( 'There was an error deleting that post', 'buddypress'), 'error' );
    434             } else {
    435                 bp_core_add_message( __( 'The post was deleted successfully', 'buddypress') );
    436             }
    437 
    438             /**
    439              * Fires after the deletion of a group forum post.
    440              *
    441              * @since 1.1.0
    442              *
    443              * @param int $post_id ID of the forum post being deleted.
    444              */
    445             do_action( 'groups_delete_forum_post', $post_id );
    446             bp_core_redirect( wp_get_referer() );
    447 
    448         // Editing a post.
    449         } elseif ( empty( $user_is_banned ) && bp_is_action_variable( 'edit', 2 ) && $post_id = bp_action_variable( 4 ) ) {
    450 
    451             // Fetch the post.
    452             $post = bp_forums_get_post( $post_id );
    453 
    454             // Check the logged in user can edit this topic.
    455             if ( ! bp_is_item_admin() && ! bp_is_item_mod() && ( (int) bp_loggedin_user_id() != (int) $post->poster_id ) ) {
    456                 bp_core_redirect( wp_get_referer() );
    457             }
    458 
    459             if ( isset( $_POST['save_changes'] ) ) {
    460                 // Check the nonce.
    461                 check_admin_referer( 'bp_forums_edit_post' );
    462 
    463                 $topic_page = isset( $_GET['topic_page'] ) ? $_GET['topic_page'] : false;
    464 
    465                 if ( !$post_id = groups_update_group_forum_post( $post_id, $_POST['post_text'], $topic_id, $topic_page ) ) {
    466                     bp_core_add_message( __( 'There was an error when editing that post', 'buddypress'), 'error' );
    467                 } else {
    468                     bp_core_add_message( __( 'The post was edited successfully', 'buddypress') );
    469                 }
    470 
    471                 if ( $_SERVER['QUERY_STRING'] ) {
    472                     $query_vars = '?' . $_SERVER['QUERY_STRING'];
    473                 }
    474 
    475                 /**
    476                  * Fires after the editing of a group forum post.
    477                  *
    478                  * @since 1.1.0
    479                  *
    480                  * @param int $post_id ID of the forum post being edited.
    481                  */
    482                 do_action( 'groups_edit_forum_post', $post_id );
    483                 bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic_slug . '/' . $query_vars . '#post-' . $post_id );
    484             }
    485 
    486             /** This filter is documented in bp-groups/bp-groups-screens.php */
    487             bp_core_load_template( apply_filters( 'groups_template_group_forum_topic_edit', 'groups/single/home' ) );
    488 
    489         // Standard topic display.
    490         } else {
    491             if ( !empty( $user_is_banned ) ) {
    492                 bp_core_add_message( __( "You have been banned from this group.", 'buddypress' ) );
    493             }
    494 
    495             /**
    496              * Filters the template to load for a topic page.
    497              *
    498              * @since 1.1.0
    499              *
    500              * @param string $value Path to a topic template.
    501              */
    502             bp_core_load_template( apply_filters( 'groups_template_group_forum_topic', 'groups/single/home' ) );
    503         }
    504 
    505     // Forum topic does not exist.
    506     } elseif ( !empty( $topic_slug ) && empty( $topic_id ) ) {
    507         bp_do_404();
    508         return;
    509 
    510     } else {
    511         // Posting a topic.
    512         if ( isset( $_POST['submit_topic'] ) && bp_is_active( 'forums' ) ) {
    513 
    514             // Check the nonce.
    515             check_admin_referer( 'bp_forums_new_topic' );
    516 
    517             if ( $user_is_banned ) {
    518                 $error_message = __( "You have been banned from this group.", 'buddypress' );
    519 
    520             } elseif ( bp_groups_auto_join() && !bp_current_user_can( 'bp_moderate' ) && 'public' == $bp->groups->current_group->status && !groups_is_user_member( bp_loggedin_user_id(), $bp->groups->current_group->id ) ) {
    521                 // Auto join this user if they are not yet a member of this group.
    522                 groups_join_group( $bp->groups->current_group->id, bp_loggedin_user_id() );
    523             }
    524 
    525             if ( empty( $_POST['topic_title'] ) ) {
    526                 $error_message = __( 'Please provide a title for your forum topic.', 'buddypress' );
    527             } elseif ( empty( $_POST['topic_text'] ) ) {
    528                 $error_message = __( 'Forum posts cannot be empty. Please enter some text.', 'buddypress' );
    529             }
    530 
    531             if ( empty( $forum_id ) ) {
    532                 $error_message = __( 'This group does not have a forum setup yet.', 'buddypress' );
    533             }
    534 
    535             if ( isset( $error_message ) ) {
    536                 bp_core_add_message( $error_message, 'error' );
    537                 $redirect = bp_get_group_permalink( $bp->groups->current_group ) . 'forum';
    538             } else {
    539                 if ( !$topic = groups_new_group_forum_topic( $_POST['topic_title'], $_POST['topic_text'], $_POST['topic_tags'], $forum_id ) ) {
    540                     bp_core_add_message( __( 'There was an error when creating the topic', 'buddypress'), 'error' );
    541                     $redirect = bp_get_group_permalink( $bp->groups->current_group ) . 'forum';
    542                 } else {
    543                     bp_core_add_message( __( 'The topic was created successfully', 'buddypress') );
    544                     $redirect = bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug . '/';
    545                 }
    546             }
    547 
    548             bp_core_redirect( $redirect );
    549         }
    550 
    551         /**
    552          * Fires at the end of the group forum screen loading process.
    553          *
    554          * @since 1.0.0
    555          *
    556          * @param int $topic_id ID of the topic being displayed.
    557          * @param int $forum_id ID of the forum being displayed.
    558          */
    559         do_action( 'groups_screen_group_forum', $topic_id, $forum_id );
    560 
    561         /**
    562          * Filters the template to load for a group forum page.
    563          *
    564          * @since 1.0.0
    565          *
    566          * @param string $value Path to a group forum template.
    567          */
    568         bp_core_load_template( apply_filters( 'groups_template_group_forum', 'groups/single/home' ) );
    569     }
    570 }
    571 
    572 /**
    573  * Handle the display of a group's Members page.
    574  *
    575  * @since 1.0.0
    576  */
    577 function groups_screen_group_members() {
    578 
    579     if ( !bp_is_single_item() )
    580         return false;
    581 
    582     $bp = buddypress();
    583 
    584     // Refresh the group member count meta.
    585     groups_update_groupmeta( $bp->groups->current_group->id, 'total_member_count', groups_get_total_member_count( $bp->groups->current_group->id ) );
    586 
    587     /**
    588      * Fires before the loading of a group's Members page.
    589      *
    590      * @since 1.0.0
    591      *
    592      * @param int $id ID of the group whose members are being displayed.
    593      */
    594     do_action( 'groups_screen_group_members', $bp->groups->current_group->id );
    595 
    596     /**
    597      * Filters the template to load for a group's Members page.
    598      *
    599      * @since 1.0.0
    600      *
    601      * @param string $value Path to a group's Members template.
    602      */
    603     bp_core_load_template( apply_filters( 'groups_template_group_members', 'groups/single/home' ) );
    604 }
    605 
    606 /**
    607  * Handle the display of a group's Send Invites page.
    608  *
    609  * @since 1.0.0
    610  */
    611 function groups_screen_group_invite() {
    612 
    613     if ( !bp_is_single_item() )
    614         return false;
    615 
    616     $bp = buddypress();
    617 
    618     if ( bp_is_action_variable( 'send', 0 ) ) {
    619 
    620         if ( !check_admin_referer( 'groups_send_invites', '_wpnonce_send_invites' ) )
    621