Skip to:
Content

BuddyPress.org

Ticket #6749: 6749-3.diff

File 6749-3.diff, 38.8 KB (added by espellcaste, 5 years ago)
  • src/bp-groups/bp-groups-template.php

    diff --git src/bp-groups/bp-groups-template.php src/bp-groups/bp-groups-template.php
    index 7b5687744..4ba18f121 100644
    function bp_group_avatar( $args = '', $group = false ) { 
    896896                                'id'      => false,
    897897                                // translators: %1$s is the name of the group.
    898898                                'alt'     => sprintf( __( 'Group logo of %1$s', 'buddypress' ), $group->name ),
    899                         )
     899                        ),
     900                        'get_group_avatar'
    900901                );
    901902
    902903                // Fetch the avatar from the folder.
    function bp_group_avatar_url( $group = false, $type = 'full' ) { 
    10171018         * Returns the group avatar URL.
    10181019         *
    10191020         * @since 5.0.0
    1020          * @since 10.0.0 Updated to use `bp_get_group_avatar`
     1021         * @since 10.0.0 Updated to use `bp_get_group_avatar`.
    10211022         *
    10221023         * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
    10231024         *                                                Default: false.
    function bp_group_last_active( $group = false, $args = array() ) { 
    11111112                        return '';
    11121113                }
    11131114
    1114                 $r = bp_parse_args( $args, array(
    1115                         'relative' => true,
    1116                 ), 'group_last_active' );
     1115                $r = bp_parse_args(
     1116                        $args,
     1117                        array(
     1118                                'relative' => true,
     1119                        ),
     1120                        'group_last_active'
     1121                );
    11171122
    11181123                $last_active = $group->last_activity;
    11191124                if ( ! $last_active ) {
    function bp_group_last_active( $group = false, $args = array() ) { 
    11361141                         * @since 1.0.0
    11371142                         * @since 2.5.0 Added the `$group` parameter.
    11381143                         *
    1139                          * @param string               $value Determined last active value for the current group.
    1140                          * @param BP_Groups_Group|null $group The group object.
     1144                         * @param string          $value Determined last active value for the current group.
     1145                         * @param BP_Groups_Group $group The group object.
    11411146                         */
    11421147                        return apply_filters( 'bp_get_group_last_active', bp_core_time_since( $last_active ), $group );
    11431148                }
    function bp_is_group_creator( $group = false, $user_id = 0 ) { 
    16471652}
    16481653
    16491654/**
    1650  * Output the avatar of the creator of the current group in the loop.
     1655 * Output the avatar of the creator of the group.
    16511656 *
    16521657 * @since 1.7.0
    16531658 *
    1654  * @param object|bool $group Optional. Group object.
    1655  *                           Default: current group in loop.
    1656  * @param array       $args {
     1659 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     1660 *                                                Default: false.
     1661 * @param array                            $args {
    16571662 *     Array of optional arguments. See {@link bp_get_group_creator_avatar()}
    16581663 *     for description.
    16591664 * }
    function bp_group_creator_avatar( $group = false, $args = array() ) { 
    16621667        echo bp_get_group_creator_avatar( $group, $args );
    16631668}
    16641669        /**
    1665          * Return the avatar of the creator of the current group in the loop.
     1670         * Return the avatar of the creator of the group.
    16661671         *
    16671672         * @since 1.7.0
     1673         * @since 10.0.0 Updated to use `bp_get_group`.
    16681674         *
    1669          * @param object|bool $group Optional. Group object.
    1670          *                           Default: current group in loop.
    1671          * @param array       $args {
     1675         * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     1676     *                                                Default: false.
     1677         * @param array                            $args {
    16721678         *     Array of optional arguments. See {@link bp_core_fetch_avatar()}
    16731679         *     for detailed description of arguments.
    16741680         *     @type string $type   Default: 'full'.
    function bp_group_creator_avatar( $group = false, $args = array() ) { 
    16821688         * @return string
    16831689         */
    16841690        function bp_get_group_creator_avatar( $group = false, $args = array() ) {
    1685                 global $groups_template;
     1691                $group = bp_get_group( $group );
    16861692
    1687                 if ( empty( $group ) ) {
    1688                         $group =& $groups_template->group;
     1693                if ( empty( $group->id ) ) {
     1694                        return '';
    16891695                }
    16901696
    1691                 $r = bp_parse_args( $args, array(
    1692                         'type'   => 'full',
    1693                         'width'  => false,
    1694                         'height' => false,
    1695                         'class'  => 'avatar',
    1696                         'id'     => false,
    1697                         'alt'    => sprintf(
    1698                                 /* translators: %s: group creator name */
    1699                                 __( 'Group creator profile photo of %s', 'buddypress' ),
    1700                                 bp_core_get_user_displayname( $group->creator_id )
     1697                $r = bp_parse_args(
     1698                        $args,
     1699                        array(
     1700                                'type'   => 'full',
     1701                                'width'  => false,
     1702                                'height' => false,
     1703                                'class'  => 'avatar',
     1704                                'id'     => false,
     1705                                'alt'    => sprintf(
     1706                                        /* translators: %s: group creator name */
     1707                                        __( 'Group creator profile photo of %s', 'buddypress' ),
     1708                                        bp_core_get_user_displayname( $group->creator_id )
     1709                                ),
    17011710                        ),
    1702                 ), 'group_creator_avatar' );
    1703                 extract( $r, EXTR_SKIP );
     1711                        'group_creator_avatar'
     1712                );
    17041713
    1705                 $avatar = bp_core_fetch_avatar( array( 'item_id' => $group->creator_id, 'type' => $type, 'css_id' => $id, 'class' => $class, 'width' => $width, 'height' => $height, 'alt' => $alt ) );
     1714                $avatar = bp_core_fetch_avatar(
     1715                        array(
     1716                                'item_id' => $group->creator_id,
     1717                                'type'    => $r['type'],
     1718                                'css_id'  => $r['id'],
     1719                                'class'   => $r['class'],
     1720                                'width'   => $r['width'],
     1721                                'height'  => $r['height'],
     1722                                'alt'     => $r['alt'],
     1723                        )
     1724                );
    17061725
    17071726                /**
    1708                  * Filters the avatar of the creator of the current group in the loop.
     1727                 * Filters the avatar of the creator of the group.
    17091728                 *
    17101729                 * @since 1.7.0
    1711                  * @since 2.5.0 Added the `$group` parameter.
     1730                 * @since 2.5.0  Added the `$group` parameter.
     1731                 * @since 10.0.0 Added the `$r` parameter.
    17121732                 *
    1713                  * @param string $avatar Avatar of the group creator.
    1714                  * @param object $group  Group object.
     1733                 * @param string          $avatar Avatar of the group creator.
     1734                 * @param BP_Groups_Group $group  The group object.
     1735                 * @param array           $r      Array of parsed arguments for the group creator avatar.
    17151736                 */
    1716                 return apply_filters( 'bp_get_group_creator_avatar', $avatar, $group );
     1737                return apply_filters( 'bp_get_group_creator_avatar', $avatar, $group, $r );
    17171738        }
    17181739
    17191740/**
    function bp_group_is_mod() { 
    17461767 * Output markup listing group admins.
    17471768 *
    17481769 * @since 1.0.0
     1770 * @since 10.0.0 Updated to use `bp_get_group`.
    17491771 *
    1750  * @param object|bool $group Optional. Group object.
    1751  *                           Default: current group in loop.
     1772 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     1773 *                                                Default: false.
    17521774 */
    17531775function bp_group_list_admins( $group = false ) {
    1754         global $groups_template;
    1755 
    1756         if ( empty( $group ) ) {
    1757                 $group =& $groups_template->group;
    1758         }
     1776        $group = bp_get_group( $group );
    17591777
    17601778        if ( ! empty( $group->admins ) ) { ?>
    17611779                <ul id="group-admins">
    1762                         <?php foreach( (array) $group->admins as $admin ) { ?>
     1780                        <?php foreach ( (array) $group->admins as $admin ) { ?>
    17631781                                <li>
    1764                                         <a href="<?php echo bp_core_get_user_domain( $admin->user_id, $admin->user_nicename, $admin->user_login ) ?>" class="bp-tooltip" data-bp-tooltip="<?php printf( ('%s'),  bp_core_get_user_displayname( $admin->user_id ) ); ?>">
     1782                                        <a
     1783                                                href="<?php echo esc_url( bp_core_get_user_domain( $admin->user_id, $admin->user_nicename, $admin->user_login ) ); ?>"
     1784                                                class="bp-tooltip"
     1785                                                data-bp-tooltip="<?php printf( ( '%s' ), bp_core_get_user_displayname( $admin->user_id ) ); ?>"
     1786                                        >
    17651787                                                <?php
    17661788                                                echo bp_core_fetch_avatar(
    17671789                                                        array(
    function bp_group_list_admins( $group = false ) { 
    17801802                        <?php } ?>
    17811803                </ul>
    17821804        <?php } else { ?>
    1783                 <span class="activity"><?php _e( 'No Admins', 'buddypress' ) ?></span>
     1805                <span class="activity">
     1806                        <?php esc_html_e( 'No Admins', 'buddypress' ); ?>
     1807                </span>
    17841808        <?php } ?>
    1785 <?php
     1809        <?php
    17861810}
    17871811
    17881812/**
    17891813 * Output markup listing group mod.
    17901814 *
    17911815 * @since 1.0.0
     1816 * @since 10.0.0 Updated to use `bp_get_group`.
    17921817 *
    1793  * @param object|bool $group Optional. Group object.
    1794  *                           Default: current group in loop.
     1818 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     1819 *                                                Default: false.
    17951820 */
    17961821function bp_group_list_mods( $group = false ) {
    1797         global $groups_template;
    1798 
    1799         if ( empty( $group ) ) {
    1800                 $group =& $groups_template->group;
    1801         }
    1802 
    1803         if ( ! empty( $group->mods ) ) : ?>
     1822        $group = bp_get_group( $group );
    18041823
     1824        if ( ! empty( $group->mods ) ) :
     1825                ?>
    18051826                <ul id="group-mods">
    1806 
    1807                         <?php foreach( (array) $group->mods as $mod ) { ?>
    1808 
     1827                        <?php foreach ( (array) $group->mods as $mod ) { ?>
    18091828                                <li>
    1810                                         <a href="<?php echo bp_core_get_user_domain( $mod->user_id, $mod->user_nicename, $mod->user_login ) ?>" class="bp-tooltip" data-bp-tooltip="<?php printf( ('%s'),  bp_core_get_user_displayname( $mod->user_id ) ); ?>">
     1829                                        <a
     1830                                                href="<?php echo esc_url( bp_core_get_user_domain( $mod->user_id, $mod->user_nicename, $mod->user_login ) ); ?>"
     1831                                                class="bp-tooltip"
     1832                                                data-bp-tooltip="<?php printf( ( '%s' ), bp_core_get_user_displayname( $mod->user_id ) ); ?>">
    18111833                                                <?php
    18121834                                                echo bp_core_fetch_avatar(
    18131835                                                        array(
    function bp_group_list_mods( $group = false ) { 
    18191841                                                                        bp_core_get_user_displayname( $mod->user_id )
    18201842                                                                ),
    18211843                                                        )
    1822                                                 ); ?>
     1844                                                );
     1845                                                ?>
    18231846                                        </a>
    18241847                                </li>
    1825 
    18261848                        <?php } ?>
    1827 
    18281849                </ul>
    1829 
    1830 <?php else : ?>
    1831 
    1832                 <span class="activity"><?php _e( 'No Mods', 'buddypress' ) ?></span>
    1833 
    1834 <?php endif;
    1835 
     1850        <?php else : ?>
     1851                <span class="activity">
     1852                        <?php esc_html_e( 'No Mods', 'buddypress' ); ?>
     1853                </span>
     1854                <?php
     1855        endif;
    18361856}
    18371857
    18381858/**
    18391859 * Return a list of user IDs for a group's admins.
    18401860 *
    18411861 * @since 1.5.0
     1862 * @since 10.0.0 Updated to use `bp_get_group`.
    18421863 *
    1843  * @param BP_Groups_Group|bool $group     Optional. The group being queried. Defaults
    1844  *                                        to the current group in the loop.
    1845  * @param string               $format    Optional. 'string' to get a comma-separated string,
    1846  *                                        'array' to get an array.
    1847  * @return mixed               $admin_ids A string or array of user IDs.
     1864 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     1865 *                                                Default: false.
     1866 * @param string                           $format (Optional) 'string' to get a comma-separated string,
     1867 *                                                 'array' to get an array.
     1868 * @return string|array|false A string or an array of user IDs, false if group does not exist.
    18481869 */
    18491870function bp_group_admin_ids( $group = false, $format = 'string' ) {
    1850         global $groups_template;
     1871        $group = bp_get_group( $group );
    18511872
    1852         if ( empty( $group ) ) {
    1853                 $group =& $groups_template->group;
     1873        if ( empty( $group->id ) ) {
     1874                return false;
    18541875        }
    18551876
    18561877        $admin_ids = array();
    18571878
    1858         if ( $group->admins ) {
    1859                 foreach( $group->admins as $admin ) {
     1879        if ( ! empty( $group->admins ) ) {
     1880                foreach ( $group->admins as $admin ) {
    18601881                        $admin_ids[] = $admin->user_id;
    18611882                }
    18621883        }
    18631884
    1864         if ( 'string' == $format ) {
     1885        if ( 'string' == $format && ! empty( $admin_ids ) ) {
    18651886                $admin_ids = implode( ',', $admin_ids );
    18661887        }
    18671888
    function bp_group_admin_ids( $group = false, $format = 'string' ) { 
    18711892         * This filter may return either an array or a comma separated string.
    18721893         *
    18731894         * @since 1.5.0
    1874          * @since 2.5.0 Added the `$group` parameter.
     1895         * @since 2.5.0  Added the `$group` parameter.
     1896         * @since 10.0.0 Added the `$format` parameter.
    18751897         *
    1876          * @param array|string $admin_ids List of user IDs for a group's admins.
    1877          * @param object       $group     Group object.
     1898         * @param array|string     $admin_ids List of user IDs for a group's admins.
     1899         * @param BP_Groups_Group  $group     The group object.
     1900         * @param string           $format    The filter used to format the results.
    18781901         */
    1879         return apply_filters( 'bp_group_admin_ids', $admin_ids, $group );
     1902        return apply_filters( 'bp_group_admin_ids', $admin_ids, $group, $format );
    18801903}
    18811904
    18821905/**
    18831906 * Return a list of user IDs for a group's moderators.
    18841907 *
    18851908 * @since 1.5.0
     1909 * @since 10.0.0 Updated to use `bp_get_group`.
    18861910 *
    1887  * @param BP_Groups_Group|bool $group   Optional. The group being queried.
    1888  *                                      Defaults to the current group in the loop.
    1889  * @param string               $format  Optional. 'string' to get a comma-separated string,
    1890  *                                      'array' to get an array.
    1891  * @return mixed               $mod_ids A string or array of user IDs.
     1911 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     1912 *                                                Default: false.
     1913 * @param string                           $format (Optional) 'string' to get a comma-separated string,
     1914 *                                                 'array' to get an array.
     1915 * @return string|array|false A string or an array of user IDs, false if group does not exist.
    18921916 */
    18931917function bp_group_mod_ids( $group = false, $format = 'string' ) {
    1894         global $groups_template;
     1918        $group = bp_get_group( $group );
    18951919
    1896         if ( empty( $group ) ) {
    1897                 $group =& $groups_template->group;
     1920        if ( empty( $group->id ) ) {
     1921                return false;
    18981922        }
    18991923
    19001924        $mod_ids = array();
    19011925
    1902         if ( $group->mods ) {
    1903                 foreach( $group->mods as $mod ) {
     1926        if ( ! empty( $group->mods ) ) {
     1927                foreach ( $group->mods as $mod ) {
    19041928                        $mod_ids[] = $mod->user_id;
    19051929                }
    19061930        }
    19071931
    1908         if ( 'string' == $format ) {
     1932        if ( 'string' == $format && ! empty( $mod_ids ) ) {
    19091933                $mod_ids = implode( ',', $mod_ids );
    19101934        }
    19111935
    function bp_group_mod_ids( $group = false, $format = 'string' ) { 
    19151939         * This filter may return either an array or a comma separated string.
    19161940         *
    19171941         * @since 1.5.0
    1918          * @since 2.5.0 Added the `$group` parameter.
     1942         * @since 2.5.0  Added the `$group` parameter.
     1943         * @since 10.0.0 Added the `$format` parameter.
    19191944         *
    1920          * @param array|string $admin_ids List of user IDs for a group's moderators.
    1921          * @param object       $group     Group object.
     1945         * @param array|string     $mod_ids List of user IDs for a group's moderators.
     1946         * @param BP_Groups_Group  $group   The group object.
     1947         * @param string           $format  The filter used to format the results.
    19221948         */
    1923         return apply_filters( 'bp_group_mod_ids', $mod_ids, $group );
     1949        return apply_filters( 'bp_group_mod_ids', $mod_ids, $group, $format );
    19241950}
    19251951
    19261952/**
    1927  * Output the permalink of the current group's Members page.
     1953 * Output the permalink of a group's Members page.
    19281954 *
    19291955 * @since 1.0.0
     1956 * @since 10.0.0 Added the `$group` parameter.
     1957 *
     1958 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     1959 *                                                Default: false.
    19301960 */
    1931 function bp_group_all_members_permalink() {
    1932         echo bp_get_group_all_members_permalink();
     1961function bp_group_all_members_permalink( $group = false ) {
     1962        echo bp_get_group_all_members_permalink( $group );
    19331963}
    19341964        /**
    1935          * Return the permalink of the Members page of the current group in the loop.
     1965         * Return the permalink of the Members page of a group.
    19361966         *
    19371967         * @since 1.0.0
     1968         * @since 10.0.0 Updated to use `bp_get_group`.
    19381969         *
    1939          * @param object|bool $group Optional. Group object.
    1940          *                           Default: current group in loop.
     1970         * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     1971     *                                                Default: false.
    19411972         * @return string
    19421973         */
    19431974        function bp_get_group_all_members_permalink( $group = false ) {
    1944                 global $groups_template;
     1975                $group = bp_get_group( $group );
    19451976
    1946                 if ( empty( $group ) ) {
    1947                         $group =& $groups_template->group;
     1977                if ( empty( $group->id ) ) {
     1978                        return '';
    19481979                }
    19491980
    19501981                /**
    1951                  * Filters the permalink of the Members page for the current group in the loop.
     1982                 * Filters the permalink of the Members page for a group.
    19521983                 *
    19531984                 * @since 1.0.0
    19541985                 * @since 2.5.0 Added the `$group` parameter.
    19551986                 *
    1956                  * @param string $value Permalink of the Members page for the current group.
    1957                  * @param object $group Group object.
     1987                 * @param string          $value Permalink of the Members page for a group.
     1988                 * @param BP_Groups_Group $group The group object.
    19581989                 */
    19591990                return apply_filters( 'bp_get_group_all_members_permalink', trailingslashit( bp_get_group_permalink( $group ) . 'members' ), $group );
    19601991        }
    function bp_groups_auto_join() { 
    21152146 *
    21162147 * @since 1.0.0
    21172148 *
    2118  * @param object|bool $group Optional. Group object. Default: current group in loop.
     2149 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     2150 *                                                Default: false.
    21192151 */
    21202152function bp_group_total_members( $group = false ) {
    21212153        echo bp_get_group_total_members( $group );
    function bp_group_total_members( $group = false ) { 
    21252157         *
    21262158         * @since 1.0.0
    21272159         *
    2128          * @param object|bool $group Optional. Group object.
    2129          *                           Default: current group in loop.
     2160         * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     2161     *                                                Default: false.
    21302162         * @return int
    21312163         */
    21322164        function bp_get_group_total_members( $group = false ) {
    2133                 global $groups_template;
     2165                $group = bp_get_group( $group );
    21342166
    2135                 if ( empty( $group ) ) {
    2136                         $group =& $groups_template->group;
     2167                if ( empty( $group->id ) ) {
     2168                        return 0;
    21372169                }
    21382170
    21392171                /**
    function bp_group_total_members( $group = false ) { 
    21422174                 * @since 1.0.0
    21432175                 * @since 2.5.0 Added the `$group` parameter.
    21442176                 *
    2145                  * @param int    $total_member_count Total member count for a group.
    2146                  * @param object $group              Group object.
     2177                 * @param int             $total_member_count Total member count for a group.
     2178                 * @param BP_Groups_Group $group              The group object.
    21472179                 */
    2148                 return apply_filters( 'bp_get_group_total_members', $group->total_member_count, $group );
     2180                return apply_filters( 'bp_get_group_total_members', (int) $group->total_member_count, $group );
    21492181        }
    21502182
    21512183/**
    function bp_group_total_members( $group = false ) { 
    21542186 * @since 1.2.0
    21552187 * @since 7.0.0 Adds the `$group` optional parameter.
    21562188 *
    2157  * @param object|bool $group Optional. Group object. Default: current group in loop.
     2189 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     2190 *                                                Default: false.
    21582191 */
    21592192function bp_group_member_count( $group = false ) {
    21602193        echo bp_get_group_member_count( $group );
    function bp_group_member_count( $group = false ) { 
    21632196         * Generate the "x members" count string for a group.
    21642197         *
    21652198         * @since 1.2.0
     2199         * @since 7.0.0  Adds the `$group` optional parameter.
     2200         * @since 10.0.0 Updated to use `bp_get_group`.
    21662201         *
    2167          * @since 7.0.0 Adds the `$group` optional parameter.
    2168          *
    2169          * @param object|bool $group Optional. Group object. Default: current group in loop.
     2202         * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     2203     *                                                Default: false.
    21702204         * @return string
    21712205         */
    21722206        function bp_get_group_member_count( $group = false ) {
    2173                 global $groups_template;
     2207                $group = bp_get_group( $group );
    21742208
    2175                 if ( isset( $group->total_member_count ) ) {
    2176                         $count = (int) $group->total_member_count;
    2177                 } elseif ( isset( $groups_template->group->total_member_count ) ) {
    2178                         $count = (int) $groups_template->group->total_member_count;
    2179                 } else {
    2180                         $count = 0;
     2209                if ( empty( $group->id ) ) {
     2210                        return '';
    21812211                }
    21822212
    2183                 $count_string = sprintf( _n( '%s member', '%s members', $count, 'buddypress' ), bp_core_number_format( $count ) );
     2213                $count        = (int) $group->total_member_count;
     2214                $count_string = sprintf(
     2215                        // translators: %s: total member count for the group.
     2216                        _n( '%s member', '%s members', $count, 'buddypress' ),
     2217                        bp_core_number_format( $count )
     2218                );
    21842219
    21852220                /**
    21862221                 * Filters the "x members" count string for a group.
    21872222                 *
    21882223                 * @since 1.2.0
     2224                 * @since 10.0.0 Added the `$group` paremeter.
    21892225                 *
    2190                  * @param string $count_string The "x members" count string for a group.
     2226                 * @param string          $count_string The "x members" count string for a group.
     2227                 * @param BP_Groups_Group $group        The group object.
    21912228                 */
    2192                 return apply_filters( 'bp_get_group_member_count', $count_string );
     2229                return apply_filters( 'bp_get_group_member_count', $count_string, $group );
    21932230        }
    21942231
    21952232/**
    2196  * Output the URL of the Forum page of the current group in the loop.
     2233 * Output the URL of the Forum page of a group.
    21972234 *
    21982235 * @since 1.0.0
     2236 * @since 10.0.0 Adds the `$group` optional parameter.
     2237 *
     2238 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     2239 *                                                Default: false.
    21992240 */
    2200 function bp_group_forum_permalink() {
    2201         echo bp_get_group_forum_permalink();
     2241function bp_group_forum_permalink( $group = false ) {
     2242        echo bp_get_group_forum_permalink( $group );
    22022243}
    22032244        /**
    22042245         * Generate the URL of the Forum page of a group.
    22052246         *
    22062247         * @since 1.0.0
     2248         * @since 10.0.0 Updated to use `bp_get_group`.
    22072249         *
    2208          * @param object|bool $group Optional. Group object.
    2209          *                           Default: current group in loop.
     2250         * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     2251     *                                                Default: false.
    22102252         * @return string
    22112253         */
    22122254        function bp_get_group_forum_permalink( $group = false ) {
    2213                 global $groups_template;
     2255                $group = bp_get_group( $group );
    22142256
    2215                 if ( empty( $group ) ) {
    2216                         $group =& $groups_template->group;
     2257                if ( empty( $group->id ) ) {
     2258                        return '';
    22172259                }
    22182260
    22192261                /**
    function bp_group_forum_permalink() { 
    22222264                 * @since 1.0.0
    22232265                 * @since 2.5.0 Added the `$group` parameter.
    22242266                 *
    2225                  * @param string $value URL permalink for the Forum Page.
    2226                  * @param object $group Group object.
     2267                 * @param string          $value URL permalink for the Forum Page.
     2268                 * @param BP_Groups_Group $group The group object.
    22272269                 */
    22282270                return apply_filters( 'bp_get_group_forum_permalink', trailingslashit( bp_get_group_permalink( $group ) . 'forum' ), $group );
    22292271        }
    function bp_group_forum_permalink() { 
    22322274 * Determine whether forums are enabled for a group.
    22332275 *
    22342276 * @since 1.0.0
     2277 * @since 10.0.0 Updated to use `bp_get_group`.
    22352278 *
    2236  * @param object|bool $group Optional. Group object. Default: current group in loop.
     2279 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     2280 *                                                Default: false.
    22372281 * @return bool
    22382282 */
    22392283function bp_group_is_forum_enabled( $group = false ) {
    2240         global $groups_template;
    2241 
    2242         if ( empty( $group ) ) {
    2243                 $group =& $groups_template->group;
    2244         }
    2245 
    2246         if ( ! empty( $group->enable_forum ) ) {
    2247                 return true;
    2248         }
     2284        $group = bp_get_group( $group );
    22492285
    2250         return false;
     2286        return ! empty( $group->enable_forum );
    22512287}
    22522288
    22532289/**
    22542290 * Output the 'checked' attribute for the group forums settings UI.
    22552291 *
    22562292 * @since 1.0.0
     2293 * @since 10.0.0 Updated to use `bp_group_is_forum_enabled`.
    22572294 *
    2258  * @param object|bool $group Optional. Group object. Default: current group in loop.
     2295 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     2296 *                                                Default: false.
    22592297 */
    22602298function bp_group_show_forum_setting( $group = false ) {
    2261         global $groups_template;
    2262 
    2263         if ( empty( $group ) ) {
    2264                 $group =& $groups_template->group;
    2265         }
    2266 
    2267         if ( $group->enable_forum ) {
     2299        if ( bp_group_is_forum_enabled( $group ) ) {
    22682300                echo ' checked="checked"';
    22692301        }
    22702302}
    function bp_group_show_forum_setting( $group = false ) { 
    22732305 * Output the 'checked' attribute for a given status in the settings UI.
    22742306 *
    22752307 * @since 1.0.0
     2308 * @since 10.0.0 Updated to use `bp_get_group`.
    22762309 *
    2277  * @param string      $setting Group status. 'public', 'private', 'hidden'.
    2278  * @param object|bool $group   Optional. Group object. Default: current group in loop.
     2310 * @param string                           $setting Group status: 'public', 'private', 'hidden'.
     2311 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     2312 *                                                Default: false.
    22792313 */
    22802314function bp_group_show_status_setting( $setting, $group = false ) {
    2281         global $groups_template;
    2282 
    2283         if ( empty( $group ) ) {
    2284                 $group =& $groups_template->group;
    2285         }
     2315        $group = bp_get_group( $group );
    22862316
    2287         if ( $setting == $group->status ) {
     2317        if ( ! empty( $group->status ) && $setting === $group->status ) {
    22882318                echo ' checked="checked"';
    22892319        }
    22902320}
    function bp_group_show_status_setting( $setting, $group = false ) { 
    22942324 *
    22952325 * @since 1.5.0
    22962326 *
    2297  * @param string      $setting The setting you want to check against ('members',
    2298  *                             'mods', or 'admins').
    2299  * @param object|bool $group   Optional. Group object. Default: current group in loop.
     2327 * @param string                           $setting The setting you want to check against ('members', 'mods', or 'admins').
     2328 * @param false|int|string|BP_Groups_Group $group   (Optional) The Group ID, the Group Slug or the Group object.
     2329 *                                                   Default: false.
    23002330 */
    23012331function bp_group_show_invite_status_setting( $setting, $group = false ) {
    2302         $group_id = isset( $group->id ) ? $group->id : false;
    2303 
    2304         $invite_status = bp_group_get_invite_status( $group_id );
     2332        $invite_status = bp_group_get_invite_status( $group );
    23052333
    2306         if ( $setting == $invite_status ) {
     2334        if ( ! empty( $invite_status ) && $setting === $invite_status ) {
    23072335                echo ' checked="checked"';
    23082336        }
    23092337}
    function bp_group_show_invite_status_setting( $setting, $group = false ) { 
    23202348 * This function can be used either in or out of the loop.
    23212349 *
    23222350 * @since 1.5.0
     2351 * @since 10.0.0 Updated to use `bp_get_group`.
    23232352 *
    2324  * @param int|bool $group_id Optional. The ID of the group whose status you want to
    2325  *                           check. Default: the displayed group, or the current group
    2326  *                           in the loop.
     2353 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     2354 *                                                Default: false.
    23272355 * @return bool|string Returns false when no group can be found. Otherwise
    23282356 *                     returns the group invite status, from among 'members',
    23292357 *                     'mods', and 'admins'.
    23302358 */
    2331 function bp_group_get_invite_status( $group_id = false ) {
    2332         global $groups_template;
     2359function bp_group_get_invite_status( $group = false ) {
     2360        $group = bp_get_group( $group );
    23332361
    2334         if ( !$group_id ) {
     2362        if ( empty( $group->id ) ) {
    23352363                $bp = buddypress();
    23362364
    2337                 if ( isset( $bp->groups->current_group->id ) ) {
    2338                         // Default to the current group first.
    2339                         $group_id = $bp->groups->current_group->id;
    2340                 } elseif ( isset( $groups_template->group->id ) ) {
    2341                         // Then see if we're in the loop.
    2342                         $group_id = $groups_template->group->id;
     2365                // Default to the current group first.
     2366                if ( ! empty( $bp->groups->current_group->id ) ) {
     2367                        $group = $bp->groups->current_group;
    23432368                } else {
    23442369                        return false;
    23452370                }
    23462371        }
    23472372
    2348         $invite_status = groups_get_groupmeta( $group_id, 'invite_status' );
     2373        $invite_status = groups_get_groupmeta( $group->id, 'invite_status' );
    23492374
    23502375        // Backward compatibility. When 'invite_status' is not set, fall back to a default value.
    2351         if ( !$invite_status ) {
     2376        if ( ! $invite_status ) {
    23522377                $invite_status = apply_filters( 'bp_group_invite_status_fallback', 'members' );
    23532378        }
    23542379
    function bp_group_get_invite_status( $group_id = false ) { 
    23582383         * Invite status in this case means who from the group can send invites.
    23592384         *
    23602385         * @since 1.5.0
     2386         * @since 10.0.0 Added the `$group` paremeter.
    23612387         *
    2362          * @param string $invite_status Membership level needed to send an invite.
    2363          * @param int    $group_id      ID of the group whose status is being checked.
     2388         * @param string          $invite_status Membership level needed to send an invite.
     2389         * @param int             $group_id      ID of the group whose status is being checked.
     2390         * @param BP_Groups_Group $group         The group object.
    23642391         */
    2365         return apply_filters( 'bp_group_get_invite_status', $invite_status, $group_id );
     2392        return apply_filters( 'bp_group_get_invite_status', $invite_status, $group->id, $group );
    23662393}
    23672394
    23682395/**
    function bp_group_mod_memberlist( $admin_list = false, $group = false ) { 
    26262653 * Determine whether a group has moderators.
    26272654 *
    26282655 * @since 1.0.0
     2656 * @since 10.0.0 Updated to use `bp_get_group`.
    26292657 *
    2630  * @param object|bool $group Optional. Group object. Default: current group in loop.
     2658 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     2659 *                                                Default: false.
    26312660 * @return array Info about group admins (user_id + date_modified).
    26322661 */
    26332662function bp_group_has_moderators( $group = false ) {
    2634         global $groups_template;
     2663        $group = bp_get_group( $group );
    26352664
    2636         if ( empty( $group ) ) {
    2637                 $group =& $groups_template->group;
     2665        if ( empty( $group->id ) ) {
     2666                return array();
    26382667        }
    26392668
    26402669        /**
    function bp_group_has_moderators( $group = false ) { 
    26432672         * @since 1.0.0
    26442673         * @since 2.5.0 Added the `$group` parameter.
    26452674         *
    2646          * @param array  $value Array of user IDs who are a moderator of the provided group.
    2647          * @param object $group Group object.
     2675         * @param array           $value Array of user IDs who are a moderator of the provided group.
     2676         * @param BP_Groups_Group $group The group object.
    26482677         */
    26492678        return apply_filters( 'bp_group_has_moderators', groups_get_group_mods( $group->id ), $group );
    26502679}
  • src/bp-groups/classes/class-bp-groups-member.php

    diff --git src/bp-groups/classes/class-bp-groups-member.php src/bp-groups/classes/class-bp-groups-member.php
    index a442ce932..738a8aa8b 100644
    class BP_Groups_Member { 
    11881188         * @return array Info about group mods (user_id + date_modified).
    11891189         */
    11901190        public static function get_group_moderator_ids( $group_id ) {
    1191                 global $wpdb;
    11921191
    11931192                if ( empty( $group_id ) ) {
    11941193                        return array();
  • new file tests/phpunit/testcases/groups/functions/get-group.php

    diff --git tests/phpunit/testcases/groups/functions/get-group.php tests/phpunit/testcases/groups/functions/get-group.php
    new file mode 100644
    index 000000000..c86240832
    - +  
     1<?php
     2
     3/**
     4 * @group groups
     5 * @group functions
     6 */
     7class BP_Tests_Get_Groups_Param extends BP_UnitTestCase {
     8
     9        public function setUp() {
     10                parent::setUp();
     11
     12                if ( isset( $GLOBALS['groups_template'] ) ) {
     13                        $this->groups_template = $GLOBALS['groups_template'];
     14                }
     15        }
     16
     17        public function tearDown() {
     18                if ( $this->groups_template ) {
     19                        $GLOBALS['groups_template'] = $this->groups_template;
     20                }
     21
     22                parent::tearDown();
     23        }
     24
     25        public function test_bp_get_group_with_no_group() {
     26                $this->assertFalse( bp_get_group() );
     27                $this->assertFalse( bp_get_group_by( 'id', 0 ) );
     28        }
     29
     30        public function test_bp_get_group_with_id() {
     31                $g = $this->factory->group->create();
     32
     33                $this->assertSame( $g, bp_get_group( $g )->id );
     34                $this->assertSame( $g, bp_get_group_by( 'id', $g )->id );
     35                $this->assertSame( $g, bp_get_group_by( 'ID', $g )->id );
     36        }
     37
     38        public function test_bp_get_group_with_slug() {
     39                $slug = 'test-group';
     40                $g    = $this->factory->group->create( array( 'slug' => $slug ) );
     41                $g1   = bp_get_group( $slug );
     42
     43                $this->assertSame( $g, $g1->id );
     44                $this->assertSame( $slug, $g1->slug );
     45
     46                $g2 = bp_get_group_by( 'slug', $slug );
     47
     48                $this->assertSame( $g, $g2->id );
     49                $this->assertSame( $slug, $g2->slug );
     50        }
     51
     52        public function test_bp_get_group_with_object() {
     53                $g = $this->factory->group->create_and_get();
     54
     55                $this->assertSame( $g->id, bp_get_group( $g )->id );
     56        }
     57
     58        public function test_bp_get_group_from_groups_template() {
     59                $g = $this->factory->group->create( array( 'status' => 'private' ) );
     60
     61                // Fake the current group.
     62                $GLOBALS['groups_template'] = new stdClass;
     63                $GLOBALS['groups_template']->group = groups_get_group( $g );
     64
     65                $this->assertSame( $g, bp_get_group()->id );
     66        }
     67}
  • tests/phpunit/testcases/groups/template.php

    diff --git tests/phpunit/testcases/groups/template.php tests/phpunit/testcases/groups/template.php
    index 489bf8134..af1e8159c 100644
     
    44 * @group template
    55 */
    66class BP_Tests_Groups_Template extends BP_UnitTestCase {
     7
     8        public function setUp() {
     9                parent::setUp();
     10
     11                if ( isset( $GLOBALS['groups_template'] ) ) {
     12                        $this->groups_template = $GLOBALS['groups_template'];
     13                }
     14        }
     15
     16        public function tearDown() {
     17                if ( $this->groups_template ) {
     18                        $GLOBALS['groups_template'] = $this->groups_template;
     19                }
     20
     21                parent::tearDown();
     22        }
     23
    724        /**
    825         * Integration test to make sure meta_query is getting passed through
    926         *
    class BP_Tests_Groups_Template extends BP_UnitTestCase { 
    949966                $this->set_current_user( $old_user );
    950967        }
    951968
     969        /**
     970         * @group bp_group_is_forum_enabled
     971         */
     972        public function test_bp_group_is_forum_enabled() {
     973                $g1 = $this->factory->group->create( array( 'enable_forum' => 0 ) );
     974                $g2 = $this->factory->group->create( array( 'enable_forum' => 1 ) );
     975
     976                $this->assertFalse( bp_group_is_forum_enabled( $g1 ) );
     977                $this->assertTrue( bp_group_is_forum_enabled( $g2 ) );
     978        }
     979
    952980        /**
    953981         * @group bp_get_group_member_count
    954982         */
    955983        public function test_bp_get_group_member_count_0_members() {
    956                 global $groups_template;
    957                 $gt = $groups_template;
    958                 $groups_template = new stdClass;
    959                 $groups_template->group = new stdClass;
    960                 $groups_template->group->total_member_count = 0;
     984                $u = $this->factory->user->create();
     985                $g = $this->factory->group->create( array( 'creator_id' => $u ) );
    961986
    962                 $found = bp_get_group_member_count();
     987                // Fake the current group.
     988                $GLOBALS['groups_template'] = new stdClass;
     989                $GLOBALS['groups_template']->group = groups_get_group( $g );
    963990
    964                 $groups_template = $gt;
     991                // Kick group creator.
     992                wp_delete_user( $u );
    965993
    966                 $this->assertSame( '0 members', $found );
     994                $this->assertNotSame( '0 member', bp_get_group_member_count() );
    967995        }
    968996
    969997        /**
    970998         * @group bp_get_group_member_count
    971999         */
    9721000        public function test_bp_get_group_member_count_1_member() {
    973                 global $groups_template;
    974                 $gt = $groups_template;
    975                 $groups_template = new stdClass;
    976                 $groups_template->group = new stdClass;
    977                 $groups_template->group->total_member_count = 1;
    978 
    979                 $found = bp_get_group_member_count();
     1001                $g = $this->factory->group->create();
    9801002
    981                 $groups_template = $gt;
     1003                // Fake the current group.
     1004                $GLOBALS['groups_template'] = new stdClass;
     1005                $GLOBALS['groups_template']->group = groups_get_group( $g );
    9821006
    983                 $this->assertSame( '1 member', $found );
     1007                $this->assertSame( '1 member', bp_get_group_member_count() );
    9841008        }
    9851009
    9861010        /**
    9871011         * @group bp_get_group_member_count
    9881012         */
    9891013        public function test_bp_get_group_member_count_2_members() {
    990                 global $groups_template;
    991                 $gt = $groups_template;
    992                 $groups_template = new stdClass;
    993                 $groups_template->group = new stdClass;
    994                 $groups_template->group->total_member_count = 2;
     1014                $u1 = $this->factory->user->create();
     1015                $u2 = $this->factory->user->create();
     1016                $g  = $this->factory->group->create( array( 'creator_id' => $u1 ) );
    9951017
    996                 $found = bp_get_group_member_count();
     1018                $this->add_user_to_group( $u2, $g );
    9971019
    998                 $groups_template = $gt;
     1020                // Fake the current group.
     1021                $GLOBALS['groups_template'] = new stdClass;
     1022                $GLOBALS['groups_template']->group = groups_get_group( $g );
    9991023
    1000                 $this->assertSame( '2 members', $found );
     1024                $this->assertSame( '2 members', bp_get_group_member_count() );
    10011025        }
    10021026
    10031027        /**
  • new file tests/phpunit/testcases/groups/template/group-is-visible.php

    diff --git tests/phpunit/testcases/groups/template/group-is-visible.php tests/phpunit/testcases/groups/template/group-is-visible.php
    new file mode 100644
    index 000000000..c1f78148b
    - +  
     1<?php
     2
     3/**
     4 * @group groups
     5 * @group template
     6 */
     7class BP_Tests_Groups_Template_Is_Visible extends BP_UnitTestCase {
     8
     9        public function setUp() {
     10                parent::setUp();
     11
     12                if ( isset( $GLOBALS['groups_template'] ) ) {
     13                        $this->groups_template = $GLOBALS['groups_template'];
     14                }
     15        }
     16
     17        public function tearDown() {
     18                if ( $this->groups_template ) {
     19                        $GLOBALS['groups_template'] = $this->groups_template;
     20                }
     21
     22                parent::tearDown();
     23        }
     24
     25        public function test_bp_group_is_visible_no_member() {
     26                $g = $this->factory->group->create( array( 'status' => 'private' ) );
     27
     28                $this->assertFalse( bp_group_is_visible( $g ) );
     29        }
     30
     31        public function test_bp_group_is_visible_regular_member() {
     32                $g = $this->factory->group->create( array( 'status' => 'private' ) );
     33                $u = $this->factory->user->create();
     34
     35                $this->set_current_user( $u );
     36
     37                $this->assertFalse( bp_group_is_visible( $g ) );
     38        }
     39
     40        public function test_bp_group_is_visible_regular_member_from_group() {
     41                $g = $this->factory->group->create( array( 'status' => 'private' ) );
     42                $u = $this->factory->user->create();
     43
     44                $this->set_current_user( $u );
     45
     46                $this->add_user_to_group( $u, $g );
     47
     48                $this->assertTrue( bp_group_is_visible( $g ) );
     49        }
     50
     51        public function test_bp_group_is_visible_invalid_group() {
     52                $u = $this->factory->user->create();
     53
     54                // Empty the current group.
     55                $GLOBALS['groups_template'] = new stdClass;
     56                $GLOBALS['groups_template']->group = null;
     57
     58                $this->set_current_user( $u );
     59
     60                $this->assertFalse( bp_group_is_visible() );
     61        }
     62
     63        public function test_bp_group_is_visible_admin() {
     64                $g = $this->factory->group->create( array( 'status' => 'private' ) );
     65                $u = $this->factory->user->create( array( 'role' => 'administrator' ) );
     66
     67                $this->set_current_user( $u );
     68
     69                $this->assertTrue( bp_group_is_visible( $g ) );
     70        }
     71
     72        public function test_bp_group_is_visible_using_user_id() {
     73                $g = $this->factory->group->create( array( 'status' => 'hidden' ) );
     74                $u = $this->factory->user->create();
     75
     76                $this->add_user_to_group( $u, $g );
     77
     78                $this->assertTrue( bp_group_is_visible( $g, $u ) );
     79        }
     80
     81        public function test_bp_group_is_not_visible_using_user_id() {
     82                $g = $this->factory->group->create( array( 'status' => 'private' ) );
     83                $u = $this->factory->user->create();
     84
     85                $this->assertFalse( bp_group_is_visible( $g, $u ) );
     86        }
     87
     88        public function test_bp_group_is_visible_with_group_slug() {
     89                $slug = 'test-group';
     90
     91                $this->factory->group->create(
     92                        array(
     93                                'status' => 'private',
     94                                'slug'   => $slug,
     95                        )
     96                );
     97
     98                $u = $this->factory->user->create( array( 'role' => 'administrator' ) );
     99
     100                $this->set_current_user( $u );
     101
     102                $this->assertTrue( bp_group_is_visible( $slug ) );
     103        }
     104
     105        public function test_bp_group_is_visible_from_current_group() {
     106                $g = $this->factory->group->create( array( 'status' => 'private' ) );
     107                $u = $this->factory->user->create( array( 'role' => 'administrator' ) );
     108
     109                // Fake the current group.
     110                $GLOBALS['groups_template'] = new stdClass;
     111                $GLOBALS['groups_template']->group = groups_get_group( $g );
     112
     113                $this->set_current_user( $u );
     114
     115                $this->assertTrue( bp_group_is_visible() );
     116        }
     117}