Ticket #3278: master...suggestions.patch
File master...suggestions.patch, 108.2 KB (added by , 10 years ago) |
---|
-
src/bp-core/bp-core-functions.php
From 3c4b6b991f7a882a1567122698678a115a47376d Mon Sep 17 00:00:00 2001 From: Paul Gibbs <paul@byotos.com> Date: Sat, 21 Jun 2014 13:34:35 +0100 Subject: [PATCH 01/35] Add current Suggestions API work. --- src/bp-core/bp-core-functions.php | 70 ++++ src/bp-members/bp-members-filters.php | 13 + src/bp-members/bp-members-functions.php | 62 ++++ .../phpunit/testcases/apis/suggestions-nonauth.php | 107 ++++++ tests/phpunit/testcases/apis/suggestions.php | 386 +++++++++++++++++++++ 5 files changed, 638 insertions(+) create mode 100644 tests/phpunit/testcases/apis/suggestions-nonauth.php create mode 100644 tests/phpunit/testcases/apis/suggestions.php diff --git a/src/bp-core/bp-core-functions.php b/src/bp-core/bp-core-functions.php index 9e46100..75cb9f5 100644
a b function bp_nav_menu_get_item_url( $slug ) { 1921 1921 1922 1922 return $nav_item_url; 1923 1923 } 1924 1925 /** Suggestions***************************************************************/ 1926 1927 /** 1928 * BuddyPress Suggestions API for types of at-mentions. 1929 * 1930 * This is used to power BuddyPress' at-mentions suggestions, but it is flexible enough to be used 1931 * for similar kinds of requirements. 1932 * 1933 * If a Component or a third-party plugin wants to provide suggestions for a custom type of object, 1934 * use the bp_suggestions_get_types filter and return an associative array with its key as the new 1935 * "type", and its value as a function callback. 1936 * 1937 * The callback must validate any custom requirements in $args and fetch results that match $term 1938 * in some relevant way. If validation fails, a WP_Error object must be returned. If no matches are 1939 * found, an empty array must be returned. Matches must be returned as objects in an array. 1940 * 1941 * The object format for each match must be: { 'ID': string, 'image': string, 'name': string } 1942 * For example: { 'ID': 'admin', 'image': 'http://example.com/logo.png', 'name': 'Name Surname' } 1943 * 1944 * @param array $args { 1945 * @type int limit Maximum number of results to display. Default: 16. 1946 * @type int|string $object_id Specifies a particular object that may be used by a suggestion 1947 * service. Accepts either an integer or a string. For example, this could be used by a 1948 * Groups suggestion type that searches for members who are members of a specific group. 1949 * @type string $type The name of the suggestion service to use for the request. Mandatory. 1950 * @type string $term The suggestion service will try to find results that contain this string. 1951 * Mandatory. 1952 * } 1953 * @return array|WP_Error Array of results. If there were any problems, returns a WP_Error object. 1954 * @since BuddyPress (2.1.0) 1955 */ 1956 function bp_core_get_suggestions( $args ) { 1957 $defaults = array( 1958 'limit' => 16, 1959 'object_id' => 0, 1960 'type' => '', 1961 'term' => '', 1962 ); 1963 $args = wp_parse_args( $args, $defaults ); 1964 1965 if ( ctype_digit( $args['object_id'] ) ) { 1966 $args['object_id'] = absint( $args['object_id'] ); 1967 } else { 1968 $args['object_id'] = sanitize_text_field( $args['object_id'] ); 1969 } 1970 1971 $args['limit'] = absint( $args['limit'] ); 1972 $args['term'] = trim( sanitize_text_field( $args['term'] ) ); 1973 1974 $args = apply_filters( 'bp_suggestions_args', $args ); 1975 $callbacks = apply_filters( 'bp_suggestions_get_types', array() ); 1976 1977 if ( ! in_array( $args['type'], array_keys( $callbacks ) ) ) { 1978 $args['type'] = null; 1979 } 1980 1981 if ( ! $args['limit'] || is_null( $args['type'] ) || ! is_callable( $callbacks[ $args['type'] ] ) || ! $args['term'] ) { 1982 // Invalid or missing mandatory parameter. 1983 return new WP_Error( 'missing_parameter' ); 1984 } 1985 1986 if ( is_user_logged_in() && ! bp_is_user_active( get_current_user_id() ) ) { 1987 // Blocked user account (e.g. deleted or spammer). 1988 return new WP_Error( 'invalid_user' ); 1989 } 1990 1991 $results = call_user_func( $callbacks[ $args['type'] ], $args ); 1992 return apply_filters( 'bp_core_get_suggestions', $results, $args ); 1993 } 1994 No newline at end of file -
src/bp-members/bp-members-filters.php
diff --git a/src/bp-members/bp-members-filters.php b/src/bp-members/bp-members-filters.php index fed76b6..3c0c610 100644
a b function bp_members_edit_profile_url( $url, $user_id, $scheme = 'admin' ) { 77 77 return apply_filters( 'bp_members_edit_profile_url', $profile_link, $url, $user_id, $scheme ); 78 78 } 79 79 add_filter( 'edit_profile_url', 'bp_members_edit_profile_url', 10, 3 ); 80 81 /** 82 * Add support for @username mentions to BuddyPress. 83 * 84 * @param array $types Array of registered extensions to the Suggestion API. 85 * @return array 86 * @see bp_core_get_suggestions() 87 */ 88 function bp_members_register_suggestion_types( $types ) { 89 $types['members'] = 'bp_members_get_suggestions'; 90 return $types; 91 } 92 add_filter( 'bp_suggestions_get_types', 'bp_members_register_suggestion_types' ); -
src/bp-members/bp-members-functions.php
diff --git a/src/bp-members/bp-members-functions.php b/src/bp-members/bp-members-functions.php index 6e6a529..6e28ec3 100644
a b function bp_live_spammer_login_error() { 2085 2085 add_action( 'login_head', 'wp_shake_js', 12 ); 2086 2086 } 2087 2087 add_action( 'login_form_bp-spam', 'bp_live_spammer_login_error' ); 2088 2089 /** 2090 * Implement support for @username mentions. 2091 * 2092 * The $args parameter may include other parameters not documented here; if so, they are not used 2093 * by this particular Suggestions API extension. 2094 * 2095 * @param array $args { 2096 * @type int limit Maximum number of results to display. Default: 16. 2097 * @type string $term The suggestion service will try to find results that contain this string. 2098 * Mandatory. 2099 * } 2100 * @return array|WP_Error See {@see bp_core_get_suggestions()}. If any problems, return a WP_Error. 2101 * @see bp_core_get_suggestions() 2102 * @since BuddyPress (2.1.0) 2103 */ 2104 function bp_members_get_suggestions( $args ) { 2105 $defaults = array( 2106 'limit' => 16, // Sanitised upstream 2107 'only_friends' => false, 2108 'term' => '', // Sanitised upstream 2109 ); 2110 $args = apply_filters( 'bp_members_get_suggestions_args', wp_parse_args( $args, $defaults ) ); 2111 2112 if ( $args['only_friends'] && ! bp_is_active( 'friends' ) ) { 2113 // Friends component is missing. 2114 return new WP_Error( 'missing_requirement' ); 2115 } 2116 2117 $user_query = array( 2118 'count_total' => '', // Prevents total count 2119 'populate_extras' => false, 2120 'type' => 'alphabetical', 2121 2122 'page' => 1, 2123 'per_page' => $args['limit'], 2124 'search_terms' => $args['term'], 2125 ); 2126 2127 if ( $args['only_friends'] ) { 2128 $user_query['user_id'] = get_current_user_id(); 2129 } 2130 2131 2132 $user_query = new BP_User_Query( $user_query ); 2133 $results = array(); 2134 2135 foreach ( $user_query->results as $user ) { 2136 $result = new stdClass(); 2137 $result->ID = $user->user_nicename; 2138 $result->image = get_avatar( $user ); 2139 $result->name = $user->display_name; 2140 2141 if ( bp_disable_profile_sync() ) { 2142 $result->name = BP_XProfile_Field::get_fullname( $user->ID ); 2143 } 2144 2145 $results[] = $result; 2146 } 2147 2148 return apply_filters( 'bp_members_get_suggestions', $results, $args ); 2149 } 2150 No newline at end of file -
new file tests/phpunit/testcases/apis/suggestions-nonauth.php
diff --git a/tests/phpunit/testcases/apis/suggestions-nonauth.php b/tests/phpunit/testcases/apis/suggestions-nonauth.php new file mode 100644 index 0000000..0e1be23
- + 1 <?php 2 /** 3 * Suggestions API tests specifically for non-authenticated (anonymous) users. 4 * 5 * @group api 6 * @group suggestions 7 */ 8 class BP_Tests_Suggestions_Non_Authenticated extends BP_UnitTestCase { 9 protected $group_ids = array(); 10 protected $group_slugs = array(); 11 protected $user_ids = array(); 12 13 public function setUp() { 14 parent::setUp(); 15 16 $users = array( 17 // user_login, display_name 18 array( 'aardvark', 'Bob Smith' ), 19 array( 'alpaca red', 'William Quinn' ), 20 array( 'cat', 'Lauren Curtis' ), 21 array( 'caterpillar', 'Eldon Burrows' ), 22 array( 'dog green', 'Reece Thornton' ), 23 array( 'pig', 'Joshua Barton' ), 24 array( 'rabbit blue', 'Amber Hooper' ), 25 array( 'smith', 'Robert Bar' ), 26 array( 'snake', 'Eleanor Moore' ), 27 array( 'zoom', 'Lisa Smithy' ), 28 ); 29 30 // Create some dummy users. 31 foreach( $users as $user ) { 32 $this->user_ids[ $user[0] ] = $this->factory->user->create( array( 33 'display_name' => $user[1], 34 'user_login' => $user[0], 35 ) ); 36 } 37 38 $this->group_slugs['hidden'] = 'the-maw'; 39 $this->group_slugs['public'] = 'the-great-journey'; 40 $this->group_slugs['private'] = 'tsavo-highway'; 41 42 // Create dummy groups. 43 $this->group_ids['hidden'] = $this->factory->group->create( array( 'slug' => $this->group_slugs['hidden'], 'status' => 'hidden' ) ); 44 $this->group_ids['public'] = $this->factory->group->create( array( 'slug' => $this->group_slugs['public'], 'status' => 'public' ) ); 45 $this->group_ids['private'] = $this->factory->group->create( array( 'slug' => $this->group_slugs['private'], 'status' => 'private' ) ); 46 47 // Add dummy users to dummy hidden groups. 48 groups_join_group( $this->group_ids['hidden'], $this->user_ids['pig'] ); 49 groups_join_group( $this->group_ids['hidden'], $this->user_ids['alpaca red'] ); 50 51 // Add dummy users to dummy public groups. 52 groups_join_group( $this->group_ids['public'], $this->user_ids['aardvark'] ); 53 groups_join_group( $this->group_ids['public'], $this->user_ids['smith'] ); 54 55 // Add dummy users to dummy private groups. 56 groups_join_group( $this->group_ids['private'], $this->user_ids['cat'] ); 57 groups_join_group( $this->group_ids['private'], $this->user_ids['caterpillar'] ); 58 } 59 60 61 /** 62 * Tests below this point are expected to fail. 63 */ 64 65 public function test_suggestions_with_type_members_and_only_friends() { 66 // only_friends requires authenticated requests 67 $suggestions = bp_core_get_suggestions( array( 68 'only_friends' => true, 69 'type' => 'members', 70 'term' => 'smith', 71 ) ); 72 73 $this->assertTrue( is_wp_error( $suggestions ) ); 74 } 75 76 public function test_suggestions_with_type_group_and_only_friends() { 77 // only_friends requires authenticated requests 78 $suggestions = bp_core_get_suggestions( array( 79 'object_id' => $this->group_ids['public'], 80 'only_friends' => true, 81 'type' => 'group-members', 82 'term' => 'smith', 83 ) ); 84 85 $this->assertTrue( is_wp_error( $suggestions ) ); 86 } 87 88 public function test_suggestions_with_type_group_hidden() { 89 $suggestions = bp_core_get_suggestions( array( 90 'object_id' => $this->group_ids['hidden'], 91 'type' => 'group-members', 92 'term' => 'pig', 93 ) ); 94 95 $this->assertTrue( is_wp_error( $suggestions ) ); 96 } 97 98 public function test_suggestions_with_type_group_private() { 99 $suggestions = bp_core_get_suggestions( array( 100 'object_id' => $this->group_ids['private'], 101 'type' => 'group-members', 102 'term' => 'cat', 103 ) ); 104 105 $this->assertTrue( is_wp_error( $suggestions ) ); 106 } 107 } 108 No newline at end of file -
new file tests/phpunit/testcases/apis/suggestions.php
diff --git a/tests/phpunit/testcases/apis/suggestions.php b/tests/phpunit/testcases/apis/suggestions.php new file mode 100644 index 0000000..7fc85d7
- + 1 <?php 2 /** 3 * Suggestions API tests for authenticated (logged in) users. 4 * 5 * @group api 6 * @group suggestions 7 */ 8 class BP_Tests_Suggestions_Authenticated extends BP_UnitTestCase { 9 protected $current_user = null; 10 protected $group_ids = array(); 11 protected $group_slugs = array(); 12 protected $old_user_id = 0; 13 protected $user_ids = array(); 14 15 public function setUp() { 16 parent::setUp(); 17 18 $this->old_user_id = get_current_user_id(); 19 $this->current_user = $this->factory->user->create( array( 20 'display_name' => 'Katie Parker', 21 'user_login' => 'admin', 22 ) ); 23 24 $this->set_current_user( $this->current_user ); 25 26 $users = array( 27 // user_login, display_name 28 array( 'aardvark', 'Bob Smith' ), 29 array( 'alpaca red', 'William Quinn' ), 30 array( 'cat', 'Lauren Curtis' ), 31 array( 'caterpillar', 'Eldon Burrows' ), 32 array( 'dog green', 'Reece Thornton' ), 33 array( 'pig', 'Joshua Barton' ), 34 array( 'rabbit blue', 'Amber Hooper' ), 35 array( 'smith', 'Robert Bar' ), 36 array( 'snake', 'Eleanor Moore' ), 37 array( 'zoom', 'Lisa Smithy' ), 38 ); 39 40 // Create some dummy users. 41 foreach( $users as $user ) { 42 $this->user_ids[ $user[0] ] = $this->factory->user->create( array( 43 'display_name' => $user[1], 44 'user_login' => $user[0], 45 ) ); 46 } 47 48 // Create some dummy friendships. 49 friends_add_friend( $this->current_user, $this->user_ids['aardvark'], true ); 50 friends_add_friend( $this->current_user, $this->user_ids['cat'], true ); 51 friends_add_friend( $this->current_user, $this->user_ids['caterpillar'], true ); 52 friends_add_friend( $this->current_user, $this->user_ids['pig'], true ); 53 54 $this->group_slugs['hidden'] = 'the-maw'; 55 $this->group_slugs['public'] = 'the-great-journey'; 56 $this->group_slugs['private'] = 'tsavo-highway'; 57 58 // Create dummy groups. 59 $this->group_ids['hidden'] = $this->factory->group->create( array( 'slug' => $this->group_slugs['hidden'], 'status' => 'hidden' ) ); 60 $this->group_ids['public'] = $this->factory->group->create( array( 'slug' => $this->group_slugs['public'], 'status' => 'public' ) ); 61 $this->group_ids['private'] = $this->factory->group->create( array( 'slug' => $this->group_slugs['private'], 'status' => 'private' ) ); 62 63 // Add dummy users to dummy hidden groups. 64 groups_join_group( $this->group_ids['hidden'], $this->user_ids['pig'] ); 65 groups_join_group( $this->group_ids['hidden'], $this->user_ids['alpaca red'] ); 66 67 // Add dummy users to dummy public groups. 68 groups_join_group( $this->group_ids['public'], $this->current_user ); 69 groups_join_group( $this->group_ids['public'], $this->user_ids['aardvark'] ); 70 groups_join_group( $this->group_ids['public'], $this->user_ids['smith'] ); 71 72 // Add dummy users to dummy private groups. 73 groups_join_group( $this->group_ids['private'], $this->user_ids['cat'] ); 74 groups_join_group( $this->group_ids['private'], $this->user_ids['caterpillar'] ); 75 } 76 77 public function tearDown() { 78 parent::tearDown(); 79 $this->set_current_user( $this->old_user_id ); 80 } 81 82 83 public function test_suggestions_with_type_members() { 84 $suggestions = bp_core_get_suggestions( array( 85 'type' => 'members', 86 'term' => 'smith', 87 ) ); 88 89 $this->assertEquals( 3, count( $suggestions ) ); // aardvark, smith, zoom. 90 } 91 92 public function test_suggestions_with_type_members_and_limit() { 93 $suggestions = bp_core_get_suggestions( array( 94 'limit' => 2, 95 'type' => 'members', 96 'term' => 'smith', 97 ) ); 98 99 $this->assertEquals( 2, count( $suggestions ) ); // two of: aardvark, smith, zoom. 100 } 101 102 public function test_suggestions_with_type_members_and_only_friends() { 103 $suggestions = bp_core_get_suggestions( array( 104 'only_friends' => true, 105 'type' => 'members', 106 'term' => 'smith', 107 ) ); 108 $this->assertEquals( 1, count( $suggestions ) ); // aardvark. 109 110 $suggestions = bp_core_get_suggestions( array( 111 'only_friends' => true, 112 'type' => 'members', 113 'term' => 'cat', 114 ) ); 115 $this->assertEquals( 2, count( $suggestions ) ); // cat, caterpillar. 116 } 117 118 public function test_suggestions_with_type_members_and_term_as_displayname() { 119 $suggestions = bp_core_get_suggestions( array( 120 'type' => 'members', 121 'term' => 'aardvark', 122 ) ); 123 124 $this->assertEquals( 1, count( $suggestions ) ); // aardvark. 125 } 126 127 public function test_suggestions_with_type_members_and_term_as_usernicename() { 128 $suggestions = bp_core_get_suggestions( array( 129 'type' => 'members', 130 'term' => 'eleanor', 131 ) ); 132 133 $this->assertEquals( 1, count( $suggestions ) ); // snake. 134 } 135 136 public function test_suggestions_with_term_as_current_user() { 137 $suggestions = bp_core_get_suggestions( array( 138 'type' => 'members', 139 'term' => 'katie', 140 ) ); 141 $this->assertEquals( 1, count( $suggestions ) ); 142 $this->assertSame( 'admin', $suggestions[0]->id ); 143 } 144 145 146 public function test_suggestions_with_type_groupmembers_public() { 147 $suggestions = bp_core_get_suggestions( array( 148 'object_id' => $this->group_ids['public'], 149 'type' => 'group-members', 150 'term' => 'smith', 151 ) ); 152 153 $this->assertEquals( 2, count( $suggestions ) ); // aardvark, smith. 154 } 155 156 public function test_suggestions_with_type_groupmembers_public_and_limit() { 157 $suggestions = bp_core_get_suggestions( array( 158 'limit' => 1, 159 'object_id' => $this->group_ids['public'], 160 'type' => 'group-members', 161 'term' => 'smith', 162 ) ); 163 164 $this->assertEquals( 1, count( $suggestions ) ); // one of: aardvark, smith. 165 } 166 167 public function test_suggestions_with_type_groupmembers_public_and_only_friends() { 168 $suggestions = bp_core_get_suggestions( array( 169 'object_id' => $this->group_ids['public'], 170 'only_friends' => true, 171 'type' => 'group-members', 172 'term' => 'smith', 173 ) ); 174 175 $this->assertEquals( 1, count( $suggestions ) ); // aardvark. 176 } 177 178 public function test_suggestions_with_type_groupmembers_public_and_term_as_displayname() { 179 $suggestions = bp_core_get_suggestions( array( 180 'object_id' => $this->group_ids['public'], 181 'type' => 'group-members', 182 'term' => 'aardvark', 183 ) ); 184 185 $this->assertEquals( 1, count( $suggestions ) ); // aardvark. 186 } 187 188 public function test_suggestions_with_type_groupmembers_public_and_term_as_usernicename() { 189 $suggestions = bp_core_get_suggestions( array( 190 'object_id' => $this->group_ids['public'], 191 'type' => 'group-members', 192 'term' => 'robert', 193 ) ); 194 195 $this->assertEquals( 1, count( $suggestions ) ); // smith. 196 } 197 198 public function test_suggestions_with_type_groupmembers_public_as_id() { 199 $suggestions = bp_core_get_suggestions( array( 200 'object_id' => $this->group_ids['public'], 201 'type' => 'group-members', 202 'term' => 'smith', 203 ) ); 204 205 $this->assertEquals( 2, count( $suggestions ) ); // aardvark, smith. 206 } 207 208 public function test_suggestions_with_type_groupmembers_public_as_slug() { 209 $suggestions = bp_core_get_suggestions( array( 210 'object_id' => $this->group_slugs['public'], 211 'type' => 'group-members', 212 'term' => 'smith', 213 ) ); 214 215 $this->assertEquals( 2, count( $suggestions ) ); // aardvark, smith. 216 } 217 218 public function test_suggestions_with_type_groupmembers_hidden() { 219 // current_user isn't a member of the hidden group 220 $suggestions = bp_core_get_suggestions( array( 221 'object_id' => $this->group_ids['hidden'], 222 'type' => 'group-members', 223 'term' => 'pig', 224 ) ); 225 $this->assertTrue( is_wp_error( $suggestions ) ); 226 227 // "alpaca red" is in the hidden group 228 $this->set_current_user( $this->users['alpaca red'] ); 229 $suggestions = bp_core_get_suggestions( array( 230 'object_id' => $this->group_ids['hidden'], 231 'type' => 'group-members', 232 'term' => 'pig', 233 ) ); 234 $this->assertEquals( 1, count( $suggestions ) ); // pig 235 } 236 237 public function test_suggestions_with_type_groupmembers_private() { 238 // current_user isn't a member of the private group 239 $suggestions = bp_core_get_suggestions( array( 240 'object_id' => $this->group_ids['private'], 241 'type' => 'group-members', 242 'term' => 'cat', 243 ) ); 244 $this->assertTrue( is_wp_error( $suggestions ) ); 245 246 // "caterpillar" is in the private group 247 $this->set_current_user( $this->users['caterpillar'] ); 248 $suggestions = bp_core_get_suggestions( array( 249 'object_id' => $this->group_ids['private'], 250 'type' => 'group-members', 251 'term' => 'cat', 252 ) ); 253 $this->assertEquals( 2, count( $suggestions ) ); // cat, caterpillar 254 } 255 256 257 /** 258 * These next tests check the format of the response from the Suggestions API. 259 */ 260 261 public function test_suggestions_response_no_matches() { 262 $suggestions = bp_core_get_suggestions( array( 263 'term' => 'abcdefghijklmnopqrstuvwxyz', 264 ) ); 265 266 $this->assertInternalType( 'array', $suggestions ); 267 $this->assertEmpty( $suggestions ); 268 } 269 270 public function test_suggestions_response_single_match() { 271 $suggestion = bp_core_get_suggestions( array( 272 'term' => 'zoom', 273 ) ); 274 275 $this->assertInternalType( 'array', $suggestion ); 276 $this->assertNotEmpty( $suggestion ); 277 278 $suggestion = array_shift( $suggestion ); 279 280 $this->assertInternalType( 'object', $suggestion ); 281 $this->assertAttributeNotEmpty( 'image', $suggestion ); 282 $this->assertAttributeNotEmpty( 'id', $suggestion ); 283 $this->assertAttributeNotEmpty( 'name', $suggestion ); 284 } 285 286 public function test_suggestions_response_multiple_matches() { 287 $suggestions = bp_core_get_suggestions( array( 288 'term' => 'cat', 289 ) ); 290 291 $this->assertInternalType( 'array', $suggestions ); 292 $this->assertNotEmpty( $suggestions ); 293 294 foreach ( $suggestions as $suggestion ) { 295 $this->assertInternalType( 'object', $suggestion ); 296 $this->assertAttributeNotEmpty( 'image', $suggestion ); 297 $this->assertAttributeNotEmpty( 'id', $suggestion ); 298 $this->assertAttributeNotEmpty( 'name', $suggestion ); 299 } 300 } 301 302 public function test_suggestions_term_is_case_insensitive() { 303 $lowercase = bp_core_get_suggestions( array( 304 'term' => 'lisa', 305 ) ); 306 $this->assertEquals( 1, count( $lowercase ) ); 307 308 $uppercase = bp_core_get_suggestions( array( 309 'term' => 'LISA', 310 ) ); 311 $this->assertEquals( 1, count( $uppercase ) ); 312 313 $this->assertSame( $lowercase[0]->id, $uppercase[0]->id ); 314 $this->assertSame( 'zoom', $lowercase[0]->id ); 315 } 316 317 public function test_suggestions_response_property_types() { 318 $suggestion = bp_core_get_suggestions( array( 319 'term' => 'zoom', 320 ) ); 321 322 $this->assertInternalType( 'array', $suggestion ); 323 $this->assertNotEmpty( $suggestion ); 324 325 $suggestion = array_shift( $suggestion ); 326 327 $this->assertInternalType( 'object', $suggestion ); 328 $this->assertAttributeInternalType( 'string', 'image', $suggestion ); 329 $this->assertAttributeInternalType( 'string', 'id', $suggestion ); 330 $this->assertAttributeInternalType( 'string', 'name', $suggestion ); 331 } 332 333 334 /** 335 * Tests below this point are expected to fail. 336 */ 337 338 public function test_suggestions_with_bad_type() { 339 $suggestions = bp_core_get_suggestions( array( 340 'type' => 'fake_type', 341 ) ); 342 343 $this->assertTrue( is_wp_error( $suggestions ) ); 344 } 345 346 public function test_suggestions_with_type_groupmembers_and_bad_object_id() { 347 // object_id must be a positive integer. 348 $suggestions = bp_core_get_suggestions( array( 349 'object_id' => -12, 350 'type' => 'group-members', 351 ) ); 352 $this->assertTrue( is_wp_error( $suggestions ) ); 353 354 // object_id can also be a group slug. 355 $suggestions = bp_core_get_suggestions( array( 356 'object_id' => 'fake-group-slug', 357 'type' => 'group-members', 358 ) ); 359 $this->assertTrue( is_wp_error( $suggestions ) ); 360 361 // object_id must be set when scope=group 362 $suggestions = bp_core_get_suggestions( array( 363 'type' => 'group-members', 364 ) ); 365 $this->assertTrue( is_wp_error( $suggestions ) ); 366 } 367 368 public function test_suggestions_with_type_members_and_object_id() { 369 // object_id cannot be set when scope=global 370 $suggestions = bp_core_get_suggestions( array( 371 'object_id' => 12, 372 'type' => 'members', 373 ) ); 374 375 $this->assertTrue( is_wp_error( $suggestions ) ); 376 } 377 378 public function test_suggestions_with_bad_term() { 379 // a non-empty term is mandatory 380 $suggestions = bp_core_get_suggestions( array( 381 'term' => '', 382 ) ); 383 384 $this->assertTrue( is_wp_error( $suggestions ) ); 385 } 386 } 387 No newline at end of file -
src/bp-members/bp-members-functions.php
-- 1.9.3 From adb7f2705e15a288c79e51c42b28a035a83ec94b Mon Sep 17 00:00:00 2001 From: Paul Gibbs <paul@byotos.com> Date: Sat, 21 Jun 2014 14:00:10 +0100 Subject: [PATCH 02/35] Suggestions: sanitise only_friends param --- src/bp-members/bp-members-functions.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/bp-members/bp-members-functions.php b/src/bp-members/bp-members-functions.php index 6e28ec3..9f8a498 100644
a b function bp_members_get_suggestions( $args ) { 2107 2107 'only_friends' => false, 2108 2108 'term' => '', // Sanitised upstream 2109 2109 ); 2110 $args = apply_filters( 'bp_members_get_suggestions_args', wp_parse_args( $args, $defaults ) );2111 2110 2112 2111 if ( $args['only_friends'] && ! bp_is_active( 'friends' ) ) { 2113 2112 // Friends component is missing. -
src/bp-members/bp-members-functions.php
-- 1.9.3 From 30569b070333aee5d2e8c870a5e033c758d3bc64 Mon Sep 17 00:00:00 2001 From: Paul Gibbs <paul@byotos.com> Date: Sat, 21 Jun 2014 14:00:38 +0100 Subject: [PATCH 03/35] Suggestions: sanitise only_friends param MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (Let’s try to commit the whole thing this time) --- src/bp-members/bp-members-functions.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/bp-members/bp-members-functions.php b/src/bp-members/bp-members-functions.php index 9f8a498..bccedc1 100644
a b function bp_members_get_suggestions( $args ) { 2107 2107 'only_friends' => false, 2108 2108 'term' => '', // Sanitised upstream 2109 2109 ); 2110 $args = apply_filters( 'bp_members_get_suggestions_args', wp_parse_args( $args, $defaults ) ); 2111 $args['only_friends'] = (bool) $args['only_friends']; 2112 2110 2113 2111 2114 if ( $args['only_friends'] && ! bp_is_active( 'friends' ) ) { 2112 2115 // Friends component is missing. -
src/bp-members/bp-members-filters.php
-- 1.9.3 From 760fa37bef55193ca38b387741c66f73df364c52 Mon Sep 17 00:00:00 2001 From: Paul Gibbs <paul@byotos.com> Date: Sat, 21 Jun 2014 14:51:50 +0100 Subject: [PATCH 04/35] phpDoc tweaks --- src/bp-members/bp-members-filters.php | 2 +- src/bp-members/bp-members-functions.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/bp-members/bp-members-filters.php b/src/bp-members/bp-members-filters.php index 3c0c610..8860609 100644
a b function bp_members_register_suggestion_types( $types ) { 89 89 $types['members'] = 'bp_members_get_suggestions'; 90 90 return $types; 91 91 } 92 add_filter( 'bp_suggestions_get_types', 'bp_members_register_suggestion_types' ); 92 add_filter( 'bp_suggestions_get_types', 'bp_members_register_suggestion_types' ); 93 No newline at end of file -
src/bp-members/bp-members-functions.php
diff --git a/src/bp-members/bp-members-functions.php b/src/bp-members/bp-members-functions.php index bccedc1..63b6465 100644
a b function bp_live_spammer_login_error() { 2093 2093 * by this particular Suggestions API extension. 2094 2094 * 2095 2095 * @param array $args { 2096 * @type int limit Maximum number of results to display. Default: 16. 2096 * @type int $limit Maximum number of results to display. Default: 16. 2097 * @type bool $only_friends If true, only return matches who are friends with the current user. Default: false. 2097 2098 * @type string $term The suggestion service will try to find results that contain this string. 2098 2099 * Mandatory. 2099 2100 * } -
src/bp-friends/bp-friends-filters.php
-- 1.9.3 From a9e1785ca59cde277377ce6751a91d27841e5002 Mon Sep 17 00:00:00 2001 From: Paul Gibbs <paul@byotos.com> Date: Sat, 21 Jun 2014 15:45:21 +0100 Subject: [PATCH 05/35] Suggestions: move user friends logic into Friends component --- src/bp-friends/bp-friends-filters.php | 2 ++ src/bp-friends/bp-friends-functions.php | 20 ++++++++++++++++++++ src/bp-members/bp-members-functions.php | 11 +++-------- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/bp-friends/bp-friends-filters.php b/src/bp-friends/bp-friends-filters.php index 6ada0e7..69b39dd 100644
a b function bp_friends_filter_user_query_populate_extras( BP_User_Query $user_query 50 50 } 51 51 } 52 52 add_filter( 'bp_user_query_populate_extras', 'bp_friends_filter_user_query_populate_extras', 4, 2 ); 53 54 add_filter( 'bp_suggestions_members_query_args', 'bp_friends_suggestions_filter_query_args', 10, 2 ); 55 No newline at end of file -
src/bp-friends/bp-friends-functions.php
diff --git a/src/bp-friends/bp-friends-functions.php b/src/bp-friends/bp-friends-functions.php index 5f797c7..dce5320 100644
a b function friends_remove_data( $user_id ) { 566 566 add_action( 'wpmu_delete_user', 'friends_remove_data' ); 567 567 add_action( 'delete_user', 'friends_remove_data' ); 568 568 add_action( 'bp_make_spam_user', 'friends_remove_data' ); 569 570 /** 571 * Extend the members' component's @username suggestions by adding support for friendships. 572 * 573 * Assumes there is currently a logged-in user. 574 * 575 * @param array $query_args The parameters that will be passed to {@see BP_User_Query}. 576 * @param array $suggestion_args Arguments originally sent to the {@see bp_core_get_suggestions()}. 577 * @return array The parameters that will be passed to {@see BP_User_Query}. 578 * @see bp_members_get_suggestions() 579 * @since BuddyPress (2.1.0) 580 */ 581 function bp_friends_suggestions_filter_query_args( $query_args, $suggestion_args ) { 582 if ( $suggestion_args['only_friends'] ) { 583 // Only return matches of friends of this user. 584 $query_args['user_id'] = get_current_user_id(); 585 } 586 587 return $query_args; 588 } 589 No newline at end of file -
src/bp-members/bp-members-functions.php
diff --git a/src/bp-members/bp-members-functions.php b/src/bp-members/bp-members-functions.php index 63b6465..d182256 100644
a b function bp_live_spammer_login_error() { 2094 2094 * 2095 2095 * @param array $args { 2096 2096 * @type int $limit Maximum number of results to display. Default: 16. 2097 * @type bool $only_friends If true, only return matches who are friends with the current user. Default: false.2097 * @type bool $only_friends If true, only match the current user's friends. Default: false. 2098 2098 * @type string $term The suggestion service will try to find results that contain this string. 2099 2099 * Mandatory. 2100 2100 * } … … function bp_members_get_suggestions( $args ) { 2112 2112 $args['only_friends'] = (bool) $args['only_friends']; 2113 2113 2114 2114 2115 if ( $args['only_friends'] && ! bp_is_active( 'friends') ) {2115 if ( $args['only_friends'] && ( ! bp_is_active( 'friends' ) || ! is_user_logged_in() ) ) { 2116 2116 // Friends component is missing. 2117 2117 return new WP_Error( 'missing_requirement' ); 2118 2118 } … … function bp_members_get_suggestions( $args ) { 2127 2127 'search_terms' => $args['term'], 2128 2128 ); 2129 2129 2130 if ( $args['only_friends'] ) { 2131 $user_query['user_id'] = get_current_user_id(); 2132 } 2133 2134 2135 $user_query = new BP_User_Query( $user_query ); 2130 $user_query = new BP_User_Query( apply_filters( 'bp_suggestions_members_query_args', $user_query, $args ) ); 2136 2131 $results = array(); 2137 2132 2138 2133 foreach ( $user_query->results as $user ) { -
src/bp-core/bp-core-functions.php
-- 1.9.3 From 3ceb230e58d8c688eeea73376cd1b7664b351a71 Mon Sep 17 00:00:00 2001 From: Paul Gibbs <paul@byotos.com> Date: Sat, 21 Jun 2014 15:47:19 +0100 Subject: [PATCH 06/35] Suggestions: remove object_id logic for now. Re-implementing/renaming/re-working. --- src/bp-core/bp-core-functions.php | 10 ------ src/bp-groups/bp-groups-filters.php | 13 +++++++ src/bp-groups/bp-groups-functions.php | 66 +++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 10 deletions(-) diff --git a/src/bp-core/bp-core-functions.php b/src/bp-core/bp-core-functions.php index 75cb9f5..837113a 100644
a b function bp_nav_menu_get_item_url( $slug ) { 1943 1943 * 1944 1944 * @param array $args { 1945 1945 * @type int limit Maximum number of results to display. Default: 16. 1946 * @type int|string $object_id Specifies a particular object that may be used by a suggestion1947 * service. Accepts either an integer or a string. For example, this could be used by a1948 * Groups suggestion type that searches for members who are members of a specific group.1949 1946 * @type string $type The name of the suggestion service to use for the request. Mandatory. 1950 1947 * @type string $term The suggestion service will try to find results that contain this string. 1951 1948 * Mandatory. … … function bp_nav_menu_get_item_url( $slug ) { 1956 1953 function bp_core_get_suggestions( $args ) { 1957 1954 $defaults = array( 1958 1955 'limit' => 16, 1959 'object_id' => 0,1960 1956 'type' => '', 1961 1957 'term' => '', 1962 1958 ); 1963 1959 $args = wp_parse_args( $args, $defaults ); 1964 1960 1965 if ( ctype_digit( $args['object_id'] ) ) {1966 $args['object_id'] = absint( $args['object_id'] );1967 } else {1968 $args['object_id'] = sanitize_text_field( $args['object_id'] );1969 }1970 1971 1961 $args['limit'] = absint( $args['limit'] ); 1972 1962 $args['term'] = trim( sanitize_text_field( $args['term'] ) ); 1973 1963 -
src/bp-groups/bp-groups-filters.php
diff --git a/src/bp-groups/bp-groups-filters.php b/src/bp-groups/bp-groups-filters.php index 5ec2d91..8df573e 100644
a b function groups_filter_forums_root_page_sql( $sql ) { 205 205 return apply_filters( 'groups_filter_bbpress_root_page_sql', 't.topic_id' ); 206 206 } 207 207 add_filter( 'get_latest_topics_fields', 'groups_filter_forums_root_page_sql' ); 208 209 /** 210 * Add support for @username mentions for people who belong to a specific Group. 211 * 212 * @param array $types Array of registered extensions to the Suggestion API. 213 * @return array 214 * @see bp_core_get_suggestions() 215 */ 216 function bp_groups_register_suggestion_types( $types ) { 217 $types['group-members'] = 'bp_groups_get_member_suggestions'; 218 return $types; 219 } 220 add_filter( 'bp_suggestions_get_types', 'bp_groups_register_suggestion_types' ); 221 No newline at end of file -
src/bp-groups/bp-groups-functions.php
diff --git a/src/bp-groups/bp-groups-functions.php b/src/bp-groups/bp-groups-functions.php index 971f8b1..d3cdfdd 100644
a b function groups_remove_data_for_user( $user_id ) { 1153 1153 add_action( 'wpmu_delete_user', 'groups_remove_data_for_user' ); 1154 1154 add_action( 'delete_user', 'groups_remove_data_for_user' ); 1155 1155 add_action( 'bp_make_spam_user', 'groups_remove_data_for_user' ); 1156 1157 1158 /** 1159 * Implement support for @username mentions for people who belong to a specific Group. 1160 * 1161 * The $args parameter may include other parameters not documented here; if so, they are not used 1162 * by this particular Suggestions API extension. 1163 * 1164 * @param array $args { 1165 * @type int $limit Maximum number of results to display. Default: 16. 1166 * @type bool $only_friends If true, only return matches who are friends with the current user. Default: false. 1167 * @type string $term The suggestion service will try to find results that contain this string. 1168 * Mandatory. 1169 * } 1170 * @return array|WP_Error See {@see bp_core_get_suggestions()}. If any problems, return a WP_Error. 1171 * @see bp_core_get_suggestions() 1172 * @since BuddyPress (2.1.0) 1173 */ 1174 function bp_groups_get_member_suggestions( $args ) { 1175 $defaults = array( 1176 'limit' => 16, // Sanitised upstream 1177 'only_friends' => false, 1178 'term' => '', // Sanitised upstream 1179 ); 1180 $args = apply_filters( 'bp_groups_get_member_suggestions_args', wp_parse_args( $args, $defaults ) ); 1181 $args['only_friends'] = (bool) $args['only_friends']; 1182 1183 1184 if ( $args['only_friends'] && ! bp_is_active( 'friends' ) ) { 1185 // Friends component is missing. 1186 return new WP_Error( 'missing_requirement' ); 1187 } 1188 1189 $user_query = array( 1190 'count_total' => '', // Prevents total count 1191 'populate_extras' => false, 1192 'type' => 'alphabetical', 1193 1194 'page' => 1, 1195 'per_page' => $args['limit'], 1196 'search_terms' => $args['term'], 1197 ); 1198 1199 if ( $args['only_friends'] ) { 1200 $user_query['user_id'] = get_current_user_id(); 1201 } 1202 1203 1204 $user_query = new BP_User_Query( $user_query ); 1205 $results = array(); 1206 1207 foreach ( $user_query->results as $user ) { 1208 $result = new stdClass(); 1209 $result->ID = $user->user_nicename; 1210 $result->image = get_avatar( $user ); 1211 $result->name = $user->display_name; 1212 1213 if ( bp_disable_profile_sync() ) { 1214 $result->name = BP_XProfile_Field::get_fullname( $user->ID ); 1215 } 1216 1217 $results[] = $result; 1218 } 1219 1220 return apply_filters( 'bp_groups_get_member_suggestions', $results, $args ); 1221 } 1222 No newline at end of file -
src/bp-groups/bp-groups-functions.php
-- 1.9.3 From e164fbc0aa1bb7b5ff21706383e806dc95108fa9 Mon Sep 17 00:00:00 2001 From: Paul Gibbs <paul@byotos.com> Date: Sat, 21 Jun 2014 16:10:23 +0100 Subject: [PATCH 07/35] Removing code that shouldn't been committed yet. --- src/bp-groups/bp-groups-functions.php | 65 ----------------------------------- 1 file changed, 65 deletions(-) diff --git a/src/bp-groups/bp-groups-functions.php b/src/bp-groups/bp-groups-functions.php index d3cdfdd..a8cbab9 100644
a b function groups_remove_data_for_user( $user_id ) { 1154 1154 add_action( 'delete_user', 'groups_remove_data_for_user' ); 1155 1155 add_action( 'bp_make_spam_user', 'groups_remove_data_for_user' ); 1156 1156 1157 1158 /**1159 * Implement support for @username mentions for people who belong to a specific Group.1160 *1161 * The $args parameter may include other parameters not documented here; if so, they are not used1162 * by this particular Suggestions API extension.1163 *1164 * @param array $args {1165 * @type int $limit Maximum number of results to display. Default: 16.1166 * @type bool $only_friends If true, only return matches who are friends with the current user. Default: false.1167 * @type string $term The suggestion service will try to find results that contain this string.1168 * Mandatory.1169 * }1170 * @return array|WP_Error See {@see bp_core_get_suggestions()}. If any problems, return a WP_Error.1171 * @see bp_core_get_suggestions()1172 * @since BuddyPress (2.1.0)1173 */1174 function bp_groups_get_member_suggestions( $args ) {1175 $defaults = array(1176 'limit' => 16, // Sanitised upstream1177 'only_friends' => false,1178 'term' => '', // Sanitised upstream1179 );1180 $args = apply_filters( 'bp_groups_get_member_suggestions_args', wp_parse_args( $args, $defaults ) );1181 $args['only_friends'] = (bool) $args['only_friends'];1182 1183 1184 if ( $args['only_friends'] && ! bp_is_active( 'friends' ) ) {1185 // Friends component is missing.1186 return new WP_Error( 'missing_requirement' );1187 }1188 1189 $user_query = array(1190 'count_total' => '', // Prevents total count1191 'populate_extras' => false,1192 'type' => 'alphabetical',1193 1194 'page' => 1,1195 'per_page' => $args['limit'],1196 'search_terms' => $args['term'],1197 );1198 1199 if ( $args['only_friends'] ) {1200 $user_query['user_id'] = get_current_user_id();1201 }1202 1203 1204 $user_query = new BP_User_Query( $user_query );1205 $results = array();1206 1207 foreach ( $user_query->results as $user ) {1208 $result = new stdClass();1209 $result->ID = $user->user_nicename;1210 $result->image = get_avatar( $user );1211 $result->name = $user->display_name;1212 1213 if ( bp_disable_profile_sync() ) {1214 $result->name = BP_XProfile_Field::get_fullname( $user->ID );1215 }1216 1217 $results[] = $result;1218 }1219 1220 return apply_filters( 'bp_groups_get_member_suggestions', $results, $args );1221 }1222 No newline at end of file -
src/bp-members/bp-members-functions.php
-- 1.9.3 From 74d23221b179788b566ae55d9ffbb2b142d0dd11 Mon Sep 17 00:00:00 2001 From: Paul Gibbs <paul@byotos.com> Date: Sat, 21 Jun 2014 17:03:00 +0100 Subject: [PATCH 08/35] Allow components to bail out of suggestions if the request is bad --- src/bp-members/bp-members-functions.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/bp-members/bp-members-functions.php b/src/bp-members/bp-members-functions.php index d182256..2fbcd17 100644
a b function bp_members_get_suggestions( $args ) { 2118 2118 } 2119 2119 2120 2120 $user_query = array( 2121 $user_query = apply_filters( 'bp_suggestions_members_query_args', array( 2121 2122 'count_total' => '', // Prevents total count 2122 2123 'populate_extras' => false, 2123 2124 'type' => 'alphabetical', … … function bp_members_get_suggestions( $args ) { 2125 2126 'page' => 1, 2126 2127 'per_page' => $args['limit'], 2127 2128 'search_terms' => $args['term'], 2128 ); 2129 ), $args ); 2130 2131 // Allow components to bail us out if the request is bad. 2132 if ( is_wp_error( $user_query ) ) { 2133 return $user_query; 2134 } 2135 2129 2136 2130 $user_query = new BP_User_Query( apply_filters( 'bp_suggestions_members_query_args', $user_query, $args ));2137 $user_query = new BP_User_Query( $user_query ); 2131 2138 $results = array(); 2132 2139 2133 2140 foreach ( $user_query->results as $user ) { -
src/bp-friends/bp-friends-functions.php
-- 1.9.3 From 6bd552b446ac2d8879c1cacb4854a6deeb2e4bef Mon Sep 17 00:00:00 2001 From: Paul Gibbs <paul@byotos.com> Date: Sat, 21 Jun 2014 17:03:54 +0100 Subject: [PATCH 09/35] Suggestions, Members: support filtering by group. --- src/bp-friends/bp-friends-functions.php | 2 +- src/bp-groups/bp-groups-filters.php | 13 +--------- src/bp-groups/bp-groups-functions.php | 42 +++++++++++++++++++++++++++++++++ src/bp-members/bp-members-functions.php | 9 ++++++- 4 files changed, 52 insertions(+), 14 deletions(-) diff --git a/src/bp-friends/bp-friends-functions.php b/src/bp-friends/bp-friends-functions.php index dce5320..fa7ff37 100644
a b function friends_remove_data( $user_id ) { 574 574 * 575 575 * @param array $query_args The parameters that will be passed to {@see BP_User_Query}. 576 576 * @param array $suggestion_args Arguments originally sent to the {@see bp_core_get_suggestions()}. 577 * @return array The parameters that will be passed to {@see BP_User_Query}.577 * @return array|WP_Error The parameters that will be passed to {@see BP_User_Query}. 578 578 * @see bp_members_get_suggestions() 579 579 * @since BuddyPress (2.1.0) 580 580 */ -
src/bp-groups/bp-groups-filters.php
diff --git a/src/bp-groups/bp-groups-filters.php b/src/bp-groups/bp-groups-filters.php index 8df573e..77cbf27 100644
a b function groups_filter_forums_root_page_sql( $sql ) { 206 206 } 207 207 add_filter( 'get_latest_topics_fields', 'groups_filter_forums_root_page_sql' ); 208 208 209 /** 210 * Add support for @username mentions for people who belong to a specific Group. 211 * 212 * @param array $types Array of registered extensions to the Suggestion API. 213 * @return array 214 * @see bp_core_get_suggestions() 215 */ 216 function bp_groups_register_suggestion_types( $types ) { 217 $types['group-members'] = 'bp_groups_get_member_suggestions'; 218 return $types; 219 } 220 add_filter( 'bp_suggestions_get_types', 'bp_groups_register_suggestion_types' ); 221 No newline at end of file 209 add_filter( 'bp_suggestions_members_query_args', 'bp_groups_suggestions_filter_query_args', 10, 2 ); 210 No newline at end of file -
src/bp-groups/bp-groups-functions.php
diff --git a/src/bp-groups/bp-groups-functions.php b/src/bp-groups/bp-groups-functions.php index a8cbab9..a1b27df 100644
a b function groups_remove_data_for_user( $user_id ) { 1154 1154 add_action( 'delete_user', 'groups_remove_data_for_user' ); 1155 1155 add_action( 'bp_make_spam_user', 'groups_remove_data_for_user' ); 1156 1156 1157 /*** Suggestions API ************************************************************/ 1158 1159 /** 1160 * Extend the members' component's @username suggestions by adding support for group memberships. 1161 * 1162 * @param array $query_args The parameters that will be passed to {@see BP_User_Query}. 1163 * @param array $suggestion_args Arguments originally sent to the {@see bp_core_get_suggestions()}. 1164 * @return array|WP_Error The parameters that will be passed to {@see BP_User_Query}. 1165 * @see bp_members_get_suggestions() 1166 * @since BuddyPress (2.1.0) 1167 */ 1168 function bp_groups_suggestions_filter_query_args( $query_args, $suggestion_args ) { 1169 if ( ! $suggestion_args['group_id'] ) { 1170 return $query_args; 1171 } 1172 1173 $the_group = groups_get_group( array( 1174 'group_id' => $suggestion_args['group_id'], 1175 'populate_extras' => true, 1176 ) ); 1177 1178 if ( $the_group->id === 0 || ! $the_group->user_has_access ) { 1179 return new WP_Error( 'access_denied' ); 1180 } 1181 1182 $group_query = array( 1183 'count_total' => '', // Prevents total count 1184 'populate_extras' => false, 1185 'type' => 'alphabetical', 1186 1187 'group_id' => $suggestion_args['group_id'], 1188 ); 1189 1190 $group_users = new BP_Group_Member_Query( $group_query ); 1191 if ( $group_users->results ) { 1192 $query_args['include'] = wp_list_pluck( $group_users->results, 'ID' ); 1193 } else { 1194 $query_args['include'] = array( 0 ); 1195 } 1196 1197 return $query_args; 1198 } 1199 No newline at end of file -
src/bp-members/bp-members-functions.php
diff --git a/src/bp-members/bp-members-functions.php b/src/bp-members/bp-members-functions.php index 2fbcd17..24f5ddb 100644
a b function bp_live_spammer_login_error() { 2093 2093 * by this particular Suggestions API extension. 2094 2094 * 2095 2095 * @param array $args { 2096 * @type int $group_id If set, only match users that are in this group. 2096 2097 * @type int $limit Maximum number of results to display. Default: 16. 2097 2098 * @type bool $only_friends If true, only match the current user's friends. Default: false. 2098 2099 * @type string $term The suggestion service will try to find results that contain this string. … … function bp_live_spammer_login_error() { 2104 2105 */ 2105 2106 function bp_members_get_suggestions( $args ) { 2106 2107 $defaults = array( 2108 'group_id' => 0, 2107 2109 'limit' => 16, // Sanitised upstream 2108 2110 'only_friends' => false, 2109 2111 'term' => '', // Sanitised upstream 2110 2112 ); 2111 2113 $args = apply_filters( 'bp_members_get_suggestions_args', wp_parse_args( $args, $defaults ) ); 2114 $args['group_id'] = absint( $args['group_id'] ); 2112 2115 $args['only_friends'] = (bool) $args['only_friends']; 2113 2116 2114 2117 … … function bp_members_get_suggestions( $args ) { 2117 2120 return new WP_Error( 'missing_requirement' ); 2118 2121 } 2119 2122 2120 $user_query = array( 2123 if ( $args['group_id'] && ! bp_is_active( 'groups' ) ) { 2124 // Groups component is missing. 2125 return new WP_Error( 'missing_requirement' ); 2126 } 2127 2121 2128 $user_query = apply_filters( 'bp_suggestions_members_query_args', array( 2122 2129 'count_total' => '', // Prevents total count 2123 2130 'populate_extras' => false, -
tests/phpunit/testcases/apis/suggestions-nonauth.php
-- 1.9.3 From 6f32be7a364d78fcf09e813faffc88a75bfbbb91 Mon Sep 17 00:00:00 2001 From: Paul Gibbs <paul@byotos.com> Date: Sat, 21 Jun 2014 17:04:19 +0100 Subject: [PATCH 10/35] Update tests for recent API changes. --- .../phpunit/testcases/apis/suggestions-nonauth.php | 18 ++-- tests/phpunit/testcases/apis/suggestions.php | 96 +++++++++------------- 2 files changed, 49 insertions(+), 65 deletions(-) diff --git a/tests/phpunit/testcases/apis/suggestions-nonauth.php b/tests/phpunit/testcases/apis/suggestions-nonauth.php index 0e1be23..0c67d17 100644
a b public function test_suggestions_with_type_members_and_only_friends() { 73 73 $this->assertTrue( is_wp_error( $suggestions ) ); 74 74 } 75 75 76 public function test_suggestions_with_type_group _and_only_friends() {76 public function test_suggestions_with_type_groupmembers_and_only_friends() { 77 77 // only_friends requires authenticated requests 78 78 $suggestions = bp_core_get_suggestions( array( 79 ' object_id'=> $this->group_ids['public'],79 'group_id' => $this->group_ids['public'], 80 80 'only_friends' => true, 81 'type' => ' group-members',81 'type' => 'members', 82 82 'term' => 'smith', 83 83 ) ); 84 84 85 85 $this->assertTrue( is_wp_error( $suggestions ) ); 86 86 } 87 87 88 public function test_suggestions_with_type_group _hidden() {88 public function test_suggestions_with_type_groupmembers_hidden() { 89 89 $suggestions = bp_core_get_suggestions( array( 90 ' object_id'=> $this->group_ids['hidden'],91 'type' => ' group-members',90 'group_id' => $this->group_ids['hidden'], 91 'type' => 'members', 92 92 'term' => 'pig', 93 93 ) ); 94 94 95 95 $this->assertTrue( is_wp_error( $suggestions ) ); 96 96 } 97 97 98 public function test_suggestions_with_type_group _private() {98 public function test_suggestions_with_type_groupmembers_private() { 99 99 $suggestions = bp_core_get_suggestions( array( 100 ' object_id'=> $this->group_ids['private'],101 'type' => ' group-members',100 'group_id' => $this->group_ids['private'], 101 'type' => 'members', 102 102 'term' => 'cat', 103 103 ) ); 104 104 -
tests/phpunit/testcases/apis/suggestions.php
diff --git a/tests/phpunit/testcases/apis/suggestions.php b/tests/phpunit/testcases/apis/suggestions.php index 7fc85d7..b2d6274 100644
a b public function test_suggestions_with_term_as_current_user() { 145 145 146 146 public function test_suggestions_with_type_groupmembers_public() { 147 147 $suggestions = bp_core_get_suggestions( array( 148 ' object_id' => $this->group_ids['public'],149 'type' => 'group-members',150 'term' 148 'group_id' => $this->group_ids['public'], 149 'type' => 'members', 150 'term' => 'smith', 151 151 ) ); 152 152 153 153 $this->assertEquals( 2, count( $suggestions ) ); // aardvark, smith. … … public function test_suggestions_with_type_groupmembers_public() { 155 155 156 156 public function test_suggestions_with_type_groupmembers_public_and_limit() { 157 157 $suggestions = bp_core_get_suggestions( array( 158 'limit' 159 ' object_id' => $this->group_ids['public'],160 'type' => 'group-members',161 'term' 158 'limit' => 1, 159 'group_id' => $this->group_ids['public'], 160 'type' => 'members', 161 'term' => 'smith', 162 162 ) ); 163 163 164 164 $this->assertEquals( 1, count( $suggestions ) ); // one of: aardvark, smith. … … public function test_suggestions_with_type_groupmembers_public_and_limit() { 166 166 167 167 public function test_suggestions_with_type_groupmembers_public_and_only_friends() { 168 168 $suggestions = bp_core_get_suggestions( array( 169 ' object_id'=> $this->group_ids['public'],169 'group_id' => $this->group_ids['public'], 170 170 'only_friends' => true, 171 'type' => ' group-members',171 'type' => 'members', 172 172 'term' => 'smith', 173 173 ) ); 174 174 … … public function test_suggestions_with_type_groupmembers_public_and_only_friends( 177 177 178 178 public function test_suggestions_with_type_groupmembers_public_and_term_as_displayname() { 179 179 $suggestions = bp_core_get_suggestions( array( 180 ' object_id' => $this->group_ids['public'],181 'type' => 'group-members',182 'term' 180 'group_id' => $this->group_ids['public'], 181 'type' => 'members', 182 'term' => 'aardvark', 183 183 ) ); 184 184 185 185 $this->assertEquals( 1, count( $suggestions ) ); // aardvark. … … public function test_suggestions_with_type_groupmembers_public_and_term_as_displ 187 187 188 188 public function test_suggestions_with_type_groupmembers_public_and_term_as_usernicename() { 189 189 $suggestions = bp_core_get_suggestions( array( 190 ' object_id' => $this->group_ids['public'],191 'type' => 'group-members',192 'term' 190 'group_id' => $this->group_ids['public'], 191 'type' => 'members', 192 'term' => 'robert', 193 193 ) ); 194 194 195 195 $this->assertEquals( 1, count( $suggestions ) ); // smith. … … public function test_suggestions_with_type_groupmembers_public_and_term_as_usern 197 197 198 198 public function test_suggestions_with_type_groupmembers_public_as_id() { 199 199 $suggestions = bp_core_get_suggestions( array( 200 ' object_id' => $this->group_ids['public'],201 'type' => 'group-members',202 'term' 200 'group_id' => $this->group_ids['public'], 201 'type' => 'members', 202 'term' => 'smith', 203 203 ) ); 204 204 205 205 $this->assertEquals( 2, count( $suggestions ) ); // aardvark, smith. … … public function test_suggestions_with_type_groupmembers_public_as_id() { 207 207 208 208 public function test_suggestions_with_type_groupmembers_public_as_slug() { 209 209 $suggestions = bp_core_get_suggestions( array( 210 ' object_id' => $this->group_slugs['public'],211 'type' => 'group-members',212 'term' 210 'group_id' => $this->group_slugs['public'], 211 'type' => 'members', 212 'term' => 'smith', 213 213 ) ); 214 214 215 215 $this->assertEquals( 2, count( $suggestions ) ); // aardvark, smith. … … public function test_suggestions_with_type_groupmembers_public_as_slug() { 218 218 public function test_suggestions_with_type_groupmembers_hidden() { 219 219 // current_user isn't a member of the hidden group 220 220 $suggestions = bp_core_get_suggestions( array( 221 ' object_id' => $this->group_ids['hidden'],222 'type' => 'group-members',223 'term' 221 'group_id' => $this->group_ids['hidden'], 222 'type' => 'members', 223 'term' => 'pig', 224 224 ) ); 225 225 $this->assertTrue( is_wp_error( $suggestions ) ); 226 226 227 227 // "alpaca red" is in the hidden group 228 228 $this->set_current_user( $this->users['alpaca red'] ); 229 229 $suggestions = bp_core_get_suggestions( array( 230 ' object_id' => $this->group_ids['hidden'],231 'type' => 'group-members',232 'term' 230 'group_id' => $this->group_ids['hidden'], 231 'type' => 'members', 232 'term' => 'pig', 233 233 ) ); 234 234 $this->assertEquals( 1, count( $suggestions ) ); // pig 235 235 } … … public function test_suggestions_with_type_groupmembers_hidden() { 237 237 public function test_suggestions_with_type_groupmembers_private() { 238 238 // current_user isn't a member of the private group 239 239 $suggestions = bp_core_get_suggestions( array( 240 ' object_id' => $this->group_ids['private'],241 'type' => 'group-members',242 'term' 240 'group_id' => $this->group_ids['private'], 241 'type' => 'members', 242 'term' => 'cat', 243 243 ) ); 244 244 $this->assertTrue( is_wp_error( $suggestions ) ); 245 245 246 246 // "caterpillar" is in the private group 247 247 $this->set_current_user( $this->users['caterpillar'] ); 248 248 $suggestions = bp_core_get_suggestions( array( 249 ' object_id' => $this->group_ids['private'],250 'type' => 'group-members',251 'term' 249 'group_id' => $this->group_ids['private'], 250 'type' => 'members', 251 'term' => 'cat', 252 252 ) ); 253 253 $this->assertEquals( 2, count( $suggestions ) ); // cat, caterpillar 254 254 } … … public function test_suggestions_with_bad_type() { 343 343 $this->assertTrue( is_wp_error( $suggestions ) ); 344 344 } 345 345 346 public function test_suggestions_with_type_groupmembers_and_bad_object_id() { 347 // object_id must be a positive integer. 348 $suggestions = bp_core_get_suggestions( array( 349 'object_id' => -12, 350 'type' => 'group-members', 351 ) ); 352 $this->assertTrue( is_wp_error( $suggestions ) ); 353 354 // object_id can also be a group slug. 346 public function test_suggestions_with_type_groupmembers_and_bad_group_ids() { 347 // group_ids must be a positive integer. 355 348 $suggestions = bp_core_get_suggestions( array( 356 ' object_id' => 'fake-group-slug',357 'type' => 'group-members',349 'group_id' => -12, 350 'type' => 'members', 358 351 ) ); 359 352 $this->assertTrue( is_wp_error( $suggestions ) ); 360 353 361 // object_id must be set when scope=group354 // group_ids can also be a group slug. 362 355 $suggestions = bp_core_get_suggestions( array( 363 'type' => 'group-members', 356 'group_id' => 'fake-group-slug', 357 'type' => 'members', 364 358 ) ); 365 359 $this->assertTrue( is_wp_error( $suggestions ) ); 366 360 } 367 361 368 public function test_suggestions_with_type_members_and_object_id() {369 // object_id cannot be set when scope=global370 $suggestions = bp_core_get_suggestions( array(371 'object_id' => 12,372 'type' => 'members',373 ) );374 375 $this->assertTrue( is_wp_error( $suggestions ) );376 }377 378 362 public function test_suggestions_with_bad_term() { 379 363 // a non-empty term is mandatory 380 364 $suggestions = bp_core_get_suggestions( array( -
src/bp-members/bp-members-functions.php
-- 1.9.3 From 75f9285389ffc6293af4520e624667c34803466a Mon Sep 17 00:00:00 2001 From: Paul Gibbs <paul@byotos.com> Date: Sat, 21 Jun 2014 20:42:19 +0100 Subject: [PATCH 11/35] Suggestions: change how we get the display name The function now used has internal logic for bp_disable_profile_sync(), as well as caching. --- src/bp-members/bp-members-functions.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/bp-members/bp-members-functions.php b/src/bp-members/bp-members-functions.php index 24f5ddb..9b6eb64 100644
a b function bp_members_get_suggestions( $args ) { 2148 2148 $result = new stdClass(); 2149 2149 $result->ID = $user->user_nicename; 2150 2150 $result->image = get_avatar( $user ); 2151 $result->name = $user->display_name; 2152 2153 if ( bp_disable_profile_sync() ) { 2154 $result->name = BP_XProfile_Field::get_fullname( $user->ID ); 2155 } 2151 $result->name = bp_core_get_user_displayname( $user->ID ); 2156 2152 2157 2153 $results[] = $result; 2158 2154 } -
tests/phpunit/testcases/apis/suggestions.php
-- 1.9.3 From 6617e1c8bbb54b3f6dc296a80fbe39d0be173349 Mon Sep 17 00:00:00 2001 From: Paul Gibbs <paul@byotos.com> Date: Sat, 21 Jun 2014 20:50:42 +0100 Subject: [PATCH 12/35] Add missing required parameter to some tests type was optional in an early iteration :) --- tests/phpunit/testcases/apis/suggestions.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/phpunit/testcases/apis/suggestions.php b/tests/phpunit/testcases/apis/suggestions.php index b2d6274..81d228e 100644
a b public function test_suggestions_with_type_groupmembers_private() { 261 261 public function test_suggestions_response_no_matches() { 262 262 $suggestions = bp_core_get_suggestions( array( 263 263 'term' => 'abcdefghijklmnopqrstuvwxyz', 264 'type' => 'members', 264 265 ) ); 265 266 266 267 $this->assertInternalType( 'array', $suggestions ); … … public function test_suggestions_response_no_matches() { 270 271 public function test_suggestions_response_single_match() { 271 272 $suggestion = bp_core_get_suggestions( array( 272 273 'term' => 'zoom', 274 'type' => 'members', 273 275 ) ); 274 276 275 277 $this->assertInternalType( 'array', $suggestion ); … … public function test_suggestions_response_single_match() { 286 288 public function test_suggestions_response_multiple_matches() { 287 289 $suggestions = bp_core_get_suggestions( array( 288 290 'term' => 'cat', 291 'type' => 'members', 289 292 ) ); 290 293 291 294 $this->assertInternalType( 'array', $suggestions ); … … public function test_suggestions_response_multiple_matches() { 302 305 public function test_suggestions_term_is_case_insensitive() { 303 306 $lowercase = bp_core_get_suggestions( array( 304 307 'term' => 'lisa', 308 'type' => 'members', 305 309 ) ); 306 310 $this->assertEquals( 1, count( $lowercase ) ); 307 311 308 312 $uppercase = bp_core_get_suggestions( array( 309 313 'term' => 'LISA', 314 'type' => 'members', 310 315 ) ); 311 316 $this->assertEquals( 1, count( $uppercase ) ); 312 317 … … public function test_suggestions_term_is_case_insensitive() { 317 322 public function test_suggestions_response_property_types() { 318 323 $suggestion = bp_core_get_suggestions( array( 319 324 'term' => 'zoom', 325 'type' => 'members', 320 326 ) ); 321 327 322 328 $this->assertInternalType( 'array', $suggestion ); … … public function test_suggestions_with_bad_term() { 363 369 // a non-empty term is mandatory 364 370 $suggestions = bp_core_get_suggestions( array( 365 371 'term' => '', 372 'type' => 'members', 366 373 ) ); 367 374 368 375 $this->assertTrue( is_wp_error( $suggestions ) ); -
tests/phpunit/testcases/apis/suggestions-nonauth.php
-- 1.9.3 From dce81b7dab00a12513ecc1527c4920e39edf394c Mon Sep 17 00:00:00 2001 From: Paul Gibbs <paul@byotos.com> Date: Sat, 21 Jun 2014 21:39:12 +0100 Subject: [PATCH 13/35] Suggestions tests: use $this->create_user() to create users MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit factory->user->create doesn’t add xprofile data which we need for these tests. --- tests/phpunit/testcases/apis/suggestions-nonauth.php | 2 +- tests/phpunit/testcases/apis/suggestions.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/phpunit/testcases/apis/suggestions-nonauth.php b/tests/phpunit/testcases/apis/suggestions-nonauth.php index 0c67d17..e21a4af 100644
a b public function setUp() { 29 29 30 30 // Create some dummy users. 31 31 foreach( $users as $user ) { 32 $this->user_ids[ $user[0] ] = $this-> factory->user->create( array(32 $this->user_ids[ $user[0] ] = $this->create_user( array( 33 33 'display_name' => $user[1], 34 34 'user_login' => $user[0], 35 35 ) ); -
tests/phpunit/testcases/apis/suggestions.php
diff --git a/tests/phpunit/testcases/apis/suggestions.php b/tests/phpunit/testcases/apis/suggestions.php index 81d228e..0a1ac10 100644
a b public function setUp() { 16 16 parent::setUp(); 17 17 18 18 $this->old_user_id = get_current_user_id(); 19 $this->current_user = $this-> factory->user->create( array(19 $this->current_user = $this->create_user( array( 20 20 'display_name' => 'Katie Parker', 21 21 'user_login' => 'admin', 22 22 ) ); … … public function setUp() { 38 38 ); 39 39 40 40 // Create some dummy users. 41 foreach ( $users as $user ) {42 $this->user_ids[ $user[0] ] = $this-> factory->user->create( array(41 foreach ( $users as $user ) { 42 $this->user_ids[ $user[0] ] = $this->create_user( array( 43 43 'display_name' => $user[1], 44 44 'user_login' => $user[0], 45 45 ) ); -
tests/phpunit/testcases/apis/suggestions-nonauth.php
-- 1.9.3 From 5eac207f9230a48e89a939a33a4a68a01934f19a Mon Sep 17 00:00:00 2001 From: Paul Gibbs <paul@byotos.com> Date: Sat, 21 Jun 2014 21:43:54 +0100 Subject: [PATCH 14/35] Whitespace tweaks --- tests/phpunit/testcases/apis/suggestions-nonauth.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/phpunit/testcases/apis/suggestions-nonauth.php b/tests/phpunit/testcases/apis/suggestions-nonauth.php index e21a4af..b7d7aaa 100644
a b public function test_suggestions_with_type_groupmembers_and_only_friends() { 87 87 88 88 public function test_suggestions_with_type_groupmembers_hidden() { 89 89 $suggestions = bp_core_get_suggestions( array( 90 'group_id' 91 'type' 92 'term' 90 'group_id' => $this->group_ids['hidden'], 91 'type' => 'members', 92 'term' => 'pig', 93 93 ) ); 94 94 95 95 $this->assertTrue( is_wp_error( $suggestions ) ); … … public function test_suggestions_with_type_groupmembers_hidden() { 97 97 98 98 public function test_suggestions_with_type_groupmembers_private() { 99 99 $suggestions = bp_core_get_suggestions( array( 100 'group_id' 101 'type' 102 'term' 100 'group_id' => $this->group_ids['private'], 101 'type' => 'members', 102 'term' => 'cat', 103 103 ) ); 104 104 105 105 $this->assertTrue( is_wp_error( $suggestions ) ); -
tests/phpunit/testcases/apis/suggestions.php
-- 1.9.3 From affc24b90d58dae0c7d327b7ca5350fb77f64d9a Mon Sep 17 00:00:00 2001 From: Paul Gibbs <paul@byotos.com> Date: Sat, 21 Jun 2014 21:44:13 +0100 Subject: [PATCH 15/35] Suggestions: ID property is uppercase --- tests/phpunit/testcases/apis/suggestions.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/testcases/apis/suggestions.php b/tests/phpunit/testcases/apis/suggestions.php index 0a1ac10..092834a 100644
a b public function test_suggestions_with_term_as_current_user() { 139 139 'term' => 'katie', 140 140 ) ); 141 141 $this->assertEquals( 1, count( $suggestions ) ); 142 $this->assertSame( 'admin', $suggestions[0]-> id);142 $this->assertSame( 'admin', $suggestions[0]->ID ); 143 143 } 144 144 145 145 … … public function test_suggestions_term_is_case_insensitive() { 315 315 ) ); 316 316 $this->assertEquals( 1, count( $uppercase ) ); 317 317 318 $this->assertSame( $lowercase[0]-> id, $uppercase[0]->id);319 $this->assertSame( 'zoom', $lowercase[0]-> id);318 $this->assertSame( $lowercase[0]->ID, $uppercase[0]->ID ); 319 $this->assertSame( 'zoom', $lowercase[0]->ID ); 320 320 } 321 321 322 322 public function test_suggestions_response_property_types() { -
tests/phpunit/testcases/apis/suggestions.php
-- 1.9.3 From 82ef062a9cb731c7726261946f2a309a18b1cfba Mon Sep 17 00:00:00 2001 From: Paul Gibbs <paul@byotos.com> Date: Sat, 21 Jun 2014 21:48:11 +0100 Subject: [PATCH 16/35] Suggestions: uppercase more IDs --- tests/phpunit/testcases/apis/suggestions.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/testcases/apis/suggestions.php b/tests/phpunit/testcases/apis/suggestions.php index 092834a..e2f0540 100644
a b public function test_suggestions_response_single_match() { 281 281 282 282 $this->assertInternalType( 'object', $suggestion ); 283 283 $this->assertAttributeNotEmpty( 'image', $suggestion ); 284 $this->assertAttributeNotEmpty( ' id', $suggestion );284 $this->assertAttributeNotEmpty( 'ID', $suggestion ); 285 285 $this->assertAttributeNotEmpty( 'name', $suggestion ); 286 286 } 287 287 … … public function test_suggestions_response_multiple_matches() { 297 297 foreach ( $suggestions as $suggestion ) { 298 298 $this->assertInternalType( 'object', $suggestion ); 299 299 $this->assertAttributeNotEmpty( 'image', $suggestion ); 300 $this->assertAttributeNotEmpty( ' id', $suggestion );300 $this->assertAttributeNotEmpty( 'ID', $suggestion ); 301 301 $this->assertAttributeNotEmpty( 'name', $suggestion ); 302 302 } 303 303 } … … public function test_suggestions_response_property_types() { 332 332 333 333 $this->assertInternalType( 'object', $suggestion ); 334 334 $this->assertAttributeInternalType( 'string', 'image', $suggestion ); 335 $this->assertAttributeInternalType( 'string', ' id', $suggestion );335 $this->assertAttributeInternalType( 'string', 'ID', $suggestion ); 336 336 $this->assertAttributeInternalType( 'string', 'name', $suggestion ); 337 337 } 338 338 -
src/bp-members/bp-members-functions.php
-- 1.9.3 From 192cde4679ff029be90cc96acb839a8610d713c4 Mon Sep 17 00:00:00 2001 From: Paul Gibbs <paul@byotos.com> Date: Sat, 21 Jun 2014 22:23:45 +0100 Subject: [PATCH 17/35] Suggestions: image needs to be a direct URL get_avatar() returns a full `<img>` ta.g --- src/bp-members/bp-members-functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bp-members/bp-members-functions.php b/src/bp-members/bp-members-functions.php index 9b6eb64..8b9bc9a 100644
a b function bp_members_get_suggestions( $args ) { 2147 2147 foreach ( $user_query->results as $user ) { 2148 2148 $result = new stdClass(); 2149 2149 $result->ID = $user->user_nicename; 2150 $result->image = get_avatar( $user);2150 $result->image = bp_core_fetch_avatar( array( 'html' => false, 'item_id' => $user->ID ) ); 2151 2151 $result->name = bp_core_get_user_displayname( $user->ID ); 2152 2152 2153 2153 $results[] = $result; -
src/bp-members/bp-members-functions.php
-- 1.9.3 From e4ac3acd744420cfe58cf05d5a895f9c3c64b7ef Mon Sep 17 00:00:00 2001 From: Paul Gibbs <paul@byotos.com> Date: Sat, 21 Jun 2014 22:41:40 +0100 Subject: [PATCH 18/35] phpDoc tweak --- src/bp-members/bp-members-functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bp-members/bp-members-functions.php b/src/bp-members/bp-members-functions.php index 8b9bc9a..45c9377 100644
a b function bp_live_spammer_login_error() { 2093 2093 * by this particular Suggestions API extension. 2094 2094 * 2095 2095 * @param array $args { 2096 * @type int $group_id If set, only match users that are in this group.2096 * @type int $group_id If set, only match against users that are in this group. 2097 2097 * @type int $limit Maximum number of results to display. Default: 16. 2098 2098 * @type bool $only_friends If true, only match the current user's friends. Default: false. 2099 2099 * @type string $term The suggestion service will try to find results that contain this string. -
tests/phpunit/testcases/apis/suggestions.php
-- 1.9.3 From 8453b916780a3817fd002ef0a6a6e34105e82c78 Mon Sep 17 00:00:00 2001 From: Paul Gibbs <paul@byotos.com> Date: Sat, 21 Jun 2014 22:42:05 +0100 Subject: [PATCH 19/35] Remove Suggestions test that doesn't match API Querying groups by slug was removed. --- tests/phpunit/testcases/apis/suggestions.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/tests/phpunit/testcases/apis/suggestions.php b/tests/phpunit/testcases/apis/suggestions.php index e2f0540..4bc6a68 100644
a b public function test_suggestions_with_type_groupmembers_public_as_id() { 205 205 $this->assertEquals( 2, count( $suggestions ) ); // aardvark, smith. 206 206 } 207 207 208 public function test_suggestions_with_type_groupmembers_public_as_slug() {209 $suggestions = bp_core_get_suggestions( array(210 'group_id' => $this->group_slugs['public'],211 'type' => 'members',212 'term' => 'smith',213 ) );214 215 $this->assertEquals( 2, count( $suggestions ) ); // aardvark, smith.216 }217 218 208 public function test_suggestions_with_type_groupmembers_hidden() { 219 209 // current_user isn't a member of the hidden group 220 210 $suggestions = bp_core_get_suggestions( array( -
tests/phpunit/testcases/apis/suggestions-nonauth.php
-- 1.9.3 From 4437de02b04ce2b133abb13feea084f05c4d6233 Mon Sep 17 00:00:00 2001 From: Paul Gibbs <paul@byotos.com> Date: Sat, 21 Jun 2014 23:03:38 +0100 Subject: [PATCH 20/35] Create test groups from non-current user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Otherwise current user is the group admin and has access to the groups which weren’t accounted for in the test. --- tests/phpunit/testcases/apis/suggestions-nonauth.php | 19 ++++++++++++++++--- tests/phpunit/testcases/apis/suggestions.php | 19 ++++++++++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/tests/phpunit/testcases/apis/suggestions-nonauth.php b/tests/phpunit/testcases/apis/suggestions-nonauth.php index b7d7aaa..85f9d10 100644
a b public function setUp() { 24 24 array( 'rabbit blue', 'Amber Hooper' ), 25 25 array( 'smith', 'Robert Bar' ), 26 26 array( 'snake', 'Eleanor Moore' ), 27 array( 'xylo', 'Silver McFadden' ), 27 28 array( 'zoom', 'Lisa Smithy' ), 28 29 ); 29 30 … … public function setUp() { 40 41 $this->group_slugs['private'] = 'tsavo-highway'; 41 42 42 43 // Create dummy groups. 43 $this->group_ids['hidden'] = $this->factory->group->create( array( 'slug' => $this->group_slugs['hidden'], 'status' => 'hidden' ) ); 44 $this->group_ids['public'] = $this->factory->group->create( array( 'slug' => $this->group_slugs['public'], 'status' => 'public' ) ); 45 $this->group_ids['private'] = $this->factory->group->create( array( 'slug' => $this->group_slugs['private'], 'status' => 'private' ) ); 44 $this->group_ids['hidden'] = $this->factory->group->create( array( 45 'creator_id' => $this->user_ids['xylo'], 46 'slug' => $this->group_slugs['hidden'], 47 'status' => 'hidden', 48 ) ); 49 $this->group_ids['public'] = $this->factory->group->create( array( 50 'creator_id' => $this->user_ids['xylo'], 51 'slug' => $this->group_slugs['public'], 52 'status' => 'public', 53 ) ); 54 $this->group_ids['private'] = $this->factory->group->create( array( 55 'creator_id' => $this->user_ids['xylo'], 56 'slug' => $this->group_slugs['private'], 57 'status' => 'private', 58 ) ); 46 59 47 60 // Add dummy users to dummy hidden groups. 48 61 groups_join_group( $this->group_ids['hidden'], $this->user_ids['pig'] ); -
tests/phpunit/testcases/apis/suggestions.php
diff --git a/tests/phpunit/testcases/apis/suggestions.php b/tests/phpunit/testcases/apis/suggestions.php index 4bc6a68..494854a 100644
a b public function setUp() { 34 34 array( 'rabbit blue', 'Amber Hooper' ), 35 35 array( 'smith', 'Robert Bar' ), 36 36 array( 'snake', 'Eleanor Moore' ), 37 array( 'xylo', 'Silver McFadden' ), 37 38 array( 'zoom', 'Lisa Smithy' ), 38 39 ); 39 40 … … public function setUp() { 56 57 $this->group_slugs['private'] = 'tsavo-highway'; 57 58 58 59 // Create dummy groups. 59 $this->group_ids['hidden'] = $this->factory->group->create( array( 'slug' => $this->group_slugs['hidden'], 'status' => 'hidden' ) ); 60 $this->group_ids['public'] = $this->factory->group->create( array( 'slug' => $this->group_slugs['public'], 'status' => 'public' ) ); 61 $this->group_ids['private'] = $this->factory->group->create( array( 'slug' => $this->group_slugs['private'], 'status' => 'private' ) ); 60 $this->group_ids['hidden'] = $this->factory->group->create( array( 61 'creator_id' => $this->user_ids['xylo'], 62 'slug' => $this->group_slugs['hidden'], 63 'status' => 'hidden', 64 ) ); 65 $this->group_ids['public'] = $this->factory->group->create( array( 66 'creator_id' => $this->user_ids['xylo'], 67 'slug' => $this->group_slugs['public'], 68 'status' => 'public', 69 ) ); 70 $this->group_ids['private'] = $this->factory->group->create( array( 71 'creator_id' => $this->user_ids['xylo'], 72 'slug' => $this->group_slugs['private'], 73 'status' => 'private', 74 ) ); 62 75 63 76 // Add dummy users to dummy hidden groups. 64 77 groups_join_group( $this->group_ids['hidden'], $this->user_ids['pig'] ); -
tests/phpunit/testcases/apis/suggestions.php
-- 1.9.3 From a0508e2ff186a1eaa542f17d6a174803eae5a04f Mon Sep 17 00:00:00 2001 From: Paul Gibbs <paul@byotos.com> Date: Sat, 21 Jun 2014 23:06:57 +0100 Subject: [PATCH 21/35] Suggestions, tests: fix incorrectly named variables --- tests/phpunit/testcases/apis/suggestions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/testcases/apis/suggestions.php b/tests/phpunit/testcases/apis/suggestions.php index 494854a..381c98e 100644
a b public function test_suggestions_with_type_groupmembers_hidden() { 228 228 $this->assertTrue( is_wp_error( $suggestions ) ); 229 229 230 230 // "alpaca red" is in the hidden group 231 $this->set_current_user( $this->user s['alpaca red'] );231 $this->set_current_user( $this->user_ids['alpaca red'] ); 232 232 $suggestions = bp_core_get_suggestions( array( 233 233 'group_id' => $this->group_ids['hidden'], 234 234 'type' => 'members', … … public function test_suggestions_with_type_groupmembers_private() { 247 247 $this->assertTrue( is_wp_error( $suggestions ) ); 248 248 249 249 // "caterpillar" is in the private group 250 $this->set_current_user( $this->user s['caterpillar'] );250 $this->set_current_user( $this->user_ids['caterpillar'] ); 251 251 $suggestions = bp_core_get_suggestions( array( 252 252 'group_id' => $this->group_ids['private'], 253 253 'type' => 'members', -
src/bp-core/bp-core-functions.php
-- 1.9.3 From d039b95e6b429057e1e6e0f906e089b8e794f3b0 Mon Sep 17 00:00:00 2001 From: Paul Gibbs <paul@byotos.com> Date: Sun, 22 Jun 2014 00:03:52 +0100 Subject: [PATCH 22/35] phpDoc tweaks --- src/bp-core/bp-core-functions.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bp-core/bp-core-functions.php b/src/bp-core/bp-core-functions.php index 837113a..e565cd0 100644
a b function bp_nav_menu_get_item_url( $slug ) { 1930 1930 * This is used to power BuddyPress' at-mentions suggestions, but it is flexible enough to be used 1931 1931 * for similar kinds of requirements. 1932 1932 * 1933 * If a Component or a third-party plugin wants to provide suggestions for a custom type of object,1933 * If a component or a third-party plugin wants to provide suggestions for a custom type of object, 1934 1934 * use the bp_suggestions_get_types filter and return an associative array with its key as the new 1935 1935 * "type", and its value as a function callback. 1936 1936 * … … function bp_nav_menu_get_item_url( $slug ) { 1952 1952 */ 1953 1953 function bp_core_get_suggestions( $args ) { 1954 1954 $defaults = array( 1955 'limit' 1956 'type' 1957 'term' 1955 'limit' => 16, 1956 'type' => '', 1957 'term' => '', 1958 1958 ); 1959 1959 $args = wp_parse_args( $args, $defaults ); 1960 1960 -
src/bp-templates/bp-legacy/buddypress-functions.php
-- 1.9.3 From a8b48961249f8d0eb760ccd29d9d7d84b77317c2 Mon Sep 17 00:00:00 2001 From: Paul Gibbs <paul@byotos.com> Date: Sun, 22 Jun 2014 13:46:40 +0100 Subject: [PATCH 23/35] Re-implement autosuggest for Messages --- .../bp-legacy/buddypress-functions.php | 78 ++++++---------------- 1 file changed, 21 insertions(+), 57 deletions(-) diff --git a/src/bp-templates/bp-legacy/buddypress-functions.php b/src/bp-templates/bp-legacy/buddypress-functions.php index 784b2dc..455b60e 100644
a b function bp_legacy_theme_ajax_messages_delete() { 1383 1383 * @return string HTML. 1384 1384 */ 1385 1385 function bp_legacy_theme_ajax_messages_autocomplete_results() { 1386 1386 $limit = isset( $_GET['limit'] ) ? absint( $_GET['limit'] ) : (int) apply_filters( 'bp_autocomplete_max_results', 10 ); 1387 $term = isset( $_GET['q'] ) ? sanitize_text_field( $_GET['q'] ) : ''; 1388 1387 1389 // Include everyone in the autocomplete, or just friends? 1388 if ( bp_is_current_component( bp_get_messages_slug() ) ) 1389 $autocomplete_all = buddypress()->messages->autocomplete_all; 1390 1391 $pag_page = 1; 1392 $limit = (int) $_GET['limit'] ? $_GET['limit'] : apply_filters( 'bp_autocomplete_max_results', 10 ); 1393 $search_terms = isset( $_GET['q'] ) ? $_GET['q'] : ''; 1394 1395 $user_query_args = array( 1396 'search_terms' => $search_terms, 1397 'page' => intval( $pag_page ), 1398 'per_page' => intval( $limit ), 1399 ); 1400 1401 // If only matching against friends, get an $include param for 1402 // BP_User_Query 1403 if ( ! $autocomplete_all && bp_is_active( 'friends' ) ) { 1404 $include = BP_Friends_Friendship::get_friend_user_ids( bp_loggedin_user_id() ); 1405 1406 // Ensure zero matches if no friends are found 1407 if ( empty( $include ) ) { 1408 $include = array( 0 ); 1409 } 1410 1411 $user_query_args['include'] = $include; 1390 if ( bp_is_current_component( bp_get_messages_slug() ) ) { 1391 $only_friends = ( buddypress()->messages->autocomplete_all === false ); 1392 } else { 1393 $only_friends = true; 1412 1394 } 1413 1395 1414 $user_query = new BP_User_Query( $user_query_args ); 1415 1416 // Backward compatibility - if a plugin is expecting a legacy 1417 // filter, pass the IDs through the filter and requery (groan) 1418 if ( has_filter( 'bp_core_autocomplete_ids' ) || has_filter( 'bp_friends_autocomplete_ids' ) ) { 1419 $found_user_ids = wp_list_pluck( $user_query->results, 'ID' ); 1420 1421 if ( $autocomplete_all ) { 1422 $found_user_ids = apply_filters( 'bp_core_autocomplete_ids', $found_user_ids ); 1423 } else { 1424 $found_user_ids = apply_filters( 'bp_friends_autocomplete_ids', $found_user_ids ); 1425 } 1426 1427 if ( empty( $found_user_ids ) ) { 1428 $found_user_ids = array( 0 ); 1429 } 1430 1431 // Repopulate the $user_query variable 1432 $user_query = new BP_User_Query( array( 1433 'include' => $found_user_ids, 1434 ) ); 1435 } 1396 $suggestions = bp_core_get_suggestions( array( 1397 'limit' => $limit, 1398 'only_friends' => $only_friends, 1399 'term' => $term, 1400 'type' => 'members', 1401 ) ); 1436 1402 1437 if ( ! empty( $user_query->results ) ) { 1438 foreach ( $user_query->results as $user ) { 1439 if ( bp_is_username_compatibility_mode() ) { 1440 // Sanitize for spaces. Use urlencode() rather 1441 // than rawurlencode() because %20 breaks JS 1442 $username = urlencode( $user->user_login ); 1443 } else { 1444 $username = $user->user_nicename; 1445 } 1403 if ( $suggestions && ! is_wp_error( $suggestions ) ) { 1404 foreach ( $suggestions as $user ) { 1446 1405 1447 1406 // Note that the final line break acts as a delimiter for the 1448 1407 // autocomplete javascript and thus should not be removed 1449 echo '<span id="link-' . esc_attr( $username ) . '" href="' . bp_core_get_user_domain( $user->ID ) . '"></span>' . bp_core_fetch_avatar( array( 'item_id' => $user->ID, 'type' => 'thumb', 'width' => 15, 'height' => 15, 'alt' => $user->display_name ) ) . ' ' . bp_core_get_user_displayname( $user->ID ) . ' (' . esc_html( $username ) . ')' . "\n"; 1408 printf( '<span id="%s" href="#"></span><img src="%s" style="width: 15px"> %s (%s)' . "\n", 1409 esc_attr( 'link-' . $user->ID ), 1410 esc_url( $user->image ), 1411 esc_html( $user->name ), 1412 esc_html( $user->ID ) 1413 ); 1450 1414 } 1451 1415 } 1452 1416 -
tests/phpunit/testcases/apis/suggestions.php
-- 1.9.3 From bc1e065ec696b65e84d447acdf3ff5a0cb30ddf8 Mon Sep 17 00:00:00 2001 From: Paul Gibbs <paul@byotos.com> Date: Sun, 22 Jun 2014 17:32:00 +0100 Subject: [PATCH 24/35] Fix typo in test description --- tests/phpunit/testcases/apis/suggestions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/testcases/apis/suggestions.php b/tests/phpunit/testcases/apis/suggestions.php index 381c98e..2facd6c 100644
a b public function test_suggestions_with_type_groupmembers_and_bad_group_ids() { 360 360 ) ); 361 361 $this->assertTrue( is_wp_error( $suggestions ) ); 362 362 363 // group_ids can alsobe a group slug.363 // group_ids can't be a group slug. 364 364 $suggestions = bp_core_get_suggestions( array( 365 365 'group_id' => 'fake-group-slug', 366 366 'type' => 'members', -
src/bp-groups/bp-groups-admin.php
-- 1.9.3 From 389540f1d8a2c56a22905fcd425e98afbad46a1d Mon Sep 17 00:00:00 2001 From: Paul Gibbs <paul@byotos.com> Date: Sun, 22 Jun 2014 17:44:08 +0100 Subject: [PATCH 25/35] Re-implement autosuggest for group wp-admin. First pass. Suggestions API still needs updates to make this work as expected. --- src/bp-groups/bp-groups-admin.php | 49 +++++++++++++--------------- tests/phpunit/testcases/apis/suggestions.php | 7 ---- 2 files changed, 23 insertions(+), 33 deletions(-) diff --git a/src/bp-groups/bp-groups-admin.php b/src/bp-groups/bp-groups-admin.php index 46e6a94..899b41f 100644
a b function bp_groups_admin_get_usernames_from_ids( $user_ids = array() ) { 984 984 function bp_groups_admin_autocomplete_handler() { 985 985 986 986 // Bail if user user shouldn't be here, or is a large network 987 if ( ! current_user_can( 'bp_moderate' ) || ( is_multisite() && wp_is_large_network( 'users' ) ) ) 987 if ( ! current_user_can( 'bp_moderate' ) || ( is_multisite() && wp_is_large_network( 'users' ) ) ) { 988 988 wp_die( -1 ); 989 } 990 991 $term = isset( $_GET['term'] ) ? sanitize_text_field( $_GET['term'] ) : ''; 992 $group_id = isset( $_GET['group_id'] ) ? absint( $_GET['group_id'] ) : 0; 989 993 990 $return = array(); 994 if ( ! $term || ! $group_id ) { 995 wp_die( -1 ); 996 } 991 997 992 // Exclude current group members 993 $group_id = isset( $_GET['group_id'] ) ? wp_parse_id_list( $_GET['group_id'] ) : array(); 994 $group_member_query = new BP_Group_Member_Query( array( 995 'group_id' => $group_id, 996 'per_page' => 0, // show all 997 'group_role' => array( 'member', 'mod', 'admin', ), 998 'populate_extras' => false, 999 'count_total' => false, 998 $suggestions = bp_core_get_suggestions( array( 999 'group_id' => -$group_id, // A negative value will exclude this group's members from the suggestions. 1000 'limit' => 10, 1001 'term' => $term, 1002 'type' => 'members', 1000 1003 ) ); 1001 1004 1002 $ group_members = ! empty( $group_member_query->results ) ? wp_list_pluck( $group_member_query->results, 'ID' ) :array();1005 $matches = array(); 1003 1006 1004 $terms = isset( $_GET['term'] ) ? $_GET['term'] : ''; 1005 $users = bp_core_get_users( array( 1006 'type' => 'alphabetical', 1007 'search_terms' => $terms, 1008 'exclude' => $group_members, 1009 'per_page' => 10, 1010 'populate_extras' => false 1011 ) ); 1007 if ( $suggestions && ! is_wp_error( $suggestions ) ) { 1008 foreach ( $suggestions as $user ) { 1012 1009 1013 foreach ( (array) $users['users'] as $user ) {1014 $return[] = array(1015 /* translators: 1: user_login, 2: user_email */1016 'label' => sprintf( __( '%1$s (%2$s)', 'buddypress' ), bp_is_username_compatibility_mode() ? $user->user_login : $user->user_nicename, $user->user_email ),1017 'value' => $user->user_nicename,1018 );1010 $matches[] = array( 1011 // translators: 1: user_login, 2: user_email 1012 'label' => sprintf( __( '%1$s (%2$s)', 'buddypress' ), $user->name, $user->ID ), 1013 'value' => $user->ID, 1014 ); 1015 } 1019 1016 } 1020 1017 1021 wp_die( json_encode( $ return) );1018 wp_die( json_encode( $matches ) ); 1022 1019 } 1023 1020 add_action( 'wp_ajax_bp_group_admin_member_autocomplete', 'bp_groups_admin_autocomplete_handler' ); 1024 1021 -
tests/phpunit/testcases/apis/suggestions.php
diff --git a/tests/phpunit/testcases/apis/suggestions.php b/tests/phpunit/testcases/apis/suggestions.php index 2facd6c..c4b845c 100644
a b public function test_suggestions_with_bad_type() { 353 353 } 354 354 355 355 public function test_suggestions_with_type_groupmembers_and_bad_group_ids() { 356 // group_ids must be a positive integer.357 $suggestions = bp_core_get_suggestions( array(358 'group_id' => -12,359 'type' => 'members',360 ) );361 $this->assertTrue( is_wp_error( $suggestions ) );362 363 356 // group_ids can't be a group slug. 364 357 $suggestions = bp_core_get_suggestions( array( 365 358 'group_id' => 'fake-group-slug', -
src/bp-groups/bp-groups-functions.php
-- 1.9.3 From 8be8f55862e11f7da3d13451d390d65c622f01de Mon Sep 17 00:00:00 2001 From: Paul Gibbs <paul@byotos.com> Date: Sun, 22 Jun 2014 18:45:19 +0100 Subject: [PATCH 26/35] API tweaks to fix group wp-admin suggestions. --- src/bp-groups/bp-groups-functions.php | 17 +++++++++++++---- src/bp-members/bp-members-functions.php | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/bp-groups/bp-groups-functions.php b/src/bp-groups/bp-groups-functions.php index a1b27df..15f78bf 100644
a b function groups_remove_data_for_user( $user_id ) { 1166 1166 * @since BuddyPress (2.1.0) 1167 1167 */ 1168 1168 function bp_groups_suggestions_filter_query_args( $query_args, $suggestion_args ) { 1169 if ( ! $suggestion_args['group_id'] ) {1169 if ( ! (int) $suggestion_args['group_id'] ) { 1170 1170 return $query_args; 1171 1171 } 1172 1172 1173 // Positive integers will restrict the search to members in that group. 1174 // Negative integers will restrict the search to members in every other group. 1175 $suggestion_args['group_id'] = (int) $suggestion_args['group_id']; 1176 1173 1177 $the_group = groups_get_group( array( 1174 'group_id' => $suggestion_args['group_id'],1178 'group_id' => absint( $suggestion_args['group_id'] ), 1175 1179 'populate_extras' => true, 1176 1180 ) ); 1177 1181 … … function bp_groups_suggestions_filter_query_args( $query_args, $suggestion_args 1184 1188 'populate_extras' => false, 1185 1189 'type' => 'alphabetical', 1186 1190 1187 'group_id' => $suggestion_args['group_id'],1191 'group_id' => absint( $suggestion_args['group_id'] ), 1188 1192 ); 1189 1193 1190 1194 $group_users = new BP_Group_Member_Query( $group_query ); 1191 1195 if ( $group_users->results ) { 1192 $query_args['include'] = wp_list_pluck( $group_users->results, 'ID' ); 1196 if ( $suggestion_args['group_id'] > 0 ) { 1197 $query_args['include'] = wp_list_pluck( $group_users->results, 'ID' ); 1198 } else { 1199 $query_args['exclude'] = wp_list_pluck( $group_users->results, 'ID' ); 1200 } 1201 1193 1202 } else { 1194 1203 $query_args['include'] = array( 0 ); 1195 1204 } -
src/bp-members/bp-members-functions.php
diff --git a/src/bp-members/bp-members-functions.php b/src/bp-members/bp-members-functions.php index 45c9377..cccae3c 100644
a b function bp_members_get_suggestions( $args ) { 2111 2111 'term' => '', // Sanitised upstream 2112 2112 ); 2113 2113 $args = apply_filters( 'bp_members_get_suggestions_args', wp_parse_args( $args, $defaults ) ); 2114 $args['group_id'] = absint( $args['group_id'] );2114 $args['group_id'] = (int) $args['group_id']; 2115 2115 $args['only_friends'] = (bool) $args['only_friends']; 2116 2116 2117 2117 -
tests/phpunit/testcases/apis/suggestions.php
-- 1.9.3 From 96541bd37c69b7213c001ab5d7fc55f14977075b Mon Sep 17 00:00:00 2001 From: Paul Gibbs <paul@byotos.com> Date: Sun, 22 Jun 2014 19:03:57 +0100 Subject: [PATCH 27/35] Minor whitespace tweaks --- tests/phpunit/testcases/apis/suggestions.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/testcases/apis/suggestions.php b/tests/phpunit/testcases/apis/suggestions.php index c4b845c..651cfba 100644
a b public function test_suggestions_with_type_groupmembers_hidden() { 238 238 } 239 239 240 240 public function test_suggestions_with_type_groupmembers_private() { 241 // current_user isn't a member of the private group 241 // current_user isn't a member of the private group. 242 242 $suggestions = bp_core_get_suggestions( array( 243 243 'group_id' => $this->group_ids['private'], 244 244 'type' => 'members', … … public function test_suggestions_with_type_groupmembers_and_bad_group_ids() { 358 358 'group_id' => 'fake-group-slug', 359 359 'type' => 'members', 360 360 ) ); 361 361 362 $this->assertTrue( is_wp_error( $suggestions ) ); 362 363 } 363 364 -
tests/phpunit/testcases/apis/suggestions.php
-- 1.9.3 From 9434ddc992cb554a98d3220e1812ff72d5047a36 Mon Sep 17 00:00:00 2001 From: Paul Gibbs <paul@byotos.com> Date: Sun, 22 Jun 2014 19:17:49 +0100 Subject: [PATCH 28/35] Tests for group wp-admin auto-suggest --- tests/phpunit/testcases/apis/suggestions.php | 78 ++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/tests/phpunit/testcases/apis/suggestions.php b/tests/phpunit/testcases/apis/suggestions.php index 651cfba..7bfc961 100644
a b public function setUp() { 80 80 // Add dummy users to dummy public groups. 81 81 groups_join_group( $this->group_ids['public'], $this->current_user ); 82 82 groups_join_group( $this->group_ids['public'], $this->user_ids['aardvark'] ); 83 groups_join_group( $this->group_ids['public'], $this->user_ids['alpaca red'] ); 84 groups_join_group( $this->group_ids['public'], $this->user_ids['cat'] ); 83 85 groups_join_group( $this->group_ids['public'], $this->user_ids['smith'] ); 84 86 85 87 // Add dummy users to dummy private groups. … … public function test_suggestions_with_type_groupmembers_private() { 257 259 } 258 260 259 261 262 public function test_suggestions_with_type_groupmembers_public_and_exclude_group_from_results() { 263 $suggestions = bp_core_get_suggestions( array( 264 'group_id' => $this->group_ids['public'], 265 'type' => 'members', 266 'term' => 'smith', 267 ) ); 268 $this->assertEquals( 2, count( $suggestions ) ); // aardvark, smith. 269 270 $suggestions = bp_core_get_suggestions( array( 271 'group_id' => -$this->group_ids['public'], 272 'type' => 'members', 273 'term' => 'smith', 274 ) ); 275 $this->assertEquals( 1, count( $suggestions ) ); // zoom 276 } 277 278 public function test_suggestions_with_type_groupmembers_private_and_exclude_group_from_results() { 279 // current_user isn't a member of the private group. 280 $suggestions = bp_core_get_suggestions( array( 281 'group_id' => -$this->group_ids['private'], 282 'type' => 'members', 283 'term' => 'cat', 284 ) ); 285 $this->assertTrue( is_wp_error( $suggestions ) ); 286 287 288 $this->set_current_user( $this->user_ids['caterpillar'] ); 289 290 // "cat" is in the private group, so won't show up here. 291 $suggestions = bp_core_get_suggestions( array( 292 'group_id' => -$this->group_ids['private'], 293 'type' => 'members', 294 'term' => 'cat', 295 ) ); 296 $this->assertEmpty( $suggestions ); 297 298 // "zoo" is not the private group, so will show up here. 299 $suggestions = bp_core_get_suggestions( array( 300 'group_id' => -$this->group_ids['private'], 301 'type' => 'members', 302 'term' => 'zoo', 303 ) ); 304 $this->assertEquals( 1, count( $suggestions ) ); // zoo 305 } 306 307 public function test_suggestions_with_type_groupmembers_hidden_and_exclude_group_from_results() { 308 // current_user isn't a member of the hidden group. 309 $suggestions = bp_core_get_suggestions( array( 310 'group_id' => $this->group_ids['hidden'], 311 'type' => 'members', 312 'term' => 'pig', 313 ) ); 314 $this->assertTrue( is_wp_error( $suggestions ) ); 315 316 317 $this->set_current_user( $this->user_ids['alpaca red'] ); 318 319 // "alpaca red" is in the hidden group, so won't show up here. 320 $suggestions = bp_core_get_suggestions( array( 321 'group_id' => -$this->group_ids['hidden'], 322 'type' => 'members', 323 'term' => 'alpaca red', 324 ) ); 325 $this->assertEmpty( $suggestions ); 326 327 // "zoo" is not the hidden group, so will show up here. 328 $suggestions = bp_core_get_suggestions( array( 329 'group_id' => -$this->group_ids['hidden'], 330 'type' => 'members', 331 'term' => 'zoo', 332 ) ); 333 die(var_dump('too many', $suggestions)); 334 $this->assertEquals( 1, count( $suggestions ) ); // zoo 335 } 336 337 260 338 /** 261 339 * These next tests check the format of the response from the Suggestions API. 262 340 */ -
tests/phpunit/testcases/apis/suggestions.php
-- 1.9.3 From 726128795a67253052ce28836c79ce4586ce0c63 Mon Sep 17 00:00:00 2001 From: Paul Gibbs <paul@byotos.com> Date: Sun, 22 Jun 2014 19:22:30 +0100 Subject: [PATCH 29/35] Remove debug --- tests/phpunit/testcases/apis/suggestions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/testcases/apis/suggestions.php b/tests/phpunit/testcases/apis/suggestions.php index 7bfc961..974b79a 100644
a b public function test_suggestions_with_type_groupmembers_hidden_and_exclude_group 330 330 'type' => 'members', 331 331 'term' => 'zoo', 332 332 ) ); 333 die(var_dump('too many', $suggestions));333 $this->assertFalse( is_wp_error( $suggestions ) ); 334 334 $this->assertEquals( 1, count( $suggestions ) ); // zoo 335 335 } 336 336 -
tests/phpunit/testcases/apis/suggestions-nonauth.php
-- 1.9.3 From 084653598ae4b600efffc65ed815e189513ed25e Mon Sep 17 00:00:00 2001 From: Paul Gibbs <paul@byotos.com> Date: Sun, 22 Jun 2014 19:23:09 +0100 Subject: [PATCH 30/35] Suggestions tests: sync group members to non-auth tests --- tests/phpunit/testcases/apis/suggestions-nonauth.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/phpunit/testcases/apis/suggestions-nonauth.php b/tests/phpunit/testcases/apis/suggestions-nonauth.php index 85f9d10..4f7366b 100644
a b public function setUp() { 62 62 groups_join_group( $this->group_ids['hidden'], $this->user_ids['alpaca red'] ); 63 63 64 64 // Add dummy users to dummy public groups. 65 groups_join_group( $this->group_ids['public'], $this->current_user ); 65 66 groups_join_group( $this->group_ids['public'], $this->user_ids['aardvark'] ); 67 groups_join_group( $this->group_ids['public'], $this->user_ids['alpaca red'] ); 68 groups_join_group( $this->group_ids['public'], $this->user_ids['cat'] ); 66 69 groups_join_group( $this->group_ids['public'], $this->user_ids['smith'] ); 67 70 68 71 // Add dummy users to dummy private groups. -
tests/phpunit/testcases/apis/suggestions.php
-- 1.9.3 From e01ab4f108f46c41569db673476dc600c2d923a2 Mon Sep 17 00:00:00 2001 From: Paul Gibbs <paul@byotos.com> Date: Sun, 22 Jun 2014 19:24:52 +0100 Subject: [PATCH 31/35] Suggestions tests: count() can lie MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit count() on a WP_Error object can return 1. This is making some tests pass accidentally. Check `is_wp_error` for each test just to be very sure we don’t let anything similar through in future. --- tests/phpunit/testcases/apis/suggestions.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/phpunit/testcases/apis/suggestions.php b/tests/phpunit/testcases/apis/suggestions.php index 974b79a..dbc82fd 100644
a b public function test_suggestions_with_type_members() { 101 101 'term' => 'smith', 102 102 ) ); 103 103 104 $this->assertFalse( is_wp_error( $suggestions ) ); 104 105 $this->assertEquals( 3, count( $suggestions ) ); // aardvark, smith, zoom. 105 106 } 106 107 … … public function test_suggestions_with_type_members_and_limit() { 111 112 'term' => 'smith', 112 113 ) ); 113 114 115 $this->assertFalse( is_wp_error( $suggestions ) ); 114 116 $this->assertEquals( 2, count( $suggestions ) ); // two of: aardvark, smith, zoom. 115 117 } 116 118 … … public function test_suggestions_with_type_members_and_only_friends() { 120 122 'type' => 'members', 121 123 'term' => 'smith', 122 124 ) ); 125 $this->assertFalse( is_wp_error( $suggestions ) ); 123 126 $this->assertEquals( 1, count( $suggestions ) ); // aardvark. 124 127 125 128 $suggestions = bp_core_get_suggestions( array( … … public function test_suggestions_with_type_members_and_only_friends() { 127 130 'type' => 'members', 128 131 'term' => 'cat', 129 132 ) ); 133 $this->assertFalse( is_wp_error( $suggestions ) ); 130 134 $this->assertEquals( 2, count( $suggestions ) ); // cat, caterpillar. 131 135 } 132 136 … … public function test_suggestions_with_type_members_and_term_as_displayname() { 136 140 'term' => 'aardvark', 137 141 ) ); 138 142 143 $this->assertFalse( is_wp_error( $suggestions ) ); 139 144 $this->assertEquals( 1, count( $suggestions ) ); // aardvark. 140 145 } 141 146 … … public function test_suggestions_with_type_members_and_term_as_usernicename() { 145 150 'term' => 'eleanor', 146 151 ) ); 147 152 153 $this->assertFalse( is_wp_error( $suggestions ) ); 148 154 $this->assertEquals( 1, count( $suggestions ) ); // snake. 149 155 } 150 156 … … public function test_suggestions_with_term_as_current_user() { 153 159 'type' => 'members', 154 160 'term' => 'katie', 155 161 ) ); 162 163 $this->assertFalse( is_wp_error( $suggestions ) ); 156 164 $this->assertEquals( 1, count( $suggestions ) ); 157 165 $this->assertSame( 'admin', $suggestions[0]->ID ); 158 166 } … … public function test_suggestions_with_type_groupmembers_public() { 165 173 'term' => 'smith', 166 174 ) ); 167 175 176 $this->assertFalse( is_wp_error( $suggestions ) ); 168 177 $this->assertEquals( 2, count( $suggestions ) ); // aardvark, smith. 169 178 } 170 179 … … public function test_suggestions_with_type_groupmembers_public_and_limit() { 176 185 'term' => 'smith', 177 186 ) ); 178 187 188 $this->assertFalse( is_wp_error( $suggestions ) ); 179 189 $this->assertEquals( 1, count( $suggestions ) ); // one of: aardvark, smith. 180 190 } 181 191 … … public function test_suggestions_with_type_groupmembers_public_and_only_friends( 187 197 'term' => 'smith', 188 198 ) ); 189 199 200 $this->assertFalse( is_wp_error( $suggestions ) ); 190 201 $this->assertEquals( 1, count( $suggestions ) ); // aardvark. 191 202 } 192 203 … … public function test_suggestions_with_type_groupmembers_public_and_term_as_displ 197 208 'term' => 'aardvark', 198 209 ) ); 199 210 211 $this->assertFalse( is_wp_error( $suggestions ) ); 200 212 $this->assertEquals( 1, count( $suggestions ) ); // aardvark. 201 213 } 202 214 … … public function test_suggestions_with_type_groupmembers_public_and_term_as_usern 207 219 'term' => 'robert', 208 220 ) ); 209 221 222 $this->assertFalse( is_wp_error( $suggestions ) ); 210 223 $this->assertEquals( 1, count( $suggestions ) ); // smith. 211 224 } 212 225 … … public function test_suggestions_with_type_groupmembers_public_as_id() { 217 230 'term' => 'smith', 218 231 ) ); 219 232 233 $this->assertFalse( is_wp_error( $suggestions ) ); 220 234 $this->assertEquals( 2, count( $suggestions ) ); // aardvark, smith. 221 235 } 222 236 … … public function test_suggestions_with_type_groupmembers_hidden() { 236 250 'type' => 'members', 237 251 'term' => 'pig', 238 252 ) ); 253 $this->assertFalse( is_wp_error( $suggestions ) ); 239 254 $this->assertEquals( 1, count( $suggestions ) ); // pig 240 255 } 241 256 … … public function test_suggestions_with_type_groupmembers_private() { 255 270 'type' => 'members', 256 271 'term' => 'cat', 257 272 ) ); 273 $this->assertFalse( is_wp_error( $suggestions ) ); 258 274 $this->assertEquals( 2, count( $suggestions ) ); // cat, caterpillar 259 275 } 260 276 … … public function test_suggestions_with_type_groupmembers_public_and_exclude_group 265 281 'type' => 'members', 266 282 'term' => 'smith', 267 283 ) ); 284 $this->assertFalse( is_wp_error( $suggestions ) ); 268 285 $this->assertEquals( 2, count( $suggestions ) ); // aardvark, smith. 269 286 270 287 $suggestions = bp_core_get_suggestions( array( … … public function test_suggestions_with_type_groupmembers_public_and_exclude_group 272 289 'type' => 'members', 273 290 'term' => 'smith', 274 291 ) ); 292 $this->assertFalse( is_wp_error( $suggestions ) ); 275 293 $this->assertEquals( 1, count( $suggestions ) ); // zoom 276 294 } 277 295 … … public function test_suggestions_with_type_groupmembers_private_and_exclude_grou 293 311 'type' => 'members', 294 312 'term' => 'cat', 295 313 ) ); 314 $this->assertFalse( is_wp_error( $suggestions ) ); 296 315 $this->assertEmpty( $suggestions ); 297 316 298 317 // "zoo" is not the private group, so will show up here. … … public function test_suggestions_with_type_groupmembers_private_and_exclude_grou 301 320 'type' => 'members', 302 321 'term' => 'zoo', 303 322 ) ); 323 $this->assertFalse( is_wp_error( $suggestions ) ); 304 324 $this->assertEquals( 1, count( $suggestions ) ); // zoo 305 325 } 306 326 … … public function test_suggestions_with_type_groupmembers_hidden_and_exclude_group 322 342 'type' => 'members', 323 343 'term' => 'alpaca red', 324 344 ) ); 345 $this->assertFalse( is_wp_error( $suggestions ) ); 325 346 $this->assertEmpty( $suggestions ); 326 347 327 348 // "zoo" is not the hidden group, so will show up here. … … public function test_suggestions_response_no_matches() { 345 366 'type' => 'members', 346 367 ) ); 347 368 369 $this->assertFalse( is_wp_error( $suggestions ) ); 348 370 $this->assertInternalType( 'array', $suggestions ); 349 371 $this->assertEmpty( $suggestions ); 350 372 } … … public function test_suggestions_response_single_match() { 355 377 'type' => 'members', 356 378 ) ); 357 379 380 $this->assertFalse( is_wp_error( $suggestions ) ); 358 381 $this->assertInternalType( 'array', $suggestion ); 359 382 $this->assertNotEmpty( $suggestion ); 360 383 … … public function test_suggestions_response_multiple_matches() { 372 395 'type' => 'members', 373 396 ) ); 374 397 398 $this->assertFalse( is_wp_error( $suggestions ) ); 375 399 $this->assertInternalType( 'array', $suggestions ); 376 400 $this->assertNotEmpty( $suggestions ); 377 401 … … public function test_suggestions_term_is_case_insensitive() { 388 412 'term' => 'lisa', 389 413 'type' => 'members', 390 414 ) ); 415 $this->assertFalse( is_wp_error( $suggestions ) ); 391 416 $this->assertEquals( 1, count( $lowercase ) ); 392 417 393 418 $uppercase = bp_core_get_suggestions( array( 394 419 'term' => 'LISA', 395 420 'type' => 'members', 396 421 ) ); 422 $this->assertFalse( is_wp_error( $suggestions ) ); 397 423 $this->assertEquals( 1, count( $uppercase ) ); 398 424 399 425 $this->assertSame( $lowercase[0]->ID, $uppercase[0]->ID ); … … public function test_suggestions_response_property_types() { 406 432 'type' => 'members', 407 433 ) ); 408 434 435 $this->assertFalse( is_wp_error( $suggestions ) ); 409 436 $this->assertInternalType( 'array', $suggestion ); 410 437 $this->assertNotEmpty( $suggestion ); 411 438 -
tests/phpunit/testcases/apis/suggestions-nonauth.php
-- 1.9.3 From cbaf3a8a2c972bd01d2e6747f7a53ccf67d02c1d Mon Sep 17 00:00:00 2001 From: Paul Gibbs <paul@byotos.com> Date: Sun, 22 Jun 2014 19:29:17 +0100 Subject: [PATCH 32/35] Remove copypasta from 0846535 --- tests/phpunit/testcases/apis/suggestions-nonauth.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/phpunit/testcases/apis/suggestions-nonauth.php b/tests/phpunit/testcases/apis/suggestions-nonauth.php index 4f7366b..f953264 100644
a b public function setUp() { 62 62 groups_join_group( $this->group_ids['hidden'], $this->user_ids['alpaca red'] ); 63 63 64 64 // Add dummy users to dummy public groups. 65 groups_join_group( $this->group_ids['public'], $this->current_user );66 65 groups_join_group( $this->group_ids['public'], $this->user_ids['aardvark'] ); 67 66 groups_join_group( $this->group_ids['public'], $this->user_ids['alpaca red'] ); 68 67 groups_join_group( $this->group_ids['public'], $this->user_ids['cat'] ); -
tests/phpunit/testcases/apis/suggestions.php
-- 1.9.3 From e0699342f99508312b8612637ef9009444bca646 Mon Sep 17 00:00:00 2001 From: Paul Gibbs <paul@byotos.com> Date: Sun, 22 Jun 2014 19:32:47 +0100 Subject: [PATCH 33/35] More copypasta --- tests/phpunit/testcases/apis/suggestions.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/phpunit/testcases/apis/suggestions.php b/tests/phpunit/testcases/apis/suggestions.php index dbc82fd..c551a33 100644
a b public function test_suggestions_response_single_match() { 377 377 'type' => 'members', 378 378 ) ); 379 379 380 $this->assertFalse( is_wp_error( $suggestion s) );380 $this->assertFalse( is_wp_error( $suggestion ) ); 381 381 $this->assertInternalType( 'array', $suggestion ); 382 382 $this->assertNotEmpty( $suggestion ); 383 383 … … public function test_suggestions_term_is_case_insensitive() { 412 412 'term' => 'lisa', 413 413 'type' => 'members', 414 414 ) ); 415 $this->assertFalse( is_wp_error( $ suggestions) );415 $this->assertFalse( is_wp_error( $lowercase ) ); 416 416 $this->assertEquals( 1, count( $lowercase ) ); 417 417 418 418 $uppercase = bp_core_get_suggestions( array( 419 419 'term' => 'LISA', 420 420 'type' => 'members', 421 421 ) ); 422 $this->assertFalse( is_wp_error( $ suggestions) );422 $this->assertFalse( is_wp_error( $uppercase ) ); 423 423 $this->assertEquals( 1, count( $uppercase ) ); 424 424 425 425 $this->assertSame( $lowercase[0]->ID, $uppercase[0]->ID ); … … public function test_suggestions_response_property_types() { 432 432 'type' => 'members', 433 433 ) ); 434 434 435 $this->assertFalse( is_wp_error( $suggestion s) );435 $this->assertFalse( is_wp_error( $suggestion ) ); 436 436 $this->assertInternalType( 'array', $suggestion ); 437 437 $this->assertNotEmpty( $suggestion ); 438 438 -
tests/phpunit/testcases/apis/suggestions-nonauth.php
-- 1.9.3 From 12995d9a257a9a5fd43b65ae23bd8c725586b636 Mon Sep 17 00:00:00 2001 From: Paul Gibbs <paul@byotos.com> Date: Sun, 22 Jun 2014 19:43:17 +0100 Subject: [PATCH 34/35] Suggestions: grp members exclude test for non-auth --- .../phpunit/testcases/apis/suggestions-nonauth.php | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/phpunit/testcases/apis/suggestions-nonauth.php b/tests/phpunit/testcases/apis/suggestions-nonauth.php index f953264..a16fb8e 100644
a b public function test_suggestions_with_type_groupmembers_private() { 119 119 120 120 $this->assertTrue( is_wp_error( $suggestions ) ); 121 121 } 122 123 public function test_suggestions_with_type_groupmembers_public_and_exclude_group_from_results() { 124 $suggestions = bp_core_get_suggestions( array( 125 'group_id' => $this->group_ids['public'], 126 'type' => 'members', 127 'term' => 'smith', 128 ) ); 129 $this->assertFalse( is_wp_error( $suggestions ) ); 130 $this->assertEquals( 2, count( $suggestions ) ); // aardvark, smith. 131 132 $suggestions = bp_core_get_suggestions( array( 133 'group_id' => -$this->group_ids['public'], 134 'type' => 'members', 135 'term' => 'smith', 136 ) ); 137 $this->assertFalse( is_wp_error( $suggestions ) ); 138 $this->assertEquals( 1, count( $suggestions ) ); // zoom 139 } 140 141 public function test_suggestions_with_type_groupmembers_private_and_exclude_group_from_results() { 142 $suggestions = bp_core_get_suggestions( array( 143 'group_id' => -$this->group_ids['private'], 144 'type' => 'members', 145 'term' => 'cat', 146 ) ); 147 $this->assertTrue( is_wp_error( $suggestions ) ); // no access to group. 148 } 149 150 public function test_suggestions_with_type_groupmembers_hidden_and_exclude_group_from_results() { 151 $suggestions = bp_core_get_suggestions( array( 152 'group_id' => $this->group_ids['hidden'], 153 'type' => 'members', 154 'term' => 'pig', 155 ) ); 156 $this->assertTrue( is_wp_error( $suggestions ) ); // no access to group. 157 } 122 158 } 159 No newline at end of file -
src/bp-groups/bp-groups-functions.php
-- 1.9.3 From 7813626a7a28bcfd1208bc5968587ec26089068b Mon Sep 17 00:00:00 2001 From: Paul Gibbs <paul@byotos.com> Date: Sun, 22 Jun 2014 20:08:04 +0100 Subject: [PATCH 35/35] Suggestions: group member queries need roles set --- src/bp-groups/bp-groups-functions.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bp-groups/bp-groups-functions.php b/src/bp-groups/bp-groups-functions.php index 15f78bf..a9edf9b 100644
a b function bp_groups_suggestions_filter_query_args( $query_args, $suggestion_args 1188 1188 'populate_extras' => false, 1189 1189 'type' => 'alphabetical', 1190 1190 1191 'page' => 1, 1191 1192 'group_id' => absint( $suggestion_args['group_id'] ), 1193 'group_role' => array( 'admin', 'member', 'mod' ), 1192 1194 ); 1193 1195 1194 1196 $group_users = new BP_Group_Member_Query( $group_query );