Ticket #5266: 5266.friends.patch
File 5266.friends.patch, 11.5 KB (added by , 12 years ago) |
---|
-
bp-friends-cache.php
10 10 * @subpackage FriendsCaching 11 11 */ 12 12 13 14 13 // Exit if accessed directly 15 14 if ( !defined( 'ABSPATH' ) ) exit; 16 15 … … 28 27 wp_cache_delete( 'friends_friend_ids_' . $friendship->friend_user_id, 'bp' ); 29 28 } 30 29 31 /**32 * Clear friend-related notifications when ?new=1.33 */34 function friends_clear_friend_notifications() {35 if ( isset( $_GET['new'] ) ) {36 bp_core_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->friends->id, 'friendship_accepted' );37 }38 }39 add_action( 'bp_activity_screen_my_activity', 'friends_clear_friend_notifications' );40 41 30 // List actions to clear object caches on 42 31 add_action( 'friends_friendship_accepted', 'friends_clear_friend_object_cache' ); 43 32 add_action( 'friends_friendship_deleted', 'friends_clear_friend_object_cache' ); -
bp-friends-functions.php
29 29 * @return bool True on success, false on failure. 30 30 */ 31 31 function friends_add_friend( $initiator_userid, $friend_userid, $force_accept = false ) { 32 global $bp;33 32 34 33 $friendship = new BP_Friends_Friendship; 35 34 36 if ( (int) $friendship->is_confirmed ) 35 if ( (int) $friendship->is_confirmed ) { 37 36 return true; 37 } 38 38 39 39 $friendship->initiator_user_id = $initiator_userid; 40 40 $friendship->friend_user_id = $friend_userid; … … 42 42 $friendship->is_limited = 0; 43 43 $friendship->date_created = bp_core_current_time(); 44 44 45 if ( $force_accept )45 if ( !empty( $force_accept ) ) { 46 46 $friendship->is_confirmed = 1; 47 } 47 48 48 49 if ( $friendship->save() ) { 49 50 50 if ( !$force_accept ) { 51 // Add the on screen notification 52 bp_core_add_notification( $friendship->initiator_user_id, $friendship->friend_user_id, $bp->friends->id, 'friendship_request' ); 53 54 // Send the email notification 51 // Send the email notification 52 if ( empty( $force_accept ) ) { 55 53 friends_notification_new_request( $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id ); 56 54 57 55 do_action( 'friends_friendship_requested', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id ); 56 57 // Update friend totals 58 58 } else { 59 // Update friend totals60 59 friends_update_friend_totals( $friendship->initiator_user_id, $friendship->friend_user_id, 'add' ); 61 60 62 61 do_action( 'friends_friendship_accepted', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id ); … … 111 110 * @return bool True on success, false on failure. 112 111 */ 113 112 function friends_accept_friendship( $friendship_id ) { 114 global $bp;115 113 116 114 $friendship = new BP_Friends_Friendship( $friendship_id, true, false ); 117 115 118 116 if ( !$friendship->is_confirmed && BP_Friends_Friendship::accept( $friendship_id ) ) { 119 117 friends_update_friend_totals( $friendship->initiator_user_id, $friendship->friend_user_id ); 120 118 121 // Remove the friend request notice122 bp_core_mark_notifications_by_item_id( $friendship->friend_user_id, $friendship->initiator_user_id, $bp->friends->id, 'friendship_request' );123 124 // Add a friend accepted notice for the initiating user125 bp_core_add_notification( $friendship->friend_user_id, $friendship->initiator_user_id, $bp->friends->id, 'friendship_accepted' );126 127 119 $initiator_link = bp_core_get_userlink( $friendship->initiator_user_id ); 128 $friend_link = bp_core_get_userlink( $friendship->friend_user_id);120 $friend_link = bp_core_get_userlink( $friendship->friend_user_id ); 129 121 130 122 // Record in activity streams for the initiator 131 123 friends_record_activity( array( … … 164 156 * @return bool True on success, false on failure. 165 157 */ 166 158 function friends_reject_friendship( $friendship_id ) { 167 global $bp;168 169 159 $friendship = new BP_Friends_Friendship( $friendship_id, true, false ); 170 160 171 if ( !$friendship->is_confirmed && BP_Friends_Friendship::reject( $friendship_id ) ) { 172 173 // Remove the friend request notice 174 bp_core_mark_notifications_by_item_id( $friendship->friend_user_id, $friendship->initiator_user_id, $bp->friends->id, 'friendship_request' ); 175 161 if ( empty( $friendship->is_confirmed ) && BP_Friends_Friendship::reject( $friendship_id ) ) { 176 162 do_action_ref_array( 'friends_friendship_rejected', array( $friendship_id, &$friendship ) ); 177 163 return true; 178 164 } … … 189 175 * @return bool True on success, false on failure. 190 176 */ 191 177 function friends_withdraw_friendship( $initiator_userid, $friend_userid ) { 192 global $bp;193 194 178 $friendship_id = BP_Friends_Friendship::get_friendship_id( $initiator_userid, $friend_userid ); 195 179 $friendship = new BP_Friends_Friendship( $friendship_id, true, false ); 196 180 197 if ( !$friendship->is_confirmed && BP_Friends_Friendship::withdraw( $friendship_id ) ) { 198 // Remove the friend request notice 199 bp_core_delete_notifications_by_item_id( $friendship->friend_user_id, $friendship->initiator_user_id, $bp->friends->id, 'friendship_request' ); 200 181 if ( empty( $friendship->is_confirmed ) && BP_Friends_Friendship::withdraw( $friendship_id ) ) { 201 182 do_action_ref_array( 'friends_friendship_whithdrawn', array( $friendship_id, &$friendship ) ); 202 183 return true; 203 184 } … … 566 547 * @param int $user_id ID of the user whose friend data is being removed. 567 548 */ 568 549 function friends_remove_data( $user_id ) { 569 global $bp;570 550 571 551 do_action( 'friends_before_remove_data', $user_id ); 572 552 … … 575 555 // Remove usermeta 576 556 bp_delete_user_meta( $user_id, 'total_friend_count' ); 577 557 578 // Remove friendship requests FROM user579 bp_core_delete_notifications_from_user( $user_id, $bp->friends->id, 'friendship_request' );580 581 558 do_action( 'friends_remove_data', $user_id ); 582 559 } 583 560 add_action( 'wpmu_delete_user', 'friends_remove_data' ); -
bp-friends-notifications.php
13 13 // Exit if accessed directly 14 14 if ( !defined( 'ABSPATH' ) ) exit; 15 15 16 /** Emails ********************************************************************/ 17 16 18 /** 17 19 * Send notifications related to a new friendship request. 18 20 * … … 111 113 112 114 do_action( 'bp_friends_sent_accepted_email', $initiator_id, $subject, $message, $friendship_id, $friend_id ); 113 115 } 116 117 /** Notifications *************************************************************/ 118 119 /** 120 * Clear friend-related notifications when ?new=1 121 */ 122 function friends_clear_friend_notifications() { 123 if ( isset( $_GET['new'] ) && bp_is_active( 'notifications' ) ) { 124 bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->friends->id, 'friendship_accepted' ); 125 } 126 } 127 add_action( 'bp_activity_screen_my_activity', 'friends_clear_friend_notifications' ); 128 129 /** 130 * Delete any friendship request notifications for the logged in user. 131 * 132 * @since BuddyPress (1.9.0) 133 */ 134 function bp_friends_mark_friendship_request_notifications_by_type() { 135 if ( isset( $_GET['new'] ) && bp_is_active( 'notifications' ) ) { 136 bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->friends->id, 'friendship_request' ); 137 } 138 } 139 add_action( 'friends_screen_requests', 'bp_friends_mark_friendship_request_notifications_by_type' ); 140 141 /** 142 * Delete any friendship acceptance notifications for the logged in user. 143 * 144 * @since BuddyPress (1.9.0) 145 */ 146 function bp_friends_mark_friendship_accepted_notifications_by_type() { 147 if ( bp_is_active( 'notifications' ) ) { 148 bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->friends->id, 'friendship_accepted' ); 149 } 150 } 151 add_action( 'friends_screen_my_friends', 'bp_friends_mark_friendship_accepted_notifications_by_type' ); 152 153 /** 154 * Notify one use that another user has requested their virtual friendship. 155 * 156 * @since BuddyPress (1.9.0) 157 */ 158 function bp_friends_friendship_requested_notification( $friendship_id, $initiator_user_id, $friend_user_id ) { 159 if ( bp_is_active( 'notifications' ) ) { 160 bp_notifications_add_notification( $initiator_user_id, $friend_user_id, $friendship_id, 'friendship_request' ); 161 } 162 } 163 add_action( 'friends_friendship_requested', 'friends_friendship_requested' ); 164 165 /** 166 * Remove friend request notice when a member rejects another members 167 * 168 * @since BuddyPress (1.9.0) 169 * 170 * @param int $friendship_id (not used) 171 * @param object $friendship 172 */ 173 function bp_friends_mark_friendship_rejected_notifications_by_item_id( $friendship_id, $friendship ) { 174 if ( bp_is_active( 'notifications' ) ) { 175 bp_notifications_mark_notifications_by_item_id( $friendship->friend_user_id, $friendship->initiator_user_id, buddypress()->friends->id, 'friendship_request' ); 176 } 177 } 178 add_action( 'friends_friendship_rejected', 'bp_friends_mark_friendship_rejected_notifications_by_item_id' ); 179 180 /** 181 * Notify a member when another member accepts their virtual friendsip request. 182 * 183 * @since BuddyPress (1.9.0) 184 * @param int $relationship_id 185 * @param int $initiator_user_id 186 * @param int $friend_user_id 187 */ 188 function bp_friends_add_friendship_accepted_notification( $friendship_id, $initiator_user_id, $friend_user_id ) { 189 190 // Bail if notifications is not active 191 if ( ! bp_is_active( 'notifications' ) ) { 192 return; 193 } 194 195 // Remove the friend request notice 196 bp_notifications_mark_notifications_by_item_id( $friend_user_id, $initiator_user_id, buddypress()->friends->id, 'friendship_request' ); 197 198 // Add a friend accepted notice for the initiating user 199 bp_notifications_add_notification( array( 200 'user_id' => $initiator_user_id, 201 'item_id' => $friend_user_id, 202 'secondary_item_id' => 0, 203 'component_name' => buddypress()->friends->id, 204 'component_action' => 'friendship_accepted', 205 'date_notified' => bp_core_current_time(), 206 'is_new' => 1, 207 ) ); 208 } 209 add_action( 'friends_friendship_accepted', 'bp_friends_add_friendship_accepted_notification' ); 210 211 /** 212 * Remove friend request notice when a member withdraws their friend request 213 * 214 * @since BuddyPress (1.9.0) 215 * 216 * @param int $friendship_id (not used) 217 * @param object $friendship 218 */ 219 function bp_friends_mark_friendship_withdrawn_notifications_by_item_id( $friendship_id, $friendship ) { 220 if ( bp_is_active( 'notifications' ) ) { 221 bp_notifications_delete_notifications_by_item_id( $friendship->friend_user_id, $friendship->initiator_user_id, buddypress()->friends->id, 'friendship_request' ); 222 } 223 } 224 add_action( 'friends_friendship_withdrawn', 'bp_friends_mark_friendship_withdrawn_notifications_by_item_id' ); 225 226 /** 227 * Remove friendship requests FROM user, used primarily when a user is deleted 228 * 229 * @since BuddyPress (1.9.0) 230 * @param int $user_id 231 */ 232 function bp_friends_remove_notifications_data( $user_id = 0 ) { 233 if ( bp_is_active( 'notifications' ) ) { 234 bp_notifications_delete_notifications_from_user( $user_id, buddypress()->friends->id, 'friendship_request' ); 235 } 236 } 237 add_action( 'friends_remove_data', 'bp_friends_remove_notifications_data' ); -
bp-friends-screens.php
19 19 */ 20 20 function friends_screen_my_friends() { 21 21 22 // Delete any friendship acceptance notifications for the user when viewing a profile23 bp_core_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->friends->id, 'friendship_accepted' );24 25 22 do_action( 'friends_screen_my_friends' ); 26 23 27 24 bp_core_load_template( apply_filters( 'friends_template_my_friends', 'members/single/home' ) ); … … 67 64 68 65 do_action( 'friends_screen_requests' ); 69 66 70 if ( isset( $_GET['new'] ) ) {71 bp_core_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->friends->id, 'friendship_request' );72 }73 74 67 bp_core_load_template( apply_filters( 'friends_template_requests', 'members/single/home' ) ); 75 68 } 76 69