Ticket #7496: 7496.1.diff
File 7496.1.diff, 6.3 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..e744176 100644
class BP_Groups_Group { 860 860 * @since 1.6.0 861 861 * @since 2.6.0 Added `$group_type`, `$group_type__in`, and `$group_type__not_in` parameters. 862 862 * @since 2.7.0 Added `$update_admin_cache` and `$parent_id` parameters. 863 * @since 2.9.0 Added `$slug` parameter. 863 864 * 864 865 * @param array $args { 865 866 * Array of parameters. All items are optional. … … class BP_Groups_Group { 876 877 * Default: null (no limit). 877 878 * @type int $user_id Optional. If provided, results will be limited to groups 878 879 * of which the specified user is a member. Default: null. 879 * @type string $search_terms Optional. If provided, only groups whose names or descriptions 880 * @type array|string $slug Optional. Array or comma-separated list of group slugs to limit 881 * results to. 882 * Default: false. 883 * @type string $search_terms Optional. If provided, only groups whose names or descriptions 880 884 * match the search terms will be returned. Allows specifying the 881 885 * wildcard position using a '*' character before or after the 882 886 * string or both. Works in concert with $search_columns. … … class BP_Groups_Group { 938 942 'per_page' => null, 939 943 'page' => null, 940 944 'user_id' => 0, 945 'slug' => array(), 941 946 'search_terms' => false, 942 947 'search_columns' => array(), 943 948 'group_type' => '', … … class BP_Groups_Group { 974 979 $where_conditions['hidden'] = "g.status != 'hidden'"; 975 980 } 976 981 982 if ( ! empty( $r['slug'] ) ) { 983 if ( ! is_array( $r['slug'] ) ) { 984 $r['slug'] = preg_split( '/[\s,]+/', $r['slug'] ); 985 } 986 $r['slug'] = array_map( 'sanitize_title', $r['slug'] ); 987 $slug_in = "'" . implode( "','", $r['slug'] ) . "'"; 988 $where_conditions['slug'] = "g.slug IN ({$slug_in})"; 989 } 990 977 991 $search = ''; 978 992 if ( isset( $r['search_terms'] ) ) { 979 993 $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 /**