Ticket #6749: 6749-3.diff
| File 6749-3.diff, 38.8 KB (added by , 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 ) { 896 896 'id' => false, 897 897 // translators: %1$s is the name of the group. 898 898 'alt' => sprintf( __( 'Group logo of %1$s', 'buddypress' ), $group->name ), 899 ) 899 ), 900 'get_group_avatar' 900 901 ); 901 902 902 903 // Fetch the avatar from the folder. … … function bp_group_avatar_url( $group = false, $type = 'full' ) { 1017 1018 * Returns the group avatar URL. 1018 1019 * 1019 1020 * @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`. 1021 1022 * 1022 1023 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object. 1023 1024 * Default: false. … … function bp_group_last_active( $group = false, $args = array() ) { 1111 1112 return ''; 1112 1113 } 1113 1114 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 ); 1117 1122 1118 1123 $last_active = $group->last_activity; 1119 1124 if ( ! $last_active ) { … … function bp_group_last_active( $group = false, $args = array() ) { 1136 1141 * @since 1.0.0 1137 1142 * @since 2.5.0 Added the `$group` parameter. 1138 1143 * 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. 1141 1146 */ 1142 1147 return apply_filters( 'bp_get_group_last_active', bp_core_time_since( $last_active ), $group ); 1143 1148 } … … function bp_is_group_creator( $group = false, $user_id = 0 ) { 1647 1652 } 1648 1653 1649 1654 /** 1650 * Output the avatar of the creator of the current group in the loop.1655 * Output the avatar of the creator of the group. 1651 1656 * 1652 1657 * @since 1.7.0 1653 1658 * 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 { 1657 1662 * Array of optional arguments. See {@link bp_get_group_creator_avatar()} 1658 1663 * for description. 1659 1664 * } … … function bp_group_creator_avatar( $group = false, $args = array() ) { 1662 1667 echo bp_get_group_creator_avatar( $group, $args ); 1663 1668 } 1664 1669 /** 1665 * Return the avatar of the creator of the current group in the loop.1670 * Return the avatar of the creator of the group. 1666 1671 * 1667 1672 * @since 1.7.0 1673 * @since 10.0.0 Updated to use `bp_get_group`. 1668 1674 * 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 { 1672 1678 * Array of optional arguments. See {@link bp_core_fetch_avatar()} 1673 1679 * for detailed description of arguments. 1674 1680 * @type string $type Default: 'full'. … … function bp_group_creator_avatar( $group = false, $args = array() ) { 1682 1688 * @return string 1683 1689 */ 1684 1690 function bp_get_group_creator_avatar( $group = false, $args = array() ) { 1685 global $groups_template;1691 $group = bp_get_group( $group ); 1686 1692 1687 if ( empty( $group ) ) {1688 $group =& $groups_template->group;1693 if ( empty( $group->id ) ) { 1694 return ''; 1689 1695 } 1690 1696 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 ), 1701 1710 ), 1702 ), 'group_creator_avatar' );1703 extract( $r, EXTR_SKIP);1711 'group_creator_avatar' 1712 ); 1704 1713 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 ); 1706 1725 1707 1726 /** 1708 * Filters the avatar of the creator of the current group in the loop.1727 * Filters the avatar of the creator of the group. 1709 1728 * 1710 1729 * @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. 1712 1732 * 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. 1715 1736 */ 1716 return apply_filters( 'bp_get_group_creator_avatar', $avatar, $group );1737 return apply_filters( 'bp_get_group_creator_avatar', $avatar, $group, $r ); 1717 1738 } 1718 1739 1719 1740 /** … … function bp_group_is_mod() { 1746 1767 * Output markup listing group admins. 1747 1768 * 1748 1769 * @since 1.0.0 1770 * @since 10.0.0 Updated to use `bp_get_group`. 1749 1771 * 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. 1752 1774 */ 1753 1775 function 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 ); 1759 1777 1760 1778 if ( ! empty( $group->admins ) ) { ?> 1761 1779 <ul id="group-admins"> 1762 <?php foreach ( (array) $group->admins as $admin ) { ?>1780 <?php foreach ( (array) $group->admins as $admin ) { ?> 1763 1781 <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 > 1765 1787 <?php 1766 1788 echo bp_core_fetch_avatar( 1767 1789 array( … … function bp_group_list_admins( $group = false ) { 1780 1802 <?php } ?> 1781 1803 </ul> 1782 1804 <?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> 1784 1808 <?php } ?> 1785 <?php1809 <?php 1786 1810 } 1787 1811 1788 1812 /** 1789 1813 * Output markup listing group mod. 1790 1814 * 1791 1815 * @since 1.0.0 1816 * @since 10.0.0 Updated to use `bp_get_group`. 1792 1817 * 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. 1795 1820 */ 1796 1821 function 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 ); 1804 1823 1824 if ( ! empty( $group->mods ) ) : 1825 ?> 1805 1826 <ul id="group-mods"> 1806 1807 <?php foreach( (array) $group->mods as $mod ) { ?> 1808 1827 <?php foreach ( (array) $group->mods as $mod ) { ?> 1809 1828 <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 ) ); ?>"> 1811 1833 <?php 1812 1834 echo bp_core_fetch_avatar( 1813 1835 array( … … function bp_group_list_mods( $group = false ) { 1819 1841 bp_core_get_user_displayname( $mod->user_id ) 1820 1842 ), 1821 1843 ) 1822 ); ?> 1844 ); 1845 ?> 1823 1846 </a> 1824 1847 </li> 1825 1826 1848 <?php } ?> 1827 1828 1849 </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; 1836 1856 } 1837 1857 1838 1858 /** 1839 1859 * Return a list of user IDs for a group's admins. 1840 1860 * 1841 1861 * @since 1.5.0 1862 * @since 10.0.0 Updated to use `bp_get_group`. 1842 1863 * 1843 * @param BP_Groups_Group|bool $group Optional. The group being queried. Defaults1844 * 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. 1848 1869 */ 1849 1870 function bp_group_admin_ids( $group = false, $format = 'string' ) { 1850 global $groups_template;1871 $group = bp_get_group( $group ); 1851 1872 1852 if ( empty( $group ) ) {1853 $group =& $groups_template->group;1873 if ( empty( $group->id ) ) { 1874 return false; 1854 1875 } 1855 1876 1856 1877 $admin_ids = array(); 1857 1878 1858 if ( $group->admins) {1859 foreach ( $group->admins as $admin ) {1879 if ( ! empty( $group->admins ) ) { 1880 foreach ( $group->admins as $admin ) { 1860 1881 $admin_ids[] = $admin->user_id; 1861 1882 } 1862 1883 } 1863 1884 1864 if ( 'string' == $format ) {1885 if ( 'string' == $format && ! empty( $admin_ids ) ) { 1865 1886 $admin_ids = implode( ',', $admin_ids ); 1866 1887 } 1867 1888 … … function bp_group_admin_ids( $group = false, $format = 'string' ) { 1871 1892 * This filter may return either an array or a comma separated string. 1872 1893 * 1873 1894 * @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. 1875 1897 * 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. 1878 1901 */ 1879 return apply_filters( 'bp_group_admin_ids', $admin_ids, $group );1902 return apply_filters( 'bp_group_admin_ids', $admin_ids, $group, $format ); 1880 1903 } 1881 1904 1882 1905 /** 1883 1906 * Return a list of user IDs for a group's moderators. 1884 1907 * 1885 1908 * @since 1.5.0 1909 * @since 10.0.0 Updated to use `bp_get_group`. 1886 1910 * 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. 1892 1916 */ 1893 1917 function bp_group_mod_ids( $group = false, $format = 'string' ) { 1894 global $groups_template;1918 $group = bp_get_group( $group ); 1895 1919 1896 if ( empty( $group ) ) {1897 $group =& $groups_template->group;1920 if ( empty( $group->id ) ) { 1921 return false; 1898 1922 } 1899 1923 1900 1924 $mod_ids = array(); 1901 1925 1902 if ( $group->mods) {1903 foreach ( $group->mods as $mod ) {1926 if ( ! empty( $group->mods ) ) { 1927 foreach ( $group->mods as $mod ) { 1904 1928 $mod_ids[] = $mod->user_id; 1905 1929 } 1906 1930 } 1907 1931 1908 if ( 'string' == $format ) {1932 if ( 'string' == $format && ! empty( $mod_ids ) ) { 1909 1933 $mod_ids = implode( ',', $mod_ids ); 1910 1934 } 1911 1935 … … function bp_group_mod_ids( $group = false, $format = 'string' ) { 1915 1939 * This filter may return either an array or a comma separated string. 1916 1940 * 1917 1941 * @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. 1919 1944 * 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. 1922 1948 */ 1923 return apply_filters( 'bp_group_mod_ids', $mod_ids, $group );1949 return apply_filters( 'bp_group_mod_ids', $mod_ids, $group, $format ); 1924 1950 } 1925 1951 1926 1952 /** 1927 * Output the permalink of the currentgroup's Members page.1953 * Output the permalink of a group's Members page. 1928 1954 * 1929 1955 * @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. 1930 1960 */ 1931 function bp_group_all_members_permalink( ) {1932 echo bp_get_group_all_members_permalink( );1961 function bp_group_all_members_permalink( $group = false ) { 1962 echo bp_get_group_all_members_permalink( $group ); 1933 1963 } 1934 1964 /** 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. 1936 1966 * 1937 1967 * @since 1.0.0 1968 * @since 10.0.0 Updated to use `bp_get_group`. 1938 1969 * 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. 1941 1972 * @return string 1942 1973 */ 1943 1974 function bp_get_group_all_members_permalink( $group = false ) { 1944 global $groups_template;1975 $group = bp_get_group( $group ); 1945 1976 1946 if ( empty( $group ) ) {1947 $group =& $groups_template->group;1977 if ( empty( $group->id ) ) { 1978 return ''; 1948 1979 } 1949 1980 1950 1981 /** 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. 1952 1983 * 1953 1984 * @since 1.0.0 1954 1985 * @since 2.5.0 Added the `$group` parameter. 1955 1986 * 1956 * @param string $value Permalink of the Members page for the currentgroup.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. 1958 1989 */ 1959 1990 return apply_filters( 'bp_get_group_all_members_permalink', trailingslashit( bp_get_group_permalink( $group ) . 'members' ), $group ); 1960 1991 } … … function bp_groups_auto_join() { 2115 2146 * 2116 2147 * @since 1.0.0 2117 2148 * 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. 2119 2151 */ 2120 2152 function bp_group_total_members( $group = false ) { 2121 2153 echo bp_get_group_total_members( $group ); … … function bp_group_total_members( $group = false ) { 2125 2157 * 2126 2158 * @since 1.0.0 2127 2159 * 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. 2130 2162 * @return int 2131 2163 */ 2132 2164 function bp_get_group_total_members( $group = false ) { 2133 global $groups_template;2165 $group = bp_get_group( $group ); 2134 2166 2135 if ( empty( $group ) ) {2136 $group =& $groups_template->group;2167 if ( empty( $group->id ) ) { 2168 return 0; 2137 2169 } 2138 2170 2139 2171 /** … … function bp_group_total_members( $group = false ) { 2142 2174 * @since 1.0.0 2143 2175 * @since 2.5.0 Added the `$group` parameter. 2144 2176 * 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. 2147 2179 */ 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 ); 2149 2181 } 2150 2182 2151 2183 /** … … function bp_group_total_members( $group = false ) { 2154 2186 * @since 1.2.0 2155 2187 * @since 7.0.0 Adds the `$group` optional parameter. 2156 2188 * 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. 2158 2191 */ 2159 2192 function bp_group_member_count( $group = false ) { 2160 2193 echo bp_get_group_member_count( $group ); … … function bp_group_member_count( $group = false ) { 2163 2196 * Generate the "x members" count string for a group. 2164 2197 * 2165 2198 * @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`. 2166 2201 * 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. 2170 2204 * @return string 2171 2205 */ 2172 2206 function bp_get_group_member_count( $group = false ) { 2173 global $groups_template;2207 $group = bp_get_group( $group ); 2174 2208 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 ''; 2181 2211 } 2182 2212 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 ); 2184 2219 2185 2220 /** 2186 2221 * Filters the "x members" count string for a group. 2187 2222 * 2188 2223 * @since 1.2.0 2224 * @since 10.0.0 Added the `$group` paremeter. 2189 2225 * 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. 2191 2228 */ 2192 return apply_filters( 'bp_get_group_member_count', $count_string );2229 return apply_filters( 'bp_get_group_member_count', $count_string, $group ); 2193 2230 } 2194 2231 2195 2232 /** 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. 2197 2234 * 2198 2235 * @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. 2199 2240 */ 2200 function bp_group_forum_permalink( ) {2201 echo bp_get_group_forum_permalink( );2241 function bp_group_forum_permalink( $group = false ) { 2242 echo bp_get_group_forum_permalink( $group ); 2202 2243 } 2203 2244 /** 2204 2245 * Generate the URL of the Forum page of a group. 2205 2246 * 2206 2247 * @since 1.0.0 2248 * @since 10.0.0 Updated to use `bp_get_group`. 2207 2249 * 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. 2210 2252 * @return string 2211 2253 */ 2212 2254 function bp_get_group_forum_permalink( $group = false ) { 2213 global $groups_template;2255 $group = bp_get_group( $group ); 2214 2256 2215 if ( empty( $group ) ) {2216 $group =& $groups_template->group;2257 if ( empty( $group->id ) ) { 2258 return ''; 2217 2259 } 2218 2260 2219 2261 /** … … function bp_group_forum_permalink() { 2222 2264 * @since 1.0.0 2223 2265 * @since 2.5.0 Added the `$group` parameter. 2224 2266 * 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. 2227 2269 */ 2228 2270 return apply_filters( 'bp_get_group_forum_permalink', trailingslashit( bp_get_group_permalink( $group ) . 'forum' ), $group ); 2229 2271 } … … function bp_group_forum_permalink() { 2232 2274 * Determine whether forums are enabled for a group. 2233 2275 * 2234 2276 * @since 1.0.0 2277 * @since 10.0.0 Updated to use `bp_get_group`. 2235 2278 * 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. 2237 2281 * @return bool 2238 2282 */ 2239 2283 function 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 ); 2249 2285 2250 return false;2286 return ! empty( $group->enable_forum ); 2251 2287 } 2252 2288 2253 2289 /** 2254 2290 * Output the 'checked' attribute for the group forums settings UI. 2255 2291 * 2256 2292 * @since 1.0.0 2293 * @since 10.0.0 Updated to use `bp_group_is_forum_enabled`. 2257 2294 * 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. 2259 2297 */ 2260 2298 function 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 ) ) { 2268 2300 echo ' checked="checked"'; 2269 2301 } 2270 2302 } … … function bp_group_show_forum_setting( $group = false ) { 2273 2305 * Output the 'checked' attribute for a given status in the settings UI. 2274 2306 * 2275 2307 * @since 1.0.0 2308 * @since 10.0.0 Updated to use `bp_get_group`. 2276 2309 * 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. 2279 2313 */ 2280 2314 function 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 ); 2286 2316 2287 if ( $setting== $group->status ) {2317 if ( ! empty( $group->status ) && $setting === $group->status ) { 2288 2318 echo ' checked="checked"'; 2289 2319 } 2290 2320 } … … function bp_group_show_status_setting( $setting, $group = false ) { 2294 2324 * 2295 2325 * @since 1.5.0 2296 2326 * 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. 2300 2330 */ 2301 2331 function 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 ); 2305 2333 2306 if ( $setting== $invite_status ) {2334 if ( ! empty( $invite_status ) && $setting === $invite_status ) { 2307 2335 echo ' checked="checked"'; 2308 2336 } 2309 2337 } … … function bp_group_show_invite_status_setting( $setting, $group = false ) { 2320 2348 * This function can be used either in or out of the loop. 2321 2349 * 2322 2350 * @since 1.5.0 2351 * @since 10.0.0 Updated to use `bp_get_group`. 2323 2352 * 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. 2327 2355 * @return bool|string Returns false when no group can be found. Otherwise 2328 2356 * returns the group invite status, from among 'members', 2329 2357 * 'mods', and 'admins'. 2330 2358 */ 2331 function bp_group_get_invite_status( $group _id= false ) {2332 global $groups_template;2359 function bp_group_get_invite_status( $group = false ) { 2360 $group = bp_get_group( $group ); 2333 2361 2334 if ( !$group_id) {2362 if ( empty( $group->id ) ) { 2335 2363 $bp = buddypress(); 2336 2364 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; 2343 2368 } else { 2344 2369 return false; 2345 2370 } 2346 2371 } 2347 2372 2348 $invite_status = groups_get_groupmeta( $group _id, 'invite_status' );2373 $invite_status = groups_get_groupmeta( $group->id, 'invite_status' ); 2349 2374 2350 2375 // Backward compatibility. When 'invite_status' is not set, fall back to a default value. 2351 if ( ! $invite_status ) {2376 if ( ! $invite_status ) { 2352 2377 $invite_status = apply_filters( 'bp_group_invite_status_fallback', 'members' ); 2353 2378 } 2354 2379 … … function bp_group_get_invite_status( $group_id = false ) { 2358 2383 * Invite status in this case means who from the group can send invites. 2359 2384 * 2360 2385 * @since 1.5.0 2386 * @since 10.0.0 Added the `$group` paremeter. 2361 2387 * 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. 2364 2391 */ 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 ); 2366 2393 } 2367 2394 2368 2395 /** … … function bp_group_mod_memberlist( $admin_list = false, $group = false ) { 2626 2653 * Determine whether a group has moderators. 2627 2654 * 2628 2655 * @since 1.0.0 2656 * @since 10.0.0 Updated to use `bp_get_group`. 2629 2657 * 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. 2631 2660 * @return array Info about group admins (user_id + date_modified). 2632 2661 */ 2633 2662 function bp_group_has_moderators( $group = false ) { 2634 global $groups_template;2663 $group = bp_get_group( $group ); 2635 2664 2636 if ( empty( $group ) ) {2637 $group =& $groups_template->group;2665 if ( empty( $group->id ) ) { 2666 return array(); 2638 2667 } 2639 2668 2640 2669 /** … … function bp_group_has_moderators( $group = false ) { 2643 2672 * @since 1.0.0 2644 2673 * @since 2.5.0 Added the `$group` parameter. 2645 2674 * 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. 2648 2677 */ 2649 2678 return apply_filters( 'bp_group_has_moderators', groups_get_group_mods( $group->id ), $group ); 2650 2679 } -
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 { 1188 1188 * @return array Info about group mods (user_id + date_modified). 1189 1189 */ 1190 1190 public static function get_group_moderator_ids( $group_id ) { 1191 global $wpdb;1192 1191 1193 1192 if ( empty( $group_id ) ) { 1194 1193 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 */ 7 class 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
4 4 * @group template 5 5 */ 6 6 class 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 7 24 /** 8 25 * Integration test to make sure meta_query is getting passed through 9 26 * … … class BP_Tests_Groups_Template extends BP_UnitTestCase { 949 966 $this->set_current_user( $old_user ); 950 967 } 951 968 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 952 980 /** 953 981 * @group bp_get_group_member_count 954 982 */ 955 983 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 ) ); 961 986 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 ); 963 990 964 $groups_template = $gt; 991 // Kick group creator. 992 wp_delete_user( $u ); 965 993 966 $this->assert Same( '0 members', $found);994 $this->assertNotSame( '0 member', bp_get_group_member_count() ); 967 995 } 968 996 969 997 /** 970 998 * @group bp_get_group_member_count 971 999 */ 972 1000 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(); 980 1002 981 $groups_template = $gt; 1003 // Fake the current group. 1004 $GLOBALS['groups_template'] = new stdClass; 1005 $GLOBALS['groups_template']->group = groups_get_group( $g ); 982 1006 983 $this->assertSame( '1 member', $found);1007 $this->assertSame( '1 member', bp_get_group_member_count() ); 984 1008 } 985 1009 986 1010 /** 987 1011 * @group bp_get_group_member_count 988 1012 */ 989 1013 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 ) ); 995 1017 996 $ found = bp_get_group_member_count();1018 $this->add_user_to_group( $u2, $g ); 997 1019 998 $groups_template = $gt; 1020 // Fake the current group. 1021 $GLOBALS['groups_template'] = new stdClass; 1022 $GLOBALS['groups_template']->group = groups_get_group( $g ); 999 1023 1000 $this->assertSame( '2 members', $found);1024 $this->assertSame( '2 members', bp_get_group_member_count() ); 1001 1025 } 1002 1026 1003 1027 /** -
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 */ 7 class 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 }