Ticket #3797: 3797.core-members-template.2.diff
File 3797.core-members-template.2.diff, 8.3 KB (added by , 6 years ago) |
---|
-
src/bp-members/bp-members-template.php
diff --git src/bp-members/bp-members-template.php src/bp-members/bp-members-template.php index 9797bd5f8..29b1982f3 100644
function bp_has_members( $args = '' ) { 396 396 } 397 397 398 398 // Query for members and populate $members_template global. 399 $members_template = new BP_Core_Members_Template( 400 $r['type'], 401 $r['page'], 402 $r['per_page'], 403 $r['max'], 404 $r['user_id'], 405 $r['search_terms'], 406 $r['include'], 407 $r['populate_extras'], 408 $r['exclude'], 409 $r['meta_key'], 410 $r['meta_value'], 411 $r['page_arg'], 412 $r['member_type'], 413 $r['member_type__in'], 414 $r['member_type__not_in'] 415 ); 399 $members_template = new BP_Core_Members_Template( $r ); 416 400 417 401 /** 418 402 * Filters whether or not BuddyPress has members to iterate over. -
src/bp-members/classes/class-bp-core-members-template.php
diff --git src/bp-members/classes/class-bp-core-members-template.php src/bp-members/classes/class-bp-core-members-template.php index 7512c4442..735664e20 100644
class BP_Core_Members_Template { 113 113 * 114 114 * @see BP_User_Query for an in-depth description of parameters. 115 115 * 116 * @param string $type Sort order. 117 * @param int $page_number Page of results. 118 * @param int $per_page Number of results per page. 119 * @param int $max Max number of results to return. 120 * @param int $user_id Limit to friends of a user. 121 * @param string $search_terms Limit to users matching search terms. 122 * @param array $include Limit results by these user IDs. 123 * @param bool $populate_extras Fetch optional extras. 124 * @param array $exclude Exclude these IDs from results. 125 * @param array $meta_key Limit to users with a meta_key. 126 * @param array $meta_value Limit to users with a meta_value (with meta_key). 127 * @param string $page_arg Optional. The string used as a query parameter in pagination links. 128 * Default: 'upage'. 129 * @param array|string $member_type Array or comma-separated string of member types to limit results to. 130 * @param array|string $member_type__in Array or comma-separated string of member types to limit results to. 131 * @param array|string $member_type__not_in Array or comma-separated string of member types to exclude 132 * from results. 116 * @param array $args { 117 * Array of arguments. Supports all arguments from 118 * BP_User_Query, as well as 'max' and 119 * 'page_arg'. 'page_number' is used as 'page' argument. 120 * @type int $page_number Page of results. 121 * @type string $max Max number of results to return. 122 * @type string $page_arg Optional. The string used as a query parameter in pagination links. 123 * Default: 'upage'. 124 * } 133 125 */ 134 function __construct( $type, $page_number, $per_page, $max, $user_id, $search_terms, $include, $populate_extras, $exclude, $meta_key, $meta_value, $page_arg = 'upage', $member_type = '', $member_type__in = '', $member_type__not_in = '' ) { 126 function __construct( $args ) { 127 // Backward compatibility with old method of passing arguments. 128 if ( ! is_array( $args ) || func_num_args() > 1 ) { 129 _deprecated_argument( __METHOD__, '4.0', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) ); 130 131 $old_args_keys = array( 132 0 => 'type', 133 1 => 'page_number', 134 2 => 'per_page', 135 3 => 'max', 136 4 => 'user_id', 137 5 => 'search_terms', 138 6 => 'include', 139 7 => 'populate_extras', 140 8 => 'exclude', 141 9 => 'meta_key', 142 10 => 'meta_value', 143 11 => 'page_arg', 144 12 => 'member_type', 145 13 => 'member_type__in', 146 14 => 'member_type__not_in' 147 ); 148 149 $args = bp_core_parse_args_array( $old_args_keys, func_get_args() ); 150 } 151 152 // Support both page result arguments for backward compatibility. 153 $args['page_number'] = isset( $args['page_number'] ) ? $args['page_number'] : $args['page']; 154 155 $defaults = array( 156 'type' => 'active', 157 'page_number' => 1, 158 'per_page' => 20, 159 'max' => false, 160 'user_id' => false, 161 'search_terms' => null, 162 'include' => false, 163 'populate_extras' => true, 164 'exclude' => false, 165 'meta_key' => false, 166 'meta_value' => false, 167 'page_arg' => 'upage', 168 'member_type' => '', 169 'member_type__in' => '', 170 'member_type__not_in' => '' 171 ); 172 $r = wp_parse_args( $args, $defaults ); 173 extract( $r ); 135 174 136 175 $this->pag_arg = sanitize_key( $page_arg ); 137 176 $this->pag_page = bp_sanitize_pagination_arg( $this->pag_arg, $page_number ); 138 177 $this->pag_num = bp_sanitize_pagination_arg( 'num', $per_page ); 139 178 $this->type = $type; 140 179 141 if ( !empty( $_REQUEST['letter'] ) ) 180 if ( !empty( $_REQUEST['letter'] ) ) { 142 181 $this->members = BP_Core_User::get_users_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page, $populate_extras, $exclude ); 143 else182 } else { 144 183 $this->members = bp_core_get_users( array( 'type' => $this->type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'include' => $include, 'search_terms' => $search_terms, 'populate_extras' => $populate_extras, 'exclude' => $exclude, 'meta_key' => $meta_key, 'meta_value' => $meta_value, 'member_type' => $member_type, 'member_type__in' => $member_type__in, 'member_type__not_in' => $member_type__not_in ) ); 184 } 145 185 146 if ( !$max || $max >= (int) $this->members['total'] ) 186 if ( !$max || $max >= (int) $this->members['total'] ) { 147 187 $this->total_member_count = (int) $this->members['total']; 148 else188 } else { 149 189 $this->total_member_count = (int) $max; 190 } 150 191 151 192 $this->members = $this->members['users']; 152 193 -
tests/phpunit/testcases/members/template.php
diff --git tests/phpunit/testcases/members/template.php tests/phpunit/testcases/members/template.php index 13c53dccd..faab647c9 100644
class BP_Tests_Members_Template extends BP_UnitTestCase { 255 255 'search_terms' => '' 256 256 ); 257 257 258 $at = new BP_Core_Members_Template( 259 $r['type'], 260 $r['page'], 261 $r['per_page'], 262 $r['max'], 263 $r['user_id'], 264 $r['search_terms'], 265 $r['include'], 266 $r['populate_extras'], 267 $r['exclude'], 268 $r['meta_key'], 269 $r['meta_value'], 270 $r['page_arg'], 271 $r['member_type'] 272 ); 258 $at = new BP_Core_Members_Template( $r ); 273 259 274 260 $this->assertEquals( 5, $at->pag_page ); 275 261 … … class BP_Tests_Members_Template extends BP_UnitTestCase { 301 287 'search_terms' => '' 302 288 ); 303 289 304 $at = new BP_Core_Members_Template( 305 $r['type'], 306 $r['page'], 307 $r['per_page'], 308 $r['max'], 309 $r['user_id'], 310 $r['search_terms'], 311 $r['include'], 312 $r['populate_extras'], 313 $r['exclude'], 314 $r['meta_key'], 315 $r['meta_value'], 316 $r['page_arg'], 317 $r['member_type'] 318 ); 290 $at = new BP_Core_Members_Template( $r ); 319 291 320 292 $this->assertEquals( 8, $at->pag_page ); 321 293 … … class BP_Tests_Members_Template extends BP_UnitTestCase { 347 319 'search_terms' => '' 348 320 ); 349 321 350 $at = new BP_Core_Members_Template( 351 $r['type'], 352 $r['page'], 353 $r['per_page'], 354 $r['max'], 355 $r['user_id'], 356 $r['search_terms'], 357 $r['include'], 358 $r['populate_extras'], 359 $r['exclude'], 360 $r['meta_key'], 361 $r['meta_value'], 362 $r['page_arg'], 363 $r['member_type'] 364 ); 322 $at = new BP_Core_Members_Template( $r ); 365 323 366 324 $this->assertEquals( 14, $at->pag_num ); 367 325 … … class BP_Tests_Members_Template extends BP_UnitTestCase { 393 351 'search_terms' => '' 394 352 ); 395 353 396 $at = new BP_Core_Members_Template( 397 $r['type'], 398 $r['page'], 399 $r['per_page'], 400 $r['max'], 401 $r['user_id'], 402 $r['search_terms'], 403 $r['include'], 404 $r['populate_extras'], 405 $r['exclude'], 406 $r['meta_key'], 407 $r['meta_value'], 408 $r['page_arg'], 409 $r['member_type'] 410 ); 354 $at = new BP_Core_Members_Template( $r ); 411 355 412 356 $this->assertEquals( 13, $at->pag_num ); 413 357