Skip to:
Content

BuddyPress.org

Changeset 8173


Ignore:
Timestamp:
03/27/2014 05:37:41 PM (12 years ago)
Author:
boonebgorges
Message:

Fix check for existing friendship in friends_add_friend()

The previous logic would always result in this check failing.

Fixes #5319

Props r-a-y

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-friends/bp-friends-functions.php

    r8172 r8173  
    3737
    3838        // Check if already friends, and bail if so
     39        if ( friends_check_friendship( $initiator_userid, $friend_userid ) ) {
     40                return true;
     41        }
     42
     43        // Setup the friendship data
    3944        $friendship = new BP_Friends_Friendship;
    40         if ( (int) $friendship->is_confirmed ) {
    41                 return true;
    42         }
    43 
    44         // Setup the friendship data
    4545        $friendship->initiator_user_id = $initiator_userid;
    4646        $friendship->friend_user_id    = $friend_userid;
     
    4949        $friendship->date_created      = bp_core_current_time();
    5050
    51         if ( !empty( $force_accept ) ) {
     51        if ( ! empty( $force_accept ) ) {
    5252                $friendship->is_confirmed = 1;
    5353        }
  • trunk/tests/testcases/friends/functions.php

    r8172 r8173  
    124124                $this->assertFalse( friends_add_friend( $u1, $u1 ) );
    125125        }
     126
     127        /**
     128         * @group friends_add_friend
     129         */
     130        public function test_friends_add_friend_already_friends() {
     131                $u1 = $this->create_user();
     132                $u2 = $this->create_user();
     133
     134                friends_add_friend( $u1, $u2, true );
     135
     136                $this->assertTrue( friends_add_friend( $u1, $u2 ) );
     137        }
    126138}
Note: See TracChangeset for help on using the changeset viewer.