Skip to:
Content

BuddyPress.org

Changeset 9173


Ignore:
Timestamp:
11/25/2014 02:51:55 PM (11 years ago)
Author:
boonebgorges
Message:

Generate friend initiation hook dynamically.

This makes it easier to document per WP standards.

Props tw2113.
See #5942.

Location:
trunk
Files:
2 edited

Legend:

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

    r9102 r9173  
    6060    // Send notifications
    6161    if ( empty( $force_accept ) ) {
    62         $action = 'friends_friendship_requested';
     62        $action = 'requested';
    6363
    6464    // Update friend totals
    6565    } else {
    66         $action = 'friends_friendship_accepted';
     66        $action = 'accepted';
    6767        friends_update_friend_totals( $friendship->initiator_user_id, $friendship->friend_user_id, 'add' );
    6868    }
    6969
    70     // Call the above titled action and pass friendship data into it
    71     do_action( $action, $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id, $friendship );
     70    /**
     71     * Fires at the end of initiating a new friendship connection.
     72     *
     73     * This is a variable hook, depending on context.
     74     * The two potential hooks are: friends_friendship_requested, friends_friendship_accepted.
     75     *
     76     * @since BuddyPress (1.0.0)
     77     *
     78     * @param int    $id ID of the pending friendship connection.
     79     * @param int    $initiator_user_id ID of the friendship initiator.
     80     * @param int    $friend_user_id ID of the friend user.
     81     * @param object $friendship BuddyPress Friendship Object.
     82     */
     83    do_action( 'friends_friendship_' . $action, $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id, $friendship );
    7284
    7385    return true;
  • trunk/tests/phpunit/testcases/friends/functions.php

    r9139 r9173  
    66 */
    77class BP_Tests_Friends_Functions extends BP_UnitTestCase {
     8
     9    protected $filter_fired;
     10
     11    public function setUp() {
     12        parent::setUp();
     13        $this->filter_fired = '';
     14    }
     15
     16    public function tearDown() {
     17        parent::tearDown();
     18    }
    819
    920    /**
     
    228239        $this->assertSame( $expected, $found );
    229240    }
     241
     242    /**
     243     * @group friends_add_friend
     244     */
     245    public function test_friends_add_friend_friends_friendship_requested() {
     246        $u1 = $this->factory->user->create();
     247        $u2 = $this->factory->user->create();
     248
     249        add_filter( 'friends_friendship_requested', array( $this, 'friends_friendship_filter_callback' ) );
     250        $n = friends_add_friend( $u1, $u2, false );
     251        remove_filter( 'friends_friendship_requested', array( $this, 'friends_friendship_filter_callback' ) );
     252
     253        $this->assertSame( 'friends_friendship_requested', $this->filter_fired );
     254    }
     255
     256    /**
     257     * @group friends_add_friend
     258     */
     259    public function test_friends_add_friend_friends_friendship_accepted() {
     260        $u1 = $this->factory->user->create();
     261        $u2 = $this->factory->user->create();
     262
     263        add_filter( 'friends_friendship_accepted', array( $this, 'friends_friendship_filter_callback' ) );
     264        $n = friends_add_friend( $u1, $u2, true );
     265        remove_filter( 'friends_friendship_accepted', array( $this, 'friends_friendship_filter_callback' ) );
     266
     267        $this->assertSame( 'friends_friendship_accepted', $this->filter_fired );
     268    }
     269
     270    public function friends_friendship_filter_callback( $value ) {
     271        $this->filter_fired = current_filter();
     272        return $value;
     273    }
    230274}
Note: See TracChangeset for help on using the changeset viewer.