Ticket #7477: 7477.4.diff
File 7477.4.diff, 5.9 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 11439ba..c65af89 100644
function groups_get_groups( $args = '' ) { 708 708 'include' => false, // Only include these specific groups (group_ids). 709 709 'exclude' => false, // Do not include these specific groups (group_ids). 710 710 'parent_id' => null, // Get groups that are children of the specified group(s). 711 'slug' => array(), // Find a group or groups by slug. 711 712 'search_terms' => false, // Limit to groups that match these search terms. 712 713 'search_columns' => array(), // Select which columns to search. 713 714 'group_type' => '', // Array or comma-separated list of group types to limit results to. … … function groups_get_groups( $args = '' ) { 728 729 'user_id' => $r['user_id'], 729 730 'include' => $r['include'], 730 731 'exclude' => $r['exclude'], 732 'slug' => $r['slug'], 731 733 'parent_id' => $r['parent_id'], 732 734 'search_terms' => $r['search_terms'], 733 735 'search_columns' => $r['search_columns'], -
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 a851750..bd897d8 100644
class BP_Groups_Group { 876 876 * Default: null (no limit). 877 877 * @type int $user_id Optional. If provided, results will be limited to groups 878 878 * of which the specified user is a member. Default: null. 879 * @type string $search_terms Optional. If provided, only groups whose names or descriptions 879 * @type array|string $slug Optional. Array or comma-separated list of group slugs to limit 880 * results to. 881 * Default: false. 882 * @type string $search_terms Optional. If provided, only groups whose names or descriptions 880 883 * match the search terms will be returned. Allows specifying the 881 884 * wildcard position using a '*' character before or after the 882 885 * string or both. Works in concert with $search_columns. … … class BP_Groups_Group { 938 941 'per_page' => null, 939 942 'page' => null, 940 943 'user_id' => 0, 944 'slug' => array(), 941 945 'search_terms' => false, 942 946 'search_columns' => array(), 943 947 'group_type' => '', … … class BP_Groups_Group { 974 978 $where_conditions['hidden'] = "g.status != 'hidden'"; 975 979 } 976 980 981 if ( ! empty( $r['slug'] ) ) { 982 if ( ! is_array( $r['slug'] ) ) { 983 $r['slug'] = preg_split( '/[\s,]+/', $r['slug'] ); 984 } 985 $r['slug'] = array_map( 'sanitize_title', $r['slug'] ); 986 $slug_in = "'" . implode( "','", $r['slug'] ) . "'"; 987 $where_conditions['slug'] = "g.slug IN ({$slug_in})"; 988 } 989 977 990 $search = ''; 978 991 if ( isset( $r['search_terms'] ) ) { 979 992 $search = trim( $r['search_terms'] ); -
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 6f6d625..0fcc1d5 100644
class BP_Tests_BP_Groups_Group_TestCases extends BP_UnitTestCase { 2011 2011 $found = wp_list_pluck( $groups['groups'], 'id' ); 2012 2012 $this->assertEqualSets( array( $g1, $g4 ), $found ); 2013 2013 } 2014 2015 /** 2016 * @group get_by_slug 2017 */ 2018 public function test_get_by_slug() { 2019 $g1 = $this->factory->group->create(array( 2020 'slug' => 'apr' 2021 ) ); 2022 $g2 = $this->factory->group->create( array( 2023 'slug' => 'jan' 2024 ) ); 2025 $g3 = $this->factory->group->create( array( 2026 'slug' => 'mar' 2027 ) ); 2028 2029 $groups = BP_Groups_Group::get( array( 2030 'slug' => array( 'apr', 'mar' ), 2031 ) ); 2032 2033 $found = wp_list_pluck( $groups['groups'], 'id' ); 2034 $this->assertEqualSets( array( $g1, $g3 ), $found ); 2035 } 2036 2037 /** 2038 * @group get_by_slug 2039 */ 2040 public function test_get_by_slug_accept_string() { 2041 $g1 = $this->factory->group->create(array( 2042 'slug' => 'apr' 2043 ) ); 2044 $g2 = $this->factory->group->create( array( 2045 'slug' => 'jan' 2046 ) ); 2047 $g3 = $this->factory->group->create( array( 2048 'slug' => 'mar' 2049 ) ); 2050 2051 $groups = BP_Groups_Group::get( array( 2052 'slug' => 'jan', 2053 ) ); 2054 2055 $found = wp_list_pluck( $groups['groups'], 'id' ); 2056 $this->assertEqualSets( array( $g2 ), $found ); 2057 } 2058 2059 /** 2060 * @group get_by_slug 2061 */ 2062 public function test_get_by_slug_accept_comma_separated_string() { 2063 $g1 = $this->factory->group->create(array( 2064 'slug' => 'apr' 2065 ) ); 2066 $g2 = $this->factory->group->create( array( 2067 'slug' => 'jan' 2068 ) ); 2069 $g3 = $this->factory->group->create( array( 2070 'slug' => 'mar' 2071 ) ); 2072 2073 $groups = BP_Groups_Group::get( array( 2074 'slug' => 'apr, mar', 2075 ) ); 2076 2077 $found = wp_list_pluck( $groups['groups'], 'id' ); 2078 $this->assertEqualSets( array( $g1, $g3 ), $found ); 2079 } 2080 2081 /** 2082 * @group get_by_slug 2083 */ 2084 public function test_get_by_slug_accept_space_separated_string() { 2085 $g1 = $this->factory->group->create(array( 2086 'slug' => 'apr' 2087 ) ); 2088 $g2 = $this->factory->group->create( array( 2089 'slug' => 'jan' 2090 ) ); 2091 $g3 = $this->factory->group->create( array( 2092 'slug' => 'mar' 2093 ) ); 2094 2095 $groups = BP_Groups_Group::get( array( 2096 'slug' => 'apr mar', 2097 ) ); 2098 2099 $found = wp_list_pluck( $groups['groups'], 'id' ); 2100 $this->assertEqualSets( array( $g1, $g3 ), $found ); 2101 } 2102 2014 2103 } 2015 2104 2016 2105 /**