Changeset 11532
- Timestamp:
- 04/20/2017 12:19:36 AM (8 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-groups/bp-groups-functions.php
r11530 r11532 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. … … 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'], -
trunk/src/bp-groups/classes/class-bp-groups-group.php
r11530 r11532 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 { … … 970 973 'exclude' => false, 971 974 'show_hidden' => false, 975 'status' => array() 972 976 ); 973 977 … … 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 } -
trunk/tests/phpunit/testcases/groups/class-bp-groups-group.php
r11526 r11532 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 2119 2185 } 2120 2186
Note: See TracChangeset
for help on using the changeset viewer.