Skip to:
Content

BuddyPress.org

Changeset 7239


Ignore:
Timestamp:
06/25/2013 01:18:24 AM (13 years ago)
Author:
boonebgorges
Message:

Use strict type checking when setting default 'include' value in BP_User_Query

Using the empty() check resulted in problems when empty arrays were passed into
BP_User_Query as the 'include' parameter, such as when querying for a user's
friend requests when the user did not have any - in these cases, all users
ended up being returned.

Fixes #5071

Props imath

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-classes.php

    r7228 r7239  
    316316
    317317                // 'include' - User ids to include in the results
    318                 $include     = ! empty( $include ) ? wp_parse_id_list( $include ) : array();
     318                $include     = false !== $include ? wp_parse_id_list( $include ) : array();
    319319                $include_ids = $this->get_include_ids( $include );
    320320                if ( ! empty( $include_ids ) ) {
  • trunk/tests/testcases/members/template.php

    r7186 r7239  
    6565        }
    6666
     67        /**
     68         * @group bp_has_members
     69         * @group friends
     70         * @ticket BP5071
     71         */
     72        public function test_bp_has_members_friendship_requests_with_no_requests() {
     73                $u1 = $this->create_user();
     74                $u2 = $this->create_user();
     75
     76                $old_user = get_current_user_id();
     77                $this->set_current_user( $u2 );
     78
     79                // For some reason, in all the user switching, the cache gets
     80                // confused. Never comes up when BP runs normally, because the
     81                // loggedin_user doesn't change on a pageload. @todo Fix for
     82                // real in BP
     83                wp_cache_delete( 'bp_user_domain_' . $u2, 'bp' );
     84
     85                $this->go_to( bp_core_get_user_domain( $u2 ) . bp_get_friends_slug() . '/requests/' );
     86                $this->restore_admins();
     87
     88                global $members_template;
     89                bp_has_members( array(
     90                        'include' => bp_get_friendship_requests( $u2 ),
     91                ) );
     92
     93                $requests = is_array( $members_template->members ) ? array_values( $members_template->members ) : array();
     94                $request_ids = wp_list_pluck( $requests, 'ID' );
     95                $this->assertEquals( array(), $request_ids );
     96
     97                $this->set_current_user( $old_user );
     98        }
     99
    67100}
Note: See TracChangeset for help on using the changeset viewer.