Skip to:
Content

BuddyPress.org

Ticket #5942: bp-friends-functions-5942.diff

File bp-friends-functions-5942.diff, 9.1 KB (added by tw2113, 11 years ago)
  • src/bp-friends/bp-friends-functions.php

     
    5959
    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;
    7486}
     
    8799        $friendship_id = BP_Friends_Friendship::get_friendship_id( $initiator_userid, $friend_userid );
    88100        $friendship    = new BP_Friends_Friendship( $friendship_id );
    89101
     102        /**
     103         * Fires before the deletion of a friendship activity item
     104         * for the user who canceled the friendship.
     105         *
     106         * @since BuddyPress (1.5.0)
     107         *
     108         * @param int $friendship_id ID of the friendship object, if any, between a pair of users.
     109         * @param int $initiator_userid ID of the friendship initiator.
     110         * @param int $friend_userid ID of the friend user.
     111         */
    90112        do_action( 'friends_before_friendship_delete', $friendship_id, $initiator_userid, $friend_userid );
    91113
    92114        // Remove the activity stream item for the user who canceled the friendship
    93115        friends_delete_activity( array( 'item_id' => $friendship_id, 'type' => 'friendship_accepted', 'user_id' => bp_displayed_user_id() ) );
    94116
    95         // This hook is misleadingly named - the friendship is not yet deleted.
    96         // This is your last chance to do something while the friendship exists
     117        /**
     118         * Fires before the friendship connection is removed.
     119         *
     120         * This hook is misleadingly named - the friendship is not yet deleted.
     121         * This is your last chance to do something while the friendship exists.
     122         *
     123         * @since BuddyPress (1.0.0)
     124         *
     125         * @param int $friendship_id ID of the friendship object, if any, between a pair of users.
     126         * @param int $initiator_userid ID of the friendship initiator.
     127         * @param int $friend_userid ID of the friend user.
     128         */
    97129        do_action( 'friends_friendship_deleted', $friendship_id, $initiator_userid, $friend_userid );
    98130
    99131        if ( $friendship->delete() ) {
    100132                friends_update_friend_totals( $initiator_userid, $friend_userid, 'remove' );
    101133
     134                /**
     135                 * Fires after the friendship connection is removed.
     136                 *
     137                 * @since BuddyPress (1.8.0)
     138                 *
     139                 * @param int $initiator_userid ID of the friendship initiator.
     140                 * @param int $friend_userid ID of the friend user.
     141                 */
    102142                do_action( 'friends_friendship_post_delete', $initiator_userid, $friend_userid );
    103143
    104144                return true;
     
    126166                // Bump the friendship counts
    127167                friends_update_friend_totals( $friendship->initiator_user_id, $friendship->friend_user_id );
    128168
     169                /**
     170                 * Fires after a friendship is accepted.
     171                 *
     172                 * @since BuddyPress (1.0.0)
     173                 *
     174                 * @param int    $id ID of the pending friendship object.
     175                 * @param int    $initiator_user_id ID of the friendship initiator.
     176                 * @param int    $friend_user_id ID of the user requested friendship with.
     177                 * @param object $friendship BuddyPress Friendship Object.
     178                 */
    129179                do_action( 'friends_friendship_accepted', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id, $friendship );
    130180
    131181                return true;
     
    144194        $friendship = new BP_Friends_Friendship( $friendship_id, true, false );
    145195
    146196        if ( empty( $friendship->is_confirmed ) && BP_Friends_Friendship::reject( $friendship_id ) ) {
     197
     198                /**
     199                 * Fires after a friendship request is rejected.
     200                 *
     201                 * @since BuddyPress (1.0.0)
     202                 *
     203                 * @param array $value Array holding the ID of the pending friendship object
     204                 *                and friendship object.
     205                 */
    147206                do_action_ref_array( 'friends_friendship_rejected', array( $friendship_id, &$friendship ) );
    148207                return true;
    149208        }
     
    168227                // @deprecated Since 1.9
    169228                do_action_ref_array( 'friends_friendship_whithdrawn', array( $friendship_id, &$friendship ) );
    170229
    171                 // @since 1.9
     230                /**
     231                 * Fires after a friendship request has been withdrawn.
     232                 *
     233                 * @since BuddyPress (1.9.0)
     234                 *
     235                 * @param array $value Array holding the ID of the pending friendship object
     236                 *                and friendship object.
     237                 */
    172238                do_action_ref_array( 'friends_friendship_withdrawn',  array( $friendship_id, &$friendship ) );
    173239
    174240                return true;
     
    234300        if ( empty( $count ) )
    235301                $count = 0;
    236302
     303        /**
     304         * Filters the total friend count for a given user.
     305         *
     306         * @since BuddyPress (1.2.0)
     307         *
     308         * @param int $count Total friend count for a given user.
     309         */
    237310        return apply_filters( 'friends_get_total_friend_count', $count );
    238311}
    239312
     
    325398 * @return array See {@link BP_Core_User::get_users()}.
    326399 */
    327400function friends_get_recently_active( $user_id, $per_page = 0, $page = 0, $filter = '' ) {
     401
     402        /**
     403         * Filters a user's most recently active friends.
     404         *
     405         * @since BuddyPress (1.2.0)
     406         *
     407         * @param array $value Array holding total number of users matched by query params and
     408         *                the current page of users matched by query params.
     409         */
    328410        return apply_filters( 'friends_get_recently_active', BP_Core_User::get_users( 'active', $per_page, $page, $user_id, $filter ) );
    329411}
    330412
     
    343425 * @return array See {@link BP_Core_User::get_users()}.
    344426 */
    345427function friends_get_alphabetically( $user_id, $per_page = 0, $page = 0, $filter = '' ) {
     428
     429        /**
     430         * Filters a user's friends listed in alphabetical order.
     431         *
     432         * @since BuddyPress (1.2.0)
     433         *
     434         * @param array $value Array holding total number of users matched by query params and
     435         *                the current page of users matched by query params.
     436         */
    346437        return apply_filters( 'friends_get_alphabetically', BP_Core_User::get_users( 'alphabetical', $per_page, $page, $user_id, $filter ) );
    347438}
    348439
     
    361452 * @return array See {@link BP_Core_User::get_users()}.
    362453 */
    363454function friends_get_newest( $user_id, $per_page = 0, $page = 0, $filter = '' ) {
     455
     456        /**
     457         * Filters a user's friends listed from newest to oldest.
     458         *
     459         * @since BuddyPress (1.2.0)
     460         *
     461         * @param array $value Array holding total number of users matched by query params and
     462         *                the current page of users matched by query params.
     463         */
    364464        return apply_filters( 'friends_get_newest', BP_Core_User::get_users( 'newest', $per_page, $page, $user_id, $filter ) );
    365465}
    366466
     
    402502        // Assume no friends
    403503        $friends = array();
    404504
    405         // Default args
     505        /**
     506         * Filters default arguments for list of friends a user can invite into this group.
     507         *
     508         * @since BuddyPress (1.5.4)
     509         *
     510         * @param array $value Array of default paremters for invite list.
     511         */
    406512        $args = apply_filters( 'bp_friends_pre_get_invite_list', array(
    407513                'user_id'  => $user_id,
    408514                'type'     => 'alphabetical',
     
    449555        if ( empty( $friends ) )
    450556                $friends = false;
    451557
    452         // Allow friends to be filtered
     558        /**
     559         * Filters the list of potential friends that can be invited to this group.
     560         *
     561         * @since BuddyPress (1.5.4)
     562         *
     563         * @param array|bool $friends Array friends available to invite or false for no friends.
     564         * @param int        $user_id ID of the user checked for who they can invite.
     565         * @param int        $group_id ID of the group being checked on.
     566         */
    453567        return apply_filters( 'bp_friends_get_invite_list', $friends, $user_id, $group_id );
    454568}
    455569
     
    554668 */
    555669function friends_remove_data( $user_id ) {
    556670
     671        /**
     672         * Fires before deletion of friend-related data for a given user.
     673         *
     674         * @since BuddyPress (1.5.0)
     675         *
     676         * @param int $user_id ID for the user whose friend data is being removed.
     677         */
    557678        do_action( 'friends_before_remove_data', $user_id );
    558679
    559680        BP_Friends_Friendship::delete_all_for_user( $user_id );
     
    561682        // Remove usermeta
    562683        bp_delete_user_meta( $user_id, 'total_friend_count' );
    563684
     685        /**
     686         * Fires after deletion of friend-related data for a given user.
     687         *
     688         * @since BuddyPress (1.0.0)
     689         *
     690         * @param int $user_id ID for the user whose friend data is being removed.
     691         */
    564692        do_action( 'friends_remove_data', $user_id );
    565693}
    566694add_action( 'wpmu_delete_user',  'friends_remove_data' );
     
    617745                'friends' => $results,
    618746        ) );
    619747}
    620 add_action( 'bp_activity_mentions_prime_results', 'bp_friends_prime_mentions_results' );
    621  No newline at end of file
     748add_action( 'bp_activity_mentions_prime_results', 'bp_friends_prime_mentions_results' );