Ticket #5266: 5266.friends.3.patch
File 5266.friends.3.patch, 25.7 KB (added by , 12 years ago) |
---|
-
plugins/buddypress/bp-friends/bp-friends-activity.php
diff --git a/plugins/buddypress/bp-friends/bp-friends-activity.php b/plugins/buddypress/bp-friends/bp-friends-activity.php index fb9f585..996c48a 100644
a b 32 32 * @return bool See {@link bp_activity_add()}. 33 33 */ 34 34 function friends_record_activity( $args = '' ) { 35 global $bp;36 35 37 if ( ! bp_is_active( 'activity' ) )36 if ( ! bp_is_active( 'activity' ) ) { 38 37 return false; 38 } 39 39 40 $ defaults = array(40 $r = wp_parse_args( $args, array( 41 41 'user_id' => bp_loggedin_user_id(), 42 42 'action' => '', 43 43 'content' => '', 44 44 'primary_link' => '', 45 'component' => $bp->friends->id,45 'component' => buddypress()->friends->id, 46 46 'type' => false, 47 47 'item_id' => false, 48 48 'secondary_item_id' => false, 49 49 'recorded_time' => bp_core_current_time(), 50 50 'hide_sitewide' => false 51 ) ;51 ) ); 52 52 53 $r = wp_parse_args( $args, $defaults ); 54 extract( $r, EXTR_SKIP ); 55 56 return bp_activity_add( array( 'user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide ) ); 53 return bp_activity_add( $r ); 57 54 } 58 55 59 56 /** … … 71 68 * @return bool True on success, false on failure. 72 69 */ 73 70 function friends_delete_activity( $args ) { 74 global $bp; 75 76 if ( bp_is_active( 'activity' ) ) { 77 extract( (array) $args ); 78 bp_activity_delete_by_item_id( array( 'item_id' => $item_id, 'component' => $bp->friends->id, 'type' => $type, 'user_id' => $user_id ) ); 71 if ( ! bp_is_active( 'activity' ) ) { 72 return; 79 73 } 74 75 bp_activity_delete_by_item_id( array( 76 'component' => buddypress()->friends->id, 77 'item_id' => $args['item_id'], 78 'type' => $args['type'], 79 'user_id' => $args['user_id'] 80 ) ); 80 81 } 81 82 82 83 /** 83 84 * Register the activity actions for bp-friends. 84 85 */ 85 86 function friends_register_activity_actions() { 86 global $bp;87 87 88 if ( !bp_is_active( 'activity' ) ) 88 if ( !bp_is_active( 'activity' ) ) { 89 89 return false; 90 } 91 92 $bp = buddypress(); 90 93 91 94 // These two added in BP 1.6 92 95 bp_activity_set_action( $bp->friends->id, 'friendship_accepted', __( 'Friendships accepted', 'buddypress' ) ); 93 bp_activity_set_action( $bp->friends->id, 'friendship_created', __( 'New friendships','buddypress' ) );96 bp_activity_set_action( $bp->friends->id, 'friendship_created', __( 'New friendships', 'buddypress' ) ); 94 97 95 98 // < BP 1.6 backpat 96 99 bp_activity_set_action( $bp->friends->id, 'friends_register_activity_action', __( 'New friendship created', 'buddypress' ) ); … … 100 103 add_action( 'bp_register_activity_actions', 'friends_register_activity_actions' ); 101 104 102 105 /** 103 * Notification formatting callback for bp-friends notifications. 106 * Add activity stream items when one members accepts another members request 107 * for virtual friendship. 104 108 * 105 * @param string $action The kind of notification being rendered. 106 * @param int $item_id The primary item ID. 107 * @param int $secondary_item_id The secondary item ID. 108 * @param int $total_items The total number of messaging-related notifications 109 * waiting for the user. 110 * @param string $format 'string' for BuddyBar-compatible notifications; 111 * 'array' for WP Toolbar. Default: 'string'. 112 * @return array|string 109 * @since BuddyPress (1.9.0) 110 * 111 * @param int $friendship_id 112 * @param int $initiator_user_id 113 * @param int $friend_user_id 114 * @param object $friendship 113 115 */ 114 function friends_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string') {116 function bp_friends_friendship_accepted_activity( $friendship_id, $initiator_user_id, $friend_user_id, $friendship ) { 115 117 116 switch ( $action ) { 117 case 'friendship_accepted': 118 $link = trailingslashit( bp_loggedin_user_domain() . bp_get_friends_slug() . '/my-friends' ); 119 120 // Set up the string and the filter 121 if ( (int) $total_items > 1 ) { 122 $text = sprintf( __( '%d friends accepted your friendship requests', 'buddypress' ), (int) $total_items ); 123 $filter = 'bp_friends_multiple_friendship_accepted_notification'; 124 } else { 125 $text = sprintf( __( '%s accepted your friendship request', 'buddypress' ), bp_core_get_user_displayname( $item_id ) ); 126 $filter = 'bp_friends_single_friendship_accepted_notification'; 127 } 128 129 break; 130 131 case 'friendship_request': 132 $link = bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/?new'; 133 134 // Set up the string and the filter 135 if ( (int) $total_items > 1 ) { 136 $text = sprintf( __( 'You have %d pending friendship requests', 'buddypress' ), (int) $total_items ); 137 $filter = 'bp_friends_multiple_friendship_request_notification'; 138 } else { 139 $text = sprintf( __( 'You have a friendship request from %s', 'buddypress' ), bp_core_get_user_displayname( $item_id ) ); 140 $filter = 'bp_friends_single_friendship_request_notification'; 141 } 142 143 break; 118 // Bail if Activity component is not active 119 if ( ! bp_is_active( 'activity' ) ) { 120 return; 144 121 } 145 122 146 // Return either an HTML link or an array, depending on the requested format 147 if ( 'string' == $format ) { 148 $return = apply_filters( $filter, '<a href="' . $link . '">' . $text . '</a>', (int) $total_items ); 149 } else { 150 $return = apply_filters( $filter, array( 151 'link' => $link, 152 'text' => $text 153 ), (int) $total_items ); 154 } 123 // Get links to both members profiles 124 $initiator_link = bp_core_get_userlink( $initiator_user_id ); 125 $friend_link = bp_core_get_userlink( $friend_user_id ); 155 126 156 do_action( 'friends_format_notifications', $action, $item_id, $secondary_item_id, $total_items, $return ); 127 // Record in activity streams for the initiator 128 friends_record_activity( array( 129 'user_id' => $initiator_user_id, 130 'type' => 'friendship_created', 131 'action' => apply_filters( 'friends_activity_friendship_accepted_action', sprintf( __( '%1$s and %2$s are now friends', 'buddypress' ), $initiator_link, $friend_link ), $friendship ), 132 'item_id' => $friendship_id, 133 'secondary_item_id' => $friend_user_id 134 ) ); 157 135 158 return $return; 136 // Record in activity streams for the friend 137 friends_record_activity( array( 138 'user_id' => $friend_user_id, 139 'type' => 'friendship_created', 140 'action' => apply_filters( 'friends_activity_friendship_accepted_action', sprintf( __( '%1$s and %2$s are now friends', 'buddypress' ), $friend_link, $initiator_link ), $friendship ), 141 'item_id' => $friendship_id, 142 'secondary_item_id' => $initiator_user_id, 143 'hide_sitewide' => true // We've already got the first entry site wide 144 ) ); 159 145 } 146 add_action( 'friends_friendship_accepted', 'bp_friends_friendship_accepted_activity', 10, 4 ); -
plugins/buddypress/bp-friends/bp-friends-cache.php
diff --git a/plugins/buddypress/bp-friends/bp-friends-cache.php b/plugins/buddypress/bp-friends/bp-friends-cache.php index 4464105..ce465e8 100644
a b 10 10 * @subpackage FriendsCaching 11 11 */ 12 12 13 14 13 // Exit if accessed directly 15 14 if ( !defined( 'ABSPATH' ) ) exit; 16 15 … … 27 26 wp_cache_delete( 'friends_friend_ids_' . $friendship->initiator_user_id, 'bp' ); 28 27 wp_cache_delete( 'friends_friend_ids_' . $friendship->friend_user_id, 'bp' ); 29 28 } 30 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 29 41 30 // List actions to clear object caches on 42 31 add_action( 'friends_friendship_accepted', 'friends_clear_friend_object_cache' ); -
plugins/buddypress/bp-friends/bp-friends-functions.php
diff --git a/plugins/buddypress/bp-friends/bp-friends-functions.php b/plugins/buddypress/bp-friends/bp-friends-functions.php index dbce712..0bef80d 100644
a b 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 33 // Check if already friends, and bail if so 34 34 $friendship = new BP_Friends_Friendship; 35 36 if ( (int) $friendship->is_confirmed ) 35 if ( (int) $friendship->is_confirmed ) { 37 36 return true; 37 } 38 38 39 // Setup the friendship data 39 40 $friendship->initiator_user_id = $initiator_userid; 40 41 $friendship->friend_user_id = $friend_userid; 41 42 $friendship->is_confirmed = 0; 42 43 $friendship->is_limited = 0; 43 44 $friendship->date_created = bp_core_current_time(); 44 45 45 if ( $force_accept )46 if ( !empty( $force_accept ) ) { 46 47 $friendship->is_confirmed = 1; 47 48 if ( $friendship->save() ) {49 50 if ( !$force_accept ) {51 // Add the on screen notification52 bp_core_add_notification( $friendship->initiator_user_id, $friendship->friend_user_id, $bp->friends->id, 'friendship_request' );53 54 // Send the email notification55 friends_notification_new_request( $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id );56 57 do_action( 'friends_friendship_requested', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id );58 } else {59 // Update friend totals60 friends_update_friend_totals( $friendship->initiator_user_id, $friendship->friend_user_id, 'add' );61 62 do_action( 'friends_friendship_accepted', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id );63 }64 65 return true;66 48 } 67 49 68 return false; 50 // Bail if friendship could not be saved (how sad!) 51 if ( ! $friendship->save() ) { 52 return false; 53 } 54 55 // Send notifications 56 if ( empty( $force_accept ) ) { 57 $action = 'friends_friendship_requested'; 58 59 // Update friend totals 60 } else { 61 $action = 'friends_friendship_accepted'; 62 friends_update_friend_totals( $friendship->initiator_user_id, $friendship->friend_user_id, 'add' ); 63 } 64 65 // Call the above titled action and pass friendship data into it 66 do_action( $action, $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id ); 67 68 return true; 69 69 } 70 70 71 71 /** … … 111 111 * @return bool True on success, false on failure. 112 112 */ 113 113 function friends_accept_friendship( $friendship_id ) { 114 global $bp;115 114 115 // Get the friesdhip data 116 116 $friendship = new BP_Friends_Friendship( $friendship_id, true, false ); 117 117 118 if ( !$friendship->is_confirmed && BP_Friends_Friendship::accept( $friendship_id ) ) { 118 // Accepting friendship 119 if ( empty( $friendship->is_confirmed ) && BP_Friends_Friendship::accept( $friendship_id ) ) { 120 121 // Bump the friendship counts 119 122 friends_update_friend_totals( $friendship->initiator_user_id, $friendship->friend_user_id ); 120 123 121 // Remove the friend request notice 122 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 user 125 bp_core_add_notification( $friendship->friend_user_id, $friendship->initiator_user_id, $bp->friends->id, 'friendship_accepted' ); 126 127 $initiator_link = bp_core_get_userlink( $friendship->initiator_user_id ); 128 $friend_link = bp_core_get_userlink( $friendship->friend_user_id ); 129 130 // Record in activity streams for the initiator 131 friends_record_activity( array( 132 'user_id' => $friendship->initiator_user_id, 133 'type' => 'friendship_created', 134 'action' => apply_filters( 'friends_activity_friendship_accepted_action', sprintf( __( '%1$s and %2$s are now friends', 'buddypress' ), $initiator_link, $friend_link ), $friendship ), 135 'item_id' => $friendship_id, 136 'secondary_item_id' => $friendship->friend_user_id 137 ) ); 138 139 // Record in activity streams for the friend 140 friends_record_activity( array( 141 'user_id' => $friendship->friend_user_id, 142 'type' => 'friendship_created', 143 'action' => apply_filters( 'friends_activity_friendship_accepted_action', sprintf( __( '%1$s and %2$s are now friends', 'buddypress' ), $friend_link, $initiator_link ), $friendship ), 144 'item_id' => $friendship_id, 145 'secondary_item_id' => $friendship->initiator_user_id, 146 'hide_sitewide' => true // We've already got the first entry site wide 147 ) ); 148 149 // Send the email notification 150 friends_notification_accepted_request( $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id ); 151 152 do_action( 'friends_friendship_accepted', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id ); 124 do_action( 'friends_friendship_accepted', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id, $friendship ); 153 125 154 126 return true; 155 127 } … … 164 136 * @return bool True on success, false on failure. 165 137 */ 166 138 function friends_reject_friendship( $friendship_id ) { 167 global $bp;168 169 139 $friendship = new BP_Friends_Friendship( $friendship_id, true, false ); 170 140 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 141 if ( empty( $friendship->is_confirmed ) && BP_Friends_Friendship::reject( $friendship_id ) ) { 176 142 do_action_ref_array( 'friends_friendship_rejected', array( $friendship_id, &$friendship ) ); 177 143 return true; 178 144 } … … 189 155 * @return bool True on success, false on failure. 190 156 */ 191 157 function friends_withdraw_friendship( $initiator_userid, $friend_userid ) { 192 global $bp;193 194 158 $friendship_id = BP_Friends_Friendship::get_friendship_id( $initiator_userid, $friend_userid ); 195 159 $friendship = new BP_Friends_Friendship( $friendship_id, true, false ); 196 160 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 161 if ( empty( $friendship->is_confirmed ) && BP_Friends_Friendship::withdraw( $friendship_id ) ) { 201 162 do_action_ref_array( 'friends_friendship_whithdrawn', array( $friendship_id, &$friendship ) ); 202 163 return true; 203 164 } … … 566 527 * @param int $user_id ID of the user whose friend data is being removed. 567 528 */ 568 529 function friends_remove_data( $user_id ) { 569 global $bp;570 530 571 531 do_action( 'friends_before_remove_data', $user_id ); 572 532 … … 574 534 575 535 // Remove usermeta 576 536 bp_delete_user_meta( $user_id, 'total_friend_count' ); 577 578 // Remove friendship requests FROM user579 bp_core_delete_notifications_from_user( $user_id, $bp->friends->id, 'friendship_request' );580 537 581 538 do_action( 'friends_remove_data', $user_id ); 582 539 } -
plugins/buddypress/bp-friends/bp-friends-notifications.php
diff --git a/plugins/buddypress/bp-friends/bp-friends-notifications.php b/plugins/buddypress/bp-friends/bp-friends-notifications.php index a11bb35..a3a87f9 100644
a b 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 * … … 54 56 $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link ); 55 57 } 56 58 57 / * Send the message */58 $to = apply_filters( 'friends_notification_new_request_to', $to );59 // Send the message 60 $to = apply_filters( 'friends_notification_new_request_to', $to ); 59 61 $subject = apply_filters( 'friends_notification_new_request_subject', $subject, $initiator_name ); 60 62 $message = apply_filters( 'friends_notification_new_request_message', $message, $initiator_name, $initiator_link, $all_requests_link, $settings_link ); 61 63 … … 63 65 64 66 do_action( 'bp_friends_sent_request_email', $friend_id, $subject, $message, $friendship_id, $initiator_id ); 65 67 } 68 add_action( 'friends_friendship_requested', 'friends_notification_new_request', 10, 3 ); 66 69 67 70 /** 68 71 * Send notifications related to the acceptance of a friendship request. … … 102 105 $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link ); 103 106 } 104 107 105 / * Send the message */106 $to = apply_filters( 'friends_notification_accepted_request_to', $to );108 // Send the message 109 $to = apply_filters( 'friends_notification_accepted_request_to', $to ); 107 110 $subject = apply_filters( 'friends_notification_accepted_request_subject', $subject, $friend_name ); 108 111 $message = apply_filters( 'friends_notification_accepted_request_message', $message, $friend_name, $friend_link, $settings_link ); 109 112 … … 111 114 112 115 do_action( 'bp_friends_sent_accepted_email', $initiator_id, $subject, $message, $friendship_id, $friend_id ); 113 116 } 117 add_action( 'friends_friendship_accepted', 'friends_notification_accepted_request', 10, 3 ); 118 119 /** Notifications *************************************************************/ 120 121 /** 122 * Notification formatting callback for bp-friends notifications. 123 * 124 * @param string $action The kind of notification being rendered. 125 * @param int $item_id The primary item ID. 126 * @param int $secondary_item_id The secondary item ID. 127 * @param int $total_items The total number of messaging-related notifications 128 * waiting for the user. 129 * @param string $format 'string' for BuddyBar-compatible notifications; 130 * 'array' for WP Toolbar. Default: 'string'. 131 * @return array|string 132 */ 133 function friends_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) { 134 135 switch ( $action ) { 136 case 'friendship_accepted': 137 $link = trailingslashit( bp_loggedin_user_domain() . bp_get_friends_slug() . '/my-friends' ); 138 139 // Set up the string and the filter 140 if ( (int) $total_items > 1 ) { 141 $text = sprintf( __( '%d friends accepted your friendship requests', 'buddypress' ), (int) $total_items ); 142 $filter = 'bp_friends_multiple_friendship_accepted_notification'; 143 } else { 144 $text = sprintf( __( '%s accepted your friendship request', 'buddypress' ), bp_core_get_user_displayname( $item_id ) ); 145 $filter = 'bp_friends_single_friendship_accepted_notification'; 146 } 147 148 break; 149 150 case 'friendship_request': 151 $link = bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/?new'; 152 153 // Set up the string and the filter 154 if ( (int) $total_items > 1 ) { 155 $text = sprintf( __( 'You have %d pending friendship requests', 'buddypress' ), (int) $total_items ); 156 $filter = 'bp_friends_multiple_friendship_request_notification'; 157 } else { 158 $text = sprintf( __( 'You have a friendship request from %s', 'buddypress' ), bp_core_get_user_displayname( $item_id ) ); 159 $filter = 'bp_friends_single_friendship_request_notification'; 160 } 161 162 break; 163 } 164 165 // Return either an HTML link or an array, depending on the requested format 166 if ( 'string' == $format ) { 167 $return = apply_filters( $filter, '<a href="' . esc_url( $link ) . '">' . esc_html( $text ) . '</a>', (int) $total_items ); 168 } else { 169 $return = apply_filters( $filter, array( 170 'link' => $link, 171 'text' => $text 172 ), (int) $total_items ); 173 } 174 175 do_action( 'friends_format_notifications', $action, $item_id, $secondary_item_id, $total_items, $return ); 176 177 return $return; 178 } 179 180 /** 181 * Clear friend-related notifications when ?new=1 182 */ 183 function friends_clear_friend_notifications() { 184 if ( isset( $_GET['new'] ) && bp_is_active( 'notifications' ) ) { 185 bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->friends->id, 'friendship_accepted' ); 186 } 187 } 188 add_action( 'bp_activity_screen_my_activity', 'friends_clear_friend_notifications' ); 189 190 /** 191 * Delete any friendship request notifications for the logged in user. 192 * 193 * @since BuddyPress (1.9.0) 194 */ 195 function bp_friends_mark_friendship_request_notifications_by_type() { 196 if ( isset( $_GET['new'] ) && bp_is_active( 'notifications' ) ) { 197 bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->friends->id, 'friendship_request' ); 198 } 199 } 200 add_action( 'friends_screen_requests', 'bp_friends_mark_friendship_request_notifications_by_type' ); 201 202 /** 203 * Delete any friendship acceptance notifications for the logged in user. 204 * 205 * @since BuddyPress (1.9.0) 206 */ 207 function bp_friends_mark_friendship_accepted_notifications_by_type() { 208 if ( bp_is_active( 'notifications' ) ) { 209 bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->friends->id, 'friendship_accepted' ); 210 } 211 } 212 add_action( 'friends_screen_my_friends', 'bp_friends_mark_friendship_accepted_notifications_by_type' ); 213 214 /** 215 * Notify one use that another user has requested their virtual friendship. 216 * 217 * @since BuddyPress (1.9.0) 218 * @param int $friendship_id The unique ID of the friendship 219 * @param int $initiator_user_id The friendship initiator user ID 220 * @param int $friend_user_id The friendship request reciever user ID 221 */ 222 function bp_friends_friendship_requested_notification( $friendship_id, $initiator_user_id, $friend_user_id ) { 223 if ( bp_is_active( 'notifications' ) ) { 224 bp_notifications_add_notification( array( 225 'user_id' => $friend_user_id, 226 'item_id' => $initiator_user_id, 227 'secondary_item_id' => $friendship_id, 228 'component_name' => buddypress()->friends->id, 229 'component_action' => 'friendship_request', 230 'date_notified' => bp_core_current_time(), 231 'is_new' => 1, 232 ) ); 233 } 234 } 235 add_action( 'friends_friendship_requested', 'bp_friends_friendship_requested_notification', 10, 3 ); 236 237 /** 238 * Remove friend request notice when a member rejects another members 239 * 240 * @since BuddyPress (1.9.0) 241 * 242 * @param int $friendship_id (not used) 243 * @param object $friendship 244 */ 245 function bp_friends_mark_friendship_rejected_notifications_by_item_id( $friendship_id, $friendship ) { 246 if ( bp_is_active( 'notifications' ) ) { 247 bp_notifications_mark_notifications_by_item_id( $friendship->friend_user_id, $friendship->initiator_user_id, buddypress()->friends->id, 'friendship_request' ); 248 } 249 } 250 add_action( 'friends_friendship_rejected', 'bp_friends_mark_friendship_rejected_notifications_by_item_id', 10, 2 ); 251 252 /** 253 * Notify a member when another member accepts their virtual friendsip request. 254 * 255 * @since BuddyPress (1.9.0) 256 * @param int $friendship_id The unique ID of the friendship 257 * @param int $initiator_user_id The friendship initiator user ID 258 * @param int $friend_user_id The friendship request reciever user ID 259 */ 260 function bp_friends_add_friendship_accepted_notification( $friendship_id, $initiator_user_id, $friend_user_id ) { 261 262 // Bail if notifications is not active 263 if ( ! bp_is_active( 'notifications' ) ) { 264 return; 265 } 266 267 // Remove the friend request notice 268 bp_notifications_mark_notifications_by_item_id( $friend_user_id, $initiator_user_id, buddypress()->friends->id, 'friendship_request' ); 269 270 // Add a friend accepted notice for the initiating user 271 bp_notifications_add_notification( array( 272 'user_id' => $initiator_user_id, 273 'item_id' => $friend_user_id, 274 'secondary_item_id' => $friendship_id, 275 'component_name' => buddypress()->friends->id, 276 'component_action' => 'friendship_accepted', 277 'date_notified' => bp_core_current_time(), 278 'is_new' => 1, 279 ) ); 280 } 281 add_action( 'friends_friendship_accepted', 'bp_friends_add_friendship_accepted_notification', 10, 3 ); 282 283 /** 284 * Remove friend request notice when a member withdraws their friend request 285 * 286 * @since BuddyPress (1.9.0) 287 * 288 * @param int $friendship_id (not used) 289 * @param object $friendship 290 */ 291 function bp_friends_mark_friendship_withdrawn_notifications_by_item_id( $friendship_id, $friendship ) { 292 if ( bp_is_active( 'notifications' ) ) { 293 bp_notifications_delete_notifications_by_item_id( $friendship->friend_user_id, $friendship->initiator_user_id, buddypress()->friends->id, 'friendship_request' ); 294 } 295 } 296 add_action( 'friends_friendship_withdrawn', 'bp_friends_mark_friendship_withdrawn_notifications_by_item_id', 10, 2 ); 297 298 /** 299 * Remove friendship requests FROM user, used primarily when a user is deleted 300 * 301 * @since BuddyPress (1.9.0) 302 * @param int $user_id 303 */ 304 function bp_friends_remove_notifications_data( $user_id = 0 ) { 305 if ( bp_is_active( 'notifications' ) ) { 306 bp_notifications_delete_notifications_from_user( $user_id, buddypress()->friends->id, 'friendship_request' ); 307 } 308 } 309 add_action( 'friends_remove_data', 'bp_friends_remove_notifications_data', 10, 1 ); -
plugins/buddypress/bp-friends/bp-friends-screens.php
diff --git a/plugins/buddypress/bp-friends/bp-friends-screens.php b/plugins/buddypress/bp-friends/bp-friends-screens.php index 2972dad..9beddd3 100644
a b 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' ) ); … … 66 63 } 67 64 68 65 do_action( 'friends_screen_requests' ); 69 70 if ( isset( $_GET['new'] ) ) {71 bp_core_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->friends->id, 'friendship_request' );72 }73 66 74 67 bp_core_load_template( apply_filters( 'friends_template_requests', 'members/single/home' ) ); 75 68 }