Ticket #7501: 7501.1.diff
File 7501.1.diff, 5.6 KB (added by , 8 years ago) |
---|
-
src/bp-groups/bp-groups-functions.php
diff --git src/bp-groups/bp-groups-functions.php src/bp-groups/bp-groups-functions.php index fe7fad6..f9d66a6 100644
function groups_get_groups( $args = '' ) { 717 717 'group_type__not_in' => '', // Array or comma-separated list of group types that will be excluded from results. 718 718 'meta_query' => false, // Filter by groupmeta. See WP_Meta_Query for syntax. 719 719 'show_hidden' => false, // Show hidden groups to non-admins. 720 'status' => array(), // Array or comma-separated list of group statuses to limit results to. 720 721 'per_page' => 20, // The number of results to return per page. 721 722 'page' => 1, // The page to return if limiting per page. 722 723 'update_meta_cache' => true, // Pre-fetch groupmeta for queried groups. … … function groups_get_groups( $args = '' ) { 739 740 'group_type__not_in' => $r['group_type__not_in'], 740 741 'meta_query' => $r['meta_query'], 741 742 'show_hidden' => $r['show_hidden'], 743 'status' => $r['status'], 742 744 'per_page' => $r['per_page'], 743 745 'page' => $r['page'], 744 746 'update_meta_cache' => $r['update_meta_cache'], -
src/bp-groups/classes/class-bp-groups-group.php
diff --git src/bp-groups/classes/class-bp-groups-group.php src/bp-groups/classes/class-bp-groups-group.php index dc56591..6ee816c 100644
class BP_Groups_Group { 919 919 * @type bool $update_admin_cache Whether to pre-fetch administrator IDs for the returned 920 920 * groups. Default: false. 921 921 * @type bool $show_hidden Whether to include hidden groups in results. Default: false. 922 * @type array|string $status Optional. Array or comma-separated list of group statuses to limit 923 * results to. If specified, $show_hidden is ignored. 924 * Default: empty array. 922 925 * } 923 926 * @return array { 924 927 * @type array $groups Array of group objects returned by the … … class BP_Groups_Group { 969 972 'update_admin_cache' => false, 970 973 'exclude' => false, 971 974 'show_hidden' => false, 975 'status' => array() 972 976 ); 973 977 974 978 $r = wp_parse_args( $args, $defaults ); … … class BP_Groups_Group { 989 993 990 994 $where_conditions = array(); 991 995 992 if ( empty( $r['show_hidden'] ) ) { 996 997 if ( ! empty( $r['status'] ) ) { 998 if ( ! is_array( $r['status'] ) ) { 999 $r['status'] = preg_split( '/[\s,]+/', $r['status'] ); 1000 } 1001 $r['status'] = array_map( 'sanitize_title', $r['status'] ); 1002 $status_in = "'" . implode( "','", $r['status'] ) . "'"; 1003 $where_conditions['status'] = "g.status IN ({$status_in})"; 1004 } elseif ( empty( $r['show_hidden'] ) ) { 993 1005 $where_conditions['hidden'] = "g.status != 'hidden'"; 994 1006 } 995 1007 -
tests/phpunit/testcases/groups/class-bp-groups-group.php
diff --git tests/phpunit/testcases/groups/class-bp-groups-group.php tests/phpunit/testcases/groups/class-bp-groups-group.php index 493b1da..633f3d6 100644
class BP_Tests_BP_Groups_Group_TestCases extends BP_UnitTestCase { 2116 2116 $this->assertEqualSets( array( $g1, $g3 ), $found ); 2117 2117 } 2118 2118 2119 /** 2120 * @group get_by_status 2121 */ 2122 public function test_get_by_status() { 2123 $g1 = $this->factory->group->create(array( 2124 'status' => 'private' 2125 ) ); 2126 $g2 = $this->factory->group->create( array( 2127 'status' => 'public' 2128 ) ); 2129 $g3 = $this->factory->group->create( array( 2130 'status' => 'hidden' 2131 ) ); 2132 2133 $groups = BP_Groups_Group::get( array( 2134 'status' => array( 'private', 'hidden' ), 2135 ) ); 2136 2137 $found = wp_list_pluck( $groups['groups'], 'id' ); 2138 $this->assertEqualSets( array( $g1, $g3 ), $found ); 2139 } 2140 2141 /** 2142 * @group get_by_status 2143 */ 2144 public function test_get_by_status_accept_string() { 2145 $g1 = $this->factory->group->create(array( 2146 'status' => 'private' 2147 ) ); 2148 $g2 = $this->factory->group->create( array( 2149 'status' => 'public' 2150 ) ); 2151 $g3 = $this->factory->group->create( array( 2152 'status' => 'hidden' 2153 ) ); 2154 2155 $groups = BP_Groups_Group::get( array( 2156 'status' => 'public', 2157 ) ); 2158 2159 $found = wp_list_pluck( $groups['groups'], 'id' ); 2160 $this->assertEqualSets( array( $g2 ), $found ); 2161 } 2162 2163 /** 2164 * @group get_by_status 2165 */ 2166 public function test_get_by_status_accept_comma_separated_string() { 2167 $g1 = $this->factory->group->create(array( 2168 'status' => 'private' 2169 ) ); 2170 $g2 = $this->factory->group->create( array( 2171 'status' => 'public' 2172 ) ); 2173 $g3 = $this->factory->group->create( array( 2174 'status' => 'hidden' 2175 ) ); 2176 2177 $groups = BP_Groups_Group::get( array( 2178 'status' => 'private, hidden', 2179 ) ); 2180 2181 $found = wp_list_pluck( $groups['groups'], 'id' ); 2182 $this->assertEqualSets( array( $g1, $g3 ), $found ); 2183 } 2184 2185 /** 2186 * @group get_by_status 2187 */ 2188 public function test_get_by_status_accept_space_separated_string() { 2189 $g1 = $this->factory->group->create(array( 2190 'status' => 'private' 2191 ) ); 2192 $g2 = $this->factory->group->create( array( 2193 'status' => 'public' 2194 ) ); 2195 $g3 = $this->factory->group->create( array( 2196 'status' => 'hidden' 2197 ) ); 2198 2199 $groups = BP_Groups_Group::get( array( 2200 'status' => 'public private', 2201 ) ); 2202 2203 $found = wp_list_pluck( $groups['groups'], 'id' ); 2204 $this->assertEqualSets( array( $g1, $g2 ), $found ); 2205 } 2206 2207 2119 2208 } 2120 2209 2121 2210 /**