Ticket #5942: bp-friends-functions-5942.diff
| File bp-friends-functions-5942.diff, 9.1 KB (added by , 11 years ago) |
|---|
-
src/bp-friends/bp-friends-functions.php
59 59 60 60 // Send notifications 61 61 if ( empty( $force_accept ) ) { 62 $action = ' friends_friendship_requested';62 $action = 'requested'; 63 63 64 64 // Update friend totals 65 65 } else { 66 $action = ' friends_friendship_accepted';66 $action = 'accepted'; 67 67 friends_update_friend_totals( $friendship->initiator_user_id, $friendship->friend_user_id, 'add' ); 68 68 } 69 69 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 ); 72 84 73 85 return true; 74 86 } … … 87 99 $friendship_id = BP_Friends_Friendship::get_friendship_id( $initiator_userid, $friend_userid ); 88 100 $friendship = new BP_Friends_Friendship( $friendship_id ); 89 101 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 */ 90 112 do_action( 'friends_before_friendship_delete', $friendship_id, $initiator_userid, $friend_userid ); 91 113 92 114 // Remove the activity stream item for the user who canceled the friendship 93 115 friends_delete_activity( array( 'item_id' => $friendship_id, 'type' => 'friendship_accepted', 'user_id' => bp_displayed_user_id() ) ); 94 116 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 */ 97 129 do_action( 'friends_friendship_deleted', $friendship_id, $initiator_userid, $friend_userid ); 98 130 99 131 if ( $friendship->delete() ) { 100 132 friends_update_friend_totals( $initiator_userid, $friend_userid, 'remove' ); 101 133 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 */ 102 142 do_action( 'friends_friendship_post_delete', $initiator_userid, $friend_userid ); 103 143 104 144 return true; … … 126 166 // Bump the friendship counts 127 167 friends_update_friend_totals( $friendship->initiator_user_id, $friendship->friend_user_id ); 128 168 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 */ 129 179 do_action( 'friends_friendship_accepted', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id, $friendship ); 130 180 131 181 return true; … … 144 194 $friendship = new BP_Friends_Friendship( $friendship_id, true, false ); 145 195 146 196 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 */ 147 206 do_action_ref_array( 'friends_friendship_rejected', array( $friendship_id, &$friendship ) ); 148 207 return true; 149 208 } … … 168 227 // @deprecated Since 1.9 169 228 do_action_ref_array( 'friends_friendship_whithdrawn', array( $friendship_id, &$friendship ) ); 170 229 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 */ 172 238 do_action_ref_array( 'friends_friendship_withdrawn', array( $friendship_id, &$friendship ) ); 173 239 174 240 return true; … … 234 300 if ( empty( $count ) ) 235 301 $count = 0; 236 302 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 */ 237 310 return apply_filters( 'friends_get_total_friend_count', $count ); 238 311 } 239 312 … … 325 398 * @return array See {@link BP_Core_User::get_users()}. 326 399 */ 327 400 function 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 */ 328 410 return apply_filters( 'friends_get_recently_active', BP_Core_User::get_users( 'active', $per_page, $page, $user_id, $filter ) ); 329 411 } 330 412 … … 343 425 * @return array See {@link BP_Core_User::get_users()}. 344 426 */ 345 427 function 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 */ 346 437 return apply_filters( 'friends_get_alphabetically', BP_Core_User::get_users( 'alphabetical', $per_page, $page, $user_id, $filter ) ); 347 438 } 348 439 … … 361 452 * @return array See {@link BP_Core_User::get_users()}. 362 453 */ 363 454 function 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 */ 364 464 return apply_filters( 'friends_get_newest', BP_Core_User::get_users( 'newest', $per_page, $page, $user_id, $filter ) ); 365 465 } 366 466 … … 402 502 // Assume no friends 403 503 $friends = array(); 404 504 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 */ 406 512 $args = apply_filters( 'bp_friends_pre_get_invite_list', array( 407 513 'user_id' => $user_id, 408 514 'type' => 'alphabetical', … … 449 555 if ( empty( $friends ) ) 450 556 $friends = false; 451 557 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 */ 453 567 return apply_filters( 'bp_friends_get_invite_list', $friends, $user_id, $group_id ); 454 568 } 455 569 … … 554 668 */ 555 669 function friends_remove_data( $user_id ) { 556 670 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 */ 557 678 do_action( 'friends_before_remove_data', $user_id ); 558 679 559 680 BP_Friends_Friendship::delete_all_for_user( $user_id ); … … 561 682 // Remove usermeta 562 683 bp_delete_user_meta( $user_id, 'total_friend_count' ); 563 684 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 */ 564 692 do_action( 'friends_remove_data', $user_id ); 565 693 } 566 694 add_action( 'wpmu_delete_user', 'friends_remove_data' ); … … 617 745 'friends' => $results, 618 746 ) ); 619 747 } 620 add_action( 'bp_activity_mentions_prime_results', 'bp_friends_prime_mentions_results' ); 621 No newline at end of file 748 add_action( 'bp_activity_mentions_prime_results', 'bp_friends_prime_mentions_results' );