Changeset 11523
- Timestamp:
- 04/05/2017 12:00:40 AM (8 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-groups/bp-groups-functions.php
r11447 r11523 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. … … 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'], -
trunk/src/bp-groups/classes/class-bp-groups-group.php
r11447 r11523 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 { … … 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 … … 939 943 'page' => null, 940 944 'user_id' => 0, 945 'slug' => array(), 941 946 'search_terms' => false, 942 947 'search_columns' => array(), … … 973 978 if ( empty( $r['show_hidden'] ) ) { 974 979 $where_conditions['hidden'] = "g.status != 'hidden'"; 980 } 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})"; 975 989 } 976 990 -
trunk/tests/phpunit/testcases/groups/class-bp-groups-group.php
r11384 r11523 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
Note: See TracChangeset
for help on using the changeset viewer.